Declarative Logic Programming

ACM Books

Editor in Chief

M. Tamer Özsu, University of Waterloo

ACM Books is a new series of high-quality books for the computer science community, published by ACM in collaboration with Morgan & Claypool Publishers. ACM Books publications are widely distributed in both print and digital formats through booksellers and to libraries (and library consortia) and individual ACM members via the ACM Digital Library platform.

Declarative Logic Programming: Theory, Systems, and Applications

Editors: Michael Kifer, Stony Brook University

Yanhong Annie Liu, Stony Brook University

2018

The Handbook of Multimodal-Multisensor Interfaces, Volume 2: Signal Processing, Architectures, and Detection of Emotion and Cognition

Editors: Sharon Oviatt, Monash University

Björn Schuller, University of Augsburg and Imperial College London

Philip R. Cohen, Monash University

Daniel Sonntag, German Research Center for Artificial Intelligence (DFKI)

Gerasimos Potamianos, University of Thessaly

Antonio Krüger, German Research Center for Artificial Intelligence (DFKI)

2017

The Sparse Fourier Transform: Theory and Practice

Haitham Hassanieh, University of Illinois at Urbana-Champaign

2018

The Continuing Arms Race: Code-Reuse Attacks and Defenses

Editors: Per Larsen, Immunant, Inc.

Ahmad-Reza Sadeghi, Technische Universität Darmstadt

2018

Frontiers of Multimedia Research

Editor: Shih-Fu Chang, Columbia University

2018

Shared-Memory Parallelism Can Be Simple, Fast, and Scalable

Julian Shun, University of California, Berkeley

2017

Computational Prediction of Protein Complexes from Protein Interaction Networks

Sriganesh Srihari, The University of Queensland Institute for Molecular Bioscience

Chern Han Yong, Duke-National University of Singapore Medical School

Limsoon Wong, National University of Singapore

2017

The Handbook of Multimodal-Multisensor Interfaces, Volume 1: Foundations, User Modeling, and Common Modality Combinations

Editors: Sharon Oviatt, Incaa Designs

Björn Schuller, University of Passau and Imperial College London

Philip R. Cohen, Voicebox Technologies

Daniel Sonntag, German Research Center for Artificial Intelligence (DFKI)

Gerasimos Potamianos, University of Thessaly

Antonio Krüger, German Research Center for Artificial Intelligence (DFKI)

2017

Communities of Computing: Computer Science and Society in the ACM

Thomas J. Misa, Editor, University of Minnesota

2017

Text Data Management and Analysis: A Practical Introduction to Information Retrieval and Text Mining

ChengXiang Zhai, University of Illinois at Urbana–Champaign

Sean Massung, University of Illinois at Urbana–Champaign

2016

An Architecture for Fast and General Data Processing on Large Clusters

Matei Zaharia, Stanford University

2016

Reactive Internet Programming: State Chart XML in Action

Franck Barbier, University of Pau, France

2016

Verified Functional Programming in Agda

Aaron Stump, The University of Iowa

2016

The VR Book: Human-Centered Design for Virtual Reality

Jason Jerald, NextGen Interactions

2016

Ada’s Legacy: Cultures of Computing from the Victorian to the Digital Age

Robin Hammerman, Stevens Institute of Technology

Andrew L. Russell, Stevens Institute of Technology

2016

Edmund Berkeley and the Social Responsibility of Computer Professionals

Bernadette Longo, New Jersey Institute of Technology

2015

Candidate Multilinear Maps

Sanjam Garg, University of California, Berkeley

2015

Smarter Than Their Machines: Oral Histories of Pioneers in Interactive Computing

John Cullinane, Northeastern University; Mossavar-Rahmani Center for Business and Government, John F. Kennedy School of Government, Harvard University

2015

A Framework for Scientific Discovery through Video Games

Seth Cooper, University of Washington

2014

Trust Extension as a Mechanism for Secure Code Execution on Commodity Computers

Bryan Jeffrey Parno, Microsoft Research

2014

Embracing Interference in Wireless Systems

Shyamnath Gollakota, University of Washington

2014

Declarative Logic Programming

Theory, Systems, and Applications

Michael Kifer

Stony Brook University

Yanhong Annie Liu

Stony Brook University

ACM Books #20

Copyright © 2018 by the Association for Computing Machinery and Morgan & Claypool Publishers

All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means—electronic, mechanical, photocopy, recording, or any other except for brief quotations in printed reviews—without the prior permission of the publisher.

Designations used by companies to distinguish their products are often claimed as trademarks or registered trademarks. In all instances in which Morgan & Claypool is aware of a claim, the product names appear in initial capital or all capital letters. Readers, however, should contact the appropriate companies for more complete information regarding trademarks and registration.

Declarative Logic Programming: Theory, Systems, and Applications

Michael Kifer, Yanhong Annie Liu, editors

books.acm.org

www.morganclaypoolpublishers.com

ISBN: 978-1-97000-199-0 hardcover

ISBN: 978-1-97000-196-9 paperback

ISBN: 978-1-97000-197-6 eBook

ISBN: 978-1-97000-198-3 ePub

Series ISSN: 2374-6769 print 2374-6777 electronic

DOIs:

10.1145/3191315 Book

10.1145/3191315.3191316 Preface

10.1145/3191315.3191317 Chapter 1

10.1145/3191315.3191318 Chapter 2

10.1145/3191315.3191319 Chapter 3

10.1145/3191315.3191320 Chapter 4

10.1145/3191315.3191321 Chapter 5

10.1145/3191315.3191322 Chapter 6

10.1145/3191315.3191323 Chapter 7

10.1145/3191315.3191324 Chapter 8

10.1145/3191315.3191325 Chapter 9

10.1145/3191315.3191326 Chapter 10

10.1145/3191315.3191327 Index

A publication in the ACM Books series, #20

Editor in Chief: M. Tamer Özsu, University of Waterloo

Area Editor: Yanhong Annie Liu, Stony Brook University

This book was typeset in Arnhem Pro 10/14 and Flama using ZzTEX.

First Edition

10 9 8 7 6 5 4 3 2 1

To David Scott Warren, for his groundbreaking work on principles and systems for logic programming

Preface

The idea of this book grew out of a symposium that was held at Stony Brook in September 2012 in celebration of David S. Warren’s fundamental contributions to Computer Science and the area of Logic Programming in particular.

Logic Programming (LP) is at the nexus of Knowledge Representation, Artificial Intelligence, Mathematical Logic, Databases, and Programming Languages. It is fascinating and intellectually stimulating due to the fundamental interplay among theory, systems, and applications brought about by logic. Logic programs are more declarative in the sense that they strive to be logical specifications of “what” to do rather than “how” to do it, and thus they are high-level and easier to understand and maintain. Yet, without being given an actual algorithm, LP systems implement the logical specifications automatically.

Several books cover the basics of LP but focus mostly on the Prolog language with its incomplete control strategy and non-logical features. At the same time, there is generally a lack of accessible yet comprehensive collections of articles covering the key aspects in declarative LP. These aspects include, among others, well-founded vs. stable model semantics for negation, constraints, object-oriented LP, updates, probabilistic LP, and evaluation methods, including top-down vs. bottom-up, and tabling.

For systems, the situation is even less satisfactory, lacking accessible literature that can help train the new crop of developers, practitioners, and researchers. There are a few guides on Warren’s Abstract Machine (WAM), which underlies most implementations of Prolog, but very little exists on what is needed for constructing a state-of-the-art declarative LP inference engine. Contrast this with the literature on, say, Compilers, where one can first study a book on the general principles and algorithms and then dive in the particulars of a specific compiler. Such resources greatly facilitate the ability to start making meaningful contributions quickly. There is also a dearth of articles about systems that support truly declarative languages, especially those that tie into first-order logic, mathematical programming, and constraint solving.

LP helps solve challenging problems in a wide range of application areas, but in-depth analysis of their connection with LP language abstractions and LP implementation methods is lacking. Also, rare are surveys of challenging application areas of LP, such as Bioinformatics, Natural Language Processing, Verification, and Planning.

The goal of this book is to help fill in the previously mentioned void in the LP literature. It offers a number of overviews on key aspects of LP that are suitable for researchers and practitioners as well as graduate students. The following chapters in theory, systems, and applications of LP are included.

Part I: Theory

1.  “Datalog: Concepts, History, and Outlook” by David Maier, K. Tuncay Tekle, Michael Kifer, and David S. Warren.

This chapter is a comprehensive survey of the main concepts of Datalog, an LP language for data processing. The study of Datalog was one of the early drivers of more declarative approaches to LP. Some aspects of Datalog are covered in greater depth than others, but the bibliography at the end of the chapter can be relied upon to help fill in the details.

2.  “An Introduction to the Stable and Well-Founded Semantics of Logic Programs” by Miroslaw Truszczynski.

The theory underlying modern LP is based on two different logical semantics: the stable model semantics and the well-founded semantics, leading to two different declarative paradigms. The stable model semantics defines the meaning of an LP program as a set of two-valued models and is a leading approach in LP to solving combinatorial problems. The well-founded semantics always yields a single, possibly three-valued, model and is popular with knowledge representation systems that focus on querying. This chapter provides a rigorous yet accessible introduction to both semantics.

3.  “A Survey of Probabilistic Logic Programming” by Fabrizio Riguzzi and Theresa Swift.

Integration of probabilistic and logic reasoning is of great importance to modern Artificial Intelligence. This chapter provides a uniform introduction, based on what is called distribution semantics, to a number of leading approaches to such integration.

Part II: Systems

4.  “WAM for Everyone: A Virtual Machine for Logic Programming” by David S. Warren.

This chapter is an introduction to Warren’s Abstract Machine (WAM), the primary technology underlying modern LP systems. Unlike previous expositions of WAM, this chapter also describes tabling, one of the main breakthroughs that occurred since D.H.D. Warren developed the original WAM in 1970’s.

5.  “Predicate Logic as a Modeling Language: The IDP System” by Broes De Cat, Bart Bogaerts, Maurice Bruynooghe, Gerda Janssens, and Marc Denecker.

IDP is a language and system that supports classical predicate logic extended with inductive definitions as rules, and with aggregation, functions, and types. It promotes a declarative semantics of logic programs and allows a single logical specification to be used in multiple different reasoning tasks to solve a range of problems. This chapter gives an overview of the IDP language and system.

6.  “SolverBlox: Algebraic Modeling in Datalog” by Conrado Borraz-Sánchez, Diego Klabjan, Emir Pasalic, and Molham Aref.

LogiQL extends Datalog with aggregation, reactive rules, and constraints to support transactions in a database and software development platform called LogicBlox. This chapter introduces LogiQL and shows how it can be used to specify and solve mixed-integer linear optimization problems by adding simple declarations.

Part III: Applications

7.  “Exploring Life: Answer Set Programming in Bioinformatics” by Alessandro Dal Palù, Agostino Dovier, Andrea Formisano, and Enrico Pontelli.

This chapter surveys applications of declarative LP in Bioinformatics, including in Genomics studies, Systems Biology, and Structural studies. The necessary biological background is provided when necessary. The applications selected for this survey all rely on the Answer Set Programming paradigm.

8.  “State-Space Search with Tabled Logic Programs” by C. R. Ramakrishnan.

Model checking and planning are two important and challenging classes of problems that require extensive search through the possible states of systems. This chapter gives an overview of both types of problems as applications of LP. It focuses on tabling as an effective technique for improving the performance of state space search.

9.  “Natural Language Processing with (Tabled and Constraint) Logic Programming” by Henning Christiansen and Verónica Dahl.

Natural language processing (NLP) was the original motivation for the development of Prolog, the most popular logic-based language. This chapter is an overview of the applications of LP to NLP, primarily based on definite clause grammars.

10.  “Logic Programming Applications: What Are the Abstractions and Implementations?” by Yanhong A. Liu.

LP is used in many areas and contexts but the applicability of LP needs to be understood in more fundamental ways. This chapter gives an overview of LP applications, classifying them based on three key abstractions and their corresponding implementations. The abstractions are join, recursion, and constraint. The corresponding implementations are for-loops, fixed points, and backtracking.

Acknowledgments

Congratulations to the chapter authors for the well-thought-out surveys—all written specifically for this book. Each contribution was carefully reviewed, with at least four reviews per chapter. We are deeply grateful to the reviewers for the time and effort dedicated to perfecting the book material. Many thanks to the Editor-in-Chief of ACM Books series, M. Tamer Özsu, for his support, and to Diane Cerra of Morgan & Claypool for her help, guidance, and patience throughout the process. We were lucky to have an expert production team: Paul Anagnostopoulos of Windfall Software, who masterfully typeset this book; Sara Kreisman of Rambling Rose Press, who copyedited the pesky typos out of existence; Brent Beckley of Morgan & Claypool, who designed the beautiful and artsy cover; and Christine Kiilerich, also of Morgan & Claypool, who helped with many publication tasks.

We also acknowledge the support of NSF under grants CCF-0964196, CCF-1248184, CCF-1414078, and IIS-1447549; and of ONR under grant N000141512208.

PART I

THEORY

1

Datalog: Concepts, History, and Outlook

David Maier, K. Tuncay Tekle, Michael Kifer, David S. Warren

This chapter is a survey of the history and the main concepts of Datalog. We begin with an introduction to the language and its use for database definition and querying. We then look back at the threads from logic languages, databases, artificial intelligence, and expert systems that led to the emergence of Datalog and reminiscence about the origin of the name. We consider the interaction of recursion with other common data language features, such as negation and aggregation, and look at other extensions, such as constraints, updates, and object-oriented features. We provide an overview of the main approaches to Datalog evaluation and their variants, then recount some early implementations of Datalog and of similar deductive database systems. We speculate on the reasons for the decline in the interest in the language in the 1990s and the causes for its later resurgence in a number of application areas. We conclude with several examples of current systems based on or supporting Datalog and briefly examine the performance of some of them.

1.1    Introduction

Datalog has had a tumultuous history during which interest in it waxed and waned and waxed again. The name was originally coined to designate a simplified Hornlogic language akin to Prolog, but has since come to identify research on deductive databases and recursive query processing. Given the more than three decades since the introduction of Datalog, the time is right to explore its roots, recount early work on it, try to understand its declining fortunes in the 1990s, and examine the recent resurgence of interest in the language. This chapter is not intended to be a tutorial on Datalog nor a comprehensive research survey; rather, it is a recounting of developments in the history of Datalog, with some personal interpretation here and there.

Before examining the roots of Datalog, we review the basics of the language. We begin with a sample database that we employ throughout, followed by some examples of a Datalog program and queries that use that database. The database contains information about doctoral theses and advisors.¹ We use a schema with four relations to represent academic-descendant information:

The person relation provides an identifier for each person involved, along with the person’s name. The relation area provides areas and long descriptions of the different areas for theses. The thesis relation gives details on a person’s thesis, while advised captures the information about the advisor(s) for a person. (One can have multiple advisors if they jointly advised that person or if the person obtained multiple Ph.D. degrees.)

A Datalog program typically consists of facts and rules. A fact asserts that a particular tuple belongs to a relation. From a logical viewpoint, it represents a predicate being true for a particular combination of values. Below are some Datalog facts corresponding to the thesis schema. An alphanumeric value starting with a lowercase letter is a unique symbol, not equal to any other value. If a symbol starts with a capital letter or if it contains non-alphanumeric characters (e.g., a space) then it is enclosed in single quotes. The year is represented here as an integer. From the data below we see that David Warren completed his Ph.D. thesis on Montague grammars at Michigan in 1979, under the direction of Joyce Friedman and William Rounds.

A Datalog rule is similar to a view definition in relational database systems. It states that if certain tuples exist in specific relations, then an additional tuple is assumed to exist in a “virtual” or derived relation. It can also be considered an inference rule for deducing new facts from existing ones. A rule has a head followed by a body, separated by the symbol :–, which is intended to resemble a left-pointing implication arrow. The head indicates the tuple being defined, and the body is a comma-separated list of facts, in which the commas are interpreted as “and”. A rule generally contains one or more logical variables, which begin with uppercase letters.² Note that, under these conventions, First would be a variable, while 'First' a constant symbol. The rule asserts that the implication holds for all possible substitutions of the logical variables. For example, suppose we want to define a relation with certain information about people who received a Ph.D. in the area of Computer Science. We could use the following Datalog rule:

One way to understand a Datalog rule is as standing for all ground instances of the rule obtained by consistently substituting constants for the logical variables. Two such instances of the rule above are

The effect of a rule is to extend the database by the fact in the head for every such ground instance whenever all the facts in the body have been previously established—either because they are given explicitly as facts or because they were obtained from an instance of some rule using the same reasoning. Considering the two instances above, the first establishes the fact

as all the facts in the body are known to be true. However, the second rule instance does not establish the fact

as the fact person(jbf,'Joyce','Hansen') is not one listed in this example program (nor can it be established by the rules above).

Another way to regard this rule is as a view definition, which we could write in SQL³ as

Note that there is a difference in Datalog and SQL in referring to attributes: Datalog relies on positional notation, while SQL has explicit naming. Also, in SQL variables range over tuples while in Datalog they range over individual domain elements. For those familiar with relational database theory, the difference is essentially that between the domain and tuple relational calculi.

Datalog allows multiple rules with the same predicate in the head, in which case the database is extended by the facts established by any of the rules. For example, if we wanted to derive all people in an adjacent generation to a given person (that is, the person’s direct advisors or advisees), we could use the two rules

We can view a Datalog program as describing a database, with some tuples given by facts and others established by rules. There are various conventions for expressing a query and the result against that database. For the moment, we will use a single predicate pattern, with zero or more variables, preceded by ?-, as a query. The result of the query will be the set of all matching facts in the database specified by the Datalog program. Thus, if our program is all the previous facts and rules, then the query

has the result set

where the first two tuples are established by the first adjacent rule, and the other two by the second. A query with no variables functions as a membership test, returning a singleton set if the corresponding tuple is in the database of the Datalog program, and an empty set if not. So the query

returns the singleton answer

but the query

returns an empty result.

While the two rules for adjacent can be captured by a view using UNION in SQL, Datalog can express virtual relations that SQL cannot, via recursion in rules.⁴ Suppose we want to consider two people “related” if they have a common academic ancestor. We can describe this relation with three rules:

We see that two of the rules establish related-facts recursively, from other related-facts. So, for example, we can use the following instance of the first rule

to establish the fact related(lvk, ks), then use that fact with the following instance of the second rule

to establish the fact related(jmy, kv). Note that while a newly established related-fact might be able to establish a further related-fact, the process must eventually stop. Every related-fact involves person IDs from the original advised-facts, and there are a finite number of pairs of such IDs.

More generally, we view the meaning of a Datalog program P consisting of facts and rules as the database of ground facts obtained starting with the original facts and applying the rules to derive additional facts until there are no changes. In this context it is useful to view P as a transformation (sometimes called the immediate consequence operator) that takes a set of ground facts as input and augments them with the additional facts that can be established with a single application of any fact or rule in P. If we start with an empty input, the first “application” of P adds all the facts in P. A second application adds all facts that can be established with one rule application, a third application adds facts established with two rule applications, and so on. Eventually this process converges when some application of P adds no new facts. Thus, we can view the meaning of P as the least fixed point [Lloyd 1993, Van Emden and Kowalski 1976] under application of P’s rules and facts. It turns out that, for Datalog, that the meaning for P is also the least model for P, in the sense that it is the minimal set of facts that includes all the facts for P and makes every ground instance of a rule in P true. (We will see later that this equivalence must be adjusted in order to handle negation.)

We note that the process of repeated applications of P as described above is actually a viable procedure for computing the meaning of a Datalog program, and is referred to as bottom-up evaluation. A query is then matched against the final set of established facts to find its answers. An alternative approach is top-down evaluation, which starts with a particular query, and tries to match it with a fact or rule head in P. If it matches a fact, then a new answer has been established. If it matches a rule head, the rule body becomes the new query, and the process continues, trying to match the goals in the rule body. For example, the query

does not match any facts directly, but it does match the head of the rule

if we replace P1 by dsw. The body of the rule leaves the new query

which matches the two facts

resulting in two answers:

Matching the original query with the other adjacent rule gives two additional answers. We will cover evaluation techniques in more detail in Section 1.5.

Three final points before we leave this overview of Datalog. First, it is common to classify the tuples in the database specified by a Datalog program into two parts. The extensional database, or EDB, is all the tuples corresponding to explicit facts in the program, for example, advised(dsw, lvk). The intensional database, or IDB, is all the tuples established by the rules in the program, for example, related(lvk, ks). While the same relation could draw tuples from both the EDB and the IDB, many authors assume each relation to be strictly extensional or intensional. This assumption is not really a limitation, since a Datalog program where it does not hold is easily rewritten into one where it does and that specifies the same database.

The second is a restriction usually placed on Datalog programs that the rules be safe, in the sense that any fact in the IDB contains only the values that appear in the EDB or the rules themselves. For example, the rule

is not safe, because the value of P2 is unconstrained and therefore P2 can be bound to any value, not necessarily the ones that appear in EDB. Generally, safety is guaranteed by a syntactic condition, such as requiring that every variable in the rule head also appear in some predicate in the rule body.

The third point is a notational convenience. The first Datalog rule could be written more succinctly as:

In this formulation, since the actual names of the variables do not matter, logical variables are consistently renamed with 1-letter variable names. Furthermore, inventing names for the variables that occur only once in a rule is an unnecessary burden and the underscore is often used to denote “anonymous” variables. Each occurrence of “_” is treated as a new variable name, which the parser generates automatically.

1.2    The Emergence of Datalog

Since Datalog is a subset of Prolog, one could create and execute Datalog programs as soon as Prolog evaluators existed—around 1972. However, as a named concept and object of study, Datalog emerged in the mid-1980s, following work in deductive databases in the late 1970s. (See Section 1.3 for more on the naming of Datalog.) Why did Datalog emerge as a topic of interest at that point? It was because Datalog served as a “sweet spot”—or “middle ground”—for related research lines from Logic Programming, Database Systems, and Artificial Intelligence.

Why was Datalog interesting to the three communities? It was because pure Datalog was very simple and had a clean syntax and semantics. Yet it was expressive enough to serve as the basis for theoretical investigations and examination of evaluation alternatives, as well as a foundation from which extensions could be explored and a starting point for knowledge-representation systems. We summarize relevant trends in each of the three communities below, following each by more specific background.

Logic Programming

Logic programmers saw relational databases as an implementation of an important sublanguage, and worked to integrate them into Prolog systems. Since early Prolog implementations assumed all rules and facts were memory-resident, it was clear that for very large fact bases, something like relational database technology was necessary. Sometimes this enhancement took the form of a connection to a relational database management system (RDBMS). Translators were written to convert a subset of Prolog programs into SQL to be passed to an RDBMS and evaluated there. Datalog was a more powerful, more Prolog-ish, data-oriented subset of Prolog than SQL. Datalog was also more “declarative” than Prolog and many in the Logic Programming community liked that aspect. With Prolog, there was a serious gap between Logic Programming theory (programs understood as logical axioms and deduction) and Logic Programming practice (programs as evaluated by Prolog interpreters). For one thing, Prolog contained a number of non-logical primitives; for another, many perfectly logical Prolog programs would not terminate due to the weaknesses of the evaluation strategy used by the Prolog interpreters. With Datalog, that gap almost disappeared—deduction largely coincided with evaluation in terms of the produced results. Also, Datalog provided a basis on which to work out solutions for recursion with negation, some of which could be applied to more general logic languages.

Background. Logic programming grew out of resolution theorem proving proposed by Robinson [1965] and, especially, out of a particularly simplified version of it, called SLD resolution [Lloyd 1993, Kowalski 1974], which worked for special cases of logic, such as Horn clauses.⁵ In the early 1970s, researchers began to realize that SLD resolution combined with backtracking provided a computational model. In particular, Colmerauer and collaborators developed Prolog [Colmerauer and Roussel 1996] and Kowalski made significant contributions to the theory of logic programming, as it came to be called [Kowalski 1988]. Prolog was the starting point for languages in the Japanese Fifth-Generation Computer Systems (FGCS) project in the early 1980s [Fuchi and Furukawa 1987, Moto-oka and Stone 1984]. The FGCS project sought advances in hardware, databases, parallel computing, deduction and user interfaces to build high-performance knowledge-base systems. In the context of this project, Fuchi [1981] describes Prolog as a basis for bringing together programming languages and database query languages. D. H. D. Warren [1982b] provides interesting insights into the focus on Prolog for the FGCS. The use of Prolog to express queries dates from around the same time. For example, the Chat-80 system [Warren and Pereira 1982] analyzed natural-language questions and turned them into Prolog clauses that could be evaluated against stored predicates. (All examples there are actually in Datalog.) Warren [1981] showed that such queries were amenable to some database-style optimizations via Prolog rewriting and annotation. Prolog itself had been proposed for database query. For example, Maier [1986b] considers Prolog as a database query language and notes its advantages—avoiding the “impedance mismatch” between DBMS and programming language, expressive power, ease of transformation—but also points out its limits in terms of data definition, update, secondary storage, concurrency control and recovery. Zaniolo [1986] also notes that Prolog can be used to write complete database applications, avoiding the impedance mismatch. He further proposes extensions to Prolog for use with a data model supporting entity identity. For a recent survey of the history of logic programming, see Kowalski [2014].

Database Systems

As the relational model gained traction in the 1980s, limitations on expressiveness of the query languages became widely recognized by researchers and practitioners. In particular, fairly common applications—such as the transitive closure of a graph and bill-of-materials roll ups (i.e., aggregation of costs, weights, etc. in a partsubpart hierarchy)—could not be expressed with a single query in most relational query languages. Various approaches for enhancing expressiveness to handle such cases were proposed, such as adding control structures or a fixpoint operator to relational algebra. Datalog was a simple alternative that was similar to domain relational calculus, with which the database theory community was familiar. Thus, it was readily understood, and provided a natural setting in which to study topics such as deductive databases, recursion, its interaction with negation, and evaluation techniques. Much of the early discussion and presentations on Datalog took place at the informal “XP” workshops⁶ (particularly XP 4.5 in 1983 and XP 7.52 in 1986) and the early symposia on Principals of Database Systems (PODS), which were a follow-up to the XP workshops to some extent. Work on Datalog also highlighted the difference between query answering as evaluation in a model vs. deduction in a theory.

Background. It was recognized early on that there were recursive queries expressible neither in relational algebra nor relational calculus. For example, Aho and Ullman [1979] prove the inexpressibility of transitive closure by finite relational expressions, and consider various extensions to handle it, such as a least-fixed-point operator and embedding in a host programming language. Paredaens [1978] and Bancilhon [1978] also explore this issue. The PROBE system supported traversal recursion over directed graphs [Rosenthal et al. 1986].

The connection of logic and databases predates the relational model. For example, Green and Raphael [1968] uses theorem proving as the basis for the question-answering system QA1 that can “deduce facts that are not explicitly available in its data base.” The 1970s was an active time for investigating the connections between logic and databases, such as model-theoretic vs. proof-theoretic views of a database [Nicolas and Gallaire 1977] and “closed-world” vs. “open-world” assumptions about the information in a database [Reiter 1977b]. It was also a time when prototype deductive databases based on logic began appearing, such as MRRPS 3.0 [Minker 1977], DADM [Kellogg et al. 1977], and DEDUCE 2 [Chang 1977]. While many researchers of deductive databases focused on function-free logic, Reiter [1977a] was explicit in his opinion that function-free logic “approximates [his] own intuitive concept of what should be a database,” for otherwise “any first-order theory is a database,” such as point-set topology. For a history of deductive databases, see Minker et al. [2014].

Artificial Intelligence

The use of logic and deduction as a basis for question-answering and reasoning in expert systems dates to at least the late 1960s. Rule-based systems were also a common approach to AI problem solving. Logic languages such as Prolog were attractive to this community because they encompassed both basic information and rule-based “intelligence” to work with that knowledge in a uniform model, while providing a formal foundation for rule-based reasoning. There were other attractions, such as the natural use of meta-programming features to manipulate programs and implement alternative evaluation systems. Prolog rules seemed an accessible means for domain experts (who were assumed not to be sophisticated programmers) to directly capture their reasoning strategies. Furthermore, the resolution-based deduction methods used with Prolog were at once a close analog of human reasoning and an efficient evaluation mechanism. By the early 1980s, there was interest in working with large fact bases in expert systems, and imbuing database systems with intelligence, manifested in the closely related areas of Knowledge-Based Systems (KBS) and Expert Database Systems (EDS). Some saw the function-free subset of Prolog as a happy medium between databases and general rule-based reasoning. Datalog became a common basis for work in the KBS and especially the EDS communities.

Background. As mentioned, one of the earliest proposals to use theorem proving as a mechanism for query answering was that of Green [1969]. The 1970s saw a proliferation of expert systems that tried to replicate human expertise in computational form [Puppe 1993]. These early systems tended to be ad hoc, with much of their knowledge encoded procedurally. Toward 1980, KBS emerged as an architectural approach to make expert systems (and other reasoning applications) easier to construct and maintain, especially when involving large collections of information [Davis 1986]. In a KBS, there is a separation of knowledge structures and the computational mechanism to apply that knowledge. These two parts are often called the knowledge base and the inference engine. (The inference engine did not necessarily use logical inference. It could, for example, make use of probabilistic reasoning.) The knowledge base contains both concrete information (facts) and more abstract forms of knowledge, such as rules, templates, or classification hierarchies. Logic was the representation for the knowledge base in some KBS, although there were competing approaches, such as frame-based systems [Minsky 1975] and semantic networks [Findler 1979]. (It is interesting to note that there was some debate at the time as to the suitability of logic for this role [Hayes 1977, Hayes 1980, Winograd 1975].) The logic-based KBS often structured the knowledge base in the form of facts and rules, similar to a logic program. For example, the DLOG system [Goebel 1985] was a KBS using logic, and its implemented subset consisted of facts and Horn clauses that were passed to a Prolog-based interpreter. Another example of a logic-based framework for KBS was the Syllog system [Fellenstein et al. 1985], which had a database and Prolog-style rules, but presented a structured natural-language interface to them. In a similar vein to KBS, Expert Database Systems (EDS) were an effort to imbue database systems with richer representation and reasoning capabilities. Logic (usually in the guise of logic programming) was often the choice for providing capabilities such as classification hierarchies [Dahl 1982] and incorporating constraints into query answering [Dahl 1986, Kifer and Li 1988]. Kerschberg [1990] provides an overview of EDS.

1.2.1    Uptake

While Datalog had precursors from Logic Programming, Database Systems, and Artificial Intelligence, the bulk of the early work on it took place in the database theory and query-language communities. Deductive-database researchers showed some interest, but their focus was more on removing non-declarative features—such as cut—from Prolog while retaining top-down, SLD-resolution approaches to evaluation [Minker et al. 2014]. On the database-query side, however, there was strong interest in adding rules and recursion to existing query frameworks, which mainly employed bottom-up techniques based on relational algebra for evaluation. Since Datalog did not have function symbols, a safe program implied a finite number IDB facts from a finite EDB, meaning that bottom-up techniques would converge. Much early work on implementation techniques for Datalog and similar languages was based on bottom-up approaches, and researchers found ways to adapt these approaches to support additional features, such as complex objects, aggregation, and negation. These extensions motivated new semantic constructs, such as stratification and stable models for negation and other non-monotone extensions. Therefore, it should be no surprise that the majority of sources cited in this chapter appeared in database venues, through there is a significant body of references from logic programming and AI publications.

1.3    Coining “Datalog”

To the best of our knowledge, the name “Datalog” as applied to function-free Prolog was coined while two of the authors of this chapter, David Maier and David S. Warren, were working on the book Computing with Logic [Maier and Warren 1988]. The book used simplified logics and languages to introduce concepts such as substitution and resolution. The simplest logic was propositional Horn clauses, and the obvious name for the corresponding language was “Proplog.” We wanted to introduce unification and specialization of clauses using predicate Horn logic without function symbols, to avoid some of more complicated bits of Prolog initially, such as the occurs check and structure sharing. Maier and Warren kicked around ideas for a name for the corresponding language, but came up with nothing exciting at first. The next day, Maier came back with “Datalog,” presumably because predicates without function symbols looked a lot like database relations.

At the time, several researchers had already proposed function-free, definiteclause logic as a basis for deductive databases. While Maier and Warren were not thinking about “Datalog” as the name for a database language, it quickly spread to that use, and the first appearances in print of “Datalog” depict it as a database language. Computing with Logic only came out in January 1988, but Maier introduced the name to students at Oregon Graduate Institute (then Oregon Graduate Center) and to collaborators at Stanford University while he was working on the book. The first uses of the name Datalog in the general literature, as far was we can tell, were in the proceedings of the PODS conference in March 1986, where it appears in Afrati et al. [1986] and Bancilhon et al. [1986]. The first mention of Datalog in the gray literature was by Harry Porter, who had taken a class from Maier on the magic of Logic Programming based on the notes for Computing with Logic. The earliest use we have found is a manuscript by Porter from October 1985 [Porter 1985]. We note that the name “Datalog” was also applied about the same time to a natural-language system for database query (written in Lisp) [Hafner and Godden 1985]. That use came from “database dialog,” and does not seem to have a connection to Prolog.

In any case, by mid-1986, Datalog as the name for a database language had been established. Viewed from the programming language side, it was a restricted version of Prolog, with no function symbols and no extra-logical predicates, such as cut and var. From a logical perspective, it was based on definite Horn clauses over predicates. (A definite Horn clause is a disjunction of literals with exactly one positive literal.) As a database query language, it resembled domain relational calculus. There is some variation across authors about whether or not “pure Datalog” includes negation; here we will assume not. We do assume Datalog programs are safe; safety conditions need to be modified appropriately for some of the extensions below.

1.4    Extensions to Datalog

While pure Datalog has a simple syntax and a clean theory, it does lack direct support for features commonly found in database languages: negation (and set difference), arithmetic, sets and multi-sets, aggregation, updates, and typing and constraints. (There are also system capabilities such as concurrency and recovery that are orthogonal to expressiveness. We do not cover them in this chapter.) There have also been extensions to add object-oriented features (such as object identity, type hierarchies, and nested structures) and higher-order capabilities (such as variables over predicates). We treat negation in some detail, as it has a large effect on semantics and evaluation techniques, and touch on other extensions in varying degrees of detail.

1.4.1    Negation

Pure Datalog cannot express all queries that the relational algebra can because, in particular, it lacks an analog for the difference operator (which requires negation in logic). For example, to find pairs of people who do not share a common advisor, we would want to use a negation operator and write

or something similar.⁷ One approach would be to extend Datalog to use a form of logic more general than definite clauses, and use an evaluation approach based on more general theorem-proving methods. However, such a generalization brings with it much higher computational costs, as the simple proof scheme (called linear resolution) is no longer complete for more general logics. In fact, this “classical” approach to negation does not easily extend to how negation is used in databases. Prolog makes use of the notion of “negation as finite failure,” whereby the negation of a goal is established if attempting to establish the goal fails. This approach is a form of default negation: if something cannot be determined to be true, it is assumed by default to be false. Traditional databases can be seen as using such a form of default negation, if we assume a relation is understood as a set of true facts. If a database query asking whether “Michael” is an employee finds no employee fact for “Michael,” then it answers “No,” that is, “Michael is not an employee.” It does not answer “I don’t know,” which would be an answer according to the classical logic, since neither “Michael is an employee” nor “Michael is not an employee” is logically implied by the set of (positive) employee facts in this case.

The meaning of default negation is straightforward in traditional databases, but becomes problematic when queries are recursive. The simplest definition that raises questions has the form:

Interpreted as a rule to define shavesBarber in some “real world,” this seems to be saying that if shavesBarber is false in our world, then the body of the rule is true, and so it implies that shavesBarber is true. If, on the other hand, shavesBarber is true in our world then the body of the rule is false, and so there is no way to show that shavesBarber is true. Having failed to establish truth of this fact, by negation as failure one might conclude that shavesBarber should thus be false.

The first proposal from the Prolog community to precisely define the meaning of negation in arbitrary rule sets was by Clark [1978] and is known as Clark’s completion. The idea is to “complete” the set of rules (thought of as implications) by essentially turning them into if-and-only-if rules (after combining clauses defining the same predicate using disjunction), and then to use first-order logical implication to determine which goals are true and which are false. So under the completion, the rule above becomes shavesBarber ⇔ ¬shavesBarber, which is inconsistent and has no models. So this situation can be taken to mean that shavesBarber is neither true nor false. This result seems reasonable for this particular one-rule program, but suppose we have a perfectly reasonable and consistent program and one adds the additional shaves-not-shaved rule above. Suddenly the entire database becomes inconsistent just because of one rule—even if this rule has nothing to do with the rest of the database.

But problems with Clark’s completion do not end there. Consider the following positive rule:

What should this program say about iAmHappy? Under the usual semantics for positive rules, iAmHappy would be false since it is not in the minimum model of this program. Alternatively one can see that this rule (being a tautology) says nothing about anything (including iAmHappy) being true, so by default reasoning iAmHappy should be false. But if we take the completion of this program, we get iAmHappy ⇔ iAmHappy which is a tautology, so neither iAmHappy nor not iAmHappy is a logical consequence of this completed program. Thus, iAmHappy is not determined to be either true or false. This situation might not seem much of a problem for this program, but it has deeper consequences for other, more interesting programs. Consider a program defining the transitive closure of an edge relation:

If the edge relation has self-loops, there will be instances of the second rule that simplify to the form reachable(a,b) :– reachable(a,b). For example, if we simply have the single edge fact, edge(b,b), and take the instance of the second rule using X = a, Y = b, and Z = b, then edge(b,b) can be simplified away leaving the self-recursive form. In order to get the right answers for pairs of nodes that are unreachable, we must treat such an instance as determining that reachable(a,b) is definitely false, not that it is unknown. Thus, this example shows that the completion semantics gives the wrong answer for the fully positive program for transitive closure, i.e., the program above, under the completion semantics, does not define transitive closure. It is particularly unpleasant that this attempt to extend the semantics of definite programs (the least model) to programs with negations changes the meaning of definite programs. But this situation indeed is not surprising when we observe that the completion of a Datalog program is a first-order theory and that transitive closure is not first-order definable. And since, for many in the database community, the ability to define transitive closure was one of the key motivations for adding recursion to a query language, the completion semantics appeared to be a wrong semantics for Datalog programs with negation. Its problem was not even with negative recursion, but with positive recursion.

So the search commenced for a semantics of logic programs with negation that would extend the least-fixed-point semantics of positive rule sets. Nicolas and Gallaire [1977] described the alternative approaches to formalizing database semantics in logic, using a theory or an interpretation. The completion semantics used a theory. The following semantics use interpretations.

The first approach was to restrict the set of programs to those that were not problematic. If a program does not involve recursion through negation, there is no problem. When a program can be stratified [Apt et al. 1988, Van Gelder 1989] in such a way that whenever a first goal depends negatively on a second goal, the second goal is in a strictly lower stratum than the first, then we can compute the goals in order from lower strata to higher strata. For example, consider the program:

We can assign a stratum to each proposition, as, for example, t:1, r:2, s:3, q:3, and p:4. Then every proposition depends positively on other propositions at its stratum or lower, and depends negatively on propositions only at strictly lower strata. So p depends negatively on q and q is at a lower stratum than p. Propositions q and s depend on each other positively and have the same stratum. For such stratified programs, we can compute the meanings of propositions by starting with the propositions of the lowest stratum and then moving to the next higher stratum. Thus, when the negation of a proposition is needed, it has already been completely evaluated at a previous stratum. This stratum-by-stratum fixed point, which is called the perfect model of the program [Przymusinski 1988b], defines the semantics for stratified programs. A key point in this definition is how to precisely define when a goal depends on another goal. Initially the notion of predicate stratification was defined that used the static predicate call graph to determine potential goal dependencies. The introductory example, along with the rule for unrelated above, is predicate-stratified, with person, related, and advised in the first stratum and unrelated in the second stratum. However, many meaningful, useful programs were not predicate-stratified, but still did not have real recursion through negation and could be given reasonable meanings. So a second, more refined, definition of stratification, called local stratification [Przymusinski 1988a], was proposed, but the same situation occurred. Thus, dynamically stratified [Przymusinski 1989] and yet more definitions were proposed. It was generally agreed that all forms of stratification gave appropriate semantics for the programs to which they applied, but a semantics that worked for all programs with negation was desired.

Two general solutions followed: the Well-Founded Semantics [Van Gelder et al. 1991] and the Stable-Model Semantics [Gelfond and Lifschitz 1988]. There have been (many) others, but these two have had the most acceptance and influence. We will discuss them in turn. For a detailed treatment of this topic, see Chapter 2.

The Well-Founded Semantics (WFS) uses a three-valued logic, in which goals can be true, false, or undefined. The WFS can be defined by an iterated fixed point, which at each iteration computes facts that must be true and facts that must be false. When the computation converges, facts that are neither determined true nor false are undefined. In this manner, a three-valued well-founded model can be constructed for every program. If the program is stratified (for any of the forms of stratification), the well-founded model will be two valued and agree with the perfect model.

For the program

the fact teaches_db(maier) is undefined in the WFS. And for the program

all facts are undefined in the WFS. The well-founded model is polynomially computable in the size of the ground program, and has polynomial data complexity for Datalog programs. The WFS satisfies the “relevancy” property, in that the truth value of a goal depends only on goals it depends on in the goal-dependency graph. Thus, there is a goal-directed, top-down evaluation strategy for the well-founded semantics that is worst-case quadratic in the size of the ground program [Chen and Warren 1996]. We discuss the most popular such strategy in Section 1.5.

The other definition is the Stable-Model Semantics (SMS). Stable models are two-valued, and a Datalog program may have multiple stable models, or it may have none. A stable model is defined as a model that has the property that, if all negative goals in the (ground) Datalog program are interpreted as true or false according to the model and the program is then simplified accordingly, then the minimum model of the resulting positive program is that original model.

For instance, the program

has no stable models, but the program

has the following two stable models:

Finding a stable model is in general NP-hard in the size of the (ground) program. Also, there is no obvious goal-directed way to compute a stable model; the entire program may have to be processed, since an inconsistency (e.g., a rule p :- not p) anywhere in the program means the entire program has no stable model. A rule such as p :- q, not p. (where p appears nowhere else in the program) implies that q must be false in any stable model, regardless of how q might be defined elsewhere in the program.

The AI community was most interested in the SMS, which was defined by Gelfond and Lifschitz [1988], who came from theoretical AI. The general idea of assuming false what is not known to be true is known as the “closed world assumption” [Reiter 1977b]. It can be interpreted as a kind of common-sense reasoning and has close ties to nonmonotonic logic formalisms that had been studied previously in the AI community [Bobrow 1980, Brewka et al. 1997] by John McCarthy, Drew McDermott, Jon Doyle, Ray Reiter, and Robert Moore, among many others. Since many AI formalisms inherently have high complexity, the fact that SMS was NP-hard was not seen as a particular problem. Datalog under the SMS led to the exploration of some traditional AI problems, such as planning and reasoning about change and actions.

The database community was more interested in WFS, which was defined by Van Gelder et al. [1991], who were researchers in the theoretical database community. Its computational properties conformed much more to traditional database requirements. Some have constrained their interest to Datalog programs that have two-valued well-founded models, which can be considered as the strongest definition possible for stratified programs.

The logic programming community has shown interest in both definitions, but probably more in the SMS. SMS has spawned a large subcommunity that studies Answer-Set Programming (ASP) [Marek and Truszczyński 1999]. The idea is to use Datalog under SMS as a “programming language” to specify sets of propositions, i.e., those determined as true in some stable model of the program. Many combinatorial problems can be naturally specified by such Datalog programs. ASP also allows disjunction in the rule heads—an extension inspired by the earlier work on disjunctive logic programming [Minker 1994, Minker and Seipel 2002]. It is shown in Eiter et al. [1997] that this extension adds both the expressive power and complexity to the language. Much research has gone into developing efficient solvers that can find one or all of the stable models of a Datalog program. ASP is closely related to SAT solving, i.e., finding truth assignments that satisfy a set of propositional formulas. The difference is that an ASP solver will find only “minimal” satisfying truth assignments,⁸ and for this reason they may be better suited to problems where minimality is important, such as planning. Planning is often formulated as reachability in a graph whose nodes are states and whose edges are possible actions, and formulating reachability using logic rules requires minimality.

There have been proposals for integrating the desirable aspects of WFS and SMS into a single framework. Of particular interest is FO(ID) [Denecker et al. 2001, Vennekens et al. 2010] and, more recently, the founded semantics [Liu and Stoller 2018]. This line of work may eventually provide the basis for a broadly accepted integrated semantics for Datalog.

1.4.2    Arithmetic and Other Evaluable Predicates

As presented so far, Datalog is limited to symbolic computations. Database queries often need arithmetic operators and comparison, and functions on other scalar types (such as string matching and concatenation). Such functions can be viewed as predefined predicates (with large, possibly infinite, extents). For example, addition can be modeled as a three-place predicate sum(M,N,P) that contains all facts where M + N = P, such as sum(2,3,5) and sum(5,0,5). The greater-than comparison can be modeled as a predefined two-place predicate gt(M,N) containing all pairs of numbers that stand in the correct relationship, such as gt(5,1) and gt(6,3). Obviously, the extents of such predicates cannot be stored explicitly (unless the domain is small, such as for Boolean operators). Thus, such predicates are actually supported by evaluation in the underlying processor. Because of this computational realization the use of evaluable predicates is restricted in which positions must be bound before evaluation. For example, sum might require that the first two or all three arguments be bound; gt requires both arguments to be bound. The conditions for safe Datalog rules can be extended to incorporate these binding requirements. Maier and Warren [1981] give a general method of checking safety in a query by modeling binding patterns with functional dependencies.

Most logic languages provide alternative syntax for evaluable predicates. For example, the rule

can be written in Prolog as

1.4.3    Aggregation and Sets

Aggregates (such as sum, count, and average) are important operations for database query, and so should be supported in a data language such as Datalog. But just as the inclusion of recursion complicates the semantics of negation, it also complicates the semantics of aggregation. With any reasonably powerful aggregation capability, we can define negation in terms of aggregation. For example, the COUNT of solutions to a goal is 0 if and only if the goal has no solutions.

So, just as definitions that involve recursion through negation can be problematic, so can definitions that involve recursion through aggregation. There have been a number of approaches to providing a semantics of aggregation operators in Datalog.

Prolog has basically one aggregation operator, findall/3 (or variants setof/3 and bagof/3),⁹ which collects the answers to a query into a list. With this operation, the programmer can then explicitly program many other aggregation operators by iterating over that list of collected results. But that approach requires complex data structures (the list) which are excluded from basic Datalog. LDL [Tsur and Zaniolo 1986] added a set data structure to Datalog, in which a program variable could take on the value of an extensional set. Aggregates were then defined over these extensional sets in a way not unlike in Prolog. In Prolog the evaluation of some definitions would go into infinite loops; in LDL some specifications were “undefined” or “unsafe”. Fully supporting extensional sets in a logic language, including general set unification, is quite complex, and was abandoned in the move to LDL++ [Zaniolo et al. 1993]. Another approach to supporting sets, an intensional approach in which sets have names, is discussed below in Section 1.4.7 on higherorder extensions.

XSB [Swift and Warren 2011] supports aggregation by allowing the user to provide a lattice operation or a partial order relation defined in Prolog, and then applying the operator incrementally as values are added to goal tables to retain the set of minimal covering values. This capability has found interesting application in implementing conditional preference theories [Cornelio et al. 2015]. But XSB provides no formal definition of when aggregations are well defined, and the user is responsible for avoiding problematic definitions.

A first approach to ensuring the well-definedness of recursive rules that include aggregation was to require that definitions involving aggregation be stratified. In this case, the computation can proceed bottom-up from lower to higher strata in such a way that any values needed for an aggregate operator are defined at a lower stratum from the aggregate, and can therefore be completely evaluated before they are needed. Predicate stratification of a program is easily decided at compile time, but it turns out that many reasonable uses of aggregation are not predicate stratified. But local stratification is more complex and essentially requires full computation to determine whether a Datalog program is locally stratified. So efforts have been made to define efficiently recognizable classes of locally stratified programs that cover all (or most of) the meaningful aggregate definitions that involve recursion, for example LDL++ [Zaniolo et al. 1993].

Another approach is to define the meaning of aggregates for all programs using the Stable-Model Semantics or the Well-Founded Semantics [Kemp and Stuckey 1991, Pelov et al. 2007]. These approaches define powerful languages for aggregates and give them semantics under both frameworks, but some program restrictions seem necessary to ensure efficient computation of correct answers.

An interesting example of a meaningful definition using non-predicate-stratified aggregation is for shortest path. In XSB, it would be written as:

The table declaration indicates the use of the minimum lattice operation to aggregate the third argument of the sp/3 predicate with grouping on the first two arguments. When a query :- sp(X, Y, D). is invoked, computation proceeds as usual, except when a new answer, say sp(a, b, 3), is computed for the predicate sp/3, the table is checked to see if the new answer for the aggregate argument, here 3, is smaller than an existing answer, say 1 for sp(a, b, 1). If it is smaller (or if there is no previous answer for X and Y) the new answer is added (and any old one is deleted). If it is not smaller than the existing answer, the new answer is not added and computation fails.

We can understand the semantics of this program by assuming that the aggregate table declaration asserts, in this case, the axiom

and so sp(X, Y, D) is true if there is some path from X to Y of length D or less. Operationally we do not add a new answer to the table if it is implied by an existing answer. And when we add a new answer, we delete any old one implied by the new one.

We also mention here approaches to aggregation that involve introducing new structures or language constructs, such as lattices [Conway et al. 2012, Ross and Sagiv 1992], keys on results [Zaniolo 2002], and non-deterministic choice [Zaniolo and Wang 1999].

1.4.4    Existential Variables in Rule Heads: Datalog±

Datalog± [Calì et al. 2011, Gottlob et al. 2014] extends the basic Datalog by allowing existential variables in the rule heads. That is, rules can now have the form

Here, the head of the rule has existentially quantified variables (Z), while the variables X (common to the head and the body) and Y (exclusive to the body) are universally quantified outside of the rule. These latter quantifiers are omitted, following the usual convention in logic programming. Another novelty is that the head can have the form X1 = X2 (possibly quantified with ∃), meaning that the inferred instantiations for X1 and X2 must be the same constant. Here is an example:

Rules 2 and 3 here have existentials in the head and rule 8 has equality in the head. In the database theory (from which Datalog± came), the rules with head-existentials as well as the regular Datalog rules (such as rules 4–7) are called tuple-generating dependencies (TGDs), while the rules with head-equality, such as rule 8, are known as equality-generating dependencies (EGDs) [Beeri and Vardi 1981].¹⁰

What is the meaning of such rules? As with regular Datalog, we can start by deriving more facts bottom-up, as explained in Section 1.1. The first bottom-up application of the rules above would derive these facts:

The little twist here with respect to the ordinary bottom-up strategy is that rules 2 and 3 have existential variables in the head and they must be bound to completely new constants that do not appear elsewhere in the database or in the rules. In the above, we denoted these constants with o1–o4. In databases, such new constants are usually called “nulls” and in logic “Skolem constants.” We assume that each head-existential gives us a unique new constant, since there is no reason to think that any of these constants might refer to the same entity. (There are also good theoretical reasons behind this choice, of course—see, for example, the work of Calì et al. [2013] and Deutsch et al. [2008].) We will further derive that each of these new entities is a human and therefore has an unknown parent and a mother:

and so on. The resulting set of facts can (and, in this example, will) be infinite because this process will keep inventing new nulls. What happens if we use mary and bob in rules 2 and 3 again? In case of rule 2, we will derive a pair of new entities, o1’ and o2’, as the second parents for mary and bob (and then the third, the fourth, and so on). There is no reason to assume that these new constants refer to the same entities as o1 and o2. Things are different in case of rule 3, however. Here we derive entities o3’ and o4’, but then the EGD rule 8 says that o3’ should be the same as o3 (since both are mothers of mary, and EGD rule 8 says that each human has only one mother) and o4’ must be the same as o4 (for a similar reason: bob can have only one mother). As a result, o3’ and o4’ are renamed into o3 and o4, respectively, which turns the newly derived facts mother(mary, o3’) and mother(bob, o4’) into the “old” facts mother(mary, o3) and mother(bob, o4), making the new facts duplicate and redundant.

The set of facts thus computed satisfies all the rules and is known as a universal model of these rules. It has a homomorphism into any other model of these rules and all universal models are isomorphic to each other [Deutsch et al. 2008, Maier et al. 1979]. (They are the same up to a renaming of the null constants.) Query answering in a database defined by these rules and facts is taken to mean query answering in the universal model. Usually, only the answers that do not contain null values are considered meaningful.

The bottom-up process just described is known as the chase [Deutsch et al. 2008, Maier et al. 1979] because it “chases” after a database instance that satisfies the given rules. It is also sometimes called the oblivious chase, because it keeps rederiving new existentials, as in our case of the parents of mary and bob, and does not try to remember which existentials were used previously. The chase was originally proposed as a proof procedure for deriving implications of data dependencies [Maier et al. 1979], but later found other applications, including query containment and optimization [Johnson and Klug 1984] and data exchange [Deutsch et al. 2008].

There is also a restricted chase, which does not rederive existential constants such as o3’ and o4’ in the example above. The restricted chase is not guaranteed to compute the entire universal model. However, sometimes it is enough to compute a subset of that model, via the restricted chase, in order to have a decision procedure for query answering. These decidable cases are obtained via various syntactic restrictions on the appearance of variables in the rules [Calautti et al. 2015, Calì et al. 2013, Gottlob et al. 2013]. The key idea (which dates back to Johnson and Klug [1984]) is that, although the chase may be infinite, various restrictions may reduce the problem of query answering and containment over the infinite chase to a similar problem over a bounded finite prefix of that chase.

Note that although the chase, TGDs, and EGDs have been around since the late 1970s, they were used mostly for query processing and not as a language for knowledge representation. Datalog± as a language was introduced only in 2011 [Calì et al. 2011]. Decidable cases of Datalog± are implemented in a number of prototypes, such as Alaska [da Silva et al. 2012], DLV∃ [Alviano et al. 2012], and IRIS±.¹¹ A partial implementation of Datalog± is provided in the Ergo knowledge-representation and reasoning system [Coherent Knowledge LLC 2017]. It does not rely on the chase to ensure termination and does not take advantage of the aforementioned decidable cases, however. Instead, it uses a form of bounded rationality called radial restraint [Grosof and Swift 2013]. Ergo’s semantics for head-existentials is also slightly different and corresponds to the aforementioned restricted chase. In fact, the restricted chase is equivalent to replacing head-existentials with Skolem functions and, in that sense, any Datalog system that permits function symbols in the rule heads, such as XSB [Swift and Warren 2011] or LogicBlox [Aref et al. 2015], can be said to partially implement Datalog±.

1.4.5    Typing and Constraints

Most computer languages have some notion of typing or constraints (or both). In databases, these aspects both manifest in the database schema, which supports the declaration of domains (datatypes) for attributes, primary keys (uniqueness constraints) on single tables, and foreign keys (referential integrity) between pairs of tables. For example, for the tables

the database schema might declare that Univ is a character string, Year is a 4-digit number, ID is a key for person, and every PID value in the thesis table should have a matching ID value in the table person, among other things. Most programming languages will associate types with program variables—implicitly or explicitly—and use those types to determine that expressions are well formed. For instance, given that the type of variable Title is a character string, then a compiler can determine that the expression

is well formed, whereas

is not. One might say that a database schema protects data from “wrong code,” while programming-language types protect code from “wrong data.” Constraints and typing information can also improve execution times, for example, by simplifying queries or limiting the bindings that need to be considered for a given variable.

Datalog as a language has neither constraints nor types. However, we can consider integrity constraints as an alternative kind of axiom in a deductive database. So far, axioms have been interpreted as deductive rules: the EDB should be augmented so that resulting EDB plus IDB satisfies the axioms. But an axiom can also serve as an integrity constraint—it prohibits models where the axiom is not satisfied [Nicolas and Yazdanian 1977]. For example, if we want to require that the first argument of the area predicate is a unique key, we could use the axiom

This constraint applies to an EDB table, but there can be constraints on IDB predicates as well. For example, if we wanted to prohibit cycles in the advised predicate, we can define the ancestor predicate as

and then say an advisee cannot be an ancestor of his or her advisor.

To distinguish axioms that act as integrity constraints from those that act as derivation rules, the former are often written in the form of a denial [Kowalski et al. 1987], which can be viewed as a query that should have an empty answer.¹² In this denial form, our two constraints above become

Some authors put an explicit false proposition to the left of the arrow in denial form, to emphasize that satisfaction of the body should be regarded as inconsistency:

Typing information about predicates can also be represented in the same form as integrity constraints. For example, if isPersonID is a unary EDB predicate that contains all IDs of persons (viewing a type as a set of values), then we might require all participants in the ancestor predicate to be people:

or, in denial form,

Denial form for an integrity constrain suggests a direct way of enforcing it: simply execute is as a query and see if it succeeds. In that case, the constraint is violated and the answers to the query are the witnesses of that violation. However, the prospect of enforcing integrity constraints in this manner is not attractive, if it has to be done frequently (such as after each database update). It potentially involves a scan of the whole database, even if only a small part changes. That observation has led to the approaches that target constraint maintenance rather than constraint enforcement. Constraint maintenance assumes that before an update, all constraints are satisfied, so that any violations after the update must be the consequence of the values that were changed [Lloyd et al. 1987]. For example, assume the key constraint on area currently holds, and an update inserts the fact area(ss, 'Systems Science'). Then any violation of

must involve that new fact. The integrity constraint can be “reduced” [Martinenghi et al. 2006] by matching the new fact with the first subgoal, leaving

This clause is much quicker to check, especially if there is an index on area. Similarly, for the integrity constraint on ancestor, if we inserted advised(kr, jf), then we would only need to check whether

can be established or not.

There have been a range of constraint-maintenance approaches for logic languages, including forward-chaining updates to try to establish denials [Kowalski et al. 1987] and translating integrity constraints to SQL triggers on the EDB relations [Decker 1986]. Other methods are discussed in the survey by Martinenghi et al. [2006].

Constraint maintenance can still involve significant computation, especially for constraints on IDB predicates. For certain constraints, it may be possible to show statically that they must hold if other constraints are enforced. A particular situation where this approach is valuable (and generally feasible) is to show that typing constraints on IDB predicates hold if such constraints on EDB predicates are enforced. For example, for the typing constraint

on the EDB relation advised can be used to establish the typing constraint

essentially by proving a theorem on the IDB predicate ancestor. Richer type systems, including features such as subtyping and mutual exclusion, can also be statically checked [Reiter 1981]. However, there is a trade-off between the speed of checking and the completeness of the method [Zook et al. 2009]. There are other classes of constraints where the consistency of the IDB can be proved from the consistency of the EDB. For example, Wang and Yuan [1992] give a method for handling downward closed constraints—constraints that are preserved if tuples are removed from a predicate, such as functional dependencies.

Typing and constraints, as noted, can help prevent data corruption and programming errors, but they can also improve performance. In terms of low-level implementation, knowing the type of an argument, such as Integer, permits a specialized representation, and avoids checks for handling other possibilities. At a higher level, there is a long history of using constraints for semantic query optimization: rewriting queries into simpler or more efficient forms, based on constraints that hold. For example, Chakravarthy et al. [1990] introduce a method of residues that can variously remove redundant literals from a query or include additional ones that are more restrictive. Residues are produced by matching parts of an integrity constraint to subgoals in a rule. The unmatched part of the constraint (the residue) is attached to the rule and used during query evaluation. For example, consider the following rule for possible dissertation committee chairs for a student:

which says the possible chairs for a student are the tenured professors appointed in the department where the student is enrolled. If there is an integrity constraint

that says an adjunct professor cannot be tenured, then the residue of the constraint relative to the rule is

This residue could be used to simplify the query

by removing the second literal (if there is only one rule for possibleChair). Lee and Han [1988] adapted the residue method to handle recursive queries, and Lakshmanan and Missaoui [1992] focused on semantic query optimization for inclusion and context dependencies. (A context dependency is an extension of an inclusion dependency that involves algebraic expressions and not just individual relations.) Sagiv [1987] incorporates tuple-generating dependencies (such as multi-valued and join dependencies) into testing containment of Datalog programs, which thereby extends the earlier methods for query optimization [Johnson and Klug 1984]. (See Section 1.5.5 for the role of containment in optimization.) Levy and Sagiv [1995] look at optimizing recursive programs, using integrity constraints to avoid rule applications that will necessarily have empty results, as well as augmenting rules with additional restrictions.

1.4.6    Object-Oriented Logic Programming

Extending Datalog and Logic Programming in general with object-oriented features has been an active area in database and logic programming research since the late 1980s, and the most influential systems were developed in the 1990s and 2000s. Two main approaches can be identified among the variety of works on this subject.

The first can be called object-oriented Prolog or OOP. That approach takes Prolog, with its procedural semantics and extra-logical predicates, and adds the syntactic constructs to represent objects, classes, and so forth. The main idea is support for object-oriented programming in Prolog, rather than to develop new logical theories for a combination of these two paradigms. Prolog++ [Moss 1994] and SICStus [Carlsson et al. 2015] took this approach in the 1990s and more recently Jinni [Tarau 2004] and Logtalk [Moura 2000, Moura et al. 2008] did so. Logtalk is by far the best known and best developed approach and system in the OOP stream of work.

In contrast, the object-logic approach, or OLOG, aims to extend the very logical foundations of logic programming to incorporate the notions of complex objects and classes not only at the level of syntax but also to make them first-class citizens in the semantics of the logic. A great number of approaches to OLOG have been proposed [Abiteboul and Grumbach 1987, Abiteboul and Kanellakis 1989, Aït-Kaci and Nasr 1986, Aït-Kaci and Podelski 1993, Beeri et al. 1991, Beeri et al. 1988, Chen and Warren 1989, Heuer and Sander 1989, Kifer and Wu 1989, Maier 1986a, McCabe 1992], where F-logic [Kifer and Lausen 1989, Kifer et al. 1995] is the best known and most developed—both in terms of theory and systems.

In OOP systems, an object is typically a container for data (facts) and rules. Some of the predicates may be exported to the outside world and can be invoked by other objects. Here is an example from Logtalk’s manual, which illustrates the idea.

The snippet above defines two classes, bird and penguin, where the latter is a subclass of the former. Bird exports the mode-predicate, which represents the modalities of birds’ movements. In general, this class would have many more predicates to represent the various properties of birds, but here we ignore those for the sake of clarity. The second class, penguin, modifies the transportation modalities for penguins by adding the mode swims, inheriting the mode walks, and blocking the inheritance of flies. The latter is achieved via the construct ^^mode(…), which calls the predicate mode in the immediate superclass of penguin (i.e., bird in our case).

In contrast to OOP approaches, OLOG approaches build on the idea of a complex object, which is mainly influenced by database practice. The theory of complex objects underwent rapid development in the 1980s, starting with the idea of Non-First-Normal-Form and Nested Relation data models and ending with a general and elegant data model for complex objects [Abiteboul and Beeri 1995, Bancilhon and Khoshafian 1989, Beeri 1989]. RDF [Lassila and Swick 1999] and JSON¹³ are largely reinventions of this earlier work and of the subsequent work on semi-structured data [Abiteboul et al. 2000]. Extending these theories to include logic rules proved harder, however, and some doubted that this goal was even possible given that object-oriented systems are inherently “pointer-based” and therefore non-logical [Ullman 1987].

One of the first important developments was the LOGIN language by Aït-Kaci and Nasr [1986]—later extended to LIFE [Aït-Kaci and Podelski 1993]—which included elements of functional programming. LOGIN gave the basic idea of how a simple logical syntax for logic object-oriented databases could be constructed, but both LOGIN and LIFE were largely constraint languages with semantics that was at odds with database query languages. This limitation led Maier [1986a] to propose elements of a semantics that was “right for databases,” and this semantics, in turn, inspired the work on O-logic by Kifer and Wu [1989], Kifer and Wu [1993]—the first coherent exposition of an OLOG approach that was completely logical and fully compatible with the logical foundations of both databases and logic programming. F-logic, which culminated this line of work, was developed shortly thereafter [Kifer and Lausen 1989, Kifer et al. 1995].

The first F-logic system was FLORID [Frohn et al. 1998], but it is no longer being maintained. The open-source Flora-2 system [Kifer 2015, Yang et al. 2003] is both well maintained and has a community of users. There also are two commercial versions: Ontobroker from Semafora, GmbH [1999] and Ergo from [Coherent Knowledge LLC 2017]. The latter is based on Flora-2, but includes many additional language constructs, connectivity to the outside world, optimizations, a development environment, and knowledge-acquisition tools.

The basic language constructs in F-logic are the subclass and membership relations as well as the frame representation (whence the “F” in F-logic). For instance, bird123:Penguin means that an object with the particular Id bird123 belongs to class Penguin. The statement Penguin::Bird means that the class Penguin is a subclass of the class Bird and Bird is a superclass of Penguin. (F-logic-based systems treat upper-case symbols just like the lower-case ones—as constants; variables are prefixed with the “?” sign instead.) Frames¹⁴ specify properties of objects, as in

This example extends the earlier one used to illustrate Logtalk, using Flora-2 syntax rather than the original F-logic syntax [Kifer et al. 1995].

The Bird[|…|] construct (and the like) is a frame that represents the default values attached to classes and inherited by subclasses and the members of the classes. (The symbol -> means “has value” and [|…|] means the value is a default one. Thus, the first statement above means that, in any object in class Bird, the default value for the attributes limb(wing) and limb(leg) is 2 and the default values for mode are flies and walks.) These default values can be overwritten. In terms of Java, these properties correspond to instance methods. Thus, the first statement above says that normally birds have two legs and wings, and their modalities of movement are flying and walking. Note that limb is a parameterized property, which can be thought of as a method that takes arguments. We already discussed the second statement, which says that penguins are birds, and the third statement explicitly says that penguins swim. This explicit statement overrides the inheritance of the movement modality from Bird. However, we do not want to completely discard the information about birds’ movement modalities—we just want to drop the flying modality. The fourth rule does so, stating that, in addition to swimming, any movement mode of a bird—except flying—is also a valid modality for a penguin.

The fifth statement is another frame: one that provides information about a particular bird with object ID bird123. First, it says that this object is a penguin. In addition, it says that this bird is (apparently a pet) named “Tweety”, and it is a one-legged creature. To indicate this situation, we use the bird123[…] construct, which provides information about a particular object instance, rather than default information about all objects in a class.¹⁵ Tweety will inherit some of the information from Bird, some from Penguin, and some of that information will be overridden. Specifically, the mode information for birds will be overridden by the more specific Penguin information, so bird123 will get the modalities of walking and swimming, but not flying. Tweety will also inherit the property of being biwinged, but the property of having two legs is overridden by the explicit statement that this bird has only one leg.

There is more to the story, however. The last rule brings in an aspect of defeasibility, which is much more flexible and powerful than inheritance overriding. It says that birds with fewer than two legs do not walk. Thus there will be two contradictory inferred facts: that Tweety both walks and does not, and the result is that each of these facts defeats the other, so none of these conflicting derived facts will hold. We refer the reader to Wan et al. [2009] and the Flora-2 manual for the details of the logical semantics for defeasible reasoning in that system.

In conclusion, we note that Flora-2 and Ergo go well beyond F-logic. Besides defeasibility, they support other important aspects of Datalog discussed in this chapter, including HiLog (Section 1.4.7), Transaction Logic (Section 1.4.8), modularity, some aspects of functional programming, and more. We should also mention that F-logic frames are closely related to semi-structured data [Abiteboul et al. 2000]. This relationship was gainfully employed in FLORID [Frohn et al. 1998], which uses F-logic to query semi-structured data, and WebLog [Lakshmanan et al. 1996], which uses an F-logic-like language for querying Web data.

1.4.7    Higher-Order Extensions

Since the early days of Prolog, users felt constrained by the inability to query the meta-structure of logic programs. Since Datalog is a subset of Prolog, it inherits this limitation. For instance, we have already defined several binary predicates, such as advised, adjacent, and related. How can one find out in which relationships lvk and ks stand to each other? We could ask series of queries

This approach is hardly satisfactory: If additional relations are defined later on, more queries need to be added. It would be nice if we could just ask a single query

(R being a variable) and get an answer related(lvk, ks) (that is, R = related). One of the first logic programmers to pay attention to this issue was D. H. D. Warren [1982a], who proposed a programming style (or, one can say, an encoding scheme) that allows treating predicates as first-class objects. The idea is, roughly, to introduce a new predicate, say binary_property/3, and then represent information about the aforesaid predicates as

In this approach, we still cannot ask ?– R(lvk, ks), but we can write instead:

which, although awkward, does the job. This approach is essentially an adaptation of the well-known technique from formal AI, which prescribes a single predicate, true (or holds) and “downgrades” predicates to the level of data (for example, true(advised(X,Y)) or, closer to Warren’s style, true(advised,X,Y)).

The problem of awkwardness and other limitations of Warren’s proposal are overcome by HiLog [Chen et al. 1989b, Chen et al. 1989a, Chen et al. 1993], which is a full-blown logic that admits variables over predicates, function symbols and more. While HiLog has a higher-order syntax, its semantics is first-order. As a result, it provides a convenient higher-order syntax and yet computationally it is not more expensive than Prolog.

For instance, the aforesaid query ?– R(lvk, ks), which has a variable in the predicate position, is syntactically correct and has the expected semantics. More interestingly, HiLog supports parameterized predicates, which can significantly simplify working with Datalog and make rules more generic. To understand this idea, suppose we have various binary relations, such as parent, edge, and direct_flight. In all of these cases, transitive closure creates a new, meaningful, and commonly used concept. For instance, by closing parent transitively, we get the concept of an ancestor—also a binary relation. Similarly, the transitive closure of edge gives us the concept of a path in a graph; the transitive closure of direct_flight is also a meaningful concept—the ability to travel between cities by air with stops in-between. In Datalog and in Prolog, one would have to write three different rule sets to define these different closures. Here is one such a set for parent:

For edge, the rules would be similar except that the names of the predicates would change. To make such rules generic, it is not enough to just put variables in place of the predicates: one also needs to be able to construct new names for relations because if parent were replaced by edge, then ancestor would need to be changed to some other name that depends on the underlying predicate. Here is a solution to the problem in HiLog:

Here Pred is a variable that can be bound to parent, edge, or direct_flight. If, say, Pred is bound to direct_flight, then the rules above define the relation closure(direct_flight). If Pred is bound to edge then these rules define closure(edge). Details can be found in Chen et al. [1993].

HiLog is available in a number of systems. First, it is supported in XSB, but its usability there is limited because it is not integrated with XSB’s module system. HiLog is fully supported by and is extensively used in the Flora-2 system [Kifer 2015, Yang et al. 2003] and in its commercial cousin, the Ergo reasoner [Coherent Knowledge LLC 2017].

We mention another important extension in this area, Lambda Prolog [Miller and Nadathur 1986]. Like HiLog, Lambda Prolog supports second-order syntax. However, unlike HiLog, it is semantically a second-order logic. As a result, Lambda Prolog has a much greater expressive power than HiLog, but it is also more expensive computationally.

1.4.8    Datalog and Updates

The need to endow logic-based declarative languages with an ability to change the state of the underlying database has been recognized early on, and both Prolog and SQL—the two earliest and most prominent such languages—have the facilities to do so. The trouble is that neither facility was wholly satisfactory. In Prolog, database updates are performed via assert and retract, “predicates” with side effects. In SQL one uses INSERT, DELETE, and UPDATE statements. We put the term “predicates” inside the quotes because neither assert nor retract are predicates in that they do not state or test any kind of a truth-valued statement. Instead, they perform extra-logical operations of inserting or deleting information, and their semantics can be explained only procedurally and non-logically, hence not declaratively. In SQL, the situation is similar, but, realizing the theoretical difficulty of integrating update operators into a declarative language, the designers relegated these operators to a separate sublanguage. Then, to put everything together, they came up with a host of less than ideally designed procedural languages for so-called stored procedures, completely abandoning any pretense of declarativeness.

This state of affairs has been deemed unsatisfactory by a long list of researchers and practitioners leading to an equally long list of proposed fixes. Few have gained traction, however. Bonner and Kifer give a comprehensive survey of many of these proposals [Bonner and Kifer 1998a]. In this section, we review some of the approaches from that earlier survey and also cover some newer proposals. In addition, we will try to classify the different approaches along several dimensions.

The approaches to updates in logic languages can be roughly classified into two broad categories: explicit state identifiers and destructive updates. The latter are further subdivided into updates in the rule heads and updates in the rule bodies. There are also approaches based on other logics, such as dynamic logic [Harel 1979] and process logic [Harel et al. 1982], which we do not cover here, but they are covered in the survey cited above.

What features should one expect or want from integrating an update capability into a logic language, beyond the basic modification of data? The following desiderata are the most important features, in our view, and they will serve as additional classification dimensions for the different proposals.

1.  Declarative semantics. This requirement roughly means that one would like the integration to be as smooth as possible and be declarative. Prolog and SQL clearly fail soundly on this score.

2.  Subroutines, compositionality. Every programming language worth its salt has subroutines, and programming without them is pretty much unthinkable these days. Prolog and SQL let the user define derived predicates (or views, as they are known in SQL), which act much like subroutines in procedural languages. These derived predicates can be further combined into more complex predicates—similarly to other programming languages. When it comes to updates, however, some approaches falter on this score. For instance, Prolog supports subroutines that perform updates, but SQL views cannot.

3.  Reactive rules. A reactive system is one that can execute certain actions in response to internal or external events. This capability is related to our topic because these events can be viewed as updates and reactivity has been identified as an important paradigm in building large systems. Reactive rules, which usually come in the form of event-condition-action rules (or ECA rules), are a natural adaptation of this paradigm to declarative languages. In SQL, for example, this idea is realized through triggers. Prolog, on the other hand, does not have explicit support for this paradigm, but it can be simulated.

4.  Reasoning about actions. If a robot picks up a block from the top of another block, will the top of that other block become clear in the next state? It seems like an obvious question, but can this statement be proven within the same logical language that is being used to specify the states of such a “blocks world” and the actions of a robot in it? Most of the approaches surveyed here do not support such reasoning.

We will now briefly survey the three aforementioned categories of approaches to updates and discuss them vis-à-vis the above desiderata.

1.4.8.1    Approaches Based on Explicit State Identifiers

The oldest and best-known approach in this category is the situation calculus [McCarthy and Hayes 1969], which is still widely used for reasoning about actions, albeit not in Datalog or other logic-programming languages.

The idea is to use one designated argument of each state-dependent predicate to hold a state identifier. For instance, if the initial state is denoted s₀ then the state obtained by picking up block a in state s₀ and then putting that block down on top of block b would be represented as do(putdown(a, b), do(pickup(a), s₀)). Thus, the state identifier reflects the history of actions that brought about that state. The effects of the various actions are specified via logical formulas. For instance, in the following example, the designated state argument is the last one:

This formula says that if in state S block a is on some block X and it is possible to execute the action of picking up a, then in the new state, denoted do(pickup(a), S), block X would be clear and the robot would be holding block a.

One of the issues with situation calculus and the other approaches that rely on state identifiers is the frame problem. To understand the issue, consider the example above. The rule that specifies the effects of the pickup action deals with the direct effects of that action, but it says nothing about what did not change. Indeed, suppose that in state s₀ we had on(d, e, s₀). Intuitively, picking up block a should not affect the fact that block d is sitting on top of block e, so we would expect that on(d, e, do(pickup(a), s₀)) is true. However, there is no way to derive this fact given the rules above. The missing piece of the puzzle can be provided using frame axioms, which state that the facts that are not directly affected by an action remain true in the state resulting from that action.

There are two problems with frame axioms. The first is that the number of such axioms can be large. The original solution [Green 1969] required a quadratic number of frame axioms (predicates × actions). A more feasible solution, which required only one frame axiom, was presented by Kowalski and Sergot [1986]. It was well received by database and logic programming communities, but not by some AI researchers because that solution relied on the closed-world assumption, which goes beyond first-order logic. A purely first-order logic solution, requiring a linear number of frame axioms, was later proposed by Reiter [1991]. The other problem with frame axioms is that, as the system evolves, inference can slow down significantly. For instance, after 10,000 actions, finding out what is true in the current state might require a 10,000-element chain of inferences via the frame axioms.

With respect to the desiderata stated earlier, situation calculus scores well on the first and the fourth criteria (declarativeness and reasoning), but it does not do well when it comes to the second and third criteria. Among the other approaches that rely on state identifiers [Chomicki 1990, Kowalski and Sergot 1986, Lausen and Ludäscher 1995, Zaniolo 1993], the event calculus [Kowalski and Sergot 1986] is the best-known one. Unlike the situation calculus, these approaches use time (continuous or discrete) as a state identifier and they rely on the closed-world assumption to specify the frame axioms, which greatly reduces the number of such axioms. Apart from that, they suffer from some of the same limitations as the situation calculus but score well on the first and the fourth desiderata. Here is an example expressed in the event calculus:

The first rule here says that an event of picking up a block initiates the states in which the robot holds that block. The second rule says that an event of putting down a block terminates such state sequences. The third rule does not depend on the domain of discourse. It says that a fact holds at a certain time if that fact was initiated at some prior time and was not terminated between the initiation time and the time under consideration.

1.4.8.2    Destructive Updates in Rule Heads

The most prominent representatives of this category of systems are SQL triggers [Zaniolo et al. 1997] and production-rule (or business-rule) systems [Agrawal et al. 1991, de Sainte Marie et al. 2013, Snyder and Schmolze 1996], which are based on the event-condition-action paradigm. An event-condition-action rule (ECA rule) is a statement of the form

which means that if an event E occurs (usually some kind of a database state change) and if precondition C of the rule is satisfied, then perform action A. This action corresponds to what one would call a “rule head” in logic. An action can be complex and affect many database objects, such as “increase the salary of all administrators by 5%.” Much more needs to be said in order to make this statement precise, however.

1.  Several ECA rules may find their preconditions satisfied after the event E. Should only one of these rules fire (that is, has its action executed) or all?

(a)  If one, then which one?

(b)  If all, then sequentially (in which order, if so?) or all at once?

(c)  If sequentially, should the condition C be retested after each rule firing? (Firing of a rule may mean the preconditions of some other rules may no longer be satisfied, while other, previously ineligible, rules might suddenly find that their preconditions are now satisfied.)

2.  If a rule fires and the database gets updated as a result, can this update event trigger execution of other ECA rules?

3.  If an event involves several updates to the database, should ECA rules attempt to fire right after each update or they must wait until all the updates associated with the event are committed?

4.  Can rule firing continue indefinitely? How does one ensure termination?

In addition to database triggers and production rules, many other approaches were developed [Abiteboul and Vianu 1990, Alferes et al. 2002, Kowalski and Sadri 2012]. The differences among them essentially boils down to the answers to the questions above and to the details of the preconditions and actions, such as can an action change multiple database objects? For example, how does one ensure that the same employee has his salary changed at most once and not repeatedly?

With respect to our classification dimensions discussed at the beginning of this section, updates in rule heads are good for representing reactive systems (desideratum 3) but hardly anything else.¹⁶ Their semantics is usually described as a series of applications of various state-changing operators, which often gets quite involved (depending on the choices made in deciding which ECA rules fire, when, and so forth), and they can hardly be regarded as declarative.

1.4.8.3    Destructive Updates in Rule Bodies

Prolog introduces updates via the assert and retract pseudo-predicates in rule bodies and the heads of those rules can be naturally viewed as subroutine calls. Invocation of these subroutines can result in side effects (such as updating the database) and these subroutines can be combined into bigger and bigger subroutines. Thus, Prolog fulfills the subroutining and compositionality requirement (desideratum 2). Despite the fact that it does not fulfill any other desiderata, there is a sense in which one can say that—by-and-large—Prolog got it right, and with the right semantics all the pieces would fall in place. That “right” semantics comes in the form of Transaction Logic [Bonner and Kifer 1993, Bonner and Kifer 1994], described shortly, but first we need to explain what is wrong with Prolog’s approach. To this end, consider the following Prolog program, which purports to color graph nodes so that no pair of adjacent nodes has the same color:

At first look, everything seems fine: we pick a node that has not been colored yet and assign it a color that is different from that of all adjacent nodes. This process continues until everything gets colored. Problems start when, after a series of color assignments, the condition not (adjacent(N, N2), colored(N2, C)) cannot be satisfied by any color C for some still uncolored node N2. In this situation, colorNode fails and so does colorGraph, leading to two problems. One is that the graph remains partially colored (due to earlier, successful coloring steps), and this partial coloring cannot be extended to full coloring. The result is that the database is left in a “garbage” state. Second, there may be a way to color the graph, if the program picked the colors in a different order, but if this right order is not chosen the first time, then the program above would neither find a correct order nor leave the database in a coherent state.

The problem with the example above is that the predicate assert in Prolog has no logical semantics—only a procedural one, and this semantics is hard to rely on. Even though superficially it might seem that Prolog subroutines are compositional, it is not so if updates are involved: two subroutines may be working correctly by themselves but not in combination. For instance,

By itself, the transaction above will always work correctly and will never leave us in an incoherent state. However, combining this transaction with itself to make two transfers:

may run into problems, if Acct1 has balance less than $300. Indeed, the first transfer may come through correctly, but the second will fail due to the check Bal1 > Amt in the second transfer. If the two transfers were supposed to be done together (e.g., the seller and the broker must both be paid) then we are left in an incoherent state.

A popular solution to “fixing” Prolog’s update operators is provided by Transaction Logic [Bonner and Kifer 1993, Bonner and Kifer 1994]. The intuitive idea is to require that all subroutines must be transactional (whence “Transaction Logic”). This qualification means that colorGraph and the double-transfer above must be treated as transactions, and one of the key aspects of a transaction is its atomicity. Atomicity refers to the property that a transaction either executes in its entirety or not at all. If a successful execution exists then the updates performed during the transaction execution are committed and become visible. If a successful execution is not possible, all the intermediate updates are undone and the database is left in the original state—as if nothing happened at all. In case of the double-transfer above, if Bal1 is greater than $300 then the transaction succeeds and the amounts are transferred out of Acct1. Otherwise, the first or the second transfers will fail and the partial changes made to the database are undone. In case of graph coloring, the program will keep searching for a correct assignment of colors. If, at some point, the condition not (adjacent(N, N2), colored(N2, C)) cannot be satisfied, some previous color assignments will be undone and other assignments will be tried until either a correct assignment is found or all assignments have been tried and rejected. Practically, this trial-and-error is implemented through backtracking and so such transactional updates are sometimes called backtrackable.

In brief, Transaction Logic extends the classical logic with one new connective, the serial conjunction, denoted ⊗. Further extensions (such as concurrency, hypothetical updates, defeasible updates) introduced additional connectives [Bonner and Kifer 1995, Bonner and Kifer 1996, Fodor and Kifer 2011]. The Transaction Logic version of the graph-coloring example above thus looks very similarly to Prolog:

where tinsert is a transactional insert operator. The main difference with Prolog is, of course, the transactional semantics of the program above, which is defined by extending the standard model theory of first-order logic. Details can be found in Bonner and Kifer [1993, 1994, 1995].

In summary, the original Transaction Logic takes care of the first two desiderata on our list. A follow-up work [Bonner et al. 1993] showed that this logic is good at modeling reactive systems (specifically, event-condition-action rules), thereby fulfilling desideratum 3. The use of this logic for reasoning about actions (desideratum 4) was discussed in Bonner and Kifer [1998b] and further significant developments in this direction appeared in Rezk and Kifer [2012]. Transaction Logic also has applications to planning and Web services [Basseda and Kifer 2015b, Basseda and Kifer 2015a, Basseda et al. 2014, Roman and Kifer 2007]. Parts of this logic have been implemented in the Flora-2 system [Kifer 2015, Yang et al. 2003] and a standalone interpreter is available.¹⁷

Finally, we mention the approach in the updates-in-rule-body category used in LDL—one of the earliest Datalog systems [Naqvi and Krishnamurthy 1988, Naqvi and Tsur 1989]. Due to the problems with the non-declarative nature of Prolog’s update operators, this system restricts the syntactic forms of the rules in which update operators can appear. Although this requirement makes it possible to give a logical semantics to such rules, the restrictions themselves are severe. For instance, they prohibit recursion through updates as well as most post-conditions, which excludes both the graph-coloring and the double-transfer examples discussed earlier.

1.5    Evaluation Techniques

The intended uses of Datalog required rethinking the evaluation mechanisms used for Prolog and other logic-based question-answering systems. Because of the use of definite clauses, Prolog was able to base its query evaluation mechanism on SLD resolution, using depth-first search over the SLD tree based on the rules and facts. We illustrate this top-down approach later. While Prolog-style top-down evaluation worked reasonably for many cases, particularly those where the rules and facts fit in main memory, there were several considerations that dictated developing new techniques for Datalog.

All derivations vs. all answers. Prolog and other logic programming approaches generally focused on finding a solution to a problem or deciding the truth of a statement. (Are X and Y related?) Top-down approaches can be efficient in such cases, because the sequence of rule applications is directed by the current goal, where bottom-up approaches can derive a lot of extraneous facts that are not connected to the goal. Datalog was targeting database settings, where a collection of answers is expected. (Who are all the people related to Y?) While Prolog-style top-down evaluation can generate multiple answers by backtracking to choice points, this process may be inefficient, because there can be more than one way to derive the same answer. (In deductive terms: there can be more than one proof for some facts.) For example, if persons A and B are related because of a common ancestor C, then their relatedness can also be deduced from any ancestor D of C. Moreover, with some rule sets, there can be more than one way to derive relatedness using C. If the number of derivations greatly exceeds the number of facts, Prologlike approaches can be inefficient for finding all answers. Datalog techniques tried to avoid multiple derivations, for example, by remembering previously derived facts, and avoiding re-deriving them (in top-down approaches) or excluding them when trying to derive new facts (in bottom-up approaches).

Recursion. A key advantage of Datalog over other relational languages, like SQL, was the natural expression of recursion in queries. The top-down, leftto-right evaluation style of Prolog can behave differently depending on how rules are written. Some rules can cause infinite regress in trying to prove a goal. For example, if the first rule for related were

Prolog evaluation would keep solving the first goal with a recursive application of the same rule, and never actually encounter rules or facts for the advised predicate. Even when rule sets are better constructed, there can still be an unbounded number of search paths even when there are only finitely many answers. In fact, if the SLD tree is infinite and all answers are desired, no complete search strategy will terminate. Here the bottom-up approaches have a decided advantage, as termination is guaranteed if the set of answers is finite (though bottom up can re-derive facts).

Large fact bases. Prolog implementations largely assumed that rules and facts all fit in memory. However, this assumption was questionable for applications of Datalog to large datasets. If virtual memory is required for the fact base, then accessing facts turns into disk accesses. Different binding patterns for goals lead to different orders of access, hence not all disk accesses will be clustered, leading to random reads on disk. If there is alternative storage for facts (in the file system or a database), then there can be costs associated with moving facts into internal memory structures—such as the parsing associated with the Prolog assert command. For efficient access to large fact bases on disk, data needs to be read in chunks, and manipulated in its format on disk.

A great deal of the early work on Datalog (and deductive databases more generally) centered on alternative evaluation mechanisms. These approaches generally started either from basic bottom-up (BU) or top-down (TD) evaluation. The bottomup methods tried to avoid re-deriving established facts, and providing more direction as to which facts to derive. Top-down methods tried to access facts in groups (rather than one at a time), rearrange the order of sub-goals, generate database queries to solve goal lists, and memoize derived facts to break recursive cycles. Theoretical proposals for alternative evaluation methods proliferated, with further and further refinements. However, side-by-side comparisons of actual implementations of these approaches were not common (although there was some comparative analysis of methods [Bancilhon and Ramakrishnan 1986]). The potential for scaling and performance of logic languages was promoted, such as via parallel evaluation in the Japanese Fifth-Generation Project [Moto-oka and Stone 1984] or using database techniques such as indexing and query optimization.

1.5.1    Bottom-Up Methods

In Section 1.1, we described the bottom-up evaluation of a Datalog program P at the level of single instantiations of rules to generate new facts. This derivation process is commonly organized into “rounds,” where in one round we consider all satisfied instances of all rules. A round can be viewed as a transformation TP, called the immediate consequence operator, that takes a set of established facts F and produces a set G of newly established facts [Van Emden and Kowalski 1976]. If we let F₀ represent the initial EDB facts, then bottom-up evaluation can be seen as producing a sequence of fact-sets F₀, F₁, F₂, … where

For a Datalog program, we eventually reach a fixed point Fj where Fj = Fj−1 (that is, a point at which no new facts can be established using rules in program P). Call this fixpoint F*. At this point, a query over the virtual database embodied by P can be answered. This iterative application of TP is called the naïve approach to bottom-up evaluation. There are two big problems with the naïve approach: repeated derivation and irrelevant results, which give rise to more sophisticated evaluation strategies.

Repeated Derivation. Note that Fi ⊇ F by construction. For a standard Datalog program P, TP is monotone in the sense that adding more facts to the input cannot reduce the number of facts in the output. Thus TP(Fi) ⊇ TP(Fi−1). So each round in the naïve approach re-establishes all the facts from the previous round, which is wasted work. The semi-naïve approach addresses this problem by only using rule instances in a round that have not been tried in previous rounds. It does so by determining which are the new facts generated in a round, then making sure any rule instance used in the next round contains at least one of the new facts. Thus, semi-naïve determines the newly established facts at round i as

and restricts TP to only generate facts if a rule instance uses at least one fact from Di. Rather than examining rule instances on a one-by-one basis, semi-naïve constructs an alternative rule set Q using a version rN and rO of each predicate r, where rN contains the “new” r-facts from Di and rO the “old” facts from Fi−1. So, for example, the rule

in program P would be replaced by three rules in program Q:

where rN and rO are computed by the system at each iteration anew. Note that the semi-naïve approach does not completely avoid repeated derivation of facts, since distinct rule instances can establish the same facts independently. For example, the rule instances

both establish r(a, b).

A systematic method based on incrementalization [Liu and Stoller 2009] has been developed to ensure that each combination of facts that makes two subgoals of a rule true simultaneously is considered at most once, and furthermore to provide precise time and space complexity guarantees. The method compiles a set of Datalog rules into a stand-alone imperative program. The generated program does a minimum addition of one fact at a time, incrementally maintains the results of expensive computations after each addition, and uses a combination of indexed and linked data structures to ensure that each firing of a rule takes worst-case constant time in the size of the data.

Irrelevant Derivation. The variants of bottom-up we have described so far generate the entire virtual database before turning to determining which results match the goal. Some facts that are non-goal results are nevertheless needed in order to establish facts that are goal-facts. But there can be facts in the virtual database that neither match the goal nor are required to derive the goal facts. For example, suppose the related predicate had only the first two rules:

and the goal is related(P, ks). Then any derived fact related(a, b) where b ≠ ks will not be in the result, nor will it be useful in deriving goal facts. Aho and Ullman [1979] point out that in certain cases optimizations used for relational databases are applicable. For example, we can use “selection push-down” to move the restriction that P2 = ks into the rule bodies to get

Note that this strategy works because the bound value stays in the same position. However, if our goal were related(ks, P), the binding in the goal does not directly restrict the binding in the rule body. Notice, however, that the bindings for the recursive call to related(B, P2) in the second rule are not totally unrestricted. If we think about the top-down evaluation of this rule, we see that the only useful facts for related(B, P2) are those where B is an ancestor of ks. In the genealogy database, the set of ancestors of a single person is likely a much smaller set than the set of all known people in the EDB. Thus, for example, if we computed

initially, to find all the ancestors of ks, we could modify the second rule to be

With bottom-up evaluation, this rule would only establish facts where B is an ancestor of ks, effectively eliminating the derivation of many of the irrelevant facts. This idea of deriving an auxiliary predicate that mimics the propagation of topdown bindings (but which can be evaluated bottom up) is the basis of the Magic Sets approach [Bancilhon et al. 1986]. Magic Sets tries to avoid derivation of irrelevant facts by limiting bindings based on constants in the final goal. It might be seen as top-down direction of bottom-up evaluation. The full Magic Sets method is more complicated than the example above, as it has to track binding propagation through all the rules of a program, and different occurrences of the same predicate in a program may be constrained differently. In the worst case, this variation may lead to an exponential blow-up in the number of intermediate rules that Magic Sets might generate in order to track all such bindings.

Optimization of the bottom-up evaluation with respect to the goal has been studied extensively—both as generalizations of selection push-down and as variants of the Magic Sets ideas discussed above. Selection push-down is a specific instance of the general idea of propagating constants in the queries or in the rules so that only the relevant facts are derived, if possible. This strategy is analogous to partial evaluation in the programming languages literature [Jones et al. 1993]. Other evaluation methods include static filtering [Kifer and Lozinskii 1990] and dynamic filtering [Kifer and Lozinskii 1987, Kifer and Lozinskii 1988], which limit the facts being processed during evaluation, as well as rewrite methods such as specialization [Tekle et al. 2008], which rewrites the program to achieve the same effect given any evaluation strategy.

As briefly described above, Magic Sets [Bancilhon et al. 1986] limits inference during bottom-up evaluation by introducing magic predicates that infer a relevant subset of values for arguments of predicates by using the binding of variables in other goals in a rule, an example of sideways information passing. In the years following the initial work on Magic Sets, many variants have been developed including supplementary Magic Sets [Saccà and Zaniolo 1986b], which saves space and time by introducing intermediate predicates that can be reused, generalized counting [Beeri and Ramakrishnan 1991, Saccà and Zaniolo 1986a], which optimizes rules by keeping track of which rules were used to infer a particular fact, and Magic Templates [Ramakrishnan 1991], which generalize to Horn clauses with function symbols. Beeri and Ramakrishnan [1991] provide a formal discussion of these methods.

One serious problem with Magic Sets and its derivatives is that the same fact may be manifested an exponential number of times in several variants of the same predicate, since Magic Sets introduces a new copy of each original predicate for every possible binding pattern for the arguments of that original predicate. For example, consider the reachability rules from Section 1.4.1 and a query with both arguments bound (such as reachable(a, b)). Magic Sets would produce the following rules and a fact, where reachable_bb is a copy of reachable created for the calls where both arguments are bound, and reachable_bf is a copy for the calls where the first argument is bound and the is second free, and so forth.

It can be seen that the same reachability fact may be associated with both reachable_bf and reachable_bb. In general, one predicate may get blown up into as many as 2k variants, where k is the number of arguments of the predicate (for different sequences of b’s and f’s), and so the same fact may be represented an exponential number of times. In addition, note that this method can generate spurious rules that infer no facts, such as the second-to-last rule. This situation arises from hypotheses that generate no “new” magic facts, analogous to the generation of a subquery that is isomorphically equivalent to the head of a rule in top-down evaluation.

More recently, a novel method, called demand transformation [Tekle and Liu 2010], has been introduced, which solves the problem of propagating top-down bindings cleanly, including avoiding the problem above and in other Magic Sets variants.

Demand transformation avoids the blow-up by storing facts for the same predicate together, and using an incremental evaluation strategy with carefully selected data structures to ensure that each firing of a rule takes constant time [Liu and Stoller 2009]. It has also been shown that bottom-up evaluation of rules generated by demand transformation has the same time complexity as the top-down evaluation with variant tabling as implemented in various systems, including XSB [Swift and Warren 2011] and YAP [Costa et al. 2012]. Variant tabling reuses answers from previous queries that are identical to the current query up to variable renaming—see Section 1.5.2.1. In contrast to variant tabling, subsumptive tabling, also implemented in XSB, reuses answers from previous queries that subsume (i.e., are more general than) the current query. A method that has the same performance characteristic as the top-down evaluation with subsumptive tabling, called subsumptive demand transformation [Tekle and Liu 2011], has also been developed.

What distinguishes Demand Transformation (and Subsumptive Demand Transformation) from Magic Sets and variants is not just that it is simpler, but more importantly, that it provides precise time and space complexity guarantees [Tekle and Liu 2010, Tekle and Liu 2011]. In particular, it improves over Magic Sets asymptotically, even exponentially.

1.5.2    Top-Down Evaluation

We now turn to top-down evaluation. This strategy starts with a query that is represented by one or more goal literals and compares each goal against the heads of the various rules in the program. If we get a match, possibly substituting for variables, then we replace the goal with new subgoals from the rule’s body (noting that the body is empty when matching against EDB facts). If all the subgoals are eventually dispatched, then the collection of all variable substitutions used in the process can provide an answer to the original query. By considering alternative matches to subgoals, we can generate additional answers to the query.

For example, consider an EDB predicate cited that indicates that the person in the first argument has cited the person in the second argument. We also define an IDB predicate influenced that is the transitive closure of cited. (A more precise definition would consider the date of citation, but we do not do it here.)

Suppose we have the query goal

We can match this goal against the head of the first rule, substituting dm for P1 and X for P2. The new goal is

Matching this goal against the cited-facts gives two query answers:

The initial goal can also be matched against the second rule, with the same substitutions, yielding the goal list

The first goal here can be matched to the fact cited(dsw, dm), yielding the goal

Matching this subgoal to the first rule, and then matching the result to the fact cited(tt, dsw) gives the additional query answer

There are some choices in the top-down approach, in terms of the order that goals and rules are considered. The standard for logic-programming languages is to proceed depth first, always working on the first subgoal, and trying rules in order. However, there are other strategies, such as choosing the subgoal to work on based on the number of bound or unbound variables, proceeding breadth first.

1.5.2.1    Memoing (Tabling) Approaches

One big problem with top-down computation is that it can lead to an infinite recursion because a subgoal may be defined in such a way that it depends on itself. Consider the subgoal influenced(dsw, X) above. If we match it against the second (recursive) rule for influenced and match the first subgoal of that rule with the fact cited(tjg, dm), we get the subgoal

When we use the second rule on this new goal, we can match its first subgoal in the body of that rule with cited(dsw, tjg), we get the already seen subgoal

Thus, a naïve top-down strategy would lead to an infinite loop.

Resolving a subgoal repeatedly as it arises in different contexts can obviously lead to inefficiency in evaluation, not to mention infinite recursion. Unlike Prolog, where it is possible to have an unbounded sequence of distinct subgoals, Datalog queries with finite EDBs can lead only a finite number of different subgoals, up to renaming of variables. We can avoid redundant work and endless loops if we keep track of prior subgoals and their answers [Warren 1992]. We can then avoid a recursive call to a previously seen subgoal (or a more specific version of a previous subgoal). Furthermore, if we record previous answers to a given subgoal, then, if we encounter the subgoal again, we can look up the answers already found rather than computing them again. This strategy is an example of memoization, or tabling, which can be viewed as a variant of dynamic programming [Warren 1992].

Under tabled evaluation, every encountered subgoal is remembered in a table of subgoals, and every answer computed for a subgoal is remembered in the answerstable associated with this subgoal. No answer is added to the table of a subgoal more than once. Whenever a subgoal is encountered during evaluation, it is checked against the table to see if it has been previously encountered and is thus already evaluated or is in the process of being evaluated. If it is in the table, then it is not re-evaluated, but instead its answers from the table are returned as answers to the current subgoal invocation. It may happen that not all the answers for a subgoal (or even none of the answers) are in the table when it is subsequently encountered, so the computation must be able to suspend and resume later, when answers show up in the table for this subgoal.

When a goal is looked up in the table to see if it has been previously called, there are two options: one can look for a goal that is the same as the current goal up to variable renaming; this option is called variant tabling. Alternatively, one can look for a more general goal that subsumes the current goal.¹⁸ In this case, all the answers for the subsumed goal will be answers to the subsuming goal, so a subsumed goal can get its answers from the table of the subsuming goal. Using subsuming calls is known as subsumptive tabling. Our examples below assume variant tabling.

Consider again the definition of the influenced relation, but with the instance of cited shown below:

We want to pose a query to find all the colleagues that dm influences. In Prolog, this program goes into an infinite loop, repeatedly generating dsw and dm, because Prolog’s evaluation strategy tries to enumerate all the paths in the graph and there are infinitely many of them.¹⁹

Under tabled evaluation, subgoal calls and their corresponding answers are remembered and re-used. Answers are returned only once and calls are made only once, with subsequent calls using the answers returned by the initial call. Consider the following trace of tabled evaluation of the query ?– influenced(dm, COLL). 1 influenced(dm, COLL)

The non-indented lines indicate additions to the table: either a new goal or a new answer to an existing goal. The posed goals are simply added to the table as is, and returned answers are prefixed by “ans:”. In lines 1–5, influenced(dm, COLL) is called, which in turn calls cited(COLL, dm) and returns the answer dsw; the new goal (on line 2) and its new answer (on line 5) are then added to the table. On line 10, evaluation of the second rule for influenced(dm, COLL) begins, with computation continuing as in Prolog (except for the table-update side effects) to line 19. At line 19, another call to influenced(dm, COLL) is posed. A variant of this goal (in this case, identical to this very goal) is found in the table and so influenced(dm, COLL) is not actually called; instead the answers in the table for that goal are returned. Specifically, we see on line 20 that the answer of dsw is returned from the table. This step leads to a new answer from the second clause for the goal influenced(dsw, COLL), with COLL = dsw. This fact is added to the table on line 21. Then, backtracking to the first goal of that second clause returns tjg as the other answer to the subgoal cited(_h795, dsw). This step leads to the new call to influenced(tjg, COLL) in line 23, which gets added to the table, and the search through line 27 determines that tjg cited no one. At this point the contents of the table is:

Now we can return answers from the table to suspended goals. Returning the answer dm to influenced(dsw, COLL) results in the new answer dm to the goal influenced(dm, COLL), which gets added to the table in line 29. Similarly for tjg in lines 30 and 31. Lines 32–35 show other answers being returned to calls in the table, but they generate only answers that are already in the table, so they are simply no-ops. At this point all answers have been returned to all goals, and the computation is complete. The table now contains all the answers to the posed goal (and all generated subgoals).

Consider now a different, logically equivalent, way of writing the influenced rules:

No experienced Prolog programmer would ever try to write the transitive closure in this form, since the immediate recursion of the second clause would always result in an infinite loop. However, with tabling, such rules are easily handled and, in fact, this left-recursive form of transitive closure is more efficient!

Consider the following trace of a tabled evaluation of this left-recursive form for transitive closure with the same facts as before:

Here, again, lines 1–6 are the same as in Prolog, with the side effects that update the goal–answer tables. At line 7 we see the recursive call to influenced(dm, COLL). This goal (up to variable renaming) is found in the table, so it is not called again but instead the answers in the table are returned to it, which leads to new answers: dsw is returned from the table in line 8, which results in a new answer of dm on line 11; and of tjg is returned on line 13. Then the new answer of dm is returned from the table but that does not lead to new answers. Finally, tjg is returned but that again does not lead to any answers.

Looking at these two programs and the single-source query, it is interesting to compare the different algorithms. We see that the second derivation is shorter, and this aspect is not an accident! Say we have a database with N people in which everyone cited everyone else. Note that with the right-recursive definition we will get N tabled subgoals, each of the form influenced(person, XX) for the N persons. And each tabled subgoal will have N answers, one for each person cited. So this table has size O(N²). For the left-recursive definition, we have only one tabled subgoal, influenced(dm, COLL)—for the initial query—and that subgoal will have only N answers. So the size of the table is O(N). It can be shown that O(N²d) and O(Nd), where d is the maximum node out-degree, are the respective worst-case time complexities of the two algorithms.

Tekle and Liu [2010, 2011] present precise time and space complexity analysis for top-down evaluation with variant tabling and subsumptive tabling using finegrained complexity factors.

1.5.2.2    Other Top-Down Approaches

We briefly mention some variations on the top-down strategy aimed at evaluation of Datalog (or more general) programs. Tamaki and Sato [1986] introduced OLDT resolution, which is an iterative-deepening approach with tabling of answers from previous iterations. This paper was the first formal specification of a top-down tabling algorithm for logic programming, but it did not include an implementation.

The Extension Table (ET) evaluation mechanism [Dietrich 1987, Dietrich and Warren 1986] is a form of tabling that can be implemented easily in Prolog. It uses two additional structures for each predicate p to which it is applied. One we call et_p, for the extension table for p. It has the same columns as p, and is used to record previously derived facts for p. The other is call_p, which contains the patterns of variables and constants used in subgoals for p encountered so far. These predicates record the subgoals and their answers, and are updated, or used, when subgoals are invoked and answers are returned. However, this simple Prolog-based algorithm is not complete. Consider for example the left-recursive influenced/2 definition, with the order of the two rules reversed. Then the initial goal, influenced(dm, COLL), will immediately call itself. But there are no answers for it yet, so it must fail back to try other paths to generate answers. Unless computation somehow comes back to restart that “failed” subgoal call, some answers may be lost. One might think that by re-ordering clauses, one can avoid this problem, but that strategy does not work in general. For completeness, subsequent subgoals must either suspend, to be resumed later if necessary, or must somehow be regenerated. To be complete, the ET algorithm repeatedly iterates its computation until the table predicates do not change.

Variations and extensions of the ET algorithm have been developed and implemented in some Prolog systems including B-Prolog by Zhou et al. [2001] and ALS Prolog by Guo and Gupta [2001]. These techniques are known as linear tabling.

The SLG algorithm of XSB [Chen and Warren 1996, Swift and Warren 2011, Warren et al. 2007] is an extension of OLDT, described above. It differs from OLDT mainly in that it suspends subgoal computations, which may later be resumed, as necessary, similarly to the discussion in Section 1.5.2.1. The fact that it suspends and resumes computation means that it does not do the recomputation that is necessary with iterative methods, such as ET, and thus has better, and simpler, complexity properties. XSB also incorporates an “incremental completion” algorithm that, by controlling the order of task scheduling and keeping track of subgoal dependencies, determines when subgoals are completely evaluated (that is, have all their answers in the table) well before the entire computation is completed. This approach enables efficient handling of default negation.

Vielle developed the Query-SubQuery (QSQ) approach [Vieille 1986] specifically for Datalog, and it differs from tabling and ET in having “multigoals” where a given argument position in a predicate can contain a set of bindings. (We note that the original version of QSQ was incomplete on some programs—it did not always find all answers. Later work by Nejdl [1987] and Vieille [1987] provided complete versions of QSQ.) Such generalized goals can arise both from combining goals sharing the same pattern of variables and constants, and by solving goals against an EDB in a set-at-a-time manner. For example, consider solving the query

using the second rule for related/2:

The first subgoal will be advised(B, dsw). If we ask for all matching bindings from the EDB at once, we will get back {advised(jbf, dsw), advised(wcr, dsw)}. From that result, QSQ will generate the generalized subgoal related({jbf, wcr}, X). That subgoal can be matched with the same related rule, generating the generalized subgoal advised(B1, {jsf,wcr}). This subgoal illustrates one of the advantages of QSQ, that it can merge several calls to the EDB into one call (which is useful if the EDB is managed externally, say, by a database system). Solving this generalized subgoal will give the set of bindings B1 = {hw, dss}. However, rather than creating a new generalized subgoal related({hw,dss}, P2), these bindings will be merged with the existing generalized subgoal to get

If any of the new bindings had matched old bindings, it would indicate that there might be some results already available.

QSQ comes in two flavors: iterative (QSQI) and recursive (QSQR). Both involve the steps of generating new answers and creating new subgoals [Gottlob et al. 1989]. QSQI gives priority to new answers, and suspends working on any new subgoals until all answers have been generated that do not require those subgoals. In QSQR, on the other hand, when a new subgoal is encountered, it becomes the focus and processing of the current subgoal is suspended. In practice, QSQI tends to be worse because of duplicate rule firings [Bancilhon and Ramakrishnan 1986]. QSQR seems closely related to SLG resolution applied to programs without negation, but to our knowledge no detailed comparison has been attempted.

1.5.3    Bottom-Up vs. Top-Down

The question naturally arises as to whether bottom-up or top-down is generally better for Datalog evaluation, and which particular methods are best. Obviously, one can concoct programs and datasets that favor a particular method, and some methods will not work at all on a given program. (For example, some counting variants of Magic Sets work for only some patterns of recursion.) Bancilhon and Ramakrishnan [1986] compare a range of bottom-up and top-down methods analytically on a variety of Datalog programs, EDB structures and query-binding patterns. While there are different orderings of the methods on the different cases, some patterns emerge, such as Magic Sets and QSQR generally being comparable in predicted performance, and usually beating QSQI and semi-naïve. Ullman [1989] claims that there are bottom-up methods that will always perform as well or better as top-down methods on Datalog. His argument is that for a given Datalog program P and query Q, there is a modified version of P that will generate all answers for Q that, when evaluated by the semi-naïve method, will beat a depth-first top-down method. He further claims that the Magic Sets approach bounds the performance of memoizing versions of top-down such as OLDT and QSQ. Bry [1990], however, disputes Ullman’s conclusion. He defines a top-down method called the Backward Fixpoint Procedure (BFP) and claims that bottom-up rewrite methods and top-down memoizing methods are actually BFP in different forms.

In terms of asymptotic time and space complexities, Tekle and Liu [2010, 2011] have recently established the precise relationship between (1) bottom-up evaluation using Demand Transformation and Subsumptive Demand Transformation, as well as Magic Sets, and (2) top-down evaluation using variant tabling and subsumptive tabling. However, the actual performance varies widely due to constant factors, and performance of internal data structures. Faced with the ambiguity of such analyses, some Datalog systems include both bottom-up and top-down methods, though determining the best method and optimizations to apply to a particular Datalog program and dataset is far from a solved problem.

1.5.4    Evaluation Methods Using Database Systems

An obvious approach to scaling is to use a relational DBMS to manage the ground facts in a Datalog program, which are easily stored as rows in a table, where each predicate has a separate table. The DBMS might be used just for secondary-storage management and indexing capabilities, or for more general query processing and evaluation. As an example of the former, consider top-down evaluation of the query related(lvk, Y). If we are considering the rule

we will need to solve the sub-goal advised(A, lvk). If advised is stored in a DBMS, and indexed on the second position, the database could quickly retrieve all facts having lvk as the value in the second position. Even if we were using a very simple top-down strategy, and only considering advised(A,lvk)-facts one at a time, bringing them into memory in a batch and caching them can save I/O time. As an example of the more general strategy, consider a rule-compilation approach. When working on a query, the evaluator can accumulate EDB goals, while trying to solve IDB goals with rules. Then, when a goal list contains only EDB goals, it can be converted to a database query. For example, if for the query related(lvk, Y) we try to solve the goal using the rule

we obtain a goal list advised(B, lvk), related(B, Y). If we then, in turn, solve the related/2 goal with the previous rule, the resulting goal list is

which consists entirely of EDB goals. This goal list can be converted to the SQL query

If there are multiple ways to solve IDB goals, then there will be multiple database queries. (In the presence of recursion, the number of queries may be unbounded, however.)

Bottom-up evaluation can also make use of DBMS capabilities. The database can handle all or part of evaluation of each application of TP for a Datalog program P. A rule that mentions only EDB predicates can be translated into an SQL query. A rule that contains one or more IDB predicates needs to also access newly derived facts during right-to-left evaluation. We can create temporary tables in the database for each IDB predicate, to hold derived IDB facts, thereby having TP execute entirely within the database. Alternatively, a bottom-up evaluator might hold IDB facts in its own memory, and evaluate each rule with a nested-loop approach, issuing database queries for EDB facts, taking into account each combination of bindings determined by the predicates outside of those queries. We discuss specific instances of these approaches in the following paragraphs—first TD methods and then BU methods.

In terms of specific approaches, top-down methods tend to be more “proof” oriented, driven by derivation, whereas bottom-up methods are more “syntactic,” based on the structure of the program rules. Reiter [1977a] talks about an initial “compilation” phase where the IDB is consulted, resulting in a set of queries against the EDB. More specifically, he describes feeding the IDB to a theorem prover that flags EDB literals for later evaluation, and proposes that evaluation take place in a relational database. (Reiter notes that his particular method will not be complete for recursive queries.) The DADM [Kellogg et al. 1977] and DEDUCE 2 [Chang 1977] systems also present approaches where the IDB rules are first processed to yield (perhaps multiple) goal lists of EDB literals that can be evaluated against a relational database. Cuppens and Demolombe [1988] describe an accumulation approach to collect maximal sequences of EDB predicates for database evaluation. Grant and Minker [Grant and Minker 1981] note that the collection of EDB queries generated by such approaches will often have shared subexpressions that can be factored out for efficiency. Ceri et al. [1989] address overlap of database retrievals by caching the results returned from queries. The BERMUDA system [Ioannidis et al. 1988] takes a similar approach, collecting sequences of EDB predicates for evaluation by the database, caching results in a file, and having a “loader” component provide access to answers to a Prolog interpreter on demand.

On the bottom-up side, it has long been known that the immediate consequence operator TP for a Datalog program P can be translated into a relational-algebra expression. Ceri et al. [1986] show that a complete translation of bottom-up evaluation can be obtained by extending relational algebra with a fixpoint operator. Ceri and Tanca [1987] discuss various optimizations that can be applied to such a translation. The PRISMAlog language [Houtsma and Apers 1992] was a Datalog extension that was also translated to relational algebra extended with a general fixpoint operator, then optimized into standard relational-algebra expressions with possibly transitive closure over them. Relational algebra generally needs to be translated to SQL before sending it to a relational DBMS. Draxler [1993] provides a direct translation of a logic language into SQL, bypassing relational algebra. The NED-2 Intelligent Information System [Maier et al. 2002] introduced a specialized syntax for database queries in a logic language that are transmitted to the DBMS as SQL. Finally, van Emde Boas and van Emde Boas [1986] describe an approach to extending a relational DBMS (IBM’s Business System 12) with logic programming functionality, but it is unclear whether the project got beyond the prototype stage.

1.5.5    Query Optimization in Datalog

Optimization of Datalog queries has been studied from a theoretical perspective as well, mostly in the 1980s. Since the optimization problem is equivalent to finding another Datalog program that computes an equivalent set of facts given a set of facts for extensional predicates, but is faster to evaluate, optimization has been mainly looked at in the context of query equivalence or, more generally, query containment. Query containment means that the results of one query are always guaranteed to be a subset of the results of another query. Showing containment in both directions proves equivalence. Many Datalog optimization techniques involve simplifying the original Datalog program by removing rules or subgoals and then testing for equivalence with the original. Unfortunately, the equivalence problem for Datalog queries has been shown to be undecidable [Shmueli 1993]. Furthermore, query equivalence turned out to be undecidable for many subclasses of Datalog, e.g., even if each rule contains at most one recursive predicate [Gaifman et al. 1993]. Thus, fragments of Datalog for which the query containment problem is decidable have been of strong interest. In particular, Cosmadakis et al. [1988] have shown that, for monadic Datalog, where only predicates with one arguments are recursively defined, query containment is decidable and that if binary relations are allowed to be recursively defined then the problem is undecidable. A stronger version of query equivalence, called uniform equivalence, is the decision problem of whether two Datalog programs compute an equivalent set of facts given initial facts for both intensional and extensional predicates. Sagiv [1987] showed that uniform equivalence is decidable, and provided an algorithm for minimizing a set of Datalog rules with respect to uniform equivalence. For an even simpler subset of Datalog, with no recursion altogether, called union of conjunctive queries, many positive results regarding query optimization have been obtained, especially in the context of SQL [Chaudhuri 1998]. More recently, Vardi [2016] showed that the query containment problem for union of conjunctive queries extended with transitive closure is also decidable. For Datalog optimization techniques that involve constraints, see Section 1.4.5. Another class of equivalence results looks at whether a (syntactically) recursive Datalog program has a non-recursive counterpart [Chaudhuri and Vardi 1992, Naughton 1986],

We should add that the area of Description Logic [Baader et al. 2003] is concerned with the query containment and equivalence questions for various subsets of first-order logic, which have a limited intersection with Datalog. However, we are not aware of a result from that area that yields new insights when applied to that intersection.

1.6    Early Datalog and Deductive Database Systems

While much of the initial work on Datalog looked at evaluation options, semantics and extensions, a number of fairly complete implementations of deductive database systems were built in the late 1980s and early 1990s. These systems differed in several ways.

One was in how they provided for ordered execution. Although Datalog has pure logical semantics and (at least, in theory) the programmer does not need to worry about rules and goal ordering, most applications need operations with side effects, such as updates and I/O, where order is important. Thus, these systems tended either to embed declarative queries in a procedural language, or have certain rules where evaluation order was enforced.

A second source of variation is in what kinds of extensions of basic Datalog were supported, such as structured terms, collections, negation and aggregation. A third aspect was the optimizations and evaluation strategies employed, which are dictated to some extent by the extensions supported. The final area we call out is how base relations were managed. Some systems had disk-based storage for the EDB, either custom built or using an existing DBMS or storage system. Others worked with a main-memory database (possibly backed to secondary storage between sessions).

The coverage that follows is by no means exhaustive, but serves to illustrate the differences we mentioned above. We have also leaned toward systems that were publicly distributed. We recommend the survey by Ramakrishnan and Ullman [1995] for a more in-depth comparison of systems from that era. Also, while we refer to these systems in the present tense, to our knowledge only XSB is still being supported and widely used, though some of the concepts and techniques of LDL++ are incorporated in DeALS [Shkapsky et al. 2013].

1.6.1    LDL and LDL++

The LDL language and implementation were developed at the Microelectronics and Computer Technology Corporation (MCC) during the mid-1980s as an alternative to lose coupling between logic languages and databases [Tsur and Zaniolo 1986, Zaniolo 1988]. LDL was intended to be complete enough for full application development, although it can be called from procedural languages and can call computed predicates defined in C++. While starting from pure Horn clauses with declarative semantics, it does provide some control constructs to enforce order on updates and screen output.

LDL preserves complex terms from Prolog, such as date(1981, 'March'), and augments them with sets. Set values can be listed explicitly, or created in rules by grouping results. For example, a rule

will return result facts such as

LDL provides a partition predicate that can non-deterministically split a set, to support parallel processing of large datasets. LDL also supports non-determinism through a choice predicate, which selects a specific assignment of values from a range of options. For example, in

the choice((AID), (PDI)) goal ensures that each advisor id AID will have only one person id PID associated with it in oneAdvisee. (In relational database terms, the view oneAdvisee will satisfy the functional dependency AID → PID.) LDL supports stratified negation, which is handled via an anti-join strategy. For example, the rule

is evaluated by anti-join of the person table with the advised table on their first arguments. (Anti-join removes any rows from its first argument that connects with at least one row in the second argument on the join condition. Here it will knock out any person-fact that has a matching advised-fact.)

LDL has two implementations. The first compiles LDL into FAD, an algebraic language designed at MCC for execution on a parallel database machine. A later, single-user prototype for Unix called SALAD [Chimenti et al. 1990] was created to make LDL available more broadly. SALAD was among the first systems to integrate many of the evaluation techniques covered in Section 1.5. SALAD applies both Magic Sets and Generalized Counting [Saccà and Zaniolo 1986a] rewrites. (The latter is suitable for graph-like queries where path length matters but not path membership.) SALAD evaluation is bottom-up semi-naïve, but has several variants for processing joins associated with individual rules, such as various combinations of eager and lazy evaluation, sideways information passing, materialization, and memoization. Some methods support recursive predicates, and some can be used with intelligent backtracking. Intelligent backtracking detects cases where a join should not continue iterating from an earlier subgoal than it normally would. Consider the rule for the csInfo predicate from the initial example,

which is essentially a join of the thesis, person and area relations. Suppose we are currently considering the two rows

and fail to find any area row matching the goal

There is no reason to return to consider further person-rows, since the hw value comes from the thesis-row. The SALAD optimizer chooses among the joinprocessing options based on program requirements, as well as estimated costs and index availability. The LDL compiler can process a predicate differently depending on the binding pattern of a call. So, for example, for csInfo(b, b, f, f) (a call with the first two arguments bound and the last two free), it might choose to put person first in the join, whereas for csInfo(f, f, b, b), it might put person last in the join.

LDL++ [Arni et al. 2003] was an extension of LDL begun at MCC and completed at UCLA. LDL++ adds support for user-defined aggregates (UDAs), offering both forms that provide final results as well as versions that can return “online” results. For example, an aggregate for average might return the intermediate value after each group of 100 inputs has been examined. LDL++ also introduced a testable form of local stratification in which iterations of a predicate are explicitly indexed, and rules with negation must only use results available at a previous index.

LDL++ added access to external databases to SALAD’s internal main-memory database. LDL++ can create SQL calls to external sources that contain multiple goals, thus benefitting from the DBMS’s query optimizer.

1.6.2    CORAL

Ramakrishnan et al. [1994] developed the CORAL deductive system at the University of Wisconsin. To support imperative aspects, CORAL is “mutually embedding” with C++ code—that is, CORAL modules can be called from C++ and evaluable predicates for CORAL can be written in C++. In terms of Datalog extensions, CORAL supports structured terms in predicates and explicit multi-set values, with grouping capabilities similar to LDL sets. CORAL also provides functions, such as union and subset, to operate over multi-set values, and aggregation functions, such as sum and count, that can reduce a multi-set to a scalar. CORAL supports a generalized form of stratified negation where a predicate can depend negatively on itself, as long as no individual ground goal does. So, for example, if a predicate p can have a rule of the form

as long as the advised is acyclic, meaning a goal can never depend negatively on itself.

CORAL programs are structured into modules, where different optimizations and evaluation techniques are applied to different modules. CORAL offers a variety of program rewriting techniques, including Magic Templates [Ramakrishnan 1991] and variants. The programmer can annotate a module to indicate which kind of rewriting to use. Other annotations on a per-predicate basis can control aspects such as duplicate elimination, aggregate selection (for example, retain only minimum-cost paths), and prioritization of newly derived facts for use in further deductions. The evaluation technique can be selected on a per-module basis, as well. A CORAL module can be evaluated bottom-up, using semi-naïve evaluation, or top-down in “pipelined” fashion, which provides a cursor-like functionality to retrieve query answers, but does not retain derived results.

CORAL supports persistent EDB data via either file storage or the EXODUS storage manager [Carey et al. 1986]. Data in files is loaded all at once when first accessed, whereas EXODUS can load pages of tuples incrementally.

1.6.3    Glue-Nail

Glue and Nail are a pair of set-oriented languages developed at Stanford University to work together cleanly [Derr et al. 1994]. Glue is a procedural language, whereas Nail is a declarative logic language originally developed as part of the NAIL! system [Morris et al. 1986]. Glue provides for control structures, update operations, and I/O. Its basic computation is a join operation, which can take any combination of stored relations, Glue procedures, and Nail predicates.

Glue and Nail support structured terms, including literals and terms with variables in predicate and function names, an extension of HiLog syntax referred to as NailLog. Sets are handled differently than in the previous systems described. Rather than sets being a new kind of structured term, each set value is a predicate with a distinct name, parameterized by one or more values. So, for instance, to construct advisee sets as in an earlier example, we can use the Glue assignment statement

One such set would be

and the value advisees(lvk) can be passed around as a name for this extent. Glue also supports subgoals that compute aggregates over tuples defined by previous subgoals in an assignment statement.

Both Glue and Nail are compiled into an intermediate language, IGlue, which can execute joins, tests and data movement. The Nail compiler uses two variants of Magic Sets, and decides which evaluation strategy to use at run time, which can be semi-naïve, stratified, or alternating fixpoint [Morishita 1993]. The Glue compiler analyzes the possible matches for each subgoal (which can be large because of the use of variables in predicate names), and limits the run-time tests to those predicates and procedures that could possibly match. There is also an IGlue-to-IGlue static optimizer that performs various data-flow analyses, including constant propagation. The optimizer also detects cases where a virtual relation can have at most one tuple, and provides a simpler data structure for that relation. The IGlue interpreter also has an optimizer for use at run time. The need for this component arises from the fact that during iterative computation (such as for a recursive predicate), the size of relations can change, hence the optimal execution plan for a join can change. The IGlue interpreter will therefore reoptimize a query if a relation’s cardinality changes by more than a factor of two up or down.

The Glue-Nail systems keeps all data in main memory during execution, but reads EDB relations from disk initially, and writes query results back to disk.

1.6.4    EKS

EKS is a Knowledge-Base Management System (KBMS) initially developed at the European Computer-Industry Research Center (ECRC) and later transferred to commercial interests [Vieille et al. 1992]. EKS is callable from MegaLog, an extended Prolog system that provides efficient disk-based storage via BANG files, a data organization similar to grid files that support look up on multiple attributes [Freeston 1987].

While EKS does not have complex terms, it does support negation and several other language features—the and and or connectives, aggregation, explicit quantifiers, evaluable predicates—that are translated into an extended Datalog. It supports general integrity constraints in the form of yes-no queries on base and virtual predicates that need to be satisfied if an update is to be allowed. For example, a constraint might require that the person and area mentioned in any thesis-fact have corresponding facts in the person and area tables:

Constraints are supported via propagation rules and transactions. The propagation rules determine which facts actually have to be checked upon update. For example, deletion of a area-fact requires checking only for any thesis-facts that have that area. Transactions can roll back an update if any constraints are violated. The transaction capability supports other features, such as hypothetical reasoning in which “what-if” queries can be run over temporary updates.

EKS rule compilation begins with determining an evaluation order on subgoals that satisfies any restrictions on binding patterns for the corresponding predicates. Such restrictions can arise from evaluable predicates, the use of negation, or virtual rules whose own rules induced binding restrictions. The rules are then translated into programs consisting of BANG operators—such as join, select, and difference—plus control constructs. These programs implement a breadth-first, top-down search of the rules, using the Query-Subquery approach to avoid solving the same goal repeatedly.

As mentioned, EKS relies on BANG files for external storage. BANG files are designed to accommodate the need to look up facts (and clause heads in general) based on alternative combinations of attributes, since a predicate can occur with varying binding patterns.

EKS was transferred to the French computer company Bull, and became the basis for the VALIDITY deductive object-oriented database [Vieille 1998]. VALIDITY became the property of Next Century Media, which used it to support targeted advertising.

1.6.5    XSB

The XSB Logic Programming System was developed by David S. Warren and his students at Stony Brook University in the early 1990s and is being constantly enhanced and extended to this day. It is a conservative extension of the Prolog programming language, by the addition of tables in which subgoal calls and answers are maintained to avoid redundant computation—an embodiment of the memoization strategy discussed in Section 1.5.2.1. In the context of a relational language, such as Prolog, where a single predicate (or procedure) call can have multiple (or no) answers, tabling changes the termination characteristics of the language, avoiding many infinite loops that are notorious in Prolog. With tabling, XSB is complete and terminating for Datalog programs [Chen and Warren 1996], and as such can be considered as an implementation of an in-memory deductive database system [Sagonas et al. 1994].

Being an extension of Prolog, XSB can be used as a procedural programming language [Warren et al. 2007], just as Prolog. The programmer determines which predicates are to be tabled, either by explicitly declaring them to be tabled or by providing an auto_table directive telling the system to chose predicates to table. Thus, the programmer can use the Prolog language to provide the necessary procedural capabilities, such as loading files, generating output, and controlling query evaluation.

XSB, as an extension of Prolog, includes function symbols and complex terms, including lists. Of course, termination is not guaranteed if the programmer uses them, but they provide programmers with the ability to program their own extensions. So programmers, for example, can use Prolog builtins, such as findall and setof, to collect lists of goal solutions and then use Prolog’s list-processing capabilities to compute arbitrary functions over those lists. XSB also provides a general aggregation capability, integrated with tables, that allows programmers to define their own aggregation operators to be applied to all answers of a query. These operators can be used in recursive rules to solve such problems as finding the length of the shortest path between a pair of nodes in a directed graph.

XSB does minimal automatic query optimization. The general philosophy is to allow the programmer to control how the query is evaluated by determining how it is specified. This approach was inherited from XSB’s foundation in the Prolog programming language. XSB does include a few simple program transformations to improve indexing and to factor clauses to potentially reduce the polynomial complexity of some queries. But these optimizations must be explicitly invoked by the user. XSB also supports subsumptive tabling, which allows a table to be re-used if a proper instance of the original goal is encountered. This capability supports inserting a bottom-up component into the normal goal-directed computation of XSB. For example, for transitive closure, we could declare the predicate as subsumptively tabled, and then make the fully open call (i.e., where each argument is a distinct variable). In this case, there will be only one call that uses the clauses that match this predicate; every subsequent call is subsumed by that first call, and so it will suspend on the table associated with the initial open call, waiting for answers to show up that it can return. So the first answers must come from the base case, since only these answer do not require a recursive call. The next answers will come from a single use of the recursive call, and so on, simulating bottom-up computation.

XSB does not directly provide much support for persistent data. Using Prolog, programmers can read and write files to define internal predicates. So the programmer can batch-load data files, or can read them incrementally. Some work explored evaluation-control strategies that would provide more efficient disk access patterns when accessing external data [Freire et al. 1997]. XSB also has a powerful ODBC interface to any relational database system,²⁰ so an XSB user has access to data persistence facilities.

1.6.6    Other Systems

Aditi was a deductive database project started in 1988 at the University of Melbourne [Vaghani et al. 1994]. Aditi-Prolog is a declarative variant of Prolog, which can be used to define predicates in the NU-Prolog system [Ramamohanarao et al. 1988]. Aditi can evaluate predicates bottom up (with optional parallelism) and in tuple-at-a-time top-down mode. Aditi provides different strategies to order literals in a clause during compilation, such as choosing the next subgoal to maximize bound variables or to minimize free variables. Aditi programs are translated to relational algebra programs, which are further optimized using programming-language and database techniques. Joins can be evaluated by several methods, which can take advantage of different tuple representations that Aditi supports. Parallelism is available both among different subgoals of a rule and among multiple rules for a predicate.

DECLARE is the language for the Smart Data System (SDS) [Kießling et al. 1994] whose foundational work was done at the Technical University of Munich (TUM) and then continued at a research and development center during the period of 1986–1990. One of the main targets of SDS was decision making over heterogeneous data, hence it emphasizes connectivity to multiple data sources, both local and remote. DECLARE is a typed language using SQL types plus lists and supporting constraints. SDS provides distributed query processing, where evaluation plans can contain complex SQL queries executed by external systems. Also, the SDS developers were interested in search strategies beyond top-down and bottom-up techniques, in particular, using domain-specific knowledge. For example, in a rule for connecting flights, the intermediate city will generally be in the same geographic region as the source and destination cities.

LOLA is another deductive database system from TUM [Freitag et al. 1992], which can access stored relations in external databases and predicates defined in Common Lisp. It supports type groups that collect terms into classes, such as airports and geographic regions. LOLA is translated to an intermediate language, from which it builds operator graphs that are optimized for subexpressions and indexing opportunities. These graphs are evaluated in R-Lisp, which implements an in-memory algebra for relations with complex objects. Some of the preprocessing routines are in fact written in LOLA itself.

RDL is a production-rule system from INRIA [Kiernan et al. 1990]. It uses “if … then” rules with the consequent being a sequence of inserts, deletes, and updates of stored or virtual tables. We mention it here because unlike most production-rule systems, which fire a rule separately for each instantiation, RDL takes a set-oriented approach similar to most Datalog systems. It computes all bindings of a rule body under the current database state, then processes all modifications.

The Starburst project at IBM sought to make relational DBMSs more extensible in several dimensions, including query processing [Haas et al. 1989]. It introduced table functions. A table function produces a table as a result, and can call itself in its own definition, thus expressing a recursive query. An interesting outcome of the project was a method for applying the Magic Sets technique to full SQL [Mumick and Pirahesh 1994].

FLORID [Frohn et al. 1998] is an object-oriented Datalog system developed in the 1990s at Freiburg University. It differs from all the aforementioned early systems in that it was based on the object-oriented model provided by F-logic (see Section 1.4.6) and not on the usual predicate syntax. It was thus one of the first systems that provided theoretically clean support for semi-structured data.²¹ It was also one of the first to support the well-founded semantics for negation (Section 1.4.1). In other aspects, FLORID’s evaluation strategy is bottom-up and it has a very flexible support for aggregation, which allows aggregations to be nested arbitrarily.

1.7    The Decline and Resurgence of Datalog

After its swift rise in the 1980s, interest in Datalog entered into a period of decline in 1990s and then started to rise again in 2000s. This section reviews some of the reasons for the decline and the subsequent resurgence.

1.7.1    The Decline

With the notable exception of XSB, the systems in the previous section are no longer supported. A limited form of linear recursion made it from Starburst into IBM’s DB2 product and into the SQL:1999 standard. Datalog and deductive databases did not emerge as a major commercial category. Research on Datalog ebbed in the 1990s. The reasons for the waning of interest are not completely clear, but we consider here some contributing factors. We were helped by comments from colleagues in the field (see Acknowledgments).

No “Killer Application”. A new technology is often propelled by a “killer application” that it enables for which existing technologies are ill-suited. For example, the World Wide Web led to major growth in the Internet (and network connectivity in the home). No such application emerged for Datalog—nobody seemed that interested in computing his or her ancestors. While there were problems that could not be handled directly by conventional relational DBMSs, there were often specific products in the market to solve those problems. For example, IBM’s COPICS product had a module that handled the Bill-of-Materials problem (traversing down the part-subpart hierarchy while aggregating numbers of parts, weight, total cost, and so forth), thus supporting a particular type of recursive query.

Theoretical and Practical Limitations. There were limitations in both evaluation technology and computer hardware that hampered the efficiency and applicability of early Datalog systems. While Magic Sets and similar approaches helped the performance of bottom-up evaluation, in the worst case they could cause an exponential expansion in program size, if the target predicates had many binding patterns. For top-down evaluation, while tabling techniques had been investigated, there were still issues with handling negation, incrementality, and the best way to schedule subgoals. On the hardware side, computers were limited in processor power and memory (4–64 MB of main memory was typical for desktop machines in the 1990s), which meant that Datalog programs on what today would be considered small amounts of data could easily be disk bound.

Loss of Mindshare by Logic Programming in General. Logic programming was being overshadowed by object-oriented languages, which were much better at user interfaces and graphics at a point where powerful desktop workstations were coming on the market. Prolog had modest UI capabilities, and most would not transfer into Datalog, so you could not write a complete application in it, in contrast to object-oriented languages such as Smalltalk and C++. Programmer productivity issues seemed focused on graphics and interactivity vs. sophisticated query and analysis, though there was still interest in expert systems and knowledge bases. Coverage of Datalog (and logic programming) in academic settings declined, meaning there were fewer programmers versed in logic languages as compared to object-oriented languages.

Antipathy in the Database Systems Community. There was open antagonism by some in the commercial and systems research communities toward deductive database work. Some of that ill will seemed rooted in a vested stake in SQL orthodoxy (which also manifested in criticism of object-oriented databases). That sentiment might also have come from feelings that deductive database work was not addressing the most important issues in data management, such as extensibility and spatial access methods. The nature of some of the research contributions might have added to these perceptions. For example, there were many papers on proposed evaluation techniques, but a lot of them were not actually implemented, much less benchmarked for performance.

Barriers to Entry in the Database Market. While Datalog systems could support more expressive querying than SQL-based DBMSs, the latter had many features that were often primitive or lacking in Datalog implementations, such as concurrency control, recovery, authorizations, cost-based optimization, indexing (and other physical design options), replication and back-up services, integrity constraints, and programming interfaces from multiple languages. While some Datalog implementations had some of these features, most database applications need all of them. Faced with a choice between recursive queries and the other features, developers chose the other features. Recursive queries could be implemented in a generalpurpose programming language making calls to the DBMS, whereas simulating the missing features in Datalog systems that did not have them was in most cases infeasible. Some of the features, such as concurrency and recovery, need quite sophisticated techniques to perform efficiently, and the investment costs to provide them to a Datalog system were likely beyond the means of most development projects. An alternative approach is to have a regular DBMS as a submodule of a Datalog system (and some systems followed this approach). Such a hybrid could provide most of the features mentioned, however, query optimization and evaluation was split across two components, limiting the performance of the resulting system. Datalog systems could not meet the minimum requirements to compete in the data-management market.

Inaccessibility of the Literature. Some whom we consulted said they found the deductive database literature overly dry and complicated. Papers were not easy to understand, and often lacked compelling examples or applications. This aspect may have limited uptake of ideas into existing DBMSs, especially since papers did not say how to fit these approaches into current implementation technology. Also, while Datalog bore close resemblance to the domain relational calculus, leading relational languages, such as SQL and QUEL, were tuple-calculus based. While the difference may seem trivial, and although in many cases Datalog allowed more concise expression of queries, positional notation can be challenging and errorprone for predicates with dozens of attributes, compared to named notation.

Contributions of Datalog. Even during its decline stage and before it started to surge again, Datalog had lasting effects on the contributing areas of logic programming, knowledge representation, and databases. In logic programming, it provided a “declarative reset,” and got people thinking again about how far one could go in logic languages without procedural or extra-logical features. For example, Datalog provided an arena to examine the recursion and negation, to find approaches that were more declarative than negation-as-failure. One approach was the Stable Model semantics, which led to Answer Set programming—the focus of much of current logic programming activity. In knowledge representation, it has influenced languages to deal with graph-based knowledge structures. For example, the core of the SPARQL language for RDF builds from Datalog-like goals over triples of the form (Subject, Predicate, Object). (SELECT queries in SPARQL have been shown equivalent to non-recursive safe Datalog with negation [Angles and Gutierrez 2008] and some implementation strategies for SPARQL are based on translation to Datalog [Polleres 2007].) In the database area, many SQL products now have support for certain forms of recursion, and some evaluation techniques for Datalog have been applied to non-recursive aspects of relational query languages.

Another large area of contribution for Datalog was as a vehicle for understanding the complexity and expressiveness of database querying. Complexity refers to the amount of time or space to evaluate a query over a database, as a function of input size. The relevant input can be the data (for data complexity), the query (for query or expression complexity), or both (for combined complexity). The complexity is generally characterized by broad classes, such as logarithmic space (LOGSPACE) or polynomial time (PTIME). A classical result is that domain relational calculus (essentially non-recursive Datalog with negation) has LOGSPACE data complexity and PSPACE query complexity. (Domain relational calculus is PSPACE-complete, meaning—informally—that domain relational calculus evaluation is as hard as any problem in PSPACE.) Abiteboul et al. [1995] provide an introduction to such complexity concepts and results. We note that Datalog itself is PTIME-complete for data complexity and EXPTIME-complete for query and combined complexity [Immerman 1982, Vardi 1982].

Datalog has helped the study of database query complexity (and decidability), particularly in terms of the complexity “consequences” of different language features and semantics. Compared to a syntactically complicated language such as SQL, language features can be more cleanly removed from or added to Datalog, such as recursion, negation, second-order variables, inequality literals, ordered domains, fixpoint operators, iteration, disjunction (in rule heads) and complex objects. It also readily admits alternative semantics, such as Well-Founded vs. Stable-Model semantics for negation. A survey by Dantsin et al. [2001] covers complexity of these variants and more. There is also work investigating restrictions of Datlog, such as linear recursion (at most one IDB goal per rule body) [Ullman and Van Gelder 1988] and limitation to a single rule [Gottlob and Papadimitriou 1999]. We also note that Datalog has also proved a useful tool in studying the complexity of non-database problems, such as constraint satisfaction [Feder and Vardi 1999].

Work on expressiveness considers questions such as which queries cannot be expressed in a particular language, how two query languages are related in terms of the queries they can express, and how query languages relate to complexity classes. For example, it is not possible to express a transitive-closure query in non-recursive Datalog [Aho and Ullman 1979], linear Datalog is strictly less expressive than regular Datalog [Afrati and Cosmadakis 1989], Datalog with equality and inequality predicates is equivalent to fixpoints over positive existential queries [Chandra and Harel 1985], and Datalog with ordered structures (that is, with a built-in ordering predicate on the domain of values) exactly captures polynomial time [Papadimitriou 1985]. Such expressiveness results are not purely of theoretical interest—they can show that a language with better “programmability” can be substituted for another without diminishing the queries that can be expressed. For example, both Monadic Datalog (all head predicates have a single variable) and a natural subset of Elog (a language for web wrappers) are as expressive as Monadic Second-Order logic (logic with variables ranging over sets) on trees [Gottlob and Koch 2004]. Thus, for tasks such as information extraction from the Web, the former languages provide an easier-to-use alternative to the latter. The survey by Dantsin et al. [2001] also covers a wide range of expressiveness results.

1.7.2    The Resurgence

Work on Datalog always kept going at some level, even after the initial flurry of activity subsided. Beginning around 1998 there was renewed interest in Datalog, driven by its use to solve real problems rather than by intrinsic properties or theoretical developments (although there have been new extensions and evaluation techniques motivated by these applications). Some of this interest was due to the new (at the time) field of the Semantic Web and its focus on inference [Berners-Lee et al. 2001, Boley and Kifer 2013a, Decker et al. 1998, Guha et al. 1998]. In other cases, Datalog was being applied in settings where database technology was not commonly used, such as program analysis and networking. Thus, its adoption was more a matter of introducing a declarative approach into a new domain or a domain where solutions were typically expressed imperatively, rather than of replacing another database language.

Semantic Web. The idea of the Semantic Web emerged in late 1990s as the next step in the evolution of the World Wide Web. Instead of HTML pages, the Semantic Web was to rely on machine-readable logical statements (most of which would be just database facts written in an open standard format called RDF [Lassila and Swick 1999]), making search results more relevant, giving rise to better recommendation systems, making Semantic Web services possible (for example, automatic arrangement of trips), and even enabling automated contract negotiation.

The two main research directions in this area are reasoning and machine learning; we focus here on the former. In reasoning, two approaches dominated: OWL [Grau et al. 2008], which is based on a particular strain of knowledge representation, called Description Logic [Baader et al. 2003], and rule-based reasoning, which is based on logic programming and includes Datalog. Both approaches have led to W3C recommendations (W3C calls its standards “recommendations”)—the already mentioned OWL and the Rule Interchange Format (RIF) [Boley and Kifer 2013a, Boley and Kifer 2013b], which is based on logic programming and, more specifically, on F-logic and HiLog (see Section 1.4.6). The expressive powers of OWL and of rules are quite different, which is why both approaches exist, each having its adherents. This bifurcation of efforts on the reasoning side has also led to a number of efforts to reconcile OWL with rules. First, it resulted in the development of an OWL subset, called OWL RL,²² which lies in the intersection of OWL and Datalog. Second, several approaches attempted to combine OWL and logic programming at a much more general level so as to take advantage of both paradigms [Eiter et al. 2004a, Eiter et al. 2004b, Motik et al. 2006].

Overall, building the Semantic Web turned out to be harder than originally envisioned, but the effort is proceeding apace. It resulted in Google’s Knowledge Graph, DBpedia, Wikidata, Semantic MediaWiki, and other resources. In addition, it led to a number of commercial Datalog-based systems for RDF stores such as Ontotext’s GraphDB,²³ Franz’s AllegroGraph,²⁴ and Apache’s Jena,²⁵ to name a few. Many leading logic programming systems (for example, SWI Prolog, Ciao Prolog, and XSB) also have extensive web-related capabilities.

Datalog for Program Analysis. Program analysis is an example of an application of Datalog to an area that had largely used imperative approaches before. Figuring out program properties, such as call chains or pointer aliasing, often involves graph traversal or mutual recursion, which are directly expressed in Datalog. Lam et al. [2005] relate their experience with implementing program analyses to detect security holes in web applications. They turned to Datalog after coding their analysis algorithms in Java proved hard to get correct and efficient. They also found their Datalog implementation easier to maintain and extend. Their evaluation approach to Datalog was to translate it to relational algebra and thence to Boolean functions. Relations with program-structure and execution-context information are represented as characteristic functions (mappings of tuples to true or false). Each function is encoded into a compact structure, called a binary decision diagram, upon which the Boolean functions can be efficiently evaluated. The CodeQuest system [Hajiyev et al. 2006] used Datalog to query program information, aimed in particular at enforcing style rules and programming conventions that the compiler does not enforce, such as requiring all subclasses of an abstract class to reimplement a particular method. The developers report that Datalog hits a “sweet spot” between expressiveness and efficiency. While not working with enormous datasets, the space requirements can exceed main memory, with code bases containing more than one million lines of code and greater than 10,000 classes. Their approach to evaluation is to send Datalog through an optimizing compiler that emits SQL, using iteration in stored procedures or SQL’s Common Table Expressions to handle recursion. The Semmle product takes a similar approach for code inspection and analysis. However, queries are written in an SQL-like language that is translated to Datalog and thence to relational database queries [de Moor et al. 2007]. The Doop system [Smaragdakis and Bravenboer 2011] also queries programs using Datalog, such as performing points-to analysis—determining all the memory locations to which a pointer variable might refer. They report that their analyses are as precise as previous methods, but faster. Their evaluation relies on the aggressive optimization of Datalog, as well as programmer-assisted indexing of EDB relations.

The use of Datalog for program analysis illustrates several themes that emerge across recent applications that motivate some of the renewed interest in the language. One is handling of complex reasoning. For example, program analysis involves mutual recursion among different properties being reported, such as pointsto, call graph and exception analysis. Also, the algorithms are expressed in a way that they can often be readily modified via adding an additional parameter in a predicate, or a few more rules. For example, Lam et al. [2005] point out that the Datalog rules for their context-sensitive points-to analysis are almost identical to their counterparts in context-insensitive points-to analysis. In contrast, capturing the reasoning and relationships for program analysis, along with appropriate control strategies, in an imperative programming language is a labor-intensive and error-prone task. Also, while the data sizes involved are not staggering, they are large enough that manual optimization of code may not be sufficient to deal with them efficiently. Another use of Datalog illustrated by the program-analysis domain is the use of Datalog as an intermediate form. It is often fairly easy to write a translator from a domain-specific syntax to Datalog. From there, a wide variety of implementation and optimization options are available. As we have seen, there are multiple control strategies based on top-down and bottom-up methods, and representation alternatives for data and rules, such as binary decision diagrams. Although not discussed extensively in this chapter, Datalog admits a range of parallel and distributed evaluation techniques. With these approaches, Datalog performance can match or exceed that of custom analysis tools [de Moor et al. 2007, Smaragdakis and Bravenboer 2011].

Declarative Networking. Datalog has also gained popularity for reasoning about networks. The general area of declarative networking [Loo et al. 2009] has grown to encompass network protocols, services, analysis, and monitoring. It is an area with many examples of recursive reasoning over both extensional (link tables) and intensional (state-transition rules) information. Describing network algorithms in Datalog exposes the essential differences between them, generates predicates that can be reused across algorithms, and suggests new alternatives [Loo et al. 2006]. Simple syntactic extensions of Datalog, such as location variables, can capture key aspects of the domain. A range of distributed evaluation techniques are available, including asynchronous data-flow computation derived from the convergence properties of Datalog. (Bottom-up evaluation of a monotonic Datalog program will always converge to the same result regardless of the order in which rules are applied.)

The P2 facility [Loo et al. 2005] supports the expression of overlay networks, in a (cyclic) data-flow framework using asynchronous messages. The authors found that using Datalog as a basis supported succinct expression of overlay algorithms. For example, the Chord overlay algorithm can be expressed in 47 rules, with many reusable parts, in contrast to finite-automaton-based approaches that are less concise and more monolithic, and the P2 version provides acceptable performance. The Datalog-based approach called out similarities and distinctions among different algorithms. (For example, a wired and wireless protocol were found to differ only in predicate order in one rule body.) Their approach also made hybrid algorithms easy to construct. Overlay specifications in P2 are written in Overlog, a Datalog-based language with extension for location attributes in tuples and continuous queries over a changing EDB (including handling of deletion). Overlog is translatable into data-flow graphs with local Datalog evaluation engines communicating via asynchronous messages.

Loo et al. [2006] extend the P2 work, looking at general techniques for prototyping, deploying and evolving continuous recursive queries over networks. In that work, the network is both the object of study and the vehicle for evaluation. Their language NDlog (for Network Datalog) emphasizes this latter aspect through both location flags in predicates and an explicit #link EDB predicate that lists all direct node-to-node connections in the network. Every predicate in NDlog must have a location-specifier variable as the first argument, which is used to distribute tuples in the network. Further, any “non-local” rule must contain a #link literal, and every predicate in the rule must have the source or destination of that link as its location specifier. An example from the paper is

which says there is a path from source @S to destination @D with first hop to @Z. (NDlog supports list values through built-in functions.) We see that all predicates in the rule have either @S or @Z as the location specifier. NDlog is compiled into local dataflow graphs that run at each node in the network. A non-local rule such as the one above is split into two local rules communicating through messages across the link. Evaluation is a relaxed form of semi-naïve, in which iterations happen locally, with tuples that arrive from other nodes during an iteration either being used immediately or buffered for the next iteration. The system uses both traditional and newly proposed Datalog optimizations. The former include predicate reordering, Magic Sets and aggregate selection, in which presence of an aggregate function, such as min in shortest path, allows suppression of non-optimal results [Furfaro et al. 2002]. The authors also present optimizations particular to the distributed setting, based on caching of results that pass through a node, and merging of messages with certain attribute values in common, as well as choosing between (or possibly combining) alternative evaluation strategies based on costs.

Abiteboul et al. [2005] apply Datalog to determining possible event sequences leading to alarm reports in a networked application. (A distributed telecom system is their example.) They target Datalog because of the need to reason over extensional (alarms) and intensional (potential execution flows) knowledge with recursive dependencies. The authors note that Datalog’s convergence properties are a good match to asynchronous, distributed settings, such as reasoning in and about networks. Their distributed version of Datalog—dDatalog—assigns whole relations to nodes. They adapt QSQ to evaluating dDatalog in a distributed setting. When a node encounters a remote predicate in evaluating a query, it ships that sub-goal, its binding pattern, and the remainder of the query to the node with the remote predicate.

The Cassandra access-control framework [Becker and Sewell 2004] is another example of the use of Datalog in a distributed setting. Cassandra augments Datalog with location and credential-issuer qualifiers, as well as constraints. The domain for the constraints is pluggable, and gives rise to “a sequence of increasingly expressive policy specification languages.” For example, a constraint domain for arithmetic allows specification of policies that limit the length of a delegation chain. Policy rules that can invoke remote policies over the network, to request resources, roles, and credentials, and are interpreted in a policy-evaluation engine. Cassandra chooses a tabled, top-down evaluation approach, because of potential problems with bottom-up evaluation. In particular, the distributed setting means that right-to-left evaluation of rules would require distributed query plans.

Datalog and Big Data. More recently, Datalog has been the basis for scalable dataanalytics systems, especially those targeting graph structures such as arise in social networks. SociaLite [Lam et al. 2013] extends Datalog for analyzing social networks. It supports some kinds of recursive aggregates, and allows the programmer to provide hints on data representation and evaluation order, which leads to performance comparable to imperative implementations, but with programs that are an order of magnitude smaller. Distributed SociaLite [Seo et al. 2013] further allows the programmer to specify how data should be shared across servers, and derives how to distribute evaluation and organize communication from that specification. The Myria system supports iterative analytic routines using recursion in Datalog [Wang et al. 2015]. Myria supports asynchronous and prioritized evaluation of Datalog on a shared-nothing cluster, as well as fault tolerance. BigDatalog [Shkapsky et al. 2016] also supports recursive analyses, in this case for Spark. While Spark supports iterative processing, the authors point out that directly coding recursive computations via iteration is challenging in Spark, and tends to be inefficient, as there are no opportunities for global analysis and optimization provided in Datalog. BigDatalog is especially well suited to graph analytics, where it outperforms systems specifically targeted at graphs, such as GraphX [Gonzalez et al. 2014]. One advantage systems such as SociaLite, Myria, and BigDatalog have over earlier Datlog systems for analytics application is support for aggregates—for example, max and sum—in recursive rules [Zaniolo et al. 2017].

Datalog is also the basis for parallel approaches to data analysis. Google’s Yedalog [Chin et al. 2015] is a recent Datalog-based system that is designed specifically to exploit data parallelism and aggregation of massive amounts of data. Also, the DeALS system [Shkapsky et al. 2013] has compilation techniques to support multicore processing [Yang et al. 2017].

Other Application Areas. We briefly mention other areas in which Datalog—and its derivatives—have been applied. The DLV system [Leone et al. 2006] uses Disjunctive Datalog to represent knowledge and to reason about alternatives. Disjunctive Datalog allows the “or” of predicates in the head of a rule, which gives rise to multiple minimal answer sets, similarly to what is seen for negation in a rule body. DLV also includes integrity constraints that rule out certain answer sets, and “soft” constraints that prioritize among answer sets. Ashley-Rollman et al. [2007] use a Datalog-like language called MELD to plan shape-shifting maneuvers for a swarm of modular robots. They find that the declarative approach allows programs that are 20 times smaller and allow more optimizations, compared to imperative alternatives.

A variety of Web-related applications also use Datalog. The Lixto system [Gottlob et al. 2004] supports Web data extraction and service definition. With Lixto, a designer can specify a data-extraction wrapper via a special browser and the system generates a Datalog program to perform the extraction. Its Elog language is based on Monadic Datalog (where all IDB predicates are unary), and supports visual wrapper specification. Lixto technology is now part of the McKinsey Periscope product. A follow-on project, DIADEM [Furche et al. 2014], targets fully automated data extraction from collections of web pages. DIADEM uses a form of Datalog± internally to represent domain knowledge. Orchestra [Ives et al. 2008] supports data sharing on the Web, and translates data-exchange programs to an extended version of Datalog with Skolem functions to support virtual-entity creation. WebDamlog [Abiteboul et al. 2011] is a Datalog-style language for implementing distributed applications among peer systems on the Web. Toward that goal, WebDamlog supports the exchange of both facts and rules.

We will also see uses of Datalog for data management in LogicBlox and Datomic in the next section. Also see chapters 7 and 9 to learn about applications in bioinformatics and natural language processing.

Summary. Datalog is gaining more acceptance of late, as evaluation methods and optimization techniques proposed on a theoretical level in the past have been implemented and tested on actual applications. These applications have demonstrated the utility of the language as a direct interface, as an intermediate language, and as a framework for additional features. These application have also inspired new extensions, such as for distribution, along with new evaluation and optimization approaches.

There is also a growing number of Datalog vendors and companies that rely on Datalog for their mission-critical applications, including LogicBlox, Datomic, XSB, Inc., Semmle, DLV Systems, Ontotext, and Coherent Knowledge Systems.

1.8    Current Systems and Comparison

This section describes and compares four current systems that implement Datalog: XSB, LogicBlox, Datomic, and Flora-2/Ergo. We show how a selection of Datalog rules and queries are written for each system, and report on experiments that illustrate their performance.

These systems all implement Datalog (or a superset). However, the observed performance of each system is unique. They show asymptotically different behavior due to fundamental factors, including their choices for evaluation strategies, selection of underlying data structures, and data indexing. Even when these factors are the same, there are differences in performance due to implementation details, such as the choice of implementation language.

1.8.1    Preliminaries: Data and Queries

For the illustration of rules and queries, we use the Mathematics Genealogy data [MathGen 2000] that contains basic facts about people, dissertations, and advisor relationships between people and dissertations. We assume the following EDB predicates, which are slightly different from those in the introductory example. In particular, an advisor ID (AID) is connected to a dissertation ID (DID), and a dissertation has a candidate (CID) who wrote it.

The data sets contains 198,962 people, 202,505 dissertations, and 211,107 facts of the advised predicate. In each of the systems, we answer the following five queries to illustrate the performance.

1.  Who are the grand-advisors of David Scott Warren?

2.  Which candidates got their degrees from the same university as their advisor?

3.  Which candidates worked in a different area than at least one of their advisors?

4.  Who are the academic ancestors of David Scott Warren?

5.  How many academic ancestors does David Scott Warren have?

These queries make use of simple joins, recursive rules, and aggregations that facilitate assessing the performance of the systems in various aspects. In the next subsections, we introduce four systems and how these queries are expressed in each.

1.8.2    XSB

XSB [Sagonas et al. 1994] is a top-down implementation of Prolog extended with tabled resolution as described in Section 1.5.2.1. XSB allows fine-grained control over which tabling strategy and indexes to use for each predicate, and the choices for tabling and indexing affect asymptotic behavior. Consider Query 1, which is written in XSB as follows:

Here the rule defining enumallq1/0 uses a Prolog idiom of a fail-loop, which has the effect of generating all results in the most efficient way.

By default, XSB indexes each predicate on its first argument. However that may not be the most effective choice. For example, in the rule defining q1, after the first subgoal binds D, top-down evaluation will need to obtain values for the first argument of adv given a binding for the second argument. The following directive creates an index on the second argument:

To illustrate tabling, consider Query 4:

For this query, one can show that there can be repeated subgoals for predicate anc. The following tabling directive will avoid reevaluating such repeated subgoals and, therefore, avoid an infinite loop, which would affect an ordinary Prolog system:

Rules for Queries 2 and 3 can be written in XSB as follows:

Query 5 can be implemented using the aggregate construct findall in XSB, which returns all answers to a query as a list via the last argument:

The same query can also be implemented using the table aggregation construct in XSB as follows:

The special tabling directive in the first line works as follows: whenever an answer acc for q4 is generated, XSB calls cnt(acc, _, NewAcc), removes acc from the table, and adds NewAcc. For the first answer found, the first argument in the call to cnt would be 0, as indicated by the tabling directive. So q5_2 returns the number of facts found for q4.

1.8.3    LogicBlox

LogicBlox [Aref et al. 2015] is a commercial system unifying the programming model for enterprise software development that combines transactions with analytics by using a flavor of Datalog called LogiQL. LogiQL is a strongly typed, extended form of Datalog that allows coding of entire enterprise applications, including business logic, workflows, user interfaces, statistical modeling, and optimization tasks. LogicBlox evaluates LogiQL rules in a bottom-up fashion.

In terms of the language, in addition to pure Datalog, LogiQL has functional predicates that map keys to values, and various aggregation operators. In LogiQL, the arguments of each EDB predicate need to be typed. For our queries, these types can be specified as follows:

In the specification above, person is a functional predicate (shown by the bracket notation), mapping person IDs to names. Using these specifications, Query 1 can be answered with the following rules:

Apart from the use of the functional predicates shown above, Queries 2–4 can be implemented similarly to XSB:

Query 5 can be specified using the aggregation construct in LogiQL as follows.

1.8.4    Datomic

Datomic [Anderson et al. 2016] is a distributed NoSQL database, which uses Datalog as its rule and query language. Since the system is closed-source and no academic paper has been published by the implementation team, one can only rely on the documentation for its details. Datalog evaluation in Datomic is performed bottomup, and indexing directives can be specified.

The syntax of a Datalog rule in Datomic is quite distinct from that used in the logic programming literature. It is akin to the RDF query language SPARQL [Prud’hommeaux et al. 2008]. Datomic operates on object-like predicates. For example, for our EDB predicate dissertation, rather than representing it as a predicate with arguments, each dissertation is considered an object with an identifier and arguments that can be accessed as fields. Therefore, all EDB predicates are represented by binary predicates written in infix form, and they use square brackets. For example, a dissertation’s candidate ID can be thought of as a predicate :dissertation/cid whose form in the body is [?d :dissertation/cid ?c], where variables are preceded by ?. In contrast, IDB predicates are written in prefix notation and use round parentheses, as seen in the rules below.

A rule is written as a list whose first element is the conclusion of the rule and the rest of the elements in the list are the body. For example, a new predicate author whose arguments are the dissertation ID and the candidate ID can be defined via the following rule:

Once a new predicate is defined, it can be used in the body of a rule to define more predicates, as shown in the definition of the advisor relationship below.

Queries use a similar syntax, where a list of variables appears after the keyword :find and the body is given after the :where keyword. Therefore, Query 1 can be defined as follows (the three dots after the arguments to :find will return a collection):

In this fashion, Queries 2–4 can be written in Datomic as follows:

Aggregates are handled in Datomic by applying aggregate functions to variables. For instance, Query 5 is written as follows:

1.8.5    Flora-2 and Ergo

Flora-2 [Kifer 2015, Yang et al. 2003] is a knowledge-representation and reasoning system that supports Datalog as a subset of its various reasoning paradigms, such as the ones described in Section 1.4. The bouquet of these extensions is unique to Flora-2 and many were pioneered by that system. The list of these advanced features includes well-founded negation (Section 1.4.1), aggregation (Section 1.4.3), object-oriented extensions based on F-logic and defeasible reasoning (Section 1.4.6), HiLog (Section 1.4.7), logical updates (Section 1.4.8), certain styles of functional programming, explicit logical quantifiers, and more. Flora-2 uses XSB as an underlying inference engine. In particular, it relies on XSB’s top-down evaluation strategy, but also brings in new elements such as dynamic reordering of subgoals. Ergo is a commercial variant of Flora-2 offered by Coherent Knowledge, LLC. It includes additional language extensions and optimizations as well as development tools and connectors to various external data sources (for example, SPARQL endpoints, tabular data and JSON). Our running example of the fragment of the Genealogy Database, expressed in Flora-2, is shown below. To illustrate the object-oriented features of this system, we modify the database schema to use frame-based rather than predicate-based representation. (If we used predicate representation then Flora-2 rules would be similar to XSB’s with minor syntactic differences.)

These declarations specify the types of the attributes for classes Dissertation and Person (=> means “has type”). In this application, these declarations are not required, but they make the schema of the database explicit and easier to grasp.

Since the object-oriented schema above is quite different from the original relational schema in Section 1.8.1, the next pair of rules specifies the “bridge” between the two schemes:

We recall that the symbol -> means “has value” and thus the first rule above says that, given a tuple 〈d, c, t, g, u, y, ar〉 in table dissertation and a tuple 〈adv, d〉 in advised, one can derive that d is an object in class Dissertation such that: its attribute cid has value c, the attribute advisor has a value adv, title has value t, and so on. Note that an attribute can have multiple values and so, if dissertation d was advised by several advisors, the advisor attribute for d will be multi-valued.

The next batch of statements contains the actual queries for our running example. It starts with three auxiliary rules that define additional view-methods for classes Dissertation and Person. The first rule, for example, says that if there is a Dissertation-object (denoted by a name-less variable ?) that has a candidate with Id ?P (i.e., the attribute cid has value ?P) and an advisor ?A then that dissertation’s advisor is also an advisor for ?P. The next two rules recursively define the method ancAdvisor in class Person.

The last rule is interesting because it appears in the form of a fact, but is really a shorthand for a rule like

but count{…} is an evaluable aggregate function that can be placed directly as an argument to q5. This last query provides a glimpse of how logical and functional styles can be mixed in Flora-2.

1.8.6    Experiments

In this section, we report experimental results on two of the four modern systems we have discussed: XSB and LogicBlox. The systems that we have chosen for experiments are representative of two schools of evaluation, top-down and bottom-up. Each school has its own challenges, and we will illustrate those challenges via experiments, and show techniques to tackle them.

An issue pertinent to both schools of evaluation is indexing. During an evaluation, a system needs to retrieve facts for a predicate given some bound arguments. XSB, by default, generates an index on the first argument of each predicate. However, as we will illustrate, that index may not be enough. In such cases, XSB allows the user to specify additional indexing directives. LogicBlox automatically generates relevant indexes, and the user cannot affect the system’s choices. We will illustrate the importance of indexing in XSB via experiments.

An issue pertinent only to top-down evaluation is repeated calls to subgoals, as described in Section 1.5.2.1. We will show how the user specifies tabling directives, and the difference in query evaluation time with and without tabling in XSB.

An issue pertinent only to bottom-up evaluation is that, in its basic form, it does not take the particular query into account. Many methods exist to transform the rules so that the query is taken into account, most notably the Magic Sets transformation [Bancilhon et al. 1986]. We will use demand transformation instead [Tekle and Liu 2010], since it is a simpler method and its space complexity can be exponentially less (in the number of arguments of predicates) than Magic Sets. We will illustrate the effect of demand transformation via experiments in the LogicBlox system.

Another impact on performance for a system is the inclusion of database features such as atomicity and durability. These require various mechanisms, including locks and writes to disk, which impact performance negatively. LogicBlox has various such features, but XSB does not, and the experiment results should be evaluated in this light as well.

Optimization of Datalog queries by transforming rules and queries has been widely studied. These include specialization and recursion conversion [Tekle et al. 2008]; the latter is illustrated for relevant queries for both systems.

We now show our experiments for each query. We performed the experiments on a 2.8 GHz Intel Core i5 with 8 GB RAM, using XSB 3.7 and LogicBlox 4.3.10. We performed each experiment 10 times and took the average times of the runs.

Loading Input Data. Input data load times are important to the viability of a system, but it is a task that need be performed only once, and does not change with respect to a given query. For this reason, we separate loading input data from query answering in our experiments. In order to load the input data into XSB, we run the following query:

and in order to load the input data into LogicBlox, we install the definitions of the input predicates, and then run import scripts via its TDX mechanism.

Setting up the environment and loading of input data as described above takes 3.91 s in XSB, and 14.9 s in LogicBlox.

Query 1.1 The first query asks for the grand-advisors of David Scott Warren.

XSB. Recall the rules and query in XSB:

Note that a call to q1 will be made with its argument as a free variable, and therefore the following calls will be made in the body of the rule for q1: (i) a call to person with the second argument bound due to the first subgoal, since that argument is a constant; (ii) a call to adv with the second argument bound due to the second subgoal, since D will be bound by the first subgoal; (iii) another call to adv with the second argument bound due to the third subgoal, since X will be bound by the second subgoal; and (iv) another call to person with the first argument bound due to the final subgoal, since Y will be bound by the third subgoal.

The rules and query may be analyzed for each relevant predicate to find binding patterns for predicates, as shown above. For optimal performance, it is critical to have indexes corresponding to each binding pattern for the IDB predicates. As noted, XSB provides indexes on the first argument by default. For each non-default index, we write the indexing directives as follows:

The query is answered in 261 ms without the index, and in 238 ms with the index, 9.6% faster. The effect is not so dramatic, since only one subgoal binds the second argument of person. We will see more dramatic effects in other queries.

LogicBlox. Recall that in LogicBlox, we do not have control over the indexing mechanism. Running the first query takes 1400 ms. However, LogicBlox does not take the query into account, and therefore will infer facts for the adv predicate for every possible pair, but the only relevant ones are David Scott Warren’s advisors, and their advisors in turn. To avoid the extra computation, we can perform demand transformation, which yields the following rules:

The demand predicate stores David Scott Warren, and his advisors, so that the new rules only infer facts of the adv predicate that are relevant to our query. This version takes 944 ms, 33% faster than the original rules. This example illustrates that demand transformation is important, even for a small query.

Query 1.2 This query finds the people who got their degrees from the same university as their advisor.

XSB. Running the rules and query as given in XSB results in quite a long execution time, 49.2 min. However, if we analyze the rules for binding patterns, and therefore add the following indexing directive, which indexes the dissertation predicate on its first, second, and the combination of second and fifth arguments:

the running time is reduced to 511 ms, almost 5800 times faster than the original! The effect here is more dramatic than in the previous query because of repeated calls to dissertation with a different binding pattern than only the first argument being bound.

LogicBlox. The original rules and query take 2.14 s to run. Performing demand transformation in the original rules does not result in a new program, since in this order of subgoals, there is no IDB predicate with bound arguments in a left-to-right evaluation. However, we can change the order of subgoals to obtain the following rule for q2, to effect a different demand for adv without changing the semantics or performance of the given rule.

The demand for adv can be defined as

We can see that this join is quite expensive, joining every pair of people and filtering with respect to their universities. Therefore, demand transformation results in slower performance. Our experiments confirm this behavior, since this set of rules takes 77.9 s, 36 times slower.

Query 1.3 This query finds the people who worked in a different area than their advisors.

XSB. This query is similar in essence to Query 2, and without indexing the query takes 47.4 minutes to run. With the correct indexing directives, it takes 325 ms, 8750 times faster.

LogicBlox. Since Queries 2 and 3 are very similar, we again get the best performance with the initial rules, since the demand transformation after subgoal reordering results in extra work. The original rules and query take 1.74 s to run. If the adv predicate is moved to a later position and demand transformation is applied, the resulting rules and query take 74.4 s, 43 times slower.

Queries 1.4/5 These queries find the academic ancestors of David Scott Warren, and their count, respectively. The count is only a small overhead for each system, therefore we have grouped the queries together.

XSB. For all the prior queries, it can be shown that, based on the rules and the nature of the data (the genealogy information does not contain cycles), this query would terminate even without tabling. However, even in the absence of repeated subqueries, recursion could lead to exponential time complexity. As we discussed, the solution to this problem in top-down systems is tabling. To enable tabling, we write the following directive with the rules for ancestry:

Recall that our query will generate an initial subquery for anc with the second argument bound (to David Scott Warren). However, adding the tabling directive does not seem to help, since for every person, this set of rules will generate a query: Is this person an ancestor of David Scott Warren?

This strategy results in a lot of unnecessary computation, and XSB quickly runs out of memory; tabling did not help us get the answers here. Can we, however, reduce the number of queries, and therefore evaluate the query efficiently? The answer was already provided in Section 1.5.2.1, where we showed that left-recursive transitive closure is much more efficient than right-recursive, if tabling is used. Indeed, if we reorder the goals in the second rule as follows:

we will only ever ask: Who is an ancestor of David Scott Warren? And, voilà, we get the answers quickly, in 3.19 s. This example shows that tabling and subgoal ordering are essential to optimizing queries for top-down evaluation. Getting the count for Query 5 only takes a marginal 0.2% longer. The performance can be further improved by indexing the tabled predicate adv on its second argument, since it is always called with the second argument bound, with the directive:

This change improves the runtime to 181 ms, 17 times faster than without the index.

Apart from indexing and reordering, we can change the recursion to obtain another left-recursive version of the rules above:

However, this version runs slower at 11.3 s, since it immediately creates a subquery with both arguments free (neither X nor Z are bound in the head), therefore it finds all possible ancestry pairs.

These experiments show that the correct choice of directives, of rule type, and goal ordering can drastically affect the performance of queries. As a final remark, note that in the evaluation of such recursive queries, tabling directives should always be provided to avoid infinite recursion or exponential time complexity. Without tabling, XSB fails to complete this query in a pre-defined amount of time (1 h).

LogicBlox. Since basic bottom-up evaluation computes the ancestry for every possible pair of people, it is extremely inefficient not to take the query into account. LogicBlox takes 79.1 s to get the answers to the query, in contrast to XSB answering the query in a fraction of a second.

The time complexity of the evaluation for this query in LogicBlox is quadratic (with a polylog factor) in the size of the genealogy graph. We can reduce that time to linear, and observe a benefit that brings the performance to acceptable levels, if we perform demand transformation after reordering the goals as we did for XSB. These changes yield the following rules:

After this transformation, the query takes only 1.14 s in LogicBlox, 70 times faster than the original rules. Adding the count for Query 5 results in a marginal increase of only 0.03%.

Summary. We have illustrated the behavior of the two systems for each of our queries. In particular, specifying indexes and tabling for XSB, and demand transformation for LogicBlox have been shown to dramatically improve the running time. Note that these improvements are not constant-time, but rather asymptotic speedups. We have also shown that even when the systems theoretically should have similar asymptotic behavior, differences in implementation can result in significant variations in actual running times.

1.9    Conclusions

Datalog was a product of converging trends in databases, logic programming, and artificial intelligence with the goal of being able to support more advanced (than conventional databases) reasoning while being amenable to optimization and alternative evaluation strategies needed for larger data sets. After the initial surge in enthusiasm, the field entered a period of reduced interest and activity for a number of reasons. Among the most important ones was the blow-back due to “over-promise.” In the 1980s and early 1990s, the technology was simply not ready for production deployment, and it is not coincidental that this period of decline had a big overlap with the so-called “AI Winter.” Back then, the necessary theory and technology was yet to be developed and the pace was not keeping up with the expectations. On top of it, computers were severely underpowered compared to today and simply could not support the computational demands of either AI or logic programming. Another important factor was that the chosen application-area target—databases—was not optimal: DBMSs are demanding to implement, the query language is just one component of a DBMS out of many, and special-purpose solutions—albeit clunky—were available for applications requiring recursion (such as a bill of materials).

By the late 1990s, however, the situation started to change: computers became hundreds of times more powerful and the technology finally started to catch up with the needs. Importantly, that technology came both from the “ivory tower”—academia—as well as from application-driven research and practitioners. Moreover, people discovered that the application base for Datalog is much broader than just data management. Datalog has shown advantages in areas that involve complex, mutually recursive reasoning (program analysis) and benefits for distributed, asynchronous evaluation (declarative networking). Datalog was likewise recognized as an important reasoning tool for the Semantic Web as well as a design and prototyping tool. It is often used as an intermediate form that is easy to map to because it supports analysis and optimization, and can be translated to a variety of representations and evaluation techniques. Finally, Datalog simply took its place in the diverse family of programming languages.

The original idea about Datalog as a query language for DBMS turned out to be not that outlandish either: companies such as LogicBlox and Datomic have built DBMSs based on Datalog, and they include schemas, concurrency control and most of the usual accouterments of database systems. It just took more time.

In summary, do not expect Datalog (or any other language) to replace other technologies going forward, but it is clear that it has established itself as a viable option in commercially relevant applications. One should expect that there will be additional areas where Datalog will show advantages, such as data analytics.

Acknowledgments

The authors wish to thank Jeff Ullman, Raghu Ramakrishnan, Molham Aref, Moshe Vardi, Joe Hellerstein, and Serge Abiteboul for their comments on the ups and downs of Datalog. TJ Green helped early on with the structure of this chapter. Georg Gottlob and Bob Kowalski read this material and shared with us invaluable comments and critique, as did several anonymous reviewers. Special thanks is due Annie Liu for, without her gentle but persistent push and thoughtful comments, this chapter would not have been completed.

References

S. Abiteboul and C. Beeri. Oct. 1995. The power of languages for the manipulation of complex values. The VLDB Journal, 4(4):727–794. DOI: 10.1007/BF01354881. 34

S. Abiteboul and S. Grumbach. Sept. 1987. COL: A logic-based language for complex objects. In Advanced in Database Programming Languages: Proc. of the Workshop on Database Programming Languages, pp. 253–276. DOI: 10.1016/0022-0000(93)90021-N. 33

S. Abiteboul and P. C. Kanellakis. May/Jun. 1989. Object identity as a query language primitive. In ACM SIGMOD Conference on Management of Data, pp. 159–173. DOI: 0.1145/66926.66941. 33

S. Abiteboul and V. Vianu. 1990. Procedural languages for database queries and updates. Journal of Computer and System Sciences, 41(2):181–229. DOI: 10.1016/0022-0000(90)90036-K. 43

S. Abiteboul, R. Hull, and V. Vianu. 1995. Foundations of Databases. Addison-Wesley. 76

S. Abiteboul, P. Buneman, and D. Suciu. 2000. Data on the Web: From Relations to Semistructured Data and XML. Morgan Kaufmann, San Francisco, CA. 34, 36

S. Abiteboul, Z. Abrams, S. Haar, and T. Milo. 2005. Diagnosis of asynchronous discrete event systems: Datalog to the rescue! In Proc. of the Twenty-fourth ACM SIGMOD-SIGACTSIGART Symposium on Principles of Database Systems, PODS ’05, pp. 358–367. ACM. DOI: 10.1145/1065167.1065214. 82

S. Abiteboul, M. Bienvenu, A. Galland, and E. Antoine. 2011. A rule-based language for web data management. In Proc. of the Thirtieth ACM SIGMOD-SIGACT-SIGART Symposium on Principles of Database Systems, PODS ’11, pp. 293–304. ACM. DOI: 10.1145/1989284.1989320. 84

F. Afrati and S. S. Cosmadakis. 1989. Expressiveness of restricted recursive queries. In Proc. of the Twenty-first Annual ACM Symposium on Theory of Computing, STOC ’89, pp. 113–126. ACM. DOI: 10.1145/73007.73018. 77

F. Afrati, C. H. Papadimitriou, G. Papageorgiou, A. Roussou, Y. Sagiv, and J. D. Ullman. 1986. Convergence of sideways query evaluation. In ACM Symposium on Principles of Database Systems, pp. 24–30. DOI: 10.1145/6012.15400.. 42

R. Agrawal, R. Cochrane, and B. Lindsay. 1991. On maintaining priorities in a production rule system. In International Conference on Very Large Data Bases, pp. 479–487. Morgan Kaufmann, San Francisco, CA. 42

A. V. Aho and J. D. Ullman. 1979. Universality of data retrieval languages. In Proc. of the 6th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages, POPL ’79, pp. 110–119. ACM. DOI: 10.1145/567752.567763. 13, 50, 77

H. Aït-Kaci and R. Nasr. 1986. LOGIN: A logic programming language with builtin inheritance. Journal of Logic Programming, 3: 185–215. DOI: 10.1016/0743-1066(86)90013-0. 33, 34

H. Aït-Kaci and A. Podelski. Aug. 1993. Towards a meaning of LIFE. Journal of Logic Programming, 16: 195–234. DOI: 10.1016/0743-1066(93)90043-G. 33, 34

J. J. Alferes, A. Brogi, J. A. Leite, and L. M. Pereira. Sept. 2002. Evolving logic programs. In Proc. of Logics in Artificial Intelligence: 8th European Conference, pp. 50–62. Springer, Berlin, Heidelberg. DOI: 10.1007/3-540-45757-7_5. 43

M. Alviano, N. Leone, M. Manna, G. Terracina, and P. Veltri. 2012. Magic-sets for Datalog with existential quantifiers. In Proc. of the Second International Workshop on Datalog in Academia and Industry: Datalog 2.0, pp. 31–43. Springer, Berlin, Heidelberg. DOI: 10.1007/978-3-642-32925-8_5. 28

J. Anderson, M. Gaare, J. Holguín, N. Bailey, and T. Pratley. 2016. The Datomic database. In Professional Clojure, pp. 169–215. Wiley Online Library. 88

R. Angles and C. Gutierrez. 2008. The expressive power of SPARQL. In Proc. of the 7th International Conference on The Semantic Web, ISWC ’08, pp. 114–129. Springer-Verlag, Berlin, Heidelberg. DOI: 10.1007/978-3-540-88564-1_8. 76

K. R. Apt, H. A. Blair, and A. Walker. 1988. Towards a theory of declarative knowledge. In J. Minker, editor, Foundations of Deductive Databases and Logic Programming, pp. 89–148. Morgan Kaufmann Publishers Inc., San Francisco, CA, USA. DOI: 10.1016/B978-0-934613-40-8.50006-3. 19

M. Aref, B. ten Cate, T. J. Green, B. Kimelfeld, D. Olteanu, E. Pasalic, T. L. Veldhuizen, and G. Washburn. 2015. Design and implementation of the LogicBlox system. In Proc. of the 2015 ACM SIGMOD International Conference on Management of Data, SIGMOD ’15, pp. 1371–1382. ACM. DOI: 10.1145/2723372.2742796. 28, 29, 87

F. Arni, K. Ong, S. Tsur, H. Wang, and C. Zaniolo. Jan. 2003. The deductive database system LDL++. Theory and Practice of Logic Programming, 3(1):61–94. DOI: 10.1017/S1471068402001515. 67

M. P. Ashley-Rollman, S. C. Goldstein, P. Lee, T. C. Mowry, and P. Pillai. Oct. 2007. Meld: A declarative approach to programming ensembles. In 2007 IEEE/RSJ International Conference on Intelligent Robots and Systems, pp. 2794–2800. DOI: 10.1109/IROS.2007.4399480. 83

F. Baader, D. Calvanese, D. L. McGuinness, D. Nardi, and P. F. Patel-Schneider, editors. 2003. The Description Logic Handbook: Theory, Implementation, and Applications. Cambridge University Press, New York. 64, 78

F. Bancilhon. Sept. 1978. On the completeness of query languages for relational data bases. In Proc. of the 7th Symposium on Mathematical Foundations of Computer Science, pp. 112–123. DOI: 10.1007/3-540-08921-7_60. 13

F. Bancilhon and S. N. Khoshafian. Apr. 1989. A calculus for complex objects. Journal of Computer and System Sciences, 38(2):326–340. DOI: 10.1016/0022-0000(89)90005-6. 34

F. Bancilhon and R. Ramakrishnan. 1986. An amateur’s introduction to recursive query processing strategies. In Proc. of the 1986 ACM SIGMOD International Conference on Management of Data, SIGMOD ’86, pp. 16–52. ACM. DOI: 10.1145/16894.16859. 48, 60, 61

F. Bancilhon, D. Maier, Y. Sagiv, and J. D. Ullman. 1986. Magic sets and other strange ways to implement logic programs. In ACM Symposium on Principles of Database Systems, pp. 1–15. DOI: 10.1145/6012.15399. 16, 50, 51, 93

R. Basseda and M. Kifer. June 2015a. State space planning using Transaction Logic. In International Symposium on Practical Aspects of Declarative Languages (PADL 2015), pp. 17–33. DOI: 10.1007/978-3-319-19686-2_2. 46

R. Basseda and M. Kifer. Aug. 2015b. Planning with regression analysis in Transaction Logic. In Web Reasoning and Rule Systems, 9th International Conference (RR 2015), pp. 45–60. DOI: 10.1007/978-3-319-22002-4_5. 46

R. Basseda, M. Kifer, and A. J. Bonner. Sept. 2014. Planning with Transaction Logic. In 8th International Conference on Web Reasoning and Rule Systems, (RR 2014), vol. 8741 of Lecture Notes in Computer Science, pp. 29–44. Springer. DOI: 10.1007/978-3-319-11113-1_3. 46

M. Y. Becker and P. Sewell. 2004. Cassandra: Distributed access control policies with tunable expressiveness. In Proc. of the Fifth IEEE International Workshop on Policies for Distributed Systems and Networks, POLICY ’04, pp. 159–168. IEEE Computer Society. DOI: 10.1109/POLICY.2004.1309162. 82

C. Beeri. 1989. Formal models for object-oriented databases. In International Conference on Deductive and Object-Oriented Databases, pp. 370–395. Elsevier Science Publishers. DOI: 10.1016/B978-0-444-88433-6.50030-7. 34

C. Beeri and R. Ramakrishnan. 1991. On the power of magic. Journal of Logic Programming, 10(3&4):255–299. DOI: 10.1016/0743-1066(91)90038-Q. 51

C. Beeri and M. Y. Vardi. 1981. The implication problem for data dependencies. In S. Even and O. Kariv, editors, Automata, Languages and Programming: Eighth Colloquium, pp. 73–85. Springer, Berlin, Heidelberg. DOI: 10.1007/3-540-10843-2_7. 26

C. Beeri, R. Nasr, and S. Tsur. 1988. Embedding ψ-terms in a horn-clause logic language. In Third International Conference on Data and Knowledge Bases: Improving Usability and Responsiveness, pp. 347–359. Morgan Kaufmann. DOI: 10.1016/B978-1-4832-1313-2.50033-0. 33

C. Beeri, S. Naqvi, O. Shmueli, and S. Tsur. Apr. 1991. Set constructors in a logic database language. Journal of Logic Programming, 10: 181–232. DOI: 10.1016/0743-1066(91)90036-O. 33

T. Berners-Lee, J. Handler, and O. Lassila. May 2001. The Semantic Web. Scientific American. 78

D. G. Bobrow. Apr. 1980. Artificial Intelligence: Special Issue on Non-Monotonic Logic, vol. 13 no. 1-2. Elsevier. 21

H. Boley and M. Kifer, July 2013a. RIF Basic logic dialect. W3C Recommendation. Available at: http://www.w3.org/TR/rif-bld/. 78

H. Boley and M. Kifer, July 2013b. RIF Framework for logic dialects. W3C Recommendation. Available at: http://www.w3.org/TR/rif-fld/. 78

A. J. Bonner and M. Kifer. June 1993. Transaction Logic programming. In International Conference on Logic Programming, pp. 257–282. MIT Press. 43, 45

A. J. Bonner and M. Kifer. Oct. 1994. An overview of Transaction Logic. Theoretical Computer Science, 133: 205–265. DOI: 10.1016/0304-3975(94)90190-2. 43, 45

A. J. Bonner and M. Kifer. Nov. 1995. Transaction Logic programming (or a logic of declarative and procedural knowledge). Technical Report CSRI-323, University of Toronto. Available at: http://www.cs.toronto.edu/~bonner/transaction-logic.html. 45

A. J. Bonner and M. Kifer. Sept. 1996. Concurrency and communication in Transaction Logic. In Joint International Conference and Symposium on Logic Programming, pp. 142–156. MIT Press. 45

A. J. Bonner and M. Kifer. 1998a. The state of change: A survey. In Freitag et al. [1998]. Springer. 39

A. J. Bonner and M. Kifer. 1998b. Results on reasoning about action in Transaction Logic. In Freitag et al. [1998]. Springer-Verlag. 46

A. J. Bonner, M. Kifer, and M. Consens. Aug./Sept. 1993. Database programming in Transaction Logic. In Proc. of the Fourth International Workshop on Database Programming Languages, pp. 309–337. DOI: 10.1007/978-1-4471-3564-7_18. 45

G. Brewka, J. Dix, and K. Konolige. 1997. Nonmonotonic Reasoning: An Overview, vol. 73 of CSLI Lecture Notes. CSLI Publications, Stanford, CA. 21

F. Bry. Oct. 1990. Query evaluation in recursive databases: Bottom-up and top-down reconciled. Data Knowledge Engineering, 5(4):289–312. DOI: 10.1016/B978-0-444-88433-6.50010-1. 61

M. Calautti, G. Gottlob, and A. Pieris. 2015. Chase termination for guarded existential rules. In Proc. of the 34th ACM Symposium on Principles of Database Systems, PODS 2015, pp. 91–103. DOI: 10.1145/2745754.2745773. 27

A. Calì, G. Gottlob, and A. Pieris. 2011. New expressive languages for ontological query answering. In Proc. of the Twenty-Fifth AAAI Conference on Artificial Intelligence, AAAI 2011, pp. 1541–1546. 25, 28

A. Calì, G. Gottlob, and M. Kifer. 2013. Taming the infinite chase: Query answering under expressive relational constraints. Journal of Artificial Intelligence Research, 48: 115–174. 26, 28

M. J. Carey, D. J. DeWitt, J. E. Richardson, and E. J. Shekita. 1986. Object and file management in the EXODUS extensible database system. In Proc. of the 12th International Conference on Very Large Data Bases, VLDB ’86, pp. 91–100. Morgan Kaufmann Publishers Inc., San Francisco, CA. 68

M. Carlsson et al. 2015. SICStus Prolog User’s Manual. RISE SICS AB, Kista, Sweden. http://sicstus.sics.se/sicstus/docs/latest4/pdf/sicstus.pdf. 33

S. Ceri and L. Tanca. 1987. Optimization of systems of algebraic equations for evaluating Datalog queries. In Proc. of the 13th International Conference on Very Large Data Bases, VLDB ’87, pp. 31–41. Morgan Kaufmann Publishers Inc., San Francisco, CA. 63

S. Ceri, G. Gottlob, and L. Lavazza. 1986. Translation and optimization of logic queries: The algebraic approach. In Proc. of the 12th International Conference on Very Large Data Bases, VLDB ’86, pp. 395–402. Morgan Kaufmann Publishers Inc., San Francisco, CA. 63

S. Ceri, G. Gottlob, and G. Wiederhold. Feb. 1989. Efficient database access from Prolog. IEEE Trans. on Software Engineering, 15(2):153–164. DOI: 10.1109/32.21742. 63

U. S. Chakravarthy, J. Grant, and J. Minker. June 1990. Logic-based approach to semantic query optimization. ACM Trans. on Database Systems, 15(2):162–207. DOI: 10.1145/78922.78924. 31

A. Chandra and D. Harel. Apr. 1985. Horn clause queries and generalizations. Journal of Logic Programming, 2(1):1–15. DOI: 10.1016/0743-1066(85)90002-0. 77

C. Chang. 1977. DEDUCE 2: Further investigations of deduction in relational data bases. In H. Gallaire and J. Minker, editors, Logic and Data Bases, pp. 201–236, Plenum Press, New York. DOI: 10.1007/978-1-4684-3384-5_8. 13, 63

S. Chaudhuri. 1998. An overview of query optimization in relational systems. In Proc. of the Seventeenth ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, pp. 34–43. ACM Press. 64

S. Chaudhuri and M. Y. Vardi. 1992. On the equivalence of recursive and nonrecursive datalog programs. In Proc. of the Eleventh ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, PODS ’92, pp. 55–66. ACM. DOI: 10.1006/jcss.1997.1452. 64

W. Chen and D. S. Warren. Mar. 1989. C-logic for complex objects. In ACM Symposium on Principles of Database Systems, pp. 369–378. ACM. DOI: 10.1145/73721.73757. 33

W. Chen and D. S. Warren. Jan. 1996. Tabled evaluation with delaying for general logic programs. JACM, 43(1):20–74. DOI: 10.1145/227595.227597. 21, 59, 71

W. Chen, M. Kifer, and D. S. Warren. June 1989a. HiLog as a platform for database programming languages (or why predicate calculus is not enough). In Proc. of the Second International Workshop on Database Programming Languages, pp. 315–329. 37

W. Chen, M. Kifer, and D. S. Warren. Oct. 1989b. HiLog: A first-order semantics for higher-order logic programming constructs. In North American Conference on Logic Programming, pp. 1090–1114. MIT Press, Cambridge, MA. 37

W. Chen, M. Kifer, and D. S. Warren. Feb. 1993. HiLog: A foundation for higher-order logic programming. Journal of Logic Programming, 15(3):187–230. DOI: 10.1016/0743-1066(93)90039-J. 37, 38

D. Chimenti, R. Gamboa, R. Krishnamurthy, S. Naqvi, S. Tsur, and C. Zaniolo. Mar. 1990. The LDL system prototype. IEEE Trans. on Knowledge and Data Engineering, 2(1):76–90. DOI: 10.1109/69.50907. 66

B. Chin, D. von Dincklage, V. Ercegovac, P. Hawkins, M. S. Miller, F. Och, C. Olston, and F. Pereira. 2015. Yedalog: Exploring knowledge at scale. In 1st Summit on Advances in Programming Languages (SNAPL 2015), pp. 63–78. 83

J. Chomicki. 1990. Polynomial time query processing in temporal deductive databases. In ACM Symposium on Principles of Database Systems, pp. 379–391. DOI: 10.1145/298514.298589. 41

K. L. Clark. 1978. Negation as failure. In H. Gallaire and J. Minker, editors, Logic and Data Bases, pp. 293-322, Plenum Press, New York. 18

Coherent Knowledge LLC, 2017. Ergo Suite. Available at: http://coherentknowledge.com/. 28, 34, 38

A. Colmerauer and P. Roussel. 1996. The birth of Prolog. In T. J. Bergin, Jr. and R. G. Gibson, Jr., editors, History of Programming Languages—II, pp. 331–367. ACM. DOI: 10.1145/154766.155362. 11

N. Conway, W. R. Marczak, P. Alvaro, J. M. Hellerstein, and D. Maier. 2012. Logic and lattices for distributed programming. In Proc. of the Third ACM Symposium on Cloud Computing, SoCC ’12, pp. 1:1–1:14. ACM. DOI: 10.1145/2391229.2391230. 25

C. Cornelio, A. Loreggia, and V. Saraswat. 2015. Logical conditional preference theories. Technical report, T.J. Watson Research Center. arXiv preprint: 1504.06374. 24

S. S. Cosmadakis, H. Gaifman, P. C. Kanellakis, and M. Y. Vardi. 1988. Decidable optimization problems for database logic programs (preliminary report). In Proc. of the 20th Annual ACM Symposium on Theory of Computing, pp. 477–490. DOI: 10.1145/62212.62259. 64

V. S. Costa, R. Rocha, and L. Damas. 2012. The YAP Prolog system. Theory and Practice of Logic Programming, 12(1-2):5–34. DOI: 10.1017/S1471068411000512. 52

F. Cuppens and R. Demolombe. 1988. A Prolog-relational DBMS interface using delayed evaluation. In Proc. of the Third International Conference on Data and Knowledge Bases: Improving Usability and Responsiveness, pp. 135–148. DOI: 10.1016/B978-1-4832-1313-2.50018-4. 63

B. P. L. da Silva, J.-F. Baget, and M. Croitoru. 2012. A generic platform for ontological query answering. In M. Bramer and M. Petridis, editors, Proc. of AI-2012, The Thirty-second SGAI International Conference on Innovative Techniques and Applications of Artificial Intelligence, pp. 151–164. Springer London, London, UK. DOI: 10.1007/978-1-4471-4739-8_11. 28

V. Dahl. Mar. 1982. On database systems development through logic. ACM Trans. on Database Systems, 7(1):102–123. DOI: 10.1145/319682.319700. 14

V. Dahl. 1986. Logic programming for constructive expert database systems. In Proc. from the First International Workshop on Expert Database Systems, pp. 209–217. Benjamin-Cummings Publishing Co., Inc., Redwood City, CA. 14

E. Dantsin, T. Eiter, G. Gottlob, and A. Voronkov. Sept. 2001. Complexity and expressive power of logic programming. ACM Computing Surveys, 33(3):374–425. DOI: 10.1145/502807.502810. 77

R. Davis. Feb. 1986. Knowledge-based systems. Science, 231(4741):957–964. 14

O. de Moor, M. Verbaere, E. Hajiyev, P. Avgustinov, T. Ekman, N. Ongkingco, D. Sereni, and J. Tibble. 2007. Keynote address: .QL for source code analysis. In Proc. of the Seventh IEEE International Working Conference on Source Code Analysis and Manipulation, SCAM ’07, pp. 3–16. IEEE Computer Society. DOI: 10.1109/SCAM.2007.31. 79, 80

C. de Sainte Marie, G. Hallmark, and A. Paschke, Feb. 2013. RIF production rule dialect. W3C Recommendation. Available at: http://www.w3.org/TR/rif-prd/. 42

H. Decker. 1986. Integrity enforcement on deductive databases. In Proc. of the Expert Database Conference, pp. 381–395. 31

S. Decker, D. Brickley, J. Saarela, and J. Angele. Dec. 1998. A query and inference service for RDF. In QL’98—The Query Languages Workshop. 78

M. Denecker, M. Bruynooghe, and V. W. Marek. 2001. Logic programming revisited: Logic programs as inductive definitions. ACM Trans. Comput. Log., 2(4):623–654. DOI: 10.1145/383779.383789. 22

M. A. Derr, S. Morishita, and G. Phipps. Apr. 1994. The Glue-Nail deductive database system: Design, implementation, and evaluation. The VLDB Journal, 3(2):123–160. DOI: 10.1007/BF01228879. 68

A. Deutsch, A. Nash, and J. Remmel. 2008. The chase revisited. In Proc. of the Twenty-seventh ACM SIGMOD-SIGACT-SIGART Symposium on Principles of Database Systems, PODS ’08, pp. 149–158. ACM. DOI: 10.1145/1376916.1376938. 26, 27

S. W. Dietrich. 1987. Extension tables: Memo relations in logic programming. In Proc. of the 1987 Symposium on Logic Programming, pp. 264–272. 59

S. W. Dietrich and D. S. Warren. 1986. Extension tables: Memo relations in logic programming. Technical Report 86/18, Dept. of Computer Science, SUNY at Stony Brook. 59

C. Draxler. Aug. 1993. A powerful Prolog to SQL compiler. Technical report, CIS Centre for Information Processing. 63

T. Eiter, G. Gottlob, and H. Mannila. Sept. 1997. Disjunctive Datalog. ACM Trans. Database Syst., 22(3):364–418. DOI: 10.1145/261124.261126. 22

T. Eiter, T. Lukasiewicz, R. Schindlauer, and H. Tompits. June 2004a. Combining answer set programming with description logics for the semantic web. In Proc. of the International Conference of Knowledge Representation and Reasoning (KR’04), pp. 141–151. DOI: 10.1016/j.artint.2008.04.002. 78

T. Eiter, T. Lukasiewicz, R. Schindlauer, and H. Tompits. Oct. 2004b. Well-founded semantics for description logic programs in the semantic Web. In Rules and Rule Markup Languages for the Semantic Web, pp. 81–97. DOI: 10.1007/978-3-540-30504-0_7. 78

T. Feder and M. Y. Vardi. Feb. 1999. The computational structure of monotone monadic SNP and constraint satisfaction: A study through Datalog and group theory. SIAM J. Computing, 28(1):57–104. DOI: 10.1137/S0097539794266766. 77

C. Fellenstein, C. O. Green, L. M. Palmer, A. Walker, and D. J. Wyler. July 1985. A prototype manufacturing knowledge base in Syllog. IBM Journal of Research and Development, 29(4):413–421. DOI: 10.1147/rd.294.0413. 14

N. V. Findler, editor. 1979. Associative Networks: The Representation and Use of Knowledge by Computers. Academic Press, Inc., Orlando, FL, USA. 14

P. Fodor and M. Kifer. July 2011. Transaction Logic with defaults and argumentation theories. In International Conference on Logic Programming, pp. 162–174. DOI: 10.4230/LIPIcs.ICLP.2011.162. 45

M. Freeston. 1987. The BANG file: A new kind of grid file. In Proc. of the 1987 ACM SIGMOD International Conference on Management of Data, SIGMOD ’87, pp. 260–269. ACM. DOI: 10.1145/38714.38743. 69

J. Freire, T. Swift, and D. S. Warren. July 1997. Taking I/O seriously: Resolution reconsidered for disk. In Proc. of the Joint Conference and Symposium on Logic Programming, pp. 198–212. MIT Press. 72

B. Freitag, H. Schütz, and G. Specht. 1992. LOLA—a logic language for deductive databases and its implementation. In Proc. of the Second International Symposium on Database Systems for Advanced Applications, pp. 216–225. World Scientific Press. 73

B. Freitag, H. Decker, M. Kifer, and A. Voronkov, editors. 1998. Transactions and Change in Logic Databases, vol. 1472 of LNCS. Springer-Verlag, Berlin. 103

J. Frohn, R. Himmeröder, G. Lausen, W. May, and C. Schlepphorst. 1998. Managing semistructured data with FLORID: A deductive object-oriented perspective. Information Systems, 23(8):589–613. 34, 36, 73

K. Fuchi. 1981. Aiming for knowledge information processing systems. In Proc. of the International Conference on Fifth Generation Computer Systems, pp. 110–117. 12

K. Fuchi and K. Furukawa. Apr. 1987. The role of logic programming in the Fifth Generation Computer Project. New Generation Computing, 5(1):3–28. DOI: 10.1007/BF03037455. 12

T. Furche, G. Gottlob, G. Grasso, X. Guo, G. Orsi, C. Schallhart, and C. Wang. Oct. 2014. DIADEM: Thousands of websites to a single database. Proc. VLDB Endow., 7(14):1845–1856. DOI: 10.14778/2733085.2733091. 83

F. Furfaro, S. Greco, S. Ganguly, and C. Zaniolo. 2002. Pushing extrema aggregates to optimize logic queries. Information Systems, 27(5):321–343. DOI: 10.1016/S0306-4379(02)00006-6. 82

H. Gaifman, H. G. Mairson, Y. Sagiv, and M. Y. Vardi. 1993. Undecidable optimization problems for database logic programs. J. ACM, 40(3):683–713. DOI: 10.1145/174130.174142. 64

H. Gallaire and J. Minker, editors. 1978. Logic and Data Bases, Symposium on Logic and Data Bases, Advances in Data Base Theory, Plenum Press, New York.

H. Gallaire, J. Nicolas, and J. Minker, editors. 1981. Advances in Data Base Theory, Vol. 1, Based on the Proc. of the Workshop on Formal Bases for Data Bases, Advances in Data Base Theory, Plenum Press, New York.

H. Garcia-Molina, J. D. Ullman, and J. Widom. 2009. Database Systems: The Complete Book (2nd ed.). Pearson Education. 6

M. Gelfond and V. Lifschitz. 1988. The stable model semantics for logic programming. In Logic Programming: Proc. of the Fifth Conference and Symposium, pp. 1070–1080. MIT Press. 20, 21

R. G. Goebel. 1985. A Logic Data Model for the Machine Representation of Knowledge. Ph.D. thesis, University of British Columbia. 14

J. E. Gonzalez, R. S. Xin, A. Dave, D. Crankshaw, M. J. Franklin, and I. Stoica. 2014. GraphX: Graph processing in a distributed dataflow framework. In Proceedings of the 11th USENIX Conference on Operating Systems Design and Implementation, OSDI’14, pp. 599–613. USENIX Association, Berkeley, CA. 83

G. Gottlob and C. Koch. Jan. 2004. Monadic datalog and the expressive power of languages for Web information extraction. J. ACM, 51(1):74–113. DOI: 10.1145/962446.962450. 77

G. Gottlob and C. H. Papadimitriou. 1999. On the complexity of single-rule datalog queries. In Proc. of the 6th International Conference on Logic Programming and Automated Reasoning, LPAR ’99, pp. 201–222. Springer-Verlag, London, UK. DOI: 10.1007/3-540-48242-3_13. 77

G. Gottlob, S. Ceri, and L. Tanca. Mar. 1989. What you always wanted to know about Datalog (and never dared to ask). IEEE Trans. on Knowledge & Data Engineering, 1(1):146–166. DOI: 10.1109/69.43410. 60

G. Gottlob, C. Koch, R. Baumgartner, M. Herzog, and S. Flesca. 2004. The Lixto data extraction project: Back and forth between theory and practice. In Proc. of the Twentythird ACM SIGMOD-SIGACT-SIGART Symposium on Principles of Database Systems, PODS ’04, pp. 1–12. ACM. DOI: 10.1145/1055558.1055560. 83

G. Gottlob, M. Manna, and A. Pieris. 2013. Combining decidability paradigms for existential rules. TPLP, 13(4-5):877–892. DOI: 10.1017/S1471068413000550. 28

G. Gottlob, T. Lukasiewicz, and A. Pieris. 2014. Datalog±: Questions and answers. In Proc. of the Fourteenth International Conference on Principles of Knowledge Representation and Reasoning, KR 2014, pp. 682–685. 25

J. Grant and J. Minker. 1981. Optimization in deductive and conventional relational database systems. In H. Gallaire, J. Nicolas, and J. Minker, editors, Advances in Data Base Theory, pp. 195-234, Vol. 1. Plenum Press, New York. DOI: 10.1007/978-1-4615-8297-7_8. 63

B. C. Grau, I. Horrocks, B. Motik, B. Parsia, P. Patel-Schneider, and U. Sattler. Nov. 2008. OWL 2: The next step for OWL. Web Semantics, 6(4):309–322. DOI: 10.1016/j.websem.2008.05.001. 78

C. C. Green. 1969. Application of theorem proving to problem solving. In International Joint Conference on Artificial Intelligence, pp. 219–240. 14, 41

C. C. Green and B. Raphael. 1968. The use of theorem-proving techniques in question-answering systems. In Proc. of the 1968 23rd ACM National Conference, ACM ’68, pp. 169–181. ACM. DOI: 10.1145/800186.810578. 13

B. Grosof and T. Swift. July 2013. Radial restraint: A semantically clean approach to bounded rationality for logic programs. In AAAI Conference on Artificial Intelligence. AAAI Press. 28

R. V. Guha, O. Lassila, E. Miler, and D. Brickley. Dec. 1998. Enabling inferencing. In QL’98—The Query Languages Workshop. 78

H. Guo and G. Gupta. Nov. 2001. A simple scheme for implementing tabled logic programming systems based on dynamic reordering of alternatives. In Proc. of the 17th International Conference on Logic Programming, ICLP 2001, pp. 181–196. DOI: 10.1007/3-540-45635-X_20. 59

L. M. Haas, J. C. Freytag, G. M. Lohman, and H. Pirahesh. 1989. Extensible query processing in Starburst. In Proc. of the 1989 ACM SIGMOD International Conference on Management of Data, SIGMOD ’89, pp. 377–388. ACM. DOI: 10.1145/67544.66962. 73

C. D. Hafner and K. Godden. Apr. 1985. Portability of syntax and semantics in DATALOG. ACM Trans. on Information Systems, 3(2):141–164. DOI: 10.1145/3914.3982. 16

E. Hajiyev, M. Verbaere, and O. de Moor. 2006. CodeQuest: Scalable source code queries with Datalog. In Proc. of the 20th European Conference on Object-Oriented Programming, ECOOP’06, pp. 2–27. Springer-Verlag, Berlin, Heidelberg. DOI: 10.1007/11785477_2. 79

D. Harel. 1979. First-Order Dynamic Logic, vol. 68 of Lecture Notes in Computer Science. Springer-Verlag. DOI: 10.1007/3-540-09237-4. 39

D. Harel, D. Kozen, and R. Parikh. Oct. 1982. Process Logic: Expressiveness, decidability, completeness. Journal of Computer and System Sciences, 25(2):144–170. DOI: 10.1016/0022-0000(82)90003-4. 39

P. J. Hayes. 1977. In defence of logic. In Proc. of the 5th International Joint Conference on Artificial Intelligence, Vol. 1, IJCAI’77, pp. 559–565. Morgan Kaufmann Publishers Inc., San Francisco, CA. 14

P. J. Hayes. 1980. The logic of frames. In Frame Conceptions and Text Understanding, pp. 46–61. Walter de Gruyter, Berlin. DOI: 10.1016/B978-0-934613-03-3.50034-9. 14

A. Heuer and P. Sander. 1989. Semantics and evaluation of rules over complex objects. In International Conference on Deductive and Object-Oriented Databases, pp. 439–458. DOI: 10.1016/B978-0-444-88433-6.50033-2. 33

M. A. W. Houtsma and P. M. G. Apers. 1992. Algebraic optimization of recursive queries. Data & Knowledge Engineering, 7(4):299–325. DOI: 10.1016/0169-023X(92)90029-B. 63

N. Immerman. 1982. Relational queries computable in polynomial time (extended abstract). In Proceedings of the Fourteenth Annual ACM Symposium on Theory of Computing, STOC ’82, pp. 147–152. ACM. DOI: 10.1145/800070.802187. 77

Y. E. Ioannidis, J. Chen, M. A. Friedman, and M. M. Tsangaris. 1988. Bermuda—an architectural perspective on interfacing Prolog to a database machine. In Expert Database Conference, pp. 229–255. 63

Z. G. Ives, T. J. Green, G. Karvounarakis, N. E. Taylor, V. Tannen, P. P. Talukdar, M. Jacob, and F. Pereira. Sept. 2008. The ORCHESTRA collaborative data sharing system. SIGMOD Rec., 37(3):26–32. DOI: 10.1145/1462571.1462577. 83

D. S. Johnson and A. Klug. 1984. Testing containment of conjunctive queries under functional and inclusion dependencies. Journal of Computer and System Sciences, 28: 167–189. DOI: 10.1016/0022-0000(84)90081-3. 27, 28, 32

N. D. Jones, C. K. Gomard, and P. Sestoft. 1993. Partial Evaluation and Automatic Program Generation. Prentice-Hall, Inc., Upper Saddle River, NJ. 51

C. Kellogg, P. Klahr, and L. Travis. 1977. Deductive planning and pathfinding for relational data bases. In H. Gallaire and J. Minker, editors, Logic and Data Bases, pp. 179-200, Plenum Press, New York. DOI: 10.1007/978-1-4684-3384-5_7. 13, 63

D. B. Kemp and P. J. Stuckey. Oct. 1991. Semantics of logic programs with aggregates. In Proc. of International Symposium on Logic Programming, pp. 387–401. MIT Press. 24

L. Kerschberg. 1990. Expert database systems: Knowledge/data management environments for intelligent information systems. Information Systems, 15(1):151–160. DOI: 10.1016/0306-4379(90)90021-G. 14

G. Kiernan, C. de Maindreville, and E. Simon. 1990. Making deductive databases a practical technology: A step forward. In Proc. of the 1990 ACM SIGMOD International Conference on Management of Data, SIGMOD ’90, pp. 237–246. ACM. DOI: 10.1145/93605.98733. 73

W. Kießling, H. Schmidt, W. Strauß, and G. Dünzinger. Apr. 1994. DECLARE and SDS: Early efforts to commercialize deductive database technology. The VLDB Journal, 3(2):211–243. 72

M. Kifer, 2015. Knowledge representation & reasoning with Flora-2. The Flora-2 Web Site. Available at: http://flora.sourceforge.net. 34, 38, 46, 91

M. Kifer and G. Lausen. 1989. F-Logic: A higher-order language for reasoning about objects, inheritance and schema. In ACM SIGMOD Conference on Management of Data, pp. 134–146. ACM. DOI: 10.1145/66926.66939. 33, 34

M. Kifer and A. Li. Sept. 1988. On the semantics of rule based expert systems with uncertainty. In International Conference on Database Theory, vol. 326 of Lecture Notes in Computer Science, pp. 186–202. Springer-Verlag. DOI: 10.1007/3-540-50171-1_6. 14

M. Kifer and E. L. Lozinskii. Feb. 1987. Implementing logic programs as a database system. In IEEE 3rd International Conference on Data Engineering, pp. 375–385. DOI: 10.1109/ICDE.1987.7272403. 51

M. Kifer and E. L. Lozinskii. 1988. SYGRAF: Implementing logic programs in a database style. IEEE Trans. on Software Engineering, 14(7):922–935. DOI: 10.1109/32.42735. 51

M. Kifer and E. L. Lozinskii. Sept. 1990. On compile-time query optimization in deductive databases by means of static filtering. ACM Trans. on Database Systems, 15(3):385–426. DOI: 10.1145/88636.87121. 51

M. Kifer and J. Wu. Mar. 1989. A logic for object-oriented logic programming (Maier’s Ologic revisited). In ACM Symposium on Principles of Database Systems, pp. 379–393. ACM. DOI: 10.1145/73721.73758. 33, 34

M. Kifer and J. Wu. Aug. 1993. A logic for programming with complex objects. Journal of Computer and System Sciences, 47(1):77–120. 34

M. Kifer, G. Lausen, and J. Wu. July 1995. Logical foundations of object-oriented and framebased languages. Journal of ACM, 42: 741–843. DOI: 10.1145/210332.210335. 33, 34, 35

R. A. Kowalski. June 1974. Predicate logic as programming language. In Proceedings of the IFIP Congress, vol. 74, pp. 569–544. 11

R. A. Kowalski. Jan. 1988. The early years of logic programming. Commun. ACM, 31(1):38–43. DOI: 10.1145/35043.35046. 11

R. A. Kowalski. 2014. Logic programming. In J. Siekmann, editor, Computational Logic, vol. 9 of History of Logic. D. Gabbay and J. Woods, editors, pp. 523–569. Elsevier. 12

R. A. Kowalski and F. Sadri. 2012. A logic-based framework for reactive systems. In Rules on the Web: Research and Applications, RuleML 2012, vol. 7438 of Lecture Notes in Computer Science, pp. 1–15. Springer. DOI: 10.1007/978-3-642-32689-9_1. 43

R. A. Kowalski and M. Sergot. 1986. A logic-based calculus of events. New Generation Computing, 4: 67–95. DOI: 10.1007/BF03037383. 41

R. A. Kowalski, F. Sadri, and P. Soper. 1987. Integrity checking in deductive databases. In Proc. of the 13th International Conference on Very Large Data Bases, VLDB ’87, pp. 61–69. Morgan Kaufmann Publishers Inc., San Francisco, CA. 29, 31

L. V. S. Lakshmanan and R. Missaoui. 1992. On semantic query optimization in deductive databases. In Proc. of the Eighth International Conference on Data Engineering, pp. 368–375. IEEE Computer Society. DOI: 10.1109/ICDE.1992.213173. 32

L. V. S. Lakshmanan, I. N. Subramanian, and F. Sadri. 1996. A declarative language for querying and restructuring the Web. In Proc. of the 6th International Workshop on Research Issues in Data Engineering (RIDE ’96) Interoperability of Nontraditional Database Systems, RIDE ’96, pp. 12–21. IEEE Computer Society. DOI: 10.1109/RIDE.1996.492238. 36, 73

M. S. Lam, J. Whaley, V. B. Livshits, M. C. Martin, D. Avots, M. Carbin, and C. Unkel. 2005. Context-sensitive program analysis as database queries. In Proc. of the Twenty-fourth ACM SIGMOD-SIGACT-SIGART Symposium on Principles of Database Systems, PODS ’05, pp. 1–12. ACM. DOI: 10.1145/1065167.1065169. 79, 80

M. S. Lam, S. Guo, and J. Seo. 2013. SociaLite: Datalog extensions for efficient social network analysis. In Proc. of the 2013 IEEE International Conference on Data Engineering (ICDE 2013), ICDE ’13, pp. 278–289. IEEE Computer Society. DOI: 10.1109/ICDE.2013.6544832. 82

O. Lassila and R. R. Swick. Feb. 1999. Resource description framework (RDF) model and syntax specification. Technical report, W3C. Available at: http://www.w3.org/TR/1999/REC-rdf-syntax-19990222/. 34, 78

G. Lausen and B. Ludäascher. 1995. Updates by reasoning about states. In Eder J., Kalinichenko L.A. (editors) East/West Database Workshop. Workshops in Computing. Springer, London. 41

S. Lee and J. Han. 1988. Semantic query optimization in recursive databases. In Proc. of the Fourth International Conference on Data Engineering, pp. 444–451. IEEE Computer Society. DOI: 10.1109/ICDE.1988.105490. 32

N. Leone, G. Pfeifer, W. Faber, T. Eiter, G. Gottlob, S. Perri, and F. Scarcello. July 2006. The DLV system for knowledge representation and reasoning. ACM Trans. on Computational Logic, 7(3):499–562. DOI: 10.1145/1149114.1149117. 83

A. Y. Levy and Y. Sagiv. 1995. Semantic query optimization in datalog programs (extended abstract). In Proc. of the Fourteenth ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, PODS ’95, pp. 163–173. ACM. DOI: 10.1145/212433.220207. 32

Y. A. Liu and S. D. Stoller. 2009. From Datalog rules to efficient programs with time and space guarantees. ACM Trans. Prog. Lang. Syst., 31(6):1–38. DOI: 10.1145/1552309.1552311. 49, 52, 535

Y. A. Liu and S. D. Stoller. Jan. 2018. Founded semantics and constraint semantics of logic rules. In International Symposium on Logical Foundations of Computer Science, vol. 10703 of Lecture Notes in Computer Science, pp. 221–241. Springer. DOI: 10.1007/978-3-319-72056-2_14. 22

J. W. Lloyd. 1993. Foundations of Logic Programming, 2nd. Springer-Verlag New York, Inc., Secaucus, NJ. 9, 11

J. W. Lloyd, L. Sonenberg, and R. W. Topor. 1987. Integrity constraint checking in stratified databases. Journal of Logic Programming, 4(4):331–343. DOI: 10.1016/0743-1066(87)90009-4. 30

B. T. Loo, T. Condie, J. M. Hellerstein, P. Maniatis, T. Roscoe, and I. Stoica. 2005. Implementing declarative overlays. In Proc. of the Twentieth ACM Symposium on Operating Systems Principles, SOSP ’05, pp. 75–90. ACM. DOI: 10.1145/1095809.1095818. 81

B. T. Loo, T. Condie, M. Garofalakis, D. E. Gay, J. M. Hellerstein, P. Maniatis, R. Ramakrishnan, T. Roscoe, and I. Stoica. 2006. Declarative networking: Language, execution and optimization. In Proc. of the 2006 ACM SIGMOD International Conference on Management of Data, SIGMOD ’06, pp. 97–108. ACM. DOI: 10.1145/1142473.1142485. 80, 81

B. T. Loo, T. Condie, M. Garofalakis, D. E. Gay, J. M. Hellerstein, P. Maniatis, R. Ramakrishnan, T. Roscoe, and I. Stoica. Nov. 2009. Declarative networking. Commun. ACM, 52(11):87–95. DOI: 10.1145/1592761.1592785. 80

D. Maier. Aug. 1986a. A logic for objects. In Workshop on Foundations of Deductive Databases and Logic Programming, pp. 6–26. Washington D.C. 33, 34

D. Maier. 1986b. Databases in the Fifth Generation project: Is Prolog a database language? In G. Ariav and J. Clifford, editors, New Directions for Database Systems, pp. 18–34. Ablex Publishing Corporation. 12

D. Maier and D. S. Warren. 1981. Incorporating computed relations in relational databases. In Proc. of the 1981 ACM SIGMOD International Conference on Management of Data, SIGMOD ’81, pp. 176–187. ACM. DOI: 10.1145/582318.582345. 23

D. Maier and D. S. Warren. 1988. Computing with Logic: Logic Programming with Prolog. Benjamin/Cummings. 15

D. Maier, A. O. Mendelzon, and Y. Sagiv. 1979. Testing implications of data dependencies. Trans. Database Syst., 4(4):455–469. DOI: 10.1145/320107.320115. 27

F. Maier, D. Nute, W. D. Potter, J. Wang, M. J. Twery, H. M. Rauscher, P. Knopp, S. Thomasma, M. Dass, and H. Uchiyama. 2002. PROLOG/RDBMS integration in the NED intelligent information system. In On the Move to Meaningful Internet Systems, 2002—DOA/CoopIS/ODBASE Proc. of the Confederated International Conferences DOA, CoopIS and ODBASE, p. 528. DOI: 10.1007/3-540-36124-3_35. 63

V. W. Marek and M. Truszczyński. 1999. Stable models and an alternative logic programming paradigm. In K. R. Apt, V. W. Marek, M. Truszczynski, and D. S. Warren, editors, The Logic Programming Paradigm: A 25-Year Perspective, pp. 375–398. Springer, Berlin, Heidelberg. DOI: 10.1007/978-3-642-60085-2_17. 22

D. Martinenghi, H. Christiansen, and H. Decker. 2006. Integrity checking and maintenance in relational and deductive databases and beyond. In Z. Ma, editor, Intelligent Databases: Technologies and Applications, pp. 238–285. Idea Group Publishing. DOI: 10.4018/978-1-59904-120-9.ch010. 30, 31

MathGen, 2000. Mathematics Genealogy Project. Available at: http://genealogy.math.ndsu.nodak.edu/. Last accessed 1 August 2016. 84

F. G. McCabe. 1992. Logic and Objects. Prentice Hall International, London, England. 33

J. M. McCarthy and P. J. Hayes. 1969. Some philosophical problems from the standpoint of artificial intelligence. In B. Meltzer and D. Michie, editors, Machine Intelligence, vol. 4, pp. 463–502. Edinburgh University Press. Reprinted in Readings in Artificial Intelligence, 1981, Tioga Publishing Co. DOI: 10.1016/B978-0-934613-03-3.50033-7. 40

D. A. Miller and G. Nadathur. July 1986. Higher-order logic programming. In International Conference on Logic Programming, vol. 225 of Lecture Notes in Computer Science, pp. 448–462. Springer-Verlag. 38

J. Minker. 1977. An experimental relational data base system based on logic. In H. Gallaire and J. Minker, editors, Logic and Data Bases, pp. 107-147, Plenum Press, New York. DOI: 10.1007/978-1-4684-3384-5_5. 13

J. Minker. Mar. 1994. Overview of disjunctive logic programming. Annals of Mathematics and Artificial Intelligence, 12(1): 1–24. DOI: 10.1007/BF01530759. 22

J. Minker and D. Seipel. 2002. Disjunctive logic programming: A survey and assessment. In Computational Logic: Logic Programming and Beyond, pp. 171–197. Springer. DOI: 10.1007/3-540-45628-7_18. 22

J. Minker, D. Seipel, and C. Zaniolo. 2014. Logic and databases: A history of deductive databases. In J. H. Siekmann, editor, Computational Logic, vol. 9 of Handbook of the History of Logic, pp. 571–627. Elsevier. DOI: 10.1016/B978-0-444-51624-4.50013-7. 13, 15

M. Minsky. 1975. A framework for representing knowledge. In P. Winston, editor, The Psychology of Computer Vision, pp. 211–277. McGraw-Hill, New York. 14, 35

S. Morishita. 1993. An alternating fixpoint tailored to magic programs. In Proc. of the Twelfth ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, PODS ’93, pp. 123–134. ACM. DOI: 10.1145/153850.153861. 69

K. A. Morris, J. D. Ullman, and A. Van Gelder. 1986. Design overview of the NAIL! system. In Proc. of the Third International Conference on Logic Programming, pp. 554–568. Springer-Verlag, London, UK. DOI: 10.1007/3-540-16492-8_104. 68

C. Moss. 1994. Prolog++: The Power of Object-Oriented and Logic Programming. Addison-Wesley. 33

B. Motik, I. Horrocks, R. Rosati, and U. Sattler. Nov. 2006. Can OWL and logic programming live together happily ever after? In International Semantic Web Conference (ISWC2006), pp. 501–514. DOI: 10.1007/11926078_36. 78

T. Moto-oka and H. S. Stone. Mar. 1984. Fifth-generation computer systems: A Japanese project. Computer, 17(3):6–13. DOI: 10.1109/MC.1984.1659076. 12, 48

P. Moura. July 2000. Logtalk documentation. Technical Report DMI-2000/1, University of Beira Interior, Portugal. Available at: http://logtalk.org/papers/trdmi20001us.pdf. 33

P. Moura, P. Crocker, and P. Nunes. Jan. 2008. High-level multi-threading programming in logtalk. In Practical Aspects of Declarative Languages (PADL), vol. 4902 of Lecture Notes in Computer Science. Springer. DOI: 10.1007/978-3-540-77442-6_18. 33

I. S. Mumick and H. Pirahesh. May 1994. Implementation of Magic-sets in a relational database system. SIGMOD Rec., 23(2):103–114. DOI: 10.1145/191839.191860. 73

S. Naqvi and R. Krishnamurthy. Mar. 1988. Database updates in logic programming. In ACM Symposium on Principles of Database Systems, pp. 251–262. ACM. DOI: 10.1145/308386.308451. 46

S. Naqvi and S. Tsur. 1989. A Logical Language for Data and Knowledge Bases. Computer Science Press, Rockville, MD. 46

J. Naughton. 1986. Data independent recursion in deductive databases. In Proc. of the Fifth ACM SIGACT-SIGMOD Symposium on Principles of Database Systems, PODS ’86, pp. 267–279. ACM. DOI: 10.1145/6012.15420. 64

W. Nejdl. 1987. Recursive strategies for answering recursive queries—the RQA/FQI strategy. In Proc. of the 13th International Conference on Very Large Data Bases, VLDB ’87, pp. 43–50. Morgan Kaufmann Publishers Inc., San Francisco, CA. 60

J. Nicolas and H. Gallaire. 1977. Data base: Theory vs. interpretation. In H. Gallaire and J. Minker, editors, Logic and Data Bases, pp. 33-54, Plenum Press, New York. 13, 19

J. Nicolas and K. Yazdanian. 1977. Integrity checking in deductive data bases. In H. Gallaire and J. Minker, editors, Logic and Data Bases, pp. 325-344, Plenum Press, New York. 29

C. H. Papadimitriou. 1985. A note the expressive power of Prolog. Bulletin of the EATCS, 26: 21–22. 77

J. Paredaens. 1978. On the expressive power of the relational algebra. Information Processing Letters, 7(2):107–111. DOI: 10.1016/0020-0190(78)90055-8. 13

N. Pelov, M. Denecker, and M. Bruynooghe. May 2007. Well-founded and stable semantics of logic programs with aggregates. Theory and Practice of Logic Programming, 7(03):301–353. DOI: 10.1017/S1471068406002973. 24

A. Polleres. 2007. From SPARQL to rules (and back). In Proc. of the 16th International Conference on World Wide Web, WWW ’07, pp. 787–796. ACM. DOI: 10.1145/1242572.1242679. 76

H. H. Porter, Oct. 1985. Optimizations to Earley deduction for DATALOG programs. Available at: http://www.cs.pdx.edu/~harry/earley/datalog.pdf. 16

E. Prud’hommeaux, A. Seaborne, et al. 2008. SPARQL query language for RDF. W3C recommendation 15 January 2008. http://www.w3.org/TR/rdf-sparql-query/. 88

T. C. Przymusinski. 1988a. On the declarative semantics of deductive databases and logic programs. In Foundations of Deductive Databases and Logic Programming, pp. 193–216. Morgan Kaufmann. DOI: 10.1016/B978-0-934613-40-8.50009-9. 20

T. C. Przymusinski. 1988b. Perfect model semantics. In Proc. of the Fifth International Conference and Symposium on Logic Programming, pp. 1081–1096. 19

T. C. Przymusinski. 1989. Every logic program has a natural stratification and an iterated least fixed point model. In Proc. of the Eighth ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, PODS ’89, pp. 11–21. ACM. DOI: 10.1145/73721.73723. 20

F. Puppe. 1993. Characterization and history of expert systems. In Systematic Introduction to Expert Systems, pp. 3–8. Springer. DOI: 10.1007/978-3-642-77971-8_1. 14

R. Ramakrishnan. Oct./Nov. 1991. Magic templates: A spellbinding approach to logic programs. Journal of Logic Programming, 11(3-4):189–216. DOI: 10.1016/0743-1066(91)90026-L. 51, 68

R. Ramakrishnan and J. D. Ullman. 1995. A survey of deductive database systems. Journal of Logic Programming, 23(2):125–149. DOI: 10.1016/0743-1066(94)00039-9. 65

R. Ramakrishnan, D. Srivastava, S. Sudarshan, and P. Seshadri. Apr. 1994. The CORAL deductive system. The VLDB Journal, 3(2):161–210. DOI: 10.1007/BF01228880. 67

K. Ramamohanarao, J. Shepherd, I. Balbin, G. S. Port, L. Naish, J. A. Thom, J. Zobel, and P. W. Dart. 1988. The NU-Prolog deductive database system. In Prolog and Databases, pp. 212–250. Halsted Press. 72

R. Reiter. 1977a. Deductive question-answering on relational data bases. In H. Gallaire and J. Minker, editors, Logic and Data Bases, pp. 149-177, Plenum Press, New York. DOI: 10.1007/978-1-4684-3384-5_6. 13, 63

R. Reiter. 1977b. On closed world data bases. In H. Gallaire and J. Minker, editors, Logic and Data Bases, pp. 55-76, Plenum Press, New York. 13, 21

R. Reiter. 1981. On the integrity of typed first order data bases. In H. Gallaire, J. Nicolas, and J. Minker, editors, Advances in Data Base Theory, pp. 137-157, Vol. 1. Plenum Press, New York. 31

R. Reiter. 1991. The frame problem in the situation calculus: A simple solution (sometimes) and a completeness result for goal regression. In V. Lifschitz, editor, Aritifial Intelligence and Mathematical Theory of Computation: Papers in Honor of John McCarty, pp. 359–380. Academic Press. 41

M. Rezk and M. Kifer. 2012. Transaction Logic with partially defined actions. Journal of Data Semantics, 1(2):99–131. DOI: 10.1007/s13740-012-0007-8. 46

J. A. Robinson. 1965. A machine-oriented logic based on the resolution principle. Journal of the ACM, 12(1):23–41. DOI: 10.1145/321250.321253. 11

D. Roman and M. Kifer. Sept. 2007. Reasoning about the behavior of semantic Web services with Concurrent Transaction Logic. In International Conference on Very Large Data Bases (VLDB), pp. 627–638. 46

A. Rosenthal, S. Heiler, U. Dayal, and F. Manola. June 1986. Traversal recursion: A practical approach to supporting recursive applications. SIGMOD Rec., 15(2):166–176. DOI: 10.1145/16894.16871. 13

K. A. Ross and Y. Sagiv. 1992. Monotonic aggregation in deductive databases. In Proc. of the Eleventh ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, PODS ’92, pp. 114–126. ACM. DOI: 10.1145/137097.137852. 25

D. Saccà and C. Zaniolo. 1986a. The generalized counting method for recursive logic queries. In G. Ausiello and P. Atzeni, editors, ICDT’86, International Conference on Database Theory, Rome, Italy, Sept. 8–10, 1986, vol. 243 of Lecture Notes in Computer Science, pp. 31–53. Springer. DOI: 10.1007/3-540-17187-8_28. 51, 66

D. Saccà and C. Zaniolo. 1986b. On the implementation of a simple class of logic queries for databases. In A. Silberschatz, editor, Proc. of the Fifth ACM SIGACT-SIGMOD Symposium on Principles of Database Systems, pp. 16–23. ACM. DOI: 10.1145/6012.6013. 51

Y. Sagiv. 1987. Optimizing Datalog programs. In Proc. of the Sixth ACM SIGACT-SIGMODSIGART Symposium on Principles of Database Systems, PODS ’87, pp. 349–362. ACM. DOI: 10.1145/28659.28696. 32, 64

K. Sagonas, T. Swift, and D. S. Warren. May 1994. XSB as an efficient deductive database engine. In Proc. of the 1994 ACM SIGMOD International Conference on Management of Data, pp. 442–453. DOI: 10.1145/191839.191927. 71, 85

Semafora, GmbH, 1999. Ontobroker. Available at: http://www.semafora-systems.com/en/. 34

J. Seo, J. Park, J. Shin, and M. S. Lam. Sept. 2013. Distributed SociaLite: A Datalog-based language for large-scale graph analysis. Proc. of the VLDB Endowment, 6(14):1906–1917. 82

A. Shkapsky, K. Zeng, and C. Zaniolo. Aug. 2013. Graph queries in a next-generation Datalog system. Proc. of the VLDB Endowment, 6(12):1258–1261. DOI: 10.14778/2536274.2536290. 65, 83

A. Shkapsky, M. Yang, M. Interlandi, H. Chiu, T. Condie, and C. Zaniolo. 2016. Big data analytics with Datalog queries on Spark. In Proc. of the 2016 International Conference on Management of Data, SIGMOD ’16, pp. 1135–1149. ACM. DOI: 10.1145/2882903.2915229. 83

O. Shmueli. 1993. Equivalence of DATALOG queries is undecidable. J. Log. Program., 15(3):231–241. DOI: 10.1016/0743-1066(93)90040-N. 64

Y. Smaragdakis and M. Bravenboer. 2011. Using Datalog for fast and easy program analysis. In Proc. of the First International Conference on Datalog Reloaded, Datalog’10, pp. 245–251. Springer-Verlag, Berlin, Heidelberg. DOI: 10.1007/978-3-642-24206-9_14. 79, 80

W. Snyder and J. Schmolze. July 1996. Rewrite semantics for production rule systems: Theory and applications. In 13th International Conference on Automated Deduction, vol. 1104 of LNAI, pp. 508–522. Springer. DOI: 10.1007/3-540-61511-3_110. 42

T. Swift and D. S. Warren. 2011. XSB: Extending the power of Prolog using tabling. Theory and Practice of Logic Programming, vol. 12, no. 1-2, pp. 157–187. Cambridge University Press. 24, 28, 52, 59

H. Tamaki and T. Sato. 1986. OLD resolution with tabulation. In Third International Conference on Logic Programming, pp. 84–98. DOI: 10.1007/3-540-16492-8_66. 59

P. Tarau. 2004. Agent-oriented logic programming constructs in Jinni. In International Conference on Logic Programming, vol. 3132 of Lecture Notes in Computer Science. DOI: 10.1007/978-3-540-27775-0_46. 33

K. T. Tekle and Y. A. Liu. 2010. Precise complexity analysis for efficient datalog queries. In Proc. of the 12th International ACM SIGPLAN Conference on Principles and Practice of Declarative Programming, pp. 35–44. DOI: 10.1145/1836089.1836094. 52, 58, 61, 93

K. T. Tekle and Y. A. Liu. 2011. More efficient Datalog queries: subsumptive tabling beats magic sets. In T. K. Sellis, R. J. Miller, A. Kementsietsidis, and Y. Velegrakis, editors, Proc. of the ACM SIGMOD International Conference on Management of Data, SIGMOD 2011, pp. 661–672. ACM. DOI: 10.1145/1989323.1989393. 52, 58, 61

K. T. Tekle, K. Hristova, and Y. A. Liu. 2008. Generating specialized rules and programs for demand-driven analysis. In Algebraic Methodology and Software Technology, 12th International Conference, AMAST 2008, Urbana, IL, USA, July 28–31, pp. 346–361. 51, 93

S. Tsur and C. Zaniolo. 1986. LDL: A logic-based data language. In Proc. of the 12th International Conference on Very Large Data Bases, VLDB ’86, pp. 33–41. Morgan Kaufmann Publishers Inc., San Francisco, CA. DOI: 10.1007/978-3-540-79980-1_26. 24, 65

J. D. Ullman. 1987. Database theory: Past and future. In ACM Symposium on Principles of Database Systems, pp. 1–10. ACM. DOI: 10.1145/28659.28660. 34

J. D. Ullman. 1989. Bottom-up beats top-down for Datalog. In Proc. of the Eighth ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, PODS ’89, pp. 140–149. ACM. DOI: 10.1145/73721.73736. 61

J. D. Ullman and A. Van Gelder. Nov. 1988. Parallel complexity of logical query programs. Algorithmica, 3(1-4):5–42. DOI: 10.1007/BF01762108. 77

J. Vaghani, K. Ramamohanarao, D. B. Kemp, Z. Somogyi, P. J. Stuckey, T. S. Leask, and J. Harland. Apr. 1994. The Aditi deductive database system. The VLDB Journal, 3(2):245–288. DOI: 10.1007/BF01228882. 72

G. van Emde Boas and P. van Emde Boas. Jan. 1986. Storing and evaluating horn-clause rules in a relational database. IBM Journal of Research and Development, 30(1):80–92. DOI: 10.1147/rd.301.0080. 63

M. H. Van Emden and R. A. Kowalski. Oct. 1976. The semantics of predicate logic as a programming language. J. ACM, 23(4):733–742. DOI: 10.1145/321978.321991. 9, 48

A. Van Gelder. 1989. Negation as failure using tight derivations for general logic programs. Journal of Logic Programming, 6(1):109–133. DOI: 10.1016/0743-1066(89)90032-0. 19

A. Van Gelder, K. A. Ross, and J. S. Schlipf. July 1991. The well-founded semantics for general logic programs. Journal of the ACM, 38(3):619–649. DOI: 10.1145/116825.116838. 20, 22

M. Y. Vardi. 1982. The complexity of relational query languages (extended abstract). In Proc. of the Fourteenth Annual ACM Symposium on Theory of Computing, STOC ’82, pp. 137–146. ACM. DOI: 10.1145/800070.802186. 77

M. Y. Vardi. 2016. A theory of regular queries. In T. Milo and W. Tan, editors, Proc. of the 35th ACM SIGMOD-SIGACT-SIGAI Symposium on Principles of Database Systems, PODS, pp. 1–9. ACM. DOI: 10.1145/2902251.2902305. 64

J. Vennekens, M. Denecker, and M. Bruynooghe. 2010. FO(ID) as an extension of DL with rules. Ann. Math. Artif. Intell., 58(1-2):85–115. 22

L. Vieille. 1986. Recursive axioms in deductive databases: The Query/Subquery approach. In Expert Database Conference, pp. 253–267. 60

L. Vieille. 1987. A database-complete proof procedure based on SLD-resolution. In Proc. of the Fourth International Conference on Logic Programming, pp. 74–103. 60

L. Vieille. 1998. From data independence to knowledge independence: An on-going story. In Proc. of the 24rd International Conference on Very Large Data Bases, VLDB ’98, pp. 650–654. Morgan Kaufmann Publishers Inc., San Francisco, CA. 70

L. Vieille, P. Bayer, V. Küchenhoff, A. Lefebvre, and R. Manthey. 1992. The EKS-V1 system. In Proc. of the International Conference on Logic Programming and Automated Reasoning, LPAR’92, pp. 504–506. DOI: 10.1007/BFb0013102. 69

H. Wan, B. Grosof, M. Kifer, P. Fodor, and S. Liang. July 2009. Logic programming with defaults and argumentation theories. In International Conference on Logic Programming. DOI: 10.1007/978-3-642-02846-5_35. 36

J. Wang, M. Balazinska, and D. Halperin. Aug. 2015. Asynchronous and fault-tolerant recursive datalog evaluation in shared-nothing engines. Proc. of the VLDB Endowment, 8(12):1542–1553. DOI: 10.14778/2824032.2824052. 82

K. Wang and L. Yuan. 1992. Preservation of integrity constraints in definite DATALOG programs. Information Processing Letters, 44(4):185–193. DOI: 10.1016/0020-0190(92)90083-8. 31

D. H. D. Warren. 1981. Efficient processing of interactive relational data base queries expressed in logic. In Proc. of the Seventh International Conference on Very Large Data Bases, VLDB ’81, pp. 272–281. VLDB Endowment. 12

D. H. D. Warren. 1982a. Higher-order extensions to Prolog: Are they needed? In J. E. Hayes, D. Michie, and Y.-H. Pao, editors, Machine Intelligence, vol. 10, pp. 441–454. Halsted Press. 37

D. H. D. Warren. 1982b. A view of the Fifth Generation and its impact. AI Magazine, 3(4):34. 12

D. H. D. Warren and F. C. N. Pereira. July 1982. An efficient easily adaptable system for interpreting natural language queries. Computational Linguistics, 8(3-4):110–122. 12

D. S. Warren. Mar. 1992. Memoing for logic programs. Commun. ACM, 35(3):93–111. DOI: 10.1145/131295.131299. 54

D. S. Warren, T. Swift, and K. F. Sagonas. Mar. 2007. The XSB Programmer’s Manual, Version 2.7.1. Technical report, Department of Computer Science, State University of New York at Stony Brook, Stony Brook, NY. The XSB System is available from xsb.sourceforge.net, and the system and manual is continually updated. 59, 71

T. Winograd. 1975. Frame Representations and the Procedural–Declarative Controversy. In D. Bobrow and A. Collins, editors, Representation and Understanding: Studies in Cognitive Science, pp. 185–210. Academic Press. DOI: 10.1016/B978-0-12-108550-6.50012-4. 14

G. Yang, M. Kifer, and C. Zhao. Nov. 2003. FLORA-2: A rule-based knowledge representation and inference infrastructure for the Semantic Web. In International Conference on Ontologies, Databases and Applications of Semantics (ODBASE-2003), vol. 2888 of Lecture Notes in Computer Science, pp. 671–688. Springer. DOI: 10.1007/978-3-540-39964-3_43. 34, 38, 46, 91

M. Yang, A. Shkapsky, and C. Zaniolo. Apr. 2017. Scaling up the performance of more powerful Datalog systems on multicore machines. The VLDB Journal, 26(2):229–248. DOI: 10.1007/s00778-016-0448-z. 83

C. Zaniolo. 1986. Prolog: A database query language for all seasons. In Proc. from the First International Workshop on Expert Database Systems, pp. 219–232. Benjamin-Cummings Publishing Co., Inc., Redwood City, CA. 12

C. Zaniolo. 1988. Design and implementation of a logic based language for data intensive applications. In Proc. of the Fifth International Conference and Symposium on Logic Programming, pp. 1666–1687. 65

C. Zaniolo. 1993. A unified semantics for active and deductive databases. In Proc. of the Workshop on Rules in Database Systems, Workshops in Computing. Springer-Verlag. DOI: 10.1007/978-1-4471-3225-7_16. 41

C. Zaniolo. 2002. Key constraints and monotonic aggregates in deductive databases. In Computational Logic: Logic Programming and Beyond, Essays in Honour of Robert A. Kowalski, Part II, pp. 109–134. Springer-Verlag, London, UK. DOI: 10.1007/3-540-45632-5_5. 25

C. Zaniolo and H. Wang. 1999. Logic-based user-defined aggregates for the next generation of database systems. In The Logic Programming Paradigm: A 25-Year Perspective, pp. 401–426. Springer Berlin Heidelberg, Berlin, Heidelberg. DOI: 10.1007/978-3-642-60085-2_18. 25

C. Zaniolo, N. Arni, and K. Ong. Dec. 1993. Negation and aggregates in recursive rules: The LDL++ approach. In Proc. of the Third International Conference on Deductive and Object-Oriented Databases (DOOD), pp. 204–221. Springer-Verlag, Lecture Notes in Computer Science 760. 24

C. Zaniolo, S. Ceri, C. Faloutsos, R. T. Snodgrass, V. S. Subrahmanian, and R. Zicari. 1997. Advanced Database Systems. Morgan Kaufmann, San Francisco, CA. 42

C. Zaniolo, M. Yang, A. Das, A. Shkapsky, T. Condie, and M. Interlandi. 2017. Fixpoint semantics and optimization of recursive Datalog programs with aggregates. TPLP, 17(5-6):1048–1065. DOI: 10.1017/S1471068417000436. 83

N. Zhou, Y. Shen, L. Yuan, and J. You. 2001. Implementation of a linear tabling mechanism. Journal of Functional and Logic Programming, 2001(10). DOI: 10.1007/3-540-46584-7_8. 59

D. Zook, E. Pasalic, and B. Sarna-Starosta. 2009. Typed Datalog. In Proc. of the 11th International Symposium on Practical Aspects of Declarative Languages, PADL ’09, pp. 168–182. Springer-Verlag, Berlin, Heidelberg. 31

1. This example is inspired by the Mathematics Genealogy Project, http://genealogy.math.ndsu.nodak.edu/, which is also the source of most of the data used.

2. Another popular convention in Datalog systems is to prefix variables with the question mark, e.g., ?First, ?Area, ?Year.

3. We assume in this chapter a basic knowledge of relational database systems, such as relational algebra and the SQL query language. The necessary background would be included in any introductory database text, such as Garcia-Molina et al. [2009].

4. SQL:1999 introduced support for the comparatively limited form of linear recursion.

5. A Horn clause is a logical implication among positive literals with at most one literal in the consequent.

6. A list of these workshops can be found in http://dblp.uni-trier.de/db/conf/xp/index.html

7. The use of negation requires an additional syntactic condition to ensure safety, namely that every variable in a rule appear in at least one non-negated goal in the rule body. Thus, for example, a rule unrelated (P1, P2) :- not related (P1, P2) would not be safe.

8. Minimality in this context means there is no other satisfying truth assignment that makes a proper subset of the propositions true. Note that there can be multiple, incomparable such assignments.

9. The notation pred/N indicates that the predicate pred takes N arguments.

10. Beeri and Vardi [1981] viewed the above rules as constraints—or dependencies—and used a different, but equivalent, tableaux representation for them.

11. http://bitbucket.org/giorsi/nyaya

12. Another convention is to use a right-pointing arrow for rules that should be interpreted as integrity constraints [Aref et al. 2015].

13. http://www.json.org

14. F-logic frames can be viewed as a formalization of the concept of frames introduced by Minsky [1975].

15. In F-logic, classes are also objects and they can have information about themselves, which is not inherited by instances of these classes. In Java terms, this information corresponds to static methods.

16. LPS [Kowalski and Sadri 2012] is an exception, as it has some of the characteristics of Transaction Logic, described in the next subsection.

17. http://flora.sourceforge.net/tr-interpreter-suite.tar.gz

18. Syntactically, G subsumes F if F can be derived from G by substituting 0 or more variables with constants or other variables. So, for example, influenced(X, Y) subsumes influenced(dm, Y), influenced(X, X), influenced(X, Y), and influenced(dm, tjg).

19. Prolog pedagogues, when teaching data recursion, wisely choose graphs, for example, the advises relation, that can have no cycles.

20. http://docs.microsoft.com/en-us/sql/odbc/microsoft-open-database-connectivity-odbc

21. Another was WebLog [Lakshmanan et al. 1996], which deals with semi-structured data using a language very similar to F-logic.

22. http://www.w3.org/TR/2008/WD-owl2-profiles-20081008/#OWL_2_RL

23. http://ontotext.com/products/graphdb/

24. http://franz.com/agraph/allegrograph/

25. http://jena.apache.org/documentation/inference/

2

An Introduction to the Stable and Well-Founded Semantics of Logic Programs

Miroslaw Truszczynski

This chapter provides a brief introduction to two main semantics of logic programs with negation, the stable-model semantics of Gelfond and Lifschitz, and the well-founded semantics of Van Gelder, Ross, and Schlipf. We present definitions, introduce basic results, and relate the two semantics to each other. We restrict attention to the syntax of normal logic programs and focus on classical results. However, throughout the chapter and in concluding remarks we briefly discuss generalizations of the syntax and extensions of the semantics, and mention several recent developments.

2.1    Introduction

The roots of logic programming can be traced back to efforts to build resolutionbased automated theorem provers in the mid-1960s [Robinson 1965]. A realization that resolution can turn Horn theories into programs came about in the early 1970s and rested on the foundational work of Kowalski and Kuehner [1971] and Kowalski [1974], as well as the implementation effort of Colmerauer and his research group, in which the Prolog programming language was developed [Colmerauer et al. 1973].

Negation was present in Prolog from the very beginning. Its meaning was specified operationally through its implementation. However, for almost two decades, finding a satisfactory declarative account of negation was elusive. The first significant progress was obtained by Clark, who proposed reading programs as definitions and formalized that reading by means of the program completion [Clark 1978]. A different plan of attack was developed a few years later by Apt, Blair, and Walker [1988] and, independently, by Przymusinski [1988a, 1988b]. They introduced a large and natural class of programs with negation, called stratified programs, and showed that the meaning of a stratified program is captured by a certain well-motivated Herbrand model. Przymusinski [1988a] called this model perfect. Soon thereafter, Gelfond and Lifschitz [1988] proposed the stable-model semantics and Van Gelder et al. [1988, 1991] the well-founded semantics. The stable-model semantics was strongly influenced by research in knowledge representation concerned with the notion of nonmonotonic reasoning, and built on the semantics of default logic by Reiter [1980] and autoepistemic logic by Moore [1985]. The well-founded semantics followed the query-evaluation paradigm of Prolog but framed it in a three-valued setting. Both semantics were heavily influenced by the perfect-model semantics and can be regarded as its generalizations to the class of all programs. Moreover, despite some fundamental differences, they also show strong and interesting connections to the completion semantics by Clark.

The stable-model and the well-founded semantics have had major implications on the fields of logic programming and knowledge representation. Since their inception, they fueled research in these two fields and gave rise to fascinating theoretical results, implementations of declarative programming languages, and successful applications. In particular, the answer-set programming paradigm [Marek and Truszczyński 1999, Niemel¨a 1999, Brewka et al. 2011] and its modern implementations trace their roots to the stable-model semantics [Gebser et al. 2012], while some closely related declarative programming systems grew out of generalizations of the well-founded semantics [Denecker 2009]. The latter underlies also a successful Prolog descendant, the XSB system [Sagonas et al. 1994], and several other systems we mention later on.

In this tutorial presentation, we introduce the two semantics and show that, despite their differences, they are closely related. Our goal is to present basic properties of the stable-model and the well-founded semantics, focusing on the most significant lines of research. After introducing the terminology and the most essential preliminaries, we start our presentation with the case of Horn programs (Section 2.3). In Section 2.4 we discuss several examples that point out problems that arise for programs with negation, and informally suggest ways in which these problems could be addressed. We follow up with a formal discussion of the stablemodel semantics as an extension of the least-model semantics of Horn programs to the case of programs with negation (Section 2.5). The key topics we discuss are stratification and program splitting, supported models, completion, tight programs, loops and the Loop Theorem, and strong equivalence of programs. We then change gears and move into the realm of four-valued Herbrand interpretations. While there, we define partial stable and partial supported models, and the most distinguished representatives of the two classes of “partial” models: the well-founded and the Kripke-Kleene models, respectively (Section 2.6). We conclude with brief closing comments.

2.2    Terminology, Notation, and Other Preliminaries

Logic Programming

The language of logic programming is determined by a countable vocabulary σ consisting of function and predicate symbols, each assigned a non-negative arity. Function symbols of arity 0 are called constant symbols. We assume that σ contains at least one constant symbol. Expressions of the language may also contain variable symbols. They come from a fixed infinite countable set Var that does not depend on σ. In other words, the same set of variables is used with every vocabulary.

The terms of the language are defined in the same way as in the first-order logic: all constant and variable symbols are terms and, if t₁, …, tk are terms and f ∈ σ is a k-ary function symbol, then f(t₁, …, tk) is also a term.

An atom is an expression p(t₁, …, tk), where p ∈ σ is a k-ary predicate symbol and t₁, …, tk are terms. Thus, atoms in logic programming are of the same form as atomic formulas in the language of first-order logic.

Terms and atoms that have no occurrences of variable symbols are ground. The Herbrand universe comprises all ground terms of the language and the Herbrand base comprises all ground atoms. One of the connectives in the language of logic programming is the negation connective not. Negation is applied only to atoms. Atoms and negated atoms are called literals. Rules are expressions constructed from literals by means of the rule connective “←” and the conjunction connective “,”. More precisely, a rule (sometimes called a clause) is an expression of the form

where a and all bi’s and cj’s are atoms. The atom a is the head of the rule (2.1) and the conjunction (list) b₁, …, bm, not c₁, …, not cn of literals is its body. If r denotes a rule, we write H(r) and B(r) for the head and the body of r, respectively. We extend this notation to programs and write H(P) and B(P) for the sets of heads and bodies of rules in a program P.

We often write rules as a ← B, where a is an atom and B is a list of literals. For every list B = b₁, …, bm, not c₁, …, not cn of literals we define B⁺ = {b₁, …, bm} and B⁻ = {c₁, …, cn}, and we often specify a rule a ← B as a ← B⁺, not B⁻. We note a slight abuse of the notation here. The expression in the body, B⁺, not B⁻, is not a list but a pair of sets. Nevertheless, as all semantics of logic programs we consider in this chapter are insensitive to the order of literals in the bodies of rules, the notation gives all essential information about the rule it describes.

If n = 0, rule (2.1) is a Horn rule and if m + n = 0, a fact. In the latter case, we omit ‘←’ from the notation, that is, we write a instead of a ←. A logic program (or just a program) is a collection of rules. A Horn program is a program consisting of Horn rules.

A program can be considered within any language of logic programming whose vocabulary σ contains all constant, function, and predicate symbols that occur in the program. However, it is convenient to see a program as an element of the minimal language within which it can be studied, the one determined by the set of the symbols the program contains. For a program P, we denote by HU(P) and HB(P) the Herbrand universe and the Herbrand base of this most economical language, and we refer to them as the Herbrand universe and the Herbrand base of P. We restrict attention to programs that contain at least one constant symbol to make sure that the requirement we imposed earlier on the language of logic programming is satisfied.

A ground instance of a rule r is any rule that can be obtained by consistently substituting its variables with ground terms. The grounding of a program P, denoted by gr(P), is the program consisting of all ground instances of rules in P. The grounding of P is determined by the language within which we consider P. However, unless stated otherwise, by the grounding of a program P we mean the grounding of P in the language determined by the symbols of P. That is, we instantiate variables to terms in the Herbrand universe of P, HU(P).

To illustrate, let P be the program

The language of P is determined by the vocabulary consisting of a constant symbol 0, a unary function symbol s, and unary predicate symbols even and odd.¹ There is one fact in P, even(0). The last two rules contain occurrences of a variable symbol X. The last rule contains an occurrence of not. The Herbrand universe of P is given by

and the Herbrand base by

The program

is the grounding of P.

The program P is not a Horn program as its third rule is not a Horn rule. However, the first two rules are Horn rules and the program consisting of these two rules is a Horn program.

Lattices, Operators, Pre-Fixpoints and Fixpoints, Monotonicity, and Antimonotonicity

A lattice is a structure 〈L, ≤〉, where L is a non-empty set, and ≤ is a partial order on L such that every two elements x, y ∈ L have the least upper bound and the greatest lower bound. We often write L to represent the lattice 〈L, ≤〉, especially when ≤ is understood. A lattice is complete if every (even empty or infinite) set X of its elements has the least upper bound and the greatest lower bound, denoted lub(X) and glb(X), respectively. An operator on a lattice 〈L, ≤〉 (or simply an operator on L) is any mapping O : L → L. An operator O on a lattice L is monotone if for every a, b ∈ L such that a ≤ b, O(a) ≤ O(b). An element a ∈ L is a pre-fixpoint of an operator O on a lattice L if O(a) ≤ a; it is a fixpoint of O if O(a) = a. The fundamental property of monotone operators on complete lattices is given by the Knaster-Tarski theorem [Tarski 1955].

Theorem 2.1 Knaster-Tarski. Let O be a monotone operator on a complete lattice 〈L, ≤〉. Then O has a least pre-fixpoint and a least fixpoint, and the two coincide.

Proof Let us define P = {x ∈ L: O(x) ≤ x}. In other words, P is the set of all pre-fixpoints of O. We note that P = ∅. This observation follows as a corollary from the argument below. However, it can also be seen in a more direct way. Indeed, since L is complete, lub(L) is well defined. Clearly, O(lub(L)) ∈ L and so, O(lub(L)) ≤ lub(L). Thus, lub(L) ∈ P.

Let p be the greatest lower bound of P (p is well-defined by the completeness of L). For every y ∈ P, p ≤ y. Thus, by the monotonicity of O and the definition of P, O(p) ≤ O(y) ≤ y. It follows that O(p) is a lower bound for P. Since p is the greatest lower bound for P, O(p) ≤ p. Thus, p ∈ P or, equivalently, p is a pre-fixpoint of O. Consequently, p is the least pre-fixpoint of O. Moreover, using the monotonicity of O again, we obtain O(O(p)) ≤ O(p); that is, O(p) ∈ P. Thus, p ≤ O(p). It follows that O(p) = p. That is, p is a fixpoint of O and, since fixpoints are pre-fixpoints, the least fixpoint of O.

■

The proof we presented is non-constructive. But the Knaster-Tarski theorem has also a simple constructive proof. It makes use of ordinal numbers, transfinite sequences, and transfinite induction. Reviewing these concepts goes beyond the scope of this text. Instead, we refer to the monograph by Jech [2003] for an elegant discussion (a brief overview can also be found in the classic logic programming text by Lloyd [1984]).

In a constructive proof of the Knaster-Tarski theorem, we define a certain transfinite sequence of sets (a sequence that is labeled with ordinal numbers). The sequence starts with the empty set. Each element in the sequence that is labeled with a successor ordinal is obtained from the previous one by applying O. Each element in the sequence that is labeled with the limit ordinal is the union of all previous sets in the sequence. Importantly, one can show that some element in the sequence is a fixpoint of O and, in fact, the least fixpoint (and the least pre-fixpoint). The least ordinal that appears as the label of such a set represents the “number” of steps in which the fixpoint is reached. We will encounter a specific example of this construction later on.

An operator O on a complete lattice L is finitary if for every countable sequence a₀ ≤ a₁ ≤ … of elements from L

Operators that are monotone and finitary are continuous. The operators we will consider in this presentation are continuous. One can show that for continuous operators the identity above becomes an equality, that is,

Moreover, the least fixpoint (whose existence is guaranteed by the monotonicity of a continuous operator) is reached in ω steps, where ω is the least infinite ordinal number.

Similarly, to monotone operators, we define an operator O on a lattice L to be antimonotone if for every a, b ∈ L such that a ≤ b, O(b) ≤ O(a). An easy to prove yet important property of an antimonotone operator O is that its “square” O², defined by O²(x) = O(O(x)), is monotone.

Theorem 2.2 Let O be an antimonotone operator on a lattice 〈L, ≤〉. Then the operator O² on 〈L, ≤〉 is monotone.

Proof Let a, b ∈ L be such that a ≤ b. Since O is antimonotone, O(b) ≤ O(a). Using antimonotonicity of O again, we get O²(a) = O(O(a)) ≤ O(O(b)) = O²(b).

■

Herbrand Interpretations

The subsets of the Herbrand base of a program P are in a one-to-one and onto correspondence with the standard first-order logic Herbrand interpretations of the vocabulary of P [Doets 1994]. It is because an Herbrand interpretation is uniquely determined by the set of ground atoms that are true in it. In fact, that set is often taken to stand for the corresponding Herbrand interpretation. We will follow this convention and refer to subsets of HB(P) as Herbrand interpretations (of the language determined by P). Below, we express the standard definition of the satisfaction relation for Herbrand interpretations under the assumption that Herbrand interpretations are sets of ground atoms, and extend it to rules and programs.

Definition 2.1 Let I be an Herbrand interpretation. The interpretation I satisfies a ground atom a if a ∈ I, and it satisfies a ground literal not a, if a ∉ I. Furthermore, I satisfies a conjunction B = b₁, …, bm, not c₁, …, not cn of ground literals if B⁺ ⊆ I and B⁻ ∩ I = ∅.

The interpretation I satisfies a ground rule a ← B, if I does not satisfy B or I satisfies a. Further, I satisfies a rule r, if I satisfies every ground instance of r. Finally, I satisfies a program P, if I satisfies every rule in P or, equivalently, if I satisfies every ground rule in gr(P).

Instead of “satisfies” we will often say “is a model of.” We write I ⊨ E, when I satisfies an expression (an atom, a literal, a rule, or a program) E. Otherwise, we write I ⊭ E.

The set All(P) of all Herbrand interpretations of a program P (that is, according to our convention, the collection of all subsets of HB(P)), together with the inclusion relation, forms a complete lattice. Similarly, the set All₄(P) = All(P) × All(P) (we explain the notation All₄(P) in the next paragraph) of pairs of Herbrand interpretations forms a complete lattice with respect to the precision ordering ≤p defined as follows:

where I, J, I′ J′ ∈ HB(P) [Denecker et al. 2000]. The term “precision ordering” is motivated by the “approximation” intuition. Namely, if I, J, and K are two-valued interpretations such that I ⊆ K ⊆ J, then the pair (I, J) can be viewed as an approximation of K, where I underestimates what is true in K and J underestimates what is false in K. Under this intuition, if (I, J) ≤p (I′, J′) and (I, J) and (I′, J′) both approximate K, then (I′, J′) provides a higher-precision approximation to K than (I, J) does. Hence, the term precision ordering for ≤p.²

The notation All₄(P) is motivated by the observation that pairs (I, J) of interpretations from All(P) can be viewed as 4-valued interpretations. Indeed, let us think of ground atoms in I as certain and those in J as possible. The following definition is then quite intuitive. A ground atom A is true in (I, J) if A ∈ I ∩ J (if it is certain and possible), unknown if A ∈ J \ I (if it is possible but not certain), inconsistent if A ∈ I \ J (if it is certain but not possible), and false if A ∉ I ∪ J (if it is neither certain nor possible).

All semantics we consider in this chapter have elegant descriptions in terms of fixpoints of monotone operators on the lattices All(P) and All₄(P).

The One-Step Provability Operator

With each program P we can associate its one-step provability operator TP introduced by van Emden and Kowalski [1976]. It maps subsets of HB(P) to subsets of HB(P). We will view it as an operator on the lattice All(P). Thus, let P be a program and let I be a subset of HB(P). We define

It is clear from the definition that TP(I) is indeed a subset of HB(P), that is, that TP is an operator on All(P).

Herbrand models of a program can be described as pre-fixpoints of its one-step provability operator.

Theorem 2.3 Let P be a logic program. An Herbrand interpretation I ⊆ HB(P) is an Herbrand model of P if and only if I is a pre-fixpoint of TP.

Proof Let us assume that I is an Herbrand model of P and let a ∈ TP (I). By the definition of the operator TP, there is a rule a ← B ∈ gr(P) such that I ⊨ B. Since I ⊨ a ← B, a ∈ I. Hence, Tp(I) ⊆ I.

Conversely, let us suppose that Tp (I) ⊆ I and let a ← B ∈ gr(P). If I ⊨ B then, by definition, a ∈ Tp (I). Thus, a ∈ I. It follows that I ⊨ a ← B and, as a ← B is an arbitrary rule in gr(P), I ⊨ P.

■

In general, the one-step provability operator has no monotonicity properties, due to the fact that negated atoms may appear in the bodies of program rules. However, for Horn programs (only non-negated occurrences of atoms in the bodies of rules) we have the following property.

Theorem 2.4 If P is a Horn program, the operator TP is a monotone and finitary operator on the lattice All(P).

Proof Let I ⊆ I′ ⊆ HB(P) and let a ∈ TP (I). It follows that there is a rule a ← B in gr(P) such that I ⊨ B. Since P is a Horn program, B⁻ = ∅. Thus, the condition I ⊨ B is equivalent to B⁺ ⊆ I. By the assumption, B⁺ ⊆ I′ and so, I ⊨ B. This implies that a ∈ TP (I′). Hence, TP (I) ⊆ TP (I′) follows.

Next, let us consider a sequence A₀ ⊆ A₁ ⊆ … ⊆ HB(P). If , then there is a rule a ← B in gr(P) such that . Since B is finite, there is n such that . Consequently, a ∈ TP(Ak). Thus, . It follows that TP is finitary.

■

Following Fitting [2002], we now extend the concept of one-step provability to the four-valued setting. Specifically, we define a two-input one-step provability operator ФP : All₄(P) → All(P), and a four-valued one-step provability operator TP : All₄ → All₄. To this end, for (I, J) ∈ All₄, we set

and

If we view an interpretation I as representing what is surely true, and J as what is possible (possibly true), ФP (I, J) consists of atoms that are derivable in one step by a rule in gr(P) that surely applies in (I, J) or, more formally, has all literals in its body surely true in (I, J) (positive atoms true, that is, in I, atoms that are negated surely false, that is, not in J). Similarly, we can see ФP (J, I) as the set of atoms that are derivable in one step by a rule that possibly applies in (I, J) or, more formally, has all literals in its body possible in (I, J) (positive atoms in J, atoms that are negated possibly false, that is, not in I). Thus, the operator TP can be seen as a four-valued counterpart to TP.

Below, we often write ФP (·, J) to represent an operator on All(P) that to any interpretation I ∈ All(P) assigns the interpretation ФP (I, J). We use the notation ФP (I, ·) in a similar way.

In the four-valued setting, we have several general monotonicity properties for operators. These properties underlie all major semantics of logic programs.

Theorem 2.5 For every logic program P, the operator ФP (·, J) on All(P) is monotone (with respect to inclusion), the operator ФP(I, ·) on All(P) is antimonotone (with respect to inclusion), and the operator TP on All₄(P) is monotone (with respect to ≤p).

Proof Let I ⊆ I′ ⊆ HB(P) and J′ ⊆ J ⊆ HB(P). Inclusions ФP (I, J) ⊆ ФP (I′, J) and ФP (I, J) ⊆ ФP (I, J) follow directly from the definition of ФP by means of a reasoning similar to that we used in the proof of Theorem 2.4. The last assertion is a direct corollary from these two properties. Let (I, J) ≤p (I′, J′). It follows that I ⊆ I′ and J′ ⊆ J. Thus, we have

and

Consequently,

■

Formal and Informal Reading of a Program

Any logic-based language to model and solve computational problems preferably will satisfy two general desiderata.

1.   Each expression in the language must have a formal semantics providing a precise specification of its meaning.

2.   Each expression in the language must also have an intuitive reading giving it a meaning corresponding to the one provided by the formal semantics.

The need for formal semantics is obvious. Expressions in the language (programs) must have a precise unambiguous meaning to allow analyzing them for correctness, and to serve as a specification for software to compile and execute them. The second requirement is not absolutely necessary, but it is critical if a formalism is to be used effectively by programmers. To build programs, programmers must understand what programs mean. This meaning should be unambiguously suggested by the informal reading of rules and programs. What this informal reading should be has been the subject of a considerable debate in the logic programming community. Denecker and his collaborators provide a comprehensive overview of issues involved [Denecker et al. 2001, Denecker and Ternovska 2008, Denecker et al. 2012]. They argue that programs should be viewed as representations of informal definitions that serve as restrictions on (Tarskian) possible worlds, and not as epistemic expressions on beliefs of an agent, a view that influenced Gelfond and Lifschitz [1988] in their work that led to the stable-model semantics.

We skirt this issue here and simply suggest to read a rule (2.1) as:

assuming that atoms C₁, …, Cn cannot be established (alternatively, derived or computed), establish atom A if atoms B₁, … Bm have already been established.

We note two related difficulties with this reading. First, it is not necessarily clear when we can assume that an atom “cannot be established.” Second, the statement “cannot be established” is applied to a single rule but clearly depends on other rules in the program. Hence, the meaning of program rules depends on the program, and the meaning of programs is not derived from the meaning of its rules by any obvious composition operator such as, for instance, conjunction. Nevertheless, the proposed reading is useful in motivating formal semantics of logic programs and we will refer to it below.

2.3    The Case of Horn Logic Programs

Since Horn rules do not contain negated atoms Ci, we do not need to worry about the precise meaning of the phrase “assuming that atoms Ci cannot be established.” Thus, for Horn programs the problematic part of the informal reading of rules disappears and therefore they seem like a good departure point for our discussion. Let us look at this program:

The first rule has an empty body. Therefore, based on our informal reading of rules we establish even(0). If in the second rule we replace X with 0, we obtain an instance of that rule, even(s²(0)) ← even(0). Since we already established even(0), based on the informal reading of rules we can now establish even(s²(0)). Continuing in this way, we can establish even(s⁴(0)), even(s⁶(0)), etc. Thus, based on our informal reading of rules we can establish all atoms in the set {even(0), even(s²(0)), …} and nothing else. It is worth noting that each atom we could establish is an element of the Herbrand base, and that all derivations used rules from the grounding of the program.

Next, let us consider the program

Reasoning as above, we can establish atoms r(1, 2), r(2, 3), and r(3, 4). The case of the rule tc(X, X) requires some consideration. Establishing an atom tc(X, X), without specifying what X is to be substituted with, is meaningless. Assuming that the program describes all that is relevant to the problem at hand, the only reasonable substitutions are those using terms from the Herbrand universe of the program, in this case, the constants 1, 2, 3, and 4. Thus, the rule tc(X, X) allows us to establish tc(1, 1), tc(2, 2), tc(3, 3), and tc(4, 4).³ From that point on, new atoms can only be established by means of instantiations of the last rule. Clearly, “potentially usable” instantiations arise only when elements of the Herbrand universe, that is, constants 1, 2, 3, and 4 are substituted for variables X, Y, and Z. Thus, we can establish tc(1, 2), since r(1, 2) and tc(2, 2) are already established, and tc(2, 3) and tc(3, 4), by a similar reasoning. Next, we can establish tc(1, 3) and tc(2, 4) and, finally, tc(1, 4). With that we reach a point where no new atoms can be established.

To summarize, each of the programs (2.6) and (2.7) has a clear meaning given by a subset of its Herbrand base. That subset is constructed in a series of steps, in which new atoms are derived based on those obtained previously by means of ground instantiations of rules of the program. In the first case, the result represents the concept of a non-negative even number and, in the second case, the graph given by the relation r and its transitive closure given by the relation tc. This suggests that Horn programs can be interpreted as definitions, an observation that underlies the definitional reading of programs mentioned above [Denecker et al. 2001, Denecker and Ternovska 2008, Denecker et al. 2012], as well as earlier extensive uses of Horn programs as database queries [Ullman 1988, Ceri et al. 1990].

The derivation process used in our two examples can be defined for an arbitrary Horn program P. Formally, we do this in terms of the one-step provability operator TP and exploit its monotonicity (in this section we implicitly assume that all programs we consider are Horn and so Theorem 2.4 applies). Specifically, we construct a sequence of subsets of HB(P) by setting

Since , we clearly have . By the monotonicity of TP, we also have

Generalizing by induction, we obtain that for every k

that is, every set in the sequence contains all elements belonging to the earlier ones.

It should be clear that the sequence is a formal representation of the derivation process we described for programs (2.6) and (2.7). The identity reflects that we start with no atoms established, and the formula captures the informal reading of rules and programs: is the set of all atoms that can be established by means of a single application of a rule from gr(P) to atoms established earlier.

In our examples we reached the limit of the process, that is, the set of atoms from which no new atoms can be derived. It turns out that it is always possible. Let us set

We will show that is a fixpoint of the operator TP, that is, . We have

Thus,

The converse inclusion also holds. Since TP is finitary,

The two inclusions show that , that is, is a fixpoint of TP. Therefore, once we reach it, no new atoms can be derived. This argument shows that the least fixpoint of TP exists and can be reached in no more than ω steps. In general, as illustrated by the program (2.6), ω steps are in fact necessary.⁴ We gather our observations in the following theorem (which, obviously, also follows from Theorems 2.1 and 2.4).

Theorem 2.6 For every Horn program P, the one-step provability operator TP has a least prefixpoint and the least fixpoint, and the two coincide. Moreover, the least (pre-)fixpoint of TP can be reached in at most ω steps.

Proof We have already demonstrated that is a fixpoint of TP. Let U be any pre-fixpoint of TP. Then, for every . Indeed, and, if , then . Hence, the claim follows by induction. Consequently, . Since fixpoints are, in particular, pre-fixpoints, the assertion follows.

■

So far we described the fixpoint in terms of a derivation procedure. It has, however, a simple declarative characterization as a certain Herbrand model of P, a property observed by van Emden and Kowalski [1976].

Theorem 2.7 Let P be a Horn program. The least fixpoint of the one-step provability operator TP and the least Herbrand model of P are equal.

Proof By Theorem 2.3, pre-fixpoints of TP and Herbrand models of TP coincide. Thus, , being the least pre-fixpoint of TP, is the least Herbrand model of P.

From now on, we write LM (P) for the least Herbrand model of P. The existence of the least Herbrand model (the least fixpoint of the one-step provability operator), allows us to formalize the meaning of Horn programs. They can be seen as definitions, that is, devices that define relations, with the precise meaning of what they define given by their least Herbrand models.

Definition 2.2 A Horn program P defines a relation R ⊆ HU(P)n if there is an n-ary relation symbol r in the language of P such that for every t₁, …, tn ∈ HU (P),

This concept of definability of relations by Horn programs is closely related to Turing’s computability. The following theorem due to Andréka and Németi [1978], building on the results by Smullyan [1961], Büchi [1962], and Börger [1974], shows the connection.

Theorem 2.8 A relation R over an Herbrand universe of a vocabulary σ is recursively enumerable if and only if R is defined by a finite Horn program P over some vocabulary σ′ extending σ.

Theorem 2.8 implies that Horn logic programming can be used as the foundation for a Turing-complete programming language. This observation found its implementation in Prolog [Colmerauer et al. 1973]. Prolog employs resolution procedures [Robinson 1965], in particular, the SLD (selective linear definite clause) resolution [Kowalski and Kuehner 1971, Lloyd 1984], for finding whether a ground atom belongs to the least Herbrand model of the program, that is, whether the tuple of its ground terms has a property defined by the program.

2.4    Moving Beyond Horn Programs—An Informal Introduction

Horn programs are important both for the theory and for the practice of logic programming. However, neither logic programming in general nor Prolog—its particular implementation—are limited to Horn programs. From its very inception, Prolog allowed negated atoms to appear in the bodies of rules. And while Prolog implementers developed techniques to process programs with negation based on generalizations of the basic SLD resolution, no corresponding characterization in terms of a class of Herbrand models was offered. Identifying such a class of models became a long-standing problem in logic programming that for many years fueled theoretical research of the semantics of logic programs. In fact, given some problems with the semantics implemented by Prolog, somewhere along the way the quest was redefined as the one to find a “correct” declarative account of programs with negation, that is, a semantics interpreting them in accordance with their informal reading.

Two semantics proposed at the end of 1980s gradually gained acceptance as satisfactory solutions to the problem: the stable-model semantics [Gelfond and Lifschitz 1988] and the well-founded semantics [Van Gelder et al. 1991]. In the remainder of this tutorial presentation, we describe them and discuss their basic properties.

When discussing the Horn case, we focused on Herbrand interpretations and viewed programs as sets of ground instantiations of their rules. When discussion programs with negation, we proceed similarly. Adopting these two “design” choices allows us to think about elements of the Herbrand base as elementary propositional atoms and about ground programs as propositional ones (albeit, in general, infinite). Thus, in the remainder of this chapter, we focus attention on propositional programs and only occasionally comment on how concepts and results we discuss can be lifted to the general case. In particular, from now on, unless explicitly stated otherwise, all programs we consider are propositional. We use the term programs with variables whenever we need to speak about the general case.

Let At denote a countable (possibly finite) set of propositional atoms. The set At can be viewed as the Herbrand base of the propositional language determined by At. Similarly, the set of propositional atoms appearing in a propositional program P can be viewed as the Herbrand base of P and could be denoted by HB(P). However, to stay closer to the most commonly used notation we write At(P) for the set of all atoms that appear in P.

We identify an interpretation of At (a truth assignment on At) with the subset of At that consists of all elements of At that hold in the interpretation (are assigned the logic value true). Thus, as in the general case, interpretations are subsets of the Herbrand base.

Before we move on to introduce and formally discuss the main semantics that emerged for programs with negation over the years, we illustrate some of the difficulties resulting from allowing negated literals in the bodies of rules.

Let P be a program consisting of the rules

where a, b, and c are propositional atoms. Reasoning as in the case of Horn programs, we see that a can be derived, as it is simply given as a fact, and b cannot be established, as there is no rule with b in the head. Applying our informal reading to the second rule, shows that it “applies” and so c can be established. It follows that the program “computes” or “justifies” the interpretation {a, c} in a way a Horn program “computes” or “justifies” their least model. It is clear that this interpretation is a model of the program and that no other interpretation can be computed in this way. It can then be reasonably taken as a unique intended model of the program. We will later extend this example in a way that yields the class of stratified programs [Apt et al. 1988, Przymusinski 1988a, Przymusinski 1988b]. These programs may include negation but the informal reading of rules allows us to identify for them a unique intended model, called a perfect model [Przymusinski 1988a]. However, even in this simple way of using negation, there is already a difference from the Horn case. The intended model {a, c} of the program (2.8) is no longer the least model of the program. It is a minimal model of the program, but the program has yet another minimal model namely, {a, b}. Hence, the property that an intended model is a least model cannot be preserved as we move to the setting of programs with negation, even if the use of negation is “stratified.”

In general, the uniqueness cannot be preserved either, at least not in the setting of two logical values true and false—an essential caveat, as we will shortly see. Let P be a program consisting of the rules

This program has three models (over the vocabulary {a, b}): {a, b}, {a}, and {b}. The first of these interpretations is inconsistent with our informal reading of rules. The two rules in the program can only be applied when a and b cannot be established. But, if it were the case, both rules would be applicable and a and b would get established, a contradiction. On the other hand, each of the two remaining interpretations is consistent with the informal reading of rules. Indeed, assuming that b cannot be established yields a (by the first rule). With a established, the second rule cannot be used and so, b cannot be established, just as we assumed. A symmetric argument justifies {b}. However, the symmetry implies that there is no difference between the interpretations {a} and {b} that could allow us to select one of them as a unique intended model of the program (2.8). The key to having multiple intended models in programs with negation turns out to be the existence of cyclic dependencies via negation. In our example, a depends on not b (the first rule) and b depends on not a (the second rule). Analyzing other similar programs led to understanding how to break such dependencies, which resulted in the concept of the reduct and in the stable-model semantics [Gelfond and Lifschitz 1988].

In the previous paragraph we restricted attention to the two-valued case. If we allow the three-valued setting or, as we do in this chapter, the four-valued one, the uniqueness can be preserved at a cost of completeness of the model. Considering again the program (2.9) one might posit that it does not provide enough information to establish the logical value of a and b and so, the correct logical value to assign to each of them is unknown. The resulting three-value model is a natural candidate for the intended model of the program. While in this example it offers no information about truth or falsity of a and b, in many other cases it assigns true or false to a vast majority of atoms, leaving only some atoms as unknown. Allowing the unknown truth value turned out to be quite fruitful. It paved the way to the well-founded semantics [Van Gelder et al. 1988, Van Gelder et al. 1991], a most broadly accepted three-valued unique intended model generalization to the case of programs with negation of the least model semantics of Horn programs and the perfect model of programs with “stratified” negation.

We discuss the stable model and the well-founded model semantics in formal terms in the remainder of the chapter. Along the way, we encounter two other semantics of programs with negation, both related to the notion of Clark’s completion of the program [Clark 1978]: the two-valued supported-model semantics [Clark 1978, Apt et al. 1988], and the three-valued Kripke-Kleene semantics [Fitting 1985]. Clark’s completion is a formalization of an intuition that programs are definitions, with all rules with the same atom, say p in the head, being the definition of p.

Let us consider a program

This program can be seen as defining a, b, and c by listing all cases when these atoms are true and implicitly assuming that these are the only cases when they can be. In our case, the program defines a to hold precisely when b is true or when c is false. In all other cases, a must be false. The program defines b to be true precisely when d is true and, as there are no rules defining c and d, the program defines c and d as false. This is the same set of constraints we would obtain in classical logic by means of the theory consisting of formulas obtained from the program by first collecting together rules with the same head leading (with some abuse of notation) to rules:

and then replacing the rule connective ← with the if and only if connective ↔ of classical logic:

We changed in this last step the program connective not to ¬ as we want to see the result as a theory in the standard language of logic. That theory is known as Clark’s completion of a program and models of Clark’s completion are known as supported. In our example, there is only one supported model: {a} (as already noted c and d are false, b is false because of the formula b ↔ d, and a is true because of the formula a ↔ b ∨ ¬c). It is worth noting that this model also arises from our adopted informal reading of programs. As there are no rules for c and d, neither can be established and so, they are false. Since d cannot be established, b cannot be established either (the rule b ← d is the only rule that has b in its head). Last, a can be established via the rule a ← not c. Since c cannot be established, a can! This program has no dependency cycles involving only non-negated occurrences of atoms (positive dependency cycles) and this is crucial. For such programs, supported models and stable models coincide. In general, any supported model is stable but, in general, the converse does not hold.

As positive dependency cycles are the main reason for the difference, let us consider an example of a program where such dependencies are present:

According to our informal reading of programs, this program has one intended model, ∅. It turns out to be the unique stable model of this program and the least model of this program (the program is a Horn one). On the other hand, the Clark’s completion of this program is the theory {a ↔ b} and this theory has two models: ∅ and {a, b}. The program has then two supported models, only one of which is a stable model.

So far, we considered two-valued models of Clark’s completion. If we change the setting to the three-valued one, the Clark’s completion of the program (2.13) will have one more model in which both a and b are unknown. It turns out we can associate with every program with negation a single “least informative” threevalued model. This model is known as the Kripke-Kleene model. We note that it is different than the well-founded model of this program which, as it will be clear later when we give formal definitions, turns out to make both a and b false. However, we also note that the Kripke-Kleene model of the program (2.10) coincides with the well-founded model. Thus, the relation between Kripke-Kleene and the wellfounded semantics follows a similar pattern to that between the supported-model and the stable-model semantics.

The point of this discussion was to show informally complexities that arise when we go beyond the class of Horn programs, and to build some intuitions. In the remainder of this chapter, we offer a formal discussion of the concepts alluded to above.

2.5    The Stable Model Semantics

We start our formal presentation of semantics of programs with negation with a discussion of the stable-model semantics proposed by Gelfond and Lifschitz [1988].

2.5.1    The Definition and Basic Properties of Stable Models

The key concept behind the semantics of stable models is that of the reduct of a program.

Definition 2.3 Let P be a program over a set At of atoms and let M ⊆ At be an interpretation of At. The reduct of P with respect to M, denoted by PM, is the program obtained from P by eliminating every rule r such that M ∩ B⁻ = ∅ and replacing each remaining rule a ← B⁺, not B − with a ← B⁺.

Informally, the reduct can be thought of as the result of evaluating negative literals in the bodies of rules with respect to M, and then simplifying in the standard way: removing every “true” from the rule bodies, and eliminating every rule that has at least one “false” in its body. To illustrate let us consider a program P over At = {a, b, c, d} consisting of the rules:

The atom d does not appear in P. Therefore, At(P) = {a, b, c}. Let us now consider an interpretation M ⊆ At, say M = {a, b, d}. To produce the reduct, we remove the second and the fourth rule, in each case, because of the negated atom a, which is an element of M (and so, not a evaluates to false in M). We then remove negative literals from the remaining rules, in each case, the literal not c is removed (it evaluates to true in M). The result is the program PM consisting of the rules:

We observe that the presence or absence of d in an interpretation does not affect the reduct, as d is not present in the program.

Before we move on to define stable models of a program, we state some simple properties of reducts.

Proposition 2.1 Let P be a program. For every interpretation M, TP (M) = TPM (M).

Proof Let a ∈ TP (M). It follows that there is a rule a ← B in P such that M ⊨ B. For that rule we have a ← B⁺ ∈ PM and M ⊨ B⁺. Thus, a ∈ TPM (M).

Conversely, if a ∈ TPM (M), there is a rule a ← C in PM such that M ⊨ C. Since a ← C belongs to PM, there is a rule a ← B in P such that M ⊨ not b, for every b ∈ B⁻, and also B⁺ = C. Clearly, M ⊨ B and so, a ∈ TP (M).

■

Corollary 2.1 If an interpretation M is a model of P, then it is a model of the reduct PM.

Proof If M is a model of P, TP (M) ⊆ M (cf. Theorem 2.3). Thus, by Proposition 2.1, TPM (M) ⊆ M and so, M is a model of TPM.

■

With the notion of the reduct in hand, we are now ready to define stable models of a program.

Definition 2.4 Let P be a program over a set At of propositional atoms. An interpretation M ⊆ At is a stable model of P if M is the least model of the reduct PM, that is, M = LM (PM).

This definition relies on the fact that a reduct of a program is a Horn program and so, it has a least model. Directly from the definition it follows that for Horn programs the stable-model semantics reduces to the least-model semantics we discussed in the previous section. This is an important and desirable property, as the least-model semantics of Horn programs is universally accepted as the right one.

Proposition 2.2 Let P be a Horn program over a set At of propositional atoms. Then the least model of P is the only stable model of P.

Proof For every M ⊆ At, PM = P. Thus, if M is a stable model of P, M = LM (PM) = LM(P). On the other hand, for the same reason, M = LM(P) satisfies M = LM (PM) and so is a stable model of P.

■

Also directly from the definition, it follows that stable models are subsets of the set of atoms that appear in the program and, even more, of the set of atoms that appear as the heads of rules of the program. (We recall that we write H(P) for the set of atoms in the heads of rules of P.)

Proposition 2.3 Let P be a propositional program over a set At of propositional atoms. If M is a stable model of P, then M ⊆ H(P).

Proof If M is a stable model of P then it is a least model of the reduct PM. If M contains an atom a that is not the head of any rule in PM, then M \ {a} is also a model of PM, a contradiction.

■

Proposition 2.3 is important for automated techniques to compute stable models as it narrows the scope of relevant atoms. For instance, let P be the program given by the rules (2.14). Then the interpretation M = {a, b, d} is not a stable model of P as d is not the head of any rule in P. In fact, every stable model of that program must be a subset of the set {a, b, c}.

Remark 2.1 In view of Proposition 2.3, from now on whenever we discuss stable models of a program P, we restrict attention to interpretations contained in At(P).

Coming back to our example program P given by the rules (2.14), let us consider the interpretation M′ = {a, b}. Since it is obtained from M = {a, b, d} by dropping d, which does not appear in the program P, PM′ is also given by the rules (2.15). Clearly, the least model of PM′ is {a, b}. Thus, M′ = {a, b} is a stable model of P. There is another stable model, M″ = {b, c}. Indeed, PM″ consists of the rules

and the least model of this program is {b, c}. On the other hand, the interpretation {a, c} is not a stable model of P. The reduct of P with respect to {a, c} is empty and so, its least model is ∅ and not {a, c}. Checking all subsets of At(P) = {a, b, c} shows that M′ = {a, b} and M″ = {b, c} are the only stable models of P.

We also note that not every program has a stable model. We will provide two examples here. First, let P = {a ← not a}. Since At(P) = {a}, there are only two candidates for a stable model: M₁ = ∅ and M₂ = {a}. It is easy to see that and so, . Similarly, and so, . For the next example, let P consist of the rules

There are now four candidates for a stable model as At(P) = {a, b}. However, if a is in a stable model, then b is not (the second rule does not contribute to the reduct; thus, b is not in the least model of the reduct). Consequently, a is not in the stable model either, a contradiction (to use the first rule to derive a, we must have b, first). On the other hand, if a is not in a stable model, then b is, but then so is a, a contradiction again.

We have been using the term stable model. But are stable models models of a program? The next result shows that it is indeed the case.

Proposition 2.4 Let P be a program and M ⊆ At(P) a stable model of P. Then, M is a model of P.

Proof Since M is a stable model of P, M is the least model of the reduct PM. In particular, M is a model of PM. By Theorem 2.3, TPM (M) ⊆ M. By Proposition 2.1, TPM (M) = TP (M). Thus, TP (M) ⊆ M and, again by Theorem 2.3, M is a model of P.

■

Stable models can be defined as fixpoints of operators. Let us define an operator Γ on the lattice All(P) of interpretations (in this case, the lattice of subsets of At(P)) by setting

The operator ΓP is antimonotone.

Proposition 2.5 Let P be a logic program. For all interpretations I ⊆ J ⊆ At(P), ΓP(J) ⊆ ΓP (I).

Proof Let us consider a rule a ← B⁺, not B− in P. Clearly, if B⁻ ∩ I = ∅, then B⁻ ∩ J = ∅. Thus, by the definition of the reduct, PJ ⊆ PI. It follows that ΓP (J) = LM (PJ) ⊆ LM (PI) = ΓP (I).

■

The operator ΓP can be used to characterize stable models of P. Directly from the definitions, it follows that stable models of P are fixpoints of the operator ΓP.

Theorem 2.9 Let P be a program. An interpretation M ⊆ At(P) is a stable model of P if and only if M = ΓP (M).

Theorem 2.9, Corollary 2.1, and Proposition 2.5 imply one of the most important properties of stable models from the perspective of knowledge representation, namely, that they are minimal models.

Theorem 2.10 Every stable model of a program P is a minimal model of P.

Proof Let M be a stable model of P and let M′ be a model of P such that M′ ⊆ M. By Proposition 2.5, ΓP(M) ⊆ ΓP(M′). Next, we recall that ΓP(M′) = LM (PM′). By Corollary 2.1, M′ is a model of PM′. Thus, ΓP(M′) ⊆ M′. Finally, since M is a stable model of P, Theorem 2.9 implies that M = ΓP(M). Putting these identities together we have

Consequently, M = M′ and so, the minimality of M follows.

■

Algorithmic aspects of the problems of determining the existence of and computing stable models of propositional programs received a substantial amount of attention. The reason is that computing stable models is a basic automated reasoning task underlying answer-set programming, a declarative programming paradigm of growing popularity [Marek and Truszczyński 1999, Niemelä 1999, Brewka et al. 2011]. We mention here two fundamental results in the long line of research on the complexity of computing stable models of logic programs, and refer to the excellent survey by Dantsin et al. [2001] for more details.

Theorem 2.11 Dowling and Gallier [1984]. The unique stable model (equivalently, the least model) of a finite propositional Horn logic program P can be computed in time linear in the size of P.

Proof (Sketch) To compute the least model of P, we start by setting X = ∅. We then arrange all atoms that are heads of rules with the empty body into a queue. We repeatedly take the front atom off the queue and add it to X. We also add to the end of the queue all atoms that are heads of rules whose bodies are contained in X. When the queue is empty, X contains the least model of P.

The task of adding atoms to the queue can be facilitated by keeping for each atom the list of rules whose bodies contain it, and by keeping for each rule a counter initially set to the number of atoms in its body. When an atom, say a, is taken off the queue, we visit each rule that contains a in the body (we have a list of those rules) and decrease the counter by 1. If the counter becomes 0, the head of the rule is placed on the queue. With this arrangement, the algorithm works in linear time.

■

The situation is drastically different for the general case.

Theorem 2.12 Marek and Truszczyński [1991]. The following problem is NP-complete: given a propositional logic program P, decide whether P has a stable model.

Proof (Sketch) The membership of the problem in the class NP is evident. Once we guess a set M ⊆ At(P) of atoms, we can compute the reduct PM, the least model of the reduct and verify that M and this least model coincide. All these tasks can be accomplished in time linear in the size of P.

To prove hardness, we show that the propositional satisfiability problem can be reduced to the problem of deciding whether a program has a stable model. Let F be a CNF formula. We introduce a fresh atom f and, for every atom a ∈ At(F), a fresh atom a′ (meant to represent the negation of a). Next, for each clause C of F, where

we define the program rule

We define P(F) to be the program consisting of all rules r(C), where C is a clause of F, and of rules a ← not a′ and a′ ← not a, for every atom appearing in F. One can show that F has a model M if and only if M ∪ {a′: a ∈ At(F) \ M} is a stable model of P(F).

■

Extension to Programs with Variables. The concept of a stable model extends to programs with variables. The key to the extension is grounding. Namely, if P is a logic program with variables, we define an Herbrand interpretation M ⊆ HB(P) to be a stable model of P if M is a stable model of gr(P). As noted at the beginning of the section, gr(P) can be viewed as a propositional logic program over the set HB(P) of ground atoms. Thus, the extension is well defined.

With this definition, most properties of stable models of propositional logic programs generalize to programs with variables in a straightforward fashion. In particular, stable models are Herbrand models of a program (cf. Proposition 2.4), a Horn program has a unique stable model (cf. Proposition 2.2), stable models of a program contain only atoms whose predicate symbol has a “head” occurrence in the program (cf. Proposition 2.3), and stable models of a program are minimal Herbrand models of the program (cf. Theorem 2.10).

2.5.2    Stratification and Splitting

By introducing negation into the bodies of rules of programs, we break a simple semantic picture of Horn programs, which are guaranteed to have a unique stable model. In the general case, some programs with negation have a single stable model but many other programs have multiple stable models or no stable models at all. The question of how stable models depend on the structure of a program and, in particular, on how negation is used in its rules, has received much attention. The notion of a “stratified” negation proposed by Apt et al. [1988] and Przymusinski [1988b] turned out to be especially fruitful.

Let P be a program given by the rule

Since b is not the head of a rule in P, it cannot be established. Applying the rule a ← not b, we establish a. Thus, our informal reading of rules and programs suggests exactly one interpretation of a and b, namely M = {a}, which makes a true and b false. It is easy to verify that, consistently with the informal reading, M is a unique stable model of P. Hence, even though P contains negation, it still has the key property of Horn programs, a unique stable model. On reflection, it is not surprising at all. There is a negation in P but it is applied only to an atom that the program has no rule for.

Programs like the one we just discussed not only have a unique stable model. In fact, they have an even stronger property.

Proposition 2.6 Let P be a program such that no atom appearing negated in P is the head of a rule in P. Then, for every set A of atoms the program P ∪ A has a unique stable model.

Proof Clearly, PA ∪ A is a Horn program. Let M = LM (PA ∪ A). It follows that A ⊆ M ⊆ H(P) ∪ A.

(Existence) By our assumption on P, (P ∪ A)M = PA ∪ A. Thus, M = LM((P ∪ A)M) and so, M is a stable model of P ∪ A.

(Uniqueness) Let M′ be a stable model of P ∪ A. It follows that A ⊆ M′ ⊆ H(P) ∪ A. Thus, by our assumption on P, (P ∪ A)M′ = PA ∪ A. Since M′ = LM((P ∪ A)M′) = LM(PA ∪ A) = M, we have M′ = M. It follows that M is the unique stable model of P.

■

Our discussion can be generalized to programs that are obtained by “stacking up” programs of the type we have just discussed one over another. The formal term is stratification and we will introduce it now.

Definition 2.5 Let P be a propositional logic program, α an ordinal (possibly transfinite). A sequence {Pβ}β<α of non-empty subsets of P is called a stratification of P in type α if

1.  ⋃β<α Pβ = P; and

2.  for every ordinal β < α, and for every propositional atom p that appears in the head of a rule in Pβ :

1.  p has no occurrences in ⋃γ<β Pγ, and

2.  p has no negated occurrences in Pβ.

The sets (programs) Pβ are called strata.

The idea is simple. By the condition (2a), atoms in the heads of rules in the program Pβ, that is, atoms defined by Pβ are not “redefined” by any later stratum. Thus, their logical values are determined by the program P≤β = ⋃γ≤β Pγ. Moreover, atoms defined in the stratum β have no effect on atoms defined in earlier strata. Thus, to determine the values of the atoms defined by the stratum Pβ, we first establish the values of the atoms defined by the program P<β = ⋃γ<β Pγ. We then use these values to simplify the program Pβ, that is, we eliminate rules whose bodies contain literals evaluated in P<β to false and, from the remaining rules of Pβ, we remove literals evaluated in P<β to true. Due to the condition (2b), the truth values of all atoms that appear negated in the bodies of rules of Pβ are determined by P<β. Thus, the result of this simplification is a Horn program, and its least model specifies the logical values for atoms defined in Pβ. Applying this reasoning according to the order of strata yields a model of the program. We will soon show that this model is in fact the unique stable model of the program.

Let P consist of the rules

Let us define P₀ = {a ← not b}, P₁ = {d ← a, e; e ← d, not b} and P₂ = {c ← a, not d}. It is easy to verify that the sequence 〈P₀, P₁, P₂〉 is a stratification of P. The negated atom in P₀ has its value established by the set of rules in lower strata, that is, by the empty program. Since the least model of the empty program is the empty set, b is false. Thus, P₀ simplifies to and so, the value of a is true. Given the logical values of a and b, P₁ simplifies to . The least model of this program is empty and so, d and e are false. Moving on to P₂, we simplify it to and obtain that c is true. In this way, we construct an interpretation {a, c} of P. It is easy to see that this interpretation is a stable model of P.

Before we proceed with a discussion of formal properties of stratified programs, we note that the concept of stratification, despite its intuitive nature, demonstrates some subtle aspects. It is clear that there are stratified programs that require infinitely many strata. What may be less obvious is that some infinite programs do not admit stratifications in type ω or less. For instance, let P consist of the following rules:

Let us define Pi = {pi+1 ← not pi } and Pω = {q ← not pi : i = 0, 1, …}. It is easy to verify that the sequence {Pβ}β<ω+1 is a stratification of P. In fact, it is the only stratification of P. Indeed, in every stratification of P, the stratum of the rule p₁ ← not p₀ must strictly precede the stratum of the rule p₂ ← not p₁, etc. Moreover, by the condition (2a), all rules q ← pi must be in the same stratum. Finally, the stratum of the rule pi+1 ← not pi must strictly precede the stratum of the rule q ← not pi+1. Thus, in every stratification, the strata must be the sets Pi, i = 0, 1, …, and Pω, and they must appear in that order.

We now formally state the key property of stratified programs, which we have already announced above.

Theorem 2.13 Let P be a stratified propositional logic program. Then P has a unique stable model.

The proof of this result depends on the Splitting Lemma, a result due to Lifschitz and Turner [1994], also discovered independently by Eiter et al. [1994, 1997].

Definition 2.6 Let P be a propositional logic program. A pair (Q, R) of programs is a splitting of P if Q and R are non-empty, P = Q ∪ R, and no atom appearing in the head of rules in R appears in Q.

Informally, if (Q, R) is a splitting, Q may feed information into R (and, in general, does) but not vice versa. This is similar to the “information flow” in stratified programs and, indeed, splitting and stratification are closely related. The only difference is that for “strata” in splitting, the condition (2b) is not required. That is, atoms in the heads of rules in a splitting stratum may appear negated in the bodies of the rules in this stratum. In this sense, splitting generalizes stratification.⁵

Lemma 2.1 Splitting Lemma. Let P be a program with a splitting (Q, R). Then an interpretation M is a stable model of P if and only if M ∩ At(Q) is a stable model of Q and M is a stable model of R ∪ (M ∩ At(Q)).

Proof (⇒) Let M be a stable model of P. We set N = M ∩ At(Q). Since (M \ N) ∩ At(Q) = ∅, QN = QM. By definition, M is the least model of PM. We have Q ⊆ P and, consequently, QM ⊆ PM. Thus, M is a model of QM and so, also a model of QN. Using again the property (M \ N) ∩ At(Q) = ∅, we obtain that N is a model of QN.

Let N′ ⊆ N be a model of QN. It follows that N′ is a model of QM (as QN = QM). Moreover, since (M \ N) ∩ At(Q) = ∅, also the interpretation N′ ∪ (M \ N) is a model of QM.

Let us consider a rule r = a ← B⁺ from RM. If B⁺ ⊆ N′ ∪ (M \ N), then B⁺ ⊆ N ∪ (M \ N) = M. Since M is a model of PM, a ∈ M. By the definition of splitting, a ∉ At(Q). Thus, a ∉ N. It follows that a ∈ M \ N and, consequently, a ∈ N′ ∪ (M \ N). Hence, N′ ∪ (M \ N) is a model of RM.

It follows that N′ ∪ (M \ N) is a model of PM. Since N′ ⊆ N ⊆ M, we have N′ ∪ (M \ N) ⊆ M. We now recall that M is the least model of PM. Thus, N′ ∪ (M \ N) = M, which implies that N′ = N. We conclude that N is the least model of QN and so, it is a stable model of QN.

Next, we show that M is a stable model of R ∪ N. First, we note that M is a model of PM and, consequently, a model of RM. Next, since N ⊆ M, M is a model of RM ∪ N = (R ∪ N)M. Let M′ ⊆ M and assume that M′ is a model of (R ∪ N)M. Then M′ is a model of RM ∪ N and so, M′ is a model of RM and N ⊆ M′. Since M′ ⊆ M, M′ ∩ At(Q) ⊆ M ∩ At(Q) = N. Moreover, N ⊆ M′ and N ⊆ At(Q). Thus, M′ ∩ At(Q) = N and so, M′ is a model of QM (since N is a model of QM). It follows that M′ is a model of QM ∪ RM = PM. But M′ ⊆ M and M is the least model of PM. Hence, M′ = M and so, M is the least model of (R ∪ N)M. Consequently, M is a stable model of R ∪ N.

(⇐) Let M be an interpretation such that M is a stable model of R ∪ N, where N = M ∩ At(Q) and N is a stable model of Q. Since M is a stable model of R ∪ N, M is a model of (R ∪ N)M = RM ∪ N. Thus, M is a model of RM. Similarly, N is a model of QN. Since N = M ∩ At(Q), M is a model of QM. It follows that M is a model of QM ∪ RM = PM.

Let us consider an interpretation M′ ⊆ M and assume M′ is a model of PM. Writing N′ for M′ ∩ At(Q), we obtain that N′ is a model of QM (since Q ⊆ P and M′ is a model of PM). Consequently, N′ is a model of QN and, since N is the least model of QN, N′ = N. It follows that N ⊆ M′ and so, M′ is a model of RM ∪ N. Since M is the least model of RM ∪ N, M′ = M. Thus, M is the least model of PM and so, a stable model of P.

■

The Splitting Lemma has some fundamental implications. First, it is the basis for the development of modular logic programs, where each next module introduces new concepts defined in terms of those defined already. In particular, splitting underlies the generate-define-test methodology proposed by Lifschitz [2002], which is now broadly used in answer-set programming [Brewka et al. 2011].

Second, splitting supports “stratum-by-stratum” computation of stable models. Consequently, at each stage stable-model finding algorithms can limit the search space of interpretations to those restricted to the language of the stratum at hand, which improves performance.

To make this last observation clear, let us assume that (Q, R) is a splitting of a program P. For every N ⊆ At(Q), we write R|N for the simplification of R with respect to N, that is, the program obtained by

1.  eliminating from R each rule a ← B such that for some b ∈ B⁺ ∩ At(Q), N ⊭ b (b ∉ N), or for some atom b ∈ B⁻ ∩ At(Q), N ⊭ not b (b ∈ N), and

2.  removing from the resulting program all remaining literals b and not b, where b ∈ At(Q).

It is easy to see that M ⊆ At(P) is a stable model of R ∪ (M ∩ At(Q)) if and only if M ∩ At(R) is a stable model of R|M ∩ At(Q). Thus, the Splitting Lemma implies that to find all stable model of P, it suffices to compute stable models of Q and, for each stable model N of Q, to compute stable models of the program R|N.

Third, and this is how we will use the Splitting Lemma here, it is a powerful technical tool. In particular, it implies Theorem 2.13.

Proof of Theorem 2.13 Let us assume that {Pβ}β<α is a stratification of P in type α. We recall that we write P<β for ⋃γ<β Pγ. In particular, P<α = P. We will prove by transfinite induction that for every β ≤ α, P<β has a unique stable model, say Mβ, and that for every γ < β, Mγ ⊆ Mβ and no atom in Mβ \ Mγ appears in P<γ.

The claim holds for β = 0. Indeed, we have P<0 = ∅ and so, P<0 has a unique stable model M₀ = ∅. The second part of the claim holds vacuously. Let us consider an ordinal β, 0 < β ≤ α and assume the claim holds for every ordinal γ such that γ < β. We will prove the claim for β.

First, let us assume that for some ordinal β′ we have β = β′ + 1. Clearly, P<β = P<β′ ∪ Pβ′. By stratification, it follows that (P<β′, Pβ′) is a splitting of P<β. By the induction hypothesis, P<β′ has a unique stable model Mβ′. Moreover, by the Splitting Lemma and Proposition 2.6, P<β has a unique stable model, say Mβ, Mβ′ ⊆ Mβ and no atom in Mβ \ Mβ′ appears in P<β′.

To complete an argument in this case, it remains to show that for every γ < β′, Mγ ⊆ Mβ and that no atom in Mβ \ Mγ appears in P<γ. By the induction hypothesis, Mγ ⊆ Mβ′ and no atom in Mβ′ \ Mγ appears in P<γ. Since Mβ′ ⊆ Mβ, we have Mγ ⊆ Mβ. Moreover, since Mγ ⊆ Mβ′ ⊆ Mβ, Mβ \ Mγ = (Mβ \ Mβ′) ∪ (Mβ′ \ Mγ). Thus, no atom in Mβ \ Mγ appears in P<γ (atoms in Mβ \ Mβ′ do not appear in P<β′ and so, they do not appear in P<γ).

Second, let us assume that β is a limit ordinal. It follows that P<β = ⋃γ<β P<γ. Indeed, for every δ < β, Pδ ⊆ P<δ+1. Since β is a limit ordinal, δ + 1 < β and so, Pδ ⊆ ⋃γ<β P<γ. Consequently, P<β ⊆ ⋃γ<β P<γ. The converse inclusion is evident.

Let Mβ = ⋃γ<β Mγ. Using the induction hypothesis, we can show that for every γ < β, Mγ ⊆ Mβ and no atom in Mβ \ Mγ appears in P<γ. We can also show that Mβ is a model of P<β. Indeed, let r be a rule in P<β. Then, there is γ < β such that r ∈ P<γ. Since Mγ is a stable model of P<γ (by the induction hypothesis), Mγ ⊆ Mβ, and Mβ \ Mγ has no atoms from P<γ (as noted above), Mβ is a model of r.

By Corollary 2.1, Mβ is a model of . Let M′ ⊆ Mβ be a model of . Then, for every γ < β, M′ is a model of . Consequently, is a model of . Since is a model of . By the induction hypothesis, for every γ < β, and so, Mβ ⊆ M′. It follows that Mβ is a least model of and so, a stable model of P<β.

Let M′ be another stable model of P<β. By the definition of stratification, for every γ < β, (P<γ, P′), where P′ = P<β \ P<γ, is a splitting of P<β. By the Splitting Lemma, M′ ∩ At(P<γ) is a stable model of P<γ. By the induction hypothesis, for every γ < β, M′ ∩ At(P<γ) = Mγ. Thus, M′ = M.

■

We will now look briefly at matters of computation. First, given a propositional logic program one can decide in linear time in the size of the program whether it is stratified. Second, given a stratified propositional logic program, its unique stable model can be computed in linear time in the size of the program. To do this we proceed stratum-by-stratum, computing the least model of the Horn program resulting by simplifying the stratum with respect to the model computed so far. Once that is done, we append that model to the set of atoms we are constructing. A stratification testing algorithm and an algorithm to compute a unique stable model of a logic program were first described by Niemel¨a and Rintanen [1994] in the setting of autoepistemic counterparts of programs.

Extension to Programs with Variables. Unlike in most other cases, there are at least two ways in which the notion of stratification can be extended to the case of programs with variables. First, we can adapt the idea of stratification to the general case by restricting the way relation symbols can occur in a program. We recall that programs with variables are assumed to be finite. Thus, there is no need to consider infinite stratifications.

Definition 2.7 Let P be a logic program over a first-order vocabulary. A sequence 〈P₀, P₁, …, Pn〉 of non-empty subsets of P is a stratification of P if

1.  ; and

2.  for every i, 0 ≤ i ≤ n, and for every relation symbol r that appears in the head of a rule in Pi :

1.  r has no occurrences in ⋃j<i Pj, and

2.  r has no negated occurrences in Pi.

Programs that have a stratification are stratified.

It is clear that if a program P over a first-order vocabulary is stratified then gr(P) is stratified according to Definition 2.5 (in fact, even finitely stratified). Thus, Theorem 2.13 implies the following corollary.

Corollary 2.2 Let P be a program over a first-order vocabulary. If P is stratified, then P has a unique stable model.

The program (2.2) is stratified. Indeed, if we define P₀ to consist of the first two rules of the program and P₁ of the third rule, then 〈P₀, P₁〉 is a stratification of P.

The second way to generalize the notion of stratification to programs with variables is motivated by an observation that some such programs are not stratified but their groundings are. For instance, let P be a program consisting of the following three rules (this program defines even and odd non-negative integers, but does it differently from the program (2.2) we considered before):

This program is not stratified in the sense of Definition 2.7. Indeed, the last two rules cannot belong to the same stratum. Moreover, neither of the two rules can appear in a stratum preceding the stratum containing the other. However, the grounding of the program is stratified in the sense of Definition 2.5.

Definition 2.8 Let P be a logic program over a first-order vocabulary. Then, P is locally stratified if gr(P) is stratified.

The following result follows directly from the corresponding definitions and from Theorem 2.13.

Theorem 2.14 If P is locally stratified then P has a unique stable model.

2.5.3    Connections to Classical Logic: Supported Models, Tight Programs, and the Loop Theorem

Stable models of programs are rooted in the intuition of non-circular justification. Relaxing the notion of non-circular justification to that of support (possibly, a circular self-support) leads to the semantics of supported models [Apt et al. 1988]. They are of interest as they can be viewed as a bridge between programs with the stable-model semantics and classical propositional theories.

Definition 2.9 Let P be a logic program. An interpretation M is a supported model of P if M = TP(M).

Let us say that an atom is “supported” by a program P with respect to an interpretation M if P contains a rule a ← B such that M ⊨ B. Then, M is a supported model of a program P when it is precisely the set of atoms “supported” by P with respect to M. This intuition motivates the term “supported.”

Let us note three simple properties of supported models. First, just as stable models, supported models of a program are contained in the set of atoms that appear in the heads of rules of the program. This follows from the fact that TP(M) ⊆ H(P).

Proposition 2.7 Let P be a logic program. If M is a supported model of P, then M ⊆ H(P).

Second, again as stable models, supported models of a program are models of the program.

Proposition 2.8 Let P be a logic program. Every supported model of P is a model of P.

Proof From the definition it follows that supported models are pre-fixpoints of the operator TP (in fact, even fixpoints). Thus, the assertion follows from Theorem 2.3.

■

The converse does not hold. There is an obvious reason why not. Namely, if M is a model of a program, extending M by any atom not in H(P) is a model of P, too. However, by Proposition 2.7, that model cannot be supported. More interestingly, the implication in Proposition 2.8 cannot be reversed even when we restrict attention to models that consist of atoms that occur as heads of rules of the program. For instance, let P = {p ← not p}. This program has no supported models. Indeed, there are only two candidates for a supported model here, M₁ = ∅ and M₂ = {p}. However, TP(M₁) = M₂ and TP(M₂) = M₁. Thus, neither M₁ nor M₂ is supported. On the other hand, M₂ is a model of P.

Finally, supported models of a program are also supported models of the reducts they determine. Speaking precisely, we have the following result.

Proposition 2.9 If M is a supported model of a logic program P, then M is a supported model of the reduct PM.

Proof Let M be a supported model of P. Then, M = TP(M) and so, by Proposition 2.1, . In other words, M is a supported model of PM.

■

Intuitively, every element a in a stable model M of a program P has a justification provided by the rule of P whose “reduced” version belongs to the reduct PM and, in the bottom-up computation of the least model of PM, “fires” to add a to M. That rule of P “supports” a with respect to M. Thus, one might expect that stable models are supported. It is indeed so.

Theorem 2.15 Let P be a logic program and M a stable model of P. Then, M is a supported model of P.

Proof Since M is a stable model of P, M = LM(PM). By Theorem 2.7, M is a fixpoint of the operator (even a least fixpoint, but we do not need this here). Thus, . By Proposition 2.1, . Thus, M = TP(M), that is, M is a supported model of P.

■

Again, the converse does not hold. Let P = {p ← p}. This program has two supported models: M₁ = ∅ and M₂ = {p}. Indeed, it is easy to verify that TP(M₁) = M₁ and TP(M₂) = M₂. On the other hand, M₂ is not a stable model of P (P is a Horn program and its least model, M₁, is the only stable model of P). We note that p in M₂ is self-supported. This is the reason why M₂ is not stable (all atoms must have non-circular support). This example also shows that supported models do not need to be minimal.

Remark 2.2 We saw that stable models are both supported and minimal. It is then natural to ask whether supportedness and minimality together characterize stable models. The answer is no. Let us assume that P = {p ← p, p ← not p}. It is clear that {p} is both a supported model of P and a minimal model of P. However, it is equally clear that it is not stable.

For some programs though, supported models are stable. In particular, it is so for those programs whose structure precludes the existence of self-support. The following definition and the subsequent result are due to Fages [1994].

Definition 2.10 A propositional program P is tight if there is a function (labeling) λ from atoms to ordinals such that for every rule a ← B in P and every b ∈ B⁺, λ(a) > λ(b). We call each labeling λ satisfying this condition a tight labeling of P.

We note that there are tight programs that require transfinite ordinals in each of their tight labelings. For instance, let us consider a program given by rules:

In every tight labeling of this program, the label of pi+1 must be strictly larger than the label of pi. Moreover, the label of q must be strictly larger than the label of every atom pi. Thus, no tight labeling in the set {0, 1, …} is possible. On the other hand, the labeling λ, where λ(pi) = i and λ(q) = ω, is tight. Of course, for every finite tight program, there is a tight labeling that uses only integers.

The intuition behind tightness is clear. Supported models are those models that can be “self-justified” by means of the one-step provability operator. Such self-justification may, in general, involve self-justification of individual atoms. For instance, if P = {p ← p}, then {p} is self-justified by means of TP (formally, {p} = TP({p})) and so, it is a supported model of P. For this program, the only way to justify p is on the basis of p itself, and this self-dependence of p is the reason why {p} is not a stable model of P. The tightness condition eliminates a possibility for positive self-dependence of individual atoms. For instance, the program {p ← not q ; q ← not p} is tight. Setting λ(p) = λ(q) = 1 yields a tight labeling of this program. Similarly, the program {a ← b, c; b ← d ; d } is tight, too (set λ(c) = λ(d) = 1, λ(b) = 2 and λ(a) = 3). Clearly, there are no positive self-dependencies of atoms in these programs and it is easy to verify that their supported models are also stable.

These considerations can be made formal to show that tightness of a program is indeed a sufficient condition for supported models to be stable, as discovered by Fages [1994].

Theorem 2.16 Fages Lemma. Let P be a tight logic program. Then every supported model of P is a stable model of P.

Proof Let M be a supported model of P. It follows that M is a model of P and so, a model of the reduct PM (cf. Corollary 2.1). Let N be a model of PM. We will show that M ⊆ N. In this way, we will show that M = LM(PM), that is, that M is stable.

Let us consider a tight labeling λ for P. To show the inclusion, we prove by transfinite induction that for every ordinal α, if a ∈ M and λ(a) = α, then a ∈ N. For α = 0, the property holds trivially. Indeed, since M is a supported model of P, M = TP(M) and so, there is a rule a ← B in P such that M ⊨ B. Clearly, a ← B⁺ belongs to PM. Consequently, N ⊨ a ← B⁺. Moreover, for every b ∈ B⁺, 0 = λ(a) > λ(b) ≥ 0. Thus, B⁺ = ∅ and so, N ⊨ B⁺. It follows then that N ⊨ a, that is, a ∈ N.

Let us then consider an ordinal α > 0 and assume that the claim holds for every ordinal that is less than α. Let a ∈ M satisfy λ(a) = α. Since M is a supported model of P, M = TP(M) and so, there is a rule a ← B in P such that B⁺ ⊆ M and B⁻ ∩ M = ∅. By the definition of tightness, for every b ∈ B⁺, λ(b) < α. Since B⁺ ⊆ M, the induction hypothesis yields b ∈ N. Hence, B⁺ ⊆ N. By the definition of the reduct, the rule a ← B⁺ belongs to PM. Since N is a model of PM, a ∈ N. Thus, the claim follows for α and, by induction, it holds for every ordinal. Consequently, the claim implies that M ⊆ N, as needed.

■

The result of Fages can be strengthened. The generalization was discovered by Erdem and Lifschitz [2003].

Definition 2.11 A program P is tight on a set X ⊆ At(P) if the program consisting of those rules a ← B in P that satisfy B⁺ ⊆ X is tight.

The following result is a simple corollary of Fages Lemma.

Corollary 2.3 Relativized Fages Lemma [Erdem and Lifschitz 2003]. If a program P is tight on a set X ⊆ At(P) and M is a supported model of P such that M ⊆ X, then M is a stable model of P.

Proof Let Q be the program consisting of all rules a ← B in P such that B⁺ ⊆ X. Since Q ⊆ P, TQ(M) ⊆ TP(M). Moreover, since M ⊆ X, TP(M) ⊆ TQ(M). It follows that TQ(M) = TP(M). Since M is a supported model of P, M = TP(M). This implies M = TQ(M), that is, M is a supported model of Q. By Fages Lemma, M is a stable model of Q. That is, M = LM(QM). Since M is a model of P, M is a model of PM. Moreover, QM ⊆ PM implies LM(QM) ⊆ LM(PM). Thus, we have that M is a model of PM and M ⊆ LM(PM). It follows that M = LM(PM) and so, M is a stable model of P.

■

To see the value of the generalization, let us consider the program consisting of the following rules:

This program has two supported models: M₁ = {p, q } and M₂ = {s}. However, this program is not tight. The second rule imposes on any tight labeling λ of the program a constraint λ(r) > λ(p), while the last rule requires that λ(p) > λ(r). Thus, we cannot apply Fages Lemma to conclude that these supported models are stable. It is easy to check that while not tight, P is tight on M₁ and on M₂. Thus, by Corollary 2.3, both supported models are in fact stable models of P.

Supported models can be characterized in terms of classical models of propositional theories obtained from programs by means of the so-called Clark’s completion [Clark 1978]. In the case of arbitrary (possibly infinite) propositional programs, the completion of a program is, in general, a formula in propositional logic with infinitary conjunctions and disjunctions. Thus, from now on in this section, we allow formulas with infinitary disjunctions and infinitary conjunctions. Since the semantics of such formulas is a straightforward generalization from the finite case and since we only rely on semantic arguments below, it is not a problem.⁶ Moreover, throughout the remainder of this section, given a possibly infinite set X of formulas we will often write X∧ and X∨ for the (infinitary) conjunction and disjunction of formulas in X, respectively.

For a rule r = a ← b₁, …, bm, not c₁, …, not cn, we define

Informally, body∧(r) is the propositional formula representing the condition of the body of the rule r. We note that if the body of r is empty, we have body∧(r) = ⊤.⁷ If we use the notation a ← B for a rule r, we write B∧ to denote the formula body∧(r).

Next, given a program P and an atom a, we set

That is, def P(a) is the disjunction (in general, infinitary) of all conditions of rules that “define” a in P.

Definition 2.12 Let P be a logic program over a propositional vocabulary At. We set

We call the last of these three (infinitary, in general) formulas the (Clark’s) completion of P.

The formula cmpl←(P) can be viewed as a propositional counterpart to the program. Its models are precisely the models of the program. The formula cmpl→(P) captures the idea that if a holds, at least one of its defining conditions holds. Thus, models of cmpl(P) are precisely those models of P whose elements are justified in the sense captured by the formula cmpl→(P). This notion of justification is precisely that of “support” in supported models. That is, models of the completion of a program are precisely the supported models of the program.

Theorem 2.17 Let P be a propositional program. An interpretation M is a supported model of P if and only if M is a model of cmpl(P).

Proof (⇒) Since M is a supported model of P, M = TP(M). Let us consider any atom a ∈ At. If a ∈ M, there is a rule r = a ← B in P, such that B⁺ ⊆ M and M ∩ B⁻ = ∅. Clearly, M ⊨ body∧(r) and so, M ⊨ def P(a). Thus, M ⊨ def P(a) ↔ a. If a ∉ M, then for every rule a ← B in P, we have B⁺ ⊈ M or M ∩ B⁻ ≠ ∅. It follows that M ⊭ def P(a) and so, M ⊨ def P(a) ↔ a. Consequently, M ⊨ cmpl(P).

(⇒) Let M ⊨ cmpl(P). It follows that M is a model of cmpl←(P) and so, M is a model of P. This implies that TP(M) ⊆ M. Moreover, since M ⊨ cmpl→(P), we have that for every a ∈ At, M ⊨ a → def P(a). In particular, if a ∈ M, M ⊨ def P(a). That is, there is a rule r = a ← B in P such that M ⊨ body∧(r). It follows that B⁺ ⊆ M and M ∩ B⁻ = ∅, that is, a ∈ TP(M). Thus, M ⊆ TP(M) and, consequently, M = TP(M), that is, M is a supported model of P.

■

It follows that in all those cases when supported and stable models coincide, stable models are models of the completion. Thus, we have the following corollary to our earlier results.

Corollary 2.4 Let P be a tight program. Then an interpretation M is a stable model of P if and only if M is a model of the completion of P.

This connection to propositional logic is important. It provides a direct way to use SAT solvers to compute stable models of tight programs. All that is needed is to construct the completion and convert it to the conjunctive normal form (clausify it). This observation is the foundation of an answer-set programming solver⁸ cmodels⁹ [Giunchiglia et al. 2006].

Clearly, not every program is tight and programs often have supported models that are not stable. For such programs, the completion is too weak to provide a description of stable models. However, it is possible to strengthen the completion so that to obtain a representation of stable models of an arbitrary logic program in terms of models of (infinitary) propositional formulas. The discussion we provide here follows closely that of Ferraris et al. [2006].

Definition 2.13 Let P be a logic program and Y a nonempty set of atoms. The external support formula for Y, written esP(Y), is the disjunction of all formulas body∧(r), where r is a rule in P such that H(r) ∈ Y and B(r)⁺ ∩ Y = ∅.

We note that for every atom a we have esP({a}) ⊨ def P(a). Indeed, def P(a) = esP({a}) ∨ F, where F is the disjunction of formulas body∧(r), for every rule r = a ← B such that a ∈ B⁺. Such rules are evidently circular and can be removed without affecting the class of stable models (such removals may affect the class of supported models, though). Thus, “reasonable” programs do not contain such rules, and for those programs we even have esP({a}) = def P(a). Let us define formulas

and let us call them the conjunctive and the disjunctive external support formulas, respectively. The following two properties follow from the observation above:

Thus, we have

The strengthening of the formula cmpl←(P) with es∧(P) (or es∨(P)), rather then with cmpl→(P), is what is needed to translate logic programs under the stable-model semantics into (infinitary, in the general case) propositional theories. The following theorem, in the form we present it, is due to Ferraris et al. [2006]. However, as they state in their paper, the theorem can essentially be attributed to Saccà and Zaniolo [1990], who provided a semantic characterization of stable models in terms of unfounded sets, the concept we will encounter later in the chapter. Since the intuitions behind unfounded sets and external support are closely related, the result of Saccà and Zaniolo can be directly reformulated in terms of external support.¹⁰

Theorem 2.18 Let P be a logic program. The following conditions are equivalent.

1.  X is a stable model of P.

2.  X is a model of cmpl←(P) ∧ es∨(P).

3.  X is a model of cmpl←(P) ∧ es∧(P).

Proof (1) ⇒ (2). Let X be a stable model of P. It follows that X is a model of P. Consequently, X is a model of cmpl←(P). Let us consider Y ⊆ At(P) such that Y = ∅ and let us assume that X ⊨ Y∨. It follows that X ∩ Y ≠ ∅. Since X = LM(PX), let a be the first element of X ∩ Y derived in the bottom-up computation of LM(PX). Let a ← B be the rule in P such that X ∩ B⁻ = ∅ and a ← B⁺ ∈ PX is used in the derivation. It follows that X ⊨ B⁺ and, so, since X ∩ B⁻ = ∅, also X ⊨ B∧. Moreover, by the choice of a, B⁺ ∩ Y = ∅. Thus, B∧ is a disjunct of esP(Y) and, consequently, X ⊨ esP(Y).

(2) ⇒ (3). This implication follows from the fact that es∨(P) entails es∧(P). Indeed, let us consider an interpretation M ⊆ At such that M ⊨ es∨(P). Let Y be a non-empty subset of At(P) such that M ⊨ Y∧. Then, M ⊨ Y∨ and so, M ⊨ esP(Y). Thus, M ⊨ es∧(P).

(3) ⇒ (1). Let us assume that X ⊨ cmpl←(P) ∪ es∧(P). Since X ⊨ cmpl←(P), X ⊨ P and, consequently, X ⊨ PX. Let X′ = LM(PX). Clearly, X′ ⊆ X. Let Y = X \ X′ and let us assume that Y ≠ ∅.

Since X ⊨ es∧(P), X ⊨ Y∧ → esP (Y). Moreover, we have Y ⊆ X and so, X ⊨ Y∧. Thus, X ⊨ esP(Y). It follows that there is a rule a ← B in P such that a ∈ Y, B⁺ ∩ Y = ∅, and X ⊨ B∧. The last property implies that a ← B⁺ belongs to PX and B⁺ ⊆ X.

Let z ∈ B⁺. Since B⁺ ∩ Y = ∅, z ∉ Y. Thus, z ∈ X′ (as we have B⁺ ⊆ X). This shows that B⁺ ⊆ X′. Since X′ is a model of PX, it is a model of a ← B⁺. Thus, a ∈ X′, a contradiction. It follows that X′ = X, that is X = LM(PX). Hence, X is a stable model of P.

■

Theorem 2.18 can be formulated in a slightly different but equivalent way. Namely, the role of cmpl←(P) is only to ensure that X is a model of P. Thus, conditions (2) and (3) can be phrased as:

2′.  X is a model of P and of es∨(P).

3′.  X is a model of P and of es∧(P),

respectively.

For finite programs, Theorem 2.18 could be used as the basis of an algorithm for computing stable models, as it reduces the problem to that of finding models of propositional theories and allows one to use satisfiability solvers for the task. We discussed a similar application of the completion construction on tight programs earlier, where we mentioned an answer-set programming solver cmodels. The problem here is that the theories es∧(P) and es∨(P) can be large, in the worst case exponential in the size of the program. However, their size can be restricted, thanks to the concept of a loop formula proposed by Lin and Zhao [2002] and an important characterization of stable models they discovered.

Definition 2.14 A positive dependency graph of a finite propositional program P, denoted by G⁺(P), has atoms of P as its nodes and there is an edge from an atom a to an atom b in G⁺(P) if P has a rule a ← B such that b ∈ B⁺. A set X ⊆ At(P) is a loop in P if the subgraph of G⁺(P) induced by X is strongly connected. We write L(P) for the set of loops of P.

We note that all subgraphs of G⁺(P) induced by single vertices are trivially strongly connected (each vertex can be reached from itself by a path of length 0). Therefore, all singleton subsets of At(P) are loops.

Let us define formulas

and let us call them the conjunctive and disjunctive loop formulas, respectively. Clearly, es∧(P) ⊨ lp∧(P) and es∨(P) ⊨ lp∨(P). Moreover, in general, the entailment relation cannot be reversed (the conjunctive and disjunctive loop formulas are weaker than the corresponding external support formulas). However, for finite graphs, the formulas lp∧(P) and lp∨(P) can be used in place of es∧(P) and es∨(P), respectively.

Theorem 2.19 Let P be a finite logic program. The following conditions are equivalent.

1.  X is a stable model of P.

2.  X is a model of cmpl←(P) ∧ lp∨(P).

3.  X is a model of cmpl←(P) ∧ lp∧(P).

Proof (1) ⇒ (2). This implication follows from the entailment es∨(P) ⊨ lp∨(P) and Theorem 2.18.

(2) ⇒ (3). The argument used in the proof of the implication (2) ⇒ (3) of Theorem 2.18 can be used here without any change.

(3) ⇒ (1). Let us assume that X ⊨ cmpl←(P) ∧ lp∧(P)}. Since X ⊨ cmpl←(P), X ⊨ P and, consequently, X ⊨ PX. Let X′ = LM(PX). Clearly, X′ ⊆ X. Let us assume that X \ X′ = ∅. Let H be the subgraph of G⁺(P) induced by X \ X′ and let Y be the set of nodes in a terminal strongly connected component in that graph (a strongly component is terminal if no edge starts in that component and ends in another). Clearly, Y ∈ L(P) and so, X ⊨ Y∧ → esP(Y).

Since Y ⊆ X, X ⊨ Y∧ and, consequently, X ⊨ esP(Y). Thus, there is a rule a ← B in P such that a ∈ Y, B⁺ ∩ Y = ∅, and X ⊨ B∧. It follows that a ← B⁺ belongs to PX and B⁺ ⊆ X.

Let z ∈ B⁺. Then the dependency graph G⁺(P) contains an edge (a, z). We observe that a ∈ X \ X′ (because a ∈ Y). If z ∈ X \ X′ then both a and z are nodes of H and so, the edge (a, z) is an edge of H. Since Y is a set of nodes of a terminal strongly connected component in H and a ∈ Y, z ∈ Y. However, we have Y ∩ B⁺ = ∅, a contradiction. Thus, z ∈ X \ X′. Since B⁺ ⊆ X and z ∈ B⁺, we have z ∈ X. Thus, z ∈ X′.

It follows that B⁺ ⊆ X′ and, since X′ = LM(PX), a ∈ X′. This is a contradiction. It follows that X′ = X, that is X = LM(PX). Hence, X is a stable model of P.

■

Theorem 2.19 can be similarly reformulated as Theorem 2.18 by stating explicitly that X must be a model of P rather than ensuring this by involving cmpl←(P) in the conditions (2) and (3).

Theorem 2.19 is the basis for the answer-set solver assat, developed by Lin and Zhao [2002]. Lin and Zhao demonstrated that it is not necessary to pre-compute the entire loop formula at once. It is possible to compute it incrementally, one loop at a time, and a stable model (if one exists) is often found after just a few loops have been exploited. Experiments proved the method worked well for many non-tight programs (for such programs, the completion is in general too weak to capture stable models). Nevertheless, the approach has its limitations as there are strong computational complexity arguments suggesting that in the worst case the number of loops must be exponential in the size of the program [Lifschitz and Razborov 2006].

It is worth noting that the use of external support formulas to find a propositional representation of a program is related to the approach proposed and investigated by Brass and Dix [1995a, 1995b, 1997]. By replacing atoms in the positive bodies of rules by the bodies of rules that define them, and by eliminating rules that cannot be reduced in this way to rules with only negative literals in the bodies, Brass and Dix construct the so called residual program for a program P. It has the same stable models as P. Since it is tight (it only contains rules that have empty positive body), the models of its completion are precisely the stable models of P.

Extensions to Programs with Variables. Concepts discussed in this subsection and the results we presented here generalize to programs with variables. For instance, we define an Herbrand interpretation M to be a supported model of a program with variables, say P, if M is a supported model of the ground program gr(P) (treated as a propositional program over the set HB(P) of atoms). Similarly, grounding allows us to extend the notion of tightness to such programs. A first-order sentence capturing the completion of a program P with variables can be constructed by adapting to the first-order case the construction we gave for propositional programs [Clark 1978]. Under these extensions the results we presented here generalize. In particular, stable models of programs with variables are supported, supported models of tight programs are stable, and supported models of programs are precisely Herbrand models of the completion.

The results characterizing stable models by means of the external support formulas and the loop formulas (Theorems 2.18 and 2.19) suggested extensions of the concept of a stable model to the case of arbitrary first-order sentences (not just programs), and to arbitrary (not just Herbrand) interpretations [Ferraris et al. 2007, Lifschitz 2010, Ferraris et al. 2011]. The general form of the characterization exposed a close relationship between the stable-model semantics and circumscription [Ferraris et al. 2011].

Stable models can also be characterized in terms of the so called equilibrium logic [Pearce 1997, Pearce 2006]. This characterization and the connection of the equilibrium logic to the logic of here-and-there [Heyting 1930] led to the notion of strong equivalence, which we discuss below. However, through extensions of the equilibrium logic to the first-order language case, it also resulted in the corresponding generalization of the stable-model semantics [Pearce and Valverde 2004, Pearce and Valverde 2008], equivalent to the one developed by Ferraris et al..

2.5.4    Equivalence and Strong Equivalence

Perhaps the most fundamental notion in any formal system is that of equivalence of formulas. A generic definition stipulates that two formulas are equivalent if they have the same models (under the semantics considered) or, informally, if they have the same meaning. Rewriting formulas into equivalent ones is an important technique of automated reasoning as it often allows us to replace formulas by simpler ones. To rewrite F, we typically identify in it a subformula, say G, and replace G with another one, say G′. The rewriting is correct if F and the result of replacing G with G′ in F are equivalent. If replacing G with G′ yields a correct rewriting no matter to what formula we apply the substitution, then G and G′are equivalent for replacement. In classical logic, two formulas G and G′are equivalent for replacement if and only if they have the same models, that is, have the same meaning. This is a simple consequence of the following monotonicity property of classical logic: for every formulas F and G, Mod(F ∧ G) = Mod(F) ∩ Mod(G).¹¹ Informally, extending a theory in classical logic by additional formulas has the effect of eliminating models.

The situation is different in the case of logic programming. Let us consider two programs P = {a ← not b} and P′ = P ∪ {b}. It is clear that M = {a} is a unique stable model of P and M′ = {b} is a unique stable model of P′. Thus, adding a new rule to P does not act on stable models in the same way as adding formulas does on models. This behavior, called non-monotonicity of the stable-model semantics, is the reason why equivalence of logic programs does not characterize the equivalence for the replacement. To give a concrete example, the programs {a} and {a ← not b} have the same stable models and so are equivalent. However, replacing in the program {a; b} the subprogram {a} with the program {a ← not b} is not a correct rewriting. The resulting program {a ← not b; b} has a unique stable model {b} while the original program has a unique stable model {a, b}. Replacing one subprogram with an equivalent one changes stable models!

We will now formally introduce the notion of equivalence for replacement for logic programs called strong equivalence. The definition is due to Lifschitz et al. [2001].

Definition 2.15 Two logic programs P and Q are strongly equivalent if for every program R, the programs P ∪ R and Q ∪ R have the same stable models.

To characterize strong equivalence we exploit the notion of an se-model [Lifschitz et al. 2001]. Se-models arise from a connection between logic programming and a certain intermediate logic, the logic here-and-there of Heyting [Heyting 1930, Chagrov and Zakharyaschev 1997]. The connection has been discovered by Pearce [1997]. He used it to define the equilibrium logic. As noted at the end of the previous section, the equilibrium logic played an important role in generalizing the stable-model semantics to the first-order setting.

Definition 2.16 Let At be a propositional vocabulary and let X and Y be subsets of At. A pair (X, Y) is an se-model of a program P over At if

1.  X ⊆ Y,

2.  Y ⊨ P, and

3.  X ⊨ PY.

We denote the set of all se-models of P by SE(P).

We note that se-models contain all information necessary to identify stable models of a program. The second components Y of se-models are models of a program P and, therefore, also of the reduct PY. For each model Y of P, the collection of se-models of the form (X, Y) allows us to decide whether Y is a stable model. If the only X such that (X, Y) is an se-model of P is X = Y, then Y is the least model of the reduct PY and, therefore, a stable model of P. Otherwise, Y is not a least model of PY and, therefore, not a stable model of P. This discussion is formalized below.

Proposition 2.10 An interpretation Y is a stable model of a program P if and only if (Y, Y) ∈ SE(P) and for every X ⊂ Y, (X, Y) ∈ SE(P).

Proof If Y is a stable model of P, then Y ⊨ P and Y ⊨ PY. Thus, (Y, Y) ∈ SE(P). If for some X ⊂ Y, we have X ⊨ PY, then Y ≠ LM(PY), a contradiction. Thus, X ⊭ PY and so (X, Y) ∈ SE(P). The converse implication follows by a similar argument.

■

We can now formulate and prove a characterization of strong equivalence discovered by Lifschitz et al. [2001].

Theorem 2.20 Logic programs P and Q are strongly equivalent if and only if SE(P) = SE(Q), that is, they have the same se-models.

Proof We first observe that for every three programs P, Q, and R,

Indeed, let (X, Y) be a pair of interpretations. By the definition, (X, Y) ∈ SE(P ∪ R) if and only if X ⊆ Y, Y ⊨ P ∪ R and X ⊨ (P ∪ R)Y = PY ∪ RY. These conditions together are equivalent to the conditions X ⊆ Y, Y ⊨ P, Y ⊨ R, X ⊨ PY, and X ⊨ RY. This new set of conditions is clearly equivalent to (X, Y) ∈ SE(P) and (X, Y) ∈ SE(R) or, equivalently, (X, Y) ∈ SE(P) ∩ SE(R).

(⇐). Let us assume that SE(P) = SE(Q). By (2.24), for every program R,

Thus, by Proposition 2.10, P ∪ R and Q ∪ R have the same stable models.

(⇒). Let us assume that P and Q are strongly equivalent and that SE(P) \ SE(Q) = ∅. Let (X, Y) ∈ SE(P) \ SE(Q). Then, (X, Y) ∈ SE(P) and (X, Y) ∉ SE(Q). The former implies that Y is a model of P and, so, of PY, as well. Thus, Y = LM(PY ∪ Y). Since PY ∪ Y = (P ∪ Y)Y, it follows that Y is a stable model of P ∪ Y. Since P and Q are strongly equivalent, Y is a stable model of Q ∪ Y and, so, a model of Q. Since (X, Y) ∉ SE(Q), X ⊭ QY.

Let us define R = X ∪ {y ← y′ | y, y′ ∈ Y \ X}. We have that Y is a model of both Q ∪ R and (Q ∪ R)Y. Let Z be any model of (Q ∪ R)Y such that Z ⊆ Y. Since R is a Horn program, (Q ∪ R)Y = QY ∪ R and, so, Z ⊨ QY ∪ R. In particular, Z ⊨ QY and, so, X ≠ Z (we recall that X ⊭ QY). Since Z ⊨ R, X ⊆ Z. Thus, Z \ X ≠ ∅. Let y ∈ Z \ X. Clearly, we have y ∈ Y \ X. Moreover, for every y′ ∈ Y \ X, we also have that the rule y′ ← y is in R. Since Z ⊨ R, Y \ X ⊆ Z. Consequently, Y ⊆ Z. It follows that Z = Y and, so, Y is a stable model of Q ∪ R. By the strong equivalence of P and Q, Y is a stable model of P ∪ R and, consequently, Y = LM((P ∪ R)Y). Since X ⊨ PY ∪ R = (P ∪ R)Y and X ⊆ Y, X = Y. We argued above that X ⊭ QY. Thus, Y ⊭ QY and, so, Y ⊭ Q, a contradiction. Hence, we obtain SE(P) ⊆ SE(Q). The converse inclusion follows by the symmetry argument.

■

Comments. The notion of strong equivalence has received a significant amount of attention. Several variants of the notion have been proposed, among which the most interesting one is that of uniform equivalence [Sagiv 1988, Maher 1988, Eiter and Fink 2003] (two propositional programs P and Q are uniformly equivalent if for every set A of atoms, the programs P ∪ A and Q ∪ A have the same stable models). As with other concepts, the notions of strong and uniform equivalence have been extended to the first-order setting. Discussing this line of research, including the vast array of complexity results is beyond the scope of this tutorial. Instead, we refer to a survey by Woltran [2011], which is a good source of references.

2.6    The Well-Founded Model Semantics

For Horn programs, the stable-model semantics coincides with the least-model semantics and forces a truth value on every atom appearing in the program. For programs with negation it is no longer so. Let P be the program consisting of rules

This program has two stable models: {a, d} and {a, e}. Considering the stable models of P as representations of two possible ways how things may be, P entails a, ¬b and ¬c. However, P entails neither d nor ¬d, and neither e nor ¬e. These properties of P are captured by a three-valued interpretation of At = {a, b, c, d, e}, in which a is true, b and c are false and d and e are unknown. The problem we study in this section is how to derive this three-valued interpretation or, at least, approximate it, without having to compute all stable models. In this example, it seems possible. The program clearly makes a true. Since there is no way to derive c, the program makes c false. But now, there is no way to derive b. Thus, b is false, too. Simplifying the program with respect to these truth values results in the program

At this point, we see that no further derivations are possible and, so, d and e are unknown.

In the remainder of this section, we study methods to approximate truth values forced by a program on its atoms. To this end, we will consider three- and fourvalued interpretations on sets of propositional atoms, most often on the set At(P) of atoms of a program P. We recall (cf. Section 2.2) that we represent a fourvalued interpretation of At(P) by a pair (I, J) of interpretations (subsets) of At(P) and that we write All(P) and All₄(P) for the lattices of two-valued and four-valued interpretations, respectively, the former with the inclusion and the latter with the precision ordering. We recall that both lattices are complete.

Given a four-valued interpretation (I, J), atoms in I can be thought of as certain, and those not in J as impossible. Because of the latter, atoms in J will often be referred to as possible. In the four-valued setting, an atom is true if it is certain and possible, false if it is not certain and not possible, unknown if it is possible but not certain, and inconsistent if it is certain and impossible (cf. Section 2.2). We are primarily interested in the space of three-valued interpretations, that is, four-valued interpretations (I, J) such that I ⊆ J (they do not use the inconsistent truth value). We call such interpretations consistent. However, for the sake of elegance and simplicity of technical arguments, it is convenient not to impose any restrictions on the class of four-valued interpretations and consider the entire lattice All₄(P).

The mappings ΦP: All₄(P) → (All(P) and TP : All₄(P) → (All(P) play the central role in our discussion. We recall that

If (I, J) is an approximation of the set of atoms that are true under P, then all atoms in ΦP(I, J) can be regarded as true under P, too. Indeed they can be derived by rules whose positive body contains only atoms that are certain and whose negative body consists of atoms that are impossible. Similarly, ΦP(J, I) can be regarded as the set of atoms that are possible. Indeed it contains those atoms that can be derived by means of a rule that possibly might “fire” (atoms that appear in the body of the rule non-negated are possible and those that appear negated are not certain and so, might possibly be false). Consequently, the pair (ΦP(I, J), ΦP(J, I)) can also be viewed as an approximation to the set of atoms that are true under the program. This is the intuition that motivated the four-valued one-step provability operator TP which, we recall, is given by

We also recall that given two interpretations (I, J) and (I′, J′), we defined (I, J) ≤p (I′, J′) to hold if and only if I ⊆ I′ and J′ ⊆ J. We say that an interpretation (I, J) is a four-valued model of P if TP(I, J) ≤p (I, J). This notion is equivalent to the notion of a model in the four-valued Belnap logic [Belnap 1977, Fitting 2002]. Fixpoints of TP are of interest as they are those models of P that TP “revises” back into themselves or, to put it differently, that cannot be “revised away” by applying TP. We call fixpoints of TP four-valued supported models of P. Consistent fixpoints of TP are called partial supported models. The terminology is motivated by the following property.

Proposition 2.11 Let P be a program and M an interpretation. Then M is a supported model of P if and only if (M, M) is a fixpoint of TP.

Proof It follows directly from the definition that ΦP(M, M) = TP(M). Thus,

and so, TP(M) = M if and only if TP(M, M) = (M, M).

■

There are programs with no two-valued supported models (for instance, {p ← not p}). However, partial supported models are guaranteed to exist. In fact, there is a unique least partial supported model, a property that follows from Theorem 2.5 according to which the operator TP is monotone and, therefore, it has the least fixpoint. We call the least partial supported model of TP the Kripke-Kleene model of P and denote it by KK(P). The Kripke-Kleene model of P is three-valued.

Proposition 2.12 Let P be a propositional logic program and let KK(P) = (I, J). Then, I ⊆ J, that is, KK(P) is three-valued.

Proof Let us consider a three-valued interpretation (I, J). By definition, I ⊆ J. By Theorem 2.5

It follows that TP(I, J) = (ΦP(I, J), ΦP(J, I)) is three-valued. The least fixpoint of TP is obtained by iterating it over the three-valued interpretation (∅, H(P)) (the argument we used to construct the least fixpoint of the operator TP applies almost literally, except that the construction needs to extend to ordinals beyond ω; footnote 4). Since (∅, H(P)) is three-valued, using the property we just proved, it is easy to show by transfinite induction that every step of the process to construct the least fixpoint of TP, yields a three-valued interpretation.

■

Let us illustrate the iterative construction behind the Kripke-Kleene model. To this end, let P be the program given by the rules (2.25). We have At(P) = {a, b, c, d, e} and

Since, as we see, we have already reached a fixpoint, KK(P) = ({a}, {a, d, e}) and it is precisely the interpretation we derived informally above. However, in general the Kripke-Kleene model is quite weak. Let now P be the program given by the rules

We have At(P) = {a, b} and

Thus, KK(P) = (∅, {a, b}) and it gives us no information about the truth values of the atoms. At the same time, {a} is the only supported model of P and the construction of the Kripke-Kleene model fails to inform us about it.

While the Kripke-Kleene construction offers an approximation to two-valued supported models (albeit often a poor one, as the last example demonstrated), we are primarily interested in approximating stable models. Since stable models are supported models, we can use the Kripke-Kleene model as an approximation to stable models (when they exist). However, the Kripke-Kleene model often fails to provide a good approximation even for Horn programs. Let P = {p ← p}. It is easy to verify that KK(P) = (∅, {p}) while P has a unique stable model in which p is false. The Kripke-Kleene process fails to discover that. The problem is that p is self-supported.

To obtain more information about the truth values of atoms under a program, we need a stronger approximation revision method. Let (I, J) be an approximation. The assumption that all atoms not in J are false implies that every rule in P with each negative literal in its body having the form not a, where a ∉ J, can be used when deriving atoms from P. The reduct PJ is the set of all such rules with their negative literals simplified away. Thus, any atom we can derive from PJ can be taken as true under P (as long as every atom not in J is false), and the set of all those atoms can be taken as the lower bound on the revised approximation. That is, we can revise the lower bound of the approximation to LM(PJ) = ΓP(J). Similarly, using the fact that all atoms not in I are possibly false, we are justified in using the rules of the reduct PI to establish atoms that are possibly true under P (given an approximation (I, J)). That is, we can revise the upper bound of the approximation to LM(PI) = ΓP(I). This motivates the following approximation revision operator:

The operator SP has the following properties similar to those of TP.

Theorem 2.21 For every logic program P, SP is monotone with respect to the precision operator and for every interpretations I and J of At(P) such that I ⊆ J, ΓP(J) ⊆ ΓP(I), that is, SP(I, J) is consistent.

Proof Let us assume that (I, J) ≤p (I′, J′). It follows that I ⊆ I′ and J′ ⊆ J. By the antimonotonicity of ΓP (cf. Proposition 2.5),

Thus,

Moreover, if I ⊆ J then ΓP(J) ⊆ ΓP(I). Thus, a single iteration of the operator SP on a consistent interpretation yields a consistent interpretation. It is a routine matter to use this property in transfinite induction to show that every interpretation obtained by iterating SP over (∅, At(P)) is consistent.

■

The following result shows that stable models of a program P can be described in terms of (some) fixpoints of the operator SP.

Proposition 2.13 For every program P, an interpretation M ⊆ At(P) is a stable model of P if and only if (M, M) is a fixpoint of SP.

Proof It is clear that SP(M, M) = (ΓP(M), ΓP(M)). Thus, the assertion follows.

■

Proposition 2.13 motivates the following concepts. An interpretation (I, J) ∈ All₄(P) is a four-valued stable model of P if it is a fixpoint of the operator SP. A consistent four-valued stable model of P is a partial stable model of P (or a threevalued stable model of P). Under this notation, we have the following generalization of Theorem 2.15.

Theorem 2.22 Let P be a propositional logic program and (I, J) a four-valued stable model of P. Then (I, J) is a four-valued supported model of P.

Proof Let (I, J) be a four-valued stable model of P. By the definition, (I, J) = SP(I, J), that is, I = ΓP(J) and J = ΓP(I). It follows that I, as a least fixpoint of , satisfies I = ΦP(I, J). Similarly, J satisfies J = ΦP(J, I). Thus, (I, J) = TP(I, J) and so, (I, J) is a four-valued supported model of P.

■

The Knaster-Tarski theorem combined with Theorem 2.21 implies that the operator SP has a least fixpoint, which is consistent and provides the basis for the following definition of the well-founded model of a program. The concept of the well-founded model is due to Van Gelder et al. [1991]. Our presentation follows the exposition proposed by Fitting [2002].

Definition 2.17 The well-founded model of a propositional logic program P is defined as the least fixpoint of SP. We denote it by WF(P).

By the definition, the well-founded model approximates all partial stable models and, in particular, all two-valued stable models (if they exist).

The well-founded model of a program is a “tighter” approximation than the Kripke-Kleene model. This property follows directly from Theorem 2.22.

Corollary 2.5 For every propositional program P, KK(P) ≤p WF(P).

Let us consider again the program P = {p ← p}. We have seen that KK(P) = (∅, {p}). On the other hand, we have

Thus, WF(P) = (∅, ∅) and so, p is false (rather than unknown) in the well-founded model, in agreement with the intuitive meaning of the program.

Remark 2.3 We note that originally the semantics we are discussing here were introduced with their own specific motivations. In particular, the motivation behind the Kripke-Kleene and the well-founded semantics was to extend the least-model semantics of Horn programs to programs with negation, with the objective to preserve the property of the uniqueness of an intended model. In general, this meant moving beyond the setting of two-valued interpretations. In contrast, the objective behind the proposal of the stable-model semantics was to keep intended models two valued. But that meant that the existence and uniqueness properties of intended models could no longer be guaranteed. Interestingly, it turned out that all major semantics can be seen from the perspective of the unifying algebraic framework of fixpoints of lattice operators. This perspective elucidates salient features of the semantics and allows us to relate them to each other showing, for instance, how stable models can be approximated by the Kripke-Kleene and the well-founded semantics. We discuss several other similar connections below.

We have seen that there is a close connection between the semantics of stable models and the well-founded semantics. First, the well-founded model of a program is one of (possibly many) four-valued stable models of the program. Moreover, if WF(P) = (I, J) and M is a two-valued stable model P then we have I ⊆ M ⊆ J. That is, the well-founded model provides some information about stable models. We will now discuss some stronger connections between the two.

Theorem 2.23 Let P be a propositional logic program such that WF(P) is two-valued and equals (I, I). Then I is a unique stable model of P.

Proof Since WF(P) is a fixpoint of the operator SP,

Thus, I = ΓP(I) and so, I is a stable model of P. Let J be any stable model of P. It follows that (J, J) is a fixpoint of SP (Proposition 2.13). Thus, (I, I) ≤p (J, J). Consequently, I ⊆ J and J ⊆ I and so, I = J.

■

In view of this result, it is natural to ask if there are any interesting classes of programs for which the well-founded model is two-valued. The classes of Horn programs and, more generally, stratified programs are obvious candidates and, indeed, stratified programs have the property in question.

Theorem 2.24 Let P be a stratified propositional program. Then, WF(P) is two-valued.

Proof We will only consider Horn programs and leave the more technically (but not conceptually) involved case of stratified programs to the reader. If P is a Horn program, for every interpretation I ⊆ At(P), ΓP(I) = LM(P). Thus, SP(∅, At(P)) = (LM(P), LM(P)) and SP(LM(P), LM(P)) = (LM(P), LM(P)). It follows that WF(P) = (LM(P), LM(P)).

■

We conclude with two alternative characterizations of the well-founded model. First, we observe that the operator is monotone.

Proposition 2.14 For every propositional program P, the operator is monotone.

Proof Let I ⊆ J. Since ΓP is antimonotone (cf. Proposition 2.5), ΓP(J) ⊆ ΓP(I). Thus, again by the antimonotonicity of ΓP, .

■

The essence of Proposition 2.14 is that has a least fixpoint, which we will denote by . We now have the following result that can be traced back to an early paper on the well-founded semantics due to Van Gelder [1993] in which he proposed and studied alternating fixpoints of programs.

Theorem 2.25 Let P be a propositional logic program and let A be the least fixpoint of . Then WF(P) = (A, ΓP(A)).

Proof By definition, SP(I, J) = (I, J) if and only if ΓP(J) = I and ΓP(I) = J or, equivalently, and J = ΓP(I). Thus, if A is the least fixpoint of , then (A, ΓP(A)) is the least fixpoint of SP, that is, WF(P) = (A, ΓP(A)).

■

Finally, we present yet another characterization of the well-founded model, the one proposed in the original paper by Van Gelder et al. [1991].

Definition 2.18 Let P be a propositional logic program and (I, J) a four-valued interpretation of At(P). A set X ⊆ At(P) is an unfounded set for P with respect to (I, J) if for each atom a ∈ X and for each rule a ← B in P at least one of these two conditions holds:

1.   B⁺ ⊈ J or I ∩ B⁻ ≠ ∅.

2.   B⁺ ∩ X ≠ ∅.

We note that unfounded sets are in some sense complementary to the idea of external support, which we exploited when discussing the Loop Theorem.

Informally, the condition (1) says that B evaluates to false in (I, J) and so, the rule a ← B cannot be used. The condition (2) says that using a ← B to derive a depends on some other element of X being true, and implies that self-support cannot be avoided when deriving elements of X. Thus, elements of an unfounded set cannot be derived from a program under the assumption that I contains atoms that are certain and J those that are possible (those that are not impossible). Consequently, elements of unfounded sets can be regarded as false. This is the reason why unfounded sets are of interest to the semantics of a program. The key property of unfounded sets is that they are closed under unions.

Theorem 2.26 Let P be a propositional logic program and (I, J) a four-valued interpretation of At(P). The union of any collection of subsets of At(P) that are unfounded for P with respect to (I, J) is unfounded for P with respect to (I, J).

Proof Let X be a family of subsets of At(P) that are unfounded for P with respect to (I, J). Let us set Y = ∪X. To show that Y is unfounded for P with respect to (I, J), let a ∈ Y and let us consider a rule a ← B in P. If B⁺ ⊈ J or I ∩ B⁻ = ∅, then the condition (1) of Definition 2.18 holds. Thus, let us assume otherwise (B⁺ ⊆ J and I ∩ B⁻ = ∅). Since a ∈ Y, there is X ∈ X such that a ∈ X. Since X is unfounded for P with respect to (I, J) and the condition (1) does not hold for the atom a and the rule a ← B, it follows that B⁺ ∩ X ≠ ∅. Thus, B⁺ ∩ Y ≠ ∅ (as X ⊆ Y).

■

As a corollary from this result, we obtain that for every propositional program P and every four-valued interpretation (I, J) of At(P), there exists a greatest unfounded set for P with respect to (I, J). We will denote it by GUSP(I, J). This mapping GUSP is monotone.

Proposition 2.15 Let P be a propositional logic program and (I, J) and (I′, J′) two four-valued interpretations of At(P) such that (I, J) ≤p (I′, J′). Then, GUSP(I, J) ⊆ GUSP(I′J′).

Proof It suffices to prove that if X is unfounded for P with respect to (I, J) then X is unfounded for P with respect to (I′, J′). To this end, let us consider an atom a ∈ X and a rule a ← B in P. If B⁺ ⊈ J or I ∩ B⁻ ≠ ∅ then, since (I, J) ≤p (I′, J′), B⁺ ⊈ J′ or I′ ∩ B⁻ ≠ ∅. If B⁺ ∩ X ≠ ∅ then, obviously, X satisfies the same condition for a and a ← B with respect to (I′, J′).

■

We now define the operator WP : All₄(P) → All₄(P) by setting

where (I, J) ∈ All₄(P). We note that the operator WP is monotone, which follows from our earlier result on the monotonicity of the operator TP (cf. Theorem 2.5; it implies that if (I, J) ≤p (I′, J′) then ΦP(I, J) ⊆ ΦP(I′, J′)) and Proposition 2.15. Thus, it has a least fixpoint. In general, the operator WP is different from SP.¹² However, the least fixpoints of the two operators coincide.

Theorem 2.27 Let P be a propositional program. The well-founded model WF(P), of P is the least fixpoint of the operator WP.

The fact that the well-founded model approximates stable models allows us to use it (or, more commonly, computation identifying unfounded sets) as a strong propagation rule (search-space pruning mechanism) when computing stable models of programs. The propagation method based on the well-founded semantics is, in general, stronger than similar methods based on the Kripke-Kleene semantics. However, computation of the well-founded model is relatively expensive. The well-founded model of a program can be computed in time that is quadratic in the size of P, as opposed to the linear-time computation of the Kripke-Kleene model. Some improvements over the quadratic-time worst-case bound have been obtained [Berman et al. 1995, Lonc and Truszczyński 2001], but it is still an open problem whether significantly faster algorithms exist. It is however important to note that the quadratic worst-case arises quite rarely. Moreover, for many programs written to exploit the well-founded model as the unique intended model in a Prolog-style fashion, the well-founded semantics can be computed fast enough to make systems such as XSB [Sagonas et al. 1994] effective in many practical settings (more comments on XSB follow below).

Extensions to Programs with Variables. The well-founded semantics can be defined for programs with variables. As in the other cases we discussed, the extension exploits the concept of grounding. Let P be a program with variables over a vocabulary σ. A pair (I, J) of two Herbrand interpretations I and J of σ (a four-valued Herbrand interpretation of σ) is the well-founded model of P if (I, J) is the well-founded model of gr(P). It follows directly from this definition that the well-founded model of a program is, in fact, a three-valued interpretation of σ.

All other notions, most importantly those of partial stable and supported models and the Kripke-Kleene semantics, extend to programs with variables in the same way. The properties we discussed generalize, too. In particular, the Kripke-Kleene model approximates all partial supported models and so, also all partial stable models, including the well-founded model. Moreover, the well-founded model approximates all partial stable models. Finally, the well-founded model of any stratified or locally stratified program is two-valued.

The fact that for many programs with negation including, as we just noted, those that are stratified, the well-founded model is two-valued gave rise to efforts aiming at making the well-founded semantics the theoretical basis of logic programming with negation. A Prolog-like query-evaluation programming language XSB was proposed, developed, and implemented by Warren and his collaborators [Chen and Warren 1993a, Chen and Warren 1993b, Chen et al. 1993, Sagonas et al. 1994]. It is at present among the most broadly used Prolog descendants.

In an orthogonal effort, Denecker proposed the well-founded semantics as the basis for the concept of an inductive definitions [Denecker 1998, Denecker 2000, Denecker and Ternovska 2008]. Together with his collaborators he designed and implemented a knowledge representation and reasoning system FO(·) [Denecker 2009], in which first-order logic is extended by modules called definitions that are interpreted in terms of the well-founded semantics adjusted to account for “inputs.” This computational knowledge representation system is now among the best in terms of performance and modeling capabilities [Denecker et al. 2009, Calimeri et al. 2014].

2.7    Concluding Remarks

This brings our brief tour of the two semantics to an end. There is much that has been omitted or addressed only briefly. For instance, we said very little about the impressive body of results concerning the complexity and the expressivity issues. Excellent papers by Schlipf [1995] and Dantsin et al. [2001] can help fill this gap.

Similarly, we only briefly mentioned answer-set programming, which transformed the stable-model into practical computational methodology and a formalism for modeling and solving hard search problems. For more details we refer to the paper by Brewka et al. [2011], the monograph by Gebser et al. [2012], papers reporting on the answer-set programming competitions [Denecker et al. 2009, Calimeri et al. 2014], and to the special issue of the AI Magazine dedicated to answer-set programming [Brewka et al. 2016]. On-going development efforts that have already resulted in answer-set program processing software with excellent performance and a growing track record of successful practical applications that are worth mentioning include the family of tools around the gringo grounder and the clasp solver,¹³ the IDP project,¹⁴, and the dlv project¹⁵

Practical systems based on the well-founded semantics form another thriving area of research, with XSB,¹⁶ Ontobroker,¹⁷ and Flora-2¹⁸ among the most prominent examples. Yap¹⁹ and Ciao Prolog²⁰ offer partial support for the well-founded semantics and plan to expand it.

Finally, we have only mentioned but not discussed in any detail recent generalizations of the stable-model semantics to the full syntax of first-order logic and arbitrary (not only Herbrand) interpretations. The papers by Ferraris et al. [2011] and Pearce and Valverde [2008] are good starting points for an in-depth look into that topic. A useful tool to study extensions to the first-order language is the theory of the stable-model semantics for infinitary propositional logic [Truszczynski 2012, Gebser et al. 2015, Harrison et al. 2015].

Acknowledgments

The author thanks the reviewers for many constructive comments that helped to improve the presentation. The author wants to extend special thanks to Thomas Eiter and Michael Kifer who commented extensively on earlier drafts of the chapter.

References

H. Andréka and I. Németi. 1978. The generalized completeness of horn predicate-logic as a programming language. Acta Cybern., 4(1): 3–10. 135

K. Apt, H. Blair, and A. Walker. 1988. Towards a theory of declarative knowledge. In J. Minker, ed., Foundations of Deductive Databases and Logic Programming, pp. 89–142. Morgan Kaufmann, Los Altos, CA. DOI: 10.1016/B978-0-934613-40-8.50006-3. 122, 137, 138, 145, 152

N. D. Belnap. 1977. A useful four-valued logic. In J. M. Dunn and G. Epstein, eds., Modern Uses of Multiple-Valued Logic. D. Reidel. DOI: 10.1007/978-94-010-1161-7_2. 168

K. Berman, J. Schlipf, and J.Franco. 1995. Computing the well-founded semantics faster. In Logic Programming and Nonmonotonic Reasoning (Lexington, KY, 1995), volume 928 of Lecture Notes in Artificial Intelligence, pp. 113–125. Springer. DOI: 10.1007/3-540-59487-6_9. 175

E. B¨orger. 1974. Beitrag zur Reduktion des Entscheidungsproblems auf Klassen von Horn-formeln mit kurzen Alternationen. Archiv für mathematische Logik und Grudlagenforschung, 16: 67–84. 135

S. Brass and J. Dix. 1995a. Characterizations of the stable semantics by partial evaluation. In V. W. Marek and A. Nerode, eds., Proceedings of the 3rd International Conference on Logic Programming and Nonmonotonic Reasoning, LPNMR 1995, volume 928 of LNCS, pp. 85–98. Springer. DOI: 10.1007/3-540-59487-6_7. 162

S. Brass and J. Dix. 1995b. Disjunctive semantics based upon partial and bottom-up evaluation. In L. Sterling, ed., Proceedings of the 12th International Conference on Logic Programming, ICLP 1995, pp. 199–213. MIT Press. DOI: 10.1007/978-3-642-51136-3_13. 162

S. Brass and J. Dix. 1997. Characterizations of the disjunctive stable semantics by partial evaluation. J. Log. Program., 32(3): 207–228. DOI: 10.1016/S0743-1066(96)00115-X. 162

G. Brewka, T. Eiter, and M. Truszczynski. 2011. Answer set programming at a glance. Commun. ACM, 54(12): 92–103. DOI: 10.1145/2043174.2043195. 122, 144, 149, 176

G. Brewka, T. Eiter, and M. Truszczynski, eds. 2016. Special Issue on Answer Set Programming, volume 37(3) of AI Magazine. AAAI. DOI: 10.1609/aimag.v37i3.2669. 176

J. Büchi. 1962. Turing Machines and the Entscheidungsproblem. Mathematische Annalen, 148. DOI: 10.1007/978-1-4613-8928-6_34. 135

F. Calimeri, G. Ianni, and F. Ricca. 2014. The third open answer set programming competition. Theory and Practice of Logic Programming, 14(1): 117–135. DOI: 10.1017/S1471068412000105. 176

S. Ceri, G. Gottlob, and L. Tanca. 1990. Logic programming and databases. Surveys in computer science. Springer-Verlag. DOI: 10.1007/978-3-642-83952-8. 133

A. Chagrov and M. Zakharyaschev. 1997. Modal Logic. Oxford University Press. 164

W. Chen and D. S. Warren. 1993a. A goal-oriented approach to computing the well-founded semantics. J. Log. Program., 17(2/3&4): 279–300. DOI: 10.1016/0743-1066(93)90034-E. 176

W. Chen and D. S. Warren. 1993b. Query evaluation under the well founded semantics. In C. Beeri, ed., Proceedings of the 12th ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, PODS 1993, pp. 168–179. ACM Press. DOI: 10.1145/153850.153865. 176

W. Chen, T. Swift, and D. S. Warren. 1993. Goal-directed evaluation of well-founded sematics for XSB. In D. Miller, ed., Proceedings of the International Symposium on Logic Programming, ISLP 1993, p. 679. MIT Press. 176

K. Clark. 1978. Negation as failure. In H. Gallaire and J. Minker, eds., Logic and data bases, pp. 293–322. Plenum Press, New York-London. DOI: 10.1007/978-1-4684-3384-5_11. 122, 138, 157, 163

A. Colmerauer, H. Kanoui, P. Roussel, and R. Passero. 1973. Un système de communication homme-machine en Francais. Technical report, Groupe de Recherche en Intelligence Artificielle, Universitè d’Aix-Marseille II. 121, 135

E. Dantsin, T. Eiter, G. Gottlob, and A. Voronkov. 2001. Complexity and expressive power of logic programming. ACM Comput. Surv., 33(3): 374–425. DOI: 10.1145/502807.502810. 144, 176

M. Denecker. 1998. The well-founded semantics is the principle of inductive definition. In J. Dix, L. F. del Cerro, and U. Furbach, eds., Proceedings of the European Workshop on Logics in Artificial Intelligence, European Workshop, JELIA 1998, volume 1489 of Lecture Notes in Computer Science, pp. 1–16. Springer. DOI: 10.1007/3-540-49545-2_1. 176

M. Denecker. 2000. Extending classical logic with inductive definitions. In J. W. Lloyd, V. Dahl, U. Furbach, M. Kerber, K.-K. Lau, C. Palamidessi, L. M. Pereira, Y. Sagiv, and P. J. Stuckey, eds., Proceedings of the First International Conference on Computational Logic, CL 2000, volume 1861 of Lecture Notes in Computer Science, pp. 703–717. Springer. DOI: 10.1007/3-540-44957-4_47. 176

M. Denecker. 2009. A knowledge base system project for fo(.). In P. M. Hill and D. S. Warren, eds., Proceedings of the 25th International Conference on Logic Programming, ICLP 2009, volume 5649 of Lecture Notes in Computer Science, p. 22. Springer. DOI: 10.1007/978-3-642-02846-5_2. 122, 176

M. Denecker and E. Ternovska. 2008. A logic for non-monotone inductive definitions. ACM Transactions on Computational Logic, 9(2). DOI: 10.1145/1342991.1342998. 131, 133, 176

M. Denecker, V. Marek, and M. Truszczynski. 2000. Approximations, stable operators, wellfounded fixpoints and applications in nonmonotonic reasoning. In J. Minker, ed., Logic-Based Artificial Intelligence, pp. 127–144. Kluwer Academic Publishers. DOI: 10.1007/978-1-4615-1567-8_6. 128

M. Denecker, M. Bruynooghe, and V. Marek. 2001. Logic programming revisited: Logic programs as inductive definitions. ACM Transactions on Computational Logic, 2(4): 623–654. DOI: 10.1145/383779.383789. 131, 133

M. Denecker, J. Vennekens, S. Bond, M. Gebser, and M. Truszczynski. 2009. The second answer set programming competition. In E. Erdem, F. Lin, and T. Schaub, eds., Proceedings of the 10th International Conference on Logic Programming and Nonmonotonic Reasoning, volume 5753 of Lecture Notes in Computer Science, pp. 637–654. Springer. DOI: 10.1007/978-3-642-04238-6_75. 176

M. Denecker, Y. Lierler, M. Truszczynski, and J. Vennekens. 2012. A Tarskian Informal Semantics for Answer Set Programming. In A. Dovier and V. S. Costa, eds., Technical Communications of the 28th International Conference on Logic Programming (ICLP 2012), volume 17 of Leibniz International Proceedings in Informatics (LIPIcs), pp. 277–289. Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, Dagstuhl, Germany. DOI: 10.4230/LIPIcs.ICLP.2012.277. 131, 133

K. Doets. 1994. From Logic to Logic Programming. Foundations of Computing Series. MIT Press, Cambridge, MA. 127

W. Dowling and J. Gallier. 1984. Linear-time algorithms for testing the satisfiability of propositional Horn formulae. Journal of Logic Programming, 1(3): 267–284. DOI: 10.1016/0743-1066(84)90014-1. 144

T. Eiter and M. Fink. 2003. Uniform equivalence of logic programs under the stable model semantics. In C. Palamidessi, ed., Proceedings of the 19th International Conference on Logic Programming, ICLP 2003, volume 2916 of Lecture Notes in Computer Science, pp. 224–238. Springer. DOI: 10.1007/978-3-540-24599-5_16. 166

T. Eiter, G. Gottlob, and H. Mannila. 1994. Adding disjunction to datalog. In V. Vianu, ed., Proceedings of the 13th ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, PODS 1994, pp. 267–278. ACM Press. DOI: 10.1145/182591.182639. 148

T. Eiter, G. Gottlob, and H. Mannila. 1997. Disjunctive datalog. ACM Trans. Database Syst., 22(3): 364–418. DOI: 10.1145/261124.261126. 148

E. Erdem and V. Lifschitz. 2003. Tight logic programs. Theory and Practice of Logic Programming, 3(4-5): 499–518. DOI: 10.1017/S1471068403001765. 156

F. Fages. 1994. Consistency of Clark’s completion and existence of stable models. Journal of Methods of Logic in Computer Science, 1: 51–60. 154, 155

P. Ferraris, J. Lee, and V. Lifschitz. 2006. A generalization of the lin-zhao theorem. Ann. Math. Artif. Intell., 47(1-2): 79–101. DOI: 10.1007/s10472-006-9025-2. 159, 160

P. Ferraris, J. Lee, and V. Lifschitz. 2007. A new perspective on stable models. In M. M. Veloso, ed., Proceedings of the 20th International Joint Conference on Artificial Intelligence, IJCAI 2007, pp. 372–379. 163

P. Ferraris, J. Lee, and V. Lifschitz. 2011. Stable models and circumscription. Artif. Intell., 175(1): 236–263. DOI: 10.1016/j.artint.2010.04.011. 163, 177

M. C. Fitting. 1985. A Kripke-Kleene semantics for logic programs. Journal of Logic Programming, 2(4): 295–312. DOI: 10.1016/S0743-1066(85)80005-4. 138

M. C. Fitting. 2002. Fixpoint semantics for logic programming—a survey. Theoretical Computer Science, 278: 25–51. DOI: 10.1016/S0304-3975(00)00330-3. 129, 168, 171

M. Gebser, R. Kaminski, B. Kaufmann, and T. Schaub. 2012. Answer Set Solving in Practice. Synthesis Lectures on Artificial Intelligence and Machine Learning. Morgan & Claypool Publishers. 122, 176

M. Gebser, A. Harrison, R. Kaminski, V. Lifschitz, and T. Schaub. 2015. Abstract Gringo. In T. Eiter and F. Toni, eds., Proceedings of International Conference on Logic Programming, ICLP 2015. (to appear). DOI: 10.1017/S1471068415000150. 177

M. Gelfond and V. Lifschitz. 1988. The Stable Semantics for Logic Programs. In R. A. Kowalski and K. A. Bowen, eds., Proceedings of the 5th International Conference and Symposium on Logic Programming, pp. 1070–1080. MIT Press. 122, 131, 136, 138, 140

E. Giunchiglia, Y. Lierler, and M. Maratea. 2006. Answer set programming based on propositional satisfiability. Journal of Automated Reasoning, 36: 345–377. DOI: 10.1007/s10817-006-9033-2. 158

A. Harrison, V. Lifschitz, D. Pearce, and A. Valverde. 2015. Infinitary equilibrium logic and strong equivalence. In F. Calimeri, G. Ianni, and M. Truszczynski, eds., Proceedings of International Conference on Logic Programming and Nonmonotonic Reasoning, LPNMR 2015, volume 9345 of LNAI. DOI: 10.1007/978-3-319-23264-5_33. 177

A. Heyting. 1930. Die formalen Regeln der intuitionistischen Logik. Sitzungsberichte der Preussischen Akademie von Wissenschaften. Physikalisch-mathematische Klasse, pp. 42–56. 163, 164

T. Jech. 2003. Set Theory. Springer Monographs in Mathematics. Springer, Berlin, New York. 126

R. Kowalski. 1974. Predicate logic as a programming language. In Proceedings of the Congress of the International Federation for Information Processing (IFIP-1974), pp. 569–574. North Holland, Amsterdam. 121

R. A. Kowalski and D. Kuehner. 1971. Linear resolution with selection function. Artif. Intell., 2(3/4): 227–260. DOI: 10.1016/0004-3702(71)90012-9. 121, 135

N. Leone, P. Rullo, and F. Scarcello. 1997. Disjunctive stable models: Unfounded sets, fixpoint semantics, and computation. Inf. Comput., 135(2): 69–112. DOI: 10.1006/inco.1997.2630. 160

V. Lifschitz. 2002. Answer set programming and plan generation. Artificial Intelligence, 138(1-2): 39–54. DOI: 10.1016/S0004-3702(02)00186-8. 149

V. Lifschitz. 2010. Thirteen definitions of a stable model. In A. Blass, N. Dershowitz, and W. Reisig, eds., Fields of Logic and Computation, Essays Dedicated to Yuri Gurevich on the Occasion of His 70th Birthday, volume 6300 of Lecture Notes in Computer Science, pp. 488–503. Springer. DOI: 10.1007/978-3-642-15025-8_24. 163

V. Lifschitz and A. A. Razborov. 2006. Why are there so many loop formulas? ACM Trans. Comput. Log., 7(2): 261–268. DOI: 10.1145/1131313.1131316. 162

V. Lifschitz and H. Turner. 1994. Splitting a logic program. In P. V. Hentenryck, ed., Proceedings of the 11th Internationall Conference on Logic Programming, ICLP 1994, pp. 23–37. MIT Press. 148

V. Lifschitz, D. Pearce, and A. Valverde. 2001. Strongly equivalent logic programs. ACM Transactions on Computational Logic, 2(4): 526–541. DOI: 10.1145/383779.383783. 164, 165

F. Lin and Y. Zhao. 2002. ASSAT: Computing answer sets of a logic program by SAT solvers. In Proceedings of the 18th National Conference on Artificial Intelligence (AAAI 2002), pp. 112–117. AAAI Press. DOI: 10.1016/j.artint.2004.04.004. 161, 162

J. W. Lloyd. 1984. Foundations of logic programming. Symbolic Computation. Artificial Intelligence. Springer, Berlin-New York. 126, 135

Z. Lonc and M. Truszczyński. 2001. On the problem of computing the well-founded semantics. Theory and Practice of Logic Programming, 5: 591–609. DOI: 10.1007/3-540-44957-4_45. 175

M. J. Maher. 1988. Equivalences of logic programs. In J. Minker, ed., Foundations of Deductive Databases and Logic Programming., pp. 627–658. Morgan Kaufmann, Los Altos, CA. DOI: 10.1007/3-540-16492-8_91. 166

V. Marek and M. Truszczyński. 1999. Stable models and an alternative logic programming paradigm. In K. Apt, W. Marek, M. Truszczyński, and D. Warren, eds., The Logic Programming Paradigm: a 25-Year Perspective, pp. 375–398. Springer, Berlin. DOI: 10.1007/978-3-642-60085-2_17. 122, 144

W. Marek and M. Truszczyński. 1991. Autoepistemic logic. Journal of the ACM, 38(3): 588–619. DOI: 10.1145/116825.116836. 144

R. Moore. 1985. Semantical considerations on nonmonotonic logic. Artificial Intelligence, 25(1): 75–94. DOI: 10.1016/0004-3702(85)90042-6. 122

I. Niemel¨a. 1999. Logic programming with stable model semantics as a constraint programming paradigm. Annals of Mathematics and Artificial Intelligence, 25(3-4): 241–273. DOI: 10.1023/A:1018930122475. 122, 144

I. Niemel¨a and J. Rintanen. 1994. On the impact of stratification on the complexity of nonmonotonic reasoning. Journal of Applied Non-Classical Logics, 4(2): 141–179. DOI: 10.1007/3-540-58107-3_16. 151

D. Pearce. 1997. A new logical characterisation of stable models and answer sets. In J. Dix, L. M. Pereira, and T. C. Przymusinski, eds., Non-Monotonic Extensions of Logic Programming, NMELP ’96, volume 1216 of Lecture Notes in Computer Science, pp. 57–70. Springer. DOI: 10.1007/BFb0023801. 163, 164

D. Pearce. 2006. Equilibrium logic. Ann. Math. Artif. Intell., 47(1-2): 3–41. DOI: 10.1007/s10472-006-9028-z. 163

D. Pearce and A. Valverde. 2004. Towards a first order equilibrium logic for nonmonotonic reasoning. In J. J. Alferes and J. A. Leite, eds., Proceedings of the 9th European Conference on Logics in Artificial Intelligence, JELIA 2004, volume 3229 of LNCS, pp. 147–160. Springer. DOI: 10.1007/978-3-540-30227-8_15. 163

D. Pearce and A. Valverde. 2008. Quantified equilibrium logic and foundations for answer set programs. In M. G. de la Banda and E. Pontelli, eds., Proceedings of the 24th International Conference on Logic Programming, ICLP 2008, volume 5366 of LNCS, pp. 546–560. Springer. DOI: 10.1007/978-3-540-89982-2_46. 163, 177

T. Przymusinski. 1988a. On the declarative semantics of deductive databases and logic programs. In J. Minker, ed., Foundations of Deductive Databases and Logic Programming, pp. 193–216. Morgan Kaufmann, Los Altos, CA. DOI: 10.1016/B978-0-934613-40-8.50009-9. 122, 137

T. C. Przymusinski. 1988b. Perfect model semantics. In R. A. Kowalski and K. A. Bowen, eds., Proceedings of the Fifth International Conference and Symposium on Logic Programming, pp. 1081–1096. MIT Press. 122, 137, 145

R. Reiter. 1980. A logic for default reasoning. Artificial Intelligence, 13(1-2): 81–132. DOI: 10.1016/0004-3702(80)90014-4. 122

J. Robinson. 1965. A machine-oriented logic based on resolution principle. Journal of the ACM, 12: 23–41. DOI: 10.1145/321250.321253. 121, 135

D. Saccà and C. Zaniolo. 1990. Stable models and non-determinism in logic programs with negation. In D. J. Rosenkrantz and Y. Sagiv, eds., Proceedings of the 9th ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, PODS 1990, pp. 205–217. ACM Press. DOI: 10.1145/298514.298572. 159

Y. Sagiv. 1988. Optimizing datalog programs. In J. Minker, ed., Foundations of Deductive Databases and Logic Programming, pp. 659–698. Morgan Kaufmann, Los Altos, CA. DOI: 10.1016/B978-0-934613-40-8.50021-X. 166

K. F. Sagonas, T. Swift, and D. S. Warren. 1994. XSB as an efficient deductive database engine. In R. T. Snodgrass and M. Winslett, eds., Proceedings of the 1994 ACM SIGMOD International Conference on Management of Data, pp. 442–453. ACM Press. DOI: 10.1145/191839.191927. 122, 175, 176

J. S. Schlipf. 1995. The expressive powers of the logic programming semantics. J. Comput. Syst. Sci., 51(1): 64–86. DOI: 10.1006/jcss.1995.1053. 176

R. M. Smullyan. 1961. Theory of Formal Systems, volume 47 of Annals of Mathematical Studies. Princeton University Press, Princeton, New Jersey. 135

A. Tarski. 1955. Lattice-theoretic fixpoint theorem and its applications. Pacific Journal of Mathematics, 5: 285–309. DOI: 10.2140/pjm.1955.5.285. 125

M. Truszczynski. 2012. Connecting first-order ASP and the logic FO(ID) through reducts. In E. Erdem, J. Lee, Y. Lierler, and D. Pearce, eds., Correct Reasoning - Essays on Logic-Based AI in Honour of Vladimir Lifschitz, volume 7265 of LNCS, pp. 543–559. Springer. DOI: 10.1007/978-3-642-30743-0_37. 177

J. Ullman. 1988. Principles of Database and Knowledge-Base Systems. Computer Science Press, Rockville, MD. 133

M. van Emden and R. Kowalski. 1976. The semantics of predicate logic as a programming language. Journal of the ACM, 23(4): 733–742. DOI: 10.1145/321978.321991. 128, 134

A. Van Gelder. 1993. The alternating fixpoint of logic programs with negation. Journal of Computer and System Sciences, 47(1): 185–221. DOI: 10.1016/0022-0000(93)90024-Q. 173

A. Van Gelder, K. A. Ross, and J. S. Schlipf. 1988. Unfounded sets and well-founded semantics for general logic programs. In C. Edmondson-Yurkanan and M. Yannakakis, eds., Proceedings of the Seventh ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, PODS 1988, pp. 221–230. ACM Press. DOI: 10.1145/308386.308444. 122, 138

A. Van Gelder, K. Ross, and J. Schlipf. 1991. The well-founded semantics for general logic programs. Journal of the ACM, 38(3): 620–650. DOI: 10.1145/116825.116838. 122, 136, 138, 171, 173

S. Woltran. 2011. Equivalence between extended datalog programs - a brief survey. In O. de Moor, G. Gottlob, T. Furche, and A. J. Sellers, eds., Datalog Reloaded - First International Workshop, Datalog 2010, volume 6702 of Lecture Notes in Computer Science, pp. 106–119. Springer. DOI: 10.1007/978-3-642-24206-9_7. 166

1. As usual, si(t) stands for . In particular, s⁰(t) stands for t.

2. We point out that the intuition no longer applies if the comparison involves pairs (I, J), where I ⊈ J, as such pairs do not approximate any interpretation. Nevertheless, we use the term “precision ordering” whenever any two pairs of interpretations are compared.

3. Rules such as tc(X, X) do not appear in programs arising in practice. The reason is precisely the ambiguity concerning legal substitutions for X. Typically, instead of the rule tc(X, X) we would have two rules tc(X, X) ← r(X, Y) and tc(X, X) ← r(Y, X). We could now produce arbitrary instantiations of these rules. However, the only “usable” instantiations would be those where X and Y are replaced with values x and y such that r(x, y) or r(y, x) might possibly be true. Such values x and y must come from the Herbrand universe of the program. In this way, we explicitly enforce the principle that the only allowed substitutions are those by elements of the Herbrand universe, rather than adopt it as a convention.

4. The discussion we presented above amounts to what we described earlier as the constructive proof of the Knaster-Tarski theorem for the one-step provability operator TP, where P is a Horn program. The sequence (where we now write for ) is the transfinite sequence we talked about then. We observe in passing that the proof remains almost the same for arbitrary monotone operators on complete lattices. The key difference is that we need to use a transfinite induction. In general, the least fixpoint of a monotone operator on a complete lattice cannot be reached in ω steps.

5. Even though we only defined splitting into two strata, extensions to the case of finite splittings and splittings into an arbitrary ordinal type are straightforward.

6. Those readers that are not comfortable with infinitary propositional logic may simply restrict the scope of the discussion to programs that are finite.

7. Here ⊤ is the standard symbol from the language of propositional logic that is always interpreted as true.

8. Programs computing stable models are commonly called answer-set solvers. It is because they typically handle programs in an extended language (allowing, among other things, disjunctions in the heads of rules, two types of negation: constraint atoms and aggregates), in which the term answer set is used instead of stable model.

9. http://www.cs.utexas.edu/users/tag/cmodels.html

10. The result by Saccà and Zaniolo was generalized by Leone et al. [1997] to the so-called disjunctive logic programs, that is, programs with disjunctions of atoms as rule heads). Ferraris et al. [2006] also considered the disjunctive programs in their study.

11. We write Mod(F) for the set of models of a formula F.

12. Indeed, we have and ΓP(∅) = LM(P∅). In general, (the latter is the limit of iterating over ∅). Whenever the two sets are different, .

13. The Potsdam group: http://potassco.sourceforge.net.

14. The Leuven group: http://dtai.cs.kuleuven.be/software/idp.

15. The University of Calabria group: http://www.dlvsystem.com.

16. http://xsb.sourceforge.net.

17. http://www.semafora-systems.com/en/products/ontobroker/.

18. http://flora.sourceforge.net.

19. http://www.dcc.fc.up.pt/~vsc/Yap/.

20. http://ciao-lang.org.

3

A Survey of Probabilistic Logic Programming

Fabrizio Riguzzi, Theresa Swift

The combination of logic programming and probability has proven useful for modeling domains with complex and uncertain relationships among elements. Many probabilistic logic programming (PLP) semantics have been proposed; among these, the distribution semantics has recently gained increased attention and has been adopted by many languages such as the Independent Choice Logic, PRISM, Logic Programs with Annotated Disjunctions, ProbLog, and P-log.

This chapter reviews the distribution semantics, beginning with the simplest case with stratified Datalog programs, and showing how the definition is extended to programs that include function symbols and non-stratified negation. The languages that adopt the distribution semantics are also discussed and compared both to one another and to Bayesian networks. We then survey existing approaches for inference in PLP languages that follow the distribution semantics. We concentrate on the PRISM, ProbLog, and PITA systems. The PRISM system was one of the first and can be applied when certain restrictions on the program hold. ProbLog introduced the use of Binary Decision Diagrams that provide a computational basis for removing these restrictions and so performing inference over more general classes of logic programs. PITA speeds up inference by using tabling and answer subsumption. It supports general probabilistic programs, but can easily be optimized for simpler settings and even possibilistic uncertain reasoning. The chapter also discusses the computational complexity of the various approaches together with techniques for limiting it by resorting to approximation.

3.1    Introduction

If inference is a central aspect of mathematical logic, then uncertain inference (a term coined by Henry Kyburg) is central to much of computational logic and to logic programming in particular. The term uncertain inference captures nonmonotonic reasoning, fuzzy, and possibilistic logic, as well as combinations of logic and probability. Intermixing probabilistic with logical inference is of particular interest for artificial intelligence tasks such as modeling agent behavior, diagnosing complex systems, assessing risk, and conducting structure learning. It is also useful for exploiting learned knowledge that is itself probabilistic, such as that used in medicine, bioinformatics, natural language parsing, marketing, and much else. These aspects have led to a huge amount of research into probabilistic formalisms such as Bayesian networks, Markov networks, and statistical learning techniques.

These trends have been reflected within the field of logic programming by various approaches to PLP. These approaches include the languages and frameworks Probabilistic Logic Programs [Dantsin 1991], Probabilistic Horn Abduction [Poole 1993b], PRISM[Sato 1995], Independent Choice Logic [Poole 1997], pD[Fuhr 2000], Bayesian Logic Programs [Kersting and Raedt 2001], CLP(BN) [Costa et al. 2003], Logic Programs with Annotated Disjunctions [Vennekens et al. 2004], P-log [Baral et al. 2009], ProbLog [De Raedt et al. 2007], and CP-logic [Vennekens et al. 2009]. While such a profusion of approaches indicates a ferment of interest in PLP, the question arises that if there are so many different languages, is one of them the right one to use? And why should PLP be used at all as opposed to Bayesian networks or other more popular approaches?

Fortunately, most of these approaches have similarities that can be brought into focus using various forms of the distribution semantics [Sato 1995].¹ Under the distribution semantics, a logic program defines a probability distribution over a set, each element of which is a normal logic program (termed a world). When there are a finite number of such worlds, as is the case with Datalog programs, the probability of an atom A is directly based on the proportion of the worlds whose model contains A as true. It can immediately be seen that distribution semantics are types of frequency semantics (cf. e.g., Halpern [2003]). By replacing worlds with sets of worlds, the same idea can be used to construct probabilities for atoms in programs that have function symbols and so may have an infinite number of worlds. Given these similarities, various forms of the distribution semantics differ on how a model is associated with a world: a model may be a (minimal) stratified model, a stable model, or even a well-founded model. Finally, the semantics of Bayesian networks can be shown to be equivalent to a restricted class of probabilistic logic program under the distribution semantics, indicating that approaches to PLP are at least as powerful as Bayesian networks.

For these reasons, this chapter uses the distribution semantics as an organizing principle to present an introduction to PLP. Our focus on the distribution semantics and on the problem of inference distinguishes this survey from [De Raedt and Kimmig 2015], a useful overview that focuses more on the actual programming in PLP. Accordingly, Section 3.2 starts with examples of some PLP languages. Section 3.3 then formally presents the distribution semantics in stages. The simplest case—that of Datalog programs with a single stratified model—is presented first in Section 3.3.1; using this basis the languages of Section 3.2 are shown to be expressively equivalent for stratified Datalog. Next, Section 3.3.3 extends the distribution semantics for programs with function symbols, by associating each explanation of a query (a set of probabilistic facts needed to prove the query) with a set of worlds, and constructing probability distributions on these sets. As a final extension, the assumption of a single stratified model for each world is lifted (Section 3.3.4).

Section 3.4 discusses semantics for probabilistic logics that are alternative to the distribution semantics. Section 3.5 then discusses PLP languages that are closely related to Bayesian networks and shows how Bayesian networks are equivalent to special cases of PLPs.

The distribution semantics is essentially model-theoretic; Section 3.6 discusses how inferences can be made from probabilistic logic programs. First, the relevant complexity results are recalled in Section 3.6.1: given that probabilistic logic programs are as expressive as Bayesian networks, query answering in probabilistic logic programs is easily seen to be NP-hard, and in fact is #P-complete. Current exact inferencing techniques for general probabistic logic programs, such as the use of Binary Decision Diagrams as pioneered in the ProbLog system [Kimmig et al. 2011], are discussed in Section 3.6.2. Section 3.6.3 discusses special cases of probabilistic logic programs for which inferencing is tractable and that have been exploited especially by the PRISM system [Sato et al. 2010]. Section 3.7 concludes the chapter with a final discussion.

3.1.1    Background and Assumptions

This survey can be read either by those with familiarity with logic programming who want to learn about its probabilistic extensions, or by those with a background in probabilistic programming systems who want to learn how probabilistic reasoning can be modeled and implemented in logic programming. In terms of logic programming, we assume a basic familiarity with the syntax and terminology of Prolog/ASP, along with the general notion that programs may have different types of models depending on how negation is used. For instance, there are two main semantics for negation that are implemented in current logic programming systems: stable models and well-founded models; see Truszczynski [2018] for a gentle introduction. These two semantics coincide for programs that either do not use negation (definite programs), or where negation is well behaved (stratified programs) [Truszczynski 2018]. Technical details about these models, such as how they are constructed via a fixed point, are not required. In terms of probability theory, we usually assume only a basic understanding of discrete distributions; definitions of other concepts are recalled when needed.

3.2    Languages with the Distribution Semantics

The languages following distribution semantics largely differ in how they encode choices for clauses, and how the probabilities for these choices are stated. In all languages, however, choices are independent from each other. As will be shown in Section 3.3.2, as long as models for the various types of programs are associated to worlds in the same manner they all have the same expressive power. This fact shows that the differences in the languages are syntactic, and also justifies speaking of the distribution semantics.

3.2.1    Probabilistic Horn Abduction

In Probabilistic Horn Abduction (PHA) [Poole 1993b] and Independent Choice Logic (ICL) [Poole 1997], alternatives are expressed by facts, called disjoint-statements, having the form

where each Ai is a logical atom and each pi a number in [0, 1] such that . Such a statement can be interpreted in terms of its ground instantiations: for each substitution θ grounding the atoms of the statement the Aiθs are random alternatives and Aiθ is true with probability pi. Each world is obtained by selecting one atom from each grounding of each disjoint-statement in the program. In practice, each ground instantiation of a disjoint-statement corresponds to a random variable with as many values as the alternatives in the statement. The variables corresponding to different instantiations of the same disjoint-statement are independent and identically distributed (iid).

Example 3.1 The following PHA/ICL program encodes the fact that a person sneezes if he has the flu and this is the active cause of sneezing, or if he has hay fever and hay fever is the active cause for sneezing:

Here, and for the other languages based on the distribution semantics, the atom null does not appear in the body of any clause and is used to represent an alternative in which no atom is selected.

3.2.2    PRISM

The language PRISM [Sato and Kameya 1997] is similar to PHA/ICL but introduces random facts via the predicate msw/3 (multi-switch):

The first argument of this predicate is a random switch name, a term representing a set of discrete random variables; the second argument is an integer, the trial id; and the third argument represents a value for that variable. The set of possible values for a switch is defined by a fact of the form

where SwitchName is again a term representing a switch and each vi is a term. Each ground pair (SwitchName, TrialId) represents a distinct random variable and the set of random variables associated with the same switch are iid.

The probability distribution over the values of the random variables associated to SwitchName is defined by a directive of the form

where pi is the probability that variable SwitchName takes value vi. Each world is obtained by selecting one value for each trial id of each random switch.

Example 3.2 The modeling of coin tosses shows differences in how the various PLP languages represent iid random variables. Suppose that coin c₁ is known not to be fair, but that all tosses of c₁ have the same probabilities of outcomes; in other words, each toss of c₁ is taken from a family of iid random variables. This can be represented in PRISM as

Different tosses of c₁ can then be identified using the trial id argument of msw/3.

In PHA/ICL and many other PLP languages, each ground instantiation of a disjoint/1 statement represents a distinct random variable so that iid random variables need to be represented through the statement’s instantiation patterns, e.g.,

In practice, the PRISM systems accepts an msw/2 predicate whose atoms do not contain the trial id and for which each occurrence in a program is considered as being associated to a different new variable.

Example 3.3 Example 3.1 can be encoded in PRISM as:

3.2.3    Logic Programs with Annotated Disjunctions

In Logic Programs with Annotated Disjunctions (LPADs) [Vennekens et al. 2004], the alternatives are expressed by means of annotated disjunctive heads of clauses. An annotated disjunctive clause has the form

where are logical atoms, are logical literals, and are real numbers in the interval [0, 1] such that . Each world is obtained by selecting one atom from the head of each grounding of each annotated disjunctive clause.²

Example 3.4 Example 3.1 can be expressed in LPADs as:

3.2.4    ProbLog

The design of ProbLog [De Raedt et al. 2007] was motivated by the desire to make as simple a probabilistic extension of Prolog as possible. In ProbLog, alternatives are expressed by probabilistic facts of the form

where pi ∈ [0, 1] and Ai is an atom, meaning that each ground instantiation Aiθ of Ai is true with probability pi and false with probability 1 − pi. Each world is obtained by selecting or rejecting each grounding of all probabilistic facts.

Example 3.5 Example 3.1 can be expressed in ProbLog as:

As for ICL, in LPADs and ProbLog each grounding of a probabilistic clause is associated to a random variable with as many values as head disjuncts for LPADs and with two values for ProbLog. The random variables corresponding to different instantiations of a probabilistic clause are iid.

3.3    Defining the Distribution Semantics

In presenting the distribution semantics, we use the term probabilistic construct to refer to disjoint-statements, multi-switches, annotated disjunctive clauses, and probabilistic facts, in order to discuss their common properties.

The distribution semantics applies to unrestricted normal logic programs. Nonetheless, for the purposes of explanation, we begin in Section 3.3.1 by making two simplifications.

Datalog Programs. if a program has no function symbols, the Herbrand universe is finite and so is the set of groundings of each probabilistic construct.

Stratified Programs. these programs have either a total well-founded model [Van Gelder et al. 1991] or equivalently a single stable model [Gelfond and Lifschitz 1988].³

With the distribution semantics thus defined, Section 3.3.2 discusses the relationships among the languages presented in Section 3.2. Afterward, the restriction to Datalog programs is lifted in Section 3.3.3, while the restriction of stratification is lifted in Section 3.3.4. We note that throughout this section, all probabilities distributions are discrete; however, continuous probability distributions have also been used with the distribution semantics [Gutmann et al. 2011a, Islam et al. 2012].

3.3.1    The Distribution Semantics for Stratified Datalog Programs

An atomic choice is the selection of the i-th atom for grounding Cθ of a probabilistic construct C. It is denoted with the triple (C, θ, i) where C is a clause, θ is a grounding substitution, and i is the index of the alternative atom chosen. In Example 3.1, (C₁, {X/bob}, 1) is an atomic choice relative to disjoint-statement

denoting the selection of atom flu sneezing(bob). Atomic choices for other languages are made similarly: for instance, an atomic choice for a ProbLog fact p :: foo(X) and a substitution θ = {X/a} can be obtained by interpreting the fact as C = foo(X) : p ∨ null : 1 − p, so (C, θ, 1) selects atom Aθ while (C, θ, 2) selects atom null.

A set of atomic choices is consistent if it does not contain two atomic choices (C, θ, i) and (C, θ, j) with i ≠ j (only one alternative is selected for a ground probabilistic construct).

A composite choice κ is a consistent set of atomic choices, i.e., if (C, θ, i) ∈ κ and (C, θ, j) ∈ κ then i = j. In Example 3.1, the set of atomic choices κ = {(C₁, {X/bob}, 1), (C₁, {X/bob}, 2)} is not consistent. The probability of composite choice κ is

where pi is the probability of the i-th alternative for probabilistic construct C.

A selection σ is a total composite choice, i.e., it contains one atomic choice for every grounding of each probabilistic construct. A selection in Example 3.1 is

A world wσ is a normal logic program that is identified by a selection σ. The world wσ is formed by replacing probabilistic constructs from the program with the non probabilistic constructs corresponding to each atomic choice of σ. In other words, for each atomic choice (C, θ, i), a ground clause or fact is obtained from Cθ by selecting the i-th alternative from the construct. For instance, given the previous selection σ₁, the atoms flu_sneezing(bob) and hay_fever_sneezing(bob) would be added to the first four clauses of Example 3.1 to make wσ₁. Note that a world is a normal logic program, which may include rules and facts; see Examples 3.6 and 3.7 below. For the LPAD of Example 3.4, the selection σ₁ = {(C₁, {X/bob}, 1), (C₂, {X/bob}, 1)} yields the clauses

that are included in wσ₁.

The probability of a world wσ is

Since in this section we are assuming Datalog programs, the set of groundings of each probabilistic construct is finite, and so is the set of worlds WT. Accordingly, for a probabilistic logic program T, WT = {w₁, …, wm}. Moreover, P(w) is a distribution over worlds: .

Let Q be a query in the form of a ground atom. We define the conditional probability of Q given a world w as: P(Q|w) = 1 if Q is true in the model of w and 0 otherwise. Since in this section we consider only stratified negation (sound programs), w has only one two-valued model and Q can be only true or false in it. The probability of Q can thus be computed by summing out the worlds from the joint distribution of the query and the worlds:

Example 3.6 The PHA/ICL program of Example 3.1 has four worlds {w₁, w₂, w₃, w₄}, each containing the certain (non-probabilistic) clauses:

The facts from disjoint-statements are distributed among the worlds as:

The query sneezing(bob) is true in three worlds and its probability is

Example 3.7 The LPAD of Example 3.4 has four worlds {w₁, w₂, w₃, w₄}:

The query sneezing(bob) is true in three worlds and its probability is

The probability of sneezing(bob) is calculated in a similar manner for PRISM and ProbLog.

Example 3.8 PHA/ICL, PRISM, and LPADs can have probabilistic statements with more than two alternatives. For example, the LPAD

encodes the fact that flu and hay fever can cause strong sneezing, moderate sneezing, or no sneezing. The clauses contain an extra atom null in the head that receives the missing probability mass and that is left implicit for brevity.

3.3.2    Equivalence of Expressive Power

To show that all these languages have the same expressive power for stratified Datalog programs, we discuss transformations among probabilistic constructs from the various languages. The mapping between PHA/ICL and PRISM translates each PHA/ICL disjoint statement into a multi-switch declaration and vice versa in the obvious way. The mapping from PHA/ICL and PRISM to LPADs translates each disjoint statement/multi-switch declaration into a disjunctive LPAD fact.

The translation from an LPAD into PHA/ICL (first shown in [Vennekens and Verbaeten 2003]) rewrites each clause Ci with v variables

into PHA/ICL by adding n new predicates {choicei,1/v, …, choice i,n/v} and a disjoint statement:

For instance, clause C₁ of the LPAD of Example 3.8 is translated to

where the clause null :− flu(X), choice1,3. is omitted since null does not appear in the body of any clause.

Finally, as shown in De Raedt et al. [2008], to convert LPADs to ProbLog, each clause Ci with v variables

is translated into ProbLog by adding n − 1 probabilistic facts for predicates {fi,1/v, …, fi,n/v}:

where ,…. In general, . Note that while the translation into ProbLog introduces negation, the introduced negation only involves probabilistic facts, and so the transformed program will have a two-valued model whenever the original program does.

For instance, clause C₁ of the LPAD of Example 3.8 is translated to

3.3.2.1    Additional Examples

Example 3.9 The following program encodes the Mendelian rules of inheritance of the color of pea plants [Blockeel 2004]. The color of a pea plant is determined by a gene that exists in two forms (alleles); purple, p, and white, w. Each plant has two alleles for the color gene that reside on a couple of chromosomes. cg(X,N,A) indicates that plant X has allele A on chromosome N. The facts of the program express that c is the offspring of f and m and that the alleles of m are ww and of f are pw. The disjunctive rules encode the fact that an offspring inherits the allele on chromosome 1 from the mother and the allele on chromosome 2 from the father. In particular, each allele of the parent has a probability of 50% of being transmitted. The definite clauses for color express the fact that the color of a plant is purple if at least one of the alleles is p, i.e., that the p allele is dominant.

Example 3.10 An interesting application of PLP under the distribution semantics is the computation of the probability of a path between two nodes in a graph in which the presence of each edge is probabilistic:

This program, coded in ProbLog, was used in De Raedt et al. [2007] for computing the probability that two biological concepts are related in the BIOMINE network [Sevon et al. 2006].

3.3.3    Distribution Semantics for Stratified Programs with Function Symbols

When a program contains functions symbols, there is the possibility that its grounding may be infinite. If so, there may be an uncountably infinite number of worlds, or equivalently, the number of atomic choices in a selection that defines a world may be infinite. In this case, the probability of each individual world is zero since it is the product of infinite numbers all smaller than one. So the semantics as defined in Section 3.3 is not well defined. The distribution semantics with function symbols has been proposed for PRISM [Sato 1995] and ICL [Poole 1997] but is easily applicable also to the other languages discussed in Section 3.2. Before delving into the semantics, we first present a motivating example.

Example 3.11 A Hidden Markov Model (HMM) is a graphical model that represents a timedependent process with a state and an output symbol for every time point. The state at time t depends only on the state at the previous time point t − 1 while the output symbol at time t depends only on the state at the same time t. Let us suppose that the initial time is 0 and the final time is T. HMMs, which are used in speech recognition and many other applications, are usually represented as in Figure 3.1.

There are various specialized algorithm for computing the probability of an output, the state sequence that most likely gave a certain output and the values of the parameters. However the HMM of Figure 3.1 can also be easily encoded as a probabilistic logic program (in this case an LPAD):

Figure 3.1    Hidden Markov Model.

This program models an HMM with three (hidden) states, q1, q2, and end, of which the last is an end state. The output symbols are a, c, g, and t. This HMM can for example model DNA sequences, where the output symbols are the amino-acids. The disjunctive clauses for next_state/3 define the transition probabilities, while the disjunctive clauses for emission/3 define the output probabilities. hmm(S, O) is true when O is the output sequence for state sequence S. hmm(Q, S0, S, O) is true when Q is the current state (time t), S0 is the list of previous states (up to time t − 1), S is the final list of states (for time points in [0, T]), and O is the list of output symbols for the time interval [t, T]. next state(Q, Q1, S) is true when Q1 is the next state from current state Q and list of previous states S. emission(Q, L, S) is true when L is the output symbol from current state Q and list of previous states S.

Note that the clauses for next state/3 and emission/3 have a variable argument holding the list of previous states. This is needed in order to have a different random variable for the next state and the output symbol for each time point. In fact, without that argument, in each world a single next state and output symbol would be always selected for each time point.

Note that the above program uses a function symbol (the list constructor) for representing the sequence of visited states. While finite HMMs can be represented by Bayesian networks, if a probabilistic logic program with functions has an infinite grounding or if it has cycles, then it cannot have a direct transformation into a Bayesian network. This theme will be discussed further in Section 3.5.3.

We now present the definition of the distribution semantics for programs with function symbols following [Poole 1997]. We preferred to follow [Poole 1997] because we think it is more constructive than [Sato 1995].

3.3.3.1    Algebras and Probability Measures

The semantics for a probabilistic logic program T with function symbols is given by defining a probability measure μ over the set of worlds WT. Informally, μ assigns a probability to subsets of WT, rather than to every element of WT.⁴ The approach dates back to Kolmogorov [1950] who defined a probability measure μ as a realvalued function whose domain is a σ-algebra Ω of subsets of a set W called the sample space. Together 〈W, Ω, μ〉 is called a probability space.⁵

Definition 3.1 The set Ω of subsets of W is an algebra of W iff

•  (a-1) W ∈ Ω;

•  (a-2) Ω is closed under complementation; and

•  (a-3) Ω is closed under finite union, i.e., v₁ ∈ Ω, v₂ ∈ Ω → (v₁ ∪ v₂) ∈ Ω.

The elements of Ω are called measurable sets. Importantly, for defining the distribution semantics for programs with function symbols, not every subset of W needs be present in Ω.

Definition 3.2 Given a sample space W and an algebra Ω of subsets of W, a (finitely additive) probability measure is a function μ : Ω → ℝ that satisfies the following axioms:

•  (μ-1) μ(v) ≥ 0 for all v ∈ Ω;

•  (μ-2) μ(W) = 1; and

•  (μ-3) μ is finitely additive, i.e., if O = {v₁, v₂, …} ⊆ Ω is a finite collection of pairwise disjoint sets, then μ(∪ν∈O) = Σi μ(νi).

3.3.3.2    Defining a Probability Measure for Programs with the Distribution Semantics

Toward defining a suitable algebra given a probabilistic logic program T, define the set of worlds νκ compatible with a finite composite choice κ as νκ = {wκ′ ∈ WT |κ ⊆ κ′} where κ′ is also a finite composite choice. Thus, a composite choice identifies a set of worlds. For programs without function symbols P(κ) = Σw∈νκ P(w).

Example 3.12 For Example 3.1, consider κ = {(C₁, {X/bob}, 1)}. The set of worlds compatible with this composite choice is

plus the non-probabilistic rules of Example 3.1. The probability of κ is thus P(κ) = 0.7 = P(w₁) + P(w₂).

Given a set of composite choices K, the set of worlds νK compatible with K is . Two composite choices κ₁ and κ₂ are incompatible if their union is not consistent. For example, the composite choices

and

are incompatible. A set K of composite choices is pairwise incompatible if for all κ₁ ∈ K, κ₂ ∈ K, κ₁ ≠ κ₂ implies that κ₁ and κ₂ are incompatible.

Note that in general, for programs without function symbols,

as can be seen from the following example.

Example 3.13 The set of composite choices for Example 3.1

with κ₁ = {(C₁, {X/bob}, 1)} and κ₂ = {(C₂, {X/bob}, 1)} is such that P(κ₁) = 0.7 and P(κ₂) = 0.8 but Σw∈νK P(w) = 0.94.

If, on the other hand, K is pairwise incompatible then

For example, consider

with so the property holds with the probabilities of the worlds summing up to 0.94.

Regardless of whether a probabilistic logic program has a finite number of worlds or not, obtaining pairwise incompatible sets of composite choices is an important problem because one way to assign probabilities to a set K of composite choices is to construct an equivalent set that is pairwise incompatible. Two sets K₁ and K₂ of finite composite choices are equivalent if they correspond to the same set of worlds: .

Then the probability of a pairwise incompatible set K of composite choices is defined as

Given a set K of composite choices, an equivalent set that is pairwise incompatible can be constructed through the technique of splitting. More specifically, if Fθ is an instantiated formula and κ is a composite choice that does not contain an atomic choice (F, θ, i) for any o, the split of κ on Fθ is the set of composite choices

where n is the number of alternatives in F. It is easy to see that κ and Sκ, Fθ identify the same set of possible worlds, i.e., that . For example, the split of κ₁ = {(C₁, {X/bob}, 1)} on C₂{X/bob} is

The technique of splitting composite choices on formulas is used for the following result [Poole 2000].

Theorem 3.1 Existence of a pairwise incompatible set of composite choices [Poole 2000]. Given a finite set K of composite choices, there exists a finite set K′ of pairwise incompatible composite choices such that K and K′ are equivalent.

Algorithm 3.1 Splitting algorithm.

Proof Given a finite set of composite choices K, there are two possibilities to form a new set K′ of composite choices so that K and K′ are equivalent:

Removing dominated elements. if κ₁, κ₂ ∈ K and κ₁ ⊂ κ₂, let K′ = K \ {κ₂}.

Splitting elements. if κ₁, κ₂ ∈ K are compatible (and neither is a superset of the other), there is a (F, θ, i) ∈ κ₁ \ κ₂. We replace κ₂ by the split of κ₂ on Fθ. Let

In both cases, νK = νK′. If we repeat this two operations until neither is applicable, we obtain a splitting algorithm (see Algorithm 3.1) that terminates because K is a finite set of composite choices. The resulting set K′ is pairwise incompatible and is equivalent to the original set. For example, the splitting algorithm applied to K (3.1) can return K′ (3.2).

■

Theorem 3.2 Equivalence of the probability of two equivalent pairwise incompatible finite sets of finite composite choices [Poole 1993a]. If K₁ and K₂ are both pairwise incompatible finite sets of finite composite choices such that they are equivalent then P(K₁) = P(K₂).

Proof Consider the set D of all instantiated formulas Fθ that appear in an atomic choice in either K₁ or K₂. This set is finite. Each composite choice in K₁ and K₂ has atomic choices for a subset of D. For both K₁ and K₂, we repeatedly replace each composite choice κ of K₁ and K₂ with its split on an Fi θj from D that does not appear in κ. This procedure does not change the total probability as the probabilities of (Fi, θj, 1), …, (Fi, θj, n) sum to 1.

At the end of this procedure the two sets of composite choices will be identical. In fact, any difference can be extended into a possible world belonging to but not to or vice versa.

■

Example 3.14 Recall from Example 3.13 the set of composite choices with

and

Consider also the composite choices

and the set . Note that K′ and K″ are equivalent and are both pairwise incompatible. By Theorem 3.2 their probabilities are equivalent:

while

For a probabilistic logic program T, we can thus define a unique probability measure μ : ΩT → [0, 1] where ΩT is defined as the set of sets of worlds identified by finite sets of finite composite choices:

The corresponding measure μ is defined by μ(νK) = P(K′) where K′ is a pairwise incompatible set of composite choices equivalent to K.

Theorem 3.3 〈WT, ΩT, μ〉 is a finitely additive probability space.

Proof ΩT is an algebra over WT since WT = νK with K = {∅}. Moreover, the complement of νK where K is a finite set of finite composite choice is where is a certain finite set of finite composite choice. In fact, can be obtained with the function duals(K) of Poole [2000] that performs Reiter’s hitting set algorithm over K, generating an element κ of by picking an atomic choice (C, θ, k) from each element of K and inserting in κ an incompatible atomic choice, i.e., an atomic choice (C, θ, k′) with k ≠ k′. After this process is performed in all possible ways, inconsistent sets of atom choices are removed obtaining . Since the possible choices of the atomic choices and of their incompatible counterparts is finite, so is .

Finally, condition (a-3) holds since the union of with is equal to by definition.

μ is a probability measure because μ(ν{∅}) = 1, μ(νK) ≥ 0 for all K and if and is pairwise incompatible and equivalent to K₁ (K₂), then is pairwise incompatible because and

■

Given a query Q, a composite choice κ is an explanation for Q if

A set K of composite choices is covering wrt Q if every world in which Q is true belongs to νK.

Definition 3.3 For a probabilistic logic program T, the probability of a ground atom Q is given by

If Q has a finite set K of finite explanations such that K is covering then {w|w ∈ WT ∧ w ⊨ Q}= νK ∈ ΩT and we say that P(Q) is well defined for the distribution semantics. A program T is well defined if the probability of all ground atoms in the grounding of T is well defined.

Example 3.15 Consider the PHA/ICL program of Example 3.1. The two composite choices:

and

are such that K = {κ₁, κ₂} is a pairwise incompatible finite set of finite explanations that are covering for the query Q = sneezing(bob). Definition 3.3 therefore applies, and P(Q) = P(κ₁) + P(κ₂) = 0.7 + 0.3 · 0.8 = 0.94

3.3.3.3    Comparison with Sato and Kameya’s Definition

Sato and Kameya [2001] build a probability measure on the sample space WT from a collection of finite distributions. Let T′ = {C₁, C₂, …} be the grounding of T and let Xi be a random variable associated to Ci whose domain is {1, …, ji } where ji is the number of alternatives of Ci.

The finite distributions for n ≥ 1 must be such that

where ki ∈ {1, …, ji}. The last equation is called the compatibility condition. It can be proved [Chow and Teicher 2012] from the compatibility condition that there exists a probability space (WT, ΨT, η) where η is a probability measure on ΨT, the minimal σ-algebra containing open sets of WT such that for any n,

Sato and Kameya [2001] define as where pi is the annotation of alternative ki in clause Ci. This definition clearly satisfies the properties in (3.4).

It can be shown that this definition of the distribution semantics with function symbols coincides with the one given above following Poole [1997] in the case that each ground atom has a finite set of finite explanations that is covering.

In this case, in fact, X₁ = k₁, …, Xn = kn is equivalent to the set of composite choices K = {{(C₁, ∅, k₁), …, (Cn, ∅, kn)}} and μ(νK) is equal to p₁ … pn, which satisfies equation (3.5).

3.3.3.4    Programs for which the Distribution Semantics Is Well Defined

Inference procedures often rely on the computation of a covering set of explanations. In this sense, the notion of well-defined programs is important, as it ensures that the set of explanations is finite and so is each explanation. Therefore, an important open question is to understand when a program or query is well defined, and to identify cases where there are decidable algorithms to determine this. For instance, ground queries to the program of Example 3.11, which describe an HMM, are well defined as each such query has a finite set of finite explanations which is covering—even though there are an infinite number of such queries.

In PRISM, well-definedness of a program is explicitly required [Sato and Kameya 2001]. In PHA/ICL, the program (excluding disjoint-statements) is required to be acyclic [Apt and Bezem 1991]. The condition of modular acyclicity is proposed in Riguzzi [2009] to enlarge the set of programs. This condition was weakened in Riguzzi and Swift [2013] to the set of programs that are bounded term-size, a property whose definition is based on dynamic stratification. While the property of being bounded term-size is semi-decidable, such programs include a number of recent static classes for programs with finite models (cf. Alviano et al. [2010], Baselice and Bonatti [2010], Calimeri et al. [2011], Greco et al. [2013] for some recent work on decidability of stable models).

The works of Sato and Meyer [2012] and Gorlin et al. [2012] go beyond well-definedness by presenting inference algorithm that can deal with infinite explanations for restricted classes of programs.

3.3.4    The Distribution Semantics for Non-Stratified Programs

3.3.4.1    The Well-Founded Semantics

The distribution semantics can be extended in a straightforward manner to the well-founded semantics (WFS).⁶ In the following, wσ ⊨ L means that the ground literal L is true in the well-founded model of the program wσ.

For a literal Lj, let t(Lj) stand as shorthand for Lj = true. We extend the probability distribution on programs to ground literals by assuming P(t(Lj)|w) = 1 if Lj is true in w and 0 otherwise (i.e., if Lj is false or undefined in w). Thus, the probability of Lj being true in a program T without function symbols is

Example 3.16 The barber paradox, introduced by Bertrand Russell [Russell 1967], is expressed as:

The village barber shaves everyone in the village who does not shave himself.

The paradox was modeled as a logic program under WFS in Dung [1991]. Making things probabilistic, the paradox can be modeled as the LPAD:

where the facts that the barber and the doctor shave themselves are probabilistic.

There are four different worlds associated with this LPAD.

•  w₁: both C₁ and C₂ are selected. In this world shaves(barber,barber), shaves(barber,mayor), and shaves(doctor,doctor) are all true. The probability of w₁ is .

•  w₂: C₁ is selected but not C₂. In this world shaves(barber,barber), shaves(barber,mayor), and shaves(barber,doctor) are all true. The probability of w₂ is .

•  w₃: C₂ is selected but not C₁. In this world shaves(barber,mayor) and shaves(doctor,doctor) are true, while shaves(barber,barber) is undefined. The probability of w₃ is .

•  w₄: neither C₁ nor C₂ is selected. In this world shaves(barber,mayor) and shaves(barber,doctor) are true, while shaves(barber,barber) is undefined. The probability of w₄ is .

In each of the above worlds, each ground instantiation of shaves/2 that is not explicitly mentioned is false.

Given the probabilities of each world, the probability of each literal can be computed:

•  

▪  

•  

▪  

•  

▪  P(not shaves(barber, barber)) = 0

Note that P(A) = 1 − P(not A), except for the case where A is shaves(barber, barber).

From the perspective of modeling, the use of the well-founded semantics provides an approximation of the probability of an atom and of its negation, and thus may prove useful for domains in which a cautious under-approximation of probabilities is necessary. In addition, as discussed in Section 3.6.4, using the third truth value of the well-founded semantics offers a promising approach to semantically sound approximation of probabilistic inference.

3.3.4.2    The Stable Model Semantics

P-log [Baral et al. 2009] is a formalism for introducing probability in Answer Set Programming (ASP). P-log has a rich syntax that allows expression of a variety of stochastic and non-monotonic information. The semantics of a P-log program T is given in terms of its translation into an Answer Set program π(T) whose stable models are the possible worlds of T. The following simple program from Baral et al. [2009] illustrates certain aspects of P-log.

Example 3.17 Consider two gamblers, john and mike: john owns a die that is fair, while mike owns a die that isn’t. This situation can be represented by the P-log program below. The first portion of the program is a declaration of sorts, such as dice, score, and person along with attributes such as roll and owner. These declarations allow P-log syntax to extend ASP syntax to include (possibly non-ground) attribute terms such as roll(Die) along with atomic statements such as roll(Die) = 6. In addition to rules with this extended syntax, P-log has random selection rules to indicate that certain attributes may be considered random over a certain domain. A simple example of such a rule is random(roll(Die)), which indicates, since Die is not restricted, that roll is random attribute over the entire domain dice. P-log also contains probability atoms indicating the probabilities of atomic statements (e.g., pr(roll(Die) = Score | owner(Die) = john) = ) which indicates that if the owner of a given die, Die, is john, the probability of roll(Die) is .

In order to evaluate the above program, the declarations are used to translate the rules and random selections into a standard ASP program. Atomic statements are translated to ground atoms using the sorts of the attribute domains and ranges if necessary: for instance owner(d1) = john is translated to the atom owner(d1,john). In a similar manner, random selection rules are translated to ground disjunctions (in ASP, a disjunction in a fact or rule head is taken as an exclusive use of “or”). In the program above, the random selection random(roll(Die)) is translated into two disjunctive ground facts:

and

As shown in the example above, random selection rules correspond to probabilistic constructs, so that when a P-log program T is translated into an ASP program π(T) the stable models of π(T) will contain total composite choices and so will correspond to possible worlds. The probability for each stable model Mπ(T) is constructed using the probability atoms that are satisfied in Mπ(T). A probability is then assigned to each stable model; the probability of a query Q is given, as for other distribution semantics languages, by the sum of the probabilities of the possible worlds where Q is true.

Example 3.18 Example 3.16 continued. There are 36 stable models for π(T) of the previous example: one for each score for d1 and d2. The probability of each world containing roll(d2,6) is while the probability of each other world is

P-log differs from the languages mentioned in Section 3.2 because the possible worlds are generated not only because of stochastic choices but also because of disjunctions and non-stratified negations appearing in the logical part of a P-log program. As a consequence, the distribution obtained by multiplying all the probability factors of choices that are true in a stable model is not normalized. In order to get a probability distribution over possible worlds, the unnormalized probability of each stable model must be divided by the sum of the unnormalized probabilities of each possible world.

In most of the literature on P-log, function symbols are not handled by the semantics, although Gelfond and Rushton [2010] provides recent work toward this end. Furthermore, recent work that extends stable models to allow function symbols [Alviano et al. 2010, Baselice and Bonatti 2010, Calimeri et al. 2011, Greco et al. 2013] may also lead to finite well-definedness conditions for P-log programs containing function symbols.

3.4    Other Semantics for Probabilistic Logics

Here we briefly discuss a few examples of frameworks related to probabilistic logic programming that are outside of the distribution semantics. Our goal in this section is simply to give the flavor of other possible approaches; a complete accounting of such frameworks is beyond the scope of this chapter.

3.4.1    Stochastic Logic Programs

Stochastic Logic Programs (SLPs) are logic programs with parameterized clauses that define a distribution over refutations of goals [Muggleton 1996, Cussens 2001]. The distribution provides, by marginalization, a distribution over variable bindings for the query. SLPs are a generalization of stochastic grammars and hidden Markov models.

An SLP S is a definite logic program where some of the clauses are of the form p : C where p ∈ ℝ, p ≥ 0 and C is a definite clause. Let n(S) be the definite logic program obtained by removing the probability labels. A pure SLP is an SLP where all clauses have probability labels. A normalized SLP is one where probability labels for clauses whose heads share the same predicate symbol sum to one.

In pure SLPs each SLD derivation for a query Q is assigned a real label by multiplying the labels of each individual derivation step. The label of a derivation step where the selected atom unifies with the head of clause pi : Ci is pi. The probability of a successful derivation from Q is the label of the derivation divided by the sum of the labels of all the successful derivations. This clearly is a distribution over successful derivations from Q

The probability of an instantiation Qθ is the sum of the probabilities of the successful derivations that produce Qθ. It can be shown that the probabilities of all the atoms for a predicate q that succeed in n(S) sum to one, i.e., S defines a probability distribution over the success set of q in n(S).

In impure SLPs, the unparameterized clauses are seen as non-probabilistic domain knowledge acting as constraints. To this purpose, derivations are identified with the set of the parameterized clauses they use. In this way, derivations that differ only on the unparameterized clauses form an equivalence class.

Given their similarity with stochastic grammars and hidden Markov models, SLPs are particularly suited to represent this kind of models. They differ from the distribution semantics because they define a probability distribution over instantiations of the query, while the distribution semantics defines a distribution over the truth values of ground atoms.

3.4.2    Nilsson’s Probabilistic Logic

Nilsson’s probabilistic logic [Nilsson 1986] takes an approach different from the distribution semantics for combining logic and probability: while the first considers sets of distributions, the latter computes a single distribution over possible worlds. In Nilsson’s logic, a probabilistic interpretation Pr defines a probability distribution over the set of interpretations Int. The probability of a logical formula F according to Pr, denoted Pr(F), is the sum of all Pr(I) such that I ∈ Int and I ⊨ F. A probabilistic knowledge base W is a set of probabilistic formulas of the form F ≥ p. A probabilistic interpretation Pr satisfies F ≥ p iff Pr(F) ≥ p. Pr satisfies W, or Pr is a model of W, iff Pr satisfies all F ≥ p ∈ W. Pr(F) ≥ p is a tight logical consequence of W iff p is the infimum of Pr(F) in the set of all models Pr of W. Computing tight logical consequences from probabilistic knowledge bases can be done by solving a linear optimization problem.

Nilsson’s logic allows different consequences to be drawn from logical formulas than the distribution semantics. Consider a ProbLog program (cf. Section 3.2) composed of the facts 0.4 :: c(a). and 0.5 :: c(b).; and a probabilistic knowledge base composed of c(a) ≥ 0.4 and c(b) ≥ 0.5. For the distribution semantics P(c(a) ∨ c(b)) = 0.7, while with Nilsson’s logic the lowest p such that Pr(c(a) ∨ c(b)) ≥ p holds is 0.5. This difference is due to the fact that, while in Nilsson’s logic no assumption about the independence of the statements is made, in the distribution semantics the probabilistic axioms are considered as independent. While independencies can be encoded in Nilsson’s logic by carefully choosing the values of the parameters, reading off the independencies from the theories becomes more difficult.

The assumption of independence of probabilistic axioms does not restrict expressiveness as one can specify any joint probability distribution over the logical ground atoms, possibly introducing new atoms if needed. This claim is substantiated by the fact that Bayesian networks can be encoded in probabilistic logic programs under the distribution semantics, as discussed in Section 3.5.3.

3.4.3    Markov Logic Networks

A Markov Logic Network (MLN) is a first-order logical theory in which each sentence has a real-valued weight. An MLN is a template for generating Markov networks, graphical models where the edges among variables are undirected. Given sets of constants defining the domains of the logical variables, an MLN defines a Markov network that has a node for each ground atom and edges connecting the atoms appearing together in a grounding of a formula. MLNs follow the so-called Knowledge Base Model Construction approach for defining a probabilistic model [Wellman et al. 1992, Bacchus 1993] in which the probabilistic-logic theory is a template for generating an underlying probabilistic graphical model (Bayesian or Markov networks). The probability distribution encoded by an MLN is

where x is a joint assignment of truth value to all atoms in the Herbrand base, M is the model, fi is the i-th formula in M, wi is its weight, and ni(x) is the number of groundings of formula fi that are satisfied in x and Z is a normalization constant.

A probabilistic logic program T under the distribution semantics differs from an MLN because T has a semantics defined directly rather than through graphical models (although there are strong relationships to graphical models; see Section 3.5) and because restricting the logic of choice to be logic programming, rather than full first-order logic, permits to exploit the plethora of techniques developed in logic programming.

3.4.4    Evidential Probability

Evidential probability (cf. Kyburg and Teng [2001]) is an approach to reason about probabilistic information that may be approximate, incomplete or even contradictory. Evidential probability adds statistical statements of the form

where Target and Reference are formulas, and Lower and Upper are numbers between 0 and 1. Although the syntax is unusual, it may help to think of % as a quantifier and Vars as the set of variables open in the Target and Reference formulas. The statistical statment thus states that the proportion of instantiations of Vars for which Target is true, among those for which Reference is also true, is between Lower and Upper.

As an example, consider

which can be read as The percentage of X such that in_urn(u₁,X) is true, where is_blue(X) also true, is between 0.3 and 0.4. This illustrates and important special case that occurs when Vars is a singleton variable shared by Target and Reference. In this case, the statement can be read as one of probabilistic set membership of a given individual in a domain, and we restrict the rest of this discussion to this special case.

To see how this works in practice consider the problem of determining the likelihood of whether an individual o₁ is in a class C (when o₁ cannot be proved for certain to be in C). Each statistical statement S = %X(CT, CR, L, U) is collected for which o₁ is known to be an element of the target class CT of S and for which C is a superset of the reference class of CR (i.e., CR implies C). For instance, in the above example, the reference class indicates the uncertain property of whether a ball were blue, so for a given ball, target classes of applicable statistical statements indicate properties known about the ball, while reference classes of these statements consist of properties that imply blueness. Once the applicable statements have been identified, a series of rules is used to derive a single interval from these collected statements, and to weigh the evidence provided for different statements if their intervals are contradictory. (Two intervals contradict each other if neither is a subinterval of the other.) One such rule is the principle of specificity: a statement S₁ may override statement S₂ if the target class of S₁ is more specific to o₁ than that of S₂. (For instance, a statistical statement about an age cohort might override a statement about the general population.)

Evidential probability is thus not a probabilistic logic, but a meta-logic for defeasible reasoning about statistical statements once non-probabilistic aspects of a model have been derived. It is thus less powerful than probabilistic logics based on the distribution semantics, but is applicable to situations where such logics don’t apply, due to contradiction, incompleteness, or other factors.

3.4.5    Annotated Probabilistic Logic Programs

Another approach is that of Annotated Probabilistic Logic Programming (Annotated PLP) [Ng and Subrahmanian 1992], which allows program atoms to be annotated with intervals that can be interpreted probabilistically. An example rule in this approach,

a : [0.75, 0.85] ← b : [1, 1], c : [0.5, 0.75],

can be taken as stating that the probability of a is between 0.75 and 0.85 if b is certainly true and the probability of c is between 0.5 and 0.75. The probability interval of a conjunction or disjunction of atoms is defined using a combinator to construct the tightest bounds for the formula. For instance, if d is annotated with [ld, hd] and e with [le, he] the probability of a ∧ b is annotated with

[max(0, ld + le − 1), min(hd, he)].

Using these combinators, an inference operator and fixed point semantics is defined for positive Datalog programs. A model theory is obtained for such programs by considering the annotations as constraints on acceptable probabilistic worlds: an Annotated PLP thus describes a family of probabilistic worlds.

Annotated PLPs have the advantage that deduction is of low complexity, as the logic is truth-functional, i.e., the probability of a query can be computed directly using combinators. The corresponding disadvantages are that Annotated PLPs may be inconsistent if they are not carefully written, and that the use of the above combinators may quickly lead to assigning overly slack probability intervals to certain atoms. These aspects are partially addressed by Hybrid Annotated PLPs [Dekhtyar and Subrahmanian 2000], which allow different flavors of combinators based on, e.g., independence or mutual exclusivity of given atoms.

3.5    Probabilistic Logic Programs and Bayesian Networks

In this section, we first present two examples of probabilistic logic programs whose semantics is explicitly related to Bayesian Networks: Bayesian Logic Programs and Knowledge Base Model Construction. Making use of the formalism of Bayesian Logic Programs, we then discuss the relationship of Bayesian Networks to the distribution semantics (for background on Bayesian networks cf. Pearl [1988] or similar texts).

3.5.1    Bayesian Logic Programs

Bayesian Logic Programs (BLPs) [Kersting and Raedt 2001] use logic programming to compactly encode a large Bayesian network. In BLPs, each ground atom represents a random variable and the clauses define the dependencies between ground atoms. A clause of the form

A|A₁, …, Am

indicates that, for each of its groundings (A|A₁, …, Am)θ, Aθ has A₁θ, …, Amθ as parents. The domains and conditional probability tables (CPTs) for the ground atom/random variables are defined in a separate portion of the model. In the case where a ground atom Aθ appears in the head of more than one clause, a combining rule is used to obtain the overall CPT from those given by individual clauses.

For example, in the Mendelian genetics program of Example 3.9, the dependency that gives the value of the color gene on chromosome 1 of a plant as a function of the color genes of its mother can be expressed as

cg(X, 1)|mother(Y, X), cg(Y, 1), cg(Y, 2),

where the domain of atoms built on predicate cg/2 is {p,w} and the domain of mother(Y,X) is Boolean. A suitable CPT should then be defined that assigns equal probability to the alleles of the mother to be inherited by the plant.

3.5.2    Knowledge Base Model Construction

In Knowledge Base Model Construction (KBMC) [Wellman et al. 1992, Bacchus 1993], PLP is a template for building a complex Bayesian network. The semantics of the probabilistic logic program is then given by the semantics of the generated network. For example, in a CLP(BN) program [Costa et al. 2003], logical variables can be random. Their domain, parents and CPTs are defined by the program. Probabilistic dependencies are expressed by means of CLP constraints:

{ Var = Function with p(Values, Dist) }
{ Var = Function with p(Values, Dist, Parents) }

The first form indicates that the logical variable Var is random with domain Values and CPT Dist but without parents; the second form defines a random variable with parents. In both forms, Function is a term over logical variables that is used to parameterize the random variable: a different random variable is defined for each instantiation of the logical variables in the term. For example, the following snippet from a school domain:

defines the random variable Dif with values h, m, and l representing the difficulty of the course identified by CKey. There is a different random variable for every instantiation of CKey—i.e., for each course. In a similar manner, the intelligence Int of a student identified by SKey is given by

Using the above predicates, the following snippet predicts the grade received by a student when taking the exam of a course.

Here Grade indicates a random variable parameterized by the identifier Key of a registration of a student to a course. The code states that there is a different random variable Grade for each student’s registration in a course and each such random variable has possible values ’A’, ’B’, ’C’ and ’D’. The actual value of the random variable depends on the intelligence of the student and on the difficulty of the course, that are thus its parents. Together with facts for registration/3 such as

the code defines a Bayesian network with a Grade random variable for each registration. CLP(BN) is implemented as a library of YAP Prolog [Costa et al. 2012].

3.5.3    Conversion of PLP under the Distribution Semantics to Bayesian Networks

In Vennekens and Verbaeten [2003] the relationship between LPADs and BLPs is investigated in detail. The authors show that ground BLPs can be converted to ground LPADs and that ground acyclic LPADs can be converted to ground BLPs.⁷ A logic program is acyclic [Apt and Bezem 1991] if its atom dependency graph is acyclic. As a BLP directly encodes a Bayesian network, the results of Vennekens and Verbaeten [2003] allow us to draw a connection between LPADs and Bayesian networks.

Example 3.19 Figure 3.2 shows a simple Bayesian network for reasoning about the causes of a building alarm. This network can be encoded as the following LPAD:

In general, given a Bayesian network B = {P(Xi|Πi)|i = 1, …, n}, we obtain a ground LPAD, α(B), as follows. For each variable Xi and value v in the domain Di = {vi1,…, vim} of Xi we have one atom in the Herbrand base of α(B). For each row P(Xi|Xi1 = v₁, …, Xil = vl) of the CPT for Xi with probabilities p₁, …, pim for the values of Xi, we have an LPAD clause in α(B):

Figure 3.2    Bayesian network.

Theorem 3.4 Bayesian network B and LPAD α(B) define the same probability distribution.

Proof There is an immediate translation from a Bayesian network B to a ground BLP B′. Theorem 4 of Vennekens and Verbaeten [2003] states the equivalence of the semantics of a ground BLP B′ and a ground LPAD γ(B′) obtained from B′ with a translation γ. This translation is in close correspondence with α so the theorem is proved.

■

Extending Theorem 3.4, acyclic Datalog LPADs under the distribution semantics can be translated to Bayesian networks. To do so, first the grounding of the program must be generated. Consider an LPAD T and let ground(T) be its grounding. For each atom A in the Herbrand base HT of T, the network contains a binary variable A. For each clause Ci in ground(T)

H₁ : p₁ ∨ … ∨ Hn : pn :− B₁, … Bm, ¬C₁, …, ¬Cl

the network contains a variable CHi with H₁, …, Hn and null as values. CHi has

B₁, …, Bm, C₁, …, Cl

as parents. The CPT of CHi is

Basically, if the body assumes a false value, then CHi assumes value null with certainty, otherwise the probability is distributed over atoms in the head of Ci according to the annotations.

Each variable A corresponding to atom A has as parents all the variables CHi of clauses Ci that have A in the head. The CPT for A is:

This table encodes a deterministic function: A assumes value 1 with certainty if at least one parent assumes value A, otherwise it assumes value 0 with certainty.

Let us call λ(T) the Bayesian network obtained with the above translation from an LPAD T. Then the following theorem holds.

Theorem 3.5 Given an acyclic Datalog LPAD T, the Bayesian network λ(T) defines the same probability distribution over the atoms of HT.

Proof The proof uses Theorem 5 of Vennekens and Verbaeten [2003] that states the equivalence of the semantics of a ground LPAD T and a ground BLP β(T) obtained from T with a translation β in close correspondence with λ. Since there is an immediate translation from a ground BLP to a Bayesian network, the theorem is proved.

■

Together, Theorems 3.4 and 3.5 show the equivalence of the distribution semantics with that of Bayesian networks for the special case of acyclic probabilistic Datalog programs. As discussed in previous sections, however, the distribution semantics is defined for larger classes of programs, indicating its generality.

3.6    Inferencing in Probabilistic Logic Programs

So far, we have focused mainly on definitions and expressiveness of the distribution semantics, and this presentation has had a somewhat model-theoretic flavor. This section focuses primarily on the main inference task for probabilistic logic programs: that of query evaluation. In its simplest form, query evaluation means determining the probability of a ground query Q when no evidence is given.

Section 3.6.1 discusses the computational complexity of query evaluation which, perhaps not surprisingly, is high. Current techniques for computing the distribution semantics for stratified programs are discussed in Section 3.6.2. Because of the high computational complexity, these general techniques are not always scalable. Section 3.6.3 discusses a restriction of the distribution semantics, pioneered by the PRISM system, for which query evaluation is tractable. Another approach is to only approximate the point intervals of the distribution semantics, as discussed in Section 3.6.4. Section 3.6.4 also briefly discusses other inferencing tasks, such as computing the Viterbi probability for a query.

3.6.1    The Complexity of Query Evaluation

To understand the complexity of query evaluation for PLPs, let Q be a ground query to a probabilistic logic program T. A simple approach might be to somehow save the probabilistic choices made for each proof of Q. For instance, each time a probabilistic atom was encountered as a subgoal, the corresponding atomic choice (C, θ, i) would be added to a data structure. As a result each proof of Q would be associated with an explanation Ej, and when all n proofs of Q had been exhausted the set of explanations would cover Q. While this approach was sketched for top-down evaluations, a similar approach could be constructed in a bottom-up manner.

If all Ej were known to be mutually exclusive, the probability of Q (= P(E)) could be computed simply by computing the probability of each explanation and summing them up; but this is not generally the case. Usually, explanations are not pairwise exclusive, requiring a technique such as the principle of inclusion-exclusion to be used (cf. e.g., Rauzy et al. [2003]):

Unfortunately, use of the inclusion-exclusion algorithm is exponential in n. Is there a better way? E can also be viewed as a propositional formula, formula(E), in disjunctive normal form. The difficulty of determining the number of solutions to a propositional formula such as formula(E) is the canonical #P-complete problem, and computing the probability of E is at least as difficult as computing the number of solutions of formula(E). It can easily be shown that computing the probability of E also is in #P so that it is a #P-complete problem. For practical purposes, computing the probability of E can be thought of as equivalent to a FPspace complete problem (where an FPspace problem outputs a value, unlike a Pspace problem).⁸

3.6.2    Exact Query Evaluation for Unrestricted Programs

At this point, there have been two classes of approaches to exact query evaluation for programs in which the use of the distribution semantics is unrestricted (although the programs themselves may be restricted): transformational and direct approaches. As mentioned above, we focus on probabilistic queries without evidence.

3.6.2.1    Transformational Approaches

Given the relationship between an acyclic Datalog probabilistic logic program T and a Bayesian Network as stated in Theorem 3.5 of Section 3.5, one approach is to transform T into a Bayesian network, use Bayesian Network inference algorithms to evaluate the query, and then translate back the results. Given the large amount of work on efficiently evaluating Bayesian networks (cf. [Koller and Friedman 2009]), such an approach could lead to efficient evaluations.

This approach was used in CVE inferencing [Meert et al. 2008, Meert et al. 2009], which evaluated CP-logic [Vennekens et al. 2009], a formalism closely related to LPADs. Some of the factors of the Bayesian network that results from the translation contain redundant information since they have many identical columns. To reduce the size of the generated network, this situation, called contextual independence, can be exploited during inference using a special technique called contextual variable elimination [Poole and Zhang 2003]. CVE applies this technique to compute the probability of queries to CP-logic programs.

An alternative approach is taken by a very recent implementation of the ProbLog system (called ProbLog2 to distinguish it from previous implementations; Fierens et al. [2015]), which converts a program, queries and evidence (if any) to a weighted Boolean formula (cf. Chavira and Darwiche [2008]). Once transformed, the program can be evaluated by an external weighted model counting or max-SAT solver.

3.6.2.2    Direct Approaches Based on Explanation

A more direct approach is to find a set of explanations that is covering for a query Q and then to make the explanations pairwise incompatible. Explanations can be made pairwise incompatible in a number of ways. The pD engine [Fuhr 2000] uses inclusion-exclusion (Equation 3.7) directly. The Ailog2 system for Independent Choice Logic [Poole 2000] iteratively applies the Splitting Algorithm (Algorithm 3.1). More commonly, however, Binary Decision Diagrams (BDDs) [Bryant 1992] are used to ensure pairwise incompatibility. This approach was first used in the ProbLog system [De Raedt et al. 2007], and later adopted by several other systems including cplint [Riguzzi 2007, Riguzzi 2009] and PITA [Riguzzi and Swift 2013]

The BDD data structure was designed to efficiently store Boolean functions (i.e., formulas), which makes it a natural candidate to store explanations. A BDD is a directed acyclic graph, with a root node representing the start of the function, and with terminal nodes 0 (false) and 1 (true). An interior node, ni, sometimes called a decision node, represents a variable vi in the Boolean function. Each such ni has a 0-child representing the next node whose truth value will be examined if vi is false, and a 1-node representing the next node whose truth value will be examined if vi is true. Accordingly, each path from root to terminal node in a BDD represents a (partial or total) truth assignment to the variables leading to the truth of falsity of the formula. What gives a BDD its power are the following operations.

Ordering. all paths through the BDD traverse variables in the same order. This ensures that each variable is traversed at most once on a given path.

Reduction. within a BDD isomorphic subgraphs are merged, and any node whose two children root isomorphic subgraphs (or the same subgraph) is considered redundant and removed from the BDD. These operations ensure that once enough variables have been traversed to determine the value of the Boolean function, no other variables will be traversed (or need to be stored).

Although performing these operations when building a BDD can be expensive, the resulting BDD has the property that any two distinct paths differ in the truth value of at least one variable, so that BDDs are an efficient way to store and manipulate pairwise incompatible explanations, as described in Section 3.3.3.1.

To explain the details, consider an application to ProbLog, where in each probabilistic fact, either an atom or null may be chosen. Let (C, θ, i) be an atomic choice for the selection of the ground probabilistic fact: (C, θ, 1) means that Cθ was chosen, and (C, θ, 2) means that null was chosen. If we consider these atomic choices as Boolean random variables, then a set of explanations is simply a DNF formula, and storing this formula in a BDD will ensure pairwise incompatibility of the explanations in the set. Recall that if K is a pairwise incompatible set of explanations that is covering for a probabilistic query Q, then the probability of Q is given by

Accordingly, once K is stored in a BDD, a simple traversal of the BDD suffices to compute the probability of Q, as shown in Figure 3.3.

Figure 3.3    Determining the probability of a node in a BDD used to store a covering set of explanations [De Raedt et al. 2007].

Figure 3.4    A BDD representing a pairwise incompatible set of explanations for sneezing(david).

Example 3.20 Returning to the sneezing example of Section 3.2, a set of covering explanations for sneezing(david) is K = {κ₁, κ₂}, where κ₁ = {(C₁, {X/david}, 1)} and κ₂ = {(C₂, {X/david}, 1)}. A BDD representing K is shown in Figure 3.4: while K is not pairwise incompatible, note that the ordering and reduction operations used in constructing the BDD result in the fact that all paths through the BDD represent pairwise incompatible explanations. Using this BDD, the probability of sneezing(david) can be calculated by the simple algorithm of Figure 3.3.

Implementations of BDD-Based Explanation Approaches. The ProbLog system [Kimmig et al. 2011], implemented using YAP Prolog [Costa et al. 2012], has a twophase approach to computing probabilities for ProbLog programs. A source-code transformation is made of a ProbLog program so that during the SLD-proof phase each atomic choice is added to a running list representing the explanation of the proof. When the proof is completed the explanation is stored in a trie of the style used for tabling in YAP and XSB. Once all proofs have been completed the trie is traversed so that a BDD can be efficiently created using an external BDD package.⁹

The cplint system [Riguzzi 2007] is also implemented using YAP Prolog and an external BDD package, but implements LPADs. To directly implement LPADs, two extensions must be made. First, the BDD interface must be modified to support ground atomic choices that allow more than two outcomes; second default negation is supported via SLDNF. The PITA system [Riguzzi and Swift 2013] is based on XSB [Swift and Warren 2012] and uses tabling extended with answer subsumption in order to combine different explanations. As each new explanation is derived for a given subgoal G, it is added to the current BDD for G. When a tabling technique termed call subsumption is also used, PITA can be shown to theoretically terminate on any finitely well-defined LPAD that is stratified and for which all worlds have finite models.

Papers about CVE, BDD-based ProbLog, cplint, and PITA have compared the systems on certain probabilistic programs. Not surprisingly, source code transformations outperform meta-interpretations. The current generation of BDD-based systems usually—but not always—outperforms the transformation-based CVE, while recent experiments in [Fierens et al. 2015] indicate that translation of probabilistic logic programs into weighted Boolean formulas outperforms the use of BDDs on certain programs. ProbLog and PITA, which are more closely related, show conflicting experimental results. Timings based on PITA have shown that for traversals of probabilistic networks, the vast majority of time is spent in BDD manipulation. Based on the current set of experiments and benchmarks, there is no clear evidence about whether it is more efficient to construct a BDD during the course of evaluation as with PITA or to wait until the end as with ProbLog. In short, much more implementational and experimental work is needed to determine the best way to evaluate queries for unrestricted probabilistic logic programs.

Overall, implementation of probabilistic reasoning for the ASP-based P-Log has received less attention, although Gelfond et al. [2006] describe a prototype implementation. On the other hand, Anh et al. [2008] describe an approach that grounds a P-Log program using XSB and then sends it to an ASP solver.

3.6.3    Exact Query Evaluation for Restricted Programs

As an alternative to inference for unrestricted programs, an implementation may be restricted to programs for which the probability of queries is easy to compute. In particular, an implementation may assume axioms of exclusion and independence. This approach has been followed in an early implementation of PHA [Poole 1993b], and in a module of the PITA system [Riguzzi and Swift 2011]; however, this approach has been most thoroughly developed in the PRISM system [Sato et al. 2010], implemented using B-Prolog [Zhou 2012].¹⁰

In order to define when an LPAD T satisfies the assumption of exclusion, consider its grounding ground(T). If there is no world W of T such that the bodies of a pair of clauses of ground(T) sharing an atom in the head are both true, then T satisfies the assumption of exclusion. In this case, a covering set of explanations will always be pairwise incompatible and the probability of a query can be computed by summing the probability of the individual explanations. As an example, the program

violates the exclusiveness assumption as the two clauses for the ground atom q have non-exclusive bodies.

An LPAD T satisfies the assumption of independence when, for each clause C of ground(T), no pair of literals in the body of C depends on a common subgoal. The assumption of independence allows the probability of a body to be computed as the product of the probabilities of its literals. As an example, the program

doesn’t satisfy the independence assumption because a and b both depend on c. In the distribution semantics the probability of q is 0.2, while if we multiply the probabilities of a and b in the body of the clause for q we get 0.04.

To get an idea about how restrictive these assumptions are in practice, consider the examples introduced so far in this chapter. The sneezing examples (Examples 3.1–3.8) violate the exclusion assumption; the path example (Example 3.10) violates both independence and exclusion; the barber example (Example 3.16) violates independence. However the examples about Mendelian inheritance (Example 3.9), Hidden Markov Models (Example 3.11) and alarm (Section 3.5.2) satisfy both assumptions. In terms of practical applications, programs with the independence and exclusion assumptions have been used for parameter learning [Sato and Kameya 2001], and for numerous forms of generative modeling [Sato and Kameya 2008].

PRISM implements queries to probabilistic logic programs with the independence and exclusion assumptions by using tabling to collect a set of explanations that has any duplicates filtered out. Probabilities are then collected directly from this set. PITA also uses tabling, but with the addition of answer subsumption to combine probabilities of different explanations as query evaluation progresses. In either case, computation is much faster than if the independence and exclusion assumptions do not hold. In particular, the learning algorithm of PRISM in the case of HMMs achieves the same complexity of the Baum-Welch algorithm that is specific of HMMs [Sato and Kameya 2001].

Additionally, projecting out superfluous (non-discriminating) arguments from subgoals using the technique of Christiansen and Gallagher [2009] can lead to significant speed improvement for Hidden Markov Model examples. Finally, Riguzzi [2012] presents approaches for efficient evaluation of probabilistic logic programs that do not use the full independence and exclusion assumptions.

3.6.4    Approximation and Other Inferencing Tasks

For programs that violate the independence or exclusion assumptions, and for which exact inference may be too expensive, approximate inference may be considered. Recall from Equation 3.7 that, using the inclusion-exclusion principle, computing probability is exponential in the number of explanations. Accordingly, ProbLog [Kimmig et al. 2011] supports an optimization that retains only the k most likely explanations, thus reducing the cost of building a BDD to make the explanations pairwise incompatible. ProbLog also offers an approach similar to iterative deepening, where lower and upper bounds on the probability are iteratively computed and inference terminates when their difference is below a given threshold. Both of these approximations are sound only for definite programs; if negation is used, sound approximation requires a three-valued semantics (Section 3.3.4.1) to distinguish the known probabilities of a query and negation from the range that is still unknown due to approximation.

Monte Carlo simulations are also used by various systems. Monte Carlo in PRISM performs Bayesian inference (updating a prior probability distribution in the light of evidence) by updating a Metropolis-Hastings algorithm for Probabilistic Context Free Grammars [Sato 2011]. ProbLog and PITA perform plain Monte Carlo by sampling the worlds and counting the fraction where the query is true, exploiting tabling to save computation.

Lastly, while this section has focused on evaluation of ground queries when there is no additional supporting evidence, this is by no means the only inference problem that has been studied. ProbLog2 [Fierens et al. 2015] evaluates queries with and without supporting evidence. PRISM supports Maximum A Posteriori (or Most Probable Explanation) inference, which finds the most likely state of a set of query atoms given some evidence. In Hidden Markov Models, this inference reduces to finding the most likely sequence of the state variables also called the Viterbi path (also supported by PITA). Again, thanks to the exclusion and independence assumptions, the complexity of finding the Viterbi path in HMMs with PRISM is the same of the Viterbi algorithm that is specific to HMMs. Finally, recent work seeks to perform inference in a lifted way, i.e., by avoiding grounding the model as much as possible. This technique can lead to exponential savings in some cases [Van den Broeck et al. 2014, Bellodi et al. 2014].

3.7    Discussion

This chapter has described the distribution semantics for logic programs, starting with stratified Datalog programs, then showing how the semantics can be extended to programs that include function symbols and non-stratified negation (Section 3.3). Various PLP languages have been described and their inter-translatability has been discussed (Section 3.2). The relationship of PLPs and Bayesian networks has also been shown (Section 3.5). Finally, the intractable problem of inferencing with the distribution semantics was discussed in Section 3.6 along with implementations that either directly address the full distribution semantics, make simplifying restrictions about the types of programs for which they provide inference, or perform heuristic approximations.

We believe that this material provides necessary background for much of the current research into PLP. However as noted, our focus on the distribution semantics leaves out many interesting and important languages and systems (a few of which were summarized in Section 3.4). In addition, we have not covered the important problem of using these languages for machine learning. Indeed, the support for machine learning has been an important motivation for PLPs since the very first proposals and nowadays a variety of systems are available for learning either the parameters or the structure of programs under the distribution semantics.

To mention a very few such systems, PRISM [Sato and Kameya 2001], LeProbLog [Gutmann et al. 2008], LFI-ProbLog [Gutmann et al. 2011b], EMBLEM [Bellodi and Riguzzi 2013], and ProbLog2 [Fierens et al. 2015] learn the parameters either by using an EM algorithm or by gradient descent. SEM-CP-logic [Meert et al. 2008], SLIPCASE [Bellodi and Riguzzi 2012], and SLIPCOVER [Bellodi and Riguzzi 2015] learn both the structure and the parameters by performing a search in the space of possible programs and using parameter learning as a subroutine.

All these systems have been successfully applied to a variety of domains, including biology, medicine, link prediction, and text classification. The results obtained show that these systems are competitive with systems at the state of the art of statistical relational learning such as Alchemy [Richardson and Domingos 2006] and others.

Acknowledgments

This work was supported by the National Group of Computing Science (GNCS-INDAM).

References

M. Alviano, W. Faber, and N. Leone. 2010. Disjunctive ASP with functions: Decidable queries and effective computation. Theory and Practice of Logic Programming, 10(4-6): 497–512. DOI: 10.1017/S1471068410000244. 207, 210

H. Anh, C. Ramli, and C. Dam´asio. 2008. An implementation of extended P-Log using XASP. In Proceedings 24th International Conference Logic Programming, pp. 739–743. DOI: 10.1007/978-3-540-89982-2_68. 224

K. R. Apt and M. Bezem. 1991. Acyclic programs. New Generation Computing, 9(3/4): 335–364. DOI: 10.1007/BF03037168. 207, 217

F. Bacchus. 1993. Using first-order probability logic for the construction of bayesian networks. In Proceedings 9th Annual Conference on Uncertainty in Artificial Intelligence, pp. 219–226. DOI: 10.1016/B978-1-4832-1451-1.50031-7. 212, 215

C. Baral, M. Gelfond, and N. Rushton. 2009. Probabilistic reasoning with answer sets. Theory and Practice of Logic Programming, 9(1): 57–144. DOI: 10.1017/S1471068408003645. 186, 208, 209

S. Baselice and P. Bonatti. 2010. A decidable subclass of finitary programs. Theory and Practice of Logic Programming, 10(4-6): 481–496. DOI: 10.1017/S1471068410000232. 207, 210

E. Bellodi and F. Riguzzi. 2012. Learning the structure of probabilistic logic programs. In Proceedings 21st International Conference on Inductive Logic Programming, vol. 7207 of LNCS, pp. 61–75. Springer Berlin Heidelberg. DOI: 10.1007/978-3-642-31951-8_10. 227

E. Bellodi and F. Riguzzi. 2013. Expectation Maximization over binary decision diagrams for probabilistic logic programs. Intelligent Data Analysis, 17(2): 343–363. DOI: 10.3233/IDA-130582. 227

E. Bellodi and F. Riguzzi. 2015. Structure learning of probabilistic logic programs by searching the clause space. Theory and Practice of Logic Programming, 15(2): 169–212. DOI: 10.1017/S1471068413000689. 227

E. Bellodi, E. Lamma, F. Riguzzi, V. Santos Costa, and R. Zese. 2014. Lifted variable elimination for probabilistic logic programming. Theory and Practice of Logic Programming, 14(Special issue 4-5 - ICLP 2014): 681–695. DOI: 10.1017/S1471068414000283. 227

H. Blockeel. 2004. Probabilistic logical models for Mendel’s experiments: An exercise. In Proceedings 14th International Conference on Inductive Logic Programming, Work in Progress track. 197

R. Bryant. 1992. Symbolic boolean manipulation with ordered binary decision diagrams. ACM Computing Surveys, 24(3): 293–318. DOI: 10.1145/136035.136043. 221

F. Calimeri, S. Cozza, G. Ianni, and N. Leone. 2011. Finitely recursive programs: Decidability and bottom-up computation. AI Communication, 24(4): 311–334. DOI: 10.3233/AIC-2011-0509. 207, 210

M. Chavira and A. Darwiche. 2008. On probabilistic inference by weighted model counting. Artificial Intelligence, 172(6-7): 772–799. DOI: 10.1016/j.artint.2007.11.002. 221

Y. Chow and H. Teicher. 2012. Probability Theory: Independence, Interchangeability, Martingales. Springer Texts in Statistics. Springer, New York. 206

H. Christiansen and J. Gallagher. 2009. Non-discriminating arguments and their uses. In Proceedings 25th International Conference on Logic Programming, pp. 55–69. DOI: 10.1007/978-3-642-02846-5_10. 226

V. S. Costa, D. Page, M. Qazi, and J. Cussens. 2003. CLP(BN): Constraint logic programming for probabilistic knowledge. In Proceedings 19th Conference on Uncertainty in Artificial Intelligence, pp. 517–524. 186, 215

V. S. Costa, L. Damas, and R. Rocha. 2012. The YAP Prolog system. Theory and Practice of Logic Programming, 12(1-2): 5–34. DOI: 10.1017/S1471068411000512. 217, 223

J. Cussens. 2001. Parameter estimation in stochastic logic programs. Machine Learning, 44(3): 245–271. DOI: 10.1023/A:1010924021315. 211

E. Dantsin. 1991. Probabilistic logic programs and their semantics. In Proceedings 1st and 2nd Russian Conference on Logic Programming, vol. 592 of LNCS, pp. 152–164. Springer. DOI: 10.1007/3-540-55460-2_11. 186

L. De Raedt and A. Kimmig. 2015. Probabilistic (Logic) Programming Concepts. Machine Learning, 100(1): 5–47. DOI: 10.1007/s10994-015-5494-z. 187

L. De Raedt, A. Kimmig, and H. Toivonen. 2007. ProbLog: A probabilistic Prolog and its application in link discovery. In Proceedings 20th International Joint Conference on AI, pp. 2462–2467. 186, 191, 198, 222, 223

L. De Raedt, B. Demoen, D. Fierens, B. Gutmann, G. Janssens, A. Kimmig, N. Landwehr,

T. Mantadelis, W. Meert, R. Rocha, V. Santos Costa, I. Thon, and J. Vennekens. 2008. Towards digesting the alphabet-soup of statistical relational learning. In NIPS*2008 Workshop on Probabilistic Programming. 196

A. Dekhtyar and V. Subrahmanian. 2000. Hybrid probabilistic programs. Journal of Logic Programming, 43(2): 187–250. DOI: 10.1016/S0743-1066(99)00059-X. 215

P. Dung. 1991. Negation as hypothesis: An abductive foundation for logic programming. In Proceedings 8th International Conference on Logic Programming, pp. 1–17. 207

D. Fierens, G. Van den Broeck, J. Renkens, D. Shterionov, B. Gutmann, I. Thon, G. Janssens, and L. De Raedt. 2015. Inference and learning in probabilistic logic programs using weighted boolean formulas. Theory and Practice of Logic Programming, 15(3): 358–401. DOI: 10.1017/S1471068414000076. 221, 224, 226, 227

N. Fuhr. 2000. Probabilistic Datalog: Implementing logical information retrieval for advanced applications. Journal of the American Society of Information Sciences, 51(2): 95–110. DOI: 10.1002/(SICI)1097-4571(2000)51:2%3C95::AID-ASI2%3E3.0.CO;2-H. 186, 221

M. Gelfond and V. Lifschitz. 1988. The stable model semantics for logic programming. In Proceedings 5th International Conference Logic Programming, pp. 1070–1080. 192

M. Gelfond and N. Rushton. 2010. Causal and probabilistic reasoning in p-log: Heuristics, probabilities and causality. In R. Dechter, H. Geffner, and J. Halpern, editors, A Tribute to Judea Pearl, pp. 337–359. College Publications. 210

M. Gelfond, N. R. N, and W. Zhu. 2006. Combining logical and probabilistic reasoning. In Proceedings of AAAI 06 Spring Symposium: Formalizing and Compiling Background Knowledge and Its Applications to Knowledge Representationand Question Answering, pp. 50–55. 224

A. Gorlin, C. R. Ramakrishnan, and S. A. Smolka. 2012. Model checking with probabilistic tabled logic programming. Theory and Practice of Logic Programmimg, 12(4-5): 681–700. DOI: 10.1017/S1471068412000245. 207

S. Greco, C. Molinaro, and I. Trubitsyna. 2013. Bounded programs: A new decidable class of logic programs with function symbols. In Proceedings 23rd International Joint Conference on AI, pp. 926–932. 207, 210

B. Gutmann, A. Kimmig, K. Kersting, and L. De Raedt. 2008. Parameter learning in probabilistic databases: A least squares approach. In Proceedings European Conference on Machine Learning and Knowledge Discovery in Databases, pp. 473–488. DOI: 10.1007/978-3-540-87479-9_49. 227

B. Gutmann, M. Jaeger, and L. De Raedt. 2011a. Extending problog with continuous distributions. In Proceedings 20th International Conference on Inductive Logic Programming, vol. 6489 of LNCS, pp. 76–91. Springer. DOI: 10.1007/978-3-642-21295-6_12. 192

B. Gutmann, I. Thon, and L. D. Raedt. 2011b. Learning the parameters of probabilistic logic programs from interpretations. In Proceedings European Conference on Machine Learning and Knowledge Discovery in Databases, pp. 581–596. DOI: 10.1007/978-3-642-23780-5_47. 227

J. H. Halpern. 2003. Reasoning About Uncertainty. MIT Press, Cambridge, MA. 186, 200

M. Islam, C. R. Ramakrishnan, and I. V. Ramrkrishnan. 2012. Inference in probabilistic logic programs with continuous random variables. Theory and Practice of Logic Programming, 12(4-5): 505–523. DOI: 10.1017/S1471068412000154. 192

K. Kersting and L. D. Raedt. 2001. Towards combining inductive logic programming with Bayesian networks. In Proceedings 11th International Conference on Inductive Logic Programming, pp. 118–131. DOI: 10.1007/3-540-44797-0_10. 186, 215

A. Kimmig, B. Demoen, L. De Raedt, V. S. Costa, and R. Rocha. 2011. On the implementation of the probabilistic logic programming language ProbLog. Theory and Practice of Logic Programming, 11(2-3): 235–262. DOI: 10.1017/S1471068410000566. 187, 223, 226

D. Koller and N. Friedman. 2009. Probabilistic Graphical Models: Principles and Techniques. MIT Press, Cambridge, MA. 221

A. N. Kolmogorov. 1950. Foundations of the Theory of Probability. Chelsea Publishing Company, New York. 200

H. Kyburg and C. Teng. 2001. Uncertain Inference. Cambridge University Press. 213

W. Meert, J. Struyf, and H. Blockeel. 2008. Learning ground CP-Logic theories by leveraging Bayesian network learning techniques. Fundamanta Informaticae, 89(1): 131–160. 221, 227

W. Meert, J. Struyf, and H. Blockeel. 2009. CP-Logic theory inference with contextual variable elimination and comparison to BDD based inference methods. In Proceedings 19th International Conference on Inductive Logic Programming. DOI: 10.1007/978-3-642-13840-9_10. 221

S. Muggleton. 1996. Stochastic logic programs. In Advances in inductive logic programming, pp. 254–264. IOS Press. 211

R. Ng and V. S. Subrahmanian. 1992. Probabilistic logic programming. Information and Computation, 101(2): 150–201. DOI: 10.1016/0890-5401(92)90061-J. 214

N. J. Nilsson. 1986. Probabilistic logic. Artificial Intelligence, 28(1): 71–87. DOI: 10.1016/0004-3702(86)90031-7. 211

C. Papadimitriou. 1994. Computational Complexity. Addison-Wesley. 220

J. Pearl. 1988. Probabilistic Reasoning in Intelligent Systems: Networks of Plausible Inference. Morgan Kaufmann. 215

D. Poole. 1993a. Probabilistic Horn abduction and Bayesian networks. Artificial Intelligence, 64(1). DOI: 10.1016/0004-3702(93)90061-F. 203

D. Poole. 1993b. Logic programming, abduction and probability - a top-down anytime algorithm for estimating prior and posterior probabilities. New Generation Computing, 11(3): 377–400. DOI: 10.1007/BF03037184. 186, 188, 224

D. Poole. 1997. The Independent Choice Logic for modelling multiple agents under uncertainty. Artificial Intelligence, 94(1-2): 7–56. DOI: 10.1016/S0004-3702(97) 00027-1. 186, 188, 198, 200, 206

D. Poole. 2000. Abducing through negation as failure: stable models within the independent choice logic. Journal of Logic Programming, 44(1-3): 5–35. DOI: 10.1016/S0743-1066(99)00071-0. 202, 205, 221

D. Poole and N. Zhang. 2003. Exploiting contextual independence in probabilistic inference. Journal of Artificial Intelligence Research, 18: 266–313. DOI: 10.1613/jair.1122. 221

T. Przymusinski. 1989. Every logic program has a natural stratification and an iterated least fixed point model. In Proceedings 8th ACM SIGACT-SIGMOD-SIGART Symp. on Principles of Database Systems, pp. 11–21. ACM Press. DOI: 10.1145/73721.73723. 192

A. Rauzy, E. Chˆatelet, Y. Dutuit, and C. B´erenguer. January 2003. A practical comparison of methods to assess sum-of-products. Reliability Engineering and System Safety, 79(1): 33–42. DOI: 10.1016/S0951-8320(02)00165-5. 220

M. Richardson and P. Domingos. 2006. Markov logic networks. Machine Learning, 62(1-2): 107–136. DOI: 10.1007/s10994-006-5833-1. 227

F. Riguzzi. 2007. A top-down interpreter for LPAD and CP-logic. In Proceedings 10th Congress of the Italian Association for Artificial Intelligence, vol. 4733 of LNAI, pp. 109–120. Springer. DOI: 10.1007/978-3-540-74782-6_11. 222, 223

F. Riguzzi. 2009. Extended semantics and inference for the Independent Choice Logic. Logic Journal of the IGPL, 17(6): 589–629. DOI: 10.1093/jigpal/jzp025. 207, 222

F. Riguzzi. 2012. Optimizing inference for probabilistic logic programs exploiting independence and exclusiveness. In Proceedings 27th Italian Conference on Computational Logic. 226

F. Riguzzi and T. Swift. 2011. The PITA system: Tabling and answer subsumption for reasoning under uncertainty. Theory and Practice of Logic Programming, 11(4-5): 433–449. DOI: 10.1017/S147106841100010X. 224

F. Riguzzi and T. Swift. March 2013. Well-definedness and efficient inference for probabilistic logic programming under the distribution semantics. Theory and Practice of Logic Programming, 13(2): 279–302. DOI: 10.1017/S1471068411000664. 207, 222, 224

B. Russell. 1967. Mathematical logic as based on the theory of types. In J. van Heikenoort, editor, From Frege to Godel, pp. 150–182. Harvard University Press, Cambridge, MA. 207

T. Sato. 1995. A statistical learning method for logic programs with distribution semantics. In Proceedings 12th International Conference Logic Programming, pp. 715–729. 186, 198, 200

T. Sato. 2011. A general MCMC method for Bayesian inference in logic-based probabilistic modeling. In Proceedings 22nd International Joint Conference on AI. 226

T. Sato and Y. Kameya. 1997. PRISM: A language for symbolic-statistical modeling. In Proceedings 15th International Joint Conference on AI, pp. 1330–1339. 189, 224

T. Sato and Y. Kameya. 2001. Parameter learning of logic programs for symbolic-statistical modeling. Journal of Artificial Intelligence Research, 15: 391–454. DOI: 10.1613/jair.912. 200, 206, 225, 226, 227

T. Sato and Y. Kameya. 2008. New advances in logic-based probabilistic modeling by PRISM. In L. De Raedt, P. Frasconi, K. Kersting, and S. Muggleton, editors, Probabilistic Inductive Logic Programming - Theory and Applications, vol. 4911 of LNCS, pp. 118–155. Springer-Verlag. DOI: 10.1007/978-3-540-78652-8_5. 225

T. Sato and P. Meyer. 2012. Tabling for infinite probability computation. In Proceedings 28th International Conference Logic Programming, vol. 17 of LIPIcs, pp. 348–358. DOI: 10.4230/LIPIcs.ICLP.2012.348. 207

T. Sato, Y. Kameya, and N.-F. Zhou. 2005. Generative modeling with failure in PRISM. In Proceedings 19th International Joint Conference on AI, pp. 847–852. 207

T. Sato, N.-F. Zhou, Y. Kameya, and Y. Izumi, 2010. PRISM User’s Manual (Version 2.0). http://sato-www.cs.titech.ac.jp/prism/download/prism20.pdf. 187, 224

P. Sevon, L. Eronen, P. Hintsanen, K. Kulovesi, and H. Toivonen. 2006. Link discovery in graphs derived from biological databases. In International Workshop on Data Integration in the Life Sciences, vol. 4075 of LNCS, pp. 35–49. Springer. DOI: 10.1007/11799511_5. 198

T. Swift and D. S. Warren. 2012. XSB: Extending the power of Prolog using tabling. Theory and Practice of Logic Programming, 12(1-2): 157–187. DOI: 10.1017/S1471068411000500. 224

M. Truszczynski. 2018. An introduction to the stable and the well-founded semantics of logic programs. In M. Kifer and Y. A. Liu, editors, Declarative Logic Programming: Theory, Systems, and Applications. MCP/ACM. 188

G. Van den Broeck, W. Meert, and A. Darwiche. 2014. Skolemization for weighted first-order model counting. In Proceedings 17th International Conference Principles of Knowledge Representation and Reasoning. 227

A. Van Gelder, K. A. Ross, and J. S. Schlipf. 1991. The well-founded semantics for general logic programs. Journal of the ACM, 38(3): 620–650. DOI: 10.1145/116825.116838. 192

J. Vennekens and S. Verbaeten. 2003. Logic programs with annotated disjunctions. Technical Report CW386, KU Leuven. 196, 217, 218, 219

J. Vennekens, S. Verbaeten, and M. Bruynooghe. 2004. Logic programs with annotated disjunctions. In Proceedings 20th International Conference Logic Programming, pp. 195–209. DOI: 10.1007/978-3-540-27775-0_30. 186, 190

J. Vennekens, M. Denecker, and M. Bruynooghe. 2009. CP-logic: A language of causal probabilistic events and its relation to logic programming. Theory and Practice of Logic Programming, 9(3): 245–308. DOI: 10.1017/S1471068409003767. 186, 191, 221

M. P. Wellman, J. S. Breese, and R. P. Goldman. 1992. From knowledge bases to decision models. The Knowledge Engineering Review, 7(01): 35–53. DOI: 10.1017/S0269888900006147. 212, 215

N. Zhou. 2012. The language features and architecture of B-Prolog. Theory and Practice of Logic Programming, 12(1-2): 189–218. DOI: 10.1017/S1471068411000445. 224

1. In this chapter the term distribution semantics is used in different contexts to refer both to a particular semantics and to a family of related semantics.

2. CP-logic [Vennekens et al. 2009] has a similar syntax to LPADs, and the semantics of both languages coincide for stratified Datalog programs.

3. This restriction is sometimes called soundness in the PLP literature. There have been various definitions of stratification in the literature that involve various types of negative self-dependency occurring in the derivation of an atom A. Among the most general is that of Przymusinski [1989], in which a program is dynamically stratified iff it has a two-valued well-founded model. This notion of stratification is used (sometimes implicitly) in this chapter.

4. The probability measure is then turned into a probability distribution by the identity map.

5. For simplicity, we consider only the finite additivity version of probability spaces [Halpern 2003]. A more general case, the case of countable additivity, is detailed in Sato and Kameya [2001]. In this case, probability measures are defined over σ-algebras.

6. As an alternative approach, Sato et al. [2005] provides a semantics for negation in probabilistic programs based on the three-valued fitting semantics for logic programs.

7. We note that this equivalence is only for ground programs, unlike the equivalences of Section 3.3.2 which hold for non-ground programs.

8. It is easy to see that counting solutions to a #P-complete problem can be done in polynomial space. By Toda’s Theorem, every problem in FPspace is reducible in polynomial time to a problem in #P (cf. Papadimitriou [1994]).

9. The Cudd package (http://vlsi.colorado.edu/~fabio/CUDD/node7.html) is used for ProbLog as well as for cplint and for PITA.

10. The assumptions of exclusion and independence are made in the PRISM system, but not in the PRISM language [Sato and Kameya 1997].

PART II

SYSTEMS

4

WAM for Everyone: A Virtual Machine for Logic Programming

David S. Warren

This chapter is a tutorial presentation of the Warren Abstract Machine (aka WAM), which is a virtual machine for Prolog designed by David H. D. Warren [Warren 1983] (note not David S. Warren, who is the author of this chapter.) We present a variant of the WAM by developing it incrementally through a series of examples. Its similarity to a traditional implementation of a procedural language is emphasized. The development starts with a description of the run-time environment that supports Prolog program execution. Then it is shown how deterministic Datalog programs compile to WAM instructions, followed by deterministic Prolog programs that include complex terms, and finally nondeterministic Prolog programs that require backtracking.

4.1    Introduction

In this chapter I describe my personal version of the Prolog virtual machine that is known as the Warren Abstract Machine (WAM). The WAM was originally designed by David H. D. Warren (no relation to this author) as an implementation vehicle for the logic programming language, Prolog, and first described in an unpublished technical report [Warren 1983] and then given as a brief description in a publication by Tick and Warren [1984]. The other best-known description of the WAM is the book by Ait-Kaci [1991]. The original description is rather cryptic and the book is rather long. I also found the terminology and description of the instruction set to be somewhat nonstandard and potentially confusing to those with a background in traditional compiler technology. The hope for this chapter is that the description of the WAM variant given here is more accessible to those somewhat familiar with traditional compiler technology and interested in how Prolog can be implemented efficiently. This chapter is a major revision, with 30 years of hindsight, of a technical report [Warren 1984] that was written for compiler students long ago in the mid 1980s.

Perhaps it is appropriate to clarify the intended meaning of the title of this chapter: WAM for Everyone. There are many (minor and major) variations of the virtual machine that D. H. D. Warren developed [Warren 1983], and the one described here is this author’s. We have changed a number of register names, instruction names, and instruction formats, in particular the treatment of temporary variables, to improve (we hope) clarity, but the underlying architecture is very much the same.¹ So, while it is not exactly The WAM, it is certainly close enough to be A WAM. And for the Everyone: to easily follow this tutorial, the reader should have some background in basic machine architectures (e.g., registers, memory, addresses) and in the basic implementation techniques of procedural programming languages (e.g., the run-time stack, procedure invocation).² Also, a minimal knowledge of the Prolog language and how it works is necessary. So while this tutorial may not be for Everyone, we hope it will be accessible to Everyone likely to be interested in Prolog implementation.

Here we develop the WAM through a series of stages.

•  We describe the run-time environment for compiled Prolog programs: how data values are stored, how activation records are formatted, how procedures are invoked, return, and fail, etc.

•  We develop and motivate the representation by starting with a brief review of the run-time environment for a procedural language like C.

•  We then describe the run-time environment necessary to support Prolog data values and their handling, initially limiting variables to take on only constants (and variables) as values. This is introduced in a situation without nondeterminism and thus without backtracking. With this representation we discuss unification and parameter passing in Prolog.

•  We next introduce structured records (complex terms involving functor symbols) and the global heap to store them, and discuss how parameter passing works in this context.

•  We then introduce the mechanisms necessary for nondeterminism and backtracking.

•  After that we describe various further optimizations, which can make programs more time and space efficient.

•  Finally, we briefly discuss how to add some extended Prolog functionality that was not part of the original WAM.

4.2    The Run-Time Environment of a Traditional Procedural Language

A compiler translates source code to some form of object code for which there is a machine that can execute it. That machine can be actual physical hardware, or it can be a virtual machine, which has its own instruction set. Virtual machines can be executed by an emulator program that interprets all the instructions of the virtual machine. Or the instructions of a virtual machine can be further translated to a lower-level machine language, in which case the language of the virtual machine is often called “intermediate code.” The WAM is a virtual machine that is usually implemented by an emulator.³

4.2.1    Activation Records

In a procedural programming language, such as C, a run-time stack of Activation Records (ARs) is used to store the values of all variables local to a procedure. Since Prolog doesn’t have global variables, we need not consider them. Also for our purposes of explication, we will consider only C functions that return void, which we call C procedures. To begin, we will assume they have no parameters. And we start with a naïve, non-optimized compilation of these procedures.

An executing C program maintains a run-time stack (or run-stack) of activation records.⁴ Each active procedure has an AR, which contains the values of the variables local to that procedure. During execution of the C program, the AR on the top of the stack is the one for the currently active procedure and contains the values of its variables. When a procedure is called, it pushes its AR onto the run-stack. When a procedure returns, it pops its AR (which will be the top one) off the stack. When a procedure accesses a local variable, it looks in the AR on the top of the stack, and uses the appropriate offset to access the desired variable value.

The AR for a procedure might be formatted as follows:

This AR is a record that contains first a pointer to the AR of the calling procedure (i.e., the next lower one on the run-stack), then a pointer to the return point for this procedure (i.e., the address of the instruction in the calling procedure that immediately follows the branch that caused entry to this procedure), and then the local variables for the procedure.⁵

Now consider the following simple C-like program (sketch):

Figure 4.1    C partial run-stack.

Control starts in main(), which calls the procedure C(), which in turn calls B(). Figure 4.1 shows the activation stack after B has been called and is active. (The run-stack is shown growing upward.)

4.2.2    Procedure Invocation Code

The code executed at the time of call and at the time of return must carry out the necessary changes to the structure of the run-stack. There are three points at which code may be generated for this:

1.  at the point of call to a procedure P;

2.  at the entry point of a procedure P; and

3.  at the return point of a procedure P.⁶

Consider the code that is emitted by the compiler at these three points: procedure call, procedure entry, and procedure exit. We will consider both the necessary intermediate code, and the final code generated from each intermediate code instruction.⁷ Initially, we assume that the called procedure has no parameters.

Source Code

Intermediate Code

Detailed Operations

call P;

call P

put retpt in known register;

branch to P’s entry point;

procedure P;

procbeg P

save prevAR in new AR;

save retpt in new AR;

make new AR current;

up stacktop;

end;

procend P

reset stacktop;

use prevAR to reset current AR;

branch to retpt;

4.2.3    Passing Parameters

Now consider what more is required when we introduce procedures with parameters. We consider call-by-value parameters, as for the procedure with heading:

Let’s assume that we will pass the addresses (or perhaps values) of the parameters in a set of general registers: R1, R2, …, Rn. We include space in the AR for the integer variable iVar, and for the character pointer strVar. The AR for aProc would have the following format:

Accesses to iVar or strVar within the procedure aProc use the local copies in this AR, exactly as local variables. We assume that the virtual machine has enough global registers to hold some addresses necessary to manage the run-time environment: a register RcurAR to hold the address of the current AR, which will be used by all instructions to find the address of a local variable by adding the correct displacement to the value of this register; a register Rretpt to hold (temporarily) the return point for a procedure call; and a register Rstacktop to point to the top of the runstack. Therefore, code generated for an invocation of this routine by the statement aProc(j+k,c) could be as follows.

Source Code

Intermediate Code

Comments

aProc(j+k,c)

t1 := j+k

ld R1,t1

ld R2,c

call aProc

eval j+k and assign to temp t1;

load t1 into register 1;

load (ptr to) c into register 2;

set Rretpt to addr of next instr, and branch to aProc’s entry point;

procedure aProc

procbeg aProc

store RcurAR in new AR (at address in Rstacktop);

store Rretpt in new AR;

set RcurAR to this new AR;

up Rstacktop of run-stack;

store R1 to iVar (in AR);

store R2 to strVar (in AR);

end aProc

procend aProc

reset stacktop;

use RcurAR → prevAR, reset RcurAR;

branch to retpt;

We see that at the point of call, code is generated to evaluate the parameters and load their values into registers R1 to Rn, for the n parameters. Then a branch is made to the entry point of the called procedure, with the address of the following instruction (the return point) saved in the return register Rretpt. At entry to a procedure, the register Rstacktop is used to allocate a new AR, and the two required fields: the previous AR address and the return address, are set from the respective registers. Then Rstacktop is updated to the new stack top, using the known size of the AR, and the values of the actual parameters, in the registers, are saved into the new AR. At return from a procedure, Rstacktop is reset from RcurAR, RcurAR is reset to its previous value from the current AR, and a branch is made to retpt.

With this simple introduction to a run-time environment for a simple standard procedural language, we proceed now to consider the run-time environment for a simple subset of Prolog.

4.3    Deterministic Datalog

Prolog variables take on terms as values. Terms can be variables, constants (which include atoms, integers, and floats), or complex terms made up of a record name (aka functor) followed by a fixed length sequence of fields, each of which can contain another term. Datalog is a subset of Prolog where the only values are constants and variables; no complex terms are allowed. We begin by considering deterministic Datalog programs, i.e., Datalog programs without the nondeterminism normally found in Prolog. This is quite a limited subset of Prolog with very limited expressibility, but it will serve as a good basis from which to understand the WAM.

4.3.1    Representing Variables and Constants

We first need to consider how values in Prolog are represented in computer memory. Prolog is a dynamically typed language, in that a Prolog variable may, at runtime, contain any Prolog value. For example, a variable may get assigned (or unified with) a constant, or a complex term (i.e., named record structure), or even another variable as a value. The fact that a program variable can contain a variable as a value is unusual in programming languages. Prolog is dynamically typed, and the WAM has chosen to tag Prolog values so that the system can determine at run-time the type of a value by looking at its tag. We will assume, for simplicity, that our implementation is for a 64-bit processor, so all addresses are word addresses and are 8-byte aligned. This means that the three low-order bits of an address are always zero, and we will steal them for the necessary datatype tags.⁸

Since we are (for now) implementing only Datalog, the only two kinds of values we have are constants and variables. Atom constants (identified by their string names) are entered into a global table (normally hashed), called the atom table or the name table. A tagged pointer to the name in the global table is used to represent the atom constant. So, constants are equal if and only if their representations (i.e., tagged addresses) are equal (cf. String.intern in Java).

Now let’s consider the somewhat unusual variables in Prolog. In Prolog, a variable may have a value that is a constant (or complex term), or it may not (yet) have a value, in which case we say it is (still) a variable. A variable may get a non-variable value, in which case it cannot thereafter be changed.⁹ Alternatively, a variable may be assigned (aka unified with) another variable, in which case it is still a variable, and in the future computation these variables must get the same values (alternatively said as “they are the same variable” or “they are aliased.”) If a variable is assigned to another variable, the variable value is represented as a pointer (or reference) to that other variable. We use the 000 tag for references, so that such references can be followed directly without having to mask out the tag. And then we represent an unassigned variable as a reference to itself.¹⁰

Figure 4.2    Memory states for Datalog values.

Example 4.1 Consider Figure 4.2, which shows possible memory states that represent possible Datalog values. We use uppercase letters to indicate variables, and lowercase letters to indicate constants. Figure 4.2 shows variables A, B, and C as words in a single AR (for specificity and simplicity). The first diagram shows a program variable A which has not been assigned any value, so it is represented as a reference to itself.¹¹

The second diagram shows the state after A has been unified with (or assigned) the constant a. The variable A now contains a constant-tagged pointer to the string “a” in the global atom table, which we represent in the figure simply by a.

The third diagram shows the memory state after the variable A and the variable B have been unified: A points to itself and B points to A. (It might also be the case that B pointed to itself and A pointed to B.)

The fourth diagram shows the memory state that started with two distinct program variables A and B, and then the unifications: A = B and A = a, were done (in that order). After A = B, B contained a reference to A, and A still contained a reference to itself; after A = a, A gets the tagged constant and the state is as shown. Notice that to find the value of B here, we have to follow its reference to A to see that it has the constant value. This is called “dereferencing” and may be required on any access to a variable value. That is, the way the system must access a variable’s value is to follow a chain of references (if any) to its end; at its end will either be a constant value, or a location containing a reference to itself, in which case it is a variable, and that variable is the value sought.

Now we can see what would have happened if instead of pointing B to A as a result of the unification A = B, we had instead pointed A to B. This is shown in the fifth diagram. So in this case, after A = B, we have A referencing B, and B referencing itself. Then for the unification A = a, we have to find the value for A by dereferencing, which results in the variable B, which is given the value of the constant a. Notice that because we always dereference to access a value, the two memory structures of the fourth and fifth diagrams will always provide the same variable values: that is both A and B have value a. We see that it does not matter (with respect to the ultimate values of the variables) whether we point A to B or B to A when we unify A and B.

The sixth diagram shows an example where a dereference chain of length 2 has been built.

4.3.2    Simple Deterministic Datalog Programs

We begin to look at the WAM instructions that are used to implement Prolog programs. We develop the WAM incrementally through a series of examples, beginning with simple constructs and slowly adding more and more complexities. Each example builds on the previous ones, and when we are finished we will be able to compile all Prolog programs to WAM instructions that implement them.

Example 4.2 We start with a very simple Datalog rule:

The WAM code that implements this rule follows.

On entry to the predicate q/1, R1 contains the argument that is passed in, Rretpt contains the address of the return point, and RcurAR contains the address of the AR of the calling predicate. The allocate instruction uses its argument (the size of the current predicate’s AR in words: 2 for the standard global register values plus 1 for the only local variable X) to allocate a new AR on the top of the run-stack and to save the two registers in its first two words.

The getvar R1,V1 instruction is used to get the value of a top-level first occurrence of a variable in the head of a rule, with arguments indicating the register the variable is in, and the displacement in the current AR of the local variable which will hold its value. We use V1 in this assembly code to indicate the first local variable; it would be replaced in the machine code with a constant value indicating the displacement of the location of that variable in the AR. This instruction simply stores the value of the register in the current AR.

In general, get-type instructions are used to “get” the values for arguments in the heads of rules. We will encounter other get-type instructions shortly.

At this point the WAM has processed the head of the rule, having initialized the current AR to contain the appropriate values. Next, it must prepare for the call to p(a,X) by loading the general registers with the appropriate parameter values. The putcon R1,a instruction loads into register 1 the representation of the constant a, i.e., a tagged pointer to its string in the global atom table. The putval R2,V1 instruction loads the contents of the indicated local variable into the indicated register, here loading R2 to contain the value of the first local variable, which contains the value of X. Then it calls the predicate p/2 using the call p/2 instruction. This instruction sets the register Rretpt to the address of the next instruction and branches to the entry point for the predicate p/2.

In general, put-type instructions are used to “put” values into registers to pass them to predicates that are called in the bodies of rules.

The next two instructions, which will be executed after the call to p/2 returns, prepare for and call s/1, passing the value of X in R1. Finally, when s/1 returns, this predicate, q/1, must restore the run-stack and return to its caller. It does this by first using the deallocate 3 instruction, which uses the current RcurAR register to reload the Rretpt and RcurAR registers and resets the Rstacktop register to the previous top-of-run-stack value. The proceed instruction simply branches to the address in the Rretpt register.¹²

Example 4.3 Consider what the memory looks like when q/1 is called having been passed a constant, say b. In this case, on entry R1 contains the constant b (i.e., tagged pointer to the string b in the atom table) as shown in Figure 4.3(a). Then the allocate instruction pushes a new AR on the run-stack and sets the first two pointers. Next, the getvar instruction stores the contents of R1, i.e., b, in the third field of that new local AR. That value is then loaded from there to be passed to p/2 in R2, which state is shown in Figure 4.3(b). When control returns from p/2, that value is again loaded into R1 to pass to the call to s/1.

Example 4.4 It is also possible for q/1 to be called with a variable. In that case, on entry R1 contains a reference (a tagged, with 000, address) to a local variable, say Y, in an AR deeper in the run-stack. Figure 4.4(a) shows such a state at the entry point to q/1. The reference is stored (by the getvar instruction) in the local variable of this predicate, and then is passed to p/2 in R2. At this point, X and R2 (and Y itself) all contain references to Y. The state at this point is shown in Figure 4.4(b).

If p/2 accesses this value through R2, it will dereference it to find its location in that deeper AR. Any operation it performs with this address will act on that location. Note that it is important, for memory management purposes, for a variable that references another variable to point deeper in the stack (i.e., down in the upwardgrowing stacks of our figures). If a deeper variable was to point to a shallower variable, the shallower variable might be deallocated when the stack is popped, leaving the deeper variable as a dangling pointer. So we make sure that whenever one variable points to another, it points deeper in the stack. (In this particular case, this happens automatically; it would be unnatural to have the getvar instruction set the variable passed in to point to the new local variable.)

Figure 4.3    (a) State at call to q(b) and (b) state just before call to p(a,X).

Figure 4.4    (a) State at call to q(X); (b) State at call to p(a,X).

4.3.3 Eliminating the StackTop pointer

We have used an explicit Rstacktop pointer to keep track of the top of the run-stack so a new AR can be allocated on top of the stack. In fact, with a little bit of effort, we can eliminate that register altogether and make AR allocation/deallocation more efficient.

The problem is how to locate the end of the AR that is on top of the stack, since this is the location that needs to be determined when the allocate instruction must allocate a new AR. Note that an AR is allocated on entry to a procedure, and at that time, the size of the caller’s AR is needed, since the stacktop can be computed from that size and the value of the RcurAR register. By extending the call instruction with a word to contain the size of the activation record (of the procedure that contains the call), the called procedure can use the Rretpt register to access that word (which will be the word immediately preceding the return point) to get the size of the caller’s AR. So we change the two instructions, call and allocate, so that call has a second argument, the size of the AR in which it appears, and allocate uses the Rretpt contents to access that word to compute the top of stack when allocating its new AR. With these changes, there is no need to keep an explicit stacktop register.

4.3.4    Compiling Ground Facts

Often Prolog programs contain a number of ground facts, which are used to represent database knowledge. Consider how we can compile a ground fact, and how it will be executed.

Example 4.5 .

No allocate instruction is needed here. This is because there are no local variables, so no AR is required and the instructions work with data in registers or in existing ARs. The getcon instruction unifies its second argument with the contents of the register indicated in its first argument. That is, if the register contains the same constant, it is a no-op; if the register dereferences to a variable, that variable is assigned the given constant; otherwise, the operation fails. Until we consider how to handle nondeterminism, we can think of failure as being entire program failure; when we have nondeterminism, failure will trigger continued computation on an alternative path.

Note that execution of the code for a fact requires no overhead of AR processing. The return point address remains in the Rretpt register and is used from there to return after the data has been processed.

4.3.5    New Variables in the Body

Consider the following clause that is a minor extension of the clause above in that it has a new local variable Y in its body.

Example 4.6 .

The WAM code that implements this rule is an extension of the previous code to handle the extra variable. Y must be initialized to a variable before the call to p/3, and a reference to it must be loaded into R2 in preparation for the call to s/2.

The new putvar instruction handles the initialization of the local variable for Y (as a reference to itself,) and the putval instruction is used to load that value (which may have been changed by the execution of p/3) into register 2 in preparation for the call to s/2.

4.3.6    Temporary Variables

Not all variables in a clause require space in an AR. Consider, for example, the following clause.

Example 4.7 .

and its code:

On entry, R1 and R2 will contain values, and these values need to be passed to q/2 in those same registers. And when q/2 returns, this predicate immediately returns to its caller. So no handling of these values in R1 and R2 is required at all, and no local variables are required to save copies. All we do here is allocate an AR containing the fixed two register contents, call the sub-predicate (putting the length of the current AR, which is 2, in the instruction), and on return, deallocate that AR and return.

In fact, there is no need to allocate an AR for this predicate definition at all. We can compile it to the following.

Example 4.8

We introduce a new instruction, execute, which simply branches to the entry point of the indicated predicate. Now, no AR is allocated at all. This predicate, p/2, simply branches to the sub-predicate, q/2, which, when it returns, will return to p/2’s caller. (And if q/2 needs an activation record, it will access p/2’s caller’s call instruction directly to determine where to allocate it.) Use of the execute instruction here can be seen as a special case of a much more general optimization that will be discussed later in Section 4.6.

Consider the following minor variation on this clause.

Example 4.9 .

In this case, the arguments are permuted, so we will need instructions to carry out this permutation:

We introduce a new instruction, movreg, to copy the contents of one register to another, and use it to adjust the register contents as required for the sub-call to q/2. Again, note that no AR is required for this clause. The variables X and Y in this clause are called temporary variables since they need no place in an AR.

Another example introduces the gettval instruction for non-first-occurrence variables in the head.

Example 4.10 .

The gettval just unifies the contents of the registers. Note that the gettval instruction (with its variants) is the only instruction that does full unification. All the other get and put instructions know the value of one argument and so do special cases of unification.

Consider now, more generally, what properties of a variable are required in order for it to be temporary, i.e., not require space in an AR. Consider a minor variant of the preceding clause.

Example 4.11 .

In this case, Y is needed only for the call to q/2, but X is required for both the call to q/2 and the following call to r/1. We compile this as follows.

Space for X is required in the AR since it must be saved so that it can be loaded into R1 for the call to r/1, but Y does not need to be saved since it needs only to be passed to the first sub-call, q/2. We call Y a temporary variable.

The key property of a variable that allows us to make it temporary is that it appears in the head and in only the first subgoal of the rule body. It may need to be moved from one register, the register in which it was passed in, to another register, the register it is required to be in for the call to the first subgoal, but is not needed later in the clause; thus, it doesn’t need to be stored in the AR. (There will be some other situations calling for temporary variables, that is variables that do not need space in the AR, that we will encounter later.)

4.3.7    WAM Datalog Instruction Summary

We have seen many of the WAM instructions needed to manage the variables and their values for Datalog programs. Here we summarize and complete them.

Instructions for processing data in the heads of rules are “get” instructions, since they get data out of the registers, usually for storage in an AR for later use in the body. The first argument of a “get” instruction is a register indicating the parameter position of the variable, and thus the register that contains (i.e., dereferences to) the variable’s value; the second argument indicates the location of that variable in memory (or register) in which to put the value.

Instructions for processing data in the body of rules are “put” instructions, since they put data into registers in preparation for calling a sub-predicate. The first argument of a “put” instruction is a register that is the target of the data movement, and the second is a local variable (or register) that is the source of the data.

4.3.8    More Examples

Next, we give several examples that show a few more variable configurations.

Example 4.12 .

This predicate p/1 is essentially a no-op: it always succeeds without changing its argument. The variable X will unify with any argument passed in R1 without changing it, and there is no use of variable X anywhere. A single-occurrence variable in the head of a rule of a program is always a no-op and never needs any instruction.

Example 4.13 .

Here, Y is a single-use variable and needs no instruction, and X is temporary and already in the correct register for the call, so no data movement is required at all.

We now have seen how we can compile any (deterministic) Datalog program into WAM instructions.

4.4    Deterministic Prolog

As a full programming language, Prolog supports more complex data structures than the simple atoms and numbers of Datalog. Full Prolog supports complex term structures, which are made up of (nested) named records. In Prolog a variable may also have a (tagged pointer to a) record structure as a value. So we take another tag value to tag a pointer to a record structure. All named records are stored in another portion of memory, called the heap. A named record has an arity, which is the number of fields in the record. If the arity of a record is n, then an instance of that record is stored in n + 1 contiguous words in the heap: the first word indicates the name (and arity) of the record, and the following n words contain the values of the record’s subfields. Of course, a subfield of a record may contain (a pointer to) another record, so arbitrarily large trees can be constructed and used.

Example 4.14 Figure 4.5 shows the representation of the record: rec(aaa,33). The tags are indicated in the figure by s for structure pointer to a record, a for atom, and i for integer (here we assume the tag bits are taken from the integer, and so we can represent only integers using wordsize-tagsize bits.¹³) The top word in the run-stack (in the q AR) in the figure is a reference to the rec(aaa,33) record on the heap; the first word of the record points to some memory structure representing the rec/2 record symbol; the second word is tagged as an atom and points to the atom record for aaa; the third word is tagged as an integer and the word (with the tag bits shifted out) contains the integer value 33.

Figure 4.5    Memory representation of record rec(aaa,33).

The first word of a named record represents the name and arity. There are various choices for how this is represented. In our descriptions we will use name/arity (e.g., rec/2 for the above example) to express such a record name. We will assume that, in the machine representation, it is a pointer to a data structure that holds the name, arity, and any other information that might be required.¹⁴ These structures will be hashed (or otherwise indexed) so that a record name/arity pair is uniquely represented and record names/arities are the same if and only if their pointers are equal.

Example 4.15 Figure 4.6 shows a possible memory layout for the complex term f(X,g(11,aaa),22). In the figure the heap grows up. We indicate the reference tag by r. Note that records on the heap may contain variables and references to other variables. In this case the first word we show on the heap is a reference to a pointer to this complex term structure.

Recall that we ensured that all references from one variable to another in the ARs always pointed from shallower to deeper in the run-stack. The third word shown on the heap is a reference to the first word shown on the heap (which is itself a reference). The first field of the f/3 record is a variable, i.e., a reference to itself. Now that we may have variables and references also in the heap, we will ensure that all references between the run-stack and the heap point from the run-stack to the heap, and all references from heap to heap point from shallower to deeper into the heap. Maintaining these directions for the pointers ensures that there are no dangling pointers when sections of the run-stack and heap are deallocated.

The WAM treats the list constructor specially, since it is the most common record constructor in most Prolog programs. In Prolog the list constructor is ’.’/2. Instead of storing a list record in three fields, with an explicit word for the ’.’ constructor, the WAM uses another tag to indicate a pointer to a list record, and so needs to store only the two fields of the record.¹⁵

Figure 4.6    Memory representation of record f(X,g(11,aaa),22).

We next describe the additional WAM instructions needed to build and manipulate these record structures. We will need three new special registers in the machine: Rheaptop to point to the top of the heap so we know where we can allocate new records, Rmode to indicate the mode the processor is currently in, and Rsreg to point into a record as we traverse through it. The usage of these registers will be explained through the following examples.

Example 4.16 Consider a simple fact clause:

.

Remember that this clause can be called in different modes. For example, it might be called with a variable (i.e., R1 points to a variable), or it might be called with a complex term (i.e., R1 points to a record structure). In the first case the code we generate for that first argument must construct the desired record structure on the heap (and point the variable of R1 to it). In the second case, it must compare the existing structure on the heap, pointed to by R1, to the desired one. This requires some subtlety in the instructions that handle record structures.

The instructions we’ll generate for the fact p(f(a,b)) are the following.

The getstr instruction has two arguments: the register containing the argument (in this case the first argument and so R1) and the name of the record structure to be unified with it (here f/2).

If the register contains a variable (i.e., dereferences to a variable), the instruction pushes the record structure onto the heap, points that variable to that structure name (and thus to the record to be built), and sets Rmode to indicate “write” mode. “Write” mode indicates that a record is being constructed on the heap.

If the register contains a constant or a pointer to a record whose name is not the indicated one, the instruction fails.¹⁶

If the register contains a pointer to a record on the heap whose name/arity is the correct one, it sets register Rmode to “read” mode, and sets register Rsreg to point to the first subfield of that record. “Read” mode indicates that an existing record is being matched.

The unicon instructions behave differently depending on the contents of the Rmode register. If Rmode indicates write mode, the unicon instruction pushes its constant onto the heap. If Rmode indicates read mode, it unifies its argument with the value pointed to by the Rsreg register. That is, if that value is the same as its argument, it is a no-op; or if that value is a variable, that variable is set to be its argument; otherwise the unicon fails.

There are also univar, unival, unitvar, and unitval instructions that we will get to soon, but first consider a complex term in the body of a rule.

Example 4.17 .

The instructions we’ll generate for this clause are as follows.

Here we need to build the desired record structure on the heap and point R1 to it. The putstr pushes its record name onto the heap and sets its register to point to it. The bldcon instruction simply pushes its argument onto the heap. Notice that bldcon instruction is a special case of the unicon instruction, i.e., the unicon instruction in write mode.¹⁷

The instructions we have described handle only non-nested complex terms. E.g., our instructions can’t directly handle a fact like p(f(g(a,B),B)), since the term g(a,B) is nested inside the larger f/2 term. The WAM doesn’t have instructions to handle these directly. Instead they would be “flattened” and the flattened form would be compiled. This can be done by the compiler that generates the WAM instructions.

One can think of the above fact to be compiled as in the following example.

Example 4.18 .

The code could be:

Next consider a more complex example.

Example 4.19 .

Note that X can be a temporary variable because it does not need to be accessed after setting up the first call in the body of the clause. Y, however, must be stored in the AR so that it can be accessed after q/2 returns to set up the call to r/1.

The generated code is as follows.

Here we have introduced the unitvar, unitval, univar, and bldval instructions. In this clause, X is a temporary variable since it appears only in the head and first body subgoal, and R1 is used to store its value. We can do this since R1’s value is no longer needed after the getstr; and since X must be in R1 for the call to q/2, it’s good to put it there directly.

Figure 4.7(a) shows the WAM state at the point of a call to p(f(1,Z,W),g(1)); and Figure 4.7(b) shows the WAM state just before the sub-call to q(X,g(Y)).

Figure 4.8(a) shows the WAM state at the point of a call to p(Z,W) to this same predicate and Figure 4.8(b) shows the state of the WAM engine after this call at the point of calling q(X,g(Y)).

Recall that the WAM has a special representation for list records. It thus has special instructions for handling these records.

Figure 4.7    (a) Before call to p(f(1,Z,W),g(1)) and (b) before call to q(X,g(Y)).

Figure 4.8    (a) State just before call to p(Z,W) and (b) state before call to q(X,g(Y)).

Example 4.20 .

Clearly, this program (consisting of this one rule) is really rather useless: for any call it will either fail or go into an infinite loop. In order to be useful this predicate requires another clause—the base case of the recursive definition. And this requires that our machine handles nondeterminism, which we turn to next.

4.5    Nondeterministic Prolog

One of the main distinguishing features of Prolog is that it is a nondeterministic programming language. Up to this point, we have considered only deterministic Prolog programs, which are in fact extremely limited in their expressivity. Next, we consider how to add an implementation of nondeterminism.

Nondeterminism is expressed in Prolog by providing multiple definitions (or clauses) for a single predicate. In a deterministic language a second definition of a function would be considered either a redefinition or an error; in Prolog it is considered as an alternate possible definition of the predicate, and execution must explore all execution paths through all possible definitions. This is done by performing a depth-first, backtracking search through the possible execution paths.

The WAM uses a stack to save unexplored alternatives: when a predicate is called that has multiple clauses that define it, that “choice point” is pushed onto the stack, and when a computation fails, the topmost “choice point” on the stack is used to determine where to go back to in order to continue the computation.

The main implementation problem is to maintain a memory structure that supports the ability to save and restore the machine state when the current computation path fails and the state at an earlier choice point must be restored. In general, there are two basic methods that can be used in systems that need to be able to save and restore a state: (1) checkpointing, which saves the active state by copying it as necessary, and then restoring a checkpointed state by recopying the saved state back to the active state; and (2) logging, which logs changes made to the current state, and then restores an earlier state by processing the log backward to undo the changes made back to the desired point.

The WAM uses both of these techniques: a stack of checkpoints (called choice points in Prolog) is used to save the states of the required global machine registers and a stack of log records is used to save changes to the memory structures of the activation records in the run-stack and the record structures in the heap.

New registers are needed to manage these new data structures. Choice points are pushed onto the run-stack, and so are “interleaved” with ARs.¹⁸ A new register, RCP, points to the top choice point on the run-stack. A new memory structure, called the trail stack is used to store the log records, and a new register, Rtrail, is maintained to point to the top of the trail stack.

The choice point consists of the following fields:

NextClause

Entry point of next clause to execute

RCP

Address of previous CP on stack

RcurAR

Address of current Activation Record

Rtrail

Address of top of trail stack

Rheaptop

Address of top of heap

R1

Contents of general register 1

R2

Contents of general register 2

Rn

General register n, for n the arity of the entered predicate

The trail stack logs changes to the run-stack of ARs and to the heap. In the usual logging situation a log record must consist of a pair of values: (a) the address of the memory location that was changed and (b) the pre-image at that address, so that the memory location can be restored to its earlier value on backtracking, i.e., on state restoration. However, consider how Prolog memory values on the run-stack and heap can be changed. The only way a value can be changed is for it to have previously been a variable and subsequently become a value. Once it has become a value, it cannot be changed. So this means that the pre-state of every memory update is a variable, and a variable is represented as a pointer to its own address. So the Prolog log need contain only the addresses of changes; restoring the earlier state is done by restoring each logged address to be a variable, a pointer to itself. So the trail is simply a stack of addresses, addresses of local variables in the run-stack of ARs, or addresses of locations in the heap.

Given a choice point and the trail stack, the machine can restore the registers, the run-stack, and the heap back to their state at the time the choice point was saved. It uses the choice point to restore the machine registers, and the trail to restore the run-stack and heap.

4.5.1    Compiling for Nondeterminism

Consider the following definition of append/3, which consists of two clauses, as shown below.

Example 4.21 .

We need to introduce some new instructions to handle the processing of choice points. For this program we need trymeelse, which has two arguments: (1) the arity of the predicate to be entered (which is the number of general registers that need to be saved in the choice point) and (2) the address of the next clause to try in case of failure. We also need trustmeelsefail which just needs the arity of the predicate. Also, other instructions that change memory locations must be modified to include the logging (or trailing, in Prolog parlance) of memory changes to the trail stack. The code is as follows.

The deterministic code for each clause is just as before. We need only to add the trymeelse before the first clause, and the trustmeelsefail before the last clause. There is also a retrymeelse instruction, not needed in this example, that is used for all clauses except the first and last. The trymeelse instruction pushes a choice point onto the run-stack. The retrymeelse instruction restores the state using the top choice point on the stack, and updates the NextClause field of that choice point to point to the following clause. The trustmeelsefail instruction restores the state just as retrymeelse but also pops that top choice point from the stack (since there are no more alternative clauses to try). It does this by simply restoring the RCP register to its value in the choice point.

Again, note that all get- and uni-type instructions must be modified so that they trail any change they make to the run-stack or the heap.

The choice points are kept on the run-stack, interspersed with ARs. The top of the run-stack can be determined by comparing the contents of the RcurAR register (the pointer to the current AR on the run-stack) and the RCP (the pointer to the top choice point). Only the allocate instruction needs to have its function changed; now it finds the top of the stack by comparing those two registers and allocating the new AR either above the top AR (as before) or above the top choice point, depending on which is on top. The trymeelse instruction finds the place to allocate the new choice point in the same way.

The retrymeelse and retrymeelsefail instructions restore the machine to an earlier state, a state represented by a choice point. They do this by restoring the registers from the choice point and by running the trail backward from the current top (Rtrail) back to the value of Rtrail that is saved in the choice point. For each address in that portion of the trail, it restores the value at the trailed address to be the address itself (and thus represent a variable).

Note that now the current AR may not be on top of the stack; it may have a choice point above it and thus be “trapped.” Space is reclaimed in the runstack now in two ways: always when backtracking causes an earlier state to be reinstated, and sometimes when the allocation of a new AR is made over the AR of a previously returning last clause of a predicate. Note that there is no explicit action of reclaiming run-stack space; the allocation of a new AR or CP on the current “top” of the stack implicitly reclaims that space. Space in the heap is reclaimed when the Rheaptop register is restored to its value from a choice point.

The entries on the trail are created when get- and uni-type instructions change the values of locations in the run-stack or in the heap. So we must update the definitions of these instructions to push pointers onto the trail stack for those locations that they change. However, we notice that not all changes need to be trailed and can implement an optimization known as conditional trailing. If the change is to a location in an AR that is above the top choice point, then that change need not be trailed. This is because when backtracking occurs, the AR, and thus the location itself, will be deallocated. That is, that location wasn’t in the machine’s state space at the time of the most recent choice point, so there is no need to reset it. This can easily be determined by comparing the address of the location to be changed and RCP, the address of the top choice point. Similarly, if the location being changed is in the heap, but it is above what was the top of the heap at the time of the last choice point, then it also need not be trailed. This can be checked by comparing the address of the location to be changed to the Rheaptop value stored in the top choice point, since that was the top of the heap at the time of that choice point. Since this comparison is required at every heap location update, we want it to be very fast. To this end, the WAM has a new register, RCPheaptop, to contain this previous heap-top address. Its value is maintained by the try- retry- trust-type instructions, when choice points are saved and restored.

As an example, consider the “database” table and its WAM compilation in Example 4.22.

Example 4.22

4.6    Last Call Optimization

The WAM, as we have seen it thus far, is able to evaluate all (pure) Prolog programs. However for efficient execution in a language whose only looping construct is recursion, an important optimization is required: the last-call optimization. This is an optimization that allows the run-time system, in some cases, to deallocate an AR before the last call in the body of the rule, and change that last call instruction to an execute (i.e., a branch). Then the (formerly) called predicate will return directly to caller of the optimized predicate. This optimization can be done only if the current AR is the top one on the run-stack. Note that if the called predicate is the same predicate as the one that is optimized, this results in what is known as the tailrecursion optimization; it essentially turns recursion into iteration, and thus uses constant space.

The problem is to ensure that there is no reference to the current top AR when the machine is about to make the last call in the body of a clause. So, let’s look more closely at how there might be references into the current AR at that point. The only pointers into that AR must be in the general registers, which contain the values of the arguments to that last call. This is because, since it is the top AR on the run-stack, no pointers from other ARs can point into it (all pointers in the runstack point deeper), and no pointers from the heap can point into it (there are no pointers from the heap to the run-stack).¹⁹ If a general register has a non-variable value in it, it cannot point to the current AR. This is because constants would be directly in the register and references to records would be into the heap. So, we need only worry about how a register might contain a variable that is represented in the current AR.

Consider situations in which a variable is an argument of the last call. If the first occurrence of that variable is in the head of the rule, then if it does dereference to a variable, that variable will live in a deeper AR or on the heap. So such a variable is no problem. If the variable occurs only in the last call and as a subfield of a record, then it will live on the heap and there will be no problem. If it occurs only at the top-level and only in the last call (i.e., directly as an argument to the call, and not as a subfield of a complex term), then it would normally be in the AR. But we can avoid this happening by putting such a variable on the heap. So we will make the puttvar Ri,Rj instruction create a new variable on the heap and point Ri and Rj to that variable. Then we use this instruction for top-level first occurrences of variables whose first occurrence is in the last call. So with this change, variables whose first occurrences are in the head and variables whose first occurrences are in the last call are handled. None of these variables will be in the current AR at the time of the call to the last goal of a rule.

That leaves us with variables whose first occurrence is top-level in some body subgoal before the last call. That variable was initialized to a variable by a putvar instruction when it was passed to that called predicate in which it first appears. It’s possible (probably even probable) that the called predicate bound it to a nonvariable value, in which case there is no problem. But it is possible that the called predicate left it as a variable and so the general register about to be passed to the last call will contain a pointer to that variable. This is called an “unsafe variable” and it occurs when (a) all occurrences of a variable are at the top level, (b) the first occurrence is in a body subgoal that is not the last subgoal, and (c) it also occurs in the last subgoal. In this case, it is possible that it is still a variable in that AR at the time of the last call, and if allowed to stand, this would keep us from being able to deallocate that AR. The solution is to introduce a new instruction and, instead of generating a putval instruction to load a reference to that unsafe variable into its general register in preparation for that last call, we use the new putuval instruction with the same arguments. This instruction checks to see whether the value being loaded dereferences to a variable in the current AR, and if it does, it allocates a new variable on the heap, points that variable to that new heap variable and points the register to the new heap variable. This is called “globalizing” the variable. With this change, we can be assured that, at the point of the last call after the registers are loaded with the values of its arguments, there are no references into the current AR and it can be deallocated.

The last-call optimization is a generalization of what is commonly known as the tail recursion optimization, which applies when the last call is a recursive call to the head predicate. It should be noted that only if the AR of the predicate is on the top of the stack will its space be reclaimed. If it is trapped by a choice point, then it will not be reclaimed. For this reason (among others) it is generally desirable for a Prolog programmer to put recursive clauses for a predicate after non-recursive clauses.

4.6.1    Another Type of Variable

We saw above that some variables in a clause do not need locations in the AR, but can be handled with registers. Another example of a variable that can be temporary is a variable that occurs in only one subgoal in the body of a rule. If it occurs as a subfield of a record, then it will be built on the heap in its record and we can use a register to refer to it; if it occurs only at the top level, then we allocate it a location and so it appears in the AR.

4.7    Indexing

In order to evaluate Prolog programs efficiently, it is important, when calling a predicate, to quickly exclude clauses that cannot match. For example, consider a call of emp(‘Emily’,N) to the definition of emp/2 given in Example 4.22 above. The current compilation of emp/2 requires that every clause be tried, even though only the last clause will succeed. With our current WAM instructions, every clause of a predicate will be executed for every call to that predicate. With only 5 clauses in emp/2 the overhead may not be great, but if we have 10,000 employees, the inefficiency would be unacceptable. So the WAM has special instructions to support “indexing”, i.e., the quick selection of those clauses that might match a given call.

The original WAM suggested three indexing instructions: switch_on_type, switch_on_constant, and switch_on_structure.

The switch_on_type instruction takes three program address arguments, and examines the value in general register 1; if the value is a variable, the instruction is a no-op; if the value is a constant, a jump is made to the first program address; if the value is a (non-empty) list, a jump is made to the second program address; if the value is a (non-list) structure, a jump is made to the third program address. This instruction is very useful for predicates that use structural recursion over lists. Consider an improved compilation for our friend append/3:

Example 4.23 .

Now on entry to append/3, the switch_on_type instruction checks the first argument, and if it is bound, it branches to the code for the appropriate clause (or fails if it is called with some structure that is not a list). If the first argument to append/3 is a variable, then the switch is a no-op and the code works exactly as before, laying down a choice point to try both clauses. Note that if the first argument is a (fully instantiated) list, then no choice points are laid down at all, and this is completely deterministic code. We note that it is also tail recursive, so it uses only constant space on the run-stack, regardless of the length of the list. (Of course it does use space on the heap that is linear in the length of the first list.)

The switch_on_constant instruction has one argument that is a pointer to a hash table that associates constants to program addresses. This instruction tests if the value in general register 1 is a constant: if not, it is a no-op; if so, it looks up the constant in register 1 in the hash table and if found, it branches to the associated program location; if it is not found, it fails. This instruction would be used to compile the emp/2 predicate above, and would provide direct access (through the hash table) to the last clause for a call of emp(‘Emily’,X). Note that here again, no choice point would need to be saved (assuming no hash collisions). In fact, the avoidance of saving choice points and the consequent effect of much more deterministic programs is a very important aspect of indexing.

The switch_on_structure instruction is used in a similar fashion, when there are a set of clauses whose first arguments are record structures. These instructions support indexing only on the first argument of a call and only on the main structure symbol of that argument. Many implementations of the WAM provide more extensive indexing instructions. One very simple extension is to add an argument to the indexing instructions to indicate which general register’s value is to be used. In this way any argument to a predicate call can be used for indexing.

4.8    Environment Trimming

Recall that the WAM call instruction has an extra argument to indicate the size of the AR that the calling predicate requires, and this argument is used by the allocate (and trymeelse) when allocating a new AR (or choice point). This allowed us to eliminate the top-of-stack pointer, and to delay (and sometimes avoid) the allocation of ARs. But it does require that every call instruction in the body of a clause has this extra word to contain the same AR size. We can take advantage of this “redundancy” by noticing that we could in principle have different values for the AR size in different call instructions within the same predicate. We can order the local variables in such a way that the ones needed for the later calls are located earlier in the AR than the ones needed for the first calls. Then later calls can have smaller AR sizes, when local variables no longer are required. Consider the following simple example.

Example 4.24 .

We can order the variables in the AR as follows.

X is a temporary variable and does not need an AR location. We would like the calls to be as follows.

All the local variables are needed when the first call, call q/2,6, returns, so the AR size at this point is 6. But when the call to r/2 returns, we no longer need variable A, and so we can trim the AR to be of size 5. And so on. We want to delete these local variables as we go along since we will not be needing them. However, there is a complication: other code may need them. For example, when we call r/2, we will have in R1 the value for variable A, and it is possible that A is still a variable and R1 contains a pointer to A in the local AR. So even though we no longer need to access A, others will use R1 to access it. So it is not safe to eliminate it from the AR. But we encountered exactly this same issue before: when we considered the last-call optimization. The solution here is the same as there: we use a putuval instruction to load R1 with the value of A for the call to r/2. The putuval instruction will ensure that R1 does not point into the local AR, moving the variable A to the heap if necessary. So if we use putuval instructions to load A, B, and C for their “last calls”, we ensure that they are no longer needed in the AR and we can trim the AR, as shown in the example.

Most implementations of the WAM do not do environment trimming. The overhead of the putuval instructions is deemed to outweigh the minor decrease in run-stack size. Another possible advantage of environment trimming might be during garbage collection to know that some variables are not accessible, but other techniques are now generally used for determining live variables.

4.9    Features Required for Full Prolog

We have completed the tutorial on our WAM that includes the features described by Warren [1983].²⁰ And the functionality supported is essentially what is known as “pure” Prolog, i.e., SLD theorem proving with all rules provided. But Prolog, the programming language, provides many extensions, such as the cut operation, arithmetic operations, I/O operations, assert and retract, and various other features. A full implementation of Prolog must support all this additional functionality. We will here briefly mention some of the issues involved in adding some of this functionality.

The cut operation removes choice points from the backtracking chain rooted by RCP. One way to implement cut is to add an instruction to save the address of the current top choice point (in RCP) into a variable, and an instruction to reset the RCP from a variable. These instructions can be used to implement cut. At the beginning of the scope of a cut, the current RCP value can be saved in a variable, and at the ending scope of the cut (the actual appearance of the cut) the reset RCP instruction can be used.

I/O, arithmetic, and other operations can be implemented as “builtins”, which are implemented through a general interface to routines written in the base language in which the WAM virtual machine emulator is coded. We can build a general interface from the WAM engine to (and from) such routines and use that interface to implement all necessary builtins. One natural way to do this is to create one new WAM instruction, say builtin, which takes an integer argument and dispatches on that integer to execute arbitrary code. Arguments to the builtin can be put in general registers, just as for Prolog predicate calls, and the code for each particular builtin can take its arguments from those registers and return its results by binding variables passed into it. Some particularly common and simple builtins, such as the tag tests of integer/1, var/1, etc., might deserve their own new WAM instructions.

Prolog allows the programmer to modify the program during execution by means of the operations of assert/1 and retract/1. Most current Prologs distinguish between static predicates, which are defined by clauses which cannot be changed during execution, and dynamic predicates, which are defined by clauses that can be changed (added or deleted) at run-time by assert/1 and retract/1. There are a variety of ways that assert/1 can be implemented, from simply storing the terms representing the clauses and interpreting them on execution, to compiling the clauses at run-time into WAM code and then executing them with the emulator, just as static code.

4.10  WAM Extensions for Tabling

An extension to Prolog, not contemplated in the WAM, but coming to be recognized as important in Prolog implementations is Tabling. A tabling facility allows a Prolog programmer to indicate that a particular predicate should have its calls and answers remembered in a table, so any equivalent call after the first one can use the tabled answers and avoid reexecuting the predicate. This idea also goes by the name of “memo-ization” [Michie 1968]. In the nondeterministic context of Prolog, this technique has profound implications: it causes many programs to terminate that would otherwise go into infinite loops under simple Prolog evaluation. For example, all Datalog programs terminate, in particular all finite graph traversal programs.

Extending the WAM to support tabling is nontrivial. We will here just briefly mention some of the issues that are important in an efficient implementation.

•  Because tabled predicates can be recursive and nondeterministic, the simple depth-first evaluation strategy of Prolog is not in general sufficient to generate all answers. So a more complicated memory management framework is required that allows for more earlier memory states than in the WAM to be reconstructed; a simple stack is not sufficient.

•  The efficiency of the goal look-up and addition operations on the tables is critical. A good data structure for this is a variant of the trie which handles general Prolog terms.

•  To have reasonable memory usage it is very important to be able to determine when all answers to a goal have been computed, and so memory allocated to that end can be reclaimed. This can be done by careful attention to the strategy for scheduling goals and the use of a completion stack.

We refer the interested reader to papers devoted to the implementation of tabling in Prolog [Sagonas et al. 2000, Demoen and Sagonas 1999, Zhou et al. 2000].

4.11  Concluding Remarks

We have described (our version/variant of) the architecture of the WAM, a virtual machine for executing Prolog programs, designed by David H. D. Warren. The development built on standard compiler implementation concepts, modified to apply to the unusual aspects of Prolog: logical (or assign-once) variables and nondeterminism. We started by seeing how to implement very simple Prolog (or Datalog) programs and progressed through a series of examples that incrementally introduced more complex features. After describing the basic implementation, we discussed various optimizations that improved the time and space execution of programs.

The 2012 special issue of the journal Theory and Practice of Logic Programming on Prolog Systems describes a number of Prolog systems actively under development. David H. D. Warren, in his original tech report, acknowledges David Bowen, Lawrence Byrd, and William Clocksin for precursor designs that he drew on for the WAM. There have been many additions, extensions, and modifications to the WAM since its original proposal. Its performance has been well studied. Contributors to this effort are too many to mention, but particularly noteworthy are Peter Van Roy [Van Roy 1990, Van Roy and Despain 1992, Van Roy 1994] and Bart Demoen [Demoen and Nguyen 2000, Janssens et al. 1988, Mariën and Demoen 1991, Demoen et al. 2002].

The WAM is a wonderful piece of virtual machine architecture. I’ve worked with it for over 30 years now and am still impressed with its elegance. Although it now happens rarely, there were many years when I would suddenly realize a new advantage of some particular design decision. For example, the use of a self-pointer to represent a variable allows a value of any type to be copied simply by copying the word that represents it, in particular moving a variable is just copying a word. Also, I find particularly elegant the elimination of a stack-top pointer for the run-stack, and the execution of a fact as not requiring any AR processing at all. The elegance of the mapping that the WAM defines between logic (SLD resolution theorem proving) and computation (the von Neumann computer architecture) continues to amaze me.

My own personal research history has been greatly affected by my study of (and fascination with) the WAM. Most of my research has revolved around the concept of tabling in logic programming. I had discovered and briefly developed the idea of tabling in a nondeterministic programming language (not Prolog) in my Ph.D. thesis a couple of years before I stumbled onto Prolog and the WAM, and became enamored of it. Then several years later research in the database community on deductive databases convinced me that tabling was an important idea that deserved a serious, low-level implementation. At that point my earlier study (and implementation) of the WAM convinced me that I was in the perfect position to be able to extend it to support an efficient implementation of tabling in Prolog. This led me to undertake (with the invaluable help of my students) the implementation of the XSB system, which indeed turned out to be several times faster than other implementations of similar technology at the time. XSB is still, 25 years later, an important programming language system that continues to have far-reaching impact on logic programming.

Acknowledgments

I would like to thank the following people for their contributions to this work: The reviewers gave particularly helpful feedback on the first draft of this tutorial chapter, which resulted (I hope) in significant improvements; Bart Demoen, from whom I’ve learned most of what I know about various WAM tradeoffs (and all I know about WAM garbage collection); and all my students over the years, who have contributed their insights and elbow grease to our XSB-Prolog implementations, and who have given me much more than I could ever adequately acknowledge.

References

A. V. Aho, M. S. Lam, R. Sethi, and J. D. Ullman. 1986. Compilers: Principles, Techniques, and Tools. Addison-Wesley. 238

H. Ait-Kaci. August 1991. Warren’s Abstract Machine: A Tutorial Reconstruction. MIT Press. Out of print; available from http:wambook.sourceforge.net. 237

B. Demoen and P.-L. Nguyen. 2000. So many WAM variations, so little time. Computational Logic—CL 2000, pp. 1240–1254. DOI: 10.1007/3-540-44957-4_83. 276

B. Demoen and K. Sagonas. January 1999. Chat: the copy-hybrid approach to tabling. In G. Gupta, editor, LNCS number 1551, Practical Aspects of Declarative Languages (PADL), pp. 106–121. Springer, San Antonio, TX. DOI: 10.1007/3-540-49201-1_8. 275

B. Demoen, P.-L. Nguyen, and R. Vandeginste. 2002. Copying garbage collection for the WAM: To mark or not to mark? Logic Programming, pp. 297–321. DOI: 10.1007/3-540-45619-8_14. 276

G. Janssens, B. Demoen, and A. Mariën. Aug. 1988. Improving the register allocation in WAM by reordering unification. In International Conference and Symposium on Logic Programming, pp. 1388–1402. 276

A. Mariën and B. Demoen. 1991. A new scheme for unification in WAM. In Logic Programming: Proceedings of the 1991 International Symposium. Citeseer. 276

D. Michie. 1968. Memo functions and machine learning. Nature, 218: 19–22. DOI: 10.1038/218019a0. 275

K. Sagonas, T. Swift, and D. S. Warren. September 2000. An abstract machine for efficiently computing queries to well-founded models. Journal of Logic Programming, 45(1–3): 1–41. DOI: 10.1016/S0743-1066(00)00005-4. 275

E. Tick and D. H. D. Warren. February 1984. Towards a pipelined Prolog processor. In Proceedings of the Internationsl Symposium on Logic Programming, pp. 29–40. IEEE Computer Society, Atlantic City, NJ. DOI: 10.1007/BF03037325. 237

P. Van Roy. 1994. 1983-1993: The wonder years of sequential Prolog implementation. The Journal of Logic Programming, 19: 385–441. DOI: 10.1016/0743-1066(94)90031-0. 276

P. Van Roy and A. M. Despain. 1992. High-performance logic programming with the Aquarius Prolog compiler. Computer, 25(1): 54–68. DOI: 10.1109/2.108055. 276

P. L. Van Roy. 1990. Can logic programming execute as fast as imperative programming? PhD thesis, University of California at Berkeley, Berkeley, CA. 276

D. H. D. Warren. October 1983. An abstract Prolog instruction set. Technical Report 309, SRI, International. 237, 238, 273

D. S. Warren. Mar 1984. The runtime environment for a Prolog compiler using a copy algorithm. Technical report, Department of Computer Science, University at Stony Brook, NY. Major revision of TR#83/052. 238

N.-F. Zhou, Y.-D. Shen, L.-Y. Yuan, and J.-H. You. January 2000. Implementation of a linear tabling mechanism. In E. Pontelli and V. S. Costa, eds., LNCS, Practical Aspects of Declarative Languages (PADL), pp. 109–123. Springer, Boston, MA. DOI: 10.1007/3-540-46584-7_8. 275

1. The original design by D. H. D. Warren was intended to be implemented in VAX microcode, but it has been mostly implemented through a WAM emulator written in C (or other procedural language).

2. There are many, many good textbooks on compiler technology. See the classic by Aho et al. [1986].

3. The name WAM for Warren Abstract Machine is somewhat of a misnomer, since it is really not “abstract.” But WVM isn’t very pronounceable, and WAM has stuck. I should note that David H. D. Warren did not refer to his invention as the WAM.

4. Activation records are sometimes call “environments” and the run-stack the “environment stack.”

5. The typing is somewhat loose here, in that we assume that the AR for a particular procedure has exactly the local variables needed for that procedure. To make this a type-correct C program, we would have to use a union type, but that is overly complicated, and not necessary, for our considerations here.

6. For some parameter passing conventions code might be needed also at the point of call after a return is made. We won’t need such code for the WAM’s parameter passing conventions.

7. Notice that these intermediate instructions are generic for some procedural programming language. We will later see their WAM code versions.

8. One might even get away with only 2 bits, to tag for (a) reference, (b) record reference, (c) integer, and (d) float. But most Prologs seem to want a few more, and so take 3 bits, which is still relatively few. Of course, one can use fewer tag bits by increasing the amount of indirection.

9. When we later consider nondeterministic programs, we will see that backtracking can unset a variable.

10. The reader might want to consider why this may be a better representation than, say, using a constant 0 value.

11. Use of the word “variable” can be confusing. A variable in a programming language can have a value or not yet have a value. In logic, a variable is a syntactic entity that doesn’t “have a value;” it is a kind of “place-holder.” In Prolog we sometimes use the terms “free variable” and “bound variable” to mean a variable that does not have a value and a variable that has gotten a value, respectively. These terms refer to very different concepts in formal logic.

12. If you wonder why there are two WAM instructions here instead of just one, stay tuned.

13. Most Prolog implementations also support full word-sized integers and floats. This can be done with special “boxing” representations, using perhaps specialized complex terms to represent data types requiring more bits. Many Prologs support arbitrary precision numbers.

14. Some Prologs, instead of a pointer, use bits in the word to represent both the arity of the structure symbol, and an index into a table of structure symbol atoms.

15. Demoen has done work that shows that the performance improvement of this optimization is quite minimal and perhaps not worth the extra tag and code complexity.

16. At this point, until we consider nondeterminism, we consider that to fail is to abort execution.

17. Indeed in the original WAM described by D.H.D. Warren, the putstr instruction set the Rmode register to write mode, and then unicon instructions would be used here. He did not have bldcon instructions.

18. Some variants of the WAM use a separate stack for the choice points.

19. There may be a pointer from that top AR into that same AR, but without a pointer from a register into the AR, it could not be accessed.

20. We note that we have not covered special processing of anonymous variables that was included in the original WAM.

5

Predicate Logic as a Modeling Language: The IDP System

Broes De Cat, Bart Bogaerts, Maurice Bruynooghe, Gerda Janssens, Marc Denecker

5.1    Introduction

Since the early days of artificial intelligence, it has been believed that logic could bring important benefits in solving computational problems and tasks compared to standard programming languages. Kowalski’s seminal paper “Predicate Logic as a Programming Language” [Kowalski 1974] was a major step in this direction and laid the foundations for the field of logic programming. It introduced two fundamental ideas: on the declarative level, the use of the Horn clause logic fragment of classical logic; on the procedural level, a procedural interpretation of this logic which made it possible to write algorithms in the formalism. With the technology of the time, Kowalski’s paper was a breakthrough for the use of logic in computer science.

Since then, logic programming has fanned out in many directions, but in most extensions and variants, the original key ideas are still present in a stronger or weaker form: the use of a rule-based formalism, and the presence of a procedural interpretation. Or, at least, if programs are not procedures, they are representations of computational problems, as in Datalog and in Answer Set programming.

In this chapter, we present the IDP system (and language) that, although it builds on the accomplishments of logic programming and contains language constructs based on logic programming, embodies a more pure view of logic as a modeling language. In this view, a logic theory is not a program, it cannot be executed or run; it does not describe an algorithm. A theory, in principle, is not even a specification of a problem. A theory is a bag of information, a description of possible states of affairs of the domain of discourse, a representation of knowledge, or, in other words, a modeling of the domain of discourse. As such, this view breaks the link that Kowalski had laid between logic and programming. On the other hand, the IDP language contains a language construct, namely inductive definition, that directly descends from logic programming, and the IDP system is designed to use declarative information to solve problems and uses many technologies that were developed in logic programming. As such, the IDP language and system preserve some of the contributions of logic programming but break with some of the fundamental ideas of logic programming.

Table 5.1    Prolog answers “yes” to the query?– Female(Jane).

To explain the IDP language, we need to go back to the early days of logic programming when negation as failure was introduced. On the one hand, conclusions obtained with the negation as failure inference rule were often natural and as desired. This is illustrated by the program and query in Table 5.1. On the other hand, these answers were logically unsound if rules were interpreted as material implications.¹ This problem disturbed the logic programming community for more than a decade and led to the development of stable and well-founded semantics [Gelfond and Lifschitz 1988, Van Gelder et al. 1991]. However, a formal semantics still does not explain the intuition that humans attach to such programs. For that, we need to study the informal semantics of the logic. So far, two informal semantics have been proposed that can explain the intuitive meaning of logic programs. One is the view of logic programs under stable semantics [Gelfond and Lifschitz 1988] as a non-monotonic logic closely related to default logic and autoepistemic reasoning developed by Gelfond and Lifschitz [Gelfond and Lifschitz 1991]. The second is the view of logic programs as definitions of concepts. This view was implicit already in Clark’s work [Clark 1978] on completion semantics and in the work by Van Gelder and colleagues [Van Gelder et al. 1991, Van Gelder 1993] on the well-founded semantics. It was elaborated later in a series of papers by Denecker and colleagues [Denecker 1998, Denecker et al. 2001, Denecker and Vennekens 2014].

The informal concept of definition (as found in scientific texts) has several interesting aspects. First, it is a rule-based linguistic concept of informal language: definitions, certainly inductive ones, are commonly phrased as conditionals or sets of these. Second, definitions are second nature to us. Much human knowledge is of a definitional nature; this includes inductive and recursive definitions.² Many familiar recursive logic programs are obviously representations of inductive definitions (e.g., the member, append, and transitive closure programs). Third, definitions are of mathematical precision: they are the building blocks of formal mathematical theories. Fourth, it is a well-known consequence of the compactness theorem that definitions, in particular inductive ones, cannot, in general, be correctly expressed in classical first-order logic. Fifth, recently [Denecker and Vennekens 2014], it was shown that rule sets under two-valued well-founded semantics correctly formalize all main sorts of informal definitions that we find in scientific text in the sense that the interpretation of the defined symbols in the well-founded model of a rule set always coincides with the set defined by the informal definition represented by the rule set. All these are solid arguments that the concept of definition is a good candidate for the informal semantics of logic programming. Furthermore, they suggest defining a rule-based logic construct under the well-founded semantics for expressing definitions. Importantly, given that this form of information cannot be expressed in classical logic, it makes sense to add such a construct to classical logic. This idea was carried out for the first time in Denecker [2000], leading to the logic FO(ID) that forms the basis of the IDP language. Given that logic programs were originally seen as a fragment of classical logic, the definition of this logic was certainly a remarkable turn of events.

A definition is a piece of information. It lays a strict, precise, deterministic logical relationship between the defined concept and the concepts in terms of which it is defined. For example, the definition of transitive closure of a graph specifies a logical relationship between the transitive closure relation and the graph. A definition, like all other language constructs in IDP theories, is not a procedure, it cannot be run, it does not specify a problem. It is a kind of declarative information.

The following question now naturally arises: If IDP theories are not programs, how can they be used to solve computational problems? The IDP system, which supports the IDP language, is conceived as a knowledge base system (KBS) [Denecker and Vennekens 2008]. The scientific working hypothesis underlying the knowledge base paradigm is that many computational problems can be solved by applying some form of inference to a specification of information of the problem domain. A KBS essentially consists of two parts: (1) a formal declarative knowledge representation language, and (2) a number of powerful and generic inference methods to solve a broad class of tasks using a knowledge base.

The paradigm is inspired by several observations. First, imperative programming languages allow the direct encoding of specialized algorithms, but knowledge about the problem domain is hidden deep within those algorithms. This facilitates high-performance solutions, but makes debugging and maintenance very difficult. Second, a program is typically written to perform one task and perform it well, but cannot handle many related tasks based on the same knowledge. Third, knowledge representation languages excel at representing knowledge in a natural, human-understandable format. Programming language designers are starting to realize this and provide constructs to express generic knowledge, such as the LINQ [Pialorsi and Russo 2007] data queries in C# and annotation-driven configuration [Deinum et al. 2014]. Lastly, the above-mentioned progress in automated reasoning techniques facilitates the shift of the control burden from programmer to inference engine ever more. The knowledge base paradigm is an answer to these observations: application knowledge is modeled in a high-level knowledge representation (KR) language and state-of-the-art inference methods are applied to reason on the modeled knowledge. It has also been demonstrated that, while the KBS approach cannot yet compete with highly tuned algorithms, the effort to reach an acceptable solution (w.r.t. computing time or solution optimality) can be much smaller than that to develop an algorithmic solution [Gebser et al. 2012a, Bruynooghe et al. 2015]. Furthermore, the declarative approach results in software that is less error-prone and more maintainable.

The IDP system is a state-of-the art KBS. The system is already in existence for several years, but only recently evolved into a KBS. Until 2012, IDP was a model expansion system (the IDP2 system)³ capable of representing knowledge in a rich extension of first-order log (FO) and performing model expansion by applying its grounder GidL and its solver MiniSAT(ID). Recently, we have extended it into the IDP knowledge base framework for general knowledge representation and reasoning (referred to as IDP3); the earlier technology is reused for its model expansion inference. The IDP system goes beyond the KBS paradigm: for a KBS to be truly applicable in practical software engineering domains, it needs to provide an imperative programming interface; see De Pooter et al. [2011]. Such an interface, in which logical components are first-class citizens, allows users to handle input and output (e.g., to a physical database), to modify logical objects in a procedural way and to combine multiple inference methods to solve more involved tasks. In this chapter, we use KBS to refer to a three-tier architecture consisting of language, inference methods, and procedural integration. The IDP system provides such a procedural integration through the scripting language Lua [Ierusalimschy et al. 1996]. The system’s name IDP—Imperative-Declarative Programming–also refers to this paradigm.

In the work revolving around IDP, we can distinguish between the knowledge representation language and the state-of-the-art inference engines. One can naturally model diverse application domains in the IDP language; this contrasts with many approaches that encode knowledge such that a specific inference task becomes efficient. Furthermore, reuse of knowledge is central. The IDP language is modular and provides fine-grained management of logic components, e.g., it supports namespaces. The implementation of the inference engines provided by IDP aims at the reuse of similar functionality (see Section 5.6). This has two important advantages: (i) improvement of one inference engine (e.g., due to progress in one field of research) immediately has a beneficial effect on other engines; and (ii) once “generic” functionality is available, it becomes easy to add new inference engines. To lower the bar for modelers, we aim at reducing the importance of clever modeling on the performance of the inference engines. Several techniques, such as grounding with bounds [Wittocx et al. 2010], function detection [De Cat and Bruynooghe 2013], automated translation to the most suitable solving paradigm [De Cat et al. 2013], and automated symmetry breaking [Devriendt et al. 2012] have been devised to reduce the need for an expert modeler.

The rest of the chapter is structured as follows. In Section 5.2, we present the syntax and semantics of FO(ID, AGG, PF, T), the logic underlying the system. In Section 5.3 we present a high-level overview of the IDP system. In Section 5.4, we present the IDP language, a user-friendly syntax for FO(ID, AGG, PF, T) language components, and procedural control. We present advanced language features and inference methods in Section 5.5. In Section 5.6, we focus on the inner working of some components of the IDP system. More specifically, we describe the workflow of the optimization inference and how users can control the various parts of the optimization engine. Applications, tools and performance are discussed in Section 5.7, followed by related work and a conclusion. In the rest of the chapter, we use IDP to refer to the current (2018), knowledge base version of the system.

This chapter is a tribute to David S. Warren. The XSB Prolog system [Chen and Warren 1996] by David S. Warren and his students was the first to support the well-founded semantics and was a milestone in closing the gap between the procedural semantics of the SLDNF proof procedure [Lloyd 1987] and the intuitive declarative semantics of logic programs as formalized by the well-founded semantics. In fact, XSB is used internally in the IDP system. In a personal communication, David once told the authors of this chapter that when he learned about FO(ID) and the IDP system, he was less than thrilled; specifically, he found it “a crazy idea”. It is with great satisfaction and gratitude that we have noticed that he changed his mind as can be seen in his LinkedIn editorial that is devoted to the IDP language [Warren 2014]. It is therefore a great pleasure to contribute this chapter in a book that was initiated to honor his 65th birthday.

5.2    FO(ID, AGG, PF, T), the Formal Base Language

In this section, we introduce the logic that is the basis of the IDP language. This logic, FO(ID, AGG, PF, T), is an extension of first-order logic (FO) with inductive definitions, aggregates, partial functions, and types.

5.2.1    First-Order Logic

A vocabulary Σ consists of a set of predicate and function symbols, each with an associated arity, the number of arguments they take. We sometimes use P/n (f/n) to denote the predicate symbol P (function symbol f) with arity n.

A term is a variable or an n-ary function symbol applied to n terms. An atom is an n-ary predicate symbol applied to n terms. An atom is a formula; if φ and φ′ are formulas and x is a variable, then ¬ϕ, φ ∧ φ′, φ ∨ φ′, ∀x : φ, and ∃x : φ are also formulas. The expressions φ ⇒ φ′, φ ⇐ φ′, and φ ⇔ φ′ are (as usual) shorthands for ¬φ ∨ φ′, φ ∨ ¬φ′, and (¬φ ∨ φ′) ∧ (φ ∨ ¬φ′), respectively. A literal (often denoted l) is an atom a or its negation ¬a. A sentence is a formula without free (unquantified) variables. A theory T over a vocabulary Σ consists of a set of sentences with symbols in Σ. A term t containing occurrences of a term t′ is denoted as t [t′]; the replacement of t′ in t by t″ is denoted as t [t′/t″] (similarly for formulas).

A two-valued structure (in the literature, sometimes also referred to as an interpretation) I over a vocabulary Σ consists of a domain D and an interpretation for all symbols in Σ; we use sI to refer to the interpretation of a symbol s in I. A two-valued interpretation PI of a predicate symbol P/n is a subset of Dn; a two-valued interpretation fI for a function symbol f/n is a mapping Dn → D. The latter mapping can also be represented by a subset of Dn+1 in which there is a functional dependency from the first n arguments to the last one. Given a domain D, a domain atom is a tuple (P, d̄) where P is an n-ary predicate symbol and d̄ ∈ Dn is an n-tuple of domain elements. Sometimes, we abuse notation and write a domain atom as P(d̄).

While the domain of standard FO is unordered, it is often convenient to assume that there is a total order of the set of all domain elements and that a vocabulary includes, by default, the binary comparison predicates =/2, ≠/2, </2, >/2, ≥/2, and ≤/2; their interpretation is fixed in accordance with the total order.

By evaluating a term or formula in a structure I, we obtain its value. The value of a term is a domain element, the value of a formula is a truth value, either true, denoted t, or false, denoted f, hence an element of the set {t, f}. The value of a term t, denoted as tI, is d if t is of the form f (t̄) and fI (t̄I) = d. The value P (t̄)I of an atom P (t̄) in I is t if t̄I ∈ PI and f otherwise. We define (ϕ ∧ φ′)I = t if φI = φ′I = t, φ ∨ φ′I = t if either φI = t or φ′I = t, ¬φI = t if φI = f ; (∀x : φ)I = t if (φ[x/d])I = t for all d ∈ D, (∃x : φ)I = t if (φ[x/d])I = t for at least one d ∈ D. In the two quantified forms, the replacement of x by d in φ means that x is interpreted as d when deriving the value of φ in I. We say a two-valued structure I is a model of a formula φ or I satisfies φ, denoted as , if φI = t. Given two tuples t̄ = (t₁, …, tn) and of terms of equal length n, t̄ = t̄′ denotes the conjunction . For vocabularies Σ and Σ’ with Σ′ ⊇ Σ and a structure I over Σ′, I|Σ denotes the restriction of I to the symbols in Σ.

Unless the context specifies it differently, φ denotes a formula, t a term, D a domain, I a two-valued structure, I a partial structure (introduced below), d a domain element, x and y variables, and ∼ any comparison predicate.

Sometimes it is convenient to use true and false as atoms in a formula. Therefore, we include them as nullary predicates in every vocabulary. In every structure I, true is interpreted as {()}, i.e., as the set containing only the empty tuple; hence, trueI = t, and false is interpreted as the empty set ∅, i.e., falseI = f.

Partial Structures. A typical problem-solving setting is that of model expansion [Mitchell and Ternovska 2005] where one has partial knowledge about a structure and where the goal is to expand this partial information into a structure that is a model of the given theory. Hence we also use partial structures. A partial structure over a vocabulary Σ consists of a domain D, and a partial interpretation I of the symbols in Σ. With sI, we refer to the interpretation of a symbol s in a partial structure I.

Whereas the two-valued interpretation of a predicate P/n was defined as a subset of Dn, it can as well be defined as a mapping from Dn to the set {t, f}. The latter form is better suited for generalization. The partial interpretation of a predicate P/n is defined as a mapping from Dn to the set {t, f, u}, with u standing for “unknown”. This mapping partitions Dn in the set of true tuples, denoted (here ct stands for certainly true), the set of false tuples, denoted (cf stands for certainly false), and the set of unknown tuples, denoted . Note that two of these sets fully determine the partial interpretation of P.

Whereas the two-valued interpretation of a term is a single domain element, this is no longer the case for a partial interpretation. The partial interpretation of a function f/n is as a mapping from Dn+1 to {t, f, u}. As for predicates, we can distinguish true tuples , false tuples , and unknown tuples . While a functional dependency holds in the set , this is not the case for the latter two sets. However, iff for all d′ ∈ D \ {d}.

If I is a partial structure, U a set of domain atoms, and v a truth value, we use I [U : v] to refer to the partial structure that equals I except that for each domain atom P(d̄) ∈ U, it holds that .

The partial structure I that corresponds to a two-valued structure I is such that, for predicate symbols , and and, for function symbols f/n, it holds that , and .

The truth order <t on truth values is induced by f <t u <t t. The precision order <p on truth values is induced by u <p t and u <p f. This order is extended to a precision order over partial structure. A partial structure I is less precise than a partial structure I′ (notation I ≤p I′) if, for all symbols and . Maximally precise partial structures are two-valued.

In the remainder of the chapter, partial interpretation or structure is intended when interpretation or structure is used.

5.2.2    Partial Functions

In standard logic, function symbols denote total functions. In practice, partial functions are unavoidable, e.g., a function that maps persons to their spouse is naturally undefined for singles as well as for objects that are not a person, and the arithmetic operation division is undefined when the denominator is zero. So, our logic supports partial functions; however, defining a semantics for partial functions gives rise to undefined terms (also called non-denoting); this is a subject of controversy [Frisch and Stuckey 2009, Wittocx 2010].

The simplest solution is to restrict the syntax of formulas. One could, for example, allow only terms of the form f (t) in contexts where it is certain that f (t) is defined. This option is often taken in mathematics, where terms like, for instance, 1/0 are considered meaningless, but quantifications of the form ∀x : x ≠ 0 ⇒ 1/x ≠ 42 are allowed as it is clear that the division 1/x will be defined for all relevant x. This idea has been implemented, for example, in the Rodin toolset for Event-B [Abrial et al. 2010], where for every occurrence of a partial function it should be provable that the function will only by applied to values in its domain. However, this approach is too restrictive for a KBS. For example, in planning problems, the function Do/1 in a term Do(t) that refers to the action performed at time t is typically a partial one. It can be pretty hard to come up with the right Condition/1 predicate such that one can write ∀t : Condition(t) ⇒ … Do(t) …. It is entirely impossible, when the partial function is a constant for which it is a priori unclear whether it is defined, such as Unicorn. So we allow terms in contexts where they can be undefined. This brings us to the question of what an ambiguous form such as White(Unicorn) means. Does it mean “if the unicorn exists then it is white”, i.e., ∀x : Unicorn = x ⇒ White(x), or “the unicorn exists and is white”, i.e., ∃x : Unicorn = x ∧ White(x) (which equals (∃x : Unicorn = x) ∧ White(Unicorn)). For the user, having to write the longer unambiguous form is rather inconvenient (especially in the case of nested partial functions).

The current approach, which is the result of some years of experimenting, is based on the relational semantics proposed in Frisch and Stuckey [2009]. It turns out to be flexible, intuitive, and to allow for elegant modeling. The ambiguous form A(f(t̄)) is given the second of the above two meanings, namely ∃x : f(t̄) = x ∧ A[x] or equivalently ∃x : f(t̄) = x ∧ A[f(t̄)]. When the user is in doubt or prefers the other form, he should avoid the ambiguous form and explicitly write one of the explicit forms.

In a two-valued structure I, the value of a partial function f/n is a mapping fI : S → D where S is some subset of Dn. In a partial structure I, f/n is undefined for d̄ if and only if for all d ∈ D. We say that the image f(d̄) is undefined when f is undefined for d̄. The interpretation of a term with a direct subterm that is undefined is also undefined; that of an atom with a direct subterm that is undefined is false. This corresponds to the above described semantics.

5.2.3    Arithmetic

Standard FO can easily be extended with arithmetic. Indeed, numbers can be added to the domain and various (partial) functions can be included in the vocabulary to perform arithmetic.

So far, the IDP system only supports arithmetic over integers. This is our motivation to include the integers in every domain of FO(ID, AGG, PF, T) and the arithmetic partial functions +/2, -/2, -/1, */2 (multiplication), //2 (division), %/2 (modulo), and abs/1 in every vocabulary.⁴ To refer to these integers, every vocabulary also includes the constant symbol n for every integer n. Furthermore, in every structure, the interpretation of these integer constants is fixed to the corresponding integer in the domain.

5.2.4    Aggregates

Aggregates are an important language construct to boost the expressiveness of first-order logic. FO(ID, AGG, PF, T) includes the aggregate functions cardinality, sum, product, minimum, and maximum. The basic underlying concept is the set expression {(x̄) | φ} or {(x̄, t) | φ} where x̄ is a tuple of new variables and t is a term t [x̄, ȳ] with variables in x̄ and in the free variables ȳ of the expression. Given a two-valued structure I, such a set expression denotes the set of tuples {(x̄)I | φI = t} or {(x̄, t)I | (∃z : z = t ∧ φ)I = t}, where the existential quantification ranges over the domain of t. The inclusion of ∃z : z = t in the set prescription disambiguates the set in case of partial functions in φ.

Cardinality expressions are written in FO(ID, AGG, PF, T) as #{x̄ : φ} and this term denotes the number of tuples in the set. For the other four, the aggregate expressions take the form sum{(x̄, t) : φ}, prod {(x̄, t) : φ}, min{(x̄, t) : φ}, and max{(x̄, t) : φ}, respectively. These expressions denote the value of the aggregate function on the multiset obtained by extracting the last element tI of each tuple. For instance, sum{((x₁, x₂), x₂) : P (x₁, x₂)} sums the values of the second element of all tuples in P. If there are multiple occurrences of the same “second element” in tuples of P, then they are counted according to their multiplicity.

All aggregate functions are partial functions; they are undefined for infinite sets. Moreover, all aggregate functions except # are only defined for sets containing a tuple (…, d) with d an integer. The aggregates min and max are also undefined for the empty set; in contrast, sum and prod map the empty set to 0 and 1, respectively.

The aggregates supported by FO(ID, AGG, PF, T) also include the class of formulas ∃∼nx : φ with n a natural number and ∼ one of the comparison operators. While such formulas are equivalent with #{x : φ} ∼ n, they are more concise and a convenient extension of existential quantification. They allow one to express “there exists exactly n” (= n), “at most n” (≤ n), “less than n” (< n), “more than n” (> n), “at least n” (≥ n), and “there does not exist exactly n” (≠ n) values for x such that φ holds. Note that ∃≥1x : φ is equivalent with ∃x : φ, and ∃₌₀x : φ with ¬(∃x : φ).

5.2.5    Definitions

The logic FO(ID, AGG, PF, T) contains a definition construct to express different kinds of (possibly inductive) definitions. This construct is one of the most original aspects of FO(ID, AGG, PF, T) and we explain it in more detail. For additional details we refer to Denecker and Ternovska [2008].

Definitions are important building blocks of any scientific theory. However, there is no general way to express inductive/recursive definitions in FO. Although the notion of definition is informal, definitions have some extraordinary properties. Certainly those used in formal mathematical text strike us for the precision of their meaning. The formal semantics of FO(ID, AGG, PF, T) definitions carefully formalizes this meaning. Several types of informal definitions can be distinguished. Below, the three most common ones are illustrated: Example 5.1 is a non-recursive one, Example 5.2 is a monotone one, while Example 5.3 is by induction over a well-founded order, namely over the subformula order. Definitions over a well-founded order frequently contain non-monotone rules. For instance the rule defining I ⊨ ¬α has a non-monotone condition .

Example 5.1 Let a, b, and c be integers; a is between b and c iff b ≤ a and a ≤ c.

Example 5.2 Let (N, E) be a graph with nodes N and edges E. The transitive closure T of (N, E) is defined inductively as follows.

•  If (a, b) ∈ E, then (a, b) ∈ T.

•  If for some c ∈ N, it holds that (a, c) ∈ T and (c, b) ∈ T, then also (a, b) ∈ T.

Example 5.3 Let I be a two-valued structure of a propositional vocabulary. The satisfaction relation ⊨ is defined by induction over the structure of formulas.

•  I ⊨ P if P ∈ I.

•  I ⊨ α ∧ β if I ⊨ α and I ⊨ β.

•  I ⊨ α ∨ β if I ⊨ α or I ⊨ β (or both).

•  I ⊨ ¬α if .

In FO(ID, AGG, PF, T), a formal definition Δ is a set of rules of the form ∀x̄ : P(t̄) ← φ or ∀x̄ : f(t̄) = t′ ← φ, with the free variables of φ and the variables in t̄ and t′ amongst the x̄. We refer to P(t̄) and f(t̄) = t′ as the head of the rule and to φ as the body. In the first form, P is the defined symbol; in the second, f is. The defined symbols of Δ are all symbols that are defined by at least one of its rules; all other symbols occurring in Δ are called parameters or open symbols of Δ. Intuitively, for each two-valued structure of the parameters, Δ determines the interpretation of the defined symbols in a unique way. For instance, the definition of transitive closure can be formalized as follows:

The different sorts of definitions have different semantic properties. It is commonly assumed that the defined set is the least set that satisfies the rules of the definition, i.e., the least set such that the head is true whenever the body is true. However, this is only true for monotone definitions. It does not hold for nonmonotone definitions as the following example, from Denecker and Vennekens [2014], illustrates:

Intuitively, this defines the infinite set {Even(0), Even(2), Even(4) …} of even numbers. However, also the infinite set {Even(0), Even(2), Even(3), Even(5), …} satisfies the rules as for every rule instance with a true body, the head is also true. Both solutions are minimal; however, none is “least”.

Still, there is an explanation that applies to all kind of definitions [Buchholz et al. 1981]: the set defined by an inductive definition is the result of a construction process. The construction starts with the empty set, and proceeds by iteratively applying non-satisfied rules, until the set is saturated. In the case of monotone definitions, rules can be applied in any order; but in the case of definitions over a well-founded order, rule application must follow the well-founded order. This condition is necessary for the non-monotone rules. If they would be applied too early, later rule applications may invalidate their condition. For example, in the initial step of the construction of ⊨, when the relation is still empty, we could derive I ⊨ ¬φ for each φ, but the condition will in many cases become invalidated later. The role of the induction order is exactly to prevent such an untimely rule application, e.g., to prevent deriving Even(3) before Even(2) has been derived.

The problem we face in formalizing this idea for the semantics of FO(ID, AGG, PF, T) definitions is that the syntax of FO(ID, AGG, PF, T) does not specify an explicit induction order for non-monotone FO(ID, AGG, PF, T) definitions. Thus, the question is whether one can somehow “guess” the induction order. Indeed, if we look back at the definition of Example 5.3, we see that the order is implicit in the structure of the rules: formulas in the head of rules are always larger in the induction order than those in the body. This holds true in general. It should be possible then to design a mathematical procedure that somehow is capable of exploiting this implicit structure.

In Denecker and Vennekens [2014], this idea was elaborated. The induction process of an FO(ID, AGG, PF, T) definition is formalized as a sequence of three-valued structures of increasing precision. Such a structure records what elements have been derived to be in the set, what elements have been derived to be out of the set, and which have not been derived yet. Using the current three-valued structure, one can then establish whether it is safe to apply a rule or not. All induction sequences can be proven to converge. In case the definition has the form of a logic program and the underlying structure is a Herbrand interpretation, the resulting process can be proven to converge to the well-known well-founded model of the program [Van Gelder et al. 1991]. As such, the semantics of FO(ID, AGG, PF, T) definitions is a generalization of the well-founded semantics to arbitrary bodies, to arbitrary structures, and with parameters. This (extended) well-founded semantics provides a uniform formalization for the two most common forms of induction (monotone and over a well-founded order) and even for the less common form of iterated induction [Buchholz et al. 1981]. Compared to other logics of iterated inductive definitions, e.g., the work by Buchholz et al. [1981], the contribution is that the order does not have to be expressed; a substantial advantage as this can be very tedious.

The satisfaction relation of FO is thus extended to handle definitions by means of the well-founded semantics [Van Gelder 1993], since it formalizes the informal semantics of rule sets as inductive definitions [Denecker 1998, Denecker et al. 2001, Denecker and Vennekens 2014]. We now formally describe how this is done. First, consider definitions Δ that define only predicate symbols. We use the parametrized well-founded semantics. This semantics has been implicitly present in the literature for a long time, by assigning a meaning to an intensional database. We follow the formalization by Denecker and Vennekens [2007]. We say that a two-valued structure I satisfies Δ(I ⊨ Δ) if I is the parametrized well-founded model of Δ, that means that I is the well-founded model of Δ when the open symbols/parameters are interpreted as in I.

Checking the latter is done by computing the well-founded model of Δ. This can be computed as the limit of a well-founded induction [Denecker and Vennekens 2007], defined below.

Definition 5.1 Refinement. We call a partial structure I′ a refinement of partial structure I if one of the following holds:

•  for every defined predicate P and every tuple of domain elements d̄,

•  I′ = I [U : f], where U is a set of domain atoms unknown in I such that for every P(d̄) ∈ U and every rule ∀x̄ : P(x̄) ← φ in Δ, it holds that φ[x̄/d̄]I′ = f (such a set U is called an unfounded set of Δ in I [Van Gelder et al. 1991]).

A refinement is strict if I′ ≠ I.

The first refinement evaluates all rule bodies of all defined domain atoms and assigns the largest truth value (e.g., if one rule derives an atom to be true, and the second rule does not yet derive information about that atom (u), the atom obtains the value t) to each defined atom. The second refinement identifies an unfounded set: a set of domain atoms such that the bodies of rules defining them can only become true if at least one of these atoms is true in the first place (due to cyclic dependencies). Such atoms can never be derived constructively using the definition, hence they must be false.

Definition 5.2 Well-founded induction. Let I be a partial structure that interprets only the open symbols of Δ. A well-founded induction of Δ in I is a sequence (Ii)i≤n, with n ∈ ℕ, of partial structures such that the following hold:⁵

•  I₀ = I; and

•  for each i < n, Ii+1 is a refinement of Ii.

A well-founded induction is terminal if its limit (In) has no strict refinements.

Denecker and Vennekens [2007] showed that all terminal well-founded inductions in I have the same limit, namely the well-founded model of Δ in context I.

To extend this satisfaction check to definitions defining functions, one treats a function f/n as if it is defining an n + 1-ary relation. For what concerns the use of partial functions in the head of a rule, note that ∀ȳ : p(t̄) ← φ is equivalent with ∀x̄ ȳ : p(x̄) ← x̄ = t̄ ∧ φ. Partial functions in bodies have the same meaning as in formulas.

In FO(ID, AGG, PF, T), a definition is seen in a pure declarative way, as a proposition stating a special logical relationship between defined predicates and parameter symbols. In case a theory contains multiple definitions of the same predicate, the theory states multiple independent such propositions. For instance, a theory that contains

states that “Human” is the union of men and women and also that “Human” is the union of children and adults. This implies, for example, that the union of men and women, and of children and adults, is identical. Note that this declarative view implies that the definition

has a different meaning than the pair of definitions

Indeed, in the former, p and q are false in the only well-founded model. In the latter, the structure in which p and q are true is also a model since we now have two definitions, each with a parameter.

To reason with definitions, the IDP solver makes also use of their completion. The completion of Δ for a symbol P, defined in Δ by the rules ∀x̄i : P (t̄i) ← φi with i ∈ [1, n], is the set consisting of the sentence ∀x̄i : φi ⇒ P(t̄i) for each i ∈ [1, n] and the sentence ; the completion for defined function symbols is defined similarly. This set is denoted as compP,Δ, the union of all these sets for Δ as compΔ. It is well known (see, e.g., Van Gelder et al. [1991]) that if I ⊨ Δ then I ⊨ compΔ but not always vice versa (e.g., the inductive definition expressing transitive closure is stronger than its completion).

5.2.6    Types

While first-order logic is untyped, the real world is typed. For example, in a course scheduling problem we can distinguish persons, which can be further divided into teachers and students, courses, rooms, time slots, etc. The advantages are well known in the field of programming languages. For example, the introduction of the book of Pierce [2002] lists, among others, early detection of errors and a minimum of documentation. These advantages also hold for a knowledge representation language. Moreover, the use of types leads to more detailed and more accurate modeling of the different types of objects in the domain of discourse.

FO(ID, AGG, PF, T) is a simple order sorted logic. This means that a vocabulary contains a set of types on which a subtype relation is defined. The corresponding type hierarchy is a set of trees. Two types are disjoint if they have no common supertype (a type is a supertype of itself). Every vocabulary includes the type int of the integers and its subtype nat of the natural numbers. All predicate and function symbols of a vocabulary are typed by means of a type signature which associates a type with each argument position, and, in the case of functions, with the result. All variable occurrences in a theory are typed; all occurrences of a variable within the same scope have the same type; the type of a variable is given when it is introduced in a formula or set expression, for example, ∀x[T]: φ[x] and #{x[T] y[T′]: φ[x, y]} < 3.

In a structure, a domain DT is associated with each type T; for a subtype T₁ of T₂, is a subset of ; if T₁ and T₂ are disjoint types, and must be disjoint. Structures are well-typed. This means that for a predicate symbol P of type (T₁, …, Tn), its value PI belongs to the Cartesian product and for a function symbol f from (T₁, …, Tn) to T, its value fI is a partial function from to DT. For the evaluation of quantified formulas ∀x[T]: φ and ∃x[T]: φ, enumeration of the values of x is over the domain DT. Similarly, in a set expression {(x̄ [T̄], t)|φ} of an aggregate, each xi is assigned domain elements from . Note that a term t of type T₁ that occurs in an argument of an atom or function where a term of type T₂ is expected can have the meaning of an undefined term (Section 5.2.2). Indeed, the atom evaluates to false or the function is undefined when t evaluates to a domain element outside . While this cannot happen when T₂ is a supertype of T₁, it always is the case when T₁ and T₂ are disjoint; it depends on the evaluation when there is a third type that is a supertype of both. When the types are disjoint, it is appropriate to raise a type error as this is likely a design error in the logical theory.

5.3    IDP as a Knowledge Base System

We start the section with a description of the architecture and a discussion of design decisions. We finish with sketching an application where the same knowledge is used for different tasks.

5.3.1    Architecture and Design Decisions

Here, we introduce and motivate the basic design decisions underlying the IDP system, the decisions that determine the look and feel of IDP as a KBS. IDP is an implementation of a KBS. Besides the two main parts, the declarative language and the inferences methods, there is also a part that provides procedural integration. An overview is shown in Figure 5.1.

The first design decision, the one most visible to users, is about the language of the KBS. The language should be: (i) rich enough so that users can express all their needs; (ii) natural enough so that theories stay close to the original (natural language) problem statement and are easy to read and to debug; and (iii) modular enough to allow for reuse and future extensions.

Figure 5.1    High-level representation of a KBS system.

It is sometimes argued that the expressiveness of a language should be limited, to avoid that the language becomes undecidable or intractable. We disagree. First, note that decidability and tractability depend on the task at hand. While deduction in first-order logic is undecidable, other forms of inference, such as model expansion and querying in the context of a finite domain, are decidable. Second, while a more expressive language might allow users to express tasks high in the polynomial hierarchy, that does not imply that simple tasks become harder to solve. Rather to the contrary, stating the problem in a richer language sometimes allow the KBS to exploit structural information that would be hidden in a more lower-level problem statement.

To address the requirement of a rich and a natural language, we have opted for FO(ID, AGG, PF, T), FO extended with definitions, aggregates, partial functions, and types. We choose first-order logic because conjunction, disjunction, universal quantification, and existential quantification have very natural meanings. Extensions are needed because FO has various weaknesses. Inductive definitions overcome the weakness that FO cannot express inductively defined concepts. Also, non-inductive definitions are very useful. In mathematical texts, it is common practice to use “if” when defining concepts; this “if” here is (in natural language) a definitional implication. Aggregates allow users to concisely express information requiring lengthy and complex FO formulas. Types are omnipresent in the context of natural language, where quantification typically refers to a specific set of objects (e.g., everyone is mortal). For integration with a procedural language, IDP currently offers an interface to the languages Lua and C++.

The third language requirement, modularity, is important both at the language and at the system level. An advantage of first-order logic as basis of our language is that language extensions can be added without much interference at the syntactical and semantical level. For example, to introduce aggregates to FO, it suffices to extend the satisfaction of atoms in which an aggregate occurs in order to obtain a semantics for a language extended with aggregates.

On the system level, we have also attempted to organize inference engines in a modular way so that components can be reused in multiple engines. For example, the model expansion inference is currently implemented as ground-and-solve; the solver can be used separately from the grounder, and the grounding phase is composed of several smaller, reusable parts (for example, evaluation of input- *-definitions [Jansen et al. 2013]). Also, various approaches to preprocess simple theories in order to improve their computational efficiently are integrated in the system. Examples are symmetry detection [Devriendt et al. 2016b] and symmetry breaking [Devriendt et al. 2012] methods and the use of deduction to detect functional dependencies [De Cat and Bruynooghe 2013]. Such preprocessing techniques also improve the user-friendliness and robustness of the KBS as a whole. Indeed, they let a user focus on the declarative modeling, and partly relieve the user from the task of fine-tuning it on a specific solver.

5.3.2    Multiple Inference Methods Within One Application Domain

Given any knowledge base, there are often multiple applications that require different kinds of inference. By way of example, we explore the setting of a university course management system. Its input is a database with information on students, professors, classrooms, etc. One task of the system is to help students choose their courses satisfying certain restrictions. Such an application is usually interactive; students make choices and, in between, the system checks the knowledge base. It removes choices when they become invalid, adds required prerequisites when a course is selected, etc; this is an example of propagation inference. When the student has made all choices he deems important, the system could use the same knowledge base to complete the student’s choices to obtain a complete schedule. This type of inference is called model generation or model expansion: one starts with partial information (certain selections have been made) and wants to extend it into a complete solution, namely a model of the course selection theory. Another task where model expansion is needed in the same application area is to generate a schedule where every course is assigned a location and a starting time such that (1) no person has to be at two places at the same time, (2) no room is double-booked, and (3) availability of professors is taken into account. However, due to the large number of optional courses, such a solution (in which no student has overlapping courses) will probably not exist. In this case, we might want to find a solution in which the number of conflicts is minimal; this requires minimization inference. Now, one might want to mail students with schedules with overlaps to give them the opportunity to change their selection. Hence, the solution of the minimization inference should be queried to find the overlapping courses for every student. In the course of a semester, professors might have to cancel a lecture due to other urgent obligations. In that case, we want to find a revision of the current schedule, taking the changed restrictions into account and minimizing the number of changes with respect to the current schedule. In case such revisions are done manually, the model checking inference can be used to ensure that no new conflicts are introduced. If some conflict does occur, an explanation should be provided. Finally, if a valid schedule is found, a visualization inference can be used to create an easy-to-understand, visual representation of the schedule, personalized by the viewer’s status (student, professor, administrative personnel, etc.). Part of such an application, using the IDP system as a back end, is shown at http://krr.bitbucket.org/courses.

5.4    The IDP Language

The IDP language is the input language of the IDP system. A program in the IDP language consists of declarative and imperative components. The declarative components are vocabulary, structure, theory, and term components. Together, they provide a concrete computer-readable syntax for FO(ID, AGG, PF, T). The imperative components allow one to perform computational tasks. They consist of procedures. Each procedure embeds a piece of imperative Lua [Ierusalimschy et al. 1996] code; besides performing standard imperative operations, procedures can apply inference methods upon FO(ID, AGG, PF, T) theories encoded in the declarative components.

Vocabulary, structure, and theory components are described in Section 5.4.1; procedure components in Section 5.4.2, and term components in Section 5.4.3. In this section we do not strive for completeness but focus on what is needed to get started using the IDP system and on providing answers to the difficulties a starting user might have.

Before describing the different kinds of components, we first discuss a few general notational conventions. Names are everywhere: they are used for types, predicates, functions (including constants), and variables as well as for domain elements in structures. To distinguish them from numbers, they start with a Latin letter (upper or lower case) and consist of a sequence of Latin letters and digits; also a few special characters such as “_” are allowed. For domain elements, one can deviate from this convention by using a string notation. For details, we refer to the manual [Bogaerts et al. 2012]. Comments that fit on a single line start with “//”. One can start longer comments with “/*” and end them with “*/”.

5.4.1    The Logic

5.4.1.1    Vocabulary

The vocabulary of an FO(ID, AGG, PF, T) theory is represented as a vocabulary component. We start with an example.

A vocabulary declaration takes the form “vocabulary 〈vocname〉 {〈typed symbol list〉}”. It specifies the name of the vocabulary, here courses and its symbols. The symbol list comprises type symbols, and typed predicate and function symbols. Each symbol is to be declared on a new line. Types are declared using the keyword “type”. A type may be declared as a subtype using the keyword “isa” followed by a comma-separated list of supertypes. For example “type A isa B, C” declares A as a direct subtype of B and C. The declared isa graph needs to be acyclic. The integers, type int, and its subtype, the natural numbers, type nat, are part of every vocabulary and need not be declared. The same holds for predicates and functions that are part of every FO(ID, AGG, PF, T) theory such as comparison predicates and arithmetic functions. Predicates and functions are introduced by declaring their signature. In the example, takes is a relation over student and course and hasAge is a function from person to the subtype age, a subtype of nat. The symbol Vacation is a propositional symbol, and Boss a constant symbol. Partial functions are introduced by the keyword partial, for example partial hasAge(person):age would declare hasAge as a partial function. The IDP system cannot yet cope well with infinite types, so int and nat can better be avoided in signatures of predicates and functions.

5.4.1.2    Structure

A structure component describes a partial structure for a vocabulary, in particular the domains of the user declared types. We start again with an example.

A structure has a name, here data1, and specifies the vocabulary that it (partially) interprets, here courses. It specifies an assignment of values for symbols using a list of “symbol=value” equations. Boolean values are denoted true or false, as illustrated by the equation Vacation=true in the example. Other base values are numbers, strings, or user-defined domain values like Bob, Math. Set values are denoted as “{〈semicolon separated list〉}”. The list may consist of individual entities or of tuples of individual entities. Tuples are denoted as comma separated lists of domain values, potentially between parentheses: “( …)”. The shorthand “n … m” enumerates the integer interval [n, m], as illustrated for age. The same holds for characters, e.g., student = {a … d} is a shorthand for student = {a;b;c;d}.

A structure specifies, implicitly or explicitly, the value of each type of the vocabulary.⁶ A value of a type is a set of domain elements. User-defined domain elements are identified by symbolic identifiers (e.g., Bob, Math) but these identifiers are not symbols of the vocabulary and cannot be used in the theory. One can use integers as names for the domain elements of types, even if this type is not a subtype of int. For example, student = {1 … 50} introduces 50 students. Note, these domain elements are not integers, the domain element 49 of type student is different from domain element 49 of type integer.

A (total) value for a predicate symbol is a set of domain elements or tuples of it. Alternatively, a structure may specify a partial value for a predicate symbol P, as an assignment of a list of certainly true, certainly false and unknown tuples to, respectively, P<ct>, P<cf>, and P<u>. Only two out of three need to be specified. This is illustrated by takes.

The value or partial value for functions is specified in an analogous way, with the difference that the user is allowed (but not obliged) to specify a tuple “(a1, …, an,b)” of a function in the form “a1,…, an → b”. For partial interpretations of functions, we refer to the discussion on partial structures in Section 5.2.1. For example, hasAge< cf > = {Marc → 1; Marc → 2} can be used to express that the age of Marc is neither 1 nor 2.

In IDP one cannot currently use a constant as a bound in a domain enumeration, as in student = {1…nbstudents}, where nbstudents is a constant symbol whose value is specified elsewhere. Another limitation that was already mentioned earlier, is that domain values such as Bob and Alice (identifiers introduced at the right side of “symbol=value” equations), are not part of the vocabulary and cannot appear in theories.

Recall that there exist also many interpreted symbols (e.g., numerical operators and aggregates) whose values are fixed and are implicit parts of all structures.

5.4.1.3    Theory

A theory component over some vocabulary is declared as “theory 〈theory name〉 : 〈vocname〉 { … }”. For the syntax of formulas and definitions, that of the formal base language is followed as closely as possible. Formulas and rules are terminated with a “.” and rules are grouped in definitions which are put between “define {” and “}”. Table 5.2 provides a translation in a more keyboard-friendly notation.⁷

By way of example, we show a vocabulary, a structure, and a theory for a small graph problem that formalizes a connected graph over a set of nodes.

Table 5.2    Overview of the syntax of the IDP language

The theory contains a definition⁸ of the Reachable predicate and two formulas that constrain the solution. All variables are typed with type Node; however, these types can be omitted since type inference will derive them from the signatures of the symbols in which the variables occur.⁹ Observe that this theory defines Reachable as the transitive closure of parameter Edge. This definition is syntactically similar to a Prolog program, but unlike a Prolog program, it is here the defined predicate that is known (it is the set of all nodes) and the parameter predicate that is unknown. It illustrates the declarative understanding of a definition that expresses a particular logical relationship between the parameters and the defined symbols, and not a way to compute the defined symbols in terms of the parameters.

5.4.2    Procedure

A procedure component is a chunk of Lua code [Ierusalimschy et al. 1996] encapsulated in the form of an IDP component (a keyword procedure, a name, a list of parameters and the chunk of code between “{” and “}”). When the IDP system is run, it calls the procedure main(). Typically, one will use the IDP system to do some reasoning on an FO(ID, AGG, PF, T) theory. Here is a simple example:

The first line, stdoptions.nbmodels = 0, configures the IDP system to compute all models (with a positive number n, inference is stopped after n models have been found; default value is 1). The second line calls IDP’s modelexpand procedure with as input arguments the theory T and the structure S and prints these models (printmodels). The modelexpand procedure calls upon the solver of the IDP system to search for models of T that expand the input structure S and returns an array of models. To print a single model, one can select a model and print it, e.g., print(modelexpand(T,S)[3]) to print the third model. With the theory and structure as given in the small graph theory of the previous section, the above procedure prints 24 models, the first one being:

Note that the model is written in the syntactic format of a structure component. The procedures modelexpand and printmodels are only two out of many predefined procedures in IDP. Many procedures provide other forms of inference that can perform computational tasks using the knowledge represented by an FO(ID, AGG, PF, T) theory. Other procedures serve to manipulate and create new logical components, such as vocabularies, structures, and theories. We refer to the online IDP Web-IDE (http://dtai.cs.kuleuven.be/krr/idp-ide/) and the IDP manual [Bogaerts et al. 2012] for examples and details. The main design philosophy is that all components in an IDP program are first-class citizens. They can be used to perform various reasoning tasks but can also be manipulated by Lua code to construct different ones. So, it is possible to set up a complete workflow.

This methodology in which fine-grained declarative computation steps are mixed in procedures is an exciting novel way of integrating declarative and procedural knowledge. This is illustrated by Bruynooghe et al. [2015]. This is an application in stemmatology, the study of the family relationships between different manuscripts (handmade copies) of a text. It sketches a set of procedures that describe the workflow to analyze a number of texts. For each text, a data set is read and analyzed and transformed into structures and vocabularies. These are then combined with the problem vocabulary and theory and, for each so called feature in the input data of a text, it is checked whether a model exists. Finally, for each data set, a summary report about all its features is reported.

5.4.3    Term

One of the available forms of inference in IDP is to solve minimization problems. This inference method takes as input a theory, a partial structure, and a cost term, and outputs one or more models of the theory expanding the partial structure such that the value of the cost term in these structures is minimal (among the set of all models more precise than the partial structure). The cost term is to be specified as a separate term component over the same vocabulary as the theory. To illustrate, we return to our graph problem and introduce a term to count the number of edges in the solution.

The main procedure now calls the minimization inference with the theory T, the structure S, and the optimization term t as input. With T and S as above, the procedure returns three models, however, it also returns two other values: whether optimality has been proven and the value of the term in the optimal solution. The assignment models, optimal, cost= … assigns them to different variables. The first value is an array of models, which can be printed with printmodels, the other two are simple values; they can be printed with the standard print command. In this example, optimality is reached with a cost of 3.

5.5    Advanced Features

5.5.1    Constructed Types

In Prolog and ASP, functions and constants have a fixed interpretation, their Herbrand interpretation. Equivalently, we can think of them as logics with built-in unique names and domain closure axioms (UNA and DCA), i.e., axioms stating that all those values are different and that the domain consists of nothing more than those values, respectively. In FO(ID, AGG, PF, T), the axioms are not present and interpretation of functions and constants is open as in standard FO. Both approaches have their merits, making it useful to integrate the advantages of both. In ASP, there is work to incorporate open functions [Bartholomew and Lee 2012, Lifschitz 2012]. In FO(ID, AGG, PF, T), one way to impose UNA and DCA is to explicitly specify a Herbrand interpretation. This method is illustrated below for the type of days of the week, using the following declarations in the vocabulary:

and in the structure

There is a way to avoid this cumbersome approach. The following declaration of a constructed type in the vocabulary expresses the same information but in a compact way:

This statement declares several things at once: it declares the type Day and seven constants of this type, and it specifies the values for this type and for all its constants in every structure of the vocabulary. Each constant is interpreted by itself. Here, constants and domain elements coincide.

Non-constant constructor symbols are also supported this way. For example, having types row and column, one can introduce the constructed type of positions on a chessboard by declaring “type position constructed from pos(row, col)”, and use it in the definition of a unary predicate queen(position) representing the positions where a queen stands. In theory, this approach also works for recursive constructors and types such as list of integers: type list constructed from {nil ; cons[int, list]}. However, this creates an infinite type and the current IDP solver cannot cope with such types.

5.5.2    Structuring Components

All components, vocabularies, theories, structures, terms, and procedures, as we have shown so far, are part of the implicit global namespace idpglobal. This namespace also contains all Lua procedures that are available to the user of the system. When working on large projects, different people may work on different parts, each introducing its own components. To integrate such different parts, the IDP system provides namespaces. A namespace with name MySpace is declared by

A namespace can contain other namespaces, and any sort of IDP component including vocabularies, theories, structures, terms, and procedures. Each component has a full name that is determined by the hierarchy of namespaces it belongs to. This allows users to disambiguate components with the same name but belonging to different namespaces. We refer to the manual for details [Bogaerts et al. 2012].

Another useful structuring method is to compose a vocabulary from existing ones. For instance, in the following example W is composed of the symbols of V and one function coloring/1:1 from vocabulary U:¹⁰

Such an extension construct is not available for structures and theories but it could be simulated for them by making use of certain Lua procedures. For this we refer to the list of Lua procedures described in the manual.

Worth mentioning is that there is a factlist component to initialize a two-valued structure with Prolog or ASP facts. Also, it is possible to call upon Lua procedures to initialize a structure.

5.5.3    An Output Vocabulary

In many problems we are interested only in the values of some subset of symbols. In case multiple solutions are searched, we are interested only in models having different interpretations of the output symbols. This is achieved by declaring an output vocabulary, say Vout, and adding it as an extra parameter to the modelexpand call:

5.5.4    Inference Methods

So far, we have mentioned model expansion inference, invoked as modelexpand(T, S) (or modelexpand(T,S,Vout) if there is an output vocabulary) and optimization inference, invoked as minimize(T,S,t) (or minimize(T,S,t,Vout)). The system supports several other inference methods. We discuss the most important ones. For a complete list, we refer to the manual.

Query inference takes as input a query component that declares a set expression of the form {x | φ} and a two-valued structure I and returns the set {x | φ}I. In the IDP language, this inference is invoked as query(Q,S), where Q is a query and S a structure. Continuing our graph example, consider the following IDP code:

Executing the main() procedure will print the set of all nodes that participate as the first node of an edge in the first model computed by the model expansion. Note that query(…) does not return a structure but a set.

Model checking and satisfiability checking are special cases of model expansion. In the former, the input structure is two-valued; the result of this inference is true, respectively, false if the input structure is a model of the theory. The latter also outputs a Boolean value, true if the (possibly three-valued) output structure can be expanded to a model. In the IDP language, both of these inference methods are called using sat(T,S), where T is a theory and S a structure.¹¹

Propagation inference takes a theory and a structure and returns a more precise structure that preserves all solutions. The system supports different versions of propagation with different costs. The most precise and most expensive version returns the partial structure in which atoms are unknown iff they do not have the same truth value in all models. This most expensive propagation is called using optimalpropagate(T,S). Cheaper, approximate forms of propagation are called using propagate(T,S) and groundpropagate(T,S).

Deduction takes as input an FO(ID, AGG, PF, T) theory T and an FO theory TFO and returns true if T ⊨ TFO, that is if the first theory logically entails the second one. It is implemented in a sound but incomplete way by translating T into a (weaker) FO theory and calling the theorem prover SPASS [Weidenbach et al. 2009]. It is used internally in the IDP system to detect and exploit functional dependencies in predicates [De Cat and Bruynooghe 2013]. It is called using entails(T1,T2).

Symmetry detection takes as input a theory T and a partial structure I and returns symmetries over T and I. A symmetry is a function, say f, mapping structures to structures, such that, for any two-valued expansion J of I that is a model of T, f(J) is also a model [Devriendt et al. 2012]. Symmetry detection also returns clauses to break these symmetries and to eliminate symmetric models. Symmetry detection is not available as a Lua procedure but can be exploited in the model expansion workflow using the option symmetrybreaking (see Section 5.6).

Δ-model expansion takes as input a definition Δ and a structure Iin, interpreting all parameters of Δ, and returns the unique model I that expands Iin. This task is an instance of model expansion, but is solved in IDP using different technology. The close relationship between definitions and logic programs under the well-founded semantics is exploited to translate Δ and Iin into a tabled Prolog program, after which XSB is used to compute I. Taking an extra formula φ as input, with free variables x̄, the same approach is used to solve the query φ with respect to Δ and Iin in a goal-oriented way [Jansen et al. 2013]. There is no dedicated Lua procedure for calling Δ-model expansion. However, as described in Section 5.6, it is automatically detected that Δ-model expansion can be performed in normal model expansion calls.

Unsat-core extraction takes as input a theory T and a structure I such that T has no models expanding I. It returns a (minimal) theory Tout entailed by T (obtained by instantiating some variables) such that Tout still has no models expanding I. Currently, there is only support for printing the output theory, not for actually obtaining it; this procedure also prints from which line every sentence in Tout was instantiated. This inference is particularly useful when debugging logical specification and can be called using printunsatcore(T,S).

Finally, there is support for the linear time calculus (LTC) defined by Bogaerts et al. [2014a]. One can build an LTCvocabulary component as a vocabulary extending a default LTC vocabulary and can use special inference methods to initialize the state and to perform progression inference, i.e., to infer the successor states step by step [Bogaerts et al. 2014a].

5.6    Under the Hood

In this section we focus on the inner working of some components of the IDP system. First, we discuss the workflow of the optimization inference and how users can control the various parts of the optimization engine. Afterward, we discuss techniques (under development) that help IDP scale to larger, possibly infinite, domains.

Optimization is the task of given a theory T, a structure I, and a term t, all over the same vocabulary V, finding models of T that expand (are more precise than) I. This inference captures Herbrand model generation and (bounded) model expansion, both of which were proposed as logic-based methods for constraint solving in East and Truszczyński [2006] and Mitchell and Ternovska [2005], respectively. In its most general form, we define optimization for typed FO(ID, AGG, PF) as follows. The inference OPT 〈V, T, I, t, Vout〉 takes as input a theory T, structure I, and term t, all over vocabulary V, and a vocabulary Vout ⊆ V. Both T and I are well-typed and I interprets all types. The inference returns Vout-structures J such that at least one model of T expanding both I and J exists and that expansion is minimal with respect to t. The optimization inference is a generalization of the model expansion inference that takes the same arguments without the optimization term t and that returns Vout-structures J such that at least one model of T expanding both I and J exists. The workflow of these two inference methods coincides; for optimization, more search is needed to find optimal models.

One approach to optimization, used in IDP, is through ground-and-solve: ground the input theory and term over the input structure and afterward apply a search algorithm that, e.g., uses branch-and-bound to find optimal models.

In the rest of the section, we present how the optimization algorithm in IDP solves an OPT 〈V, T, I, t, Vout〉 task. The workflow consists of an FO(ID, AGG, PF, T) grounding algorithm, a search algorithm for the full ground fragment of FO(ID, AGG, PF, T), and various analysis methods and transformations that result in a smaller grounding and/or improved search performance.

The workflow of the optimization inference consists of three parts. First, theory and structure are preprocessed to optimize performance. Second, the theory is grounded into ECNF, the language supported by MiniSAT(ID). Last, the solver MiniSAT(ID) is called to perform the actual inference on the ground theory.

5.6.1    Preprocessing

Several preprocessing steps are performed before the grounding phase. We briefly discuss them below.

5.6.1.1    Checking Structure Consistency

First, we specify the structure I that is parsed from a structure component, in particular, how the type autocompletion works. The following definitions formalize this. The value of all other symbols is clear.

We say that a type t of a vocabulary V is explicitly defined in structure I if I contains an equation t = S. We define the value of an explicitly defined type in I as stated in its explicit definition. For a type t that is not explicitly defined, the interpretation of t in I consists of all elements of its subtypes and domain elements that occur in the interpretation of symbols σ at an argument position of type t. Formally:

A number of constraints are imposed on all structures.

•  For any subtype s of t, the interpretation of s must be a subset of the interpretation of t :

•  If f is a partial or total function that is totally defined, there is at most one image for each value of the input:

•  If f is a totally defined total function, the structure must contain an image for each input argument:

•  A partially defined predicate cannot be both certainly true and certainly false for the same tuple:

•  For any partially defined function f, there is at most one certainly true image for every input:

In addition, if f is a total function, at least one output is possible (not certainly false) for each input:

When any of these constraints are violated in the autocompleted structure I, an appropriate error message is given.

5.6.1.2    Exploiting input*-Definitions

The following is a summary of the relevant results from Jansen et al. [2013].

Assume that after preprocessing, we obtained a theory T and a structure I₁ = I. The next step is to eliminate some definitions of T and extend I₁. The definitions that can be eliminated are the so called input*-definitions of T [Jansen et al. 2013].

We define inductively that a definition Δ of T is an input*-definition of T in structure I if all parameters of Δ have a 2-valued interpretation in I or are defined in input*-definitions of T in I.

All input*-definitions of T can be evaluated in advance. Essentially, this is done by iterated Δ-model expansion steps: at each iteration an input*-definition Δ is selected that has all its parameters interpreted in the current structure; we compute¹² its model in I₁ and add the interpretation of the defined symbols to I₁. The advantage of this is that as explained below, top-down grounding techniques, as used in IDP, tend to be rather inefficient in case of complex (inductive) definitions [Wittocx 2010]. By evaluating these definitions, we avoid grounding them and we make the input structure more precise.

Notice that this may result in inconsistency if the same predicate is defined in multiple input*-definitions that do not agree on its value. Otherwise, the result is a theory T₂ and a refined structure I₂.

To exploit the above procedure for a maximal effect, it is extended with a preprocessing step to split each definition Δ of T in subdefinitions Δ₁,…, Δn. The advantage is that some of these components may turn out to be input*-definitions whereas is not. In this case we can evaluate part of Δ.

The split of a definition is computed from its dependency relation. Formally, the dependency relation ≤ of a definition Δ is the least transitive relation containing all pairs P ≤ Q such that defined symbol P occurs in a rule defining Q. We say that P ~ Q if P ≤ Q ≤ P. This is an equivalence relation. The split Δ of is the partition Δ₁,…, Δn of Δ such that each Δi defines an equivalence class of ~. The idea is that each Δi defines a group of predicates that depend on each other.

5.6.1.3    Delaying output*-Definitions

The following is a summary of the relevant results from Jansen et al. [2013], Bogaerts et al. [2016]

Consider a total definition Δ ∈ T₂ such that the defined symbols of occur Δ only in Δ and are not interpreted in I₂. Any structure that satisfies T₂ \ {Δ} and does not interpret symbols defined in Δ can be extended to a model of T₂ by evaluating Δ. Consequently, there is no need to consider such Δ a during search; we prefer to delay evaluation of Δ as long as possible, to a postprocessing step.

Such a Δ is one example of an output*-definition [Jansen et al. 2013, Bogaerts et al. 2016]. In general, we define inductively that a definition Δ of T is an output*-definition of T in structure I if all defined symbols of Δ only occur in Δ and in the bodies of rules of output*-definitions.

These output*-definitions do not have to be considered during search and can be evaluated afterward in a post-processing step. Theory T₃ is the theory obtained from T₂ by removing all output*-definitions; this phase does not modify the structure, hence I₃ = I₂.

5.6.1.4    Reducing Quantification Depth Using Functional Dependencies

The following is a summary of the relevant results from De Cat and Bruynooghe [2013].

The size of the grounding is in general exponential in the nesting depth of quantifiers (as it involves the Cartesian product of the involved domain sizes). One way to reduce the quantification depth is to detect that symbols can be split into a number of symbols with a smaller arity. Assume, for example, that a predicate timeOf(session,time) specifies at which time a certain session takes place in a scheduling application. If one could detect that the second argument functionally depends on the first argument (the first uniquely determines the value of the second), then it could be replaced by a new function timeFunc(session): time instead. With appropriate transformations, a subformula ?t: timeOf(s1,t) & timeOf(s2,t) can then be reduced to timeFunc(s1)=timeFunc(s2), eliminating the quantification over t. Detection of functional dependencies is done using the deduction inference: we check whether an FO formula that expresses the dependency is entailed by the original theory. For timeOf, the functional dependency holds if the theory entails the sentence ∀s : ∃₌₁t : timeOf (s, t).

This preprocessing phase takes as input the theory T₃ and structure I₃ and returns T₄ and I₄, in which entailed functional dependencies have been made explicit and quantifications have been dropped where possible.

However, as the user expects models in the original vocabulary, additional output*-definitions are added to T₄, that define the original symbol in terms of the newly introduced ones. In our example, this would be the definition

define {

! s t: timeOf(s,t) ← t = timeFunc(s).

}

5.6.1.5    Exploiting Symmetries

The following is a summary of the relevant results from Devriendt et al. [2012], Devriendt et al. [2016b].

It is well known that if a problem exhibits symmetries, they can cause a search algorithm to solve the same (sub)problem over and over again. For example, the “pigeonhole” problem “do n pigeons fit in n – 1 holes?” is known to be hard for SAT-solvers. Symmetries can be detected and broken on the propositional level [Aloul et al. 2006, Devriendt et al. 2016b], but for large problems, even the task of detecting symmetries becomes infeasible. Detecting symmetries on the first-order theory [Devriendt et al. 2016a] is often an easier problem, as much more structure of the problem is explicitly available. For example, for an FO specification of the pigeonhole problem it is almost trivial to detect that all pigeons are interchangeable. The symmetry detection inference in IDP detects a simple, frequently occurring form of symmetries: locally interchangeable domain elements (see [Devriendt et al. 2016a]). Two domain elements are considered interchangeable if they are of the same type and occur only symmetrically in interpreted predicates. Detected symmetries are handled by adding sentences to T₄ that statically break those symmetries, resulting in the theory T₅.

5.6.2    Ground-And-Solve

5.6.2.1    Ground

The following is a summary of the relevant results from De Cat et al. [2013].

The grounding algorithm visits the resulting theory (T₅) in a depth-first, topdown fashion, basically replacing all variables by all their matching instantiations, according to the interpretation of their types in a partial structure I₅. For example, a formula ∀x[t] : ψ(x) is replaced by Λd∈tI₅ ψ(d).

However, such an instantiation might be unnecessary large. Indeed, if the value of a term or formula is known in the current structure I₅ for a given instantiation of its free variables, it should not have been grounded in the first place. The solution is to reuse query inference. For example, consider a formula ∀x̄ [T̄] : φ and an instantiation d̄ for the free variables ȳ of this formula. In that case, x̄ need only be instantiated with tuples d̄′ for which φ[y/d, x/d̄′] is not certainly true in I₅. Finding such tuples can be done using the query inference on a derived structure over a vocabulary in which <ct> and <cf> tables have an explicit representation. For all instantiations of x̄ not in the result of that query, we are certain that the subformula is true anyway. In fact, an incomplete (cheaper) query inference can be applied, as any over-approximation will result in additional grounding, still maintaining correctness. The result is a ground FO(ID, AGG, PF, T) theory. Several optimizations for this step exist, as discussed in Jansen et al. [2014]; we discuss some of them below.

5.6.2.2    Simplification

To ensure models are generated that expand the input structure, not only the ground theory, but also the structure I₅ is passed to the search algorithm. Since we use a top-down grounding algorithm, we can optimize over this: whenever a domain atom or term is generated by instantiating variables, instead of using the atom or term itself its interpretation is filled in the grounding. For example, if a formula ∀x[t] : P(x) ∨ Q(x) is grounded in a structure with interpretations

T={1;2;3}

Pct = {1}

Qcf= {3}

a simplified grounding is

This sentence can be simplified even more, by propagating derived truth values upward, resulting in

and finally

These simplification techniques can have the effect that large parts of the theory do not need to be grounded. For example, consider a sentence ∀x[t] : P(x) ∨ φ(x), where φ might be a large formula. For all instantiations d of x for which P (d) holds, the formula P(d) ∨ φ(d) simplifies to t. Hence, φ(d) does not need to be grounded for such d.

5.6.2.3    Approximation and Lifted Unit Propagation

The following is a summary of the relevant results from Wittocx et al. [2010], Wittocx et al. [2013].

The above grounding algorithm exploits information in the input structure I using the query inference. Essentially, it grounds only the instances φ[d̄] of formulas that are unknown in I. As a consequence, more precise input structures I yield smaller groundings and increased search performance. This observation gave rise to the algorithms presented in Wittocx et al. [2010], where instead of using structure I₅ directly, we first compute a more precise structure I₆ that approximates all models of T₅ that expand I₅. Ideally, we would like to compute the most precise structure that is less precise than all models of T₅ that expand I₅. Of course, finding this ideal structure is a task that is even harder than the original problem.

Instead of searching for this ideal structure, IDP’s approach is to execute a lifted (approximative) version of the unit propagation that would occur after grounding. The result is stored as a symbolic representation of a structure. Namely, with each symbol P, we associate two symbolic set expressions Sct and Scf with intended meaning that in structure I₆, Pct, respectively, Pcf, is interpreted as respectively, Consider, for example, the following theory

Symbolic unit propagation then results in, e.g., a symbolic representation of I₆ that interprets Qct as {x | Pct (x) ∨ Rcf (x)} (the latter interpreted in I₅!), Rct as {x | Qcf (x)}. During the grounding phase, all queries for variable instantiations and the interpretation of atoms and terms are evaluated relative to this symbolic interpretation, resulting in fewer instantiations and more precise interpretations. For example, if P is interpreted in I₅, and Q and R are completely unknown in I₅, then the second sentence will only be instantiated for x’s such that P (x) is not true in I₅.

A symbolic representation of complete lifted unit presentation often consists of complex formulas, which are infeasible to query. However, any approximation of those formulas is sufficient, as long as the resulting structure is at least as precise as I₅. Consequently, the formulas are simplified to balance the estimated cost of querying against the expected reduction in number of answers.

5.6.2.4    Search

Optimization in IDP relies on the search algorithm MiniSAT(ID) [De Cat et al. 2013] for ground FO(ID, AGG, PF, T) theories. It takes the ground theory as input together with structure I₅. The algorithm combines techniques from SAT, constraint programming (CP), and answer set programming (ASP) through a DPLL(T) architecture [Ganzinger et al. 2004]. At the core lies the SAT-solver MiniSAT [Eén and Sörensson 2003], a complete, Boolean search algorithm for propositional clauses. This core is complemented by a range of “propagator” modules that take care of propagation for all other types of constraints in the theory, such as aggregates, definitions, and atoms containing functions. Each module is responsible for explaining its propagations in terms of the current assignment. For a definition Δ, for example, the module checks whether the current assignment satisfies Δ’s completion, whether the current assignment contains unfounded sets, and when a complete assignment is found, whether the structure is the well-founded model of Δ. Optimization is taken care of by a module that ensures the search space is visited in a branch-and-bound fashion. Whenever a model M is found, with value v the interpretation of c in M, a constraint c < v is added to the ground theory (which raises a conflict, leading to backtracking and additional search).

On the importance of CP integration. [De Cat et al. 2013, De Cat et al. 2014] In contrast to previous versions, the current version of MiniSAT(ID) supports ground FO(ID, AGG, PF, T) with function symbols. Function symbols are handled using techniques from constraint programming [Feydy and Stuckey 2009]. To illustrate the importance of having uninterpreted function symbols, consider the following birthday riddle.

Example 5.4 Consider the sentence “To determine my age, it suffices to know that my age in 2013 is halfway between two consecutive primes, that my age’s prime factors do not sum to a prime number, and that I was born in a prime year.” In the IDP language, it can be modeled as:

IDP is unable to ground this theory without using uninterpreted function symbols (this is controlled through the option cpsupport, discussed below) due to memory exhaustion. With uninterpreted constants, IDP takes half a second to find a solution. In fact, IDP proves that 48 different solutions exist; however, only one is an age below 100, namely Age = 26.

5.6.3    Post-Processing

As a final, post-processing step, structures returned by the search step are translated back to structures over V. Next, they are merged with I, output*-definitions are evaluated over them and finally, they are projected to Vout, resulting in structures Iout that are solutions to the original OPT 〈V, T, I, t, Vout〉 problem.

An output*-definition is only evaluated if evaluating it will have an effect on the eventual Vout-structure. If symmetry-breaking was applied, additional solutions can be generated by applying the symmetries to the solutions found.

5.6.4    Controlling the Optimization Workflow

Various components of the optimization workflow can be controlled using options. We provide a brief overview.

stdoptions.assumeconsistentinput default:false

If this option is true, the systems assumes that the input provided by the user is consistent and the consistency checks are skipped. Use at your own risk.

stdoptions.xsb default:true

If this option is true, input*-definitions are evaluated using the XSB Prolog system. Otherwise, they are evaluated using standard ground-and-solve techniques. We recommend to use XSB for efficiency reasons.

stdoptions.postprocessdefs default:true

This option controls whether output*-definitions are delayed until after search. In general, we recommend to turn this option on. However, since detection of output*-definitions is implemented through a bootstrapping approach, enabling might cause a small delay of up to a second. Hence, if your goal is to solve a large number of very small problems, we recommend to turn this off.

stdoptions.splitdefs default:true

This option controls whether definitions are split into minimal strata. As with the previous, we recommend to turn it on in most cases, unless when solving very small problems.

stdoptions.symmetrybreaking default:“none”

This option controls whether symmetries are broken and if they are broken, using which method. Currently, IDP only provides support for breaking symmetries statically, hence this option can be set either to “none” or to “static”. Future versions of IDP might also offer the choice “dynamic”. Whether symmetry breaking is beneficial strongly depends on the problem at hand.

stdoptions.reducedgrounding default:true

This option controls whether the grounding is simplified using information from the structure. We recommend enabling this option in most use cases.

stdoptions.groundwithbounds default:true

This option controls whether the grounding size is reduced using the approximation techniques described above. We recommend enabling this option in most use cases.

stdoptions.liftedunitpropagation default:true

This option controls whether the symbolic representation of the input structure (I₆) is evaluated in advance, resulting in a concrete representation of the input structure. We recommend enabling this option in most use cases.

stdoptions.cpsupport default:true

This option controls whether function symbols are allowed in the grounding. If turned off, the ground theory will be entirely propositional, if turned on, functions symbols can appear in the ground theory; they are then handled by constraint programming techniques. We recommend enabling this option in most use cases, except for hard combinatorial problems with a very small grounding.

stdoptions.cpgroundatoms default:false

This option controls whether function symbols are allowed to occur nested in the grounding. This is an advanced feature, with as advantage a smaller grounding, but as disadvantage possible loss of propagation. Whether enabling this option is beneficial strongly depends on the problem at hand.

stdoptions.functiondetection default:false

This option controls whether predicate symbols are automatically replaced by function symbols. Whether enabling this option is beneficial depends strongly on the problem at hand. For theories crafted by experts (and manually optimized), this option is probably not beneficial. The more naïve the theory is, the more potential benefit this option has. If this option is enabled, we recommend to also enable the cpsupport option.

stdoptions.nbmodels default:1

This option specifies the number of models that need to be returned by the optimization (or model expansion) inference.

stdoptions.verbosity default:0 (for all suboptions)

Suboptions of this option control the verbosity of various components in the workflow. This is used mainly for debugging purposes, e.g., to know which part of the solver is causing certain delays.

5.6.5    Scalability and Infinity

The reader might have noticed that structures and groundings can be very large or even infinite (for example, when a predicate or a quantified variable is typed over int). Model expansion (and thus, optimization) over infinite structures takes infinite time in general. In IDP, several techniques are applied to address this issue; they often work well in practice.

A first such technique has been explained in Section 5.6.2. By intelligent reasoning over the entire theory, we can sometimes derive better variable bounds. Suppose for example that a theory contains formulas ∀x[int] : P(x)⇒Q(x) and ∀y[int] : P(y)⇒R(y), where Q only ranges over a finite type, say T, but P and R range over int. The first of these sentences guarantees that P will only hold for values such that Q holds, hence P can only hold for values in the finite type T. Thus, we know that the second sentence should only be instantiated for y’s in T, i.e., by deriving an improved bound for y, the grounding of the second sentence suddenly becomes finite. The first sentence can be handled similarly. We only ground this sentence for y’s in T and maintain a symbolic interpretation expressing that P is certainly false outside of T.

Second, the usage of a top-down, depth-first grounding algorithm has the advantage that interpretations can be evaluated lazily: (i) instantiations of quantifications can be generated one at a time; and (ii) the interpretation of atoms and terms needs only to be retrieved for atoms and terms that effectively occur in the grounding. The same advantage applies for symbols that are interpreted by (complex) procedures: the procedures are only executed for relevant occurrences of that symbol.

Third, the search algorithm maintains bounds on the interpretation of function terms, taking constraints in the grounding into account. Consider a constant c : int, which in itself would result in an infinite search space. However, combined with, e.g., a constraint 0 ≤ c ≤ 10 in the grounding, the solver reduces c : int to c : [0, 10], a finite search space.

A fourth technique currently under development to increase scalability is Lazy Grounding [De Cat et al. 2015]. Lazy Grounding is based on the observation that the entire grounding often is not necessary to find solutions to a model expansion or optimization problem. Instead, the technique interleaves grounding with search as follows. Initially, it (roughly) splits the input theory into two parts: one part is grounded and the underlying solver performs its standard search algorithm on it. The other part of the theory is delayed: the system makes assumptions about it that guarantee that models found by the solver can be extended to models of the entire theory. Whenever these assumptions become violated, i.e., when they are inconsistent with the solver’s current assignment, the splitting of the theory is revised. Consider, for example, ∀x[int] : P(x)⇒φ with φ a possibly large formula; it has an infinite grounding. A smart lazy grounder could delay the grounding of that sentence with the assumption that P is false for all integers. During search, only when an atom P (d) becomes true is the sentence grounded for x = d and only that ground sentence is added to the search, the remainder still delayed on the assumption that P is false. Whenever the search algorithm finds a structure that satisfies the grounding and does not violate any assumptions, that structure can be straightforwardly extended to a model of the whole theory.

5.7    In Practice

Both IDP and its search algorithm MiniSAT(ID) are open-source systems, freely available from dtai.cs.kuleuven.be/krr/software. Next to accepting input in the IDP language, both systems provide C++ interfaces. The search algorithm MiniSAT(ID) supports input in Clausal Normal Form (CNF), Quantified Boolean Form (QBF, CNF’s higher-order relative) [Egly et al. 2000], ground ASP (in the LParse-Smodels intermediate format [Syrjänen 1998]), and FlatZinc [Nethercote et al. 2007].

IDP can be tried online in our web-IDE at http://dtai.cs.kuleuven.be/krr/idp-ide/. Several modeling examples are available in the web-IDE as well as at http://dtai.cs.kuleuven.be/software/idp/examples. The web-IDE also provides support for the visualizations of structures, as explained, e.g., in http://dtai.cs.kuleuven.be/krr/idpide/?chapter=intro/9-IDPD3.

The main usage of IDP3 is currently its model expansion inference, which as discussed earlier, is closely related to generating answer sets of logic programs and to solving constraint satisfaction problems. As such, it shares applications with those domains, general examples of which are scheduling, planning, verification and configuration problems. More concretely, some applications have been modeled in Bruynooghe et al. [2015], demonstrating its applicability as both an approach to replace procedural programming in some cases and as an approach to rapid prototyping due to the short development time. It has been used to analyze security issues in several contexts, with an emphasis on formal approaches that allow intuitive modeling of the involved knowledge [Decroix et al. 2013, Heyman 2013]. The model expansion engine, and various other types of inference, have been used for interactive configuration [Van Hertum et al. 2016, Van Hertum et al. 2017].

The performance of IDP has been demonstrated for example in the ASP competition series, in 2009 [Denecker et al. 2009] (IDP2), 2011 [Calimeri et al. 2014] (IDP2), 2013 [Alviano et al. 2013] (IDP3), and in [Bruynooghe et al. 2015], where it is compared to various existing approaches to specific problems. The performance of the search algorithm MiniSAT(ID) has been demonstrated in Amadini et al. [2013b], Amadini et al. [2013a], where it turned out to be the single-best solver in their MiniZinc portfolio, and in the latest Minizinc challenges [MinizincChallenge 2012]. In Bruynooghe et al. [2015], it is demonstrated that a KR system like IDP can be practically used as a front-end for lower-level solvers (e.g., SAT-solvers), instead of manually encoding problems in SAT or using custom scripting. Experimental results showed that IDP is able to relieve this burden with minimal performance loss and greatly reduced development effort.

IDP3 is used as a didactic tool in various logic-oriented courses at various universities.

5.8    Related Work

Within several domains, research is targeting expressive specification languages and (to a lesser extent) multiple inference techniques within one language. While we do not aim at an extensive survey of related languages (e.g., Marriott et al. [2008] has a section with such a survey), we do compare with a couple of them.

The B language [Abrial 1996], a successor of Z, is a formal specification language developed specifically for the generation of procedural code. It is based on first-order logic and set theory, and supports quantification over sets. Event-B is a variant for the specification of event-based applications. The language Zinc, developed by Marriott et al. [2008], is a successor of OPL and intended as a specification language for constraint programming applications (mainly CSP and COP solving). It is based on first-order logic, type theory, and constraint programming languages. Within ASP, a number of related languages, originating from logic programs, are being developed, such as Gringo [Gebser et al. 2009] and DLV [Leone et al. 2006]. They support definitional knowledge and default reasoning. Implementations exist for inference techniques like stable model generation (related to model expansion), visualization, optimization, and debugging. A comparison of ASP and FO(ID) can be found in [Denecker et al. 2012]. The language of the Alloy [Jackson 2002] system is basically first-order logic extended with relational algebra operators, but with an object-oriented syntax, making it more natural to express knowledge from application domains centered around agents and their roles, e.g., security analysis.

The following are alternative approaches to model expansion (or to closely related inference tasks). The solver-independent CP language Zinc [Marriott et al. 2008] is grounded to the language MiniZinc [Nethercote et al. 2007], supported by a range of search algorithms using various paradigms, as can be seen at www.minizinc.org/challenge2012/results2012.html. In the context of constraint ASP (CASP), several systems ground to ASP extended with constraint atoms, such as Clingcon [Ostrowski and Schaub 2012] and EZ(CSP) [Balduccini 2011]. For search, Clingcon combines the ASP solver Clasp [Gebser et al. 2012b] with the CSP solver Gecode [Gecode Team 2013], while EZ(CSP) combines an off-the-shelf ASP solver with an off-the-shelf CLP-Prolog system. The prototype CASP solver Inca [Drescher and Walsh 2012] searches for answer sets of a ground CASP program by applying lazy clause generation (LCG) for arithmetic and all-different constraints. As opposed to extending the search algorithm, a different approach is to transform a CASP program to a pure ASP program [Drescher and Walsh 2011], afterward applying any off-the-shelf ASP solver. CASP languages generally only allow a restricted set of expressions to occur in constraint atoms and impose conditions on where constraint atoms can occur. For example, none of the languages allows general atoms P(c̄) P being an uninterpreted predicate symbol. One exception is AC(C), a language aimed at integrating ASP and Constraint Logic Programming [Mellarkod et al. 2008]. As shown in Lierler [2012], the language captures the languages of both Clingcon and EZ(CSP); however, only subsets of the language are implemented [Gelfond et al. 2008].

5.9    Conclusion

Kowalski’s [1974] paper laid the foundations for the field of Logic Programming, by giving the Horn-clause subset of predicate logic a procedural interpretation to use it for programming. More recently, progress in automated reasoning in fields such as SAT and CP made the exploration possible of more pure forms of declarative programming, gradually moving from declarative programming to declarative modeling, in which the user only has to care about the problem specification.

In this chapter, we took this development one step further and presented the knowledge base system IDP, in which knowledge is separated from computation. The knowledge representation language is both natural and extensible, cleanly integrating first-order logic with definitions, aggregates, etc. It provides a range of inference engines and functionalities for tasks encountered often in practice.

IDP is an extensible framework for declarative modeling, in which both language extensions and inference engines can be added with relative ease. It focuses on moving the burden of performance on modeling from the user to the system, demonstrated by the workflow of optimization inference, which is achieved by combining insights from fields such as SAT, constraint programming, logic programming, and answer set programming.

References

J.-R. Abrial. 1996. The B-book: Assigning Programs to Meanings. Cambridge University Press, New York. 322

J.-R. Abrial, M. J. Butler, S. Hallerstede, T. S. Hoang, F. Mehta, and L. Voisin. 2010. Rodin: An open toolset for modeling and reasoning in Event-B. STTT, 12(6): 447–466. DOI: 10.1007/s10009-010-0145-y. 287

F. A. Aloul, K. A. Sakallah, and I. L. Markov. 2006. Efficient symmetry breaking for Boolean satisfiability. IEEE Transactions on Computers, 55(5): 549–558. DOI: 10.1109/TC.2006.75. 313

M. Alviano, F. Calimeri, G. Charwat, M. Dao-Tran, C. Dodaro, G. Ianni, T. Krennwallner, M. Kronegger, J. Oetsch, A. Pfandler, J. Pührer, C. Redl, F. Ricca,

P. Schneider, M. Schwengerer, L. K. Spendier, J. P. Wallner, and G. Xiao. 2013. The fourth Answer Set Programming competition: Preliminary report. In P. Cabalar and T. C. Son, editors, Logic Programming and Nonmonotonic Reasoning, 12th International Conference, LPNMR 2013, Corunna, Spain, September 15–19, 2013. Proceedings, vol. 8148 of LNCS, pp. 42–53. Springer. DOI: 10.1007/978-3-642-40564-8_5. 321

R. Amadini, M. Gabbrielli, and J. Mauro. 2013a. Features for building CSP portfolio solvers. CoRR, abs/1308.0227. 321

R. Amadini, M. Gabbrielli, and J. Mauro. 2013b. An empirical evaluation of portfolios approaches for solving CSPs. In C. P. Gomes and M. Sellmann, editors, CPAIOR, vol. 7874 of Lecture Notes in Computer Science, pp. 316–324. Springer. DOI: 10.1007/978-3-642-38171-3_21. 321

M. Balduccini. 2011. Industrial-size scheduling with ASP+CP. In J. P. Delgrande and W. Faber, editors, LPNMR, vol. 6645 of Lecture Notes in Computer Science, pp. 284–296. Springer. DOI: 10.1007/978-3-642-20895-9_33. 322

M. Bartholomew and J. Lee. 2012. Stable models of formulas with intensional functions. In Brewka et al. [2012]. http://www.aaai.org/ocs/index.php/KR/KR12/paper/view/4559. 304

B. Bogaerts, J. Jansen, M. Bruynooghe, B. De Cat, J. Vennekens, and M. Denecker. 7 2014a. Simulating dynamic systems using linear time calculus theories. Theory and Practice of Logic Programming, 14(4–5): 477–492. DOI: 10.1017/S1471068414000155. 308

B. Bogaerts, B. De Cat, S. De Pooter, and M. Denecker, 2012. The IDP framework reference manual. http://dtai.cs.kuleuven.be/krr/files/bib/manuals/idp3-manual.pdf. 298, 303, 306

B. Bogaerts, J. Jansen, B. De Cat, G. Janssens, M. Bruynooghe, and M. Denecker. 2016. Bootstrapping inference in the IDP Knowledge Base System, New Generation Computing, 34(3): 193–220. 311, 312

G. Brewka, T. Eiter, and S. A. McIlraith, editors 2012. Principles of Knowledge Representation and Reasoning: Proceedings of the Thirteenth International Conference, KR 2012, Rome, Italy, June 10-14, 2012. AAAI Press. 324, 328

M. Bruynooghe, H. Blockeel, B. Bogaerts, B. De Cat, S. De Pooter, J. Jansen, A. Labarre, J. Ramon, M. Denecker, and S. Verwer. November 2015. Predicate logic as a modeling language: modeling and solving some machine learning and data mining problems with IDP3. Theory and Practice of Logic Programming, 15(6): 783–817. DOI: 10.1017/S147106841400009X. 282, 303, 321

W. Buchholz, S. Feferman, W. Pohlers, and W. Sieg. 1981. Iterated Inductive Definitions and Subsystems of Analysis: Recent Proof-Theoretical Studies, vol. 897 of Lecture Notes in Mathematics. Springer. 290, 291

F. Calimeri, G. Ianni, and F. Ricca. 2014. The third open answer set programming competition. Theory and Practice of Logic Programming, 14(1): 117–135. DOI: 10.1017/S1471068412000105. 321

W. Chen and D. S. Warren. 1996. Tabled evaluation with delaying for general logic programs. Journal of the ACM, 43(1): 20–74. DOI: 10.1145/227595.227597. 284

K. L. Clark. 1978. Negation as failure. In Logic and Data Bases, pp. 293–322. Plenum Press. 280

B. De Cat, B. Bogaerts, J. Devriendt, and M. Denecker. 2013. Model expansion in the presence of function symbols using constraint programming. In 2013 IEEE 25th International Conference on Tools with Artificial Intelligence, Herndon, VA, USA, November 4-6, 2013, pp. 1068–1075. IEEE Computer Society. DOI: 10.1109/ICTAI.2013.159. 283, 313, 315, 316

B. De Cat, B. Bogaerts, and M. Denecker, Sept. 2014. MiniSAT(ID) for satisfiability checking and constraint solving. ALP Newsletter. http://lirias.kuleuven.be/handle/123456789/463884. 316

B. De Cat and M. Bruynooghe. 2013. Detection and exploitation of functional dependencies for model generation. Theory and Practice of Logic Programming, 13(4–5): 471–485. DOI: 10.1017/S147106841300029X. 283, 296, 308, 312

B. De Cat, M. Denecker, M. Bruynooghe, and P. J. Stuckey. 2015. Lazy model expansion: Interleaving grounding with search. Journal of Artificial Intelligence Research (JAIR), 52: 235–286. DOI: 10.1613/jair.4591. 320

S. De Pooter, J. Wittocx, and M. Denecker. 2011. A prototype of a knowledge-based programming environment. CoRR, abs/1108.5667. DOI: 10.1007/978-3-642-41524-1_16. 283

K. Decroix, J. Lapon, B. De Decker, and V. Naessens. 2013. A formal approach for inspecting privacy and trust in advanced electronic services. In J. Jürjens, B. Livshits, and R. Scandariato, editors, ESSoS, vol. 7781 of LNCS, pp. 155–170. Springer. DOI: 10.1007/978-3-642-36563-8_11. 321

M. Deinum, J. Long, G. Mak, and D. Rubio. 2014. Spring Annotation Driven Core Tasks, pp. 135–216. Apress, Berkeley, CA. DOI: 10.1007/978-1-4302-5909-1_3. 282

M. Denecker. 1998. The well-founded semantics is the principle of inductive definition. In J. Dix, L. F. del Cerro, and U. Furbach, editors, JELIA, vol. 1489 of LNCS, pp. 1–16. Springer. DOI: 10.1007/3-540-49545-2_1. 281, 291

M. Denecker. 2000. Extending classical logic with inductive definitions. In J. W. Lloyd, V. Dahl, U. Furbach, M. Kerber, K.-K. Lau, C. Palamidessi, L. M. Pereira, Y. Sagiv, and P. J. Stuckey, editors, CL, vol. 1861 of LNCS, pp. 703–717. Springer. DOI: 10.1007/3-540-44957-4_47. 281

M. Denecker, M. Bruynooghe, and V. Marek. 2001. Logic programming revisited: Logic programs as inductive definitions. ACM Transactions on Computational Logic, 2(4): 623–654. DOI: 10.1145/383779.383789. 281, 291

M. Denecker and E. Ternovska. Apr. 2008. A logic of nonmonotone inductive definitions. ACM Transactions on Computational Logic, 9(2): 14:1–14:52. DOI: 10.1145/1342991.1342998. 289

M. Denecker and J. Vennekens. 2007. Well-founded semantics and the algebraic theory of non-monotone inductive definitions. In C. Baral, G. Brewka, and J. S. Schlipf, editors, LPNMR, vol. 4483 of Lecture Notes in Computer Science, pp. 84–96. Springer. DOI:10.1007/978-3-540-72200-7_9. 291, 292

M. Denecker and J. Vennekens. 2008. Building a knowledge base system for an integration of logic programming and classical logic. In M. García de la Banda and E. Pontelli, editors, ICLP, vol. 5366 of LNCS, pp. 71–76. Springer. DOI: 10.1007/978-3-540-89982-2_12. 282

M. Denecker and J. Vennekens. 2014. The well-founded semantics is the principle of inductive definition, revisited. In C. Baral, G. De Giacomo, and T. Eiter, editors, Principles of Knowledge Representation and Reasoning: Proceedings of the Fourteenth International Conference, pp. 1–10. AAAI Press. http://www.aaai.org/ocs/index.php/KR/KR14/paper/view/7957. 281, 290, 291

M. Denecker, Y. Lierler, M. Truszczyński, and J. Vennekens. 2012. A Tarskian informal semantics for answer set programming. In Dovier and Costa [2012], pp. 277–289. DOI: 10.4230/LIPIcs.ICLP.2012.277. 322

M. Denecker, J. Vennekens, S. Bond, M. Gebser, and M. Truszczyński. 2009. The second answer set programming competition. In Erdem et al. [2009], pp. 637–654. DOI: 10.1007/978-3-642-04238-6_75. 321

J. Devriendt, B. Bogaerts, M. Bruynooghe, and M. Denecker. 2016a. On local domain symmetry for model expansion. Theory and Practice of Logic Programming, 16(5-6): 636–652. DOI: 10.1017/S1471068416000508. 313

J. Devriendt, B. Bogaerts, M. Bruynooghe, and M. Denecker. 2016b. Improved static symmetry breaking for SAT. In N. Creignou and D. L. Berre, editors, Theory and Applications of Satisfiability Testing - SAT 2016 - 19th International Conference, Bordeaux, France, July 5-8, 2016, Proceedings, vol. 9710 of Lecture Notes in Computer Science, pp. 104–122. Springer. DOI: 10.1007/978-3-319-40970-2_8. 296, 313

J. Devriendt, B. Bogaerts, B. De Cat, M. Denecker, and C. Mears. 2012. Symmetry propagation: Improved dynamic symmetry breaking in SAT. In IEEE 24th International Conference on Tools with Artificial Intelligence, ICTAI 2012, Athens, Greece, November 7-9, 2012, pp. 49–56. IEEE Computer Society. DOI: 10.1109/ICTAI.2012.16. 283, 296, 308, 313

A. Dovier and V. S. Costa, editors 2012. Technical Communications of the 28th International Conference on Logic Programming, ICLP 2012, September 4–8, 2012, Budapest, Hungary. Proceedings, vol. 17 of LIPIcs. Schloss Dagstuhl - Leibniz-Zentrum fuer Informatik. 326

C. Drescher and T. Walsh. 2011. Translation-based constraint answer set solving. In T. Walsh, editor, IJCAI, pp. 2596–2601. IJCAI/AAAI. DOI: 10.5591/978-1-57735-516-8/IJCAI11-432. 322

C. Drescher and T. Walsh. 2012. Answer set solving with lazy nogood generation. In Dovier and Costa [2012], pp. 188–200. DOI: 10.4230/LIPIcs.ICLP.2012.188. 322

D. East and M. Truszczyński. 2006. Predicate-calculus-based logics for modeling and solving search problems. ACM Transactions on Computational Logic, 7(1): 38–83. DOI: 10.1145/1119439.1119441. 309

N. Eén and N. Sörensson. 2003. An extensible SAT-solver. In E. Giunchiglia and A. Tacchella, editors, SAT, vol. 2919 of LNCS, pp. 502–518. Springer. DOI: 10.1007/978-3-540-24605-3_37. 315

U. Egly, T. Eiter, H. Tompits, and S. Woltran. 2000. Solving advanced reasoning tasks using quantified Boolean formulas. In Proceedings of the Seventeenth National Conference on Artificial Intelligence and Twelfth Conference on Innovative Applications of Artificial Intelligence, pp. 417–422. AAAI Press. 321

E. Erdem, F. Lin, and T. Schaub, editors 2009. Logic Programming and Nonmonotonic Reasoning, 10th International Conference, LPNMR 2009, Potsdam, Germany, September 14-18, 2009. Proceedings, vol. 5753 of LNCS. Springer. 326, 327

T. Feydy and P. J. Stuckey. 2009. Lazy clause generation reengineered. In Gent [2009], pp. 352–366. DOI: 10.1007/978-3-642-04244-7_29. 316

A. M. Frisch and P. J. Stuckey. 2009. The proper treatment of undefinedness in constraint languages. In Gent [2009], pp. 367–382. DOI: 10.1007/978-3-642-04244-7_30. 286, 287

H. Ganzinger, G. Hagen, R. Nieuwenhuis, A. Oliveras, and C. Tinelli. 2004. DPLL(T): fast decision procedures. In R. Alur and D. Peled, editors, Computer Aided Verification, 16th International Conference, CAV 2004, Boston, MA, USA, July 13-17, 2004, Proceedings, vol. 3114 of LNCS, pp. 175–188. Springer. DOI: 10.1007/978-3-540-27813-9_14. 315

M. Gebser, R. Kaminski, B. Kaufmann, and T. Schaub. 2012a. Answer Set Solving in Practice. Synthesis Lectures on Artificial Intelligence and Machine Learning. Morgan & Claypool Publishers. DOI: 10.2200/S00457ED1V01Y201211AIM019. 282

M. Gebser, R. Kaminski, M. Ostrowski, T. Schaub, and S. Thiele. 2009. On the input language of ASP grounder Gringo. In Erdem et al. [2009], pp. 502–508. DOI: 10.1007/978-3-642-04238-6_49. 322

M. Gebser, B. Kaufmann, and T. Schaub. 2012b. Conflict-driven answer set solving: From theory to practice. Artificial Intelligence, 187: 52–89. DOI: 10.1016/j.artint.2012.04.001. 322

Gecode Team, 2013. Gecode: Generic constraint development environment. Available from http://www.gecode.org. 322

M. Gelfond and V. Lifschitz. 1988. The stable model semantics for logic programming. In R. A. Kowalski and K. A. Bowen, editors, ICLP/SLP, pp. 1070–1080. MIT Press. http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.24.6050. 280

M. Gelfond and V. Lifschitz. 1991. Classical negation in logic programs and disjunctive databases. New Generation Computing, 9(3/4): 365–386. 280

M. Gelfond, V. S. Mellarkod, and Y. Zhang. 2008. Systems integrating answer set programming and constraint programming. In M. Denecker, editor, Second Workshop on Logic and Search, 2008, pp. 145–152. ACCO. 323

I. P. Gent, editor 2009. Principles and Practice of Constraint Programming - CP 2009, 15th International Conference, CP 2009, Lisbon, Portugal, September 20-24, 2009, Proceedings, vol. 5732 of Lecture Notes in Computer Science. Springer. DOI: 10.1007/978-3-642-04244-7. 327

T. Heyman. Mar 2013. A Formal Analysis Technique for Secure Software Architectures. Ph.D. thesis, Department of Computer Science, KU Leuven. http://lirias.kuleuven.be/handle/123456789/389365. 321

R. Ierusalimschy, L. Henrique de Figueiredo, and W. Celes. 1996. Lua – an extensible extension language. Software: Practice and Experience, 26(6): 635–652. DOI: 10.1002/(SICI)1097-024X(199606)26:6<635::AID-SPE26>3.0.CO;2-P. 283, 297, 302

D. Jackson. 2002. Alloy: A lightweight object modeling notation. ACM Transactions on Software Engineering and Methodology (TOSEM’02), 11(2): 256–290. DOI: 10.1145/505145.505149. 322

J. Jansen, I. Dasseville, J. Devriendt, and G. Janssens. 2014. Experimental evaluation of a state-of-the-art grounder. In O. Chitil, A. King, and O. Danvy, editors, Proceedings of the 16th International Symposium on Principles and Practice of Declarative Programming, Kent, Canterbury, United Kingdom, September 8-10, 2014, pp. 249–258. ACM. DOI: 10.1145/2643135.2643149. 314

J. Jansen, A. Jorissen, and G. Janssens. 2013. Compiling input* FO(.) inductive definitions into tabled Prolog rules for IDP3. Theory and Practice of Logic Programming, 13(4–5): 691–704. DOI: 10.1017/S1471068413000434. 296, 308, 311, 312

R. A. Kowalski. 1974. Predicate logic as programming language. In IFIP Congress, pp. 569–574. 279, 323

N. Leone, G. Pfeifer, W. Faber, T. Eiter, G. Gottlob, S. Perri, and F. Scarcello. 2006. The DLV system for knowledge representation and reasoning. ACM Transactions on Computational Logic, 7(3): 499–562. DOI: 10.1145/1149114.1149117. 322

Y. Lierler. 2012. On the relation of constraint answer set programming languages and algorithms. In J. Hoffmann and B. Selman, editors, AAAI. AAAI Press. 322

V. Lifschitz. 2012. Logic programs with intensional functions. In Brewka et al. [2012]. 304

J. W. Lloyd. 1987. Foundations of Logic Programming, 2nd Ed.. Springer. 284

K. Marriott, N. Nethercote, R. Rafeh, P. J. Stuckey, M. Garcia de la Banda, and M. Wallace. 2008. The design of the Zinc modeling language. Constraints, 13(3): 229–267. DOI: 10.1007/s10601-008-9041-4. 322

V. S. Mellarkod, M. Gelfond, and Y. Zhang. 2008. Integrating answer set programming and constraint logic programming. Annals of Mathematics and Artificial Intelligence, 53(1-4): 251–287. DOI: http://dx.doi.org/10.1007/s10472-009-9116-y. 322

Minizinc challenge 2012. http://www.minizinc.org/challenge2012/results2012.html. 321

D. G. Mitchell and E. Ternovska. 2005. A framework for representing and solving NP search problems. In M. M. Veloso and S. Kambhampati, editors, AAAI, pp. 430–435. AAAI Press/The MIT Press. http://www.aaai.org/Library/AAAI/2005/aaai05-068.php. 285, 309

N. Nethercote, P. J. Stuckey, R. Becket, S. Brand, G. J. Duck, and G. Tack. 2007. Minizinc: Towards a standard CP modeling language. In C. Bessiere, editor, CP’07, vol. 4741 of LNCS, pp. 529–543. Springer. DOI: 10.1007/978-3-540-74970-7_38. 321, 322

M. Ostrowski and T. Schaub. 2012. ASP modulo CSP: The clingcon system. Theory and Practice of Logic Programming, 12(4–5): 485–503. DOI: 10.1017/S1471068412000142. 322

P. Pialorsi and M. Russo. 2007. Introducing Microsoft® Linq. Microsoft Press, Redmond, WA. 282

B. C. Pierce. 2002. Types and Programming Languages. MIT Press, Cambridge, MA. 293

T. Syrjänen. 1998. Implementation of local grounding for logic programs with stable model semantics. Technical Report B18, Helsinki University of Technology, Finland. 321

A. Van Gelder. 1993. The alternating fixpoint of logic programs with negation. Journal of Computer and System Sciences, 47(1): 185–221. DOI: 10.1145/73721.73722. 280, 291

A. Van Gelder, K. A. Ross, and J. S. Schlipf. 1991. The well-founded semantics for general logic programs. Journal of the ACM, 38(3): 620–650. DOI: 10.1145/116825.116838. 280, 291, 292, 293

P. Van Hertum, I. Dasseville, G. Janssens, and M. Denecker. 2016. The KB paradigm and its application to interactive configuration. In M. Gavanelli and J. H. Reppy, editors, Practical Aspects of Declarative Languages - 18th International Symposium, PADL 2016, St. Petersburg, FL, USA, January 18-19, 2016. Proceedings, vol. 9585 of Lecture Notes in Computer Science, pp. 13–29. Springer. DOI: 10.1007/978-3-319-28228-2_2. 321

P. Van Hertum, I. Dasseville, G. Janssens, and M. Denecker. 2017. The KB paradigm and its application to interactive configuration. Theory and Practice of Logic Programming, 17(1): 91–117. DOI: 10.1017/S1471068416000156. 321

D. Warren, 2014. One semantics for logic programming. http://www.linkedin.com/pulse/one-semantics-logic-programming-david-warren. 284

C. Weidenbach, D. Dimova, A. Fietzke, R. Kumar, M. Suda, and P. Wischnewski. 2009. SPASS version 3.5. In R. A. Schmidt, editor, CADE, vol. 5663 of LNCS, pp. 140–145. Springer. http://dx.doi.org/10.1007/978-3-642-02959-2_10. 308

J. Wittocx. May 2010. Finite Domain and Symbolic Inference Methods for Extensions of First-Order Logic. Ph.D. thesis, Department of Computer Science, K.U. Leuven, Leuven, Belgium. 286, 311

J. Wittocx, M. Denecker, and M. Bruynooghe. Aug. 2013. Constraint propagation for firstorder logic and inductive definitions. ACM Transactions on Computational Logic, 14(3): 17:1–17:45. DOI: 10.1145/2499937.2499938. 314

J. Wittocx, M. Mariën, and M. Denecker. 2010. Grounding FO and FO(ID) with bounds. Journal of Artificial Intelligence Research (JAIR), 38: 223–269. 283, 314

1. This is the logical implication φ ⇒ ψ that is interpreted as ¬φ ∨ ψ.

2. In this text, we use the names recursive definition and inductive definition interchangeably.

3. Given a logical theory and a structure interpreting the domain of discourse, model expansion searches for a model of the theory that extends the structure.

4. The current implementation of the IDP language, described in Section 5.4, has only limited support for integer division.

5. In the infinite case, a similar sequence can be constructed. For details, see Denecker and Vennekens [2007].

6. Autocompletion may derive missing type domains, e.g., in the absence of a domain for age, autocompletion will derive {19, 25, 30} for it, in absence of a domain for person, it will derive the union of the student and instructor domains.

7. The IDE at http://dtai.cs.kuleuven.be/krr/idp-ide/visualizes the symbols in the syntax of FO(ID, AGG, PF, T).

8. The define keyword is optional; it emphasizes that the brackets { and } are delimiters of a definition.

9. If within the same scope a variable appears in argument positions with different types, the inferred type is their least supertype if it exists, otherwise a type error is raised, as explained in Section 5.2.6. If no type can be inferred, e.g., as in !x: x=x, also then an error is raised.

10. Here, the notation coloring/1:1 means that coloring has arity one (/1) and is a function, i.e., has one output argument (:1).

11. Note that satisfiability checking reduces to model checking in case S is two-valued.

12. This is done by translating it to a logic program and using XSB.

6

SolverBlox: Algebraic Modeling in Datalog

Conrado Borraz-Sánchez, Diego Klabjan, Emir Pasalic, Molham Aref

Datalog is a deductive query language for relational databases. We introduce LogiQL, a language based on Datalog and show how it can be used to specify mixed-integer linear optimization models and solve them. Unlike pure algebraic modeling languages, LogiQL allows the user to both specify models, and manipulate and transform the inputs and outputs of the models. This is an advantage over conventional optimization modeling languages that rely on reading data via plug-in tools or importing data from external sources via files. In this chapter, we give a brief overview of LogiQL and describe two mixed integer programming case studies: a production-transportation model and a formulation of the traveling salesman problem.

6.1    Introduction

Solutions to many real world problems can be formulated as mathematical programs [Bradley et al. 1977]. Such problems are usually tackled by first building a model, and then converting the model and the corresponding data into a low-level problem instance. The instance can then be solved by a solver that returns a solution for further analysis and use.

One of the biggest challenges throughout the entire modeling and solution process is dealing with large amounts and diverse representations of data. One might even argue that mathematical modeling is mainly about data [Hultberg 2007] and should therefore be driven by data. A mathematical programming modeling language could be made more useful if it had facilities for declarative, expressive pre- and post-processing of data, especially at scales facilitated by database management systems.

Algebraic Modeling Languages (AML) are often used to develop mathematical programming applications. AMLs allow the user to write models in a clear and concise mathematically motivated notation. Commonly used AMLs include AIMMS (Advanced Integrated Multidimensional Modeling Software) [Bisschop 1993], GAMS (General Algebraic Modeling System) [Brook et al. 1988, GAMS 2008], AMPL (A Modeling Language for Mathematical Programming) [Fourer et al. 1993], FLOPC++ (Formulation of Linear Optimization Problems in C++) [Hultberg 2007], ILOG Concert and OPL Technologies [ILOG 2016], and optimization platforms from MSF [Microsoft 2018] (Microsoft Solver Foundation) (see Borraz-Sánchez [2010] for a recent comparison among different AMLs).

While several specialized AML systems provide plug-ins for database access, such languages cannot be used to declaratively pre-process input data and post-process the results of model optimization. These languages also do not support efficient re-optimization based on incremental changes to input data, or changes to the model itself. There seems to be three general approaches to putting together algebraic modeling, optimization, and data manipulation.

1.  Adding libraries and application programming interfaces to existing, usually imperative, languages such as C++ and Python, and relying on their native semantics to provide for the manipulation of data and generation of instances [Gurobi Optimization, Inc. 2016, Hultberg 2007, Hart et al. 2011, ILOG 2016, Barth and Bockmayr 1997].

2.  Implementing a domain specific language for algebraic modeling which may contain some additional constructs for data manipulation, and combination of data with model specification (e.g., Fourer et al. [1993], GAMS [2008], and Bisschop [1993]).

3.  Enhancing an existing declarative or query language with support for solvers (e.g., SQL-based AMLs [Atamturk et al. 2000, Choobineh 1991]).

In this chapter, we have opted for the third approach. We start with LogiQL, a purely declarative language based on Datalog. Our language design is guided by three principles.

1.  We ensure that after adding support for algebraic modeling, the resulting language remains declarative. The syntactic changes to the resulting language are minimal. In fact, they consist of only one new language construct (a second-order existential quantifier [Mancini 2004]) together with some syntactic sugar.

In this setting, the programmer does not need to learn any new language constructs, and the specification of model constraints and objective function reuses the syntax already found in our implementation of LogiQL [Aref et al. 2015].

2.  We ensure that the semantics of the existing constructs the user uses to specify the model remains compatible with Datalog: addition of mathematical programming can be treated as an alternative, but logically valid, strategy for finding models of a set of clauses. The result of any LogiQL program that uses mathematical programming features remains a valid logical model of all clauses (and constraints) in that program.

3.  We ensure that the details of grounding (creating a solvable problem instance by combining the high-level model with data) are hidden from the programmer. We also encapsulate the programming details of solver interaction into a system-level layer of our implementation, providing the user with an identical declarative interface to multiple solvers.

Datalog is primarily a database query language. By adding a second-order existential quantifier [Mancini 2004], we can increase its expressiveness to encompass the entire class of NP-complete problems, while maintaining the advantages of a relational database system: the ability to efficiently query and manipulate large sets of data, and then combine the results of data manipulation with the creation and solving of mathematical programming models.

We present two small case studies (production-transportation and traveling salesman) to illustrate the practical use of our language extensions.

The organization of this chapter is as follows. In Section 6.2, we give a short introduction to Datalog, which makes up the foundation of our language design and implementation. In Section 6.3, we present the fundamentals of LogiQL, and illustrate its use for solving mathematical programming problems (Section 6.4). In Section 6.5, we present another example of using LogiQL algebraic modeling facilities, and illustrate how native LogiQL’s data-manipulation capabilities can be combined with algebraic modeling. We conclude in Section 6.6.

6.2    Datalog

Before we proceed to describe our language LogiQL and its implementation (Section 6.3), we briefly comment on Datalog [Maier and Warren 1988], a language which serves as the basis of our language design and implementation. One may think of the relationship of our language LogiQL to Datalog the way that functional languages are related to the lambda calculus—a number of concrete systems and implementations, including ours, have used Datalog as its departure point, both in research [de Moor et al. 2011, Alvaro et al. 2010, Arenas et al. 2010, Eisner and Filardo 2010, Huang et al. 2011, Smaragdakis and Bravenboer 2010] and industrial [Chin et al. 2015, Eve 2018, Aref et al. 2015] settings.

Datalog is a rule-based query language for deductive database queries. The rules are used to specify declaratively the logical structure of the computation’s result (the what), rather than step-by step algorithmic details of computing it (the how). The specifics of how the rule logic is executed correspond to the details of the implementation of a computation engine for the language.

Syntactically, Datalog is a subset of Prolog [Colmerauer and Roussel 1993, Kowalski 1988]. A Datalog program consists of a set of clauses of the form:

At first glance, the most visible difference between Prolog and Datalog is the lack of function symbols in the arguments to predicates. Additional syntactic conditions are imposed on Datalog programs such as stratification, and certain conditions on the use of negation [Abiteboul et al. 1995]. Furthermore, variables that appear in the head of the rule, must also appear in the body of the rule. In other words, variables in the head (conclusion) of the rule cannot be existentially quantified to prevent the system from having to make a choice for their value and then ensuring the consistency of that choice across the entire logical interpretation of the Datalog program.¹

Given these restrictions, Datalog can be given set-based semantics in which each rule-specified predicate can be given an interpretation as a finite relation. Every program terminates, with strong guarantees about the complexity behavior of Datalog programs’ execution. This means that some algorithms cannot be expressed. This is a language design choice; unlike a number of other logic programming languages, Datalog is primarily a database query language designed for the retrieval and management of data in relational database management systems.

6.3    LogicBlox and LogiQL

The ideas presented in this chapter are implemented in a database and software development platform called LogicBlox [LogicBlox 2016]. The platform is designed to build enterprise-scale applications featuring analyses that require computation across very large data sets possibly combined with simulation, predictive analytics, and prescriptive analytics, and declaratively specified user interfaces. At the core of the LogicBlox platform is the language LogiQL, based on Datalog. In the rest of this section, we introduce the fundamental concepts of the LogicBlox platform.

Workspaces. The LogicBlox platform is a database management system in which a LogicBlox server manages one or more workspaces. A workspace is a database instance that contains: (a) currently populated values of predicates, which are analogous to tables containing data in relational database management systems; and (b) active program, which comprises a collection of the logical rules (analogous to database views in traditional relational databases), and constraints whose logical integrity is always maintained by the LogicBlox platform.

LogiQL. A LogiQL program consists of a number of logical statements called clauses. A clause is composed of a head and a body (optional). The user’s interaction with the workspace is managed through LogiQL’s modularity constructs, called blocks. A block is syntactically complete LogiQL program fragment which is submitted to the platform and, after compilation and type-checking, may be integrated into the active program and schema of a workspace.

Transactions. The interaction between the LogicBlox workspace and the user proceeds over time through a series of commands (most of which are executed in transactions).

Commands include operations such as:

Installing a block. Adding a set of clauses in a LogiQL block to an active program maintained by the database.

Executing a block. Evaluating a set of clauses in a LogiQL block one time (without permanently incorporating its rules into the active program) for the purpose of updating the data stored in the workspace, or returning the results of the block as a query.

Removing a block. Removing a set of clauses in a LogiQL block from the active program and deleting any data that may have been derived from it, and updating the state of the database to be logically consistent with the remaining active program.

Querying contents. Querying the contents of a predicate.

Interacting with a workspace, the user can create new relations (predicates), populate them with values, specify calculations to be performed, and formulate queries against the stored data. Each transaction has the standard database ACID properties (Atomicity, Consistency, Isolation, Durability): all commands executed in a transaction are guaranteed an atomic, and consistent view of the database, isolated from any other commands initiated by other concurrent users. At the end of the transaction, the active program is evaluated and, if logically consistent, any changes made by it are durably stored in the database (transaction commits). Should the commands cause inconsistency (for example, by violating database constraints), the transaction is aborted and the workspace reverts to the (consistent) state before the transaction had been initiated.

Incrementality. Computation in LogicBlox is incremental: rather than re-computing entire relations from scratch every time a change in other relations’ data occurs, the LogicBlox system computes a minimal set of changes to the existing relations that is sufficient to maintain the logical consistency of the database. For each relation, the evaluation engine computes a set of insertions, assertions, or retractions which are combined with the existing data stored in the database. The algorithms used for this form of evaluation have the theoretical property that “the work done is proportional to the trace edit distance between the before and after computations” [Aref et al. 2015].

6.3.1    LogiQL By Example

Predicates. All information in a LogicBlox workspace is organized using predicates, which denote relations between finite entities (user-defined types) or built-in value types (such as strings, integers, dates, and so on). A predicate has a finite number of arguments (arity). Syntactically, a predicate can be written as either P (t₁, …, tn), representing an n-ary relation, or P [t₁, …, tn−1] = tn, representing an n-ary relation in which tn functionally depends on t₁, …, tn−1.

A predicate can be derived (also called intensional, or (IDB), if it is computed as a result of a rule; it is extensional (EDB), if it is given as an input to the database. Whether or not a predicate is IDB or EDB is inferred by the LogicBlox system. While IDB predicates are always populated by the system as a result of LogiQL computation, the EDB predicates may be populated either by executing a block, or by extra-logical means (e.g., by tools that import predicates from flat files, tools that provide a logic-based interface to web services, and so on).

Derivation Rules. Derived (IDB) predicates in a LogiQL program denote relations that logically satisfy (model) a set of rules. For example, the predicate city_in_state is defined by the following rule that states that a city belongs to the same state that its county belongs to:

Every rule consists of a head formula (city_in_state[city]=state)) and a body formula (city_in_county(city,cnt), county_in_state[cnt]=state).

Formulas consist of atoms (e.g., city_in_county(city,cnt)), combined with connectives such as conjunction (,), disjunction (;), or negation (!). Rules may use recursion:

Two cities are connected if either there is a direct road connection between them (has_road), or if there is some city c3 to which c1 is connected and which is itself connected to c2.

A general mechanism of higher-order rules, called predicate to predicate mappings (P2Ps), specifies relationships among predicates not easily expressed in first-order logic. This effectively overrides the semantics of the standard logical implication (←) with a custom-defined implementation (provided by the implementers of the LogicBlox platform²). Most commonly, a set of built-in P2Ps are used in LogiQL to express aggregations. For example, the following rule calculates, for every county, the total population of all the cities belonging to that county:

In general, for any aggregation P2P rule of the following form:

The aggregation P2P finds all possible logically valid instantiations of variables x₁, …, xn, common to the body and head. Then, for each such instantiation of xs, it finds all valid instantiations of the variables in the body formula B(…, y₁, …, ym) together with the value of the expression E[…, y₁, …, ym]. Then the operator ⊕ (e.g., +, min, max, etc.) is applied over all such values of the expression E, for each set of xs.

Reactive Rules. A type of LogiQL rules, called reactive, can be used to detect and make changes to the database state by referring to versioned predicates and delta predicates [Ludäscher 1998 (for detailed discussion)]. A simple example of a reactive rule would be

When executed against an existing workspace, the above rule adds a new city, Atlanta, to two predicates containing city names and populations.

Reactive rules allow the programmer to declaratively specify modifications to the database in terms of logical specification of changes to predicates in a Datalog program. This is expressed in term of operators on predicates that allow the logic to refer to versions of predicates at different phases of the LogiQL program execution: for a LogiQL predicate p, the predicates p@prev, +p, ^p and -p refer, respectively, the facts of p that: (a) were true at the end of the previous transaction; (b) become true at the end of the transaction; (c) change from beginning to end of the transaction (i.e., if p is a functional predicate of the form p[ … ]=v); or (d) will no longer be true when the transaction ends. The LogiQL implementation ensures the logical consistency of rule referring to these by inserting, removing, or modifying ground facts of (EDB) predicates.

Reactive rules can also be installed:

The first rule above states that a city whose population declines below a thousand inhabitants should change its description to a village.³ The second rule states that once the city’s population declines below 100, it is no longer in the real_cities unary relation, but should also be added to the relation hamlets.

Constraints. In addition to rules, LogiQL allows the users to state integrity constraints. A constraint (usually written with implication arrow (->)) is a logical statement about what must be true in a workspace. For example:

The above clause can be seen as a constraint imposed on the predicate parent stating that in any instance of the workspace, if x is the parent of y, then y cannot be parent of x. Integrity constraints can be translated to rules whose head is the logical falsity, and whose body is the negation of the meaning of the constraint. Applying some standard logical equivalences, the LogicBlox compiler rewrites the above as:

(i.e., whenever x is a parent of y, and y is a parent of x, then false). Since the LogicBlox system ensures that all clauses (rules) in the active program are consistent (i.e., that falsity can never be derived), the rule above states situations in which the active program cannot be evaluated to produce a consistent database. Practically, that means that any transaction that tries to insert data that violates the constraint above will be aborted, and the state of the workspace restored to the (previously consistent) state before the start of the transaction.

Another common use of integrity constraints is to give type constraints, where unary predicates tn are used as types:

The LogicBlox compiler statically checks the validity of type constraints for LogiQL programs. Because LogiQL is a strongly typed language, the runtime evaluation of type constraints in well typed programs is unnecessary and incurs no runtime overhead in LogicBlox. Similarly, because integrity constraints make statements that are valid in any instance of a workspace, both the LogiQL compiler and the execution engine may use them to perform (compile-or run-time) optimizations on LogiQL programs.

6.4    Mathematical Programming with LogiQL

In this section, we describe a minimal set of extensions to the syntax and semantics of LogiQL (so far described) that turn it into an algebraic modeling language which allows the programmer to specify, solve, and make use of the results of linear mixed integer programming problems. We comment on our language design and implementation, and proceed to illustrate our discussion with an example mathematical programming problem.

A mathematical programming model contains elements such as sets, indices, parameters, decision variables, objectives, constraints, and algebraic expressions. An example might be the following linear programming problem:

subject to

The problem above consists of three parts.

1.  A number of sets and relations (e.g., D, R, C), variables (xij, y), and parameters (cij) that may be indexed by elements of those sets and relations.

2.  A specification of an objective function as an expression over a set of variables, and parameters which themselves may be indexed by some collection of sets and/or relations and combined with summation operators.

3.  A collection of constraints consisting of equalities and inequalities between expressions. The constraints may themselves be indexed by elements of various sets or relations.

Such a model expresses a family of mathematical programming instances that can be instantiated for concrete values of D,C,R, and c and then solved using a linear programming solver. The syntax of AMLs is designed to be as similar as possible to such textbook algebraic mathematical notations, so as to facilitate a clear and concise representations of mathematical programming problems, while allowing automatic synthesis of concrete solver instances.

The key insight in using LogiQL as an algebraic modeling language is that there is a natural conceptual mapping between the components of a mathematical model as described above and existing features of LogiQL.

•  Index sets and relations naturally map to LogiQL predicates. In particular, the full power of LogiQL’s rules can be leveraged to manipulate index sets and relations, making models concise and easy to understand.

•  Model parameters such as cij can be naturally mapped to numerical-valued LogiQL functional predicates (c[i,j]=v).

•  Model constraints are mapped to LogiQL integrity constraints over predicates representing variables and parameters.

•  Indexed operators such as summation can be mapped to LogiQL aggregations.

•  The objective function can be mapped to a predicate whose value is the value of the optimization function.

•  Mathematical programming variables such as xij and y can also be mapped to LogiQL predicates, albeit of a special kind: this is where we extend the standard Datalog semantics of LogiQL with a form of a second-order existential quantifier [Mancini 2004]. To define the concrete values for x[i,j] and y[], corresponding to the variables xij and y in the mathematical problem, we do not write a set of derivation rules in LogiQL. Rather, we assert that predicates exist, so that they (a) maximize (or minimize) the objective function and (b) satisfy all the model integrity constraints. It is at that point up to the LogiQL implementation to find relations that model those predicates, and that satisfy those conditions.

Note that once such a predicate is found and instantiated with concrete values, the standard semantics of LogiQL can evaluate the objective function, and check that the integrity constraints are satisfied by the solution.

In what follows, we will illustrate these mappings on a concrete example, and then comment on how support for (linear) mixed integer programming is implemented in LogicBlox.

6.4.1    Algebraic Modeling of a Production-Transportation Model in LogiQL

The production-transportation model [Dantzig 1963, Brook et al. 1988, Pochet and Wolsey 2006] is used to find the least cost production-shipping plan that meets demand requirements at markets and supplies at production sites. Suppose that steel products can be made at several mills, from which they are shipped to customers at various factories. For each mill, we need to decide the amount of each product to make. For each product, given a mill as the origin and a factory as the destination, we need to find out the amount of product to be shipped. The model is parameterized by data describing the costs, capacities, and demands.

We start the model by defining the sets of products (PROD), origins (ORIG), and destinations (DEST). As parameters, we are given rate as the tons produced per hour at the origins, avail as the hours available at origins, demand as amounts required at destinations, makeCost as manufacturing costs per ton of a product produced at an origin, and transCost as shipment costs per ton of a particular product shipped from an origin to a destination.

There are two kinds of decision variables: Make is the number of tons each product to be produced at an origin; and Trans is the number of tons of each product to be shipped from an origin to a destination. The mathematical model can then be formulated as follows:

The objective function to be minimized (Eq. 6.1) is the sum of total costs of manufacturing and shipping. There are three kinds of constraints: time constraints (Eq. 6.2) imposed by the number of hours available at each origin; supply constraints (Eq. 6.3) imposed by capacity restrictions; and demand constraints (Eq. 6.4) imposed by the amount of each product required at each destination.

In AMLs, the data of a specific instance of a mathematical programming model consists of index sets and parameters. An index relates to a data item, which typically is either a coefficient or a variable. For example, in the production-transportation model, the PROD set can consist of three types of items: bands, coils, and plate. In LogiQL we model such index sets by unary relations such as the PROD entity:

For convenience, we also declare a predicate PROD:name⁴ which assigns a name string to each element of the PROD set (entity). Similarly, we declare the other two sets: ORIG and DEST.

In our model, the avail parameter is indexed over ORIG and we declare the

Moreover, since the rate parameter is indexed over more than one set (ORIG and PROD), we declare the predicate rate to have the following type:

Analogously, we declare the remaining parameters of the model as follows:

In LogiQL, variables are existentially quantified functional predicates which may be indexed by keys of index-set types, and have a value of the float type. In the model we have two types of variables, one related to production and the other one related to transportation. We complete the declaration part of the model by declaring the decision variables:

The only difference between variables and parameters is an additional declaration which informs the LogiQL compiler that predicates Make and Trans are existentially quantified and to be solved for:

This syntax is the syntactic sugar for the existential quantifier over the predicates (which also happens to bind the quantified predicates to the names Make and Trans outside of the scope of the quantification and therefore makes it easier to refer to them from external queries).

Next, constraints in the mathematical programming models are directly represented by integrity constraints in LogiQL, with a minor variation that summation expressions are explicitly named (as predicates), and defined in terms of aggregations. For example, we first define:

The aggregation states that for any origin o, the total number of hours for production is the sum over all products p multiplied by the 1/rate for that product at the given origin o.

Finally, constraint (6.2) of the production-transportation problem is written in LogiQL as the following integrity constraint:

The constraint states that for all origins o, t1, the sum total of production time spent at o, must be less than equal than t2, the amount of available production time at o.

The supply and demand constraints can be modeled as follows:

The objective function is similarly defined in terms of aggregations over decision variables: both production and transportation costs. The production costs are computed by aggregation over the variable Make and parameter makeCost. Transportation costs are computed by aggregating over the variable Trans and the parameter transCost. The total cost (TotalCost) is defined as the sum of TotalMakeCost and TotalTransCost:

Finally, we use a declaration to tell the LogiQL compiler that the predicate TotalCost represents the objective function to be minimized:

Figure 6.1    Visualization of transportation production problem for a particular database instantiation.

The above clauses form the entire program block comprising the full model of the transportation-production problem in LogiQL. Figure 6.1 shows a visualization of a particular solution (implemented as a web application in LogicBlox), given a set of inputs in the database. One additional point is worth noting. Given a particular state of the database, the implementation solves the problem and populates the variable predicates with the current definition of sets, parameters, and relations referred to in the model. Suppose, however, we executed the following LogiQL rule, retracting the cities of Boise and Seattle from the set of production facilities (the EDB predicate ORIG):

By the semantics of LogiQL, the retraction of two elements from the entity predicate ORIG would retract those elements from all predicates that have those particular entity values, and logically invalidate the current solutions for the Make and Trans. This, in turn, forces the installed program to be (incrementally) recomputed, the instance to be re-solved and a new set of values asserted into the predicates Make and Trans, obtaining the visualisation in the Figure 6.1(b).⁵

6.4.2    Optimization in LogiQL: Implementation Notes

Implementing the algebraic modeling extensions for mixed integer programming in LogiQL reduces to implementing a concrete search algorithm for finding values of the second-order existential quantifier (restricted to linear/integer programming constraints), and integrating it into the LogicBlox platform. Recall that, given an objective function, and a set of constraint clauses, our task is to compute a set of (variable) predicates’ domains and codomains for concrete instantiations of the database. This proceeds in two steps.

Grounding. An instance suitable for solving with a linear programming solver is usually represented as a triple consisting of a vector c, a matrix A and vector b such that

The process of turning an algebraically specified problem into such a triple (or similar representation) is called grounding and involves figuring out the size of the various vectors and matrices, assigning indexed variables (e.g., MakeAtlanta, Plate) to an index in the vector x), and constructing the constraint matrix A and bounds b. A key feature of our implementation is that we choose to represent the instance (c, A, b) as a collection of relations stored in the LogicBlox workspace:

The grounding implementation then reduces to a program-to-program transformation which takes the original problem P, specified in LogiQL (as in production-transformation example above), and transforms it into another LogiQL program P′. Part of this process involves a static check over the source program that the constraints over existentially quantified predicates belong to the subset of constraints for which a Mixed Integer Programming (MIP) solver can find a correct instance. For example, the compiler would reject arbitrary nonlinear constraints over Make and Transport because (as of yet) we have implemented no effective method of finding a model for the existentially quantified predicates that satisfy them. Once generated, the problem P′ contains

•  A set of compiler-generated rules that populate predicates such as matrix, bound and objective.

•  A rule using a new built-in P2P solve which takes predicates matrix, bound and objective as its inputs, invokes the solver, and populates the predicate solution:

•  A set of rules that, using auxiliary predicates computed as part of the grounding, maps elements of solution back to the original variable predicates. For example, using generated predicates for domains and index maps, those rules might look as follows:

With the exception of the new built-in solve, the generated program P′ is in pure LogiQL, and is evaluated incrementally. For example, changing a particular value in the demand predicate will not recompute the entire instance matrix, but only modify one of the elements of the bound predicate. Thus, when expressed in LogiQL, the instance grounding implementation benefits from highly optimized and efficient Datalog evaluation engine in the LogicBlox platform [LogicBlox 2016].

Solving. Support for concrete solvers consists of the implementation (in the lower layers of the LogicBlox platform, implemented in C++) of the single P2P mapping solve, a relatively isolated addition to the overall LogicBlox runtime. When invoked in the course of LogiQL evaluation, solve P2P reads the contents of the grounded instance predicates, and marshals them through an a solver API translation layer with adaptors for individual solvers. This way, we are able to support several different MIP solvers (for example, Gurobi Optimization, Inc. [2016], COIN-OR Branch and Cut (CBC) [IBM Research 2005], or any solver supported by Optimization Services Instance Language (OSiL) [Ma 2005]).

Figure 6.2    Constraints used in MIP formulations of TSP (DFJ and MTZ versions).

6.5    The Traveling Salesman Problem (TSP) Test Case

The Traveling Salesman Problem (TSP) is one of the most intensively studied combinatorial optimization problems in computational mathematics specifically because it is so easy to describe and so difficult to solve: given an arc-weighted complete graph G = (V, A, c), where V is the set of nodes (cities), A is the set of arcs linking a pair of cities i, j ∈ V, and c : V × V ↦ ℝ⁺ is the cost function assigning each (i, j) ∈ A weight cij, the problem is to find a minimum weight tour in G.

MIP formulations aimed to solve the TSP are, among others, due to Dantzig et al. [1954] (DFJ model) and Miller et al. [1960] (MTZ model). The DFJ model (Figure 6.2, Equations 6.5–6.8 and 6.12) is an extension of a simple assignment model (a set of tours through the graph) with the addition of (exponentially many) subtours elimination constraints (ensuring that disconnected tours are not allowed). Since the number of proper subsets (Equation 6.12) of the set of vertices V is exponential in the number of vertices, the DFJ model requires a row generation procedure that basically generates one row after another with one design variable column only, thus providing in advance associated dual variables for each linking constraints (row). The MTZ (Equations 6.5–6.11), on the other hand, breaks subtours with fewer constraints by making use of an extra variable ui for each node i, resulting in a number of constraints that is quadratic in the size of the problem. In a language without imperative constructs such as LogiQL, the MTZ model is much easier and cleaner to implement, and will form the basis of our exposition.⁶ However, we will nevertheless show how a technique [Pataki 2003] combining the two approaches can be implemented cleanly and declaratively, with very small amount of extra code, and be used to leverage LogiQL to perform the needed data manipulation. Such a full LogiQL model is written out in Figure 6.3. Note that the model is a hybrid of MTZ and DFJ: it implements both pure MTZ and DFJ models (or a combination), depending on the contents of the predicates final_step and subtour: if the predicate final_step is false, Equations 6.9–6.11 are inactive, leaving us only with Equations 6.6–6.8 and 6.12, which specify just the subtour constraints (assuming that the subtour type contains all possible/valid subtours). Combining the two approaches to TSP is implemented in LogiQL as follows: we start with an (initially empty set of subsets of V′ (called subtour in the LogiQL code), which form subtours found in previous assignment (Equations 6.7–6.8). A condition predicate final_step guards the constraints 6.9-6.11 so that unless it is set to true, those constraints remain inactive. Each iterative step takes one LogicBlox transaction: given a set of vertices (predicate city_local), we compute the variable Xij, obtaining a graph between cities i and j, where each edge is Xij[i,j]=1.

Immediately, in the same transaction, an installed block from Figure 6.4(a) is used to compute a set of subtours in that graph (by first computing the set of cities reachable from every city and grouping the reachable cities together in a tour). This computes the set of new subtours computed by the current solution that will be added to the subtour predicate in the next step. To advance to the next step, we execute the logic in Figure 6.4(b), updating the subtour predicate, which forces re-solving of the problem, and so on.⁷ The iterations can be performed some predetermined number of steps, or until only one subtour containing all the nodes is found. After a certain number of iterative steps, we assert the predicate final_step, turning on the MTZ constraints (together with any subtour constraints we have accumulated already). This heuristic can considerably speed the solution of the overall TSP problem [Pataki 2003]. While still basically only of didactic value, this example allows us to comment on several aspects of LogiQL modeling environment.

Figure 6.3    The traveling salesman problem (hybrid) code. (Parts of the LogiQL code that directly correspond to mathematical programming constraints are shown in a slanted font.)

Figure 6.4    All the code needed (in addition to the model changes) to implement iterative TSP solution by adding subtours.

•  Each step of the iterative algorithm is performed in a different transaction. The set of subtours is modeled as an EDB entity to which we incrementally add new elements and relations. At each step of the process, the model is fully sound and consistent with the data in the database.

•  We use an installed LogiQL block (Figure 6.4(a)) to identify subtours at the end of every round of solving. This is a purely declarative specification of identifying subtours, expressed as a set of (recursive) LogiQL rules, leveraging the expressiveness of Datalog to succinctly express many graph-based queries.

•  The use of a guarded (EDB) trigger predicate final_step() to prevent the grounding of the MTZ-specific constraints until we are ready to fully solve the problem in the final step. This modeling technique allows us to declaratively specify a set of two related models whose behavior is logically consistent and easily controllable by the user.

•  Incremental evaluation/grounding can be of considerable help in solving this particular problem. At the end of each transaction, LogicBlox workspace contains the previous instance as a set of materialized predicates. When a new set of subtour constraints is added, the system need not re-ground the parts of the instance that are used for assignment and previous-step subtour constraints. Only deltas that add new rows are actually computed, stored in the database, with the cost of grounding (partially) amortized across a number of transactions/iteration steps.

Figure 6.5 shows an example of running the program above through 8 iteration transactions, on a set of 200 U.S. cities. We start in step 0 with no subtours. Each subsequent transaction adds more subtours to the set of constraints, incrementally, re-solves problem, and prepares for the next step by computing the current set of subtours to be added. Finally, we execute the clause +final_step() in the eighth transaction to obtain the result in the final image (second row of Figure 6.5). The second row of Figure 6.5 shows two final results: the image on the left shows the result with the incrementally added subtour elimination constraints and the image on the right shows the solution without subtour constraints. We solved the final problem with an MIP Solver (Gurobi 7.0.1), giving the solver a fixed time budget to produce the solution with the lowest optimality gap it can find. In the allotted time, the solver produces a much better quality solution for the hybrid iterative model presented here, as visual inspection of the second row will confirm.

Figure 6.5    Iterative Traveling Salesman Problem with 200 cities. Gradually eliminating subtours, re-grounding, re-solving, and deriving new subtour constraints (8 steps). Final results of hybrid vs. pure MTZ algorithms: reached (2.7%/34.3%) optimality gap, using Gurobi 7.0.1 solver with the time budget of 3,600 seconds on a 4-core Intel Core i7 processor with 16 GB of memory. On average each iterative step took 14.5 s.

6.6    Conclusions and Future Work

The current implementation is limited to linear and mixed-integer programming, but it is intended to be enhanced with support for additional types of optimization problems and a wider range of solvers such as quadratic programming to meta-heuristics methods. We are currently experimenting with including support for Satisfiability (SAT) and Satisfiability Modulo Theories (SMT) solvers. (Details on these solvers can be found in, e.g., Ganesh [2007] and Jha et al. [2009].)

References

S. Abiteboul, R. Hull, and V. Vianu. 1995. Foundations of Databases. Addison-Wesley. 334

P. Alvaro, W. R. Marczak, N. Conway, J. M. Hellerstein, D. Maier, and R. Sears. 2010. Dedalus: Datalog in time and space. In de Moor et al. [2011], pp. 262–281. DOI: 10.1007/978-3-642-24206-9_16. 334

M. Aref, B. ten Cate, T. J. Green, B. Kimelfeld, D. Olteanu, E. Pasalic, T. L. Veldhuizen, and G. Washburn. 2015. Design and implementation of the logicblox system. In Proceedings of the 2015 ACM SIGMOD International Conference on Management of Data, SIGMOD ’15, pp. 1371–1382. ACM, New York. DOI: 10.1145/2723372.2742796. 333, 334, 336

M. Arenas, P. Barceló, and J. L. Reutter. 2010. Datalog as a query language for data exchange systems. In de Moor et al. [2011], pp. 302–320. DOI: 10.1007/978-3-642-24206-9_18. 334

A. Atamturk, E. L. Johnson, J. T. Linderoth, and M. W. P. Savelsbergh. 2000. A relational modeling system for linear and integer programming. Operations Research, 48(6): 846–857. DOI: 10.1287/opre.48.6.846.12388. 332

P. Barth and A. Bockmayr. 1997. PLAM: Prolog and algebraic modelling. In Proceedings of the 5th International Conference on the Practical Application of Prolog, pp. 73–82. The Practical Application Company, London, UK. 332

J. Bisschop, 1993. Paragon Decision Technology, AIMMS. http://www.aimms.com. 332

C. Borraz-Sánchez. 2010. Optimization Methods for Pipeline Transportation of Natural Gas. Ph.D. thesis, Department of Informatics, University of Bergen, Norway. 332

S. P. Bradley, A. C. Hax, and T. L. Magnanti. 1977. Applied Mathematical Programming. Addison Wesley. 331

A. Brook, D. Kendrick, and A. Meeraus. December 1988. Gams, a user’s guide. SIGNUM Newsletter, 23(3-4): 10–11. DOI: 10.1145/58859.58863. 332, 341

B. Chin, D. von Dincklage, V. Ercegovac, P. Hawkins, M. S. Miller, F. Och, C. Olston, and F. Pereira. 2015. Yedalog: Exploring knowledge at scale. In 1st Summit on Advances in Programming Languages (SNAPL 2015), pp. 63–78. Dagstuhl, Germany. 334

J. Choobineh. 1991. Sqlmp: A data sublanguage for representation and formulation of linear mathematical models. ORSA Journal on Computing, 3(4): 358–375. DOI: 10.1287/ijoc.3.4.358. 332

A. Colmerauer and P. Roussel. March 1993. The birth of Prolog. SIGPLAN Notices, 28(3): 37–52. DOI: 10.1145/155360.155362. 334

G. Dantzig. 1963. Linear Programming and Extensions. Rand Corporation Research Study. Princeton University Press, Princeton, NJ. 341

G. Dantzig, R. Fulkerson, and S. Johnson. 1954. Solution of a large-scale traveling-salesman problem. Operations Research, 2: 393–410. DOI: 10.1007/978-3-540-68279-0_1. 348

O. de Moor, G. Gottlob, T. Furche, and A. J. Sellers, editors. 2011. Datalog Reloaded—First International Workshop, Datalog 2010, Oxford, UK, March 16-19, 2010. Revised Selected Papers, vol. 6702 of Lecture Notes in Computer Science. Springer. DOI: 10.1007/978-3-642-24206-9. 334, 354, 355, 356

J. Eisner and N. W. Filardo. 2010. Dyna: Extending datalog for modern AI. In de Moor et al. [2011], pp. 181–220. DOI: 10.1007/978-3-642-24206-9_11. 334

Eve. 2018. http://www.witheve.com. 334

R. Fourer, D. Gay, and B. Kernighan. 1993. AMPL: A Modeling Language for Mathematical Programming. Scientific Press. 332

GAMS. 2008. GAMS: The Solver Manuals. GAMS Development Corporation. 332

V. Ganesh. 2007. Decision Procedures for Bit-vectors, Arrays and Integers. Ph.D. thesis, Computer Science Department, Stanford University, Stanford, CA. 354

Gurobi Optimization, Inc., 2016. Gurobi Optimizer Reference Manual. http://www.gurobi.com. 332, 347

W. E. Hart, J.-P. Watson, and D. L. Woodruff. 2011. Pyomo: modeling and solving mathematical programs in python. Mathematical Programming Computation, 3(3): 219–260. DOI: 10.1007/s12532-011-0026-8. 332

S. S. Huang, T. J. Green, and B. T. Loo. 2011. Datalog and emerging applications: An interactive tutorial. In Proceedings of the 2011 ACM SIGMOD International Conference on Management of Data, SIGMOD ’11, pp. 1213–1216. ACM, New York. DOI: 10.1145/1989323.1989456. 334

T. H. Hultberg. 2007. Flopc++ an algebraic modeling language embedded in c++. In K.-H. Waldmann and U. M. Stocker, editors, Operations Research Proceedings 2006, pp. 187–190. Springer Berlin Heidelberg, Berlin, Heidelberg. DOI: 10.1007/978-3-540-69995-8_31. 331, 332

IBM Research, 2005. Coin-or branch and cut, cbc solver. An open-source mixed-integer program solver. 347

ILOG, 2016. Ilog. http://www.ilog.com/products. 332

S. Jha, R. Limaye, and S. A. Seshia. 2009. Beaver: Engineering an efficient smt solver for bitvector arithmetic. In A. Bouajjani and O. Maler, editors, Computer Aided Verification, pp. 668–674. Springer Berlin Heidelberg, Berlin, Heidelberg. DOI: 10.1007/978-3-642-02658-4_53. 354

R. A. Kowalski. January 1988. The early years of logic programming. Communications of the ACM, 31(1): 38–43. DOI: 10.1145/35043.35046. 334

LogicBlox. 2016. Logicblox Inc. http://www.logicblox.com. 335, 347

B. Ludäscher. 1998. Integration of Active and Deductive Database Rules. Ph.D. thesis, Institut fur Informatik, Universitat Freiburg. 338

J. Ma. 2005. Optimization Services (OS), a General Framework for Optimization Modeling Systems. Ph.D. thesis, Department of Industrial Engineering & Management Sciences, Northwestern University, Evanston, IL. 347

D. Maier and D. S. Warren. 1988. Computing with Logic: Logic Programming with Prolog. Benjamin-Cummings Publishing Co., Inc., Redwood City, CA. 333

T. Mancini. 2004. Declarative Constraint Modelling and Specification-Level Reasoning. Ph.D. thesis, Sapienza University of Rome. 333, 341

Microsoft. 2018. Microsoft Solver Foundation. http://code.msdn.microsoft.com/solver foundation. 332

C. Miller, A. Tucker, and R. Zemlin. 1960. Integer programming formulations of traveling salesman problems. Journal of the ACM, 7(4): 326–329. DOI: 10.1145/321043.321046. 348

G. Pataki. 2003. Teaching integer programming formulations using the traveling salesman problem. SIAM Review, 45: 116–123. DOI: 10.1137/S00361445023685. 349, 352

Y. Pochet and L. A. Wolsey. 2006. Production Planning by Mixed Integer Programming. Springer-Verlag New York, Inc., Secaucus, NJ. 341

Y. Smaragdakis and M. Bravenboer. 2010. Using datalog for fast and easy program analysis. In de Moor et al. [2011], pp. 245–251. DOI: 10.1007/978-3-642-24206-9_14. 334

1. In our implementation of LogiQL we may relax this restriction to a subset of existentially quantified rules for which choices do not lead to these undesirable situations. The full discussion is outside of the scope of this chapter (see Aref et al. [2015]).

2. As extra logical features of the language, implemented primitively in the lower layers of the LogicBlox platform, any P2P’s implementation must satisfy certain meta-theoretical assumptions that would make it compatible with the semantics of LogiQL in general. To preserve consistency and safety, these must be assured by the platform implementers for each P2P implementation.

3. More pedantically, it states that whenever a change to the value of the city_population predicate for a given city c occurs, and the changed value is less than 1,000, the value of the city_description predicate for this city should be set to “village”. The change to cit_population may occur through some other executed rules, by loading data through a user interface, or in some other way.

4. Note that the symbol “:” is lexically just a part of the name of PROD:name.

5. An additional subtlety of all this is that the LogiQL semantics is closed world and the second-order existential quantifier finds both the domain and codomain of the variable predicate under that assumption. Thus, the facts in Make are those and only those that are derived from the application of mathematical problem instance, and while no constraints are implicitly invalidated, the facts corresponding to Seattle, and all subsequent elements of the instance deriving from them are nevertheless retracted from the re-computed model of the database.

6. We do not implement, yet, in LogiQL the ability to lazily add constraints to a model during the branch-and-bound search of the solver itself, something we would need to implement most such row-generation algorithms. An additional problem with implementing such algorithm is that they are difficult to separate from the particulars of the APIs for individual solvers, breaking the abstractions of the AML formulation of the model.

7. The main idea behind the code in Figure 6.4 is as follows. The relation reachable represents the reachability relation between any two nodes, by the edges in Xij that have been assigned the value 1. Next, for every city c2 we compute the smallest (by some arbitrary measure, such as city ID) reachable city from it. This city will be used as a representative of an equivalence class of all nodes that are mutually reachable with it. We next assert that there exists a new subtour for every such representative node, thus, creating an element of new_subtour for every set of mutually reachable nodes. In the update step (Figure 6.4(b)) we use the built-in operator seq to sort newly created subtours so that we can assign them a unique identifying number consisting of the greatest identifying number of existing subtours plus the sorted order of the new subtour being added. This way we assign a unique ID to every new subtour without clashing with existing IDs.

PART III

APPLICATIONS

7

Exploring Life: Answer Set Programming in Bioinformatics

Alessandro Dal Palù, Agostino Dovier, Andrea Formisano, Enrico Pontelli

This chapter provides a broad overview of how logic programming, and more specifically Answer Set Programming (ASP), can be used to model and solve some popular and challenging classes of problems in the general domain of bioinformatics. In particular, the chapter explores the use of ASP in Genomics studies, such as Haplotype inference and Phylogenetic inference, in Structural studies, such as RNA secondary structure prediction and Protein structure prediction, and in Systems Biology. The chapter offers a brief introduction to biology and bioinformatics and working ASP code fragments for the various problems investigated. The chapter serves a dual role: (1) it offers a declarative characterization of a number of core problems in bioinformatics, making them easily understandable; and (2) it provides an “entry point” to the extensive literature on the use of logic-based methods to address such bioinformatics problems, by offering the basic modeling of the problem and pointers to the relevant literature.

7.1    Introduction

Recent advances in the field of Biology extensively rely on computational methods to model, simulate, and sift through dauntingly large data repositories. From the Computer Science point of view, the synergistic interaction with biologists, physicists, chemistry researchers, medical clinicians, etc. has provided computer scientists with a broad range of challenging problems.

Part of the computer scientist’s work is to devise a clear computational model of the phenomenon of interest. This usually requires several cycles of feedback with experts in the field. Subsequently, the selection of appropriate resolution strategies allows researchers to have an effective resolution of these problems, with the potential of having a profound impact on our ability to understand the basic mechanisms of life and to advance medical research. Moreover, available data is typically huge and suffer from several kinds of experimental errors; computer science tools help in analyzing and properly filtering this data. Bioinformatics can be broadly defined as an area of Computer Science that deals with modeling and solving problems, analyzing and filtering data, from biology and related life sciences.

In very broad strokes, we can classify typical bioinformatics application domains in three general categories. The first class includes applications of computational methods as a support infrastructure for analysis and experiments; this is the case, for example, of automated environments for workflow management, description and annotation of experiments, minimal reporting requirements (e.g., MIAME [Brazma et al. 2001]), etc. The second class includes problems that are efficiently solvable (e.g., in polynomial time), but commonly applied to very large data sets (e.g., BLAST searches and other string matching problems [Altschul et al. 1990, Gusfield 1997, Gonnet 2004]). Finally, the third class includes problems that are intractable (i.e., NP-complete or worse), even under simplifying assumptions; this is the case, for example, of problems related to ab-initio protein structure prediction and to synthesis of gene regulatory networks.

Bioinformatics problems can also be classified according to the target of the study. Genomics studies focus on the investigation of genomes; genomic studies often rely on tractable algorithms applied to very large amounts of data, such as DNA (Deoxyribonucleic Acid) and RNA (Ribonucleic Acid) sequences. Structural studies focus on the prediction and recognition of the spatial structure of biomolecules (e.g., proteins); problems in this class are often intractable and based on data sets that are smaller than those used in genomic studies. Systems studies (a.k.a. systems biology) investigate the complex interactions among components (e.g., genes) of a biological system; these studies typically belong to high complexity classes. The interested reader can refer to [Clote and Backofen 2001, Lesk 2008, Xia 2007] for an introduction to computational biology.

The literature has highlighted the potential for logic programming technology to address problems in all of these areas (see, e.g., Barahona et al. [2011]). Prolog and other logic programming paradigms have been employed in supporting workflow management—e.g., data formats interoperation, service composition (e.g., Pan et al. [2010])—and querying tasks—e.g., querying phylogenetic databases [Chisham et al. 2011]. Nevertheless, the capabilities of logic programming—especially Constraint Logic Programming (CLP) and Answer Set Programming (ASP)—to tackle complex combinatorial problems make this paradigm particularly appealing to address problems in the third class. Logic programming offers some distinct advantages, in particular the following.

•  Models are rarely stable and static—logic programming provides the level of elaboration-tolerance to support model modifications and incremental addition of new knowledge.

•  The use of more traditional techniques, such as linear programming, is often inadequate (e.g., incapable of capturing the complexity of realistic energy models).

In this chapter, we will provide a broad overview of how ASP can be used to model and solve some popular and challenging classes of Bioinformatics problems. The purpose of this presentation is twofold. First, the use of a declarative formalism allows us to provide an elegant characterization of these complex problems, and a useful formalization that can be adapted for different problem solving approaches. The second benefit of this survey is to offer an entry point to the rich literature on the use of logic programming methods in bioinformatics, by providing an intuitive and elegant description of the original formalization, removed from the complexities of scalable implementations.

In particular, we will explore ASP in the following kinds of studies.

Genomics studies. We will investigate problems associated with Haplotype inference and Phylogenetic inference.

Structural studies. We will investigate problems associated with RNA secondary structure prediction and Protein structure prediction.

Systems studies. We will investigate problems associated with reasoning about biological networks.

This chapter represents a coherent synthesis of previous research contributions (as found in the literature, including some of the authors’ own work) as well as novel problem formalizations. We also provide a brief survey of other logic programming contribution to Bioinformatics (see section 7.9). This chapter also builds on the experience gained by organizing the Workshop on Constraint-based Methods in Bioinformatics yearly from 2005 (see, e.g., http://clp.dimi.uniud.it/wcb), and related publications (e.g., Dal Palù et al. [2007], Dal Palù et al. [2008], Backofen et al. [2012]).

7.2    Biology in a Nutshell

We give here a short introduction to Biology for Computer Science. We refer the reader to classical Biological books or to Clote and Backofen [2001], Cohen [2004], Gusfield [1997], and Jones and Pevzner [2004] for more details.

A key theory, known as the central dogma of Biology, was introduced in Crick [1958] and then refined in Crick [1970] and describes how the biologically relevant information migrates from DNA sequences to RNA sequences, and from RNA sequences to proteins, whose function is determined by their 3D structure. Information cannot be transferred back from proteins. The conversion DNA ↪ RNA is called transcription, while the conversion RNA ↪ Protein is called translation. Reverse transcription (from RNA to DNA) is also possible, but this topic is beyond the focus of this chapter. Let us briefly review the above notions in order to understand the central dogma.

DNA is characterized by a sequence of nucleotides of 4 kinds: A, C, G, and T (Adenine, Cytosine, Guanine, Thymine). The nucleotides have a different atomic composition, omitted here; however they share a common substructure that is used to connect sequences of nucleotides into polymeric strands of potentially unlimited length. Typically, DNA strands have a high propensity to pair: two strands can be aligned and facing nucleotides, one from each strand, can form a relatively stable binding. Some nucleotide matchings are more favorable than others; in particular, there is a notion of complementary string. Precisely, given a sequence s ∈ {A, C, G, T}*, its complementary sequence is obtained by reversing the sequence order and by substituting A ↔ T and C ↔ G. A string s and its complementary string form bindings between each pair of corresponding nucleotides, and together they fold into the famous double helix (see, e.g., the DNA strands at both sides of Figure 7.1).

Observed DNA strings are huge (10⁶–10¹⁰ nucleotides). The organism’s complete DNA string is called genome. Differences between the DNAs of two members of the same specie are limited (e.g., 1 in 1,000 nucleotides for humans). Some fragments of the genome encode proteins, as we describe below. These regions encode information as described by the central dogma and they are called genes. Other regions perform other tasks that are beyond the focus of this chapter. With the inception of the Human Genome Project,¹ it became possible to estimate that the human genome contains anywhere between 20,000–25,000 protein-coding genes [International Human Genome Sequencing Consortium 2004]—the most recent estimates indicate such number to be roughly 21,000 genes. Differences in some nucleotides in the genomes, and in particular within the corresponding genes characterize properties that distinguish one individual from another. Some important problems dealing with genome analysis are discussed in Sections 7.4 and 7.5.

Figure 7.1    Schematic view of the central dogma: DNA double helix, transcription to RNA, and translation to protein.

In order to be transcribed, the DNA double helix is locally detached with the help of specific molecules (enzymes)—see Figure 7.1 for an example. The two single strands are exposed to the surrounding environment and they can, under proper conditions, be used to initiate the transcription. Other enzymes regulate the process, which basically ensures that a complementary copy of the DNA fragment is generated. The new string of RNA is composed of four kinds of nucleotides: A, C, G, and U, where A, C, G, are the same as in DNA, while U (Uracil) can be seen as a “variant” of T. The RNA string is single stranded and it less stable and shorter than a DNA sequence. However, RNA can perform various tasks within the cell—while DNA sequences are confined to the cell’s nucleus, for eukaryotic organisms. After the transcription is over, the DNA double helix is formed again and the new RNA sequence acts as a messenger of the information drawn from the DNA. From the string manipulation point of view, a new RNA sequence r is obtained from a substring of s that is copied, complemented (T replaced by U nucleotides), and reversed.

The RNA string r folds in the space according to a series of favorable matches between pairs of nucleotides (base pairing). In this case, the presence of a single strand allows richer shapes w.r.t. the DNA helix. The so-called RNA secondary structure is the set of its base pairings (see, for example, Figure 7.2). In particular, A–U and C–G are the favored base pairings; these are also known as the Watson-Crick pairs. Note that it is also possible to find U–G pairs. The topology of the pairs influences and stabilizes the three-dimensional functional shape of the strand. Predicting such three-dimensional shape is extremely important, and this is the topic of Section 7.6. It is interesting to note that, unlike the protein case, an accurate secondary structure prediction for RNA is sufficient to infer the overall three-dimensional shape of the strand.

Figure 7.2    Example of RNA secondary structure.

Let us focus now on the translation phase, namely how RNA sequences determine proteins sequences. In simple terms, triplets of consecutive nucleotides (codons, see the 3-letter boxes in Figure 7.1) identify a new object (monomer) called amino acid. The association is defined by the so-called universal code, and it is summarized in Figure 7.3. Each path in the tree from the root to a leaf describes a codon—the presence of multiple letters on the same edge of the tree indicates that any of the mentioned nucleotides can be used. Even if the translation involves RNA nucleotides, it is a common practice to associate the corresponding DNA triplets, in order to easily interface to genomic data. There are 4³ = 64 possible distinct codons, whereas only 20 distinct amino acids are commonly generated; this is caused by the presence of redundant codons that encode the same amino acid. For example, the rightmost branch in the tree describes the two codons UUU and UUC, both representing the amino acid F (UUU captures 46% of the occurrences of F, while UUC captures 54% of the cases of F). Notably, specific codons are used to signal to the dedicated machinery of the cell the start and the stop of a protein encoding sequence.

The process described so far can be summarized as follows: a gene contained in the DNA, trough RNA transcription, uniquely determines a sequence of amino acids, called the primary sequence of a protein.

Figure 7.3    Universal genetic code: each DNA triplet (follow the edge labels, starting from the root) is associated to a corresponding amino acid, represented by a single letter in the leaf. ⊣ is called the stop codon. Observe that Arginine (R), Leucine (L), and Serine (S) are encoded by six different codons, while Methionine (M) and Trytophan (W) are generated by just one sequence.

The process of translation assembles amino acids as connected beads, linked together by peptidic bonds. All amino acid types contain a common part, called backbone, which is formed by a set of atoms that allows high flexibility, many degrees of freedom, and yet robustness of the chain. One of these atoms is a carbon atom called Cα and it shows amenable properties when modeling protein structures. In particular, given any protein structure in any spatial arrangement, the Cα’s belonging to two consecutive amino acids in a sequence are roughly 3.81Å apart, with a very low variance. Each amino acid is characterized by a type-dependent variable group of atoms that influences its specific physical and chemical properties. This group, called side chain, contains anywhere from 1–18 atoms and is connected to the Cα atom of each amino acid.

Another fundamental result by Anfinsen [1973] states that the same protein sequence immersed in the same environment is capable of folding to a specific, and often stable, three-dimensional shape, called the native state or native conformation. The process is spontaneous and arranges the molecule according to its minimal free energy. The spatial arrangement of the protein, thanks to the chemical properties of amino acids on the surface, determines the function and how the protein interacts and binds to other molecules (ligands). Thus, the combination of the previously discussed central dogma and the properties of proteins provides the fundamental explanation of how a gene expressed by DNA can encode a protein that is capable of performing specific functions.

Proteins can contain from as few as 10 amino acids all the way to 1, 000 amino acids. An average globular protein is about 300 amino acids long. Each amino acid contains 7–24 atoms; therefore, the number possible arrangements of atoms in the three-dimensional space is well beyond any computational power. Given the atomic size of proteins and the difficulties to experimentally determine their native state, the prediction of their structure plays a crucial role. This problem is discussed in Section 7.7.

When studying a living cell and/or organism, we need to contend with the existence of a complex network of (partially known) interactions among the various active components. It is often the case that these interactions are not studied at the lowest level of atomic-level processes, but they are instead abstracted using higher level perspectives. This is often necessary in order to address the high computational complexity underlying these systems and the relatively limited knowledge about the interaction models. Depending on the level of simplification adopted, it is possible to investigate different properties of a system of cells and/or organisms. For example, metabolism, some signaling pathways of hormones and cell cycles can be modeled by fusing experimental data and stochastic analyses.

Systems biology describes the relationships among components as a complex, dynamic system, described using computational and mathematical models. Graphs are often used to represent such complex systems and computational models can be used to reproduce particular behaviors. The typical objects modeled are genes and DNA/RNA fragments, proteins and enzymes, metabolites, and external stimuli. The goals of systems biology are to (a) analyze the network of interactions, (b) predict the behavior of the system under specific conditions, and (c) integrate knowledge by merging diverse experimental data. The representation in use can vary, depending on the scope and granularity of the modeled system: a specific reaction chain may involve a few molecule types, a larger-scale system may describe a cell behavior that involves genes expressions (e.g., quantity of RNA transcribed from a specific gene in a time unit), while a very large system may describe a complete organism with a coarser description of single-cell activities. Some techniques developed within the logic programming community for dealing with problems from systems biology are presented in Section 7.8.

7.3    Answer Set Programming in a Nutshell

Answer Set Programming (ASP) [Marek and Truszczyński 1999, Niemelä 1999] is a logic programming paradigm which extends traditional Horn clause logic [Lloyd 1987] with the ability to use negation as failure in the body of the clauses, relying on the answer set semantics [Gelfond and Lifschitz 1988] to characterize the meaning of programs. We briefly recall here its syntax and semantics. A more detailed exposition can be found in Chapter 2.

Given a set of propositional symbols (atoms) P, the simplest form of an ASP rule is as follows:

where for 0 ≤ i ≤ n, we have that pi ∈ P. A rule is a fact if n = 0, namely, if it has the form p₀ ←. Given a rule r, the atom p₀ is referred to as the head of the rule (and denoted by head(r)), while the set of literals {p₁, …, pm, not pm+1, …, not pn} is referred to as the body of the rule (and denoted by body(r)). Customarily, body⁺(r) = {p₁, …, pm} and body⁻(r) = {pm+1, …, pn}. An ASP program is a collection of ASP rules.

An immediate extension of the ASP syntax permits first-order atoms, allowing the use of variables in the construction of atoms; thus, atoms are of the form p(t₁, …, tk), where p is a predicate and t₁, …, tk are variables and/or constants. An atom (rule) is non-ground if it contains at least one variable. A non-ground rule is a syntactic sugar, representing the set of all ground instantiations of the rule—i.e., all the rules obtained by consistently substituting all of its variables with elements of the Herbrand universe underlying the program. Given a program P, the ASP program composed of all the ground rules obtained in this way from rules in P is called the grounding of P. In what follows, we will consider only the case of programs that have a finite grounding. Indeed, most ASP solvers start an execution by grounding the program, thus removing all variables.

A rule of the form (7.1) describes an implication where the body represents a conjunction of literals. The not connective denotes default negation. The semantics of ASP programs is given in terms of answer sets [Gelfond and Lifschitz 1988] and view programs as sets of default (and defeasible) inference rules. An answer set is a minimal model of the program that supports each true atom—i.e., for each of the atoms in the model there is a rule of the program having such atom as head and whose body is satisfied by the model. In this view, a program is usually seen as a collection of constraints on the solution of a problem, where each answer set represents a solution compatible with such constraints.

Formally, a set of ground atoms M is an answer set of a program P if M is the minimal model of the reduct program PM, which is obtained from P and M as follows:

1.  Remove from P all rules r such that M ∩ body⁻(r) ≠ ∅.

2.  Remove all negated atoms from the remaining rules.

PM is a definite program, i.e., a set of rules that does not contain any occurrence of negation. Definite programs are characterized by the fact that they admit a unique minimal (Herbrand) model [Lloyd 1987].

The presence of default negation allows ASP to capture non-monotonic behavior. For example, given two ASP programs P₁ ⊆ P₂, in general it is not the case that a literal entailed by P₁ (i.e., it is true in all answer sets of P₁) is entailed by P₂ as well. In other words, the addition of new knowledge (i.e., new rules) might invalidate previously obtained inferences. Non-monotonicity, together with high declarativeness, makes ASP a convenient framework to support commonsense knowledge representation and reasoning, especially in presence of incomplete and uncertain information [Baral 2003, Gelfond 2008]. ASP has been successfully used in several application domains, including system configuration, information integration, security analysis, semantic web, planning, and diagnosis (see, for instance, Dovier et al. [2009], Gelfond [2008], and Truszczyński [2007] and the references therein).

Given an ASP program, an ASP-solver is used to compute its answer sets. Several ASP-solvers have become available in recent years [Web references of ASP solvers 2018].

A well-known result concerning ASP states that establishing whether a given program P admits an answer set is an NP-complete problem. Similarly, the problem of deciding if an atom p is logic consequence of P is NP-complete [Dantsin et al. 2001]. Consequently, ASP represents a declarative framework for knowledge representation and reasoning that exactly captures the NP complexity class.

A wider class of logic programs is obtained by admitting disjunctions of atoms as heads of program rules. The resulting programs are called disjunctive logic programs (DLP). While the notions of the reduct and answer set are easily extended to DLP, the expressive power of the framework strictly increases, moving from NP to [Dantsin et al. 2001].²

However, in order to simplify the treatment, we will instead make use of the following useful extensions to the basic ASP syntax. A constraint is a rule of the form

This is a shorthand notation for a rule of the form

where the atom p₀ does not occur elsewhere in the program P at hand. Since any answer set M of such P has to be a supported model of the program,³ it follows that M must model the constraint by falsifying at least one of the literals in {p₁, …, pm, not pm+1, …, not pn}, otherwise M would not be a supported model of P. Hence, in modeling a problem, a constraint of the form (7.2) can be used as a filter, in order to wipe out candidate models M such that {p₁, …, pm} ⊆ M and {pm+1, …, pn} ∩ M = ∅ (namely, the models that satisfy all literals in (7.2)). A common technique exploited in encoding a given problem into ASP consists in broadly describing a solution space in terms of rules of the form (7.1). Each answer set of such a program is intended to encode a potential solution of (a relaxation of) the problem. Then, the formalization is refined by adding a suitable collection of constraints in order to invalidate those answer sets that correspond to undesired solutions.

A useful shorthand notation permits the use of ranges to denote list of literals. For instance, the notation p(2 … 5) stands for the four atoms p(2), p(3), p(4), p(5). A similar language extension introduces conditional literals of the form p:q, where p, q are atoms possibly sharing variables.⁴ Intuitively, given an answer set M, a conditional literal p:q is satisfied by M if, for each ground atom qθ in M, the ground atom pθ is also in M.

A cardinality constraint literal is a formula of the form a{ℓ₀, …, ℓn}b, where a, b are numbers, with 0 ≤ a ≤ b, and each of the ℓis is a conditional literal. We extend the form (7.1) by admitting cardinality constraint literals in place of atoms (both as heads and in the body of rules). A set of atoms M satisfies a cardinality constraint literal if and only if the number c of literals among {ℓ₀, …, ℓn} that are satisfied by M is such that a ≤ c ≤ b. In particular, if the lower (resp., upper) bound a (resp., b) is not specified, 0 (resp., ∞) is assumed. This satisfaction relation for rules and the notions of the reduct and answer set are generalized in a straightforward manner to cover programs with cardinality constraint literals.

A further extension of the ASP language is obtained by introducing aggregates. An aggregate has the form op{t:q}, where q is an atom (possibly involving variables), t is a term possibly sharing variables with q, and op is an aggregate operator such as #count, #sum, #max, #min. As for the case of conditional literals, given an answer set M, t:q stands for the collection of all ground instances of t that correspond to satisfied instances of q. Each aggregate is evaluated by applying the operator op to such a collection of terms.

It is often the case that one is interested in the optimization version of a decision problem in NP. Hence, once the problem is encoded as an ASP program in such a way that each of its answer sets encodes an admissible solution, we may want to super-impose some optimization criteria and search for those answer sets that optimize some objective function. Most of the existing ASP solvers offer some kind of optimization statement. Concerning the ASP encodings presented in the following sections, we will make use of simple optimization statements of the form #maximize{X:p(X)}, where X is a variable and p(X) an atom that might be satisfied for selected numerical values of X. This statement guides the solver to determine, among all answer sets, the one which maximizes the value of X (i.e., the answer set satisfying the ground instance of p(X) for the greatest possible value of X). A similar type of statement is present for minimization problems.

Notice that such optimization statements are often handled by the solver through a search of the solution space (i.e., the space of answer sets) generated by the ASP solver, for instance through standard branch-and-bound techniques.

7.4    Phylogenetics

Phylogenies are abstractions commonly used to describe the relationships among entities (e.g., biological entities like proteins or genomes) derived from a process of evolution. We often refer to the entities studies in a phylogeny as taxonomic units (TUs) or, simply, taxa.

The field of Phylogenetics developed from the domain of biology as a powerful instrument to investigate similarities and differences among entities that arose as a result of an evolutionary process. Evolutionary theory provides a powerful framework for comparative biology by converting similarities and differences into events reflecting evolutionary processes. As such, evolutionary-based methods provide more reliable answers than the traditional similarity-based methods, as they employ a theory (of evolution) to describe changes instead of relying on simple pattern matching. Indeed, evolutionary analyses have become the norm in a variety of areas of biological analysis. Evolutionary methods have proved successful, not merely in addressing issues of interest to evolutionary biologists, but in regard to practical problems of structural and functional inference [Thorne 2000]. Evolutionary inference of pairing interactions determining ribosomal RNA structure [Woese and Pace 1993] is a clear case in which progress was made by the preferential use of an evolutionary inference method, even when direct (but expensive and imprecise) experimental alternatives were available. Eisen and others [Stone and Sidow 2005, Eisen and Hanawalt 1999] have shown how an explicitly evolutionary approach to protein “function” assignment eliminates certain categories of error that arise from gene duplication and loss, unequal rates of evolution, and inadequate sampling. Other inference problems that have been addressed through evolutionary methods include studies of implications of SNPs in the human population [Stone and Sidow 2005], identification of specificity-determining sites [Gruber 1995], inference of interactions between sites in proteins [Tillier and Lui 2003], interactions between proteins [Tillier et al. 2006], and inferences of categories of sets of genes that have undergone adaptive evolution in recent history [Liberles and Wayne 2002].

Phylogenetic analysis has also found applications in domains that are outside of the realm of biology; for example, a rich literature has explored the evolution of languages (e.g., Gleason [1959], Ringe et al. [2002], Taylor et al. [2000], and Dobson [1969]). The definitions and techniques employed are the same; of course the notion of “observable property” can be different. Starting from genes one notice differences using string matching algorithms. But differences (to be analyzed and explained) can be more macroscopic such as the presence/absence of a tail in an animal or the way one say “father” in a language.

7.4.1    Modeling

We will focus on the problem of phylogenetic tree reconstruction, namely: given a set of data characterizing the entities being studied (e.g., species, genes, languages), identify a phylogeny that accurately describes the evolutionary lineages among the given entities. We start with the notion of phylogenetic tree and then we give the notion of compatibility of characters.

A phylogenetic tree (or simply a phylogeny) is typically a labeled binary tree (V, E, L, T, L) where:

•  The leaves L represent the taxonomic units (TUs) being compared.

•  The internal nodes V \ L represent the (hypothetical) ancestral units; in rare cases, the internal nodes correspond to concrete entities (e.g., fossils).

•  The edges E of the tree describe evolutionary relationships; the structure of the edges describe the processes that hypothetically led to the evolution of the TUs, e.g., biological processes of speciation, gene duplication, and gene loss.

•  Commonly, each TU is described by a collection of finite domain properties, referred to as characters. In the formalization, T = (C, D, f) is the description of such properties, where

▪  C = {c₁, …, ck } is a finite set of characters.

▪   associates a finite domain to each character.⁵

▪   is a function that provides the value of each character for each TU being studied.

•  We are often interested in the length of the branches of a phylogeny and/or the assignment of dates to the internal nodes of the phylogeny; if this feature is present, then we will describe it as a function .

Whenever we do not have information about length of branches, we omit the component L from the description of the phylogeny.

For presentation simplicitly, we focus on one example with macroscopic observable properties. One might start, instead, from the value of a list of “spot points” in the genome. Figure 7.4 (top) shows a phylogenetic tree for the TUs L = {Mollusca, Annelida, Arthopoda, Echinodermata, Chordata}. In this example, the set of characters is C = {Coelom, Dark}—Coelom denotes the presence/absence of coelom (a body cavity between the intestine and the body walls), while Dark denotes the phenotypical character of having dark color. In this example, these are both binary characters, i.e., DCoelom = DDark = {0, 1}. The function f describing the five TUs is given by the table underneath each TU in the figure—e.g., f (Annelida, Coelom) = 0 and f (Annelida, Dark) = 0.

The key point in the phylogenetic tree reconstruction problem is how to define what does it mean to “accurately describe,” i.e., what measure of accuracy is used to compare plausible trees. A variety of measures have been proposed, and various phylogenetic reconstruction methods have been proposed based on the specific measure being used to assess quality of the phylogeny.

A common method used in deriving phylogenies is based on the idea of character compatibility—a principle derived from Le Quesne’s idea of uniquely derived characters [Le Quesne 1969, Le Quesne 1972].

The intuitive idea of compatibility is as follows: a character c is compatible with a phylogeny if the TUs that present the same value for such character are connected by a subtree within the phylogeny. More formally, given a phylogeny P = (V, E, L, T, L), with T = (C, D, f), a character c ∈ C is compatible with P if there is a mapping hc : V → Dc such that:

Figure 7.4    A sample phylogeny (top), compatible (middle, Coelom), and incompatible (bottom, Dark) characters.

•  For each t ∈ L, we have that hc(t) = f(t, c).

•  For each i ∈ Dc, the projection of the graph (V, E) on the set of nodes has a subgraph that has as nodes and it is a rooted tree.

A character that is not compatible with a phylogeny P is said to be incompatible. The above (sub-tree) requirement implicitly states that when a character changes (during evolution) it never goes back to the previous value. This is referred to as the Camin-Sokal requirement; moreover, it also accounts for the requirement that the “change” occurs in a unique place, known as the Dollo requirement.

In the example of Figure 7.4, the character Coelom is compatible with the given phylogeny—as shown in Figure 7.4(middle). On the other hand, the character Dark is not compatible with this phylogeny (as shown in Figure 7.4(bottom)).

The goal, in phylogeny reconstruction, is to determine a phylogeny that maximizes the number of characters that are compatible with it. This problem has been often referred to as the k-incompatibility problem [Estabrook 1997]. Formally, the k-incompatibility problem is the problem of deciding, given a set L of TUs, a character description T = (C, D, f) of L, and an integer , whether there is a phylogeny (V, E, L, T) that has at most k incompatible characters.⁶

The problem considered above, based on k-incompatibility, has been studied in the literature and determined to be NP-complete [Day and Sankoff 1986]. The proof relies on a reduction of the k-clique problem to the k-incompatibility problem. This result is not surprising, and similar complexity results can be found for other measures of phylogeny accuracy—e.g., the popular maximum parsimony method for the construction of phylogenies is shown to be NP-hard in [Day 1983].

7.4.2    ASP Encoding

The k-incompatibility problem admits an elegant encoding in ASP, thanks to its natural formulation as a generate-and-test problem.

Let us assume that the TUs for the problem at hand are represented in ASP as a collection of facts of the form taxon(i) where i is the name of a TU. For the sake of simplicity, let us assume that the TUs have been numbered and we use the index of a TU as its name—thus, we will use the ASP declaration

where N is the number of TUs. The character description T will be provided extensionally using facts of the form:

(character and domain can be defined by projection of f). The code is divided in two parts: the tree construction and the computation of hc. Let us focus on the tree construction first.

Nodes 1 to N are used for the TUs and they represent leaves of the tree being constructed. The tree has 2N − 1 nodes and node 2N − 1 is the root. Lines (1) and (2) compute the number of TUs and define the nodes of the trees. Line (3) is used to enforce the binary structure of the tree (each internal node has exactly two children) and to ensure that the TUs are appearing as leaves of the tree. Line (4) is used to ensure that edges point from bigger to smaller nodes, allowing us to remove symmetries. Finally, line (5) allows us to ensure the creation of a tree, by verifying that each node, except for the root, has exactly one parent.

The second part of the code is used to assess the compatibility of the phylogeny with respect to the characters. Given the input function f assigning values to characters of taxa, we define non-deterministically a function hc (like f, represented as a ternary relation named h) that assigns a value in each node I to each character C and such that it extends f. Then the compatibility requirements are added and a function h maximizing the compatibility is looked for.

Lines (6) and (7) provide the definition of the function hc, ensuring that it represents an extension of f. The code in line (8) extracts the edges of the phylogeny that link nodes with the same value for a given character. This creates a new tree, composed of edges labeled by the pair (c, v) of character and corresponding value. The projected trees are analyzed to determine whether they represent individual trees or forests (lines (9)–(11)). If there are multiple trees for the same (c, v), then the phylogeny is incompatible for such character value. Lines (12) and (14) allow us to classify the phylogeny with respect to each character—as being compatible or not. Finally, Lines (15) and (16) force the search for phylogenies that maximize the number of compatible characters.⁷

Table 7.1    Sample experimental results—phylogenetic inference

7.4.3    Related Work

The use of logic programming in the context of phylogenetic inference is a relatively new domain.

Erdem and her collaborators have extensively studied several variants of the phylogeny reconstruction problem, both using traditional ASP. as well as more ad-hoc logic programming systems (e.g., customized ASP solvers to provide a search process that is more suitable to the needs of the phylogeny reconstruction problems). A nice survey of their contributions can be found in Erdem [2011]. The ASP modeling of phylogenetic reconstruction using the k-incompatibility problem was originally proposed in Brooks et al. [2005] and Brooks et al. [2007], later expanded to address issues of polymorphic characters. This line of work was later extended to address the problem of formulating criteria of diversity or similarity in the generation of phylogenies, enabling the creation of pools of phylogenies that are sufficiently similar/dissimilar [Cakmak et al. 2009]; likewise, the problem of dealing with large numbers of plausible solutions has been addressed in Cakmak et al. [2010] using mechanisms to weight each phylogeny.

The proposed solution described in the previous section is not suitable to deal with very large data sets. Nevertheless, this basic formalization can be refined (e.g., embedding techniques based on divide-and-conquer) and it has been successfully adopted to the problem of phylogeny reconstruction [Brooks et al. 2007, Cakmak 2010]. Table 7.1 summarizes some of the performance results obtained from using the ASP formalization to derive different types of phylogenies (to describe evolution of the Alcataenia species and for investigating evolution of human languages), which are encouraging. Similar ideas have been used in other areas associated to manipulation of phylogenetic knowledge (e.g., for supertree construction [Son et al. 2013]).

The study of phylogenies that include time calibrations has been first considered in Erdem et al. [2003] and Erdem et al. [2006], with special considerations for how to deal with real-valued time stamps and even larger data sets. The experimental results have been shown to produce more precise results than using standardized tools (e.g., the MIPPN tool), thanks to the ability to encode expert knowledge in logic programming; the results discussed in Erdem et al. [2006] show that ASP is highly competitive—two orders of magnitude faster than standard tools used by the community.

An alternative approach to the same problem is based on building possible phylogenies on subsets of taxa (typically, every 4-tuple) and use them for building a tree maximizing compatible characters. This approach is called maximum quartet consistency (MQC) or supertree construction and was approached with ASP in Wu et al. [2007] and Koponen et al. [2015].

While a significant part of the literature focused on binary, rooted trees for the description of phylogenies, there are several instances in which this model has to be relaxed.

While true evolutionary histories are indeed rooted trees, the actual location of the root is often challenging, especially because of the lack of appropriate historical references. As a result, it is not uncommon to encounter phylogenetic analyses that make use of unrooted trees (e.g., see Figure 7.5).

Further relaxations of the binary rooted tree view of phylogenies can also be found. The binary nature of the tree can be abandoned (allowing the creation of polytomies, i.e., nodes with more than two children) when a fully resolved bifurcating tree cannot be determined with sufficient reliability.

Figure 7.5    Rooted and unrooted trees.

Typically, we assume that each node in a phylogeny has at most one immediate ancestor; this reflects the assumption that evolutionary lineages, once separate, do not fuse; this assumption follows from the “biological species concept” based on reproductive isolation [Mayr 1964]. Even the restriction of single parentage may be abandoned, for strictly biological reasons, in the case of lateral transfer (a partial mixing of lineages due to transfer of some genes) or reticulate evolution (a genomelevel mixing of lineages due to interbreeding between previously separate species) [Jin et al. 2007, Nakhleh et al. 2005]. This leads us to consider more general structures, e.g., phylogenetic networks. ASP demonstrated flexibility in capturing these variations (e.g., Erdem et al. [2006], Cakmak [2010]), which are instead challenging for traditional phylogenetic inference tools (see also Nichols and Warnow [2008] for a discussion of these challenges).

Logic-based methods have been used to address other problems related to phylogenies and, more generally, taxonomies. Thau [Thau 2010] explored the use of first-order logic representations to address questions of consistency and articulation among taxonomies. Another line of research focused on the application of logic programming technology to phylogenetic analysis and, more generally, to phyloinformatics, can be found in the context of the CDAOStore project [Le et al. 2012, Chisham et al. 2011]. The CDAOStore relies on a triple-based encoding of phylogenetic artifacts (predominantly phylogenies and associated character data matrices), encoded using the Comparative Data Analysis Ontology (CDAO) [Prosdocimi et al. 2009]. Logic programming is employed, in CDAOStore, to implement a variety of queries to a phylogenetic repository, including structural queries (to retrieve phylogenies that meet certain structural constraints) and synthesis queries (e.g., to develop supertrees of sets of collected phylogenies).

7.5    Haplotype Inference

The difference between two organisms of the same species is focused on some peculiar points of the DNA. We present here the problem of reconstructing the connection between a set of diploid organisms (such as humans) of which we know part of the information about these points.

The DNA of diploid organisms is organized in pairs of not completely identical copies of chromosomes. The sequence of nucleotides from a single copy is called haplotype, while the conflation of the two copies constitutes a genotype. Each person inherits one of the two haplotypes from each parent. The most common variation between two haplotypes is a difference in a single nucleotide. Using statistical analysis within a population, it is possible to describe and analyze the typical points where these mutations occur. Each of such differences is called a Single Nucleotide Polymorphism (SNP). In other words, a SNP is a single nucleotide site, in the DNA sequence, where more than one type of nucleotide (usually two) occur with a nonnegligible population frequency. We refer to such sites as alleles.

Considering a specific genotype, a SNP site where the two haplotypes have the same nucleotide is called an homozygous site, while it is heterozygous otherwise. Research has confirmed that SNPs are the most common and predominant form of genetic variation in DNA. Moreover, SNPs can be linked to specific traits of individuals and with their phenotypic variations within their population. Consequently, haplotype information, in general, and SNPs, in particular, are relevant in several contexts, such as, for instance, in the study and diagnosis of genetic diseases, in forensic applications, etc. This makes the identification of the haplotype structure of individuals, as well as the common part within a population, of crucial importance. However, in practice, biological experiments are used to collect directly genotype data instead of haplotype data, mainly due to cost or technological limitations. To overcome such limitations, efficient and accurate computational methods for inferring haplotype information from genotype data have been developed during the last decades (for a review, the reader is referred to Halldórsson et al. [2002], Gusfield [2002b], and Gusfield and Orzack [2005]).

7.5.1    Modeling

The haplotype inference problem can be formulated as follows. First, we apply an abstraction and represent genotypes and haplotypes by focusing on the collection of ambiguous SNPs sites in a population. Moreover, let us denote, for each site, the two possible alleles using 0 and 1, respectively. Hence, a haplotype will be represented by a sequence of n components taken from {0, 1}. Each genotype g, being a conflation of two (partially) different haplotypes h₁ and h₂, will be represented as a sequence of n elements taken from {0, 1, 2}, such that 0 and 1 are used for its homozygous sites, while 2 is used for the heterozygous sites.

More specifically, following Lancia et al. [2004], let us define the conflation operation g = h₁ ⊕ h₂ as follows:

where g[i] denotes the ith element of the sequence g, for i = 1, …, n.

We say that a genotype g is resolved by a pair of haplotypes h₁ and h₂ if g = h₁ ⊕ h₂. A set H of haplotypes explains a given set G of genotypes, if for each g ∈ G there exists a pair of haplotypes h₁, h₂ ∈ H such that g = h₁ ⊕ h₂.

Figure 7.6    The set G = {212, 121} and two possible explanations.

Given a set G of m genotypes, the haplotype inference problem consists of determining a set H of haplotypes that explains G. The cardinality of H is bound by 2m but, in principle, each genotype having k ≤ n ambiguous sites, can be explained by 2k−1 different pairs of haplotypes. For instance, the singleton G = {212} (i.e., n = 3, k = 2) can be explained in two ways, namely by choosing H = {011, 110} or H = {010, 111} (see also Figure 7.6).

Hence, in general, there might be an exponential number of explanations for a given set G. All of them are, from the combinatorial point of view, “equivalent” and a blind algorithm—not exploiting any biological insight—may result in inaccurate, i.e., biologically improbable, solutions. What is needed is a genetic model of haplotype evolution to guide the algorithm in identifying the “right” solution(s).

Several approaches have been proposed, relying on the implicit or explicit adoption of some kind of assumptions reflecting general properties of an underlying genetic model. We focus on one of such formulations, namely parsimony. The main underlying idea is the application of a variant of Ockham’s principle of parsimony: the minimum-cardinality possible set H of haplotypes is the one to be chosen as explanation for a given set of genotypes G. For instance, the set G in Figure 7.6 admits two explanations. The one at the bottom, i.e., {010, 111, 101}, is preferable by the parsimony principle. In this formulation, the haplotype inference problem has been shown in [Lancia et al. 2004] to be APX-hard, through a reduction from the node-covering problem.

7.5.2    ASP Encoding

Following [Erdem and Türe 2008] let us start by introducing the decision version of the haplotype inference by the pure parsimony problem.

HIPP-DEC. Given a set G = {g₁, …, gm} of m genotypes, each with n sites, and a positive integer k, decide whether there is a collection H of at most k distinct haplotypes such that H explains G.

As before, we denote genotypes and haplotypes by sequences of elements from {0, 1, 2} and {0, 1}, respectively. To simplify the description, we consider H as made of 2m (not necessarily distinct) haplotypes h₁, …, h2m and, consequently, every gi ∈ G is explained by the haplotypes h2i and h2i−1.

Our encoding is close to the problem definition—differently from what is used in Erdem and Türe [2008], where efficiency considerations are also taken into account. We assume that G is given extensionally using a predicate g/3, where g(i, j, k) means that the i-th genotype (i ∈ {1, …, m}) in position j (j ∈ {1, …, n}) has the value k (k ∈ {0, 1, 2}). For example, the instance of Figure 7.6 is represented by:

Moreover, the domain predicates geno(1 … m), site(1 … n), haplo(1 … 2m) are also part of the input. In the current example we have:

We propose the following ASP encoding; we define predicates h(i, j) where h(i, j) belongs to the model if and only if the corresponding haplotype hi is such that hi [j] = 1—for i ∈ {1, …, 2m} and j ∈ {1, …, n}. Then we minimize the number of different haplotypes, by defining the notion of representative (of equal haplotypes) and thus minimizing the number of representatives.

In lines (1)–(4), we deterministically require h(2i, j) and h(2i − 1, j) to be in the model if g(i, j) = 1, and to be not in the model if g(i, j) = 0. In lines (5)–(6), we introduce the non-deterministic choice for h(2i, j) and h(2i − 1, j). In lines (7)–(8), we define a predicate to determine whether the haplotype A is a representative, namely, moving from 1 to 2m, it is the first occurrence of the same haplotype. This definition makes use of the auxiliary predicate same_haplotype defined in lines (9)–(11). A minimization of the number of representative haplotypes is requested in lines (12)–(13).

7.5.3    Related Work

In Erdem and Türe [2008], C¸ oban et al. [2008], and Erdem et al. [2009], the authors present a number of heuristics aimed at establishing lower and upper bounds for the value of k w.r.t. the set of genotypes at hand. Experimental results (see Erdem and Türe [2008], C¸ oban et al. [2008]) reveal that the ASP-based approach can successfully compete with approaches based on integer linear programming and constraint programming. The ASP approach has been shown to be highly competitive with the state-of-the-art in haplotype inference. Figure 7.7 compares a refined ASP encoding (as discussed in Erdem and Türe [2008]) to state-of-the-art systems (SHIPs [Lynce and Marques-Silva 2006] and RPoly [Grac¸ a et al. 2007]) on standard benchmarks from the community [Hudson 2002, Brown and Harrower 2006], showing that ASP is capable of solving more problem instances. The work in C¸ oban et al. [2008] confirms the approach in terms of scalability and efficiency over the use of other problem solving paradigms (specifically, constraint programming and integer linear programming).

Figure 7.7    Experimental comparison on the haplotype inference problem.

A number of techniques (e.g., greedy and branch-and-bound algorithms, reduction to SAT, integer programming, stochastic local search) have been applied to address the problem of haplotype inference by pure parsimony, in its initial formulation as well as in a number of variants and refinements (such as Brown and Harrower [2006], Catanzaro and Labbé [2009], C¸ oban et al. [2008], Di Gaspero and Roli [2008], Grac¸ a et al. [2010], Grac¸ a et al. [2011], Sharan et al. [2006], Wang and Xu [2003], Zhao et al. [2007]). Among the various proposals appearing in literature, we mention the rule-based method proposed by Clark [1990], which in its general form suffers from the NP-hardness of the problem.

Several alternative principles, different from parsimony, have also been explored. One of them is called the infinite sites model. It postulates that, during the evolution of a population, a mutation that results in a SNP occurs only once in the history; this reflects the Dollo and Camin-Sokal principles discussed in the previous section. Hence, all individuals sharing a specific allele must be descendants of a single ancestor.

Methods relying on maximum likelihood criteria assume that the probability of observing a genotype is strictly related to the probability of observing its constituent haplotypes. Hence, these methods estimate the probability of (each specific set H of) haplotypes from observed genotypes frequencies in the real population. These methods seek the most probable solution.

Other methods make hypotheses on the historical evolution of the characters in a population. The notion of perfect phylogeny is introduced to represent such evolution as a rooted tree (coalescent model; see Gusfield [2002a]). The tree-structure not only imposes constraints on the candidate solutions, but also reduces the computational complexity of the problem.

For a much detailed treatment of these and other methods, we refer the interested reader to Halldórsson et al. [2002] and Gusfield and Orzack [2005] and to the references therein.

7.6    RNA Secondary Structure Prediction

In this section, we focus on the prediction of the secondary structure arrangement for RNA strands. We provide a model for a simplified version of the problem and we show an elegant ASP encoding.

Figure 7.8    An example of pairings on a sequence of length 14. Solid lines between i and j represent a pair between corresponding si and sj. The addition of the dashed line introduces a pseudo-knot.

Figure 7.9    Example of a two-dimensional hypothetical arrangement of secondary structure.

As explained in Section 7.2, an RNA sequence S = s₁ … sn is a string of symbols from {A, C, G, U}. The sequence can fold in the space, so that pairs of bases can physically interact. The secondary structure can be described by a set of pairs of interacting bases. In Figure 7.8, we show an example of an RNA sequence and a set of pairs of bases (denoted by solid lines). In general, the energetic evaluation of these interactions can be computed in a precise way, regardless of the overall three-dimensional arrangement of the sequence. Therefore, it is possible to compute the best secondary structure while ignoring the actual folding in space. This gives rise to specific prediction algorithms that are much more reliable when compared to the prediction tools for amino acid sequences (see also Section 7.7).

In order to identify the most probable secondary structure, various energetic models have been studied and efficient methods for its estimation have been proposed. In the following, we present two simple approximations of energy functions. The first one is based of the simplest approximation and maximizes the number of favorable pairings (i.e., A–U, C–G, and U–G). A more refined energy function scores the frequency of the pairs.

Figure 7.9 shows a hypothetical 2D pairing of secondary structure associated to Figure 7.8 without the dashed pair. The first section (bases 1–7) forms a ladder with a bulge, in this case containing only one base. This structure is referred to as an hairpin or stem loop, which is rather stable and it can roll into a double helix shape in the actual three-dimensional space, just as for a DNA paired double strand.⁸

7.6.1    Modeling

We are given S = s₁ … sn with si ∈ A, C, G, U and a partial injective function P : {1, …, n} → {1, …, n} such that

•  P (i) = j ⇔ P(j) = i, and

•  P(i) = j ⇒ (si, sj) ∈ {(A, U), (U, A), (C, G), (G, C), (U, G), (G, U)}.

For the sake of simplicity, we will represent P as a the set of pairs {(i, j) | P(i) = j}. P represents a possible secondary structure. The RNA secondary structure prediction problem is that of finding, among all such functions P, the one that minimizes a given energy function. We experiment with two simple energy functions:

where AU (CG) is the number of contacts of bases A–U (C–G, respectively) and c₁, c₂, c₃ are some suitable weights.

The energy function E₁ was proposed by Nussinov and Jacobson [1980] and represents the simplest approximation of the problem. It maximizes the number of admissible pairs, and thus promotes the tightest packing of the structure.

The energy function E₂ is an adaptation from McCaskill [1990] and Bavarian and Dahl [2006]. It promotes a distribution of pair types as similar as possible to a typical statistical distribution retrieved from experimental observations.

7.6.2    ASP Encoding

Let us explore the encoding of this problem in ASP. The sequence S = s₁ … sn is provided as a set of n facts of the form seq(i, si); for example:

The main program models the predicate pairing, which represents the partial function P and contains pairs of indices corresponding to interacting bases. The constraints on bases involved in pairings are added. In the first version of the code we maximize the number of “good” contacts in pairings (energy E₁).

The clauses in lines (1)–(2) extract domain knowledge from the input. Line (3) defines the partial function pairing, which is forced to be injective, by the constraint in line (4), and symmetric, by the clause in line (5). Lines (6)–(8) discard non-admissible pairs, according to the definitions in the modeling section. Line (6) implicitly forbids the pairing of a base with itself; line (9) forbids the pairing of a base with its neighbors. The constraint in line (10) enforces the absence of pseudoknots (see Sect. 7.6.3). If this constraint is removed, then the program will model the NP-complete version of the problem. The clauses in lines (11) and (12) collect and minimize the number of contacts, respectively.

Let us briefly show how to encode the energy model E₂ instead of the contact energy E₁. Line (13) replaces the optimization instruction (12) by asking for a minimal energy. The clauses in lines (14)–(18) define the count of the total number of AU and CG pairs in the sequence, respectively. The energy predicate, in line (19), defines the energy function E₂. We assign here (just for example) c₁ = c₂ = c₃ = 1. Note that the coefficients are multiplied by 100 in order to scale from floating point to integer numbers.

Let us observe that the latter version of the solution may lead to very large ground versions of the program, even for average-size inputs. This may cause a challenge to the solvers, since ASP solvers first produce a ground version of the program before computing its answer sets.

7.6.3    Related Work

The ASP encoding proposed here is the first of its type, and it is predominantly aimed at illustrating the constraints that characterize the solutions of the problem. In the literature, RNA secondary structure prediction has been addressed by a large number of proposals, presenting different algorithms and various energy functions. Starting from the seminal work by Tinoco et al. [1971], where propensity of forming helices is addressed, other popular methods include the one by Nussinov and Jacobson [1980], introduced more than 30 years ago. It promotes the maximal number of admissible pairs in the sequence. This approach can be addressed by a polynomial dynamic programming approach for a restricted class of solutions (in absence of pseudo-knots, see the complexity notes below).

More refined energy functions have been proposed, with the specific goal to better estimate hairpin loops. The Zucker’s algorithm [Zuker and Stiegler 1981] proposes a more precise estimate of stacking pairs forming a hairpin loop, as well as contributions for opening and closing a loop. The computational complexity of the solution is polynomial in absence of pseudo-knots, and non-logic programming techniques, i.e., dynamic programming, have been proposed. The original algorithm proposes an energy minimization approach. Other energy functions have been proposed as the result of probabilistic analyses. In particular, the mean distribution of base pairs found in actual RNA secondary structures has been used as the target of the secondary structure prediction. The most favorable structure is the one that best approximates such distribution [McCaskill 1990, Bavarian and Dahl 2006].

In order to improve the structural results, Sankoff proposed a simultaneous alignment and folding approach, which goes beyond the scope of this section [Sankoff 1985].

In the general case, the decisional version of the problem is NP-complete—see Lyngso and Pedersen [2000] for the original proof. The main idea is to reduce a 3-SAT formula to a particular sequence such that there exists a specific number of contacts if and only if the original formula is satisfiable. An interesting polynomial class of problems has been characterized by the absence of pseudo-knots (see dashed pair drawn in Figure 7.8). A pseudo-knot is encountered when for two pairings (i, j) and (ℓ, k) in P, it holds that i < ℓ < j ⇒ j < k ∨ k < i.

The work in Bauer et al. [2007] provides examples of energy functions for general structures with pseudo-knots. Moreover, a constraint propagation approach for alignment and folding in the presence of pseudo-knots has been presented in Dal Palù et al. [2010]. For pseudo-knot–free structures, dynamic programming algorithms can be used with a time complexity ranging from O(n²) to O(n⁴), depending on the energy function being considered, while space complexity ranges from O(n) to O(n²).

7.7    Protein Structure Prediction

The problem we introduce here is a simplification of the protein structure prediction (PSP) problem, that is the problem of predicting the 3D shape of a protein given its linear sequence of amino acids. In particular, we consider two levels of simplification.

Protein model. We select one particular atom of each amino acid as the representative of the entire amino acid. Moreover, we partition the 20 amino acids in two families: h (hydrophobic) and p (polar).

Spatial model. We focus exclusively on a simple 2D discrete lattice representation of the space.

We provide some more details on the full version of the problem and on (some) approaches for dealing with it in Section 7.7.3.

7.7.1    Modeling

We refer to such simplified version of the problem as the 2DHP-PSP. The problem can be formulated in a simple way as follows. The input is a list of amino acids S = s₁ … sn, where si ∈ {h, p}. Imagine S as a pearl necklace, where the sis are the pearls, while the distance between si and si+1 is constant. This string of pearls lays down on a large 2D matrix, where the size of the square is exactly the distance among pearls—for the sake of simplicity, we will assume such distance to be 1—with the further constraints that si must occupy the intersection of two lines, and that no two distinct si and sj occupy the same point. We call this necklace placement a folding. In a given folding, if a pair of amino acids si and sj are at distance 1, we say that they are in contact. We are interested in contacts between pairs of amino acids of type h (h-h-contacts). The 2DHP-PSP is the problem of finding a folding that maximizes the number of h-h-contacts. The decision version of the problem, described by the statement

Given a sequence S and a number k, is there a folding with at least k h-hcontacts?

has been shown to be NP-complete in Crescenzi et al. [1998].

We model the 2DHP-PSP in a mathematical way as follows. Given a list S = s₁ … sn, with si ∈ {h, p},a folding is a function such that

1.  ∀i ∈ {1, …, n − 1}next(ω (i), ω(i + 1)), and

2.  ∀i, j ∈ {1, …, n}(i ≠ j → ω(i) ≠ ω(j)),

where next(〈X₁, Y₁〉), 〈X₂, Y₂〉) holds if and only if |X₁ − X₂| + |Y₁ − Y₂| = 1. The 2DHP-PSP is the problem of finding the folding that minimizes the following energy function:

where Pot(p, p) = Pot(h, p) = Pot(p, h) = 0 and Pot(h, h) = −1.⁹

Without loss of generality, we can consider only foldings within [1 … 2n] × [1 … 2n]; moreover, to remove some symmetries in the solution space, we can set ω(1) = 〈n, n〉 and ω(2) = 〈n, n + 1〉,

Contiguous occurrences of h in the input sequence S (namely, when si = si+1 = h) contribute in the same way to the energy associated to each folding and, thus, they are not considered in the objective function. An easy observation (that unfortunately cannot be “lifted” to the general PSP formulation) is that si and sj can be in contact only if j − i is odd (we refer to this as the odd property of the lattice).

7.7.2    ASP Encoding

The ASP encoding of this problem has been originally presented in Dovier et al. [2009]. A specific instance S = s₁, …, sn of the problem is represented by a set of n facts of the kind prot(i, si). For instance, the protein phphpphp of Figure 7.10 is described as:

Figure 7.10  Light gray circles denote p amino acids, while dark gray circles are h amino acids. Two foldings for S = phphpphp. Left: one h-h contact. Right: two h-h contacts.

The ASP code used in the encoding is shown below. We define the ternary predicate sol such that sol(i, X, Y) holds if amino acid i is assigned to the position X, Y in the 2D space. Geometrical constraints stating contiguity of consecutive amino acids and non overlapping of different amino acids are added. Then a solution maximizing contacts between nonconsecutive h-amino acids (energy_pairs) is looked for.

Rules (1)–(3), together with the predicate prot, define the domains of the variables to be used later. More precisely, rules (2) and (3) state the admissible values for x and y coordinates: it is easy to see that the Manhattan distance w.r.t. the initial point (set in rule (4)) is less than N. We aim at defining the solution (sol) predicate that states, for each amino acid 1, …, n its spatial position. Rules (4) and (5) fix the positions of the two initial amino acids. Rule (6) states that each amino acid occupies exactly one position. The ASP-constraints (7) and (8) state that there are no self-loops and that two contiguous amino acids must satisfy the next property. Rule (9) defines the next relation, also including the odd property of the lattice. The objective function is defined by Rule (10) and (11), which determines the energy contribution of the amino acids, and rule (12), that searches for answer sets maximizing the energy.

7.7.3    Related Work

The literature on the protein structure prediction problem is extensive (e.g., Neumaier [1997], Floudas [2007], and Dal Palù et al. [2012a] provide some interesting surveys of this field). We just focus on some approaches based on logic and/or constraint programming. The 2DHP version of the problem is just a simplified model that, however, can be used to understand the difficulty of combining a self-avoiding-walk with a nonlinear energy function. The proposed ASP model shows significant running times even with small instances (e.g., 3.5/16/69/332 seconds¹⁰ for h¹⁰ = hhhhhhhhhh, h¹¹, h¹², h¹³, even if optimal solutions are found almost immediately—most of the time is employed by clingo to prove that they are optimal). Nevertheless, the proposed basic encoding has served as the starting point of a number of refinements leading to competitive logic-based implementations.

The HP function was introduced by Dill [1990] to model the fact that polar (p) amino acids tend to stay outside (in contact with water) and, as a consequence, hydrophobic (h) amino acids tend to stay in contact inside the protein. A 3D lattice model for the HP problem (FCC) was introduced by Backofen and Will [2001, 2006]; using clever symmetry breaking results and a geometric notion of allowed cores, they are able to find the best folding for proteins of length 200 and more. In Dal Palù et al. [2004], the authors generalizes their approach using a Prolog encoding with a more precise contact energy function. An ad-hoc constraint solver for that modeling was then developed [Dal Palù et al. 2007]. In Dal Palù et al. [2010], the same authors consider an orthogonal view of the same problem, namely the approach is that of assembly admissible fragments of the protein. The notion of a discrete lattice is no longer needed and results are more realistic, even remaining in a discrete world (the number of allowed fragments for each subset of a protein is finite). An ad-hoc constraint solver for that modeling has been described in Campeotto et al. [2012], Campeotto et al. [2013], and Campeotto et al. [2015].

Table 7.2    Comparison of logic-based methods in protein structure and loop prediction

Table 7.2 summarizes some of the results from protein structure prediction tasks realized using state-of-the-art software and methods derived from logic/constraint-based methods. The table on the left summarizes the root-mean-square deviations (RMSD) of the prediction using Robetta [Raman et al. 2009] and using a constraint-based system (FIASCO) [Campeotto et al. 2013]; the table on the right compares the same constraint-based method with tools dedicated to prediction of structure of short protein fragments (loops) that serve as connection between large, regular substructures, specifically CCD [Canutescu and Dunbrack 2003], SOS [Liu et al. 2009], and FALCm [Lee et al. 2010].

7.8    Systems Biology

A cell can be considered as a complex system composed of different interacting components. Such components can be small molecules (e.g., water, amino acids, nucleotides, etc.), DNA, RNA, and proteins. The interactions among these elements determine the diverse cellular functions and can be situated and analyzed at different levels/stages of the process that, starting from DNA replication, ends with protein synthesis. Each of these stages are usually modeled by means of some kind of network. At the DNA level, transcription factors control the transcription of genes in mRNA synthesis (transcriptional regulatory network). This affects the activities of genes through a so-called gene regulatory network (notice that genes, in turn, control the transcription factors). At the protein level, several proteins can interact and affect the products of the transcription step and form protein complexes. These interactions are modeled by protein interaction network. Biochemical reactions occurring in the cell and involving metabolites (such as enzymes, substrates, etc.) constitute the metabolic network. Signaling networks are introduced to model the complex processes that took place in a cell in order to receive different signals from the cellular environment and, possibly, from other cells. Figure 7.11 intuitively illustrates these networks and their relationships.

Figure 7.11  Various kinds of network models used to represent, at different granularity levels, the interactions between molecules in a cellular system.

A typical problem in system biology consists of developing a network model by combining existing biological knowledge. This model has to be validated with respect to experimental data. Often, because of incompleteness in the biological knowledge and partial unreliability of experiments’ outcome, the model has to be checked for consistency, modified, repaired, or extended. On the other hand, analysis of the model may give hints on how to design new experiments.

In the remainder of this section we describe some of the declarative approaches aimed at automating specific steps of the process of model definition and refinement. In particular, we focus on two problems, verifying consistency and repairing gene regulatory networks (Section 7.8.1) and on completion of metabolic network (Section 7.8.2). Related works are discussed in Section 7.8.3.

7.8.1    Gene Regulatory Networks

A gene regulatory network is a directed graph having genes as nodes and their relationships as edges. The most commonly used model to relate the concentrations of network constituents (genes, metabolites, proteins, etc.) and their evolution is derived from (systems of) ordinary differential equations. In many cases, the incompleteness of information about biochemical reactions makes the task of defining such equations hard. Moreover, in a simplified setting, one may be interested in abstracting from quantitative aspects and introducing a qualitative model. Such model should focus on controlling the relationships among genes/nodes of the network, namely, activations and inhibitions of genes’ expression as effect of other genes’ expressions.

7.8.1.1    Modeling

One of the simpler proposed models of Gene Regulatory Networks makes use of the so-called influence graph. In such a network model, the edges are labeled either by + or by −, to represent the positive, resp. negative, influence between constituents. Formally, an influence graph is a directed graph G = (N, E, σ), where N is a set of nodes, E is a set of edges, and σ : E → {+, −} is a (possibly partial) labeling of the edges.

Graphically, the edges labeled + are represented as arrows while those labeled − have a T-shaped head. Figure 7.12 describes a simplified influence graph for the lactose operon in Escherichia coli [Gebser et al. 2011] (an operon is a portion of DNA containing a cluster of genes controlled together). In this graph, for example, the node Le is not regulated by other constituents, hence it is considered as an input of the system. By increasing or decreasing the levels of input constituents one can observe how the system evolves as result of reciprocal activations and inhibitions of nodes. This represents a (simplified) simulation of the modeled biological system. Since each node may be either active or inhibited, there exists only a finite number of possible states of the network. Thus, such simulation must end in a steady state or, otherwise, enter a cycle of states. Viewed from the qualitative perspective, at a higher abstraction level, steady states can be considered as counterparts for the solutions of the system of differential equations.

Figure 7.12  An influence graph modeling lactose operon in Escherichia coli.

In reasoning on biological networks represented as influence graphs, one often adopts the so-called Sign Consistency Model. After a model has been designed and its steady state(s) are determined (corresponding to different input configurations), we may want to verify if its behavior reflects the outcome of real experiments. At this abstraction level, such an outcome is specified in terms of a node labeling μ that labels constituents by + (resp., −), depending on the variations of their concentrations, as exhibited by experimental data. Consistency of the model with respect of the experimental data is formalized a follows.

Let G = (N, E, σ) be an influence graph and μ : N → {+, −} a (partial) node labeling. Then, G and μ are consistent if there are extensions σ′ of σ and μ′ of μ such that, for each non-input node n ∈ N, there is an edge e = (m, n) ∈ E such that σ′(e) ◦ μ′(m) = μ′(n), where the usual rule for signs, namely +◦+=−◦−=+ and −◦+=+◦−= −, is adopted.

Even in this simplified setting the problem of establishing consistency of a model with respect to a data set is not trivial. In Veber et al. [2006], for instance, it is shown that in presence of incomplete information the decision problem is NP-hard.

In case inconsistency is detected, this can be caused by missing or inaccurate knowledge involved in the design of the network and by the presence of partially unreliable data. In such a situation, one may ask whether it is possible to reconcile model and data. A possibility consists in applying some changes in the network model or in the data (or both). Changing the data is an attempt in singling out those portions of the experimental outcome to be considered as unreliable. A modification of the network should yield a more refined biological model. Finding a set of such repairing operations consists in solving the repair problem. This is usually solved with respect to a collection of experimental profiles—observations or experimental evidences—represented as a collection of different node labeling.

Considering a set of experimental profiles, a typical repair operation consists of: (1) introducing a new edge in the network; (2) flipping the label of an edge; (3) considering a node to be an input node in all experimental profiles; (4) considering a node to be an input node in a specific profile; (5) flipping the label for a node in a specific profile. (1) and (2) correct incompleteness and inaccuracy of the model; (3) indicates that for that node some form of regulation is missing in the model; (4) and (5) revise the experimental observations.

We are interested in applying a minimal number of repair operations. Thus we are looking for repairs that are minimal with respect to some criteria. Two possibilities explored in the literature [Gebser et al. 2010a] are subset-minimality and cardinality-minimality. As noted in Gebser et al. [2010a], both choices are not computationally trivial, since evaluating subset-minimality and cardinality-minimality involves solving problems that are, in general, in and in , respectively.

It is possible that many repairs exist for reconciling the same inconsistency between a network and a set of profiles. We may be interested in detecting those parts in the edge/node labeling that are common to all these solutions. In other words, we are interested in determining the consequences of each minimal repair. This consists of solving the prediction problem.

7.8.1.2    ASP Encoding

The following encoding is inspired by Gebser et al. [2011, 2010a] but it avoids the use of disjunctive heads and it deals with consistency detection and with a simple notion of repairing.

The program aims to compute the predicates label_vertex and label_edges (although typically edges are already labeled). The input of the problem is given through a set of facts of the following kind: vertex(Vertex Name), edges(From Vertex, To Vertex), input(vertex Name)–for input vertices, and a set of observation for nodes and edges of the form observed(Vertex name, Sign) (for nodes) and observed(From Vertex, To Vertex, Sign) (for edges), where Sign is either plus or minus. Constraints are added to enforce the consistency of the labeling of vertexes. If a consistent labeling is not possible, a binary predicate wrong is associated to each edge whose sign should be reversed. Minimization of wrong atoms in the stable model is then required.

After defining the domain predicate sign in line (1), and the predicate opposite between signs, the mutual exclusion between plus and minus for vertices and edges is stated in lines (3) and (4). The choice for the predicate wrong stating, intuitively, that an edge should be reversed is added in line (5). The labeling we are looking for should be consistent with known observations. In particular, node labeling is required to be consistent in line (6) and the edge labeling is consistent if the edge is not wrong, otherwise the complementary value is chosen (lines (7) and (8)). Rules of signs propagation are stated in lines (9) and (10), using the auxiliary predicate receive. Then, in line (11) it is stated that the labeling of the non-input vertex must be justified by the predicate receive, namely by the rule of signs. Lines (12) and (13) are inserted for looking for the answer set with a minimum number of wrong edges. If edges_reversed(0) is in the result, then the network is already consistent.

7.8.2    Metabolic Networks

Large amounts of data are made available through experiments, making possible the study of the dynamic metabolic behavior of living cells (or systems of cells) in response to perturbations and stimuli coming from their surrounding environment. This is usually done by analyzing metabolic networks. In such networks, the nodes represent the metabolites while the edges represent the reactions. A metabolic network describes a collection of metabolite components together with a functional readout of the cellular state. The modeling and the reconstruction of biochemical reaction pathways/networks are far from being easy tasks, because of the complexity of the molecules and the reactions that may take place. This fact calls for sophisticated and refined computational techniques for reconstructing and simulating metabolic networks.

Several formal techniques and approaches have been adopted to model and reason about metabolic networks. Among them, we find Petri nets, Flux balance analysis, and Process calculi (see Chen et al. [2009], and the references therein, for further details).

In the rest of this section we describe a qualitative approach based on ASP to study this class of problems. We rely on the notion of metabolic network borrowed from Nikoloski et al. [2008b], Schaub and Thiele [2009], and Collet et al. [2013]. Intuitively speaking, a metabolic network models situations where a reaction can only occur if all of its substrates are available as nutrients or can be produced by other reactions. Starting from some initially given nutrients, called seeds, the network is expanded by adding all of the enabled reactions together with their products. Such a process iterates until no further reactions can occur. The set of metabolites in the expanded resulting network is called the scope of the given seeds. It represents all the metabolites that can be, potentially, synthesized from the seeds by the given network.

7.8.2.1    Modeling

We adopt the following definition: a metabolic network is a directed bipartite graph G = (R ∪ M, E) where R and M are sets of nodes representing reactions and metabolites, respectively, and E ⊆ (R × M) ∪ (M × R).

Given an edge (m, r) ∈ E, the metabolite m ∈ M is called reactant of the reaction r ∈ R. Similarly, for an edge (r, m) ∈ E, the metabolite m ∈ M is called product of the reaction r. We say that a reaction r is reachable from a set of metabolites S if S contains all the reactants of r. Moreover, we say that a metabolite m is reachable from a set of metabolites S if either m ∈ S or m is a product of some reaction r reachable from S. We define the scope of a set S of metabolites in the network G (denoted ΣG(S)) to be the set of metabolites that are (transitively) reachable from S.

The authors of Schaub and Thiele [2009] and Collet et al. [2013] propose ASPbased solutions for two specific reasoning tasks on metabolic networks: metabolic network completion and inverse scope problem.

The metabolic network completion problem can be stated as follows. Let us consider a metabolic network G = (R ∪ M, E), two sets S, T ⊆ M of seed and target metabolites, and a reference metabolic network (R′ ∪ M′, E′). We wish to find a set of reactions R″ ⊆ R′ \ R such that T ⊆ ΣG(S), where:

Figure 7.13  A metabolic network.

The set R″ is the completion of (R ∪ M, E) from (R′ ∪ M′, E′) w.r.t. S, T.

For instance, let us consider the network in Figure 7.13. It represents the reference network (R′ ∪ M′, E′), while G is its subgraph where R = {r₃, r₄, r₆} (the dark nodes), M = M′, and E′ is the subset of edges that concerns nodes in R. If S = {m₁, m₂} and T = {m₅, m₇}, then further reactions should be used (i.e., inserted in R″). A solution with a minimal size of new reactions is R″ = {r₁}.

Variants of this problem impose minimality requirements on the set R″, typically asking for subset-minimal or cardinality-minimal solutions. Other variants minimize the production of metabolites occurring in a set of “forbidden” products. Moreover, optimality can be imposed on the distance (i.e., path length) between seeds and scope.

The inverse scope problem can be formulated as follows. Given a metabolic network G = (R ∪ M, E) and a set T ⊆ M of target metabolites, find a set of seed metabolites S ⊆ M such that T ⊆ ΣG(S). Also, in this case minimality requirements can be imposed to obtain optimized versions of the problem, as well as specification of “forbidden” products.

Regarding computational complexity, it can be shown that, in general, the problem of metabolic network completion, as well as the inverse scope problem and other related problems, are NP-hard [Nikoloski et al. 2008b, Nikoloski et al. 2008a].

7.8.2.2    ASP Encoding

We report here a simplified encoding of the problem of metabolic network completion. The interested reader can refer to Schaub and Thiele [2009] for a description of variants of this encoding as well as for the ASP formulation of the inverse scope problem.

The instance of the problem is described by the specification of two networks. This is done using facts of the forms as follows.

•  draft(Net) to identify the network named Net as the network G.

•  reaction(R,Net) states that the reaction node is in G;

•  Other reactions of G′ are defined by reaction(R,a) (a stands for “all”; without loss of generality, let us assume that the network name Net is not a, and that it is different from the symbol x, as well).

•  Edges are represented by facts of the form reactant(M,R) and product(M,R) to specify the topology of the network.

•  seed(S) and target(T) specify seeds and targets.

For instance, considering again the network in Figure 7.13, one can state draft(d) to identify G, along with the facts

The graph is given by facts of the form:

Finally, seeds and target are defined as

The following code implements the solution to the problem of metabolic network completion. Reactions of G and of G″ are always represented by the binary predicate reaction. Graph reachability is defined recursively, and the number of reactions in G″ not present in G is minimized.

In the above code, lines (1)–(2) define the three types of reactions, d stands for the network G, a stands for the reference network, and x will denote the reactions of the intermediate network G″ we are looking for. Lines (3)–(4) define non-deterministically which reaction can be considered by the intermediate network G″. All reactions of G are included, while those in G′ \ G can be considered or not. Lines (5) and (6) define the reachability relation. In particular, let us observe the use of the conditional literal scope(M2,T) : reactant(M2,R) in the body of the rule in line (6). It is a shorthand for scope(m₁, T), …, scope(mn, T) where m₁, …, mn are all the metabolites that are reactants of the reaction R active in the network identified by T. This kind of syntactic extension to ASP is replaced by the proper list of usual literals during the grounding stage. The constraint in line (7) imposes that all targets must be obtained in the extended network. Finally, lines (8)–(10) ask for a cardinality-minimal set of new reactions.

7.8.3    Related Work

The use of ASP techniques for modeling biological networks has been shown to have a great potential, as predictions on the basis of cardinality-minimal repairs are highly accurate and enable predictions in situations with noisy data (e.g., DNA microarrays) and incomplete knowledge. To our knowledge, there are no comparable proposals that provide the ability to globally reason over whole biological networks in order to identify minimal repairs on the network and/or datasets. Experiments reported in Gebser et al. [2011] indicate predictions accuracy of over 90% on different datasets related to Escherichia coli. The ASP-based approaches have been used in the field, e.g., to aid in the construction of the metabolic network of the recently sequenced green alga Chlamydomonas reinhardtii and in the expansion of the metabolic network of Ectocarpus Siliculosus [Schaub and Thiele 2009, Collet et al. 2013]. Metabolic network completion have been also studied in Frioux et al. [2017].

It is practically impossible to compile here a comprehensive bibliography on Systems Biology. We refer the reader to Dubitzky et al. [2013], which provides a general overview of the field and an extensive bibliography, and to Chen et al. [2009] for a network-oriented perspective. Let us focus on the declarative approaches developed in the subfields of Systems Biology treated in this chapter.

In this section, we described the approach relying on the notion of Influence Graph and the Sign Consistency Model for gene regulatory networks. Other methods have been studied; for instance, Chaouiya et al. [2003], Corblin et al. [2009], Corblin et al. [2010], Corblin et al. [2012], and Folschette et al. [2012] adopt, and in some cases extend, the logical formalism introduced in Thomas [1991], Thomas and Kaufman [2001], and Thomas et al. [1995]. Notions of network, such as regulatory graphs and interaction graphs [Fayruzov et al. 2009], are defined similarly to influence graphs, but by admitting numerical labeling or activation/inhibition thresholds. Implementations have also been developed, such as SysBiOX [Corblin et al. 2012] and PINT [Folschette et al. 2012], exploiting computational logic solvers, mainly based on SAT, ASP, or CSP.

Two recent proposals use ASP for biological regulatory networks: in Fitime et al. [2017] the authors identify states where bifurcations (transitions after which a given goal is no longer reachable), while in Abdallah et al. [2017] the authors identify attractors (parts of the state-transition graph that cannot be escaped).

Boolean networks have been also used, for instance in Guziolowski et al. [2013], to declaratively tackle the learning problem for biological network models. The proposal exploits an ASP-solver as reasoning engine. Similarly, Fayruzov et al. [2009] relies on ASP to model and reason about protein interactions, while Ray et al. [2010] integrates numerical weights in Boolean networks in order to introduce a notion of preference among solutions. Another extension of Boolean networks is used in Fayruzov et al. [2010] and Fayruzov et al. [2011] to develop an ASP-based system to model regulatory networks with meta-interactions. The implementations of a collection of deductive tasks for reasoning on biological networks, developed by the authors of Guziolowski et al. [2013], Durzinsky et al. [2011], Gebser et al. [2010a], and Gebser et al. [2011] (including those presented in this section), are described in Gebser et al. [2010b]. Ostrowski et al. [2016] use ASP for generalizing previous learning procedures for Boolean networks to take into account the time series traces of phosphoproteomics data in order to discriminate networks according to their transient dynamics. In particular, they compute an over-approximation of the set of Boolean networks which fit best with experimental data, and filter out the results using model-checking, proposing a global learning algorithm.

The use of Action Description Languages to solve different computationally hard problems in Systems Biology has been explored in [Tran and Baral 2009], Tran and Baral [2007], Baral et al. [2003], Baral et al. [2004], and Tran et al. [2005]. The authors also realized a tool, named BioSigNet-RR, exploiting such ideas. Similar approaches to signaling, metabolic, and regulation networks have been proposed in Dworschak et al. [2008a, 2008b], among others, by introducing the ADL CTAID and the system BioC.

In Calzone et al. [2006], a software environment for modeling biochemical systems (BIOCHAM) has been described. It allows the analysis and simulation of Boolean, kinetic, and stochastic models and the formalization of biological properties in temporal logic. Parts of the tool are implemented in logic programming.

7.9    Other Logic Programming Approaches

In this section we briefly discuss the main logic programming approaches to bioinformatics that do not rely on ASP, trying to show how these different solutions better adapt to some specific problem features. The goal is not completeness in the review of papers in the literature, but rather a showcase of approaches and of the problems that could be successfully implemented with those models. For further details please refer to the various editions of the Workshop on Constraint-Based Approaches to Bioinformatics (clp.dimi.uniud.it/wcb), with related publications (e.g., Dal Palù et al. [2007], Dal Palù et al. [2008], Backofen et al. [2012], and Barahona et al. [2011]).

CLP derives from logic programming and focuses on the declarative nature of constraints over some specific domain. In particular, the Finite Domain represents a popular choice that allows to deal with integers. As opposed to ASP, CLP allows efficient pruning of the search space, caused by propagation of constraint information, while ASP takes advantage of conflict-driven learning strategies borrowed from SAT solving. Finally, ASP struggles to represent large sets of numbers and it is better suited for search rather than optimization tasks. For a detailed comparison about capabilities and efficiency, the interested reader is referred to Dovier et al. [2007], Dovier et al. [2009].

In the following we give some references to representatives of different lines of research. Constraint programming approaches related to bioinformatics span across several areas, including phylogenetics [Gent et al. 2003], string alignment [Dal Palù et al. 2010], and DNA motifs discovery [Buezas et al. 2010]. A large set of applications is related to protein structure modeling, including modeling of protein structure on simplified crystal lattices, recovering the atomic structure from experimental data, protein structural modeling [Barahona et al. 2011, Barahona and Krippahl 2008, Mann et al. 2014, Backofen 2001, Backofen and Will 2006], and protein design [Allouche et al. 2014]. In the field of Systems Biology, constraint programming (also in conjunction with constraint temporal logic) has been used to analyze properties of biological network, to build interpretations of them and to simulate them [Fanchon et al. 2005, Dooms et al. 2005, Bortolussi et al. 2007, Larhlimi and Bockmayr 2009, Soliman et al. 2014, Rodrigo et al. 2011, Kelsey et al. 2014, Fioretto and Pontelli 2013].

A specialization of constraint programming, where each constraint is given a preference value (weight) and the best solution maximizes the global weight, has been used to model haplotyping problems [Sanchez et al. 2008] as well as string problems [Thebault et al. 2006].

Another fruitful combination of statistical modeling and logic programming is represented by the PRISM system by Sato [1995] and Problog [Kimmig et al. 2008]. In PRISM, symbolic-statistical modeling is natively supported by the language, which combines probability with logic programs, using the so-called distribution semantics. Probabilistic inference routines are embedded in the language and predicated are equipped with parametric probability distributions. This scenario allows to capture typical string problems, where analyzing probabilistic models allows to identify genes and other motifs [Christiansen et al. 2010, Mørk and Holmes 2012]. Problog builds on a similar basis and extends Prolog facts with probabilities. An application of Problog to the interpretation of gene networks can be found in De Maeyer et al. [2013].

Compared to ASP, PRISM and Problog systems provide easy access to statistical models, while in ASP this is not supported by the resolution engine and appears to be inefficient to encode explicitly in the ASP program. Compared to CLP and specifically to wCSP, probabilistic languages offers richer built-in tools for modeling statistical properties of facts at the cost of a more demanding resolution engine.

The declarative framework of constraint handling rules (embedded in host Prolog systems), that allows a high-level definition of a constraint solvers by defining rewriting rules, is used for modeling string problems [Bavarian and Dahl 2006].

Inductive Logic Programming (ILP) has been used as a tool for learning biological properties [Muggleton et al. 1998] and to detect information on the protein structures [Turcotte et al. 2000, Turcotte et al. 2002].

Other techniques that have been used and that are close to logic programming (not discussed here) are integer linear programming, local search, pseudo Boolean, and SAT. It is worth noting that any SAT encoding of a problem can be input to an ASP solver, therefore making the ASP encoding more attractive in terms of readability of the programs.

Similarly, the field of bioinformatic has made a tremendous push toward the adoptions of semantic-based techniques (e.g., semantic annotations, formal ontologies, linked data) to enhance the power of data querying, to facilitate integration of diverse datasets and to move from dealing with raw data to dealing with knowledge (e.g., Schuurman and Leszczynski [2008], Baclawski and Niu [2005], Bard [2003], Alterovitz and Ramoni [2010]). Logic programming methods have found applications in the domain of reasoning with formalized knowedge (e.g., triple stores); examples of works in this area include applications of Prolog (e.g., Angelopoulos and Giamas [2014], Mungall [2009], Burger et al. [2004]) and ASP (e.g., Chisham et al. [2011], Erdem and Oztok [2012], Hoehndorf et al. [2007], Le et al. [2012]).

We can conclude this section by observing that ASP can be used as a starting point for encoding any problem by means of an agile and clean mathematical formalization. However, there are cases where alternative systems can be more effective: number encoding (where CLP based system are more suitable) and probabilistic problems (that account for experimental errors, variability, and statistical models).

7.10    Conclusions

This chapter reviews some classical problems that arise in Bioinformatics, namely Phylogenetics, Haplotype, RNA secondary structure prediction, protein structure prediction, and systems biology. The chapter shows how logic programming can be employed to model these problems by describing the properties of the system, rather than the process of computing the problem’s solutions. The problems have been modeled by means of Answer Set Programming, a logic programming language that allows concise and versatile programming style. The reader is guided into the modeling process and the intuitive encoding into ASP.

The relatively short encodings are fully functional and they can be tested in conjunction with input reported in Chapter Appendix 7.A. The encodings presented in this chapter are the most natural declarative models of the proposed problems; yet, these have represented the foundations of significant refinements, making these approaches highly competitive to state-of-the-art methods. Some additional considerations are as follows.

•  The ASP approaches proposed in this chapter represent the basis for refined implementations that have been deployed in the field and used to address concrete and complex problems; applications of ASP techniques are aiding researchers in reconstruction of concrete metabolic networks (e.g., Schaub and Thiele [2009], Collet et al. [2013]) and inference of phylogenies (e.g., Erdem [2011]).

•  Declarative methods, such as those provided by ASP, enables scientists to readily include additional knowledge to an existing model, without the need to reconstruct the model from scratch; the additional knowledge can be automatically used to improve solution. This is a property that is not available in other formalisms. This has been shown, for example, to be a key ingredient in protein structural studies (e.g., Dal Palù et al. [2012a], Dal Palù et al. [2012b], Campeotto et al. [2013]) and in investigation of regulatory and metabolic networks (e.g., Gebser et al. [2011]).

•  Logic Programming technology has been advancing at a very rapid pace, becoming highly competitive with other technologies (e.g., SAT solving, other combinatorial search methods). This is opening the doors to levels of scalability and efficiency that will make even relatively simple declarative encodings an effective approach to obtain solutions to complex Bioinformatics problems (e.g., to produce putative solutions to be refined with alternative methods).

•  Several areas of Bioinformatics are discovering the added value of semantic annotations of datasets, e.g., through the use of formal ontologies, leading to the evolution of existing data repositories into actual knowledge bases. The role of logic-based methods is poised to substitute some traditional database queries with computation of logic-based inferences—as demonstrated in a number of preliminary studies (e.g., Prosdocimi et al. [2009], Chisham et al. [2011]).

Acknowledgments

We would like to thank the colleagues who helped us in our research in Bioinformatics: Federico Fogolari, Federico Campeotto, Pietro Cozzini, and Ferdinando Fioretto, and also the friends that has helped us in organizing the workshops on constraint based methods for bioinformatics, and in particular Sebastian Will, Rolf Backofen, and Francois Fages. We thank the organizers of the ACP school 2012: Krzysztof Apt, Witold Charatonik, and Leszek Pacholski; the organizers of the GULP summer school 2015 in Genova: Davide Ancona, Marco Maratea, and Viviana Mascardi; the program and tutorial chairs of CP 2015 in Cork: Gilles Pesant and Willem-Jan van Hoeve; the PC chairs of TAASP 2016 in Klagenfurt: Thomas Eiter, Wolfgang Faber, and Stefan Woltran; and the PC chairs of CP-SAT-ICLP 2017 in Melbourne: J. Christopher Beck, Serge Gaspers, Toby Walsh, Ricardo Rocha, and Tran Cao Son, who gave us the stimulus for organizing this material.

The research pursued by the authors in the area presented has been partially supported by INdAM GNCS 2014–2017 grants, by PRID project UniUD ENCASE, by YASMIN (RdB-UniPG2016/17) and FCRPG.2016.0105.021 projects, and by NSF grants CBET-1401639, HRD-1345232, CNS-1337884, and DGE-0947465. A. Dal Palù, A. Dovier, and A. Formisano are members of INdAM GNCS.

7.A    Instances

For the reader’s convenience we report here some data instances on which we ran the ASP encodings presented in the chapter (just cut & paste from the pdf—line numbers should be removed from ASP code). Expected running time will depend on the machine of course, but the instances are chosen to run in at most two to three of minutes.

7.A.1   Phylogenetics Reconstruction

Here is the instance used in Figure 7.4 plus two simple instances:

http://evolution.berkeley.edu/evolibrary/article/phylogenetics_07

You might need to define the following two predicates by projection of f:

7.A.2   Haplotype Inference

We provide one instance with |G| = 20 and n = 8. To generate other instances just change 2 into 0 or 1 (or vice versa) in some of the g facts.

7.A.3   RNA Secondary Structure Prediction

Try these instances with two different energy functions.

1.  E₁: 18 contacts, E₂: 16 contacts.

2.  E₁: 16 contacts, E₂: 14 contacts.

7.A.4   Protein Structure Prediction

1.  The following instance has many equivalent solutions, but it is easy to see that the first one cannot be improved.

2.  The search for the optimal solution of the next instance takes less than 1 min. In the optimal folding the hydrophobic amino acids are closed to each other and form a single core at the center of the protein. The solution has 6 contacts between hydrophobic amino acids.

Notice that this sequence of amino acids can be denoted by the writing h(pph)⁵. Longer instances of the form h(pph)n, for n > 0, can be obtained by adding triplets of facts.

3.  The instance shown below has several equivalent best solutions but it is not easy to see that a best solution cannot be improved. The instance consists of a sequence of hydrophobic amino acids. Longer instances of this kind can be plainly obtained by adding facts.

7.A.5   Gene Regulatory Networks

This is the data instance used in [Gebser et al. 2011].

Different results can be obtained by adding different observations about nodes. For instance with the following input, a minimal solution with two edges reversed is obtained:

while giving the following partial observations the network is consistent and an answer set with zero changes is found.

observed(le,plus).  observed(g,plus).

7.A.6   Metabolic Networks

This is a complete instance for the example in Figure 7.13.

The following example is from Sven Thiele’s Ph.D. thesis [Thiele 2012 (p. 42)].

References

E. B. Abdallah, M. Folschette, O. F. Roux, and M. Magnin. 2017. Asp-based method for the enumeration of attractors in non-deterministic synchronous and asynchronous multi-valued networks. Algorithms for Molecular Biology, 12(1): 20:1–20:23. DOI: 10.1186/s13015-017-0111-2. 403

D. Allouche, I. André, S. Barbe, J. Davies, S. de Givry, G. Katsirelos, B. O’Sullivan, S. D. Prestwich, T. Schiex, and S. Traoré. 2014. Computational protein design as an optimization problem. Artificial Intelligence, 212: 59–79. DOI: 10.1016/j.artint.2014.03.005. 404

G. Alterovitz and M. Ramoni, editors 2010. Knowledge-Based Bioinformatics: From Analysis to Interpretation. Wiley. 406

S. F. Altschul, W. Gish, W. Miller, E. W. Myers, and D. J. Lipman. 1990. Basic local alignment search tool. Journal of Molecular Biology, 215(3): 403–410. DOI: 10.1016/S0022-2836(05)80360-2. 360

C. B. Anfinsen. 1973. Principles that govern the folding of protein chains. Science, 181: 223–230. DOI: 10.1126/science.181.4096.223. 365

N. Angelopoulos and G. Giamas. 2014. Prolog Bioinformatic Pipelines: A Case Study in Gene Dysregulation. In Workshop on Constraint-Based Methods in Bioinformatics (WCB14). Lyon, France. 406

R. Backofen. 2001. The protein structure prediction problem: A constraint optimization approach using a new lower bound. Constraints, 6(2–3): 223–255. DOI: 10.1023/A:1011485622743. 392, 404

R. Backofen and S. Will. 2006. A constraint-based approach to fast and exact structure prediction in three-dimensional protein models. Constraints, 11(1): 5–30. DOI: 10.1007/s10601-006-6848-8. 392, 404

R. Backofen, A. Dal Palù, A. Dovier, and S. Will, Eds. 2012. Thematic series of AMB on constraints in bioinformatics. In Algorithms for Molecular Biology. BioMed Central Ltd. http://www.biomedcentral.com/collections/constr-and-bioinf. 361, 404

K. Baclawski and T. Niu. 2005. Ontologies for Bioinformatics. The MIT Press. 406

P. Barahona and L. Krippahl. 2008. Constraint programming in structural bioinformatics. Constraints, 13(1-2): 3–20. DOI: 10.1007/s10601-007-9036-6. 404

P. Barahona, L. Krippahl, and O. Perriquet. 2011. Bioinformatics: A challenge to constraint programming. Hybrid Optimization, 45: 463–487. DOI: 10.1007/s10601-007-9036-6. 360, 404

C. Baral. 2003. Knowledge Representation, Reasoning and Declarative Problem Solving. Cambridge University Press. 368

C. Baral, K. Chancellor, N. Tran, and N. Tran. 2003. Representing and reasoning about signal networks: an illustration using NFκB dependent signaling pathways. In CSB, pp. 623–628. IEEE Computer Society. DOI: 10.1109/CSB.2003.1227427. 403

C. Baral, K. Chancellor, N. Tran, N. Tran, A. M. Joy, and M. E. Berens. 2004. A knowledge based approach for representing and reasoning about signaling networks. In ISMB/ECCB (Supplement of Bioinformatics), pp. 15–22. DOI: 10.1093/bioinformatics/bth918. 403

J. Bard. 2003. Ontologies: formalising biological knowledge for bioinformatics. Functional Genomics and Bioinformatics, 25: 501–506. DOI: 10.1002/bies.10260. 406

M. Bauer, G. W. Klau, and K. Reinert. 2007. RNA pseudoknot prediction in energy-based models. BMC Bioinformatics, 8. 389

M. Bavarian and V. Dahl. November 2006. Constraint based methods for biological sequence analysis. Journal of Universal Computer Science, 12(11): 1500–1520. 386, 388, 405

L. Bortolussi, S. Fonda, and A. Policriti. 2007. Constraint-based simulation of biological systems described by molecular interaction maps. In Proceedings of the 2007 IEEE International Conference on Bioinformatics and Biomedicine, BIBM ’07, pp. 288–293. IEEE Computer Society. DOI: 10.1109/BIBM.2007.31. 405

A. Brazma, P. Hingamp, J. Quackenbush, G. Sherlock, P. Spellman, C. Stoeckert, J. Aach, W. Ansorge, C. Ball, H. Causton, T. Gaasterland, P. Glenisson, F. Holstege, I. Kim, V. Markowitz, J. Matese, H. Parkinson, A. Robinson, U. Sarkans, S. Schulze-Kremer, J. Stewart, R. Taylor, J. Vilo, and M. Vingron. 2001. Minimum information about a microarray experiment (MIAME)-toward standards for microarray data. Nature Genetics, 4(29): 365–371. DOI: 10.1038/ng1201-365. 360

D. Brooks, E. Erdem, J. Minett, and D. Ringe. 2005. Character-based cladistics and Answer Set Programming. In Practical Aspects of Declarative Languages, pp. 37–51. Springer Verlag. DOI: 10.1007/978-3-540-30557-6_5. 377

D. Brooks, E. Erdem, S. Erdogan, J. Minett, and D. Ringe. 2007. Inferring phylogenetic trees using answer set programming. Journal of Automated Reasoning, 39(4): 471–511. DOI: 10.1007/s10817-007-9082-1. 377

D. G. Brown and I. M. Harrower. 2006. Integer programming approaches to haplotype inference by pure parsimony. IEEE/ACM Transactions on Computational Biology and Bioinformatics, 3(2): 141–154. DOI: 10.1109/TCBB.2006.24. 384

D. Buezas, J. Almeida, and P. Barahona. 2010. Minimizing enzymes to diferenciate between species. In Workshop on Constraint Based Methods for Bioinformatics (WCB10), pp. 75–82. Edinburgh, UK. 404

A. Burger, D. Davidson, and R. Baldock. 2004. Formalization of Mouse Embryo Anatomy. Bioinformatics, 20: 259–267. 406

D. Cakmak. 2010. Reconstructing Weighted Phylogenetic Trees and Weighted Phylogenetic Networks using Answer Set Programming. Master’s thesis, Sabanci University. 377, 379

D. Cakmak, E. Erdem, and H. Erdogan. 2009. Computing weighted solutions in answer set programming. In Logic Programming and Nonmonotonic Reasoning, pp. 416–422. Springer Verlag. DOI: 10.1007/978-3-642-04238-6_36. 377

D. Cakmak, H. Erdogan, and E. Erdem. 2010. Computing weighted solutions in ASP: Representation-based method vs. search-based method. In Proc. of RCRA Workshop on Experimental Evaluation of Algorithms for Solving Problems with Combinatorial Explosion. DOI: 10.1007/s10472-011-9242-1. 377

L. Calzone, F. Fages, and S. Soliman. 2006. Biocham: an environment for modeling biological systems and formalizing experimental knowledge. Bioinformatics, 22(14): 1805–1807. DOI: 10.1093/bioinformatics/btl172. 404

F. Campeotto, A. Dal Palù, A. Dovier, F. Fioretto, and E. Pontelli. 2012. A filtering technique for fragment assembly- based proteins loop modeling with constraints. In M. Milano, editor, CP, vol. 7514 of Lecture Notes in Computer Science, pp. 850–866. Springer. DOI: 10.1007/978-3-642-33558-7_61. 393

F. Campeotto, A. Dal Palù, A. Dovier, F. Fioretto, and E. Pontelli. 2013. A constraint solver for flexible protein model. Jounral of Artificial Intelligence Research (JAIR), 48: 953–1000. DOI: 10.1613/jair.4193. 393, 407

F. Campeotto, A. Dovier, and E. Pontelli. 2015. A declarative concurrent system for protein structure prediction on GPU. The Journal of Experimental and Theoretical Artificial Intelligence,, 27(5): 503–541. DOI: 10.1080/0952813X.2014.993503. 393

A. Canutescu and R. Dunbrack. 2003. Cyclic coordinate descent: a robotics algorithm for protein loop closure. Protein Science, 12: 963–972. DOI: 10.1110/ps.0242703. 393

D. Catanzaro and M. Labbé. 2009. The pure parsimony haplotyping problem: overview and computational advances. International Transactions in Operational Research, 16(5): 561–584. DOI: 10.1111/j.1475-3995.2009.00716.x. 384

C. Chaouiya, E. Remy, B. Mossé, and D. Thieffry. 2003. Qualitative analysis of regulatory graphs: A computational tool based on a discrete formal framework. In L. Benvenuti, A. D. Santis, and L. Farina, editors, POSTA, vol. 294 of Lecture Notes in Control and Information Sciences, pp. 119–126. Springer. DOI: 10.1007/978-3-540-44928-7_17. 403

L. Chen, R.-S. Wang, and X.-S. Zhang. 2009. Biomolecular Networks: Methods and Applications in Systems Biology. John Wiley & Sons. 399, 403

B. Chisham, B. Wright, T. Le, T. Son, and E. Pontelli. 2011. CDAO-Store: ontology-driven data integration for phylogenetic analysis. BMC Bioinformatics, 12: 98. DOI: 10.1186/1471-2105-12-98. 361, 379, 406, 407

H. Christiansen, C. T. Have, O. T. Lassen, and M. Petit. 2010. Inference with constrained hidden markov models in prism. Theory and Practice of Logic Programming, 10(4-6): 449–464. DOI: 10.1017/S1471068410000219. 405

A. G. Clark. 1990. Inference of haplotypes from PCR amplified samples of diploid populations. Molecular Biology and Evolution, 7(2): 111–122. DOI: 10.1093/oxfordjournals.molbev.a040591. 384

P. Clote and R. Backofen. 2001. Computational Molecular Biology: An Introduction. John Wiley & Sons. 360, 362

E. C¸ oban, E. Erdem, and F. Türe. 2008. Comparing ASP, CP, ILP on some challenging problems. In The 2nd International Workshop on Logic and Search – LaSh08. 383, 384

J. Cohen. June 2004. Bioinformatics: An introduction for computer scientists. ACM Computing Sureys., 36(2): 122–158. DOI: 10.1145/1031120.1031122. 362

G. Collet, D. Eveillard, M. Gebser, S. Prigent, T. Schaub, A. Siegel, and S. Thiele. 2013. Extending the metabolic network of Ectocarpus Siliculosus using answer set programming. In P. Cabalar and T. Son, editors, Logic Programming and Nonmonotonic Reasoning, vol. 8148 of Lecture Notes in Computer Science, pp. 245–256. Springer Berlin Heidelberg. DOI: 10.1007/978-3-642-40564-8_25. 399, 402, 406

F. Corblin, S. Tripodi, E. Fanchon, D. Ropers, and L. Trilling. 2009. A declarative constraint-based method for analyzing discrete genetic regulatory networks. Biosystems, 98(2): 91–104. DOI: 10.1016/j.biosystems.2009.07.007. 403

F. Corblin, E. Fanchon, and L. Trilling. 2010. Applications of a formal approach to decipher discrete genetic networks. BMC Bioinformatics, 11: 385. DOI: 10.1186/1471-2105-11-385. 403

F. Corblin, E. Fanchon, L. Trilling, C. Chaouiya, and D. Thieffry. 2012. Automatic inference of regulatory and dynamical properties from incomplete gene interaction and expression data. In M. A. Lones, S. L. Smith, S. A. Teichmann, F. Naef, J. A. Walker, and M. Trefzer, editors, IPCAT, vol. 7223 of Lecture Notes in Computer Science, pp. 25–30. Springer. DOI: 10.1007/978-3-642-28792-3_4. 403

P. Crescenzi, D. Goldman, C. Papadimitrou, A. Piccolboni, and M. Yannakakis. 1998. On the complexity of protein folding. In Proc. of STOC, pp. 597–603. DOI: 10.1089/cmb.1998.5.423. 390

F. Crick. 1958. On protein synthesis. In F. Sanders, editor, Symposia of the Society for Experimental Biology, Number XII: The Biological Replication of Macromolecules, p. 138–163. Cambridge University Press. 362

F. Crick. 1970. Central dogma of molecular biology. Nature, 227: 561–3. 362

A. Dal Palù, A. Dovier, and F. Fogolari. 2004. Constraint logic programming approach to protein structure prediction. BMC Bioinformatics, 5: 186. DOI: 10.1186/1471-2105-5-186. 392

A. Dal Palù, A. Dovier, F. Fages, and S. Will. 2007. Constraint based methods for bioinformatics. In PART VI of Trends in Constraint Programming, pp. 125–146. Hermes Science. 361, 404

A. Dal Palù, A. Dovier, and E. Pontelli. 2007. A constraint solver for discrete lattices, its parallelization, and application to protein structure prediction. Software Practice and Experience, 37(13): 1405–1449. DOI: 10.1002/spe.810. 392

A. Dal Palù, A. Dovier, and S. Will. June 2008. Introduction to the special issue on bioinformatics and constraints. Constraints, 13(1-2): 1–2. DOI: 10.1007/s10601-007-9030-z. 361, 404

A. Dal Palù, A. Dovier, F. Fogolari, and E. Pontelli. 2010. CLP-based protein fragment assembly. TPLP, 10(4-6): 709–724. DOI: 10.1017/S1471068410000372. 392

A. Dal Palù, M. Möhl, and S. Will. 2010. A propagator for maximum weight string alignment with arbitrary pairwise dependencies. In Proceedings of the 16th international conference on Principles and practice of constraint programming, CP’10, pp. 167–175. Springer-Verlag, Berlin, Heidelberg. DOI: 10.1007/978-3-642-15396-9_16. 389, 404

A. Dal Palù, A. Dovier, F. Fogolari, and E. Pontelli. 2012a. Protein structure analysis with constraint programming. In P. Cozzini, G. Kellogg, D. Rotella, and A. Martinez, editors, Computational Approaches to Nuclear Receptors, chap. 3, pp. 40–59. The Royal Society of Chemistry. 392, 407

A. Dal Palù, F. Spyrakis, and P. Cozzini. 2012b. A new approach for investigating protein flexibility based on Constraint Logic Programming: The first application in the case of the estrogen receptor. European Journal of Medicinal Chemistry, 49: 127–140. DOI: 10.1016/j.ejmech.2012.01.003. 407

E. Dantsin, T. Eiter, G. Gottlob, and A. Voronkov. Sept. 2001. Complexity and expressive power of logic programming. ACM Computing Surveys, 33(3): 374–425. DOI: 10.1145/502807.502810. 368

W. Day. 1983. Computationally difficult parsimony problems in phylogenetic systematics. Journal of Theoretical Biology, 103(3): 429–438. DOI: 10.1016/0022-5193(83)90296-5. 374

W. Day and D. Sankoff. 1986. Computational complexity of inferring phylogenies by compatibility. Systematic Zoology, 35(2): 224–229. DOI: 10.1093/sysbio/35.2.224. 374

D. De Maeyer, J. Renkens, L. Cloots, L. De Raedt, and K. Marchal. 2013. Phenetic: networkbased interpretation of unstructured gene lists in e. coli. Molecular BioSystems, 9: 1594–1603. DOI: 10.1039/c3mb25551d. 405

L. Di Gaspero and A. Roli. 2008. Stochastic local search for large-scale instances of the haplotype inference problem by pure parsimony. Journal of Algorithms, 63(1-3): 55–69. DOI: 10.1016/j.jalgor.2008.02.004. 384

K. A. Dill. 1990. Dominant forces in protein folding. Biochemistry, 29: 7133–7155. DOI: 10.1021/bi00483a001. 392

A. Dobson. 1969. Lexicostatistical grouping. Anthropological Linguistics, 11: 216–221. 371

G. Dooms, Y. Deville, and P. Dupont. 2005. CP(Graph): Introducing a graph computation domain in constraint programming. In P. van Beek, editor, Principles and Practice of Constraint Programming CP 2005, vol. 3709 of Lecture Notes in Computer Science, pp. 211–225. Springer Berlin Heidelberg. DOI: 10.1007/11564751_18. 405

A. Dovier, A. Formisano, and E. Pontelli. 2007. An experimental comparison of constraint logic programming and answer set programming. In Proceedings of the Twenty-Second AAAI Conference on Artificial Intelligence, July 22-26, 2007, Vancouver, British Columbia, Canada, pp. 1622–1625. AAAI Press. 404

A. Dovier, A. Formisano, and E. Pontelli. 2009. An empirical study of constraint logic programming and answer set programming solutions of combinatorial problems. Journal of Experimental and Theoretical Artificial Intelligence, 21(2): 79–121. DOI: 10.1080/09528130701538174. 368, 390, 404

W. Dubitzky, O. Wolkenhauer, K.-H. Cho, and H. Yokota. 2013. Encyclopedia of Systems Biology. Springer. 402

M. Durzinsky, W. Marwan, M. Ostrowski, T. Schaub, and A. Wagler. 2011. Automatic network reconstruction using ASP. TPLP, 11(4-5): 749–766. DOI: 10.1017/S1471068411000287. 403

S. Dworschak, S. Grell, V. J. Nikiforova, T. Schaub, and J. Selbig. 2008a. Modeling biological networks by action languages via answer set programming. Constraints, 13(1-2): 21–65. DOI: 10.1007/s10601-007-9031-y. 404

S. Dworschak, T. Grote, A. König, T. Schaub, and P. Veber. 2008b. The system BioC for reasoning about biological models in action language C. In ICTAI (1), pp. 11–18. IEEE Computer Society. DOI: 10.1109/ICTAI.2008.69. 404

J. Eisen and P. Hanawalt. 1999. A phylogenomic study of DNA repair genes, proteins, and processes. Mutation Research - DNA Repair, 435(3): 171–213. DOI: 10.1016/S0921-8777(99)00050-6. 371

E. Erdem. 2011. Applications of answer set programming in phylogenetic systematics. In M. Balduccini and T. C. Son, editors, Logic Programming, Knowledge Representation, and Nonmonotonic Reasoning, vol. 6565 of Lecture Notes in Computer Science, pp. 415–431. Springer. DOI: 10.1007/978-3-642-20832-4_26. 377, 406

E. Erdem and U. Oztok. 2012. BioQuery-ASP: Querying Biomedical Databases and Ontologies Using Answer Set Programming. EMBnet.journal, 18. DOI: 10.14806/ej.18.B.551. 406

E. Erdem and F. Türe. 2008. Efficient haplotype inference with answer set programming. In D. Fox and C. P. Gomes, editors, Proceedings of the Twenty-Third AAAI Conference on Artificial Intelligence, AAAI 2008, Chicago, IL, July 13–17, 2008, pp. 436–441. AAAI Press. 381, 382, 383

E. Erdem, V. Lifschitz, L. Nakhleh, and D. Ringe. 2003. Reconstructing the evolutionary history of Indo-European languages using answer set programming. In Practical Aspects of Declarative Languages, pp. 160–176. Springer Verlag. DOI: 10.1007/3-540-36388-2_12. 378

E. Erdem, V. Lifschitz, and D. Ringe. 2006. Temporal phylogenetic networks and logic programming. Theory and Practice of Logic Programming, 6(5): 539–558. DOI: 10.1017/S1471068406002729. 378, 379

E. Erdem, O. Erdem, and F. Türe. 2009. HAPLO-ASP: Haplotype inference using answer set programming. In E. Erdem, F. Lin, and T. Schaub, editors, Logic Programming and Nonmonotonic Reasoning, 10th International Conference, LPNMR 2009, Potsdam, Germany, September 14–18, 2009. Proceedings, vol. 5753 of Lecture Notes in Computer Science, pp. 573–578. Springer. DOI: 10.1007/978-3-642-04238-6_60. 383

G. Estabrook. 1997. Ancestor-descendant relations and incompatible data: Motivation for research in discrete mathematics. In Mathematical Hierarchies and Biology, vol. 27 of DIMAS Series in Discrete Mathematics, pp. 1–28. American Mathematical Society. 374

E. Fanchon, F. Corblin, L. Trilling, B. Hermant, and D. Gulino. 2005. Modeling the molecular network controlling adhesion between human endothelial cells: Inference and simulation using constraint logic programming. In V. Danos and V. Schachter, editors, Computational Methods in Systems Biology, vol. 3082 of Lecture Notes in Computer Science, pp. 104–118. Springer Berlin Heidelberg. DOI: 10.1007/978-3-540-25974-9_9. 405

T. Fayruzov, M. D. Cock, C. Cornelis, and D. Vermeir. 2009. Modeling protein interaction networks with answer set programming. In BIBM, pp. 99–104. IEEE Computer Society. DOI: 10.1109/BIBM.2009.9. 403

T. Fayruzov, J. Janssen, C. Cornelis, D. Vermeir, and M. De Cock. 2010. Extending boolean regulatory network models with answer set programming. In Proceedings 2010 IEEE International Conference on Bioinformatics and Biomedicine Workshops (BIBMW 2010), pp. 207–212. IEEE. DOI: 10.1109/BIBMW.2010.5703800. 403

T. Fayruzov, J. Janssen, D. Vermeir, C. Cornelis, and M. D. Cock. 2011. Modelling gene and protein regulatory networks with answer set programming. IJDMB, 5(2): 209–229. DOI: 10.1504/IJDMB.2011.039178. 403

F. Fioretto and E. Pontelli. 2013. Constraint programming in community-based gene regulatory network inference. In A. Gupta and T. Henzinger, editors, Computational Methods in Systems Biology, vol. 8130 of Lecture Notes in Computer Science, pp. 135–149. Springer Berlin Heidelberg. DOI: 10.1007/978-3-642-40708-6_11. 405

L. F. Fitime, O. F. Roux, C. Guziolowski, and L. Paulevé. 2017. Identification of bifurcation transitions in biological regulatory networks using answer-set programming. Algorithms for Molecular Biology, 12(1): 19:1–19:14. DOI: 10.1186/s13015-017-0110-3. 403

C. A. Floudas. 2007. Computational methods in protein structure prediction. Biotechnology and Bioengineering, 97(2): 207–213. DOI: 10.1002/bit.21411. 392

M. Folschette, L. Paulevé, K. Inoue, M. Magnin, and O. Roux. 2012. Concretizing the process hitting into biological regulatory networks. In D. Gilbert and M. Heiner, editors, CMSB, vol. 7605 of Lecture Notes in Computer Science, pp. 166–186. Springer. DOI: 10.1007/978-3-642-33636-2_11. 403

C. Frioux, T. Schaub, S. Schellhorn, A. Siegel, and P. Wanko. 2017. Hybrid metabolic network completion. In M. Balduccini and T. Janhunen, editors, Logic Programming and Nonmonotonic Reasoning 14th International Conference, LPNMR 2017, Espoo, Finland, July 3–6, 2017, Proceedings, vol. 10377 of Lecture Notes in Computer Science, pp. 308–321. Springer. DOI: 10.1007/978-3-319-61660-5_28. 402

M. Gebser, C. Guziolowski, M. Ivanchev, T. Schaub, A. Siegel, S. Thiele, and P. Veber. 2010a. Repair and prediction (under inconsistency) in large biological networks with answer set programming. In F. Lin, U. Sattler, and M. Truszczyński, editors, Principles of Knowledge Representation and Reasoning, 2010. Toronto, Canada. 397, 403

M. Gebser, A. König, T. Schaub, S. Thiele, and P. Veber. 2010b. The BioASP library: ASP solutions for systems biology. In ICTAI (1), pp. 383–389. IEEE Computer Society. DOI: 10.1109/ICTAI.2010.62. 403

M. Gebser, T. Schaub, S. Thiele, and P. Veber. 2011. Detecting inconsistencies in large biological networks with answer set programming. TPLP, 11(2-3): 323–360. DOI: 10.1007/978-3-540-89982-2_19. 396, 397, 402, 403, 407, 411

M. Gelfond. 2008. Answer sets. In F. van Harmelen, V. Lifschitz, B. Porter, Editors, Handbook of Knowledge Representation. chap. 7. Elsevier. DOI: 10.1016/S1574-6526(07)03007-6. 368

M. Gelfond and V. Lifschitz. 1988. The stable model semantics for logic programming. In R. A. Kowalski and K. A. Bowen, editors, Logic Programming, Proceedings of the Fifth International Conference and Symposium, Seattle, Washington, August 15–19, 1988 (2 vols.), pp. 1070–1080. MIT Press. 366, 367

I. Gent, P. Prosser, B. Smith, and W. Wei. 2003. Supertree construction with constraint programming. In F. Rossi, editor, Principles and Practice of Constraint Programming—CP 2003, vol. 2833 of Lecture Notes in Computer Science, pp. 837–841. Springer Berlin Heidelberg. DOI: 10.1007/978-3-540-45193-8_63. 404

H. Gleason. 1959. Counting and calculating for historical reconstruction. Anthropological Linguistics, 1: 22–32. 371

G. H. Gonnet. 2004. Some string matching problems from bioinformatics which still need better solutions. Journal of Discrete Algorithms, 2(1): 3 – 15. The 9th International Symposium on String Processing and Information Retrieval. DOI: 10.1016/S1570-8667(03)00062-5. 360

A. Grac¸ a, J. Marques-Silva, I. Lynce, and A. Oliveira. 2007. Efficient haplotype inference with pseudo-boolean optimization. In Proceedings of the Algebraic Biology Conference. DOI: 10.1007/978-3-540-73433-8_10. 383

A. Grac¸ a, I. Lynce, J. Marques-Silva, and A. L. Oliveira. 2010. Haplotype inference by pure parsimony: A survey. Journal of Computational Biology, 17(8): 969–992. DOI: 10.1089/cmb.2009.0101. 384

A. Grac¸ a, J. Marques-Silva, and I. Lynce. 2011. Haplotype inference using propositional satisfiability. In R. Bruni, editor, Mathematical Approaches to Polymer Sequence Analysis and Related Problems, pp. 127–147. Springer. DOI: 10.1007/978-1-4419-6800-5_7. 384

T. Gruber. 1995. Toward principles for the design of ontologies used for knowedge sharing. International Journal of Human Computer Studies, 43(5-6). DOI: 10.1006/ijhc.1995.1081. 371

D. Gusfield. 1997. Algorithms on Strings, Trees, and Sequences: Computer Science and Computational Biology. Cambridge University Press, New York. 360, 362

D. Gusfield. 2002a. Haplotyping as perfect phylogeny: conceptual framework and efficient solutions. In Sixth Annual International Conference on Computational Biology, pp. 166–175. ACM. DOI: 10.1145/565196.565218. 384

D. Gusfield. 2002b. An overview of combinatorial methods for haplotype inference. In S. Istrail, M. S. Waterman, and A. G. Clark, editors, Computational Methods for SNPs and Haplotype Inference, vol. 2983 of Lecture Notes in Computer Science, pp. 9–25. Springer. DOI: 10.1007/978-3-540-24719-7_2. 380

D. Gusfield and S. H. Orzack. 2005. Haplotype inference. In S. Aluru, editor, Handbook of Computational Molecular Biology, Computer & Information Science, chap. 18. Chapman & Hall/CRC. 380, 384

C. Guziolowski, S. Videla, F. Eduati, S. Thiele, T. Cokelaer, A. Siegel, and J. Saez-Rodriguez. 2013. Exhaustively characterizing feasible logic models of a signaling network using answer set programming. Bioinformatics, 29(18): 2320–2326. DOI: 10.1093/bioinformatics/btt393. 403

B. V. Halldórsson, V. Bafna, N. Edwards, R. Lippert, S. Yooseph, and S. Istrail. 2002. A survey of computational methods for determining haplotypes. In S. Istrail, M. S. Waterman, and A. G. Clark, editors, Computational Methods for SNPs and Haplotype Inference, vol. 2983 of Lecture Notes in Computer Science, pp. 26–47. Springer. DOI: 10.1007/978-3-540-24719-7_3. 380, 384

R. Hoehndorf, F. Loebe, J. Kelso, and H. Herre. 2007. Representing default knowledge in biomedical ontologies: application to the integration of anatomy and phenotype ontologies. BMC Bioinformatics, 8: 377. DOI: 10.1186/1471-2105-8-377. 406

R. Hudson. 2002. Generating samples under a wrightfisher neutral model of genetic variation. Bioinformatics, 18: 337–338. DOI: 10.1093/bioinformatics/18.2.337. 384

International Human Genome Sequencing Consortium. 2004. Finishing the euchromatic sequence of the human genome. Nature, 431: 931–45. DOI: 10.1038/nature03001. 362

G. Jin, L. Nakhleh, S. Snir, and T. Tuller. 2007. Inferring phylogenetic networks by the maximum parsimony criterion: a case study. Molecular Biology and Evolution, 24(1): 324–337. DOI: 10.1093/molbev/msl163. 379

N. C. Jones and P. Pevzner. 2004. An Introduction to Bioinformatics Algorithms. Computational Molecular Biology. MIT Press, Cambridge, MA, London. 362

T. Kelsey, L. Kotthoff, C. Jefferson, S. Linton, I. Miguel, P. Nightingale, and I. Gent. 2014. Qualitative modelling via constraint programming. Constraints, 19(2): 163–173. DOI: 10.1007/s10601-014-9158-6. 405

A. Kimmig, V. S. Costa, R. Rocha, B. Demoen, and L. D. Raedt. 2008. On the efficient execution of problog programs. In Logic Programming, 24th International Conference, ICLP 2008, Udine, Italy, December 9–13 2008, Proceedings, pp. 175–189. DOI: 10.1007/978-3-540-89982-2_22. 405

L. Koponen, E. Oikarinen, T. Janhunen, and L. Säilä. 2015. Optimizing phylogenetic supertrees using answer set programming. TPLP, 15(4-5): 604–619. DOI: 10.1017/S1471068415000265. 378

G. Lancia, M. C. Pinotti, and R. Rizzi. 2004. Haplotyping populations by pure parsimony: Complexity of exact and approximation algorithms. INFORMS Journal on Computing, 16(4): 348–359. DOI: 10.1287/ijoc.1040.0085. 380, 381

A. Larhlimi and A. Bockmayr. 2009. A new constraint-based description of the steady-state flux cone of metabolic networks. Discrete Applied Mathematics, 157(10): 2257–2266. Networks in Computational Biology. DOI: 10.1016/j.dam.2008.06.039. 405

T. Le, H. Nguyen, E. Pontelli, and T. Son. 2012. ASP at Work: An ASP Implementation of PhyloWS. In International Conference on Logic Programming, pp. 359–369. DOI: 10.4230/LIPIcs.ICLP.2012.359. 379, 406

W. Le Quesne. 1969. A method of selection of characters in numerical taxonomy. Systematic Zoology, 18: 201–205. DOI: 10.2307/2412604. 372

W. Le Quesne. 1972. Further studies based on the uniquely derived character concept. Systematic Zoology, 21: 281–288. DOI: 10.2307/2412166. 372

J. Lee, D. Lee, H. Park, E. Coutsias, and C. Seok. 2010. Protein Loop Modeling by Using Fragment Assembly and Analytical Loop Closure. Proteins, 78(16): 3428–3436. DOI: 10.1002/prot.22849. 393

A. Lesk. 2008. Introduction to Bioinformatics. Oxford University Press. 360

D. Liberles and M. Wayne. 2002. Tracking adaptive evolutionary events in genomic sequences. Genome Biol., 3(6). DOI: 10.1186/gb-2002-3-6-reviews1018. 371

P. Liu, F. Zhu, D. Rassokhin, and D. Agrafiotis. 2009. A self-organizing algorithm for modeling protein loops. PLOS Computational Biology, 5(8). DOI: 10.1371/journal.pcbi.1000478. 393

J. W. Lloyd. 1987. Foundations of Logic Programming. Springer-Verlag. 366, 368

I. Lynce and J. Marques-Silva. 2006. Efficient haplotype inference with boolean satisfiability. In Proceedings of the National Conference on Artificial Intelligence (AAAI). 383

R. Lyngso and C. Pedersen. 2000. RNA pseudoknot prediction in energy-based models. Journal of Computational Biology, 7(3-4): 409–427. DOI: 10.1089/106652700750050862. 389

M. Mann, F. Nahar, N. Schnorr, R. Backofen, P. F. Stadler, and C. Flamm. 2014. Atom mapping with constraint programming. Algorithms for Molecular Biology, 9: 23. DOI: 10.1186/s13015-014-0023-3. 404

V. W. Marek and M. Truszczyński. 1999. Stable models and an alternative logic programming paradigm. In The Logic Programming Paradigm, pp. 375–398. Springer Verlag. DOI: 10.1007/978-3-642-60085-2_17. 366

E. Mayr. 1964. Systematics and the Origin of Species. Dover Publications. 379

J. S. McCaskill. 1990. The equilibrium partition function and base pair binding probabilities for RNA secondary structure. Biopolymers, 29(6–7): 1105–1119. DOI: 10.1002/bip.360290621. 386, 388

S. Muggleton, A. Srinivasan, R. D. King, and M. J. E. Sternberg. 1998. Biochemical knowledge discovery using inductive logic programming. In S. Arikawa and H. Motoda, editors, Discovery Science, First International Conference, DS ’98, Fukuoka, Japan, December 14–16, 1998, Proceedings, vol. 1532 of Lecture Notes in Computer Science, pp. 326–341. Springer. DOI: 10.1007/3-540-49292-5_29. 405

C. Mungall. 2009. Experiences Using Logic Programming in Bioinformatics. In International Conference on Logic Programming, pp. 1–21. Springer Verlag. DOI: 10.1007/978-3-642-02846-5_1. 406

S. Mørk and I. Holmes. 2012. Evaluating bacterial gene-finding hmm structures as probabilistic logic programs. Bioinformatics, 28(5): 636–642. DOI: 10.1093/bioinformatics/btr698. 405

L. Nakhleh, T. Warnow, C. Linder, and K. St John. 2005. Reconstructing reticulate evolution in species-theory and practice. Journal of Computational Biology, 12(6): 796–811. DOI: 10.1089/cmb.2005.12.796. 379

A. Neumaier. 1997. Molecular modeling of proteins and mathematical prediction of protein structure. SIAM Review, 39: 407–460. DOI: 10.1137/S0036144594278060. 392

J. Nichols and T. Warnow. 2008. Tutorial on computational linguistic phylogeny. Language and Linguistics Compass, 2/5: 760–820. DOI: 10.1111/j.1749-818X.2008.00082.x. 379

I. Niemelä. 1999. Logic programs with stable model semantics as a constraint programming paradigm. Annals of Mathematics and Artificial Intelligence, 25(3-4): 241–273. DOI: 10.1023/A:1018930122475. 366

Z. Nikoloski, S. Grimbs, P. May, and J. Selbig. 2008a. Metabolic networks are NP-hard to reconstruct. Journal of Theoretical Biology, 254(4): 807–816. DOI: 10.1016/j.jtbi.2008.07.015. 400

Z. Nikoloski, S. Grimbs, J. Selbig, and O. Ebenhöh. 2008b. Hardness and approximability of the inverse scope problem. In K. A. Crandall and J. Lagergren, editors, WABI, vol. 5251 of Lecture Notes in Computer Science, pp. 99–112. Springer. DOI: 10.1007/978-3-540-87361-7_9. 399, 400

R. Nussinov and A. B. Jacobson. 1980. Fast algorithm for predicting the secondary structure of single-stranded RNA. Proceedings of the National Academy of Sciences USA, 77(11): 6309–6313. DOI: 10.1073/pnas.77.11.6309. 386, 388

M. Ostrowski, L. Paulevé, T. Schaub, A. Siegel, and C. Guziolowski. 2016. Boolean network identification from perturbation time series data combining dynamics abstraction and logic programming. Biosystems, 149: 139–153. DOI: 10.1016/j.biosystems.2016.07.009. 403

Y. Pan, E. Pontelli, and T. Son. 2010. BSIS: An Experiment in Automating Bioinformatics Tasks Through Intelligent Workflow Construction. In Semantic e-Science, pp. 189–238. Springer Verlag. DOI: 10.1007/978-1-4419-5908-9_6. 360

F. Prosdocimi, B. Chisham, E. Pontelli, J. Thompson, and A. Stoltzfus. 2009. Initial implementation of a comparative data analysis ontology. Evolutionary Bioinformatics, 5: 47–66. 379, 407

S. Raman, R. Vernon, J. Thompson, M. Tyka, R. Sadreyev, J. Pei, D. Kim, E. Kellogg, F. DiMaio, O. Lange, L. Kinch, W. Sheffler, B.-H. Kim, R. Das, N. V. Grishin, and D. Baker. 2009. Structure prediction for CASP8 with all-atom refinement using Rosetta. Proteins, 77(Suppl. 9): 89–99. DOI: 10.1002/prot.22540. 393

O. Ray, T. Soh, and K. Inoue. 2010. Analyzing pathways using ASP-based approaches. In K. Horimoto, M. Nakatsui, and N. Popov, editors, ANB, vol. 6479 of Lecture Notes in Computer Science, pp. 167–183. Springer. DOI: 10.1007/978-3-642-28067-2_10. 403

D. Ringe, T.Warnow, and A. Taylor. 2002. Indo-European and computational cladistics. Transactions of the Philological Society, 100(1): 59–129. DOI: 10.1111/1467-968X.00091. 371

G. Rodrigo, J. Carrera, and A. Jaramillo. 2011. Computational design of synthetic regulatory networks from a genetic library to characterize the designability of dynamical behaviors. Nucleic Acids Research, 39(20): e138–e138. DOI: 10.1093/nar/gkr616. 405

R. Rossnes, I. Eidhammer, and D. Liberles. 2007. Phylogenetic reconstruction of ancestral character states for gene expression and mRNA splicing data. BMC Bioinformatics, 6(1): 127. DOI: 10.1186/1471-2105-6-127. 372

M. Sanchez, S. Givry, and T. Schiex. June 2008. Mendelian error detection in complex pedigrees using weighted constraint satisfaction techniques. Constraints, 13(1-2): 130–154. DOI: 10.1007/s10601-007-9029-5. 405

D. Sankoff. 1985. Simultaneous solution of the RNA folding, alignment and protosequence problems. SIAM Journal on Applied Mathematics, 45(5): 810–825. DOI: 10.1137/0145048. 388

T. Sato. 1995. A statistical learning method for logic programs with distribution semantics. In Proceedings of the 12th International Conference on Logic Programming (ICLP 95), pp. 715–729. 405

T. Schaub and S. Thiele. 2009. Metabolic network expansion with answer set programming. In P. M. Hill and D. S. Warren, editors, ICLP, vol. 5649 of Lecture Notes in Computer Science, pp. 312–326. Springer. DOI: 10.1007/978-3-642-02846-5_27. 399, 401, 402, 406

N. Schuurman and A. Leszczynski. 2008. Ontologies for bioinformatics. Bioinformatics and Biology Insights, 2: 187–200. 406

R. Sharan, B. V. Halldórsson, and S. Istrail. 2006. Islands of tractability for parsimony haplotyping. IEEE/ACM Transactions on Computational Biology and Bioinformatics, 3(3): 303–311. DOI: 10.1109/TCBB.2006.40. 384

S. Soliman, F. Fages, and O. Radulescu. 2014. A constraint solving approach to model reduction by tropical equilibration. Algorithms for Molecular Biology, 9(1): 24. DOI: 10.1186/s13015-014-0024-2. 405

T. Son, E. Pontelli, and T. Le. 2013. Two Applications of the ASP-Prolog System: Decomposable Programs and Multi-context Systems. In Practical Aspects of Declarative Languages. Springer Verlag. DOI: 10.1007/978-3-319-04132-2_7. 377

E. Stone and A. Sidow. 2005. Physicochemical constraint violation by missense substitutions mediates impairment of protein function and disease severity. Genome Research, 15(7): 978–986. DOI: 10.1101/gr.3804205. 371

A. Taylor, T. Warnow, and D. Ringe. 2000. Character-based reconstruction of a linguistic cladogram. In J. Smith and D. Bentley, editors, Historical Linguistics, vol. 1, pp. 393–408. Benjamins. DOI: 10.1075/cilt.161.25tay. 371

D. Thau. 2010. Reasoning about Taxonomies. Ph.D. thesis, U.C. Davis. 379 379

P. Thebault, S. De Givry, T. Schiex, and C. Gaspin. 2006. Searching rna motifs and their intermolecular contacts with constraint networks. Bioinformatics, 22(17): 2074–2080. DOI: 10.1093/bioinformatics/btl354. 405

S. Thiele. 2012. Modeling Biological Systems with Answer Set Programming. Doctor rerum naturalium thesis, Universität Potsdam. 412

R. Thomas. 1991. Regulatory networks seen as asynchronous automata: A logical description. Journal of Theoretical Biology, 153(1): 1–23. DOI: 10.1016/S0022-5193(05)80350-9. 403

R. Thomas and M. Kaufman. 2001. Multistationarity, the basis of cell differentiation and memory. I. structural conditions of multistationarity and other nontrivial behavior. Chaos: An Interdisciplinary Journal of Nonlinear Science, 11(1): 170–179. DOI: 10.1063/1.1350439. 403

R. Thomas, D. Thieffry, and M. Kaufman. 1995. Dynamical behaviour of biological regulatory networks—I. biological role of feedback loops and practical use of the concept of the loop-characteristic state. Bulletin of Mathematical Biology, 57(2): 247–276. DOI: 10.1007/BF02460618. 403

J. Thorne. 2000. Models of protein sequence evolution and their applications. Current Opinions in Genetics & Development,, 10(6): 602–605. DOI: 10.1016/S0959-437X(00)00142-8. 370

E. Tillier and T. Lui. 2003. Using multiple interdependency to separate functional from phylogenetic correlations in protein alignments. Bioinformatics, 19(6): 750–755. DOI: 10.1093/bioinformatics/btg072. 371

E. Tillier, L. Biro, G. Li, and D. Tillo. 2006. Codep: maximizing co-evolutionary interdependencies to discover interacting proteins. Proteins, 63(4): 822–831. DOI: 10.1002/prot.20948. 371

I. Tinoco, O. Uhlenbeck, and M. Levine. 1971. Estimation of secondary structure in ribonucleic acids. Nature, 230: 363–367. DOI: 10.1038/230362a0. 388

N. Tran and C. Baral. 2007. Reasoning about non-immediate triggers in biological networks. Annals of Mathematics and Artificial Intelligence, 51(2-4): 267–293. DOI: 10.1007/s10472-008-9091-8. 403

N. Tran and C. Baral. 2009. Hypothesizing about signaling networks. Journal of Applied Logic, 7(3): 253–274. DOI: 10.1016/j.jal.2008.10.001. 403

N. Tran, C. Baral, V. J. Nagaraj, and L. Joshi. 2005. Knowledge-based integrative framework for hypothesis formation in biochemical networks. In B. Ludäscher and L. Raschid, editors, DILS, vol. 3615 of Lecture Notes in Computer Science, pp. 121–136. Springer. DOI: 10.1007/11530084_11. 403

M. Truszczyński. 2007. Logic programming for knowledge representation. In V. Dahl and I. Niemelä, editors, Logic Programming, 23rd International Conference, ICLP 2007, pp. 76–88. DOI: 10.1007/978-3-540-74610-2_6. 368

M. Truszczynski. 2018. An Introduction to the Stable and the Well-Founded Semantics of Logic Programs. In M. Kifer and A. Liu, editors, Declarative Logic Programming: Theory, Systems, and Applications. ACM.

M. Turcotte, S. Muggleton, and M. J. E. Sternberg. 2000. Use of inductive logic programming to learn principles of protein structure. Electronic Transactions of Artificial Intelligence, 4(B): 119–124. 405

M. Turcotte, S. Muggleton, and M. J. E. Sternberg. 2002. Generating protein three-dimensional fold signatures using inductive logic programming. Computers & Chemistry, 26(1): 57–64. DOI: 10.1016/S0097-8485(01)00100-0. 405

P. Veber, M. Le Borgne, A. Siegel, S. Lagarrigue, and O. Radulescu. 2006. Complex qualitative models in biology: A new approach. Complexus, 2(3-4): 140–151. DOI: 10.1159/000093686. 396

L. Wang and Y. Xu. 2003. Haplotype inference by maximum parsimony. Bioinformatics, 19(14): 1773–1780. DOI: 10.1093/bioinformatics/btg239. 384

Web references of ASP solvers, 2018. Clasp: potassco.sourceforge.net; Cmodels: www.cs.utexas.edu/users/tag/cmodels; DLV: www.dbai.tuwien.ac.at/proj/dlv; Smodels: www.tcs.hut.fi/Software/smodels. 368

C. Woese and N. Pace. 1993. Probing RNA Structure, Function, and History by Comparative Analysis. In The RNA World, pp. 91–117. Cold Spring Harbor Laboratory Press. 370

G. Wu, J. You, and G. Lin. 2007. Quartet-based phylogeny reconstruction with answer set programming. IEEE/ACM Transactions on Computational Biology and Bioinformatics,, 4(1): 139–152. DOI: 10.1109/TCBB.2007.1008. 378

X. Xia. 2007. Bioinformatics and the Cell: Modern Computational Approaches in Genomics, Proteomics and Transcriptomics. Springer. 360

Y. Zhao, Y. Xu, Q. Zhang, and G. Chen. 2007. An overview of the haplotype problems and algorithms. Frontiers of Computer Science in China, 1(3): 272–282. DOI: 10.1007/s11704-007-0027-y. 384

M. Zuker and P. Stiegler. 1981. Optimal computer folding of large RNA sequences using thermodynamics and auxiliary information. Nucleic Acid Research, 9(1): 133–148. DOI: 10.1093/nar/9.1.133. 388

1. http://web.ornl.gov/sci/techresources/Human_Genome/

2. Observe that, in the rest of this chapter, we will not make use of this higher expressive power in modeling.

3. A model M of P is supported if for each A ∈ M there is a rule A ← Body in P such that Body is true in M.

4. More general forms of conditional literals are present in literature. This simplified form suffices for our purposes.

5. Recent proposals have also started exploring the use of continuous characters, e.g., [Rossnes et al. 2007].

6. Given a set of n TUs, the number of unrooted trees can be computed by the formula (using the so-called double-factorial) (2n − 5)!! = 1 · 3 · 5 · … · 2n − 5, while the number of rooted trees is (2n − 3)!! = 1 · 3 · 5 · … · 2n − 3. As such, the number of possible phylogenies is exponential in the number of TUs given.

7. In the encoding above and in all encodings in the chapter we modeled the optimization version of the problems. In general, for encoding a decision version, i.e., whether there is a solution of size at least k, one has to replace the last line of the encodings with a line of the form: :– compats(N), N < k. (solutions of size less than k are forbidden), where k can be given as input to the ASP solver (e.g., using the option -c k=2 in a solver like clasp).

8. Figure 7.9 was produced using the Varna Applet http://varna.lri.fr/.

9. With a slight abuse of notation, we assume next to return 1 when it holds and 0 when it does not.

10. Desktop PC Windows 7, i7-2600@3.4GHz, memory 12GB, clingo 4.4.0.

8

State-Space Search with Tabled Logic Programs

C. R. Ramakrishnan

A number of problems involving state space search can be naturally formulated as query evaluation over tabled logic programs. This chapter uses model checking and planning problems to illustrate the effectiveness of logic programming to model and solve complex search problems over large state spaces. Logic programming techniques have been successfully employed to tackle several aspects of the model checking problem, ranging from the construction and abstraction of potentially infinite state spaces, to efficient search over the constructed state space to check a variety of properties, from simple reachability properties using transitive closure, to complex properties requiring computation of nested fixed points. In constrast to model checking, the formulation of planning problems typically involve queries with aggregates (e.g., finding minimum-cost plan instead of plan existence). We show that tabled evaluation with aggregation gives an effective means for computing minimum cost plans.

8.1    Introduction

Logic programming languages have long promised an ability to derive efficient solutions to complex problems starting from high-level declarative specifications. Tabled resolution [Chen and Warren 1996, Tamaki and Sato 1986] addressed the major shortcomings of traditional Prolog-style resolution, namely, weak termination, repeated subcomputations, and weak semantics for negation. Mature Prolog systems such as XSB [Swift et al. 2016] and YAP [Santos Costa et al. 2010] have incorporated efficient implementations of tabling based on a number of fundamental advances in the algorithms and data structures used to support tabled evaluation engines [Chen et al. 1995, Freire et al. 1998, Johnson et al. 1999, Ramakrishnan et al. 1995, Saha and Ramakrishnan 2006, Zhou et al. 2008]. More recent languages and systems such as Picat have been constructed based on tabled evaluation as well [Zhou et al. 2015b]. These systems permit certain predicates in a program to be marked as “tabled” and use tabled resolution when resolving goals involving such predicates. We call the logic programs evaluated by these systems as tabled logic programs.

This chapter reviews a wide variety of problems involving search over complex state spaces that have been successfully solved by posing them as query evaluation over logic programs. Solutions to search problems typically involve choosing an appropriate representation for the state space and choosing an appropriate procedure to control the search through this space of representations. In our approach, solutions to these problems start with high-level encoding of the problem specifications as logic programs. The choices of representation and control are then made by rewriting the program using a combination of one or more of the following steps: (a) using a judiciously chosen set of meaning-preserving optimizations; (b) choosing appropriate data representations to represent the states and state spaces efficiently; and (c) replacing specific portions by more efficient counterparts that take operational aspects into account in order to reduce the needed time or space resources.

We review these problems beginning in Section 8.2 with model checking of temporal properties of finite-state systems. For the problems described in this section, we choose a straightforward state space representation: each state is a ground term with components of the term reflecting the structure of the state space, if any. For instance, a state may be a tuple with one component representing the program counter value and others representing the values of (finite-domain) variables of a system. The benefits of using tabled evaluation become apparent in this setting, even when the state representation is chosen in a simple manner. Much of the complexity of the model checking problem arises not from the choice of a state representation but from search criteria, which are specified as temporal logic formulae. Rather than searching for a single state with a given property, the search problem here is to recognize sequences of states or trees representing alternative computational paths where a temporal property holds. We describe model checkers for non-trivial temporal logics such as the alternation-free modal mu-calculus [Kozen 1983] and with systems specified in process languages such as value-passing CCS [Milner 1989]. Model checkers of temporal logics are derived from the semantics of the logics themselves. Moreover, the semantics of the process languages are directly used to “compile” process specifications into an underlying transition system over which the state-space search is conducted.

In Section 8.3, we consider the model checking problem over different forms of unbounded state spaces. First of all, we consider the problem of model checking temporal properties of timed systems: systems with real-valued clocks. This problem is illustrative of the class of decidable infinite-state model checking problems. We handle the infinite state space of timed systems by representing possibly infinite sets of equivalent states succinctly by a finite set of constraints. The control procedure for model checking is then modified to ensure that the equivalence between states in each set is maintained. We consider model checking of data-independent properties of infinite-state systems as the second problem. This is an example of a model checking problem that is undecidable in general, but for which a constraint-based state representation leads to an algorithm that terminates for an interesting class of properties and systems. Finally, we consider model checking of sequential programs (push-down or recursive systems) by treating program traces as sentences in a context-free grammar (CFG). This third infinite-state model checking problem is solved by casting the problem in terms of constructing and analyzing an abstraction, a finite graph, where a single path through the graph may represent an infinite set of runs in the original system. Note that the abstraction does not use a constraint-based representation, in contrast to the first two examples. For properties that can be expressed as finite automata (i.e., safety or reachability properties), we encode model checking problem as a language intersection problem. We then use the power of tabled evaluation to parse arbitrary CFGs to solve the intersection problem. When the properties are expressed as automata over infinite words (i.e., Büchi automata for liveness properties), the language intersection problem becomes significantly more complex. We describe a method to solve this problem and its encoding as a tabled logic program.

Model checking problems over finite as well as infinite state spaces involve complex search to recognize certain computational structures (runs for linear-time properties; trees for branching-time properties). One common characteristic for the model checking problems is that we are generally interested in the mere existence of a computational structure with a given property. There are other search problems where existence alone is not as interesting; the key problem is to find a structure that optimizes a given cost function. A canonical example of such search problems is the deterministic version of the optimal plan generation problem: given a system with a finite state space where transitions have weights, an initial state, and a goal, find the sequence of transitions with the smallest total weight that reaches a goal state. Optimal plan generation over finite state spaces has been extensively studied before [Russell and Norvig 2010]. Recently, there has been renewed interest in solving this problem using logic programming techniques, including approaches using Answer Set Programming [Lifschitz 2002, Baral and Son 2015] and tabling with extensions [Zhou et al. 2015a]. In Section 8.4, we describe an encoding of the optimal plan generation problem as a tabled logic program with answer subsumption [Swift and Warren 2010]. For this problem, as in the case of finite-state model checking, we focus primarily on encoding the search for an optimal plan. We show that, for several examples which have been previously solved efficiently using the planner module of Picat [Zhou et al. 2015a], a declarative formulation of plan generation is effective as well.

Sections 8.2 and 8.3 review and summarize past work that cast model checking problems over finite and infinite state spaces as logic programs. These works generally start with a high-level formulation (e.g., CTL model checker starting with a high-level encoding of CTL’s semantics). When applicable and necessary, these works employed well-known program transformation techniques, including goal reordering and specialization, as well as lower-level programming constructs (e.g., Prolog’s findall to handle finitary universal quantification) to obtain logic programs that showed competitive performance relative to existing systems. We have not explored alternative formulations of these problems that fundamentally change the way solutions are computed and hence exhibit significantly different performance.

In contrast to these two sections, we formulate the planning problem as one of finding shortest paths in graphs in Section 8.4. While the basis for this formulation is obvious and not novel, there are different ways to pose the shortest path problem as a logic program. The different logic programs show significant differences in performance. Hence, this section focuses on lower-level details, and elaborates on assessing these programs.

Section 8.5 summarizes and places the work in the context of existing literature. The connections and differences between the works in model checking and those in planning are discussed in detail in that section.

8.2    Finite-State Model Checking

We illustrate the construction of model checkers from high-level specifications by first considering the temporal logic Computation Tree Logic (CTL), a simple, yet remarkably expressive temporal logic [Clarke and Emerson 1981]. We then consider a significantly more expressive temporal logic, the modal mu-calculus [Kozen 1983], which is often called the “assembly language” of propositional temporal logics. A model checker for the modal mu-calculus is not presented here (see Ramakrishna et al. [1997]) since much of its construction follows from same ideas used in the model checker for CTL. We only highlight the differences in this section. We assume that the systems being checked are explicitly specified as a graph with edges describing transitions. Transition systems corresponding to specifications in process algebraic languages can be readily generated by encoding the operational semantics of these languages as logic programs as well [Ramakrishnan et al. 2000, Yang et al. 2004]. Starting from such interpreters of process algebraic languages, we can use specialization to generate compilers to translate specifications in these languages into transition system representations [Dong and Ramakrishnan 1999].

In this chapter, we extensively make use of conventional logic programming terminology and notation [Lloyd 1984]. We use symbols starting with uppercase letters to denote variables, and those starting with lowercase letters to denote atomic constants, functions, and predicate symbols. An atomic formula is of the form p(t₁, …, tn) where p is a n-ary predicate symbol, and ti are terms constructed from atomic constants, function symbols, and variables. We use f/n to denote a predicate or function symbol f of arity n. A definite logic program is a set of clauses, where each clause is of the form lhs :- rhs where lhs is an atomic formula, and rhs is a comma-separated sequence of atomic formulae. When rhs is empty, the infix “:-” is omitted. When convenient, we use Prolog conventions and features: for instance, we sometimes use clauses with “;” to denote a disjunction between formulae, “->” to denote “if-then”, and “!” to denote “cut”. When we describe tabled logic programs, we mark predicates that will be evaluated using tabled resolution with directives such as “:-table p/n”.

8.2.1    CTL Model Checking

CTL consists of formulae φ described by the following syntax:

where p belongs to a set of base propositions. In the above, A and E are called path quantifiers (universal and existential, respectively), and X, U, and R are called state quantifiers. In CTL, path and state quantifiers strictly alternate and do not appear alone. Informally, A stands for “in every possible evolution of the system” and E stands for “there is one evolution of the system”; X stands for “in the next step”, U stands for “until”, and R stands for “release.” An “until formula” φ₁Uφ₂ states that φ₁ holds until φ₂ becomes true; and “release formula” φ₁Rφ₂ states that φ₂ must hold as long as φ₁ does not hold. We often use two additional derived state quantifiers, namely, F, which stands for “eventually, in a finite number of steps,” and G, which stands for “globally, at every step.” These derived quantifiers can be defined in terms of U and R as Fφ ≡ tt Uφ and Gφ ≡ ff Rφ, where tt and ff denote propositional constants “true” and “false,” respectively. We often use the term “temporal operators” to denote the pair of path and state quantifiers, such as EF and AU.

Among the temporal operators, the following identities hold:

Models of CTL are defined in terms of Kripke structures, which are automata described by finite directed graphs where

•  vertices, or states, are labeled by a set of propositions which hold in that state, and

•  there is at least one outgoing edge from every vertex.

For a CTL model checker encoded as a logic program, we will use the following term representation for CTL formulae. We use non-numeric constants or atoms to denote propositions, and terms prop(P), where P is a proposition, to denote a base CTL formula. We use function symbols and/2 and or/2 to denote logical connectives “∧” and “∨”, respectively. Finally, we use ex/1, ax/1, eu/2, au/2, er/2, ar/2 to denote the temporal operators EX, AX, EU, AU, ER, and AR, respectively. Thus, every CTL formula is simply a Prolog term. We add an explicit negation operator (represented by neg/1) to introduce negation that will allow us to concisely treat operators that are duals of each other.

We represent a Kripke structure as follows. Prolog facts with schema trans(S, T), where S and T are states in the structure, represent the transitions (edges) in the structure. Prolog facts of the form holds(S, P) denote that proposition P holds at state S.

A model of a CTL formula with respect to a given Kripke structure is a set of states of the structure; we often refer to the model of a formula as a set of states in which the formula holds. This is encoded by the Prolog predicate models/2 shown in Figure 8.1. A query of the form models(S,F), where S is a state in a given Kripke structure and F is a CTL formula, in essence, solves the model checking problem, determining whether (or not) S is in the model of F.

Clauses in lines 3–10 of the figure are direct statements of the semantics of base propositions and the logical connectives in CTL. The clause in lines 11–12 encodes the semantics of the EX operator: state s is in the model of EXφ if some next state t is in the model of φ.

Figure 8.1    Model checker for a CTL subset.

Least Models and Least Fixed Points. The clause in lines 13–14 encodes the semantics of the EU operator: state s is in the model of E φ₁ U φ₂ if there is some finite run of the Kripke structure s₁, s₂, …, sn, sn+1, with s₁ = s, such s₁, s₂, … sn are all in the model of φ₁, and sn+1 is in the model of φ₂. In other words, there is some run in which φ₁ continues to hold until we reach a state where φ₂ holds. This is encoded in the model checker by “unrolling” the EU operator as

Note that the above unrolling is an informal statement of a least fixed point equation since we demand that φ₂ be eventually satisfied at the end of a finite run. The least model semantics of definite logic programs is naturally used to evaluate this least fixed point with no additional programming effort. Note that tabled evaluation is essential for evaluating such formulae.

Programming with Prolog Aggregation. The clause in lines 15–16 encodes the semantics of the AX operator: state s is in the model of AXφ if every next state t is in the model of φ. Note that we could use the fact that ¬AXφ ≡ EX¬φ to encode AX in terms of EX and negation. However, when used in conjunction with recursive formulae (e.g., in the expansion of AU operator), use of the dual causes loops through negation. We avoid this issue altogether by using Prolog’s findall/3 to explicitly iterate through every transition from a state in order to establish an AX property. Note that since we iterate over a set of facts (representing transitions), the use of Prolog’s findall is sufficient. Later, we will see instances where we will need to iterate or aggregate over solutions computed by other tabled predicates, where we will use the relevant tabled aggregates.

In CTL, state s is in the model of A φ₁ U φ₂ if for every run of the Kripke structure s, s₁, s₂, …, sn, … starting from state s, there exists a finite i such that such s₁, s₂, … si−1 are all in the model of φ₁, and si is in the model of φ₂. In other words, φ₁ continues to hold until we reach a state where φ₂ holds on every run. Having encoded AX operator directly, we now use the clause in lines 17–18 to encode the semantics of the AU operator by unrolling it as:

Note that since we still demand φ₂ to hold at the end of a finite run, the above unrolling is an informal statement of a least fixed point equation.

Negation and Dynamically Stratified Programs. The dual of the “until” operators EU and AU are the “release” operators ER and AR, respectively. State s is in the model of E φ₁ R φ₂ if there is some run of the Kripke structure s₁, s₂, …, si, …, with s = s₁, such that s₁, s₂, … si, … are all in the model of φ₂, or there is a finite j such that sj is in the model of φ₁ and s₁, s₂, …, sj are all in the model of φ₂. In other words, φ₂ holds as long as φ₁ does not hold along some run. We can “unroll” the ER operator as

However, this unrolling represents a greatest fixed point: the formula is satisfied in an infinite run where φ₂ holds. Instead of attempting to compute greatest fixed points directly, we use stratified negation to dualize the computation. Predicate negate/2 (not explicitly defined in this chapter) simply finds a negation-normal-form of a formula ¬φ by pushing the negations to the leaves. The operation “tnot” in the program is a built-in in the XSB system that performs negation as failure over a tabled predicate, analogous to Prolog’s “not” over non-tabled ones. Note that this transformation will not create cycles with negation since this pushes negation through the syntax tree but does not unroll formulae.

Clauses in lines 19–24 encode the ER and AR operators in terms of their duals. Note that the program is not statically stratified: in the predicate-level dependency graph, the predicate models depends on itself through negation. However, it is dynamically stratified—i.e., no cycles through negation in the call-level dependency graph—since, e.g., a call to models(S, er(F₁, F₂)) does not depend on itself.

Complexity. Let |S| be the number of states in a given Kripke structure and |φ| be the size of a formula. Model checking the formula using the models/2 of Figure 8.1 will result in at most O(| S | × | φ |) tabled calls. Since neither the state representation nor the formula representation has variables, there is at most one answer to each call. There are two non-trivial join operations in the definition of models/2, namely, for ex and ax. Consider a specific query models(s, ex(φ)): if state s has d outgoing transitions, there are at most d instances of the “EX” clause that can be applied, resulting in d calls to models/2. With tabled resolution, it will take O(|φ|) time to access answers to each of the calls. Thus, if |T| is the size of the Kripke structure (maximum size of transition relation/number of states), evaluation of models query takes O(|T| × |φ|²) time. By suitably representing the syntax tree of a formula (and its dual) by facts, or by automatically hash-consing on demand [Zhou and Have 2012], we can eliminate this extra O(|φ|) needed to access tables, and complete model checking in O(| T | × | φ |) time as well.

Discussion. The first example of CTL model checking already illustrates the power of tabled logic programming. Tabled evaluation is necessary for termination as well as evaluating the program with dynamically stratified negation. Moreover, we introduced an operational aspect via the use of findall to our specification of the semantics of AX operator. This can be viewed as a pragmatic use of a common programming construct, that would have otherwise needed a significantly more complex encoding using (non-stratified) negation.

The example also exhibits an advantage that tabled evaluation brings to this application problem. Note that every call to models/2 is ground. Hence, as soon as one answer is found, we can complete the table early. Consequently, when verifying reachability properties, we can terminate as soon as we encounter a state that satisfies the desired property without exploring any further states. Thus, we have constructed a local model checker that avoids exploring the entire state space.

8.2.2    Model Checking the Modal Mu-Calculus

The modal mu-calculus [Kozen 1983] is an expressive temporal logic whose semantics is usually described over sets of states of labeled transition systems (LTSs). An LTS is a finite directed graph with nodes representing states, and edges representing transitions between states. In addition, the edges are labeled with an action, which is a symbol from a finite alphabet. Transitions in an LTS are denoted as by , where s is the source state of the transition, a is the action label, and s′ is the destination state. The transition relation is encoded in a logic program by a set of facts trans(Src, Act, Dest), where Src, Act, and Dest are the source state, label, and target state, respectively, of each transition.

Formulae in the modal mu-calculus are written using the following syntax:

In the above, Z is drawn from a finite set of formula names and A is a set of actions; tt and ff are propositional constants representing true and false, respectively; ∨ and ∧ are standard logical connectives; and 〈A〉φ (φ holds after some action in A) and [A]φ (φ holds after every action in A) are modal operators. The latter operators 〈A〉 and [A] are called “diamond” and “box” operators, respectively.

The semantics of modal mu-calculus is defined by associating each formula with a set of states of an LTS. Since formulae may contain free occurrences of formula names, a formula’s meaning can be known only when the formula names’ meanings are given. Hence, the semantic function is also equipped with a mapping σ which maps (free) formula names to sets of states of the LTS. Let be the set of states associated with φ in the context σ. This semantic function is defined inductively on the formulae. For instance, . The semantics of formula μZ.φ where Z occurs free is defined in terms of a least fixed point: σ(Z) is the smallest set such that . Consequently, formulae of the form μZ.φ are called least fixed point formulae. Analogously, the semantics of νZ.φ is defined in terms of a greatest fixed point: σ(Z) is the largest set such that . Formulae of the form μZ.φ are called greatest fixed point formulae.

The modal mu-calculus is an expressive logic: properties expressible in a number of other propositional temporal logics such as CTL and LTL can be expressed as modal mu-calculus formulae. For example, a basic property, the absence of deadlock, is expressed in this logic by the following formula with formula name df (denoting “deadlock freedom”):

where “−” stands for set complement (and hence “−{}” stands for the universal set of actions). The formula states that from every reachable state ([−{}]df) a transition is possible (〈−{}〉tt).

Fixed points may be nested. For instance, the property that a “b” action is eventually possible from each state is written as the following formula:

The inner fixed point (involving the formula name eb, denoting “eventually b”) states that a “b” transition is eventually reachable, and the outer fixed point (involving the formula name ib, denoting “infinitely often b”) asserts that the inner formula is true in all states.

In addition to nesting, the inner fixed point may refer to the formula name defined by the outer fixed point. Such formulae are called alternating fixed points. For instance, the property that a “c” action is enabled infinitely often on all infinite paths is written as:

A model checker for the modal mu-calculus can be constructed along the same lines as that for CTL [Ramakrishna et al. 1997]. Formulae are represented by Prolog terms, and the transition system is encoded by a set of facts. We then define a models/2 predicate such that models(S, F) holds if (and only if) state S is in the model of formula F. As in the CTL model checker, we use findall to iterate over all transitions as needed for encoding the “box” operator (analogous to the “A” path quantifier of CTL). Finally, least fixed points are evaluated via the least model computation naturally performed by tabled evaluation.

The only novelty here arises from the use of explicit nesting of fixed points. As in the case of the CTL model checker, we replace greatest fixed points with their duals using the identity:

For formulae with a single fixed point or involving only nested (non-alternating) fixed points, this replacement results in formulae with stratified negation. Again, as in the case of the CTL model checker, the model checker for the modal mucalculus is not statically stratified. However, query evaluation for non-alternating fixed point formulae will be dynamically stratified. Hence, tabled evaluation can be directly used to verify such properties. Moreover, for such properties, we can show that query evaluation for model checking results in O(|S| × |ψ|) table entries, for an LTS with |S| states, and formula of size |ψ|. Again, following the arguments as outlined for CTL model checking, with appropriate formula representations, we can model check alternation-free modal mu-calculus properties in O(|T| × |ψ|) time for an LTS of size |T|.

For formulae with alternating fixed points, replacing greatest fixed points with their duals gives rise to non-stratified formulae. Query evaluation for model checking such formulae is not dynamically stratified. For such properties, we can use the well-founded model computed by tabled evaluation to first reduce the problem, in polynomial time, to a residual non-stratified logic program. This residual program will necessarily have multiple stable models, from which a preferred model is selected; this preference is defined based on the nesting order of the fixed points. This approach was originally proposed in Liu et al. [1998] and the relationship to preferred stable models was established in Kumar et al. [2001]. Thus, when model checking alternating fixed point formulae, we limit the combinatorial search to a subset of the original state space. Finally, it should be noted that the problem of model checking modal mu-calculus formulae is in NP ∩ co − NP [Emerson et al. 1993]. All known model checking algorithms are exponential in the alternation depth, which is the length of the longest cycle of dependencies between least and greatest fixed point formulae. However, whether there is a polynomial-time algorithm remains an open problem [Bradfield and Stirling 2007].

8.2.3    Model Checkers for Linear-Time vs. Branching Time Logics

In contrast to CTL which expresses properties over computation trees, the Linear Temporal Logic (LTL) [Pnueli 1977] expresses properties over runs of a system, where a run is a (possibly infinite) sequence of states. In terms of expressiveness, CTL and LTL are incomparable: there are properties expressible in CTL but not in LTL, and vice versa. On the one hand, even certain simple CTL properties using the E quantifier cannot be expressed in LTL. For example, consider the CTL formula AG EF q, which states that from every state in every computation path (AG) there is a path that eventually reaches a state (EF) where q holds. This branching-time property requires a computation where q eventually holds to be reachable from every state, but does not require q itself to hold on some state in every computation. Such a property has no equivalent formula in LTL. On the other hand, model checking CTL is in PTIME, while LTL model checking is PSPACE-complete [Sistla and Clarke 1985].

For every LTL formula φ, we can construct a Büchi automaton, which is an automaton over infinite words, such that the set of accepting runs of the automaton are exactly those that violate φ. Recall that the condition for acceptance of a finite string by a finite-state automata is given in terms of terminating in a distinguished “final” state when spelling that string. Analogously, the acceptance of an infinite string in a Büchi automaton is determined in terms of whether a state from a distinguished (“accepting”) set is visited infinitely often when spelling that string. Given a system S, we consider the set of runs of the system as its language. To model check an LTL formula of the form Aφ over system S, we first construct a Büchi automaton B¬φ for ¬φ, and then check if the intersection of the languages of B¬φ and S is empty [Vardi and Wolper 1986], via product construction. Whether the language of a Büchi automaton is empty can be decided by checking if there is a strongly connected component containing an accepting state that is also reachable from the start state: a check that can be performed in linear time on the size of the automaton. However, the size of B¬φ may be exponential in the size of ¬φ.

The construction of automaton B¬φ corresponding to ¬φ can be specified at a high level as a tabled logic program. Tabled evaluation is needed to ensure termination of a closure operation that is used in the automaton’s construction. The construction of product automata, as well as the language emptiness check can be encoded as logic programs as well. An LTL model checker implemented along these lines was described in Pokorny and Ramakrishnan [2000].

Discussion. As an alternative to a direct encoding of an LTL model checker, a model checker for the modal mu-calculus can be used for model checking LTL formulae. Specifically, LTL formulae can be translated into modal mu-calculus formulae with alternation depth of 2, with an inner greatest fixed point, representing an accepting cycle and an outer greatest fixed point representing reachability of such a cycle. The size of the mu-calculus formulae, however, may be exponential in the size of the LTL formula [Bhat and Cleaveland 1996].

It appears that model checkers for branching-time logics, such as CTL and the modal mu-calculus, can be more directly encoded as logic programs. In contrast, for the linear time logic, LTL, the model checker involved an explicit construction of a graph that was subsequently analyzed. Although the construction and analysis of this graph can be encoded as a high-level logic program, this approach is decidedly more indirect than the model checkers for branching-time logics. The central difference appears to be that branching time properties where different branches evolve independently are directly represented by independent branching proofs during query evaluation.

A similar treatment of linear-time properties appears to be significantly more difficult. There have been recent attempts to verify LTL properties directly using logic programming with co-induction (Co-LP) [Gupta et al. 2011, Gupta et al. 2007]. The main idea in this encoding can be illustrated by the treatment of the G quantifier. In the CTL model checker given in Section 8.2.1, we turned G quantifiers into F using negation, and solved F formulae using the traditional (inductive) least fixed point computation. In contrast, Gupta et al. [2011] encodes G directly using co-inductive predicates, and solves G formulae with co-inductive greatest fixed point computation. The correctness of this formulation can be argued based on the declarative semantics of Co-LP [Simon et al. 2006]. However, it is significantly harder to establish the completeness of this approach, i.e., that a model checker based on this approach will terminate even for finite state systems [Ancona and Dovier 2015]. In contrast, the model checkers discussed earlier in this section are encoded as logic programs with bounded term depth, which can be readily transformed to Datalog programs; completeness of tabling in such programs immediately yields the desired termination results for these model checkers. A secondary difficulty is in ensuring that the model checkers built using such high-level encodings match the asymptotic complexity of existing model checking algorithms. Establishing the termination and complexity of co-LP-based model checkers remains an important open problem.

8.3    Infinite-State Model Checking

Given that infinite solution sets can be represented compactly using constraints, it is unsurprising that model checking based on query evaluation can be extended to infinite state systems as well, when query evaluation itself is extended with constraint solving. In the following, we begin with a review of the construction of model checkers for real-time systems, based on tabled logic programming with constraints. We then consider property specification logics that go beyond propositional temporal logics by using quantified data variables, and consider model checking systems with unbounded data domains with such expressive property logics. We also consider infinite-state model checking problems that can be reduced to finite-state counterparts without the use of a constraint representation, as exemplified by the model checking of linear-time properties of push-down systems. We begin with a summary of tabled evaluation with constraints that forms the basis for model checking real-time systems (Section 8.3.2) and data independent systems (Section 8.3.3).

8.3.1    Tabled Evaluation with Constraints

Model checking of a number of infinite state systems relies on representing potentially infinite sets of states succinctly, e.g., using constraints. Tabled evaluation with constraints then provides a way to formulate model checking problems over such systems. We describe the interaction between tabled evaluation and constraint processing at a high level via a tabled meta-interpreter shown in Figure 8.2. This interpreter is an extension of the well-known 3-line Prolog meta-interpreter.

The interpreter assumes a language of constraints made up of a set of atomic constraints (e.g., X < 2 is an atomic constraint). A constraint may be an atomic constraint or a conjunction of constraints (perhaps represented as a list of atomic constraints). An empty conjunction of constraints is represented by empty. The meta-interpreter uses the following predicates to process constraints.

•  atomic_constraint(G) that checks whether a given goal is an atomic constraint or not.

•  add_atomic_constraint(C, C1, C2) that adds an atomic constraint AC to a constraint C1, yielding a constraint C2.

•  project(G, C, Cg, Cng) that splits a constraint C into two disjoint parts: Cg that contains all atomic constraints involving variables in goal G; and Cng all atomic constraints in C that are not in Cg.

•  add_constraints(C1, C2, C) that yields C as the conjunction of constraints C1 and C2.

We assume that the constraints in the language have a canonical form such that two equivalent constraints have the same (syntactically identical) representation. Furthermore, we assume that operations add_atomic_constraint, project, and add_constraints yield constraints that are in canonical form, and fail if the resulting constraint is unsatisfiable.

Figure 8.2    A meta-interpreter for tabled evaluation of programs with constraints.

The constraint-processing part of the interpreter relates to the predicate ceval(G, C1, C2), where G is a goal to be evaluated, C1 is the constraint in the context of G’s evaluation (i.e., at the time of a call) and C2 is the constraint upon a successful evaluation of the goal. Note that when a goal is successfully evaluated, the answer substitutions are passed by binding variables in G. The constraint C2 contains the effect of all the constraints in C1 as well as constraints on the variables of the answer.

The first two clauses defining ceval (lines 3–6) process goals true and a conjunction of goals, respectively. Clause 3 (lines 9–11) handles a goal that is an atomic constraint, by simply adding it to the context, and checking the consistency of the resulting constraint. Clause 4 (lines 16–20) handles tabled goals. The interpreter proceeds by first identifying the set of atomic constraints in C1 that are relevant to the goal, i.e., those that share variables with the goal; these atomic constraints are placed in Cg. The goal is evaluated subsequently in the context of Cg. Answers computed in that evaluation will yield constraints Ca. The result of the entire evaluation is then computed as a conjunction of Ca and Cng, the constraints in C1 that were irrelevant to G. This process ensures that tabled evaluation shares goals as widely as possible. Note that two calls to the same predicate with the same constraint on the variables in the calls will be able to share an entry in the table, even if the two calls are placed from two distinct contexts, since the distinction between the contexts is irrelevant to the goal being evaluated. Finally, Clause 5 (lines 23–24) handles nontabled goals via program clause resolution by evaluating the body of a clause whose head unifies with the given goal (lines 34–36).

Tabled evaluation of a goal (predicate teval, lines 29–31) records the goal and context C1 in a table and computes its answers using program clause resolution. The computed answers as well as the associated constraints C2 are stored in the answer table associated with the call. The assumption that the various primitive operations yield constraints in canonical forms means that equivalence between two constraints can be checked by syntactic identity. However, a single goal with context C1 may have two answers with the same answer substitution but two syntactically distinct constraints, say C2 and C2′. If C2′ ⇒ C1, then it is wasteful to keep both answers in the table. We can, in general, maintain tables using answer subsumption [Swift and Warren 2010]: keeping only the more general answers in the table. This will need one more primitive operation over constraints that checks entailment (i.e., C₁ ⇒ C₂). Answer subsumption is a special case of aggregation which is also used for finding optimal plans in Section 8.4.

In addition to maintaining answers according to a subsumption order, it is also often useful or necessary to share the answers for a subsuming (more general) call to supply answers to a subsumed (more specific) call. Tabled evaluation with call subsumption is significantly more complex than the equivalence-based one shown in Figure 8.2. Evaluating a tabled goal under call subsumption will involve using a given subsumption relation to select a subsuming call from other calls for the same predicate already in the table. Let teval(G, Cg ,_) be a given constrained goal, and let be a subsuming call in the table such that G = G′θ and . Let an answer be an answer to the subsuming call; that is there is answer in the table of the form . Then the subsumed call teval(G, Cg, _) should have an answer that applies substitution θ′θ to G, and returns as the binding to the third argument. An implementation of call subsumption needs no additional primitive constraint operations: recall that add_constraints performs conjunction of two constraints, and answer subsumption needs an entailment check. However, an efficient implementation of call subsumption requires data structures to identify subsuming calls, and index into answer tables to select relevant answers. This is a complex problem even in the absence of constraints [Johnson et al. 1999]. Efficient implementation of call subsumption in the presence of constraints is an open problem.

It should be noted that the entries in the call and answer tables contain a projection of the constraint store (on the variables in the calls and answers, respectively). This is a significant but necessary overhead for tabled evaluation. There are few examples which need the combined power of tabled evaluation and constraint processing to justify this overhead; logic programs for model checking over infinite state spaces, described below, are among these few.

8.3.2    Real-Time Systems

We consider models of real-time systems represented as Timed Safety Automata (TSA) [Alur and Dill 1994], which augment finite-state automata with real-valued clocks. More precisely, a TSA consists of a finite set of control locations (analogous to the states of a finite-state automaton); a set of transitions from locations to locations; and a set of real-valued clocks associated with the automaton. Clock values range over non-negative real numbers. Control locations are annotated with a location invariant, which is a constraint on clock valuations. Transitions are labeled with symbols drawn from a finite set, and the labels are used for specifying synchronization across multiple TSAs. In addition, transitions may be marked with (a) guards, which are constraints on clock valuations, and specify when a transition is enabled; and (b) resets, which specify a set of clocks whose values will be reset to zero when the transition is taken. Constraints on clock valuations, including both location invariants and guards, are a conjunction of base constraints of the form x ∼ k or (x − y) ∼ k, where x, y are clocks, comparison operation “∼” is one of {<, ≤, >, ≥}, and k is an integer constant.

A state of a TSA is characterized by a control location as well as the valuation of the TSA’s clocks. A transition is enabled when the clock valuations satisfy the transition’s guard. When an enabled transition is taken, the control location changes, and the valuation of all clocks in the transition’s reset set are initialized to zero; the valuations of all the other clocks are unchanged. Thus, transitions are treated as though they are instantaneous. A transition that is enabled need not be taken, and a TSA may choose to remain at the same location for an arbitrary period of time as long as the location invariant holds. We contrast such moves, calling them as “delay” transitions, distinguishing them from the active ones that changing locations. A delay transition thus represents a TSA remaining in the same location, but with all clock valuations incremented by the same duration of the delay.

A real-time system is modeled as a synchronous parallel composition of TSAs. All clocks in the system progress at the same constant rate. Note that composition of multiple TSAs can itself be represented by a single TSA.

A TSA can be readily represented as a constraint logic program that represents its transition relation and location invariants. For instance, the TSA in Figure 8.3(a) is represented by the program in Figure 8.3(b). The trans relation in the figure makes explicit the state representation: as a pair of location and the value of clock x. For TSAs with more than one clock, the second component of the pair will be a tuple of values of all the clocks. Note that a set of states that share the same location can be represented in the same way: with a conjunction of constraints over the clocks that specify the set of all possible clock valuations. A set of clock valuations that can be represented by a finite conjunction of clock constraints is called a zone. Clock constraints can be represented using standard linear inequalities over reals and entailment can be checked using constraint solvers over reals. However, the special nature of the clock constraints makes it possible to represent zones using difference bound matrices (DBMs) [Dill 1989]: matrices whose rows and columns are indexed by clocks, and whose entries represent the bounds on their differences. Operations over DBMs, including entailment, can be performed in cubic time in the number of clocks. An implementation of a model checker for real-time systems using tabled evaluation and using the DBM representation is described in Pemmasani et al. [2002].

Figure 8.3    Example TSA (left) and its constraint logic program representation (right).

Reachability. We first consider the problem of determining whether a given location in a TSA is reachable. The trans relation already represents the relationship between the source and target zones for each labeled transition. We can explicitly encode a delay transition that models an arbitrary lapse of time at a location by a clause of the form:

When a TSA has multiple clocks, recall that the second component of a state is a tuple of all the clock values, i.e., of the form (X10, X20, …). In such cases, all components of this tuple need to be incremented with the same common delay variable, i.e., X11 = X10+D, X21 = X20+D, …. We can then define a standard reachability predicate over this augmented transition relation in order to determine the reachability of a given location, as shown below:

We define the entailment relation between two sets of clock constraints in order to determine whether or not one set of states subsumes another, and to determine equivalence between sets of states. These definitions of subsumption and equivalence can be then used during tabled evaluation for answering reachability queries. Note that with the left-recursive formulation of reach, when we are interested only in single-source reachability, there will be only one distinct call. Consequently, we will need to implement and/or use only answer subsumption and not call subsumption.

Timed Modal Mu-Calculus. Model checking more complex properties expressed in timed temporal logics can be posed as query evaluation over constraint logic programs, closely following the formulation of model checkers for finite-state systems. The timed modal mu-calculus [Sokolsky and Smolka 1995] adds formulae with realtime modalities, 〈∊〉φ and [∊]φ, to the modal mu-calculus. At a high level, 〈∊〉φ holds at a state s if φ holds at some s′ derivable from s due to delay; and [∊]φ holds at a state s if φ holds after every possible delay, i.e., for every s′ derivable from s due to delay.

For finite-state model checking, the transition system was finitary, and hence we could encode universal modalities using Prolog’s findall. Due to the infinitary nature of the delay transition, we need an alternative technique for model checking the timed modal mu-calculus, as described in Du et al. [2000]. We motivate this by starting with the earlier approach of a binary models relation suitably lifted to sets of states. Consider models(R, F) where R is a location/zone pair, and F is a formula. With constraint-based evaluation as outlined earlier, at the time of a call to models(R, F), the clock variables in R may refer to one zone, represented by a constraint, say C; when this call succeeds, it may indicate that the models relation holds for a subset of these substitutions, yielding a sub-zone represented by another constraint, say C′ such that C′ ⇒ c. There may be many such sub-zones where the relation holds, but each one may be discovered separately (based on transitions out of R). Now consider a query models(R1, 〈∊〉F), with R1’s zone specified by C₁. This can be evaluated by first finding R2 (specified by C₂) such that trans(R1, delay, R2) holds, and then checking if models(R2, F) holds. If the latter holds, we will get another constraint such that , under which the formula F holds in R2. One can view this as a further restriction on constraint C₂ to ensure that models(R2, F) holds. This restriction imposes a corresponding restriction on C₁ as well, say , representing (some of) the conditions under which models(R1, 〈∊〉F) holds. We say that is a ∃-pre-image of , representing the subset of states originally denoted by C₁ that have some delay transition into some state represented in .

For model checking [∊]φ formulae, we need to compute an analogus ∀-pre-image. However, this cannot be done using a single alone, but needs the complete set of all subzones of C₂ where a given formula holds. Hence, we encode the models relation using a ternary predicate models(R, F, RS), which when invoked with R bound to a single location/zone pair, and F to a timed modal mu-calculus formula, returns in RS the set of all subzones of R at which F holds. Note that while the zone in R is convex, RS may be non-convex (since it is a disjunction of zones). The elimination of the universally quantified delay variable is performed by explicitly computing the pre-image of RS due to the delay transition. Hence, in addition to the usual definition of entailment for clock constraints, the model checker for timed modal mu-calculus explicitly handles the computation of ∀-pre-image. As the encodings in Du et al. [2000] and Pemmasani et al. [2002] show, tabled evaluation with constraints enabled us to derive efficient model checkers for such expressive temporal logics from high-level encodings of their semantics.

8.3.3    Data-Independent Systems

Several other infinite-state systems can be encoded in a similar manner to the timed safety automata. An example of such systems are value-passing automata, called extended finite automata (EFA). In an EFA, each (concrete) state is characterized by its control location (cf. program counter) and the valuation of a set of discretevalued (possibly infinite-domain) variables. The values of these variables may be updated when transitions are taken, and the update itself may be performed either based on values of other variables, or input from an external source. Transition labels are annotated with input or output actions. Transitions may be guarded by arbitrary predicates on the valuations.

Model checking such value-passing automata is undecidable when arbitrary updates and transition guards are permitted. It is easy to turn arbitrary number theory problems into model checking problems over unrestricted value-passing automata. For instance, consider an EFA with three control locations s₀, s₁, and s₂, with s₀ as the starting location, and with one variable n. The transition from s₀ to s₁ updates n to 0; a transition from s₁ to itself updates n to n + 1; and a transition from s₁ to s₂ has no update. None of the transitions have a guard. This EFA reaches location s₂ with an arbitrary natural number in n. Now consider extending this EFA with one more location s₃ and three more transitions: a transition from s₂ to itself, with guard even(n) and update n:=n/2; and another from s₂ to itself, with guard n > 1, odd(n) and update n:=3n + 1; and the last, from s₂ to s₃, with guard n = 1. Now, the property “whenever s₂ is reached eventually s₃ is reached” is a statement of the Collatz conjecture.

Nevertheless, a large class of systems behave in a data-independent manner, where the control behavior of the system (e.g., runs considering only the control locations) is independent of the actual values of the data variables. For instance, consider a two-place first-in first-out (FIFO) buffer. The buffer can be modeled as a value-passing system with three control locations denoted by s₀, s₁, and s₂, as shown in Figure 8.4(a). In the figure, output actions are labeled as out!x, denoting value x output on a channel named out; and input actions are labeled as in?x denoting a value read from channel in into variable x. As shown in the figure, the automaton moves on an input transition from control location s₀ to s₁, and from s₁ to s₂; and on an output transition from s₂ to s₁ and s₁ to s₀. The assignments on the transitions assign the data variables in the destination state based on the values of data variables in the source state. An important aspect of the EFA for the FIFO buffer is that the domain of its data variables is left unspecified; in fact, its data variables may range over an infinite domain. Note also that the transitions between control locations are not guarded by constraints on the data variables; hence, the FIFO buffer represents a data-independent system.

Figure 8.4    FIFO buffer represented as an EFA (left) and its constraint logic program representation (right).

Figure 8.5    EFA for the “out of order message delivery” property (left) and its constraint logic program representation (right).

Certain properties of data independent systems can be described in EFA as well. Figure 8.5(a) gives an EFA representing an out-of-order message delivery: values x and y are read in that order, but y is output before x. Traditionally, properties of data independent systems are verified based on considering an equivalent finite-state model checking problem. A property that uses only a finite number of data values is first constructed. Then the data independent system is specialized to a finite-state system that uses only values over this finite domain. Verification of the finite-state system and finite-state property are then used to decide whether or not the original property holds in the data independent system. The construction of a finite domain should be such that the verification result holds for the data independent system if the result holds in the finite-state system. The crucial step of identifying property-preserving finite-state abstractions is performed either with user guidance [Ip and Dill 1996, Lazic 1999, Lin 1996, Wolper 1986] or restricted to control-flow properties that themselves have no data variables [Namjoshi and Kurshan 2000]. However, as described below, using query evaluation over constraint logic programs, we can treat a wider variety of data independent systems automatically, generating an abstraction as needed, without user intervention or annotations.

For simplicity, consider reachability properties, specified as EFA. Note that, given system and property specifications as EFA, we can construct an EFA that is the product of the system and property EFAs, and then check whether an accepting state in the resulting EFA is reachable. When the system and property EFAs are expressed as constraint logic programs, the product EFA can be constructed and represented as a constraint logic program as well. For instance, consider representing states in the product automaton as prod(S,T) where S and T are the states of the component automata. The following clauses define the product automaton:

When the constraints in an EFA are suitably restricted (e.g., to L{=} with equalities “=” and disequalities “≠”), we can check for reachability without considering the concrete data values. We can represent sets of EFA states symbolically by a location/constraint pair. We showed the relationship between symbolic (abstract) and concrete runs in an EFA in Sarna-Starosta and Ramakrishnan [2003], and showed that reachability of any symbolic state in an EFA with constraints in L{=} is decidable. Reachability, either symbolic or concrete, can be readily encoded as a logic program, as the transitive closure of the symbolic or concrete (resp.) transition relations. Thus, reachability problems over EFAs can be cast as query evaluation over constraint logic programs. Moreover, query evaluation over such EFAs terminates, and the results can then be used to determine whether or not a concrete state is reachable.

Verification of a richer class of properties than reachability alone can be done along similar lines. Safety properties can be cast in terms of (the negation of) reachability. Liveness properties can be encoded using EFAs with Büchi acceptance conditions, and the language emptiness problem can be solved by exploring the symbolic state space and identifying reachable connected components containing accepting states. This technique has been used to verify complex data independent systems, including the correctness of cache memory systems [Sarna-Starosta and Ramakrishnan 2003]. It should be noted that such systems were beyond the capability of prior techniques for the verification of data independent systems.

8.3.4    Push-Down Systems

In Section 8.2, we reviewed model checking techniques that are applicable when systems are described as finite state machines. So far, we have presented techniques that are applicable to a generalization of such machines to ones that have a finite number of locations where each location is associated with a set of variables that range over clock values for timed saftey automata, or data values over arbitrary domains for extended finite automata. In the following, we review the logic programming-based model checking techniques that are applicable for systems that permit recursive procedure calls, i.e., the systems are naturally described by push-down automata.

Consider a system described by a program with a set of possibly recursive procedures, where variables in the program take values over small finite domains. An example program is shown in Figure 8.6. Function f in the example takes a single Boolean parameter, has two Boolean local variables, and makes recursive calls to itself. In the program, statement “if (*)” represents a non-deterministic choice: the choice of executing statements in lines 5–6 or skipping over them is nondeterministic. A state of such a system consists of the entire activation stack (with the current procedure on top of the stack), where each activation record represents a valuation of variables in a procedure, and a program counter value where execution will resume when the procedure activations are completed. Since the stack may contain an unbounded number of activation records, such systems have infinitely many states. However, by defining and appropriately encoding relations that represent reachability between states, we can decide several interesting properties of such systems.

We will first consider simple reachability properties, where the properties are specified in terms of program points. A program point is a program counter value within a procedure, and a valuation of variables in that procedure. Clearly, the number of program points is finite when variables range over finite domains. For the program in Figure 8.6, we can represent program points by the pair (l, v), where l is the line number of a statement, and v is a tuple of the values of i, j, k after l is executed. For instance, for call f (1), (6, (1, 0, 1)) is a program point if, after executing the assignment statement at line 6, we have i = 1, j = 0, k = 1.

Figure 8.6    Example recursive program with finite-domain variables.

We can consider the set of all program points as an alphabet, and a run of a program as a sequence of program points during an execution of the program. Thus, each run can be seen as a string over the alphabet of program points. Note that since a program may have infinite runs (e.g., f (1) repeatedly calling itself without returning, in the program in Figure 8.6.), the strings can be infinite. Thus, the language of all runs of a program is, in general, a language over infinite strings.

Now consider a reachability property stated as a regular language over the same alphabet of program points. Note that reachability of a single program point p can be trivially written as “·∗p”, where “·” is a wildcard denoting any program point, and “∗” is the usual Kleene closure. The key aspect of reachability properties is that they specify behaviors over finite runs of the program. Instead of working with the language of all runs of the program, we can focus on the language of finite prefixes of the runs, called its prefix language.

The prefix language for a recursive program will be context free, as illustrated below. From every recursive program P, we can generate a context-free grammar GP such that the language of GP is the prefix language of P’s runs. For every function in P, we derive a set of non-terminal symbols of the form , where c represents a call (function name with actual arguments) and r its return, such that strings generated by are the set of runs when call c eventually terminates with a return value r. For instance, consider the call f (1) terminating with return value 0, in the program in Figure 8.6. Limiting program points to assignment statements and procedure entry and exit only, the terminating runs of f (1) returning 0 are given by strings derivable from non-terminal , defined as follows:

The first production represents paths that result in a call to f (1) at line 5 resulting in 0, and then a subsequent call to f (0) at line 6. The second production represents paths that result in a call to f (1) at line 5 resulting in 1, and then a subsequent call to f (1) at line 6. The third production represents the path that skips the two recursive calls, going from line 2 directly to line 7. Productions defining and , used above, are similarly defined. Using T, and similar to T, we can define non-terminals , where c is a call and p is a program point, to represent finite runs where call c eventually reaches program point p. Note that will be the set of all finite runs of the program that eventually reach p, and forms the start symbol of GP.

To verify if there is any run of the program that satisfies a given regular property φ, we need to simply check if the intersection of the languages of GP and φ is non-empty. For this, we use Prolog’s Definite Clause Grammar (DCG) notation to represent grammars. When GP is represented as a DCG, and φ is represented as the transition relation of a finite-state automaton Aφ, an emptiness check can be done by attempting to “parse” Aφ from its start state to a final state. In this formulation, tabled evaluation is essential for termination since Aφ may contain cycles and GP may have arbitrary recursion. This approach is clarified by the following illustration.

Let A be a finite state automaton over some alphabet Σ, whose transitions are represented by ftrans/3 relation such that ftrans(a, s, s′) stands for a transition labeled a from state s to state s′. Note that order of the arguments is different from our previous encodings of labeled transitions. This change in order lets us simplify the DCG-based formulation. Let start/1 specify a start state of A, and final/1 specify a set of its final states. Let G be a context free grammar over Σ with start symbol S. Without loss of generality, assume that G is in Chomsky Normal Form, that is productions of G are of one of three forms:

1.  X → YZ where X, Y and Z are non-terminal symbols;

2.  X → a where X is some non-terminal symbol and a ∈ Σ is a terminal symbol; or

3.  X → ∊ where X is some non-terminal symbol. This represents an empty production.

The emptiness of the intersection of the languages of G and A can be cast as a logic program by constructing a DCG program as follows.

1.  For each production of the form X → YZ, we derive a DCG clause of the form

n_X --> n_Y, n_Z.

Note that the above DCG clause represents a Prolog clause of the form:

 n_X(A, B) :- n_Y(A, C), n_Z(C, B).

2.  For each production of the form X → a, we derive a DCG clause of the form

n_X --> ftrans(a).

Note that the above DCG clause represents a Prolog clause of the form:

 n_X(A, B) :- f(a, A, B).

3.  For each production of the form X → ϵ, we derive a DCG clause of the form

n_X --> [].

Note that the above DCG clause represents a Prolog clause of the form n_ X(A, A).

Now consider the query:

start(St), n_S(St, Fin), final(Fin).

With tabled evaluation, this query will succeed if, and only if, there is a path in automaton A from the start state to a final state that spells a string accepted by grammar G. The automaton’s description and the DCG (when translated in the standard way to Horn clauses) is a Datalog program. Hence, tabled evaluation forms a complete procedure for checking emptiness of the language intersection problem: the intersection is empty if, and only if, the above query fails. Moreover, note that each translated clause contains no more than three variables that range over the states of A. Following this approach, it is straightforward to see that reachability properties of recursive programs can be verified in O(|GP| × |states(Aφ)|³) time, where states(Aφ) is the set of states in automaton A_varphi.

Verification of liveness properties is more complex. We assume that the liveness property is specified as an LTL formula, where the propositions are defined over program points. Following LTL model checking, given an LTL formula φ, we can construct a Büchi automaton B¬φ such that the automaton accepts runs that violate φ. However, since B¬φ accepts infinite words, we can no longer confine ourselves to runs in GP.

In [Basu et al. 2002], we presented a logic-programming-based formulation for this problem, which is summarized below. We start with a model of recursive programs as a push-down system (PDS), P, with location symbols drawn from set L, and stack symbols drawn from set Γ. A configuration in a PDS is a pair 〈p, w〉, where p ∈ L is a location and w ∈ Γ* is the contents of the stack. Transitions of a PDS are given as transition rules of the form

Without loss of generality, we can restrict transition rules to |w| ≤ 2 (analogous to Chomsky Normal Form for grammars). A run of a PDS is a (possibly infinite) sequence of configurations such that 〈p, γv〉 and 〈p, wv〉 are two consecutive elements of the sequence (for some v ∈ Γ*) only if there is a transition rule 〈p, γ〉 ↪ 〈p′, w〉. From each run of a PDS, we can construct a string by concatenating the topmost stack symbols from each configuration in the run. The set of strings that can be constructed from all possible runs of a PDS is the language of the PDS.

To check liveness properties, we consider a Büchi PDS (BPDS) which is the infinite-word analog of a PDS: it is equipped with a set of accepting states, and a string is in its language only if accepting locations occur infinitely often in the corresponding run. Given a Büchi automaton B¬φ and a PDS P, we can construct a product BPDS PB such that the language of PB is the intersection of the languages of P and B¬φ. This construction is straightforward: locations of PB are pairs (p, q) where p is a location in P and q is a state in B¬φ. There is a transition rule of the form 〈(p, q), γ〉 ↪ 〈(p′, q′), w〉 if and only if 〈p, γ) ↪ 〈p′, w〉 is a transition in P, and is a transition in B¬φ. Thus, given a recursive program and a LTL formula, we can derive, via a logic program, a product BPDS. We have reduced model checking push-down systems to the problem of checking for language emptiness of a BPDS. The logic programming formulation of this problem is explained below.

It turns out that we can check for emptiness in a BPDS by considering only the top-of-stack symbols in a run, thereby making the problem finite. First, we consider a relation Erase ⊆ L × Γ × 0, 1 × L, such that (p₁, γ₁, g, p₂) ∈ Erase iff it is possible to go from a configuration 〈p₁, γv〉 to a configuration 〈p₂, v〉, i.e., erasing γ from the stack. Here, g = 1 if a path from source to target configuration includes an accepting state in B¬φ, and g = 0 otherwise. This relation is defined inductively as a least relation satisfying the following three criteria.

1.  (p, γ, g, p′) ∈ Erase if 〈p, γ〉 ↪ 〈p′, ∈〉. Moreover, g = 1 if p is accepting; g = 0 otherwise. Since the transition rule pops γ from stack, the erasure of γ follows.

2.  (p₁, γ₁, g₁ ∨ g₂, p′) ∈ Erase if ∃p₂, γ₂ such that 〈p₁, γ₁〉 ↪ 〈p₂, γ₂〉, and (p₂, γ₂, g₂, p′) ∈ Erase. Moreover, g₁ = 1 if p is accepting; g₁ = 0 otherwise. In other words, from p₁ we can erase γ₁, if we can first replace it with γ₂, and then erase γ₂.

3.  (p₁, γ₁, g₁ ∨ g₂ ∨ g₃, p′) ∈ Erase if ∃p₂, p₃, γ₂, γ₃ such that 〈p₁, γ₁〉 ↪ 〈p₂, γ₂γ₃〉, (p₂, γ₂, g₂, p₃) ∈ Erase and (p₃, γ₃, g₃, p′) ∈ Erase. Moreover, g₁ = 1 if p is accepting; g₁ = 0 otherwise. In other words, we can erase γ₁ if we can replace it with two symbols γ₂γ₃, and erase each of them one after another.

Once we parse the formal notation in this definition, it is easy to see that the Erase relation can be readily defined as a logic program with three clauses. Note that the resulting program will be in Datalog. Hence, tabled evaluation to enumerate the tuples in the Erase relation will terminate. Given a BPDS with |L| locations, |Γ| stack symbols, and |P| transition rules, the Erase relation is of size O(|L|² |Γ|) and can be computed in time O(|P||L|²) time.

Based on Erase, we define a graph whose vertices are labeled (p, γ), i.e., with location/symbol pairs, and whose edges are labeled 0 or 1. An edge from (p₁, γ₁) to (p₂, γ₂) is in the graph if there is a run from a configuration of the form 〈p₁, γ₁v₁〉 to 〈p₂, γ₂v₂〉 for some v₁, v₂ ∈ Γ*. The edge is labeled with 1 if such a run goes through an accepting state; and 0 otherwise. We call an edge labeled 1 as “1-edge” in the following. By constructing this graph, we have reduced the problem of emptiness checking in a BPDS to one of looking for cycles with a 1-edge in this graph. The language of the BPDS is nonempty if, and only if, there is such a cycle that is reachable from the vertex corresponding to the start state of the BPDS. This graph, as well, can be constructed using a logic program by encoding the following rules defining edges in the graph (denoted by ⇒).

1.   if 〈p₁, γ₁〉 ↪ 〈p₂, γ₂〉. Moreover, g = 1 iff p₁ is accepting.

2.   if ∃γ′ such that 〈p₁, γ₁〉 ↪ 〈p₂, γ₂γ′〉. Moreover, g = 1 iff p₁ is accepting.

3.   if ∃p′, γ′ such that 〈p₁, γ₁) ↪ 〈p′, γ′γ₂), and (p′, γ′, g₂, p₂) ∈ Erase. Moreover, g₁ = 1 iff p₁ is accepting.

It is easy to see how we go from a configuration with γ₁ on top of stack to one with γ₂ on top. The third rule states that we can do this if we get to a configuration with γ′γ₂v as stack (for some v) and then erase γ′. As in the case of Erase, the edge relation of this graph can be readily constructed by a logic program with three clauses, one encoding each of the above rules. Given the Erase relation, the edges in the graph can be computed in O(|P||L|) time, where |P| is the number of transition rules and |L| is the number of locations in the given BPDS. The graph has O(|L||Γ|) vertices and O(|L|²|Γ|²) edges, where |Γ| is the number of stack symbols in the given BPDS.

Finally, detecting reachable cycles with a 1-edge can also be done using a logic program. This can be done declaratively by first defining a reach/3 relation such that reach(v₁, v₂, 1) if there is a path from v₁ to v₂ having a 1-edge; and reach(v₁, v₂, 0) if there is a path from v₁ to v₂ without a 1-edge. Vertices reachable from the start vertex vs, that also lie in cycles with a 1-edge are the results of the query reach(vs, V, _), reach(V, V, 1). This query can be evaluated in time linear in the size of the graph. Putting all this together, emptiness checking in a BPDS can be done in O(|P||L|² + |L|²|Γ|²) time, where |P| is the number of transition rules, |L| is the number of locations, and |Γ| is the number of stack symbols in the givne BPDS.

This example of model checking recursive programs illustrates how a complex search over an infinite state space can be solved by recasting the problem in terms of search over a finite state space, where the transformations needed for the recasting can be expressed as logic programs themselves. It is indeed rewarding to observe that, thanks to tabled logic programming, the heavy lifting is in formulating these transformations; little extra effort was needed to go from the formulation to an implementation.

Discussion. Tabled evaluation has been used for encoding alternative techniques for the verification of infinite-state systems. In Basu et al. [2001], we encoded a checker for bisimilarity among processes in value passing calculi as constraint logic programs. Bisimulation characterizes behavioral equivalence between states of a concurrent system, and is typically defined using greatest fixed points. We encode its complement—a relation that characterizes non-bisimilar states—as the least model a constraint logic program.

In Basu and Ramakrishnan [2006], we tackle a different form of unboundedness by considering the problem of verification of parameterized systems: an infinite family of finite-state systems. The i-th member of the family consists of i identical processes, p. We seek to verify that each member of the family satisfies a given property φ. We cast this problem as one of partial model checking: given a finite-state system S and a property φ, we construct another property φ′ such that for all environments E, the concurrent composition (S|E) models φ if and only if E models φ′. Now, consider the partial model checking of a single instance of p with φ, yielding φ′ = φ₁. We construct a sequence of properties φ₁, φ₂, … such that φi+1 is the result of partial model checking of p with φi. If this sequence converges to, say φk, and the empty process models φk, then we conclude that all members of the infinite family from index k onward model the given property φ. Partial model checkers can be directly encoded as logic programs as well. Convergence of the sequence of properties can also be tested by encoding the entailment relation among properties as a logic program. Moreover, we can encode a widening operator to compute a bound for the limit of the sequence and accelerate convergence. We extended this approach to verify families where each member may itself be an infinite-state system, by considering pi-calculus processes, in Yang et al. [2006].

8.4    Simple Planning via Tabled Search

Plan generation has been an intensely-studied problem in AI. In this section we consider deterministic planning: where each action in a system produces a deterministic (i.e., non-probabilistic) outcome. Several special-purpose algorithms and systems have been developed in this space (e.g., Fikes and Nilsson [1971], Blum and Furst [1997], Russell and Norvig [2010]). More recently, the logic-based multiparadigm language Picat [Zhou et al. 2015b] has been used to implement efficient planners.

Picat-based planners have performed comparably to systems specifically designed for solving planning problems [Barták et al. 2015]. Picat’s planner module implements plan generation via tabled evaluation and uses a number of heuristics to control the search for a valid or optimal plan. More specifically, Picat offers a variety of optimal plan generators including best_plan, which performs resource-bounded tabled search, and best_plan_unbounded, which performs tabled search with no resource bounds. It should be noted that resource-bounded tabled search has a purely operational meaning and has no logical analog. In addition to these, Picat also offers a non-optimal plan generator, plan.

The main aim of this section is to examine how different forms of search implemented using tabled evaluation and with consistent logical semantics contributes to efficient plan generation. Unlike the model checking problems considered in the earlier sections, the formulation of the planning problem as a query over a logic program is neither novel nor interesting in its own right. What makes this problem appealing for a study is that there are different logic programs that encode the planning problem; and although query evaluation over the different programs has similar asymptotic complexity, there are significant differences in performance. We call these distinct high-level logic programs that solve the same problem as different encodings. In this section, we examine how the encoding of the search—in contrast to constraint or Boolean satisfaction, state-space representation, mutable data structures, or other language features—affects the performance of plan generation.

8.4.1    Answer Subsumption and the Shortest-Path Problem

An instance of a deterministic planning problem can be represented by a triple 〈S, ι, G〉, where:

•  S a state space, which is a weighted directed graph (V, E), with vertices in V representing states, and weighted edges in E representing transitions among them.

•  ι ∈ V is a unique initial state.

•  G ⊂ V are goal states.

The state space of an instance is typically specified using “actions” which generate the transition relation E.

Given an instance of a planning problem, optimal plan generation seeks to identify a shortest path in the weighted graph from the initial state to one of the goal states. In the rest of this section, we use the following representation of a planning problem. Let edge(Src, Dest, Act, Cost) be a relation that represents edges in the graph, where Src and Dest are source and destination states, Act is the action label, and Cost is the cost or weight of the edge. Let initial_state(S) be a predicate that defines the initial state, and goal_state(S) be a predicate that defines a set of goal states. Transitive closure alone is sufficient to determine whether or not a goal state is reachable from the initial state. Determining the cost of the shortest path between the initial state and a goal state needs aggregation (minimization). In our formulation, we assume that all weights in the transition relation are non-negative.

Figure 8.7    Predicates to compute shortest path costs.

In the XSB system, aggregation over tabled predicates is implemented using answer subsumption. At a high level, for partial-order-based answer subsumption, the user specifies a partial order. When a new answer is found for a call, it is inserted into the table only if it is extremal, according to that partial order, with respect to existing answers [Swift and Warren 2010]. When an answer is inserted, all existing answers that are subsumed by the inserted answer are removed. For lattice-based answer subsumption, the user defines a join operation over a lattice. When a new answer is found for a call, an existing answer is replaced by the join of the new answer with that existing answer.

Figure 8.7(left) shows a left-recursive encoding of a predicate to compute the cost of a shortest path between two vertices. The first two arguments of scl/3 are states, and the third argument represents the cost of the shortest path between them. The directive “:- table scl(_, _, lattice(ltc/3))” declares scl/3 as a tabled predicate, whose third argument is maintained using answer subsumption specified by a join operation ltc/3. Specifically, if scl(A₁, A₂, A₃) is an answer in the table, scl(B₁, B₂, B₃) is a newly computed answer such that A₁ = B₁ and A₂ = B₂, and ltc(A₃, B₃, C₃), then the original answer will be replaced by scl(A₁, A₂, C₃). Note how aggregation is performed within each group of answers that share the remaining (non-aggregated) arguments. Mode-based tabling directives, such as those used in Picat, in contrast, can specify aggregation only at a call level (i.e., grouped by input arguments). Consequently, the left-recursive encoding of shortest path cannot be written in Picat.

Figure 8.7(right) shows a different encoding of a predicate to compute the shortest path between two vertices, using right recursion instead of left (note the second clause of scr). Consider single-source shortest path queries to the leftrecursive version, of the form scl(v, X, C) where v is a distinguished state and X and C are variables. Tabled evaluation of such queries will record O(1) calls and O(|V|) answers, where |V| is the number of states in the transition system. However, evaluation of query scr(v, X, C) for the right-recursive predicate will result in O(|V|) calls and a total of O(|V|²) answers, essentially computing the cost of shortest path between all pairs of states.

Figure 8.8    Predicates to compute a shortest path.

It should be noted that both scl/3 and scr/3 perform a forward search through the state space. We can view a query of the form scl(s,R,C) as returning in R a frontier of states forward reachable from s, progressively expanding that frontier based on prior answers. On the other hand, a query of the form scr(s,R,C) generates new calls of the form scr(s′,R,C1) where s′ is forward reachable from s.

Figure 8.8(left) shows the encoding of left-recursive spl/2 to not only compute the cost of the shortest path, but a representation of a shortest path itself. Answers to spl/2 are of the form spl(X, (C,A,Y)), where C is the cost of a shortest path from the initial state to state X, Y is the state immediately preceding X in such a shortest path, and A is the action that labels the transition from Y to X. Answers to spl/2 are computed starting with the initial state and expanding outwards. For each visited state, the cost and segment information on its currently known shortest path from the initial state is maintained in spl’s table. We call this encoding of the shortest path predicate as left-recursive shortest path (SPL): shortest paths from the initial state to all reachable vertices are computed, irrespective of when the goal state is reached.

Figure 8.9    Encoding of bounded shortest path.

An encoding of right-recursive shortest path (SPR) is shown in Figure 8.8(right). In contrast to SPL, SPR computes the shortest paths to the goal states for all vertices that are reachable from the initial state. That is, answers to spr/2 are of the form spr(X, (C,A,Y)) where X is a state reachable from the initial state, C is the cost of a shortest path from X to a goal state, Y is immediate successor of X in that shortest path, and A is the action that labels the transition from X to Y.

Figure 8.9 shows a modification to spl of Figure 8.8(left) that restricts the examination of graph vertices to only those that may be relevant to computing shortest path from the initial to a goal state. This formulation maintains and uses a dynamic predicate goal_cost/1 that represents the currently known least cost to reach a goal state from the initial state. Predicate splb/2 returns a state X only if the shortest path from the initial state to X is shorter than the currently known least cost path to a goal state. Let the cost of the currently known shortest path from initial to a goal state be cg. Note that any X whose shortest path from the initial state is longer than cg cannot itself lie on a shortest path from the initial state to a goal state. Hence pruning exploration from X is sound. We call this encoding of the shortest path predicate as “bounded left-recursive shortest path” (SPLB): shortest paths to only a subset of vertices reachable from the initial state are computed, and this subset is determined by placing a bound on the path lengths from the initial state based on the shortest path from the initial state to the goal state. The set of answers to query splb(X,T) has the following properties.

1.  Every answer to splb(X,T) is an answer to spl(X,T) as well.

2.  Let g be the goal state that has a shortest path (among all goal states) from the initial state, and the cost of that path is c. Then splb(X, T) will have an answer binding X to g and T to (c, -, -).

3.  Let g and c be as above, and let s′ be a state whose shortest path from the initial state costs c′ < c. Then query splb(X, T) has an answer of the form X=s′, T=(c′, _, _)).

4.  Let X=s′, T=(c′, _, _)) be an answer. Then there is a goal state g″ with a loop-free path of cost c″ from the initial state, such that c′ ≤ c″.

The first property states that the set of answers to splb is a subset of answers to spl. Properties 2 and 3 express the soundness of this subset: that every candidate short path is an answer to splb. The last property is a characteristic of each answer to splb. Note that there may be many distinct sets of answers that possess the above properties. The set of answers computed depends on the order in which search is performed.

8.4.2    Planning Examples

In the following, we evaluate the shortest path encodings (Section 8.4.1) for plan generation. We begin with a synthetic planning domain to isolate performance characteristics, and then use domains from existing planning benchmarks to evaluate gross performance.

8.4.2.1    Grid

The first example we consider has a state space structured as a two-dimensional grid, with transitions between adjacent points in the grid. Specifically, each state is represented by pair (i, j), where i ∈ [0, m] and j ∈ [0, n]. There are unit-cost transitions (edges) between (i, j) and (i, j ± 1) for all i ∈ [0, m] and j ∈ [1, n − 1]; and between (i, j) and (i ± 1, j) for all i ∈ [1, m − 1] and j ∈ [0, n]. The initial state is (0, 0). Each instance is characterized by the grid size (m, n), and a parameter α that defines a single goal state (⌊αm⌋, ⌊αn⌋). In this example, the parameter α is the ratio of the shortest path to the goal state to the maximal shortest path. Note that small values of α mean that the goal state is close to the initial state. This example is designed so that we can examine the characteristics of the tabled search without regard to other encoding considerations such as indexing and state-space representation.

Table 8.1    Non-optimal plan generation in Grid (time in seconds)

We consider two settings for the plan generation. In the first, we consider the search for a viable plan, with no regard to its optimality. In this setting, we consider two encodings of search.

1.  exists: to determine whether or not a plan exists (i.e., if the goal state is reachable from the initial state), without materializing a plan.

This is encoded as straightforward left-recursive reachability.

2.  first: to determine a viable plan, by materializing the first sequence of actions/edges that establish the reachability of the goal state from the initial state.

This is encoded similar to spl/3 in Figure 8.8, simulating the effect of retaining the first answer by implementing an appropriate lattice join operator.

As a baseline, we encoded this example in Picat. We used Picat’s planner module, specifically the plan predicate to generate a (possibly non-optimal) plan.

Table 8.1 shows the relative performance of Picat’s plan with that of XSB’s evaluation of exists and first, on a 200 × 200 grid, for different values of α. The evaluation was performed using XSB v3.7 and Picat 2.1, on Mac OS 10.10.5 with 2.53 GHz Intel Core 2 Duo and 8GB memory. Observe from the table that Picat’s encoding and its non-optimal plan generator plan are faster, sometimes by orders of magnitude, than XSB’s encodings. Note that the XSB encodings compute the set of all states reachable from the initial state, without regard to goal states. As expected, the performance of XSB encodings are not sensitive to the position of the goal in the state space, while that of Picat’s planner is sensitive to the goal position. It is interesting to observe that Picat finds a plan to reach (200,200) (α = 1.0) much faster than it takes to find a plan to, say, (160,160) (α = 0.8). This is an artifact of Picat’s linear tabling strategy and its interaction with the order in which planner’s actions are specified: “up” actions are tried before “right,” and’ “right” before the others. Thus, a path to (200, 200) is found without backtracking, and early completion terminates the search quickly. Data in the table also shows performance difference of a factor of more than 2 between exists and first. This corresponds to the overhead of materializing a plan by explicitly keeping fragments of paths in the tables.

Table 8.2    Optimal plan generation in Grid (time in seconds)

Table 8.2 shows the performance of the three shortest path encodings, spr (SPR), spl (SPL), and splb (SPLB), for optimal plan generation in the grid example. We compare the performance of XSB-based encoding with those of Picat’s optimal planners: best_plan (bounded) and best_plan_unbounded (unbounded). The platform used to obtain the results in Table 8.2 are the same as those used for Table 8.1. Observe from Tables 8.1 and 8.2 that search for an optimal plan takes significantly longer than search for a non-optimal plan, in both Picat and XSB. In contrast, the exhaustive nature of XSB’s evaluation of first and the left-recursive shortest path (SPL) results in their comparable performance. More interestingly, Table 8.2 shows the effectiveness of the bounded shortest path search (SPLB) encoded in splb of Figure 8.8. When there are many states which are further away from the initial state than the goal (i.e., small α), the performance of SPLB is significantly better than SPL. As α increases, the performance of SPLB approaches that of SPL. For large α, the performance of SPLB is actually worse than that of SPL, indicating that the overhead of maintaining the current estimate of the goal cost exceeds the savings obtained by pruning states using that estimate. Picat’s resource-bounded planner shows a similar performance trend, since the search succeeds in earlier iterations for smaller values of α. XSB’s encoding of SPLB shows the same trend with significantly better raw performance. This difference in performance is not primarily due to SPLB’s use of lower level programming with state-modifying predicates. The high-level encoding of SPL still exhibits better performance on the grid example than Picat’s solvers, thanks in part to its left-recursive encoding.

There are two fundamental reasons for the differences between the performance of Picat’s unbounded planner and the shortest path encodings in XSB. First of all, the SPL and SPLB encodings use the left-recursive encoding of the shortest path, and thereby generate a single call during tabled evaluation. In contrast, Picat’s planner is right-recursive and needs to not only generate O(|V|) calls, but also keep track of the dependencies between these calls for completion. This problem is especially acute for the Grid domain since every state is reachable from every other state. This difference can also be seen from the relatively poor performance of the SPR encoding in XSB, compared to that of SPL and SPLB. Secondly, Picat uses linear tabling in contrast to XSB’s use of SLG resolution, leading to the differences in performance even between the two right-recursive searches for shortest paths. Once again, the surprisingly quick generation of a plan in Picat for α = 1.0 is due to the fact that it finds a good solution (in fact the optimal one) earlier and hence is able to prune subsequent non-promising paths. For other values of α, the first plan found will not be optimal, leading fewer opportunities to prune the search.

The relative difference between the planners becomes less significant when we consider a modified version of the Grid domain where we eliminate two sets of transitions (retaining only “up” and “right” transitions, and removing “down” and “left” transitions), thereby eliminating all cycles. Table 8.3 shows the performance of Picat and XSB-based planners on this modified Unidirectional Grid domain. Observe from the table that Picat’s unbounded planner is generally faster, sometimes by factor of up to 2, compared to XSB’s SPL encoding. Due in part to the simpler dependencies between calls, XSB’s SPR encoding shows comparable performance as well, in contrast to its poor showing relative to SPL for the original Grid.

Table 8.3    Optimal plan generation in unidirectional grid (time in seconds)

8.4.2.2    Other Planning Domains

We evaluated the performance of optimal plan generation based on shortest path computations encoded in XSB, on four other planning domains. Three of these, barman, cavediving, and floortile were planning domains from the 2014 International Planning Competition (IPC14). We obtained Picat programs of the original PDDL encoding of these domains [Bártak et al. 2014]. The domain instances were present as a part of the Picat programs. We then derived the XSB encodings by translating from Picat, keeping the state representation the same whenever possible, and translating the action rules directly into Prolog clauses. Among all the domains from IPC14, for these three domains Picat’s best_plan_unbounded, performed significantly better than the resource-bounded best_plan, sometimes by an order of magnitude. The fourth domain, sokoban, was obtained from Picat’s distribution. We derived the XSB encoding along the same lines used for the other three. The domain instances were the 50 instances used in the 2011 ASP competition [Ianni et al. 2011]. All the four planning problems were posed in terms of generation of optimal plans. The platform used for data collection is the same as the one used for the results in Table 8.1.

Table 8.4 shows the number of instances successfully solved within a given time limit (120 s) by the different planners, namely Picat’s best_plan_unbounded (unbounded); and XSB’s SPL and SPLB. Observe from the table that the different planners terminate within the given time limit for roughly the same number of instances.

Table 8.4    Optimal plan generation: success in 120 s

Table 8.5    Optimal plan generation: mean time (in seconds)

Table 8.5 shows the average time for plan generation, considering only those instances for which all the three planners terminate within the given time limit. Picat’s best_plan_unbounded and XSB’s encoding of SPL and SPLB perform comparably on floortile. On barman, XSB’s encodings are almost twice as fast as Picat’s planner. On the other hand, on sokoban Picat’s planner is almost two times faster than XSB’s encodings. Perhaps more interestingly, on cavediving, Picat’s planner is four times faster than XSB’s encodings. It should be noted that the state space of the cavediving domain is mostly cycle-free, with very few small cycles. This is similar to the unidirectional Grid case, where Picat exhibited better performance as well.

Discussion. We used the optimal plan generation problem to illustrate the computation of reachable states in a weighted graph using answer subsumption. There are two noteworthy points that we have not addressed here. First, we focused only on general methods for casting the search for an optimal plan, and did not consider heuristic approaches. In many planning domains, heuristic-guided planning has been particularly effective (see Bártak et al. [2014]). Specifying heuristics to control search in the context of tabled logic programs, without compromising its declarative semantics, in an important problem that remains to be addressed. Secondly, we have, thus far, avoided any discussion on the state representation and its effect on performance. The focus of this section was on the mechanisms of search itself, and this omission was intentional.

The choice of state representation as well as the encoding of actions in a planning problem can have a significant impact on the performance of plan generation. For instance, consider the sokoban planning domain used earlier in the evaluation of planners. An instance of this domain consists of a two-dimensional grid of locations with obstacles (filled locations), a set of stones initially placed in certain locations to be moved to target locations, and a warehouse worker (Sokoban) who can push the stones vertically or horizontally (except into obstacles). The encoding evaluated in Section 8.4 defined a single action to be the movement of the Sokoban, by one or more steps, in a single direction, either by himself (move) or with a stone (push). There is an alternative formulation that combines a sequence of move actions into a single action, that prepares the Sokoban to push a stone. The shortest sequence of move actions that prepares the Sokoban can itself be computed as a shortest path in a graph (representing locations and their connectivity). This formulation can be seen as a simple instance of hierarchical planning, where optimal plans at a lower level (e.g., individual moves) correspond to actions at a higher level (e.g., preparation to push). Recall, from Table 8.4, that only 33 of the 50 instances terminated with the original formulation in XSB (with both SPL and SPLB) within 120 s. In contrast, with the hierarchical formulation of actions, XSB’s SPL encoding terminates in 44 of 50 instances in the same time; and XSB’s SPLB encoding terminates in 46 of 50 instances. Moreover, recall from Table 8.5, that for the original formulation, the average times to termination for the 33 instances were 8.768 s and 8.275 s, respectively, for SPL and SPLB. For the same 33 instances, under the hierarchical formulation, the average times to termination are 1.67 s and 1.22 s for SPL and SPLB, respectively. Note that the reformulation of the actions in the planning domain results in over five-fold reduction in plan generation time.

8.5    Discussion

We illustrated the utility of tabled logic programming for solving complex search problems, starting from the model checking of complex temporal logics over finite state systems. We showed, using CTL and the modal mu-calculus as examples, how the semantics of branching time logics can be encoded as logic programs. The correctness of these encodings can be shown by establishing the relationship between the semantics of the temporal logics and the declarative semantics of logic programs. Consequently, query evaluation over these programs result in model checking these logics over finite-state systems. We also described the construction of a model checker for the linear time temporal logic LTL, following the automata-theoretic approach [Vardi and Wolper 1986].

We illustrated the construction of model checkers and other verifiers for infinite-state systems with three examples: real-time systems, data-independent systems, and push-down systems. Although the three examples show how different approaches are used to address these problems, they are not representative of the diversity of problems that arise in the model checking of infinite-state systems. Systems specified in the pi-calculus [Milner et al. 1992] and other mobile calculi also result in infinite state spaces. In particular, state spaces constructed for mobile systems may contain an unbounded number of distinct names used as communication channels and values. In Yang et al. [2004], we describe a model checker for the finite-control fragment of the pi-calculus by representing these names as logical variables. That model checker takes advantage of resolution’s handling of variables—renaming and generating new ones as needed—in order to represent generation of new names, their communication, and the subsequent changes of scopes. That work illustrated an approach to construct model checkers over infinite state spaces by relying on the operational aspects of query evaluation. In Singh et al. [2010], we described a model checker for the ω-calculus (which can represent properties of mobile systems with local broadcast communication) that was constructed along the same lines. The proofs of correctness of these model checkers were complex since the correctness was based on the query evaluation mechanism. Nevertheless, the higher level of programming afforded by logic programming enabled the construction of model checkers for these complex temporal logics.

A number of other verification problems have been formulated as query evaluation over extended logic programs. Examples of such problems range from analysis of security policies [Stoller et al. 2007, Stoller et al. 2009, Stoller et al. 2011] to model checking of probabilistic systems [Gorlin et al. 2012, Gorlin and Ramakrishnan 2016]. The formulation of verification problems in terms of logic programs has yielded fresh insights into the model checking of expressive temporal logics. For instance, the result that reachability analysis of push-down systems can be cast in terms of mu-calculus model checking of finite-state systems was first reported in Gorlin et al. [2012]. Subsequently, the ease with which the semantics of branchingtime temporal logics can be encoded as logic programs, has enabled us to identify a decidable fragment of a probabilistic mu-calculus that is expressive enough to treat both internal non-determinism and probabilistic choice [Gorlin and Ramakrishnan 2016]. The advantage of casting model checking and other search problems in terms of query evaluation over logic programs goes beyond ease of implementation alone.

The thrust of the past work, including ours, on casting model checking problems as query evaluation over logic programs has been two fold. The first focus was on developing logic programs that capture the semantics underlying the model checking problem, rather than on implementing an algorithmic solution to the problem. The second focus was on ensuring that the asymptotic complexity as well as the raw performance of the LP-based solutions are comparable to those of any existing implementations. The later years of this line of work shifted the focus to building model checkers for expressive process languages and logics for which there were no other competing implementations, and on developing expressive logics for addressing new applications (e.g., Singh et al. [2010]). There was not much attention paid on whether there were alternative formulations for these problems, and whether the performance of these model checkers can be further improved. The work described in Section 8.4 shows that considerable performance improvements may be possible with alternative formulations.

There have been numerous works on the interconnections between planning and model checking (e.g., see Cimatti et al. [2014]). Most works have explored the use of representations that have proven to be useful in model checking for planning, or use and adapt search strategies developed in the planning community for model checking. In both planning and model checking communities, there is considerable effort in using directed (or guided) search where heuristics are used to prioritize the order in which the state space is search. It is possible to use heuristics to guide the search in Picat’s planner, but its implementation employs global structures that prevents their application to nested planning problems (e.g., for hierarchical planning). Removing such restrictions and applying these techniques to the more general setting of tabled evaluation with answer subsumption is an important open problem. Another focus of these communities has been systems with components that are unknown or unknowable at the time of model checking or plan generation (“open” systems), and/or systems where the results of actions are probabilistic. Our earlier work on model checking probabilistic systems [Gorlin et al. 2012] addresses only a small slice of this problem area.

In addition, as mentioned in the introduction, model checking problems have focused on showing the existence of runs or computation trees that satisfy or serve as counter examples to a given property. One can extend these problems to finding optimal solutions, e.g., finding the shortest counter example or the most likely run that satisfies a property. Formulating and efficiently evaluating such applications as query evaluation over logic programs is an important open problem.

Acknowledgments

This chapter is based on work with a number of collaborators. Foremost, David S. Warren was central to early work on program analysis using tabled evaluation, which eventually led to work on model checking. Scott Smolka was instrumental in identifying the role for logic programming for model checking, and contributed substantially to the subsequent research in this area. Teri Swift guided the development of the first tabled logic program for performing model checking of the modal mu-calculus. I. V. Ramakrishnan led research on subsumptive tabling, and contributed to constraint-based tabled evaluation, which enabled our work on model checking infinite-state systems. Samik Basu, Yifei Dong, Xiaoqun Du, K. Narayan Kumar, Giri Pemmasani, L. Robert Pokorny, Beata Sarna-Starosta, Anu Singh, and Ping Yang developed many of the techniques described in this chapter. I thank the reviewers for their thorough reviews and constructive suggestions for improving the content and presentation of this chapter, and Neng-Fa Zhou for help with understanding the performance issues related to Picat. This work was partially supported by NSF grant IIS-1447549.

References

R. Alur and D. L. Dill. 1994. The theory of timed automata. Theoretical Computer Science, 126(2). DOI: 10.1016/0304-3975(94)90010-8. 444

D. Ancona and A. Dovier. 2015. A theoretical perspective of coinductive logic programming. Fundamenta Informaticae, 140(3-4): 221–246. DOI: 10.3233/FI-2015-1252. 440

C. Baral and T. C. Son. 2015. “Add another blue stack of the same height!”: ASP based planning and plan failure analysis. In Proceedings 13th International Conference Logic Programming and Nonmonotonic Reasoning, pp. 127–133. DOI: 10.1007/978-3-319-23264-5_11. 430

R. Bártak, A. Dovier, and N.-F. Zhou, 2014. Picat solutions for IPC’14 problem domains. http://picat-lang.org/ipc14/. 467, 468

R. Barták, A. Dovier, and N. Zhou. 2015. On modeling planning problems in tabled logic programming. In Proceedings 17th International ACM SIGPLAN Conference on Principles and Practice of Declarative Programming, pp. 31–42. DOI: 10.1145/2790449.2790521.

S. Basu and C. R. Ramakrishnan. 2006. Compositional analysis for verification of parameterized systems. Theoretical Computer Science, 354(2): 211–229. DOI: 10.1016/j.tcs.2005.11.016. 458

S. Basu, M. Mukund, C. R. Ramakrishnan, I. V. Ramakrishnan, and R. Verma. 2001. Local and symbolic bisimulation using tabled constraint logic programming. In Proceedings 17th International Conference Logic Programming, pp. 166–180. DOI: 10.1007/3-540-45635-X_19. 457

S. Basu, K. N. Kumar, L. R. Pokorny, and C. R. Ramakrishnan. 2002. Resource-constrained model checking of recursive programs. In Proceedings 8th International Conference Tools and Algorithms for the Construction and Analysis of Systems, pp. 236–250. DOI: 10.1007/3-540-46002-0_17. 455

G. Bhat and R. Cleaveland. 1996. Efficient model checking via the equational μ-calculus. In Proceedings 11th IEEE Conference on Logic in Computer Science, pp. 304–312. DOI: 10.1109/LICS.1996.561358. 440

A. Blum and M. L. Furst. 1997. Fast planning through planning graph analysis. Artificial Intelligence, 90(1-2): 281–300. DOI: 10.1016/S0004-3702(96)00047-1. 458

J. Bradfield and C. Stirling. 2007. Modal mu-calculi. In J. V. B. Patrick Blackburn and F. Wolter, editors, Handbook of Modal Logic, vol. 3 of Studies in Logic and Practical Reasoning, pp. 721–756. Elsevier. DOI: 10.1016/S1570-2464(07)80015-2. 438

W. Chen and D. S. Warren. Jan. 1996. Tabled evaluation with delaying for general logic programs. Journal of the ACM, 43(1): 20–74. DOI: 10.1145/227595.227597. 427

W. Chen, T. Swift, and D. S. Warren. 1995. Efficient top-down computation of queries under the well-founded semantics. Journal of Logic Programming, pp. 161–199. DOI: 10.1016/0743-1066(94)00028-5. 427

A. Cimatti, S. Edelkamp, M. Fox, D. Magazzeni, and E. Plaku. 2014. Automated planning and model checking (dagstuhl seminar 14482). Dagstuhl Reports, 4(11): 227–245. DOI: 10.4230/DagRep.4.11.227. 471

E. M. Clarke and E. A. Emerson. 1981. Design and synthesis of synchronization skeletons using branching-time temporal logic. In D. Kozen, editor, Proceedings of the Workshop on Logic of Programs, Yorktown Heights, volume 131 of Lecture Notes in Computer Science, pp. 52–71. Springer Verlag. DOI: 10.1007/BFb0025774. 430

D. L. Dill. 1989. Timing assumptions and verification of finite-state concurrent systems. In Proceedings 1st International Conference Computer Aided Verification. DOI: 10.1007/3-540-52148-8_17. 446

Y. Dong and C. R. Ramakrishnan. 1999. An optimizing compiler for efficient model checking. In Formal Description Techniques For Distributed Systems and Communication Protocols & Protocol Specification, Testing, and Verification (FORTE/PSTV’99), pp. 241–256. DOI: 10.1007/978-0-387-35578-8_14. 431

X. Du, C. R. Ramakrishnan, and S. A. Smolka. 2000. Tabled resolution + constraints: A recipe for model checking real-time systems. In IEEE Real-Time Systems Symposium, pp. 175–184. DOI: 10.1109/REAL.2000.896007. 447, 448

E. A. Emerson, C. S. Jutla, and A. P. Sistla. 1993. On model-checking for fragments of μ-calculus. In Proceedings 4th International Conference Computer Aided Verification, pp. 385–396. 438

R. E. Fikes and N. J. Nilsson. 1971. Strips: A new approach to the application of theorem proving to problem solving. Artificial Intelligence, 2(3): 189–208. DOI: 10.1016/0004-3702(71)90010-5. 458

J. Freire, T. Swift, and D. S. Warren. 1998. Beyond depth-first strategies: Improving tabled logic programs through alternative scheduling. Journal of Functional and Logic Programming, 1998(3). DOI: 10.1007/3-540-61756-6_89. 427

A. Gorlin and C. R. Ramakrishnan. 2016. XPL: an extended probabilistic logic for probabilistic transition systems. CoRR, abs/1604.06118. http://arxiv.org/abs/1604.06118. 470

A. Gorlin, C. R. Ramakrishnan, and S. A. Smolka. 2012. Model checking with probabilistic tabled logic programming. Theory and Practice of Logic Programming, 12(4–5): 681–700. DOI: 10.1017/S1471068412000245. 470, 471

G. Gupta, A. Bansal, R. Min, L. Simon, and A. Mallya. 2007. Coinductive logic programming and its applications. In Proceedings 23rd International Conference Logic Programming, pp. 27–44. DOI: 10.1007/978-3-540-74610-2_4. 440

G. Gupta, N. Saeedloei, B. W. DeVries, R. Min, K. Marple, and F. Kluzniak. 2011. Infinite computation, co-induction and computational logic. In Proceedings International Conference Algebra and Coalgebra in Computer Science, pp. 40–54. DOI: 10.1007/978-3-642-22944-2_4. 440

G. Ianni et al., 2011. ASP 2011 Competition, official problem suite. http://www.mat.unical.it/aspcomp2011/OfficialProblemSuite. 467

C. N. Ip and D. L. Dill. 1996. Better verification through symmetry. Formal Methods in System Design, 9(1/2): 41–75. DOI: 10.1007/BF00625968. 450

E. Johnson, C. R. Ramakrishnan, I. V. Ramakrishnan, and P. Rao. 1999. Space efficient engine for subsumption based tabled evaluation of logic programs. In 4th Fuji International Symposium on Functional and Logic Programming, pp. 284–300. DOI: 10.1007/10705424_19. 427, 444

D. Kozen. 1983. Results on the propositional μ-calculus. Theoretical Computer Science, 27: 333–354. DOI: 10.1016/0304-3975(82)90125-6. 428, 430, 436

K. N. Kumar, C. R. Ramakrishnan, and S. A. Smolka. 2001. Alternating fixed points in boolean equation systems as preferred stable models. In Proceedings 17th International Conference Logic Programming, pp. 227–241. DOI: 10.1007/3-540-45635-X_23. 438

R. Lazic. 1999. A Semantic Study of Data Independence with Applications to Model Checking. Ph.D. thesis, Oxford University. 450

V. Lifschitz. 2002. Answer set programming and plan generation. Artificial Intelligence, 138(1): 39 – 54. DOI: 10.1016/S0004-3702(02)00186-8. 430

H. Lin. 1996. Symbolic transition graphs with assignments. In Concurrency Theory (CONCUR), pp. 50–65. DOI: 10.1007/3-540-61604-7_47. 450

X. Liu, C. R. Ramakrishnan, and S. A. Smolka. 1998. Fully local and efficient model checking of alternating fixed points. In Proceedings 4th International Conference Tools and Algorithms for the Construction and Analysis of Systems, pp. 56–70. DOI: 10.1007/BFb0054161. 438

J. W. Lloyd. 1984. Foundations of Logic Programming. Springer. 431

R. Milner. 1989. Communication and Concurrency. International Series in Computer Science. Prentice Hall. 428

R. Milner, J. Parrow, and D. Walker. 1992. A calculus of mobile processes (parts I and II). Information and Computation, 100: 1–77. DOI: 10.1016/0890-5401(92)90008-4 (Part I). and DOI: 10.1016/0890-5401(92)90009-5 (Part II). 469

K. S. Namjoshi and R. P. Kurshan. 2000. Syntactic program transformations for automatic abstraction. In Proceedings 12th International Conference Computer Aided Verification, pp. 435–449. DOI: 10.1007/10722167_33. 450

G. Pemmasani, C. R. Ramakrishnan, and I. V. Ramakrishnan. 2002. Efficient model checking of real time systems using tabled logic programming and constraints. In Proceedings 18th International Conference Logic Programming, pp. 100–114. DOI: 10.1007/3-540-45619-8_8. 446, 448

A. Pnueli. 1977. The temporal logic of programs. In Proceedings IEEE Conference on Foundations of Computer Science, pp. 46–57. DOI: 10.1109/SFCS.1977.32. 438

L. R. Pokorny and C. R. Ramakrishnan. 2000. Model checking linear temporal logic using tabled logic programming. In International Workshop on Tabulation in Parsing and Deduction (TAPD). 439

Y. S. Ramakrishna, C. R. Ramakrishnan, I. V. Ramakrishnan, S. A. Smolka, T. Swift, and D. S. Warren. 1997. Efficient model checking using tabled resolution. In Proceedings 9th International Conference Computer Aided Verification, pp. 143–154. DOI: 10.1007/3-540-63166-6_16. 430, 437

C. R. Ramakrishnan, I. V. Ramakrishnan, S. A. Smolka, Y. Dong, X. Du, A. Roychoudhury, and V. N. Venkatakrishnan. 2000. XMC: A logic-programming-based verification toolset. In Proceedings 12th International Conference Computer Aided Verification, pp. 576–580. DOI: 10.1007/10722167_48. 431

I. V. Ramakrishnan, P. Rao, K. Sagonas, T. Swift, and D. S. Warren. 1995. Efficient tabling mechanisms for logic programs. In Proceedings 12th International Conference Logic Programming, pp. 697–711. 428

S. J. Russell and P. Norvig. 2010. Artificial Intelligence: A Modern Approach. Pearson. 429, 458

D. Saha and C. R. Ramakrishnan. 2006. Incremental evaluation of tabled prolog: Beyond pure logic programs. In International Conference Practical Aspects of Declarative Languages, pp. 215–229. DOI: 10.1007/11603023_15. 428

V. Santos Costa, L. Damas, R. Reis, and R. Azevedo, 2010. Yap v 6.2.0 (user’s manual). http://www.dcc.fc.up.pt/~vsc/Yap/. 427

B. Sarna-Starosta and C. R. Ramakrishnan. 2003. Constraint-based model checking of dataindependent systems. In International Conference Formal Engineering Methods, pp. 579–598. DOI: 10.1007/978-3-540-39893-6_33. 450, 451

L. Simon, A. Mallya, A. Bansal, and G. Gupta. 2006. Coinductive logic programming. In Proceedings 22nd International Conference Logic Programming, pp. 330–345. DOI: 10.1007/11799573_25. 440

A. Singh, C. R. Ramakrishnan, and S. A. Smolka. 2010. A process calculus for mobile ad hoc networks. Science of Computer Programming, 75(6): 440–469. DOI: 10.1016/j.scico.2009.07.008. 470, 471

A. P. Sistla and E. M. Clarke. 1985. The complexity of propositional linear temporal logics. Journal of the ACM, 32(3): 733–749. DOI: 10.1145/3828.3837. 439

O. Sokolsky and S. A. Smolka. 1995. Local model checking for real-time systems. In Proceedings 7th International Conference Computer Aided Verification. DOI: 10.1007/3-540-60045-0_52. 447

S. D. Stoller, P. Yang, C. R. Ramakrishnan, and M. Gofman. 2007. Efficient policy analysis for administrative role based access control. In Proceedings 14th ACM Conference on Computer and Communication Security, pp. 445–455. DOI: 10.1145/1315245.1315300. 470

S. D. Stoller, P. Yang, M. Gofman, and C. R. Ramakrishnan. 2009. Symbolic reachability analysis for parameterized administrative role based access control. In Symposium on Access Control Models and Technologies (SACMAT), pp. 165–174. DOI: 10.1016/j.cose.2010.08.002. 470

S. D. Stoller, P. Yang, M. I. Gofman, and C. R. Ramakrishnan. 2011. Symbolic reachability analysis for parameterized role-based access control. Computers and Security, 30(2–3): 148–164. DOI: 10.1145/1542207.1542233. 470

T. Swift and D. S. Warren. 2010. Tabling with answer subsumption: Implementation, applications and performance. In T. Janhunen and I. Niemelä, editors, Proceedings 12th Euro. Conference Logics in Artificial Intelligence, pp. 300–312. DOI: 10.1007/978-3-642-15675-5_26. 430, 443, 460

T. Swift, D. S. Warren, et al. 2016. The XSB System Version 3.7. Sourceforge.net. http://xsb.sourceforge.net/. 427

H. Tamaki and T. Sato. 1986. OLDT resolution with tabulation. In Proceedings 3rd International Conference Logic Programming, pp. 84–98. DOI: 10.1007/3-540-16492-8_66. 427

M. Vardi and P. Wolper. 1986. An automata-theoretic approach to automatic program verification. In Proceedings 1st IEEE Conference on Logic in Computer Science, pp. 332–344. 439, 469

P. Wolper. 1986. Expressing interesting properties of programs in propositional temporal logic. In Proceedings 13th ACM SIGACT-SIGPLAN Symp. on Principles of Programming Languages, pp. 184–193. DOI: 10.1145/512644.512661. 450

P. Yang, C. R. Ramakrishnan, and S. A. Smolka. 2004. A logical encoding of the pi-calculus: Model checking mobile processes using tabled resolution. International Journal of Software Tools for Technology Transfer (STTT), 6(1): 38–66. DOI: 10.1007/s10009-003-0136-3. 431, 470

P. Yang, S. Basu, and C. R. Ramakrishnan. 2006. Parameterized verification of pi-calculus systems. In Proceedings 12th International Conference Tools and Algorithms for the Construction and Analysis of Systems, pp. 42–57. DOI: 10.1007/11691372_3. 458

N. Zhou and C. T. Have. 2012. Efficient tabling of structured data with enhanced hashconsing. Theory and Practice of Logic Programming, 12(4-5): 547–563. DOI: 10.1017/S1471068412000178. 435

N. Zhou, T. Sato, and Y. Shen. 2008. Linear tabling strategies and optimizations. Theory and Practice of Logic Programming, 8(1): 81–109. DOI: 10.1017/S147106840700316X. 428

N. Zhou, R. Barták, and A. Dovier. 2015a. Planning as tabled logic programming. Theory and Practice of Logic Programming, 15(4-5): 543–558. DOI: 10.1017/S1471068415000216. 430

N. Zhou, H. Kjellerstrand, and J. Fruhman. 2015b. Constraint Solving and Planning with Picat. Briefs in Intelligent Systems. Springer. 428, 458

9

Natural Language Processing with (Tabled and Constraint) Logic Programming

Henning Christiansen, Verónica Dahl

We survey the evolution of natural language processing as it relates to Logic Programming, with particular focus on David Scott Warren’s crucial contributions such as tabling, and the relationship with hypothetical reasoning and constraint based programming. These topics lead naturally to a view of parsing as constraint solving, which extends to grammar inference. Our exposition of the subject is intuitive and example-driven, with references to more formal presentations when needed.

9.1    Introduction

Language is a fascinating domain to play with for researchers. We can make models that we believe capture an essential part of, say, the syntax of a language, and yet we soon find out that the model is incomplete or incorrect. This is the case not only for computational linguistics models of language but also for theoretical linguistics models. None in existence can simultaneously account for all linguistic phenomena in any single human language, including English, which is by far the most studied one.

In that context, logic grammars stand out as a uniquely versatile and efficient tool. They can accommodate a very clear exposition of linguistic phenomena and mechanisms in a directly executable form, and new ideas and hypotheses can easily be tested out.

Language syntax is often described by a combination a compositional, generative system and constraints that delimit the set of allowed forms. A context-free grammar, for example, may tell that if we have a noun phrase (np) and a verb phrase (vp), we may put them together to form a sentence (s).

One thing is missing here, namely the ordering in which the actual phrases are put together. We may fix this by adding variables that stand for physical manifestations of these phrases seen as sequences of symbols; in the following let “·” stand for concatenation.

Now, standard Prolog systems do not like interpreted function symbols such as our concatenation operator, and instead we can use the well-known data structure called a difference list. A sequence, say, [the,lazy,dog] (here written as a Prolog list) is represented by any pair of lists of the form

With this, we can elegantly rewrite the grammar rule above without interpreted function symbols as a Prolog rule, which has good logical and operational interpretations.

The arguments in this rule can be viewed as word accumulators, which act predictably: when a call to predicate s receives an input string S0 to be analyzed, the rule passes it on to np, thus turning it into np’s own input string. If np accepts its first words as corresponding to an actual noun phrase, its remaining words accumulate into S1, which is passed on to vp as its input. Similarly, if vp recognizes the front of S1 as a verb phrase, it leaves the remaining words in S2, which fills the role of output string for s.

Assuming suitable other rules for the predicates np and vp, a successful application of this rule (i.e., with all predicates satisfied) may involve the following values of the variables:

The representation of the sentence approved in this way is the “difference” between the lists S0 and S2, which is [the,lazy,dog,sleeps]. These arguments may also be visualized as pointers to the input string, S0 to where the analysis of the sentence starts, and S2 indicating the point to which the pointer has moved when s(…) has consumed its parts.

If sentences, s, somehow were made constituents of larger constructs, the analysis would continue matching the next constituent starting from the beginning of the remaining sequence [and,a,carrot]. If, on the other hand, sentences were considered the top-level category, i.e., if we were interested in analyzing whole sentences and only those, this remainder would normally be empty; the phrase predicate shown below is a useful top-level predicate that hides this “useless” second argument.

A full grammar may consist of the following Prolog rules:

The difference list technique exemplified above was developed jointly by Alain Colmerauer and Robert Kowalski, first published in Kowalski [1979] and further disseminated in Pereira and Shieber [1987]. Most Prolog systems include Definite Clause Grammars—DCGs for short—which is a syntactically sugared notation for programs such as the above, in which the word accumulators are handled invisibly. DCGs are implemented by a simple translator applied automatically when Prolog reads a source file. The program above can be written as shown in Figure 9.1; there is no need to write the variables as they are anyhow inserted in a strict, systematic manner, invisibly to the user. To perform an analysis of a sentence one may use the built-in predicate phrase as follows:

Figure 9.1    A simple Definite Clause Grammar.

To complete the introduction of the most well-known and used logic grammars,¹ we mention the possibility of adding extra arguments to hold various attributes and the addition of Prolog code (i.e., logical formulas) in curly braces to manipulate and express requirements to these attributes. The following is an example of such a rule and its translation into Prolog:

Definite Clause Grammars are Turing-complete corresponding to Type-0 in the Chomsky hierarchy even when the curly bracket notation is left out. There is a clear similarity and formal correspondence between Definite Clause Grammars and Knuth’s Attribute Grammars [Knuth 1968, Deransart and Maluszynski 1985], with the practical difference that Definite Clause Grammars are born, so to speak, with inherent methods for parsing and attribute evaluation.² These additional attributes are useful from a grammar engineering viewpoint for imposing context-dependent correspondences such as number and case; they are also used for synthesizing different semantic or intermediate representations via term unification [Robinson 1965].

The present chapter is an overview of various logic grammars and systems, emphasizing the influential contributions of David Scott Warren (DSW) to whom this volume is dedicated.

This chapter is structured as follows. We start by giving a summary of DSW’s contributions to logic programming, highlighting those parts that are especially relevant for (natural) language and logic grammars, and here tabling in the XSB [Swift and Warren 2012] Prolog system is central. After that, in Section 9.3, we take a more critical look at the Definite Clause Grammars that we introduced above, recalling known problems of looping and exponential backtracking. It is shown that tabling is an effective medicine to cure these problems.

Next, in Section 9.4, we show how certain aspects of language syntax and semantics can be modelled when adding extra arguments to the predicates of a Definite Clause Grammar. Section 9.5 introduces an extension of Definite Clause Grammars called Assumption Grammars that allows us to model context-dependencies of different kinds, e.g., pronoun references.

While Definite Clause Grammars are essentially tied to top-down linguistic analysis, we also consider in Section 9.6.2 logical Constraint Handling Rules and how they give rise to bottom-up analyses. We demonstrate here CHR Grammars, which is a powerful grammar formalism implemented by a straightforward translation into Constraint Handling Rules, analogous to the way Definite Clause Grammars are made into Prolog rules. In Section 9.7, we show how the combination of Constraint Handling Rules with Prolog (and thus with Definite Clause Grammars) gives rise to a straightforward implementation of abductive reasoning for interpreting language, which also is integrated in the authors’ Hyprolog system. Section 8 briefly discusses probabilistic treatments of language processing, and in Section 9 we present our conclusions. The Appendix shows sample DCG code for parsing a simple subset of English.

9.2    Tabling, LP, and NLP

9.2.1    A Bit of History

In 1975, Alain Colmerauer wrote his pioneering technical report “Les grammaires de Metamorphose” [Colmerauer 1978], introducing the grammar notation described above, that was later popularized under the name of DCGs [Pereira and Warren 1980] and has become an integral part of Prolog. That same year, Verónica Dahl started her graduate studies under Alain’s supervision and developed a computer configuration system in Prolog for which she also adapted an illustrating metamorphosis grammar of French written by Alain into a natural language front end for her system [Dahl and Sambuc 1976]. In her 1977 Ph.D. thesis, she developed a more general database system with a Spanish NL front-end, also entirely written in Prolog [Dahl 1977b, Dahl 1981]. These systems were adapted into English by Fernando Pereira and David H.D. Warren [Warren and Pereira 1982] and formed the basis of many systems that followed. They involved semantic representations inspired by Montague’s fundamental work [Montague 1974], and heuristics described in Colmerauer [1982].

The λ-calculus was used implicitly in Dahl [1981], with reduction rules implemented in an implicit way in logic programming, however this correspondence did not become explicit until it was further studied by DSW [Warren 1983]. See also [Dahl 1994] for a survey of this tradition.

Around 1985, at his invited talk in Halifax, Nova Scotia, David Scott Warren recounted how he’d been agreeably surprised, when reading Dahl [1981], that the scant six pages of its grammar’s code, which appeared in an appendix, actually worked, while covering a similar language subset as the much more voluminous Lunar Science System’s code [Woods et al. 1972]. These results had made him turn his attention from Lisp to Prolog, and helped overcome his initial reluctance to enter a field that already had another “David Warren,” the famous David H.D. Warren.

DSW quickly zoomed in on the main Achilles’ heel of logic programming, namely the risk of infinite loops, as well as the problem of wasteful re-computations, introducing a fresh twist to the existing proposals for solving it. Let us first exemplify the problem: given the following grammar rules, the verb phrase in “Marie Curie discovered polonium in 1898” will lead to trying three alternative analyses, where one is a subset of another (respectively corresponding to “discovered,” “discovered polonium,” and “discovered polonium in 1898”):

Early approaches to avoid re-computations upon backtracking over such rules include chart parsing, which consists of remembering substructures by storing them in a table or chart. For instance in the ingenious Earley parsing scheme [Earley 1970] a chart is maintained which can store unfinished constituents as well as completely parsed ones. Earley parsing achieved impressive efficiency results but only for the (relatively uninteresting) restricted case where grammar symbols can have no arguments, and it did so at the expense of unacceptable overhead in terms of bookkeeping and loop-checking operations.

DSW’s insightful solution was to combine the deductive database and the logic programming paradigms, by extending Prolog’s standard proof procedure to include memoing (i.e., a mechanism to keep a table of answers to certain queries, and resolve repeated subgoals against answer clauses in the table rather than against program clauses). By implementing this idea in terms of an abstract machine (SLG-WAM; Swift and Warren [1994]) he achieved elimination of looping and redundant computations with minimal overhead [Robinson 1965], compared to similar WAM implementations [Warren 1977]. Programs that hopelessly looped before would now yield answers in finite time, and redundant computations were no more; we explain this in more detail in Section 9.3.

In retrospect, we wish SLG resolution had made its way, as DCGs did, into standard versions of Prolog, and not just as a feature of XSB and some other systems. It would have had long-term effects upon the popularity of logic programming as a practical tool. However, SLG resolution is now becoming an accepted feature for several Prolog versions: B-Prolog [Zhou et al. 2001], YAP [da Silva and Costa 2007], and CIAO [Arias et al. 2013] already incorporate it, and Jan Wielemaker is incorporating it also into SWI Prolog [Wielemaker 2014].

9.2.2    The Origins of Tabling

DSW’s Ph.D. thesis from 1979 [Warren 1979] presents a parsing algorithm, called semantic equivalence parsing, for non-context free grammars described in terms of Augmented Transition Networks [Woods 1970]. This algorithm employs semantics for reducing the combinatorial explosion due to syntactic ambiguity in Montague grammar [Montague 1974], using a lambda-calculus representation. The seeds of the idea of memoing were planted in that dissertation, since equivalence parsing is based on a recall table. This became his perhaps most important contribution to language processing due to the impact that tabling had on the execution of DCGs, as highlighted in the previous section.

We will not explain the tabling mechanism of XSB in detail; the interested reader is referred to Swift and Warren [2012], which also provides more background on tabling, tracing it to Tamaki and Sato’s OLDT resolution [Tamaki and Sato 1986].

In the remainder of this section we provide an intuitive presentation that is sufficient to see the consequences for DCGs, which we explain in Section 9.3 below. A tabling logic programming system works as a Prolog engine extended with an additional tabling mechanism, that works roughly as follows.³

•  Whenever a call to a tabled predicate is made, the mechanism checks if one or more solutions have been calculated already, and use this (or these) before trying to resolve the call with program clauses.

•  Whenever a call succeeds, the solution (i.e., variable instantiation) is stored for possible future use, as above.

•  Whenever a call fails, this is recorded as well.

•  In this process, a call is entered into the table even before a solution is found, and if recursion leads to an identical call (up to renaming of variables), this is treated as a failure, and another possible way of producing a solution is sought.

Recent enhancements of ground term storage for tabling have been developed for B-Prolog [Zhou and Have 2012] and XSB [Warren 2013], which basically adapt Lisp’s hash consing technique to tabled Prolog: the analog of Lisp’s hash consing is interned terms: ground terms that are stored in a global store and simply pointed to when needed.

The use of tabling makes life easier for the programmer, reducing the need of using non-logical features of Prolog, such as the cut (“!”), to obtain efficiency and allowing more patterns of recursion without running into loops. The price is the overhead for table maintenance and look-up, which in practice only is measurable in case of large structures as predicate arguments (and XSB has a remedy for that, as explained below).

9.3    Tabled Logic Programming and Definite Clause Grammars

As mentioned earlier, executing DCGs with traditional Prolog technology, i.e., depth-first, left-to-right control with no tabling, has a few annoying consequences. A left-recursive grammar will inevitably run into infinite loops, and backtracking may lead to exponential execution time even when linear time is expected. As a consequence, grammar writers often write grammars in awkward ways with artificial nonterminals to avoid left-recursion and need to design the grammars in a highly procedural way.

We consider here an example of standard grammar for simple arithmetic expressions adapted from the draft of a book [Warren 1999], as shown in Figure 9.2. Notice that it expresses the usual operator associativity and precedence in a correct way. The integer/1 predicate is a Prolog built-in that succeeds if and only if its argument is instantiated to an integer constant. The first rule compiles into the following Prolog rule.

An attempt to parse “2+2” (without tabling!) in terms of the query

Figure 9.2    Left-recursive grammar; correct associativity and precedence.

Figure 9.3    Left-recursive grammar; correct associativity and precedence with alternative rule ordering.

leads to the call

leading in the next step to

and an infinite loop is established.

A reordering of the rules according to the rule of thumb: simplest case first, as shown in Figure 9.3, is not sufficient. The call

leads to

and subsequently to

Figure 9.4    Right-recursive grammar; incorrect associativity.

Figure 9.5    Left-recursive grammar with expression evaluation; correct associativity.

The latter fails, so term([2,+,2],[]) is re-done, meaning that the left-recursive rule is selected and we are stuck in a loop again.⁴

When executing the query in a system with tabling, such as XSB, we get the right answer, “true,” i.e., the list [2,+,2] is accepted as an expr according to the given grammar, independently of the textual order of the rules. It is interesting to compare these grammars with the awkward way this grammar needs to be written in a non-tabling system in order to avoid left-recursion. This is shown in Figure 9.4. In addition to being more difficult read, this formulation gets associativity of the operators wrong, so that, say “3 − 2 + 1” is recognized as an expression with the minus as the top operator and not with the plus as top, as it should be. So if the grammar of Figure 9.4 is to be extended with attributes to evaluate expressions, a bit of creative coding is necessary to get the right result. In contrast, this is trivial for the grammars of Figures 9.2 and 9.3 when tabling is used, as shown in Figure 9.5.

The other problem with DCGs in non-tabling systems is immense backtracking that may occur when, say, the wrong rule is chosen in the beginning of the parsing process, and the mistake is first realized at the end of a string. The interpreter will then try to redo the most recent choice; if the grammar has a high degree of (local or global) ambiguity (as is the case for realistic NL grammars), the same subgoals are executed again and again, leading to exponential execution time. We can illustrate this phenomenon by a minimalist grammar given in Figure 9.6. A sequence of letters “a” is recognized and a number is calculated in a way such that each letter may or may not be counted; the ordering of the rules indicates that the rule for counting a letter is tried before the rule for not counting it. The following query, analyzing a list of 24 letters, takes about 20 s on a fairly new, standard office computer, using a Prolog system without tabling.

Figure 9.6    A grammar whose runtime is reduced from exponential to linear by tabling.

It will first produce an analysis in which each letter counts for one; it fails since 24\=0 and enters the unfortunate pattern of backtracking, trying out the remaining 2²⁴ − 1 analyses before finding the right one that produces the sum 0. Running the query with XSB gives the answer instantly.

However, we are not finished yet with improving the execution speed, as each table look up may take at least linear time in the size of the arguments of the given call. For example, checking, in the previous example, whether the subgoal as(0,[an],[])⁵ is in the table involves comparing the list [an] node by node, with all other lists of “a”-symbols in the table, leading to quadratic execution time.

The way to fix this is to represent the input list differently, as a set of facts, one for each symbol in the list, with integer arguments, representing its position. The list of 24 a’s may be represented by the following facts:

The grammar rules should be translated into Prolog in a slightly different way to work with these indices instead of lists, e.g., as follows:

Thus the counterpart of the subgoal as(0,[an],[]) considered for the previous compilation scheme is as(0,24 − n,24), which can be looked up in a table in constant time. This way, we reach the ideal linear time for this particular grammar and analysis.

It almost goes without saying that XSB has the necessary tools to automatically convert nested lists to such programs of facts and to change the compilation mode for DCGs as explained; see the DCG section of the XSB Manual [Swift et al. 2016].

Thus, the XSB system provides an ideal way to work with DCGs, unleashing their full logical and expressive power and their straightforward intuitive declarative reading. It is really surprising that most adherents of DCGs still stick to depth-first execution without tabling, depriving themselves of the elegance and speed of tabled DCGs.

9.4    Using Extra Arguments for Linguistic Information

9.4.1    Syntactic Features and Agreement

The sample Definite Clause Grammars of Figures 9.1 and 9.2 were both context-free, but extra arguments can be used for specifying syntactic features and agreements. The grammar of Figure 9.7 demonstrates this, imposing that the number of a nominal phrase and the following verb phrase must match. Here, s represents sentences, np nominal phrases, n names (and other simple noun phrases), vp verb phrases, and v verbs.⁶

When these rules are compiled into Prolog, the additional arguments appear side by side with the two arguments representing the string being analyzed. For example, the first rule in the grammar of Figure 9.7 is compiled into the following Prolog rule:

So, for example, [maria, sings, and, dances] is accepted as a sentence by this grammar:

Figure 9.7    Simple NL grammar with number agreement (line numbers not part of the grammar).

•  s([maria,sings,and,dances],[]) holds by rule (1), because

•  np(singular,[maria,sings,and,dances],[sings,and,dances]) holds by rule (4), and

•  vp(singular,[sings,and,dances],[]) holds by rule (8) (with N= singular) and in turn rules (9) and (11).

On the other hand, [the, police, dances] is not a sentence, as [the, police] in this grammar matches np(plural) (by rule (6), and no other rule matches), [dances] matches vp(singular) (by rule (11), and no other rule matches); combining these two by rule (1) fails as plural = singular.

We may additionally include semantic features to ensure that verbs are applied correctly, e.g., to allow [maria, eats, the, apple] and suppress [the, apple, eats, maria], as shown in Figure 9.8. As it appears, such DCGs expose grammatical principles in a clear way, which makes them suited for teaching computational linguistics and for getting language analyzers for different purposes up and running in a short time.

9.4.2    Generating Syntax Trees

The sample Definite Clause Grammars shown above can be used operationally to accept or reject linguistic expressions. We may also use additional arguments to produce more detailed results of a syntactic analysis, e.g., a syntax tree. We demonstrate this by integrating generation of syntax trees into the grammar shown in Figure 9.9.

Figure 9.8    Simple NL grammar with number and semantic agreement.

Figure 9.9    Simple NL grammar that generates syntax trees.

The following example shows a query for parsing a sentence, and its answer that gives the syntax tree:

9.4.3    Building Semantic Structures Compositionally

We can also use arguments to translate sentences into semantic structures. Let us consider a sentence consisting of a noun phrase followed by a verb phrase, in which the noun phrase contains a noun introduced by a determiner. We can first represent the sentence through a three-branched quantification (a la Montague) of the form q(x,f₁,f₂), where q is a quantifier into which the determiner translates, f₁ is the noun phrase’s translation, and f₂ is the verb phrase’s translation. Intuitively, f₁ specifies the domain of quantification, and q states what portion of the domain f₂ holds for. For instance, the sentence “the arms race threatens Gaia” can first be represented, as in Figure 9.10. Quantifier hierarchy must be carefully considered in view of producing meaning representations correctly. For instance, “every conflict has some solution” could either mean that there exists a single, universal solution, which is the same no matter what the conflict is—or, that for each conflict, a different solution exists. This gives rise to the following pair of representations, the second one usually being the intended one:

Figure 9.10  Semantic representation for “The arms race threatens Gaia”.

This might lead us to believe that quantification should proceed from left to right, with a given quantifier coming higher up in the tree than another one appearing in the sentence to its right. However, consider a possible futuristic newspaper headline such as “Canada stops the sales of all arms.” Clearly in this case, the correct representation is:

Quantification hierarchy admits, like conflicts, several possible solutions. The Appendix shows a toy grammar that builds three-branched quantification semantics for a simple subset of English, which accepts proper names, determiners, nouns, and three types of verbs: intransitive, transitive, and bi-transitive. This grammar implements the following (simplistic but useful) quantification ordering conventions: (1) a determiner in a verb’s subject introduces a quantification that dominates all quantifications introduced by the verb’s complement(s); (2) when a noun has a complement, the quantification introduced by the complement’s determiner dominates the one introduced by the noun’s determiner; and (3) when a noun, adjective, or verb has more than one complement, the quantification takes place from right to left [Dahl 1977b].

Sample runs for our grammar are also shown in the Appendix. Notice that some of its output (for yes-no questions) can serve as input to a knowledge base evaluator that can be written very simply, e.g., the representation obtained for “The moon shines” would be the(X,moon(X),shines(X)), which can be fed directly to a knowledge base system where the predicates moon/1 and shines/1 are defined, by adding a definition for the/3.

As noted in Section 9.3, tabling allows us to write grammars in more natural ways, which means that a compositional semantics can be computed on the fly during the syntactic analysis. Grammars for arithmetic expressions are a simplistic demonstration of this: calculating the value of an expression in a compositional way is straightforward in a grammar that reflects correct operator associativity, as shown in the grammar of Figure 9.5, that relies on tabling. Adding the same semantics to the grammar of Figure 9.4, which recognizes the same languages but with incorrect associativity, will be a hard exercise.

In Section 9.5, below, we show a simple grammar extension to deal with wh-questions, which require a value rather than a yes or a no.

9.5    Assumption Grammars: DCGs Plus Global Memory

Assumption Grammars [Dahl et al. 1997] are basically DCGs extended with multiple, global accumulators. Global here means that such accumulators, or assumptions as they are called, need not be explicit in all rules that connect references to the same accumulator, but are mentioned only when used. This way, long-distance dependencies can be incorporated without cluttering up the entire grammar with logical variables to port the content of the accumulators.

An intuitionistic assumption, indicated by */1, adds a clause that can be used an indefinite number of times in subsequent proofs. A linear assumption, indicated by +/1, adds a clause that may be used at most once in subsequent proofs (as in affine linear logic, rather than in Girard’s original framework where linear assumptions should be used exactly once). A built-in predicate -/1 is used for referring to such a clause (and for the linear ones, also removing it).

For instance, *a(13), -a(X), -a(Y) succeeds because intuitionistic assumptions remain available no matter how many times they have been used, whereas +a(13), -a(X), -a(Y) will fail: linear assumptions can be used only once.

For our first natural language processing example, consider the two representations of the meaning of sentences obtained by our parser in the Appendix:

In both examples, the variable queried on (namely, Y) is buried inside the third argument of the/3: as first argument of reflects/2 in the first sentence’s representation, and as second argument in the second sentence’s representation. Accessing it in order to print out an answer after evaluating them with respect to a given knowledge base would require careful programming.

Assumptions allow us an easy way of accessing such variables no matter where they appear, by assuming them in any lexical rule that parses a wh-word, and then consuming them at evaluation time. Let us first restate here the definition of a noun phrase given in the Appendix:

where name/1 contains definitions that simply retrieve a proper name as its representation, e.g.,

plus a rule which represents “who” as a variable:

We merely need to modify the latter rule to one that records the variable obtained into a linear assumption:

The grammar in the Appendix simply prints out the meaning representation obtained for the parsed sentence, which for wh-questions would be an entire the/3 formula, with the actual answer buried inside it. Instead, we need to define an evaluation predicate for the/3 formulas that checks if a wh-question’s variable has been assumed and, if so, prints out its value, for example:

9.5.1    Long-Distance Dependencies through Assumptions

Problems that occupy pure linguists also keep us, computational linguists, on our toes, as soon as the linguistic coverage gets reasonably ambitious. For instance, when, for emphasis, we say “Logic, we love,” rather than the more canonical “We love logic,” a parser needs to somehow attach the dislocated constituent “logic” to the noun phrase that should have come after the verb but is missing. This phenomenon, called the unbounded or long-distance dependency phenomenon, involves constructions such as:

•  interrogative clauses (“Who do you think I saw?”),

•  relative clauses (“the house that Jack built”),

•  anaphora: where the interpretation of an expression depends on another expression in context (e.g. “he” in “Jack and Jill went up the hill, he fell down and he broke his crown”), and

•  topicalization (“Friendships like this, one should cultivate”).

In all these cases, some phrase is missing from its standard position and a corresponding “extra” phrase appears outside of it. The relation of dependency between the “missing” and the “extra” positions is potentially unbounded, i.e., a string of any length can intervene (e.g., consider “Logic, we love,” “Logic, I know we love,” “Logic, I suspected they knew we love,” and so on). Studies of such relations in different languages (e.g., in the Scandinavian languages, where more than one constituent needs to be extracted) suggest that a purely context-free analysis of such relations may not be sufficient. In any case, having more power than context-free greatly facilitates dealing with these constructs. We now show how DCGs augmented with assumptions allow us to solve these kinds of problems in a few lines of grammar code.

9.5.1.1    Pronoun Reference

Consider the following rules shown in the DCG of the Appendix,

where int/0 merely recognizes a question mark if present.

When parsing for instance “the moon shines,” the second np rule percolates the variable X into both the noun phrase’s and the verb phrase’s representation (respectively, NP and VP), yielding the partial representation M = the(X,moon(X),VP). X is introduced directly into NP by n/2, and passed on to VP through s/1. Once the verb phrase rule yields VP = shines(X), M takes its final form M = the(X,moon(X), shines(X)).

We can modify these rules to deal with pronoun reference by globally keeping track of potential specifiers (i.e., parsed names), and when a pronoun appears later, assigning them to the meaning representation of that pronoun. Rather than linear assumptions, which disappear when consumed, we use intuitionistic assumptions to record the potential specifier, so as to cover cases in which the same specifier relates to various pronoun occurrences (as in “he fell down and he broke his crown”):

The first of these rules, upon encountering a proper name, records it as a potential pronoun specifier, through a reusable (i.e., intuitionistic) assumption, pronoun-Specifier/1. Thus, when parsing “Jack” in “Jack went up the hill and he fell down and he broke his crown,” the information that “Jack” is available as the potential meaning of a pronoun is recorded. The third rule consumes this information when a pronoun has been encountered, and unifies the pronoun’s meaning, X, with the name that was recorded as potential antecedent. Should another pronoun come next, the same rule will assign it the same meaning by reconsulting the intuitionistic assumption.

Obviously, more extensions are needed to appropriately decide between competing potential specifiers for a given pronoun. For instance, for “Jack and John went up the hill, he fell down and he broke his crown,” we could postulate that “he” should refer to the closest pronoun, or take any other empirical strategy, whereas for “Jack and Jill went down the hill, he fell down and he broke his crown,” we can use gender agreement for deciding which the antecedent is. This difficult linguistic problem admits many possible strategies that have been covered in extensive literature, with no one strategy having been proved to be the best. But at least through introducing assumptions at appropriate points in our grammar code, different strategies can be implemented in modular and concise manner, e.g., we could easily add gender and number information to enable more precise correspondences between pronouns and their antecedents.

9.5.1.2    Timeless Assumptions: Backward Anaphora

Besides linear and intuitionistic assumptions, which derive, as we said, from Girard’s work, Assumption Grammars include an original type of assumption—timeless assumptions—which Dahl introduced into Assumption Grammars [Dahl et al. 1997] motivated by the need to deal with linguistic phenomena, such as special cases of anaphora.

Timeless assumptions can be consumed either before or after being assumed. They are introduced with the predicate =+/1 if we want them to be consumed at most once, or with the predicate =*/1 if we want them to be available for consumption an indefinite number of times. Their consumption is done via the predicate =-/1, regardless of whether they are intuitionistically or linearly timeless. As shown in Dahl et al. [1997], timeless assumptions can be implemented in just four clauses in terms of linear assumptions. Basically, the mechanism consists of storing a timeless expectation, say –=(X), that has no matching timeless assumption yet, as another assumption +wait_for(X). When a matching timeless assumption +=(a) gets called, it is treated as an expectation -wait_for(a).

Backward anaphora (also called cataphora) occurs when a pronoun’s specifier appears after it rather than before (as in: “Beside her, Alice saw a Bread-and-Butterfly”).

Armed with our new type of assumptions, all we have to do in order to admit backward as well as forward anaphora is to rewrite the intuitionistic assumption and consumption in our np/3 rules of the previous section via timelessly intuitionistic calls, so that now a pronoun can either appear before or after its specifier:

Note that since we added the timeless quality while keeping the intuitionistic quality as well, we can still use the same specifier for many occurrences of a pronoun.

Linear, intuitionistic, and timeless assumptions have become a standard feature of many Prolog versions, such as BinProlog⁷ [Tarau 2012] and can be made available to SICStus⁸ [Swedish Institute of Computer Science 2016] or SWI Prolog⁹ [Wielemaker et al. 2012] through CHRGs introduced in Section 9.6. They also form part of another variant of DCGs used in Hyprolog, which we describe in Section 9.7.

9.5.1.3    Relative Clauses

Using assumptions, we can also easily extend the above grammar fragment to deal with relative clauses by modifying the second rule and adding a fourth rule, plus two rules that deal specifically with relative clauses:

The rules for rel/2 analyse a sentence with meaning representation R that the relative pronoun “that” announces as being a relative clause, i.e., as containing a non-overt noun phrase.

For instance, for the noun phrase “the building that fell,” the second np/3 rule analyzes “the building” as the “core” of the subject noun phrase, yielding the noun phrase’s meaning NP as the conjunction of NPCore = building(X) with the yet to be instantiated representation Rel of “that fell”. The call to rel(X,Rel) instantiates Rel, by a recording through a linear assumption missing_np/1 that there is a missing noun phrase with antecedent X in the sentence that follows the pronoun “that,” and then calling the analysis of that sentence. During this analysis, the fourth rule for np/3 will apply when the rule for s/1 looks for the embedded sentence’s subject, given that neither a name, nor a quantified phrase, nor a pronoun appear after “that”. This fourth rule for np/3 will consume the antecedent that has been recorded, namely the variable X that represents both “the building” and the entity that fell, so that the fully instantiated representation becomes NP = and(house(X),fell(X)).

Should there be no relative clause, the second rule for rel/2 recovers “true” as the meaning of the empty relative clause. This is spurious but harmless, and can of course be cleaned up if desired.

A relative clause’s missing noun phrase can be implicit at any position: we can relativize on the subject (“the building that fell”), the object (“the book that Henning read”), the indirect object (“the friend that Veronica lent a book to”), and so on. The rules above shown will apply to any of these cases without further ado.

9.6    Constraint Handling Rules and Their Application to Language Processing

The links between logic programming and constraint solving were first established by Gérard Huet [Huet 1972], and materialized in programming languages such as Colmerauer’s Prolog II [Colmerauer 1986] and Prolog III [Colmerauer 1990], and the family of CLP(–) languages introduced by Jaffar and Lassez [1987]. The strong links between constraint based logic programming and language (analysis) have been studied in various settings, including the CSLP series of workshop and associated publications. We refer to the recent collection [Blache et al. 2014] for an overview of different directions.

Here we concentrate on the work related to Constraint Handling Rules (or CHR) [Frühwirth 1998, Frühwirth 2009], which is an extension to Prolog with forward chaining rules developed as a language for writing constraint solvers in a declarative fashion. CHR was introduced in the early 1990s and is now included in several major versions of Prolog, including SWI¹⁰ [Wielemaker et al. 2012] and XSB. CHR was recognized very soon as a powerful language for different sorts of logical reasoning, also in combination with Prolog, see, e.g., Frühwirth [2009], Christiansen [2009], and Sneyers et al. [2010]. This also covers applications to language processing, which have been investigated mainly by the present authors and their collaborators. As it turned out, CHR is a very powerful and robust logic programming tool for language processing due to its natural bottom-up evaluation strategy. CHR makes use of a global constraint store, which can be used with the same effect as tabling (avoiding backtracking and loops), but the rules of CHR access this store in an explicit way, allowing one to access and transform previously computed results from anywhere in a linguistic analysis, including from separate stages such as syntactic, semantic, pragmatic.

We give a quick introduction to CHR and present the analogue of DCGs, called CHR Grammars, defined by a grammar notation on top of CHR. Finally, we show two other constraint-based, logic grammar systems based on CHR Grammars, namely Property Grammars and Womb Grammars. In Section 9.7, we describe the Hyprolog system, which is basically Prolog extended with facilites for abductive reasoning and assumptions that are easily implemented in CHR.

9.6.1    An introduction to CHR

A CHR program consists of declarations of constraint predicates and rewriting rules over constraint stores. A simplified explanation of CHR’s procedural semantics is that whenever a new constraint gets called, it is included in the constraint store and the rules of the current program apply as long as possible. CHR has three sorts of rules:

The hs are head constraints, bs body constraints, and Guard is a guard condition (typically testing values of variables found in the head using built-in or user defined Prolog predicates). A rule can be applied when its head constraints are matched simultaneously by constraints in the store and the guard is satisfied. For a simplification rule, the matched constraints are removed and the suitably instantiated versions of the body constraints are added. The other rules execute in a similar way, except that, for propagation, the head constraints stay in the store, and for simpagation, only the constraints following the backslash are removed. Prolog calls inside the body are executed in the usual way.

CHR has a logical semantics based on reading a simplification as a bi-implication, a propagation as an implication, and finally considering a simpagation H₁ \ H₂<=>G | B as equivalent with the simplification H₁, H₂<=>G | H₁, B (although it is executed in a different way); see Frühwirth [1998] or Frühwirth [2009] for the precise details.

Propagation and simpagation rules provide an analogy with tabling: constraints once computed are maintained in the store and potentially re-used by many rule applications (through matching in their head). This allows to produce, say, the set of all alternative analyses of an observed phenomenon (presented as the input constraints), in a bottom-up fashion without any form of backtracking or recomputation.

9.6.2    CHR Grammars

CHR Grammars, or CHRGs for short, are based on Constraint Handling Rules and were introduced in Christiansen [2005] as a bottom-up counterpart to DCGs. They are defined on top of CHR in exactly the same way as DCGs are implemented by a direct translation into Prolog.¹¹ CHRGs are executed as CHR programs that provide robust parsing with an inherent treatment of ambiguity.

CHRGs use an encoding of input strings with integer indices showing the position of each symbols, exactly as shown above in Section 9.3 as optionally available for DCGs in XSB. The only difference is that here it is given as a set of initial constraints instead of a set of Prolog facts. So, for example, the input string Peter likes Mary is given by the constraints {token(0,1,peter), token(1,2,likes), token(2,3,mary).} Parsing can be done in CHR with rules that look for recurrence of position indices, and—exactly as in a DCG—the arguments referring to these indices are added automatically by a compiler. Here is an example of a simple CHRG and its compiled version in CHR.

Executing the encoded version of the input string Peter likes Mary with this program yields the result, sentence(0,3), which means that the input string has been accepted as an np. The strict use of propagation rules in this grammar means that the resulting constraint store also keeps the input token/3 constraints and the intermediate np/2 and vp/2 constraints. Left-recursion is not a problem as computation is bottom-up, so only circularity may cause loops, e.g., adding the rule np::>np.¹²

CHRG rules also allow parsing to depend on the context to the left and right of the symbols being reduced. The following rule demonstrates the use of a left context for pronoun resolution; the symbol “-\” separates the core of the head from the left context, and “…” is an operator that allows an arbitrary gap. We show also the translation of the CHRG rule into CHR.

Notice that the gap operator is compiled into an inequality in the guard. Thus, if name(monalisa,female) has been recognized already, and pronoun(female) is encountered further down the input sequence, this rule will produce an np(monalisa) in the same position as the pronoun. Christiansen et al. [2007b], Christiansen et al. [2007a] show a realistic example of a CHR-based grammar, which reads use case text and produces UML class diagrams; they further extend the principle of pronoun resolution shown above by heuristics that select the most recent referent that fits in number and/or gender.

CHRGs have a rich collection of grammatical constructs and facilities for semantic analysis, designed according to the rule that everything compilable into CHR in a reasonable way should be allowed. This includes also assumptions, as introduced in Section 9.5 above, and facilities for abductive reasoning, implemented as in the Hyprolog system described below.

CHRGs and DCGs share the properties of being based on logic and being directly executable through existing logic programming technology via shallow compilation. CHRGs can also work with additional, non-grammatical constraints, both to be matched in the head (thus being a pre-condition for applying a rule) or produced in the body. The last part is useful for, among other things, producing knowledge bases from text.

9.6.3    Grammar Induction as Constraint Solving

So far we have used CHRG for a direct implementation of logic grammars, where the paradigm of parsing-as-constraint-solving directly translates—invisibly to the user—grammar symbols into CHR constraints, without departing from the traditional view of grammars as rewriting rules that implicitly describe a hierarchical structure as a side effect of parsing.

9.6.3.1    From Rule Rewriting to Constraints

The constraint-based approaches we discuss in this section represent a grammar by a set of constraints (instead of the more classic tree-based representation), also called properties. They thus accommodate more flexible language descriptions. For instance, if we were to work with tree-oriented rules such as:

their adaptation into a language where nouns must precede adjectives would require changing every rule where these two constituents are involved.

In contrast, if instead of using rewriting rules we used the Immediate Dominance/Linear Precedence formalism, known as IDLP [Gazdar et al. 1985], the same information would be conveyed in terms of two separate properties or constraints: linearity, stating that det must precede adj and that adj must precede n; and immediate dominance, stating that det, adj, and n are all under the dominance of np. In consequence, we would only need to change the precedence constraint concerning adjectives and nouns into stating that n must precede adj, and the modification carries over to the entire grammar without further ado.

IDLP was the first linguistic formalism proposed to represent through separate properties the information that can be conveyed in a rewrite rule. Further constraints were later added to turn this first proposal into more complete linguistic description theory, e.g., Property Grammar [Blache and Balfourier 2001] defines phrase acceptability in terms of the properties or constraints that must be satisfied by pairs of categories. For instance, English noun phrases can be described through a few constraints such as precedence (a determiner must precede a noun, an adjective must precede a noun), uniqueness (there must be at most one determiner), exclusion (an adjective phrase must not coexist with a superlative), obligation (a noun phrase must contain the head noun), and so on.

Incorrect sentences can be “accepted” through declaring some constraints as relaxable. For instance, while from the context-free grammar rules shown we wouldn’t be able to parse “the the book” (a common mistake from cutting and pasting in word processors), in the constraint-based formulation we can, if we relax the uniqueness of determiner constraint. Therefore, rather than resulting in either a parse tree or a failure, such frameworks characterize a sentence through the list of constraints a phrase satisfies and the list of constraints it violates, so that even incorrect or incomplete phrases will be parsed.

Most implementations of this approach construct as the output of a parse a list of satisfied properties and a list of those that failed, e.g., the CHRG implementation presented in Dahl and Blache [2004].

A very efficient way of implementing parsing as constraint solving paradigm, introduced in Dahl and Miralles [2012], is possible for cases in which the failed properties are the exact complement of the successful ones: in this case we only need to check constraints for failure, and should we ever want to list the successful properties as well, all we’d have to do is calculate the complement of the failed constraints. These can be easily expressed via directly executable CHRG.

For instance, violations of uniqueness constraints can be checked by a CHRG rule that finds two adjacent words of the same category C within the bounds of a phrase of category Cat being parsed, where C has been constrained to appear only once within that phrase. Should such adjacent words be found, the constraint’s violation is recorded as a fact represented as a CHR constraint. If the category is repeated through the same word (as in “the the book”), we can correct the violation by deleting one of the word’s two occurrences. If the category is repeated through two different words (as in “the a book”), they are left to coexist, so that further analysis can be made before choosing one over the other.

This implementation approach—the failure-driven approach—has recently been explored for parsing as such [Dahl et al. 2017], but was, in fact, developed with an eye on grammar inference. We next describe our failure driven approach in the context of grammatical inference.

9.6.3.2    The Womb Grammar Model

The Womb Grammar model of grammatical inference [Dahl and Miralles 2012], also based on the kinds of properties described above, was developed to infer the grammar of an unknown language based on the grammar of a known language and the lexicon and a set of legal sentences of the unknown language. The main idea is to use the set of failed constraints that will necessarily result from attempting to parse the sentences of the unknown language under the grammar of the known language, to drive a model of transformation from the known grammar to the grammar of the unknown language, producing a new grammar that fits the unknown language.

Let LS be a source human language that has been studied by linguists and for which we have a reliable parser that accepts correct sentences while pointing out, in the case of incorrect ones, what grammatical constraints are being violated. Its syntactic component will be noted , and its lexical component, .

Now imagine we come across a dialect or language called the target language, or LT, which is close to LS but has not yet been studied, so that we can only have access to its lexicon but we know its syntactic constraints overlap significantly with those of LS—perhaps being a dialect of it or a close “cousin”. If we can get hold of a sufficiently representative corpus of sentences in LT that are known to be correct, we can feed these to a hybrid parser consisting of and . This will result in some of the sentences being marked as incorrect by the parser. An analysis of the constraints these “incorrect” sentences violate can subsequently reveal how to transform so it accepts as correct the sentences in the corpus of LT—i.e., how to transform it into . If we can automate this process, we can greatly aid the work of world’s linguists. Figure 9.11 shows our problem and our proposed solution through Hybrid Parsing in schematic form.

9.6.3.3    An Example

Let LS = English and LT = French, and let us assume that English adjectives always precede the noun they modify, while in French they always post-cede it (an oversimplification, just for illustration purposes). Thus, “the blue book” is correct English, whereas in French we would more readily say “le livre bleu”.

Figure 9.11  The problem (left) and the solution (right).

If we plug the French lexicon and the English syntax constraints into our Womb Grammar parser, and run a representative corpus of (correct) French noun phrases by the resulting hybrid parser, the said precedence property will be declared unsatisfied when hitting phrases such as “le livre bleu”. The grammar repairing module can then look at the entire list of unsatisfied constraints, and produce the missing syntactic component of LT’s parser by modifying the constraints in so that none are violated by the corpus sentences.

Some of the necessary modifications are easy to identify and to perform, e.g., for accepting “le livre bleu” we only need to delete the (English) precedence requirement of adjective over noun (written as adj < n). However, subtler modifications may be in order, perhaps requiring some statistical analysis in a second round of parsing: if in our LT corpus, which we have assumed to be representative, all adjectives appear after the noun they modify, French is sure to include the reverse precedence property compared to English: n < adj. So in this case, not only do we need to delete adj < n, but we also need to add n < adj.

9.7    Hypothetical Reasoning with CHR and Prolog: Hyprolog

Abduction, or abductive reasoning, means reasoning from observed results to the basic facts from which they follow. This includes producing qualified guesses for possible causes (diagnoses) for observable phenomena (symptoms). Abduction in logic programming is usually conceived as searching for facts to add to a program to make an otherwise failing query succeed. However, so-called integrity constraints may be needed to exclude combinations of abduced facts that are incompatible with any real world situation. Abduction in logic programming has been studied since around 1990 with Kakas and Mancarella [1990] as a key reference; see also the overview papers of Kakas et al. [1998] and Denecker and Kakas [2002]. The Hyprolog system [Christiansen and Dahl 2005],¹³ developed by the present authors, appears to be the first implementation of abduction that utilizes an existing technology, in this case CHR, in a direct and efficient way with no interpretational overhead.

Figure 9.12  Abductive reasoning in Prolog with CHR: a program and a sample query.

There is an inherent connection between abductive reasoning and constraint logic programming. Abducible predicates are, as opposed to traditional Prolog predicates, understood in an open world sense, i.e., entering a goal of such a predicate that is not provable according to the known rules and facts, does not necessarily provoke failure, but is rather assumed as “might be the case.” Constraints in constraint logic programming [Jaffar and Lassez 1987] behave in exactly the same way: entering a constraint X>1 adds more information about X (as opposed to Prolog in which a similar call to the built-in predicate > would lead to a runtime error when X is unbound, meaning “too complicated, sorry”). This relationship was first identified in an early 1992 paper by Maim [1992] and spelled out in more detail by Christiansen [2014b], which also took into account the work involving CHR, explained below.

Prolog with CHR provides a direct way of writing abductive logic programs, which is shown via an example in Figure 9.12. The program declares three abducible predicates as constraints used in the Prolog rules that define how a person can be happy, either by being rich or by being a professor with nice students. The CHR rule serves as an integrity constraint, expressing the fact that you do not get rich from working as a professor. The query and its answer give the one and only explanation why a specific professor may be happy.

Hyprolog adds a layer of syntactic sugar upon Prolog and CHR, a collection of utilities plus assumptions described in Section 9.5 above. For example, abducible predicates are declared as, e.g., abducible rich/1, which introduces constraint predicates rich/1 and rich_/1, the latter representing the negation of rich/1.

Hyprolog works smoothly with DCGs as demonstrated by the examples below; it provides an implementation of Assumption Grammars that runs with current Prolog systems and is easily adaptable to any Prolog system that supports CHR; and it represents the paradigm of “(language) interpretation as abduction” [Hobbs et al. 1993] in a logic programming setting.

An Example

The application of Hyprolog with Definite Clause Grammars for abductive text analysis is shown in the following example, adapted from Christiansen [2014a].

We consider a constraint solver to be used for the analysis of stories about the students at a small university at some fixed moment of time. The university has a number of rooms and other places, where students are allowed to go. These include two lecture halls encoded in the program below as lectHall1, lectHall2; a reading room rRoom, a student bar bar, a garden garden, etc. There are currently two courses going on, programming in lectHall1 and linguistics in lectHall2. The following constraint predicates are introduced, in(s,r) indicating that student s is in room r, attends(s,c) that student s attends course c, can_see(s₁,s₂) that student s₁ can see student s₂, and finally reading(s) indicating that student s is reading. A student can only be in one room at a time, and reading can take place in any room but the lecture halls. A constraint solver for this can be expressed in CHR as follows; the constraint diff(x,y) is a standard device indicating that x and y must be different (which is easily defined in CHR):

A rule body may provide alternative suggestions for explaining different observations. For example, for student x to see student y they must be in the same room or they may see each other through a video call using Skype. The two additional constraints and a rule are introduced to capture this as follows, where the semicolon stands for Prolog’s disjunction:

The CHR declarations shown so far define a constraint solver that can be used together with any parsing algorithm in order to collect knowledge from a discourse. Here we show a DCG in which the constraints are called directly from within the grammar rules:

Consider now a query phrase(story,[peter,…]) for the analysis of the text Peter sees Mary. Peter sees Jane. Peter is at the programming course. Mary is at the programming course. Jane is reading. It yields the following answer, i.e., the final constraint store when the text sequence has been traversed by the grammar:

The uninstantiated variable “X” stands for Jane’s location, which is not determined from the discourse; it is only known not to be one of the lecture halls as expressed by the two diff/2 constraints.

The example shows an incremental analysis of the text, in which the knowledge learned up to a certain point is available for the analysis of the next sentence. Furthermore, the use of constraint-based techniques delays choices that cannot be resolved currently, but may be resolved later when new knowledge is introduced.

9.8    A Note on the Usefulness of Probabilistic Logic Programming for Language Processing

T. Sato’s PRISM system¹⁴ [Sato and Kameya 1997] is a version of Prolog extended with a special sort of random variables, which give rise to a distribution semantics [Sato 1995]. Each atom has a probability corresponding to the sum of probabilities of simultaneous outcomes of the program’s random variables that makes it true. The PRISM system is equipped with a collection of powerful algorithms, including for parameter learning from collections of samples, for finding the most probable proof of a given goal, and for sampling.

PRISM is especially interesting in the present context, as it could not work without an underlying tabling system. It is implemented in B-Prolog¹⁵ [Zhou 2012] whose tabling mechanism is quite similar compared to that of XSB: probabilities are calculated by considering all possible ways a given goal may be proven, of which there are typically exponentially many, but tabling may reduce this to a manageable complexity. The PRISM manual [Sato et al. 2017] shows applications to Probabilistic Context-Free Grammars [Charniak 1993], which have been extended to Probabilistic Definite Clause Grammars [Have 2009]. PRISM has also been applied to analysis of biological sequence data by one of the present authors, e.g., Christiansen and Dahmcke [2007], Christiansen et al. [2011b, 2011a], and Have et al. [2013].

Both probabilistic and statistical NLP are ubiquitous nowadays and yield impressive results in those cases where it is easy to separate correct results from nonsensical ones. For instance, when texting on a cell phone or dictating LaTeX, the author is there to correct automated wrong word predictions or interpretations that constantly come up. However, when one must rely on robust results, e.g., when giving directions to a machine through NL, tolerance of mistakes drops dramatically, as mandated by safety concerns. In such cases, inferential backbones are more adequate.

Also, explaining capabilities are often absent from probabilistic and statistical approaches, whose black box model precludes us from obtaining reasonable justification of the proposed results. We expect that logic grammars may experience a renaissance for the analysis in such cases, for instance in argumentation mining (see the survey of Lippi and Torroni [2016]) and in other applications involving large text corpora in which the meaning is more important than the mere occurrences of terms. It may even be interesting to combine the brute force power of statistical processing with the reasoning power of logic grammar parsing: the fact that tabled parsing is available in both approaches strongly suggests a possible synergy between them.

9.9    Conclusion

We have given an overview of logic grammars applied for analysis of natural language, admittedly not covering all the work that has been done in this field, and admittedly reflecting the personal perspective of the authors. For a more detailed overview of the work prior to 1994, we refer to Dahl [1994].

We emphasized DSW’s contributions to the field, most importantly his work on Tabled Logic Programming and his observation of how this greatly improves the expressibility and practicability of Definite Clause Grammars. We compared with other logic grammar systems that also apply different sorts of implicit or explicit memoization principles, including constraint-based systems. As interesting directions for future research work, we may point out the potentials in combining assumptions (Section 9.5) and constraint-based abductive interpretation (Section 9.7) with tabled execution of logic grammar rules.

It is intended that this chapter may be used as an introduction to the field and that it may help to create a renewed focus on logical methods for language processing as a complement to the currently dominating statistical techniques.

9.A   A Toy DCG for a Simple Subset of English

References

E. J. G. Arias, R. Haemmerlé, M. V. Hermenegildo, and J. F. Morales. 2013. The Ciao clp(FD) library. A modular CLP extension for Prolog. CoRR, abs/1301.7702. http://arxiv.org/abs/1301.7702. 483

P. Blache and J.-M. Balfourier. 2001. Property grammars: a flexible constraint-based approach to parsing. In Proceedings of the Seventh International Workshop on Parsing Technologies (IWPT-2001), October 2001, 17–19. Beijing, China. Tsinghua University Press. 502

P. Blache, H. Christiansen, V. Dahl, D. Duchier, and J. Villadsen, editors 2014. Constraints and Language. Cambridge Scholars Press. 498

E. Charniak. 1993. Statistical Language Learning. The MIT Press. 508

H. Christiansen. 2005. CHR Grammars. Theory and Practice of Logic Programming, 5(4-5): 467–501. DOI: 10.1017/S1471068405002395. 499

H. Christiansen. 2009. Executable specifications for hypothesis-based reasoning with Prolog and Constraint Handling Rules. Journal of Applied Logic, 7(3): 341–362. DOI: 10.1016/j.jal.2008.10.004. 498

H. Christiansen. 2014a. Constraints and logic programming in grammars and language analysis. In P. Blache, H. Christiansen, V. Dahl, D. Duchier, and J. Villadsen, editors, Constraints and Language, pp. 21–35. Cambridge Scholars Publishing. 506

H. Christiansen. 2014b. Constraint programming for context comprehension. In P. Brézillon and A. Gonzalez, editors, Context in Computing – A Cross-Disciplinary Approach for Modeling the Real World, pp. 401–418. Springer. DOI: 10.1007/978-1-4939-1887-4_25. 505

H. Christiansen and V. Dahl. 2005. HYPROLOG: A new logic programming language with assumptions and abduction. In M. Gabbrielli and G. Gupta, editors, Logic Programming, 21st International Conference, ICLP 2005, Sitges, Spain, October 2-5, 2005, Proceedings, vol. 3668 of Lecture Notes in Computer Science, pp. 159–173. Springer. DOI: 10.1007/11562931_14. 505

H. Christiansen and C. M. Dahmcke. 2007. A machine learning approach to test data generation: A case study in evaluation of gene finders. In P. Perner, editor, Machine Learning and Data Mining in Pattern Recognition, 5th International Conference, MLDM 2007, Leipzig, Germany, July 18–20, 2007, Proceedings, vol. 4571 of Lecture Notes in Computer Science, pp. 742–755. Springer. DOI: 10.1007/978-3-540-73499-4_56. 508

H. Christiansen, C. T. Have, and K. Tveitane. 2007a. Reasoning about use cases using logic grammars and constraints. In Proceedings of the 4th International Workshop on Constraints and Language processing (CSLP 2007), number 113 in Computer Science Research Reports, pp. 40–52. Roskilde University. 501

H. Christiansen, C. T. Have, and K. Tveitane. 2007b. From use cases to UML class diagrams using logic grammars and constraints. In Recent Advances in Natural Language Processing (RANLP-2007), pp. 128–132. INCOMA Ltd., Shoumen, Bulgaria. 501

H. Christiansen, C. T. Have, O. T. Lassen, and M. Petit. 2011a. Taming the zoo of discrete HMM subspecies & some of their relatives. In G. Bel-Enquix, V. Dahl, and M. D. J. López, editors, Biology, Computation and Linguistics, New Interdisciplinary Paradigms, Vol. 228 of Frontiers in Artificial Intelligence and Applications, pp. 28–42. IOS Press. DOI: 10.3233/978-1-60750-762-8-28. 508

H. Christiansen, C. T. Have, O. T. Lassen, and M. Petit. 2011b. Bayesian annotation networks for complex sequence analysis. In J. P. Gallagher and M. Gelfond, editors, Technical Communications of the 27th International Conference on Logic Programming, ICLP 2011, July 6–10, 2011, Lexington, Kentucky, USA, vol. 11 of LIPIcs, pp. 220–230. Schloss Dagstuhl Leibniz-Zentrum fuer Informatik. DOI: 10.4230/LIPIcs.ICLP.2011.220. 508

A. Colmerauer. 1978. Metamorphosis grammars. In L. Bolc, editor, Natural Language Communication with Computers, vol. 63 of Lecture Notes in Computer Science, pp. 133–189. Springer. First appeared as “Les Grammaires de Metamorphose,” Groupe d’Intelligence Artificielle, Université de Marseille II, November 1975. DOI: 10.1007/BFb0031371. 481

A. Colmerauer. 1982. An interesting subset of natural language. In K. Clark and S.-Å. Tärnlund, editors, Logic Programming, pp. 45–66. Academic Press. 482

A. Colmerauer. 1986. Theoretical model of Prolog II. In M. van Caneghem and D. Warren, editors, Logic Programming and its Applications, pp. 3–31. Ablex Publishing Corporation. 498

A. Colmerauer. 1990. An introduction to Prolog III. Communications of the ACM, 33(7): 69–90. DOI: 10.1145/79204.79210. 498

A. F. da Silva and V. S. Costa. 2007. Design, implementation, and evaluation of a dynamic compilation framework for the YAP system. In V. Dahl and I. Niemelä, editors, Logic Programming, 23rd International Conference, ICLP 2007, Porto, Portugal, September 8–13, 2007, Proceedings, vol. 4670 of Lecture Notes in Computer Science, pp. 410–424. Springer. DOI: 10.1007/978-3-540-74610-2_28. 483

V. Dahl. 1977a. Translating Spanish into Logic through Logic. These de Doctorat de Specialite en Intelligence Artificielle, Universite d’Aix-Marseille II, France.

V. Dahl. 1977b. Some experiences on natural language question-answering systems. Preprints of the International Workshop on Logic and Data Bases, CERT, Toulouse. 481, 492

V. Dahl. 1981. Translating Spanish into logic through logic. American Journal of Computational Linguistics, 7(3): 149–164. 481, 482

V. Dahl. 1994. Natural language processing and logic programming. Journal of Logic Program., 19/20: 681–714. DOI: 10.1016/0743-1066(94)90036-1. 482, 509

V. Dahl and P. Blache. 2004. Implantation de grammaires de propriétés en CHR. In F. Mesnard, editor, Programmation en logique avec contraintes, Journées Francophones de Programmation Logique par Contraintes 2004, June 21–23 2004, Angers, France. Hermes. 502

V. Dahl and J. E. Miralles. 2012. Womb Grammars: Constraint solving for grammar induction. In J. Sneyers and T. Frühwirth, editors, Proceedings of the 9th Workshop on Constraint Handling Rules, vol. Technical Report CW 624, pp. 32–40. Department of Computer Science, K.U. Leuven. 502, 503

V. Dahl and R. Sambuc. 1976. Un systeme de banque de donnees en logique du premier ordre, en vue de sa consultation en langue naturelle. Rapport de DEA, Universite d’Aix-Marseille II, pp. 1–29. 481

V. Dahl, P. Tarau, and R. Li. 1997. Assumption Grammars for processing natural language. In L. Naish, editor, Logic Programming, Proceedings of the Fourteenth International Conference on Logic Programming, Leuven, Belgium, July 8–11, 1997, pp. 256–270. MIT Press. 492, 496

V. Dahl, S. Tessaris, and M. de Sousa Bispo. March 2018. Parsing as semantically guided constraint solving: the role of ontologies. Annals of Mathematics and Artificial Intelligence, 82(1–3): 161—185. DOI: 10.1007/s10472-018-9573-2. 503

M. Denecker and A. C. Kakas. 2002. Abduction in logic programming. In A. C. Kakas and F. Sadri, editors, Computational Logic: Logic Programming and Beyond, vol. 2407 of Lecture Notes in Computer Science, pp. 402–436. Springer. DOI: 10.1007/3-540-45628-7_16. 505

P. Deransart and J. Maluszynski. 1985. Relating logic programs and attribute grammars. Journal of Logic Programming, 2(2): 119–155. DOI: 10.1016/0743-1066(85)90015-9. 480

J. Earley. 1970. An efficient context-free parsing algorithm. Communications of the ACM, 13(2): 94–102. DOI: 10.1145/362007.362035. 482, 500

T. W. Frühwirth. 1998. Theory and practice of Constraint Handling Rules. Journal of Logic Programming, 37(1-3): 95–138. DOI: 10.1016/S0743-1066(98)10005-5. 498, 499

T. W. Frühwirth. 2009. Constraint Handling Rules. Cambridge University Press. http://www.constraint-handling-rules.org. 498, 499

G. Gazdar, E. Klein, G. Pullum, and I. Sag. 1985. Generalized Phrase Structure Grammar. Harvard University Press, Cambridge, MA. 501

C. T. Have. 2009. Stochastic definite clause grammars. In G. Angelova, K. Bontcheva, R. Mitkov, N. Nicolov, and N. Nikolov, editors, Recent Advances in Natural Language Processing (RANLP-2009), September 14–16, 2009, Borovets, Bulgaria, pp. 139–143. Association for Computational Linguistics. http://aclweb.org/anthology/R/R09/R09-1027.pdf. 508

C. T. Have, S. Zambach, and H. Christiansen. 2013. Effects of using coding potential, sequence conservation and mRNA structure conservation for predicting pyrroly-sine containing genes. BMC Bioinformatics, 14: 118. DOI: 10.1186/1471-2105-14-118. 508

J. R. Hobbs, M. E. Stickel, D. E. Appelt, and P. A. Martin. 1993. Interpretation as abduction. Artificial Intelligence, 63(1-2): 69–142. DOI: 10.1016/0004-3702(93)90015-4. 506

G. Huet. 1972. Constrained Resolution: A Complete Method for Type Theory. Ph.D. thesis, Case Western Reserve University, Ohio, USA. 498

J. Jaffar and J. Lassez. 1987. Constraint logic programming. In Conference Record of the Fourteenth Annual ACM Symposium on Principles of Programming Languages, Munich, Germany, January 21–23, 1987, pp. 111–119. ACM Press. DOI: 10.1145/41625.41635. 498, 505

A. Kakas, R. Kowalski, and F. Toni. 1998. The role of abduction in logic programming. Handbook of Logic in Artificial Intelligence and Logic Programming, vol. 5, D.M. Gabbay, C.J. Hogger, J.A. Robinson, (editors), Oxford University Press, pp. 235–324. 505

A. C. Kakas and P. Mancarella. 1990. Database updates through abduction. In D. McLeod, R. Sacks-Davis, and H. Schek, editors, 16th International Conference on Very Large Data Bases, August 13–16, 1990, Brisbane, Queensland, Australia, Proceedings, pp. 650–661. Morgan Kaufmann. http://www.vldb.org/conf/1990/P650.PDF. 505

D. E. Knuth. 1968. Semantics of context-free languages. Mathematical Systems Theory, 2(2): 127–145. DOI: 10.1007/BF01692511. 480

R. A. Kowalski. 1979. Logic for problem solving. North-Holland. Revised version, editor T. Frühwirth, BoD – Books on Demand (2014). 479

M. Lippi and P. Torroni. Mar. 2016. Argumentation mining: State of the art and emerging trends. ACM Transactions on Internet Technology, 16(2): 10:1–10:25. DOI: 10.1145/2850417. 509

E. Maim. 1992. Abduction and constraint logic programming. In B. Neumann, editor, 10th European Conference on Artificial Intelligence, ECAI 92. Proceedings, pp. 149–153. John Wiley and Sons. 505

R. Montague. 1974. The proper treatment of quantification in ordinary English. In R. H. Thomason, editor, Formal Philosophy, pp. 188–221. Yale University Press, New Haven, CT. DOI: 10.1007/978-94-009-2727-8_7. 482, 483

F. C. N. Pereira and S. M. Shieber. 1987. Prolog and Natural-Language Analysis, vol. 10 of CSLI Lecture Notes Series. Center for the Study of Language and Information. 479

F. C. N. Pereira and D. H. D. Warren. 1980. Definite Clause Grammars for language analysis A survey of the formalism and a comparison with Augmented Transition Networks. Artificial Intelligence, 13(3): 231–278. DOI: 10.1016/0004-3702(80)90003-X. 481

J. A. Robinson. 1965. A machine-oriented logic based on the resolution principle. Journal of the ACM, 12(1): 23–41. DOI: 10.1145/321250.321253. 480, 483

T. Sato. 1995. A statistical learning method for logic programs with distribution semantics. In L. Sterling, editor, Logic Programming, Proceedings of the Twelfth International Conference on Logic Programming, Tokyo, Japan, June 13–16, 1995, pp. 715–729. MIT Press. 508

T. Sato and Y. Kameya. 1997. PRISM: A language for symbolic-statistical modeling. In Proceedings of the Fifteenth International Joint Conference on Artificial Intelligence, IJCAI 97, Nagoya, Japan, August 23–29, 1997, 2 vols., pp. 1330–1339. Morgan Kaufmann. http://ijcai.org/Proceedings/97-2/Papers/078.pdf. 508

T. Sato, N.-F. Zhou, Y. Kameya, Y. Izumi, K. Kubota, and R. Kojima, 2017. PRISM User’s Manual (Version 2.3). on-line document: http://rjida.meijo-u.ac.jp/prism/download/prism23.pdf. 508

T. Schrijvers and D. S. Warren. 2004. Constraint Handling Rules and tabled execution. In B. Demoen and V. Lifschitz, editors, Logic Programming, 20th International Conference, ICLP 2004, Saint-Malo, France, September 6–10, 2004, Proceedings, vol. 3132 of Lecture Notes in Computer Science, pp. 120–136. Springer. DOI: 10.1007/978-3-540-27775-0_9. 499

J. Sneyers, P. V. Weert, T. Schrijvers, and L. D. Koninck. 2010. As time goes by: Constraint Handling Rules. Theory and Practice of Logic Programming, 10(1): 1–47. DOI: http://doi.org/10.1017/S1471068409990123. 498

Swedish Institute of Computer Science, 2016. SICStus Prolog user’s manual, Version 4.3.5. Most recent version available at http://www.sics.se/isl. 496, 499

T. Swift and D. S. Warren. 1994. An abstract machine for SLG resolution: Definite programs. In M. Bruynooghe, editor, Logic Programming, Proceedings of the 1994 International Symposium, Ithaca, New York, USA, November 13–17, 1994, pp. 633–652. MIT Press. 483

T. Swift and D. S. Warren. 2012. XSB: extending prolog with tabled logic programming. Theory and Practice of Logic Programming, 12(1-2): 157–187. DOI: 10.1017/S1471068411000500. 481, 483

T. Swift, D. S. W. K. Sagonas, J. Freire, P. Rao, B. Cui, E. Johnson, L. de Castro, R. F. Marques, D. Saha, S. Dawson, and M. Kifer, 2016. The XSB System Version 3.7.x Vol. 1: Programmer’s Manual. Available online: http://xsb.sourceforge.net/manual1/manual1.pdf. 483, 488

H. Tamaki and T. Sato. 1986. OLD resolution with tabulation. In E. Y. Shapiro, editor, Third International Conference on Logic Programming, Imperial College of Science and Technology, London, United Kingdom, July 14–18, 1986, Proceedings, vol. 225 of Lecture Notes in Computer Science, pp. 84–98. Springer. DOI: 10.1007/3-540-16492-8_66. 483

P. Tarau. 2012. The binprolog experience: Architecture and implementation choices for continuation passing prolog and first-class logic engines. Theory and Practice of Logic Programming, 12(1-2): 97–126. DOI: 10.1017/S1471068411000433. 496

D. H. D. Warren. May 1977. Implementing Prolog – Compiling Predicate Logic Programs – Vols. 1 & 2. D.A.I. Research Report 39, 40, University of Edinburgh. 483

D. H. D. Warren and F. C. N. Pereira. July 1982. An efficient easily adaptable system for interpreting natural language queries. Computational Linguistics, 8(3-4): 110–122. 481

D. S. Warren. 1979. Syntax and Semantics in Parsing: An Application to Montague Grammar. Ph.D. thesis, University of Michigan. 483

D. S. Warren. 1983. Using Λ-calculus to represent meanings in logic grammars. In Proceedings of the 21st Annual Meeting on Association for Computational Linguistics, ACL ’83, pp. 51–56. Association for Computational Linguistics, Stroudsburg, PA. DOI: 10.3115/981311.981321. 482

D. S. Warren, 1999. Programming in Tabled Prolog (very) DRAFT 1. Available online: http://www.cs.sunysb.edu/~warren/xsbbook/book.html. 484

D. S. Warren. 2013. Interning ground terms in XSB. CoRR, abs/1307.4644. http://arxiv.org/abs/1307.4644. 484

J. Wielemaker. 2014. SWI-Prolog version 7 extensions. In T. Ströder and T. Swift, editors, Proceedings of the International Joint Workshop on Implementation of Constraint and Logic Programming Systems and Logic-based Methods in Programming Environments 2014, pp. 109–124. N 0935–3232, Aachener Informatik-Berichte. AIB-2014-09. Available online: http://www.swi-prolog.org/download/publications/swi7.pdf. 483

J. Wielemaker, T. Schrijvers, M. Triska, and T. Lager. 2012. SWI-Prolog. Theory and Practice of Logic Programming, 12(1-2): 67–96. 496, 498, 499

W. Woods, R. Kaplan, and B. Nash-Webber. 1972. The Lunar science natural language information system: Final report. Technical report, BBN Report No. 2378, Cambridge, MA. 482

W. A. Woods. 1970. Transition network grammars for natural language analysis. Communications of the ACM, 13(10): 591–606. DOI: 10.1145/355598.362773. 483

N. Zhou. 2012. The language features and architecture of B-Prolog. Theory and Practice of Logic Programming, 12(1-2): 189–218. DOI: 10.1017/S1471068411000445. 508

N. Zhou and C. T. Have. 2012. Efficient tabling of structured data with enhanced hashconsing. Theory and Practice of Logic Programming, 12(4-5): 547–563. DOI: 10.1017/S1471068412000178. 484

N. Zhou, Y. Shen, L. Yuan, and J. You. 2001. Implementation of a linear tabling mechanism. Journal of Functional and Logic Programming, 2001(10). DOI: 10.1007/3-540-46584-7_8. 483

1. From now on, we use “logic grammar” to mean a “grammar that has a sort of logical interpretation and is implemented somehow with logic programming”.

2. Definite Clause Grammars can also, under certain circumstances, be used for generating sentences. We do not go into details about this aspect here.

3. Here we explain the tabling mode based on variance, but XSB allows also a more general form based on subsumption by goals in the table; see precise details in the XSB manual [Swift et al. 2016].

4. It is very instructive to run this query with the given grammar using a Prolog tracer to see the exact execution.

5. The notation an stands for a sequence of n “a”-symbols separated by commas.

6. Strictly speaking, the grammar of Figure 9.7 is context free, since the possible instances of each nonterminal is finite and the rules with variables can be unfolded accordingly. However, writing the grammar, as shown, emphasizes the syntactic context dependencies across the sentences.

7. Available as open source at http://code.google.com/archive/p/binprolog/.

8. http://sicstus.sics.se/

9. http://www.swi-prolog.org

10. http://www.swi-prolog.org

11. The CHRG system is available with source code, user guide, and examples at http://www.ruc.dk/~henning/chrg. It runs under SICStus Prolog 5 [Swedish Institute of Computer Science 2016] and SWI Prolog (http://www.swi-prolog.org) [Wielemaker et al. 2012]. It has not yet been tested with XSB that also supports CHR; the XSB manual and Schrijvers and Warren [2004] explain some advantages of combining tabling and CHR, but the consequences for CHRGs have not been analyzed yet.

12. There is a very close analogy between a CHRG parser consisting of propagation rules only and a DCG executed under tabling. In case of an ambiguous grammar, the same analyzed text fragments are re-used in many different combinations. Both paradigms make sure that each fragment is analysed in a particular way at most once—exactly as with an Earley parser [Earley 1970]—and as opposed to a DCG that does not use tabling.

13. http://www.ruc.dk/~henning/hyprolog

14. http://rjida.meijo-u.ac.jp/sato-www/prism/

15. http://www.picat-lang.org/bprolog/

10

Logic Programming Applications: What Are the Abstractions and Implementations?

Yanhong A. Liu

This chapter presents an overview of applications of logic programming, classifying them based on the abstractions and implementations of logic languages that support the applications. The three key abstractions are join, recursion, and constraint. Their essential implementations are for-loops, fixed points, and backtracking, respectively. The corresponding kinds of applications are database queries, inductive analysis, and combinatorial search, respectively. We also discuss language extensions and programming paradigms, summarize example application problems by application areas, and touch on example systems that support variants of the abstractions with different implementations.

10.1  Introduction

Common reasoning with logic is the root of logic programming, which allows logic rules and facts to be expressed formally and used precisely for inference, querying, and analysis in general. Logic formalisms, or languages, allow complex application problems to be expressed declaratively with high-level abstractions and allow desired solutions to be found automatically with potentially efficient low-level implementations.

The biggest challenge in logic programming has been the need for efficient implementations. Much progress has been made, with efficient implementations in some cases beating manually written low-level code. However, inadequate performance in many cases has led to the introduction of non-declarative features in logic languages and resulted in the writing of obscure logic programs.

Despite the challenges, the most exciting aspect of logic programming is its vast areas of applications. They range from database queries to program analysis, from text processing to decision making, from security to knowledge engineering, and more. These vast, complex, and interrelated areas make it challenging but necessary to provide a deeper understanding of the various kinds of applications in order to help advance the state of the art of logic programming and realize its benefits.

This chapter presents an overview of applications of logic programming based on a study of the abstractions and implementations of logic languages. The rationale is that abstractions and implementations are the enabling technologies of the applications. The abstractions are essential for determining what kinds of application problems can be expressed and how they can be expressed, for ease of understanding, reuse, and maintenance. The underlying implementations are essential for high-level declarative languages to be sufficiently efficient for substantial applications.

We discuss the following essential abstractions, where data abstractions are for expressing the data, and control abstractions are for expressing computations over the data:

•  data abstractions: objects and relationships; and

•  control abstractions: (1) join, (2) recursion, and (3) constraint, which capture bounded, cyclic, and general computations, respectively.

In logic languages, the data abstractions as objects and relationships are essential for all three control abstractions.

The essential techniques for implementing the three control abstractions listed are (1) for-loops, (2) fixed points, and (3) backtracking, respectively. The corresponding kinds of applications are

1.  database-style queries, e.g., for ontology management, business intelligence, and access control;

2.  inductive analysis, e.g., for text processing, program analysis, network traversal, and trust management; and

3.  combinatorial search, e.g., for decision making, resource allocation, games and puzzles, and administrative policy analysis.

We categorize application problems using these three control abstractions because they capture conceptually different kinds of problems, with inherently different implementation techniques, and at the same time correspond to very different classes of applications.

Note that the same application domain may use different abstractions and implementations for different problems. For example, enterprise software may use all three of traditional database queries, inductive analysis, and combinatorial search, for business intelligence and decision making; and security policy analysis and enforcement may use database-style queries for access control, inductive analysis for trust management, and combinatorial search for administrative policy analysis.

We also discuss additional extensions, especially regular-expression paths for higher-level queries and updates for modeling actions; additional applications; and abstractions used in main programming paradigms. We also touch on several well-known systems while discussing the applications.

There is a large body of prior work, including surveys of logic programming in general and applications in particular, as discussed in Section 10.7. This chapter distinguishes itself from past work by analyzing classes of applications based on the language abstractions and implementations used.

The rest of the chapter is organized as follows. Section 10.2 presents essential abstractions in logic languages. Sections 10.3, 10.4, and 10.5 describe abstractions, implementations, and applications centered around join, recursion, and constraint, respectively. Section 10.6 discusses additional language extensions, applications, and programming paradigms. Section 10.7 discusses related literature and future directions.

10.2  Logic Language Abstractions

Logic languages provide very high-level data and control abstractions, using mostly very simple language constructs. We describe these abstractions and their meanings intuitively.

10.2.1  Data Abstractions

All data in logic languages are abstracted, essentially, as objects and relationships.

Objects. Objects are primitive values, such as numbers and strings, or structured values whose components are objects.

Examples of primitive values are integer number 3 and string 'Amy'. We enclose a string value in single quotes; if a string starts with a lower-case letter, such as 'amy', the quotes can be omitted, as has been conventional in logic languages.

Examples of structured values are succ(3), father(amy), and cert('Amy',birth('2000-02-28','Rome')), denoting the successor integer of 3, the father of amy, and the certificate that 'Amy' was born on '2000-02-28' in 'Rome', respectively.

The names of structures, such as succ, father, cert, and birth above, are called function symbols. They correspond to object constructors in object-oriented languages.

Relationships. Relationships are predicates, or properties, that hold among objects. In particular, p(o₁,…,ok), i.e., predicate p over objects o₁,…,ok being true, is equivalent to (o₁,…,ok) in p, i.e., tuple (o₁,…,ok ) belonging to relation p—a table that holds the set of tuples of objects over which p is true.

Examples of relationships are male(bob), is_parent(bob,amy), and issue(mario,'Amy',birth('2000-02-28','Rome')), denoting that bob is male, bob is a parent of amy, and mario issued a certificate that 'Amy' was born on '2000-02-28' in 'Rome', respectively.

Structured values can be easily captured using relationships, but not vice versa. For example, f being the structured value father(c) can be captured using relationship is_father(f,c), but relationship is_parent(p,c) cannot simply be captured as p being the structured value parent(c) when c has two parents.

Such high-level data abstraction allows real-world objects or their lower-level representations, from bits and characters to lists to sets, to be captured easily without low-level implementation details. For example:

•  bits and characters are special cases of integers and strings, respectively;

•  lists are a special case of linearly nested structured values; and

•  sets are a special case of relations consisting of tuples of one component.

Objects and relationships can be implemented using well-known data structures, including linked list, array, hash table, B-tree, and trie, usually taking O(1) or O(log n) time to access an object, where n is the size of the data.

10.2.2  Control Abstractions

Control in logic languages is abstracted at a high level, as logical inference or logic queries over asserted relationships among objects:

•  asserted relationships can be connected by logical connectives: conjunction (read “and”), disjunction (read “or”), negation (read “not”), implication (read “then”), backward implication (read “if”), and equivalence (read “if and only if”);

•  variables can be used in place of objects and be quantified over with universal quantifier (read “all”) and existential quantifier (read “some”); and

•  one can either infer all relationships that hold or query about certain relationships, among all objects or among certain objects.

Rules and facts are the most commonly supported forms in existing logic languages.

Rules. A rule is of the following form, where assertion₀ is called the conclusion, and other assertions are called the hypotheses. Each assertion is a predicate over certain objects, where variables may be used in place of objects. Intuitively, left arrow (<-) indicates backward implication, comma (,) denotes conjunction, and all variables in a rule are implicitly universally quantified, i.e., the rule holds for all values of the variables.

For example, the second rule below says: X is a grandfather of Y if X is the father of Z and Z is a parent of Y, and this holds for all values of variables X, Y, and Z; the other rules can be read similarly. Following logic language conventions, names starting with an uppercase letter are variables:

The second rule is a join query—its two hypotheses have a shared variable, and it concludes a new predicate.

The third and fourth rules are recursive—the predicate in the conclusion depends on itself in a hypothesis, or in general possibly indirectly through another predicate.

Note that disjunction of a set of hypotheses can be expressed using a set of rules with the same conclusion.

Facts. A fact is a rule that has no hypotheses and is denoted simply as assertion0. For example, is_father(bob,amy). says that bob is the father of amy, and is_positive(1). says that 1 is positive.

The meaning of a set of rules and facts is the least set of facts that contains all the given facts and all the facts that can be inferred, directly or indirectly, using the rules. This set can be computed by starting with the given facts and repeatedly applying the rules to conclude new facts—i.e., matching hypotheses of rules against facts, instantiating variables in rules with values in matched facts, and adding instantiated conclusions of rules as new facts. However,

•  Repeated application of rules might not terminate if function symbols are used in the rules, because facts about infinitely many new objects may be concluded, e.g., the fourth example rule above may infer is_positive(succ(1)), is_positive(succ(succ(1))), and so on.

•  When only certain relationships about certain objects are queried, application of rules may stop as soon as the query can be answered, e.g., if only is_positive(succ(1)) is queried, application of rules can stop after one use of the given rule and the given fact.

Rules that do not contain function symbols are called Datalog rules. For example, the first three example rules given earlier in this section are Datalog rules.

General logic forms have also been increasingly supported, typically by extending the rule form above.

Negation in the hypotheses. A hypothesis in a rule may be prefixed with not, denoting negation of the asserted relationship.

For example, the following rule says: for all values of X and Y, X is the mother of Y if X is a parent of Y and X is not male:

Difficulties arise when negation is used with recursion. For example, what can be inferred from the following rule? Is good(zak) true or false?

More general forms. More general forms include disjunction and negation in the conclusion and, most generally, quantifiers all and some in any scope, not only the outermost scope. For example, the first rule below says: X is male or female if X is a person. The second rule says: X is not a winning position if, for all Y, either there is no move from X to Y or Y is a winning position.

The meaning of recursive rules with negation is not universally agreed upon. The two dominant semantics are well-founded semantics (WFS) [Van Gelder et al. 1991, Van Gelder 1993] and stable model semantics (SMS) [Gelfond and Lifschitz 1988]. Both WFS and SMS use the closed-world assumption, i.e., they assume that what cannot be inferred to be true from the given facts and rules, is false.

•  WFS gives a single three-valued model, with the additional truth value undefined besides true and false.

•  SMS gives zero or more two-valued models, using only true and false.

Other formalisms and semantics include partial stable models, also called stationary models [Przymusinski 1994]; first-order logic with inductive and fixed-point definitions, called FO(ID) and FO(FD) [Denecker and Ternovska 2008, Hou et al. 2010]; and the newly proposed founded semantics and constraint semantics [Liu and Stoller 2018]. The first two are both aimed at unifying WFS and SMS. The last unifies and cleanly relates WFS, SMS, and other major semantics by allowing assumptions about the predicates and rules to be specified explicitly.

For practical applications, logic languages often also support predefined relationships among objects, including equality, inequality, and general comparisons. Cardinality and other aggregates over relationships are often also supported.

10.2.3  Combinations of Control Abstractions

There are many possible combinations of the language constructs. We focus on the following three combinations of constructs as essential control abstractions. We identify them by join, recursion, and constraint. They capture bounded, cyclic, and general computations, respectively.

Join. With join queries, no recursive rules, and restricted negation and other constructs; the restriction is that, for each rule, each variable in the conclusion must also appear in a hypothesis that is a predicate over arguments. Implementing this requires that common objects for the shared variables be found for the two hypotheses of a join query to be true at the same time; the number of objects considered are bounded, by the predicates in the hypotheses, following a bounded number of dependencies.

Recursion. With join queries, recursive rules, and restricted negation and other constructs; the restriction is as for join above plus that a predicate in the conclusion of a rule does not depend on the negation of the predicate itself in a hypothesis of some rule. Implementing this requires repeatedly applying the recursive rules following cyclic dependencies, potentially an unbounded number of times if new objects are in some conclusions.

Table 10.1  Essential control abstractions of logic languages

Constraint. With join queries, recursive rules, and unrestricted negation and other constructs; unrestricted negation and other constructs can be viewed as constraints to be satisfied. Implementing this could require, in general, trying different combinations of variable values, as in general constraint solving.

Table 10.1 summarizes these three essential control abstractions and the corresponding kinds of computations and applications.

10.3  Join and Database-Style Queries

Join queries are the most basic and most commonly used queries in relating different objects. They underlie essentially all nontrivial queries in database applications and many other applications.

10.3.1  Join Queries

A join query is a conjunction of two hypotheses that have shared variables, concluding possible values of variables that satisfy both hypotheses. A conjunction of two hypotheses that have no shared variables, i.e., a Cartesian product, or a single hypothesis can be considered a trivial join query. A join query corresponds to a rule whose predicate in the conclusion is different from predicates in the hypothesis, so the rule is not recursive. A non-recursive rule with more than two hypotheses corresponds to multiple join queries, as a nesting or chain of join queries starting with joining any two hypotheses first.

For example, the first rule below, as seen before, is a join query. So is the second rule; it defines sibling over X and Y to be true if X and Y have a same parent. The third rule defines a chain of red, green, and blue links from X to Y through U and V; it can be viewed as two join queries—join any two hypotheses first, and then join the result with the third hypothesis.

In general, the asserted predicates can be about relationships among any kinds of objects—whether people, things, events, or anything else, e.g., students, employees, patients, doctors, products, courses, hospitals, flights, interviews, and hangouts; and the join queries can be among any kinds of relationships—whether family, friend, owning, participating, thinking, or any other relation in the real world or conceptual world.

Join queries expressed using rules correspond to set queries. For example, in a language that supports set comprehensions with tuple patterns [Rothamel and Liu 2007, Liu et al. 2016], the is_grandfather query corresponds to

Without recursion, join queries can be easily supported together with the following extensions, with the restriction that, for each rule, each variable in the conclusion must also appear in a hypothesis that is a predicate over arguments, so the domain of the variable is bounded by the predicate; queries using these extensions can be arbitrarily nested:

•  unrestricted negation, other connectives, and predefined relationships in additional conditions;

•  aggregates, such as count and max, about the relationships; and

•  general universal and existential quantifiers in any scope.

These subsume all constructs in the select statement for SQL queries. Essentially, join queries, with no recursion, relate objects in different relationships within a bounded number of steps.

10.3.2  Implementation of Join Queries

A join query can be implemented straightforwardly using nested for-loops and if-statements, where shared variables in different hypotheses correspond to equality tests between the corresponding variables. For example, the is_grandfather query earlier in this section can be implemented as

In a language that supports set comprehensions, such as Python, the above implementation can be expressed as

For efficient implementations, several key implementation and optimization techniques are needed, described below; additional optimizations are also needed, e.g., for handling streaming data or distributed data.

Indexing. This creates an index for fast lookup based on values of the indexed arguments of a relation; the index is on the shared arguments of the two hypotheses. For example, for any fact is_father(X,Z), to find the matching is_parent(Z,Y), an index called, say, children{Z}—mapping the value of Z, the first argument of is_parent, to the set of corresponding values of second argument of is_parent—significantly speeds up the lookup, improving the time factor for the inner loop to the number of children of Z:

Join ordering. This optimizes the order of joins when there are multiple joins, e.g., in a rule with more than two hypotheses. For example, for the rule for chain, starting by joining the first and third hypotheses is never more efficient than starting by joining either of these hypotheses with the second hypothesis, because the former yields all pairs of red and blue links, even if there are no green links in the middle.

Tabling. This stores the result of common sub-joins so they are not repeatedly computed. Common sub-joins may arise when there are nested or chained join queries. For example, for the rule for chain earlier in this section, consider joining the first two hypotheses first: if there are many red and green link pairs from a value of X to a value of V, then storing the result of this sub-join avoids recomputing it when joining with blue links to find each target Y.

Demand-driven computation. This computes only those parts of relationships that affect a particular query. For example, a query may only check whether is_father(dan,bob) holds, or find all values of X for is_father(dan, X), or find all is_father pairs, as opposed to finding all relationships that can be inferred.

Basic ideas for implementing the extensions negation, aggregates, etc. are as follows, where nested queries using these extensions are computed following their order of dependencies:

•  negation, etc. in additional conditions: test them after the variables in them become bound by the joins;

•  aggregates: apply the aggregate operation while collecting the query result of its argument; and

•  quantifiers: transform them into for-loops, or into aggregates, e.g., an existential quantification is equivalent to a count being positive.

Efficient implementation techniques for join queries and extensions have been studied in a large literature, e.g., Ioannidis [1996]. Some methods also provide precise complexity guarantees, e.g., Willard [2002] and Liu et al. [2016].

10.3.3  Applications of Join Queries

Join queries are fundamental in querying complex relationships among objects. They are the core of database applications [Kifer et al. 2006], from enterprise management to ontology management, from accounting systems to airline reservation systems, and from electronic health records management to social media management. Database and logic programming are so closely related that one of the most important computer science bibliographies is called DBLP, and it was named after Database and Logic Programming [Ley 2002]. Join queries also underlie applications that do not fit in traditional database applications, such as complex access control policy frameworks [ANSI INCITS 2004].

We describe three example applications below, in the domains of ontology management, enterprise management, and security policy frameworks. They all heavily rely on the use of join queries and optimizations, especially indexing. We give specific examples of facts, rules, and indexing for the first application.

Ontology Management—Coherent Definition Framework (CDF). CDF is a system for ontology management that has been used in numerous commercial projects [Gomes et al. 2010], for organizing information about, e.g., aircraft parts, medical supplies, commercial processes, and materials. It was originally developed by XSB, Inc. Significant portions have been released in the XSB packages [Swift et al. 2014].

The data in CDF are classes and objects. For example, XSB, Inc. has a part taxonomy, combining UNSPSC (United Nations Standard Products and Services Code) and Federal INC (Item Name Code) taxonomies, with a total of over 87,000 classes of parts. The main relationships are variants of isa, hasAttr, and allAttr. Joins are used extensively to answer queries about closely related classes, objects, and attributes. Indexing and tabling are heavily used for efficiency. Appropriate join order and demand-driven computation are also important.

An example fact is as follows, indicating that specification 'A-A-1035' in ontology specs has attribute 'MATERIAL' whose value is 'ALUMINUM ALLOY UNS A91035' in material_taxonomy. Terms cid(Identifier, Namespace) represent primitive classes in CDF.

An example rule is as follows, meaning that a part PartNode has attribute 'PART-PROCESS-MATERIAL' whose value is process-material pair (Process, Material) in 'ODE Ontology' if PartNode has attribute 'PROCESS' whose value is Process, and Process has attribute 'PROCESS-MATERIAL' whose value is Material.

An example of indexing is for hasAttr_ATTR, for any ATTR. It is shown below in XSB notation, meaning: Use all symbols of the first argument as index if the first argument is bound, or else use all symbols of the second argument as index if the second argument is bound.

XSB, Inc. has five major ontologies represented in CDF, for parts, materials, etc., with a total of over one million facts and five meta rules. The rules are represented using a Description Logic form—an ontology representation language. The example rule above is an instance of such a rule when interpreted. The indexing used supports different appropriate indices for different join queries.

CDF is used in XSB, Inc.’s ontology-directed classifier (ODC) and extractor (ODE) [Swift and Warren 2012]. ODC uses a modified Bayes classifier to classify item descriptions. For example, it is used quarterly by the U.S. Department of Defense to classify over 80 million part descriptions. ODE extracts attribute-value pairs from classified descriptions to build structured knowledge about items. ODC uses aggregates extensively, and ODE uses string pattern rules.

Enterprise Management—Business Intelligence (BI). BI is a central component of enterprise software. It tracks the performance of an enterprise over time by storing and analyzing historical information recorded through online transaction processing (OLTP), and is then used to help plan future actions of the enterprise. LogicBlox simplifies the hairball of enterprise software technologies by using a Datalog-based language [Green et al. 2012, Aref et al. 2015].

All data are captured as logic relations. This includes not only data as in conventional databases—e.g., sale items and price for a retail application—but also data not in conventional databases—e.g., sales forms, display texts, and submit buttons in a user interface. Joins are used for easily querying interrelated data, as well as for generating user interfaces. Many extensions such as aggregates are also used. For efficiency, exploiting the rich literature of automatic optimizations, especially join processing strategies and incremental maintenance, is of paramount importance.

Using the same Datalog-based language, LogicBlox supports not only BI but also OLTP and prescriptive and predictive analytics. “Today, the LogicBlox platform has matured to the point that it is being used daily in dozens of mission-critical applications in some of the largest enterprises in the world, whose aggregate revenues exceed $300B” [Aref et al. 2015].

Security Policy Frameworks—Core Role-based Access Control (RBAC). RBAC is a framework for controlling user access to resources based on roles. It became an ANSI standard [ANSI INCITS 2004] building on much research during the preceding decade and earlier, e.g., Landwehr et al. [1984], Ferraiolo and Kuhn [1992], Gavrila and Barkley [1998], and Ferraiolo et al. [2001].

Core RBAC defines users, roles, objects, operations, permissions, sessions and a number of relations among these sets; the rest of RBAC adds a hierarchical relation over roles, in hierarchical RBAC, and restricts the number of roles of a user and of a session, in constrained RBAC. Join queries are used for all main system functions, especially the CheckAccess function, review functions, and advanced review functions on the sets and relations. They are easily expressed using logic rules [Barker et al. 2004, Barker and Ferńandez 2006].

Efficient implementations rely on all main optimizations discussed, especially auxiliary maps for indexing and tabling [Liu et al. 2006]. Although the queries are like relational database queries, existing database implementations would be too slow for functions like CheckAccess. Unexpectedly, uniform use of relations and join queries also led to a simplified specification, with unnecessary mappings removed, undesired omissions fixed, and constrained RBAC drastically simplified [Liu and Stoller 2007].

10.4  Recursion and Inductive Analysis

Recursive rules are most basic and essential in relating objects that are an unknown number of relationships apart. They are especially important for problems that may require performing the inference or queries a non-predetermined number of steps, depending on the data.

10.4.1  Recursive Rules and Queries

Given a set of rules, a predicate p depends on a predicate q if p is in the conclusion of a rule, and either q is in a hypothesis of the rule or some predicate r is in a hypothesis of the rule and r depends on q. A given set of rules is recursive if a predicate p in the conclusion of a rule depends on p itself.

For example, the second rule below, as seen in Section 10.2.2, is recursive; the first rule is not recursive; the set of these two rules is recursive, where the first rule is the base case, and the second rule is the recursive case:

In general, recursively asserted relationships can be between objects of any kind, e.g., relatives and friends that are an unknown number of connections apart in social networks, direct and indirect prerequisites of courses in universities, routing paths in computer networks, nesting of parts in products, supply chains in supply and demand networks, transitive role hierarchy relation in RBAC, and repeated delegations in trust management systems.

Recursive queries with restricted negation correspond to least fixed-point computations. For example, in a language that supports least fixed points, the is_ancestor query corresponds to the minimum is_ancestor set below, where, for any sets S and T, S subset T holds iff every element of S is an element of T:

With cyclic predicate dependencies, recursion allows the following restricted extensions to be supported while still providing a unique semantics; there is also the restriction that, for each rule, each variable in the conclusion must also appear in a hypothesis that is a predicate over arguments, as in extensions to join queries:

•  stratified negation, where negation and recursion are separable, i.e., there is no predicate that depends on the negation of itself; and

•  other connectives and predefined relationships in additional conditions, aggregates, and general quantifiers, as in extensions for join queries, when they do not affect the stratification.

Essentially, recursive rules capture an unbounded number of joins, and allow inference and queries by repeatedly applying the rules.

10.4.2  Implementation of Recursive Rules and Queries

Inference and queries using recursive rules can be implemented using while-loops; for-loops with predetermined number of iterations do not suffice because the number of iterations depends on the rules and facts. Each iteration applies the rules in one step, so to speak, until no more relevant facts can be concluded. For example, the is_ancestor query earlier in this section can be implemented as

Each iteration computes the existential quantification in the condition of the whileloop, and picks any witness (X,Y) to add to the result set. It can be extremely inefficient to recompute the condition in each iteration after a new pair is added.

For efficient implementations, all techniques for joins are needed but are also more critical and more complex. In particular, to ensure termination,

•  tabling is critical if relationships form cycles; and

•  demand-driven computation is critical if new objects are created in the cycles.

For the is_ancestor query, each iteration computes the following set, which is a join, plus the last test to ensure that only a new fact is added:

Two general principles underlying the optimizations for efficient implementations are:

1.  incremental computation for expensive relational join operations, with respect to facts that are added in each iteration; and

2.  data structure design for the relations, for efficient retrievals and tests of relevant facts.

For the restricted extensions, iterative computation follows the order of dependencies determined by stratification; additional aggregates, etc. that do not affect the stratification can be handled as described in Section 10.3.2 for computing the join in each iteration.

Efficient implementation techniques for recursive queries and extensions have been studied extensively, e.g., Abiteboul et al. [1995]. Some methods also provide precise complexity guarantees, e.g., McAllester [1999], Ganzinger and McAllester [2001], Liu and Stoller [2009], and Tekle and Liu [2011].

10.4.3  Applications of Recursive Rules and Queries

Recursive rules and queries can capture any complex reachability problem in recursive structures, graphs, and hyper-graphs. Examples are social network analysis based on all kinds of social graphs; program analysis over many kinds of flow and dependence graphs about program control and data values; model checking over labeled transition systems and state machines; routing in electronic data networks, telephone networks, or transportation networks; and security policy analysis and enforcement over trust or delegation relationships.

We describe three example applications below, in the domains of text and natural language processing, program analysis, and distributed security policy frameworks. They all critically depend on the use of recursive rules and efficient implementation techniques, especially tabling and indexing.

Text Processing—Super-tokenizer. Super-tokenizer is an infrastructure tool for text processing that has been used by XSB, Inc.’s ODC and ODE for complex commercial applications [Swift and Warren 2012]. It was also developed originally at XSB, Inc.

Super-tokenizer supports the declaration of complex rewriting rules for token lists. For example, over 65,000 of these rules implement abbreviations and token corrections in ODC and complex pattern-matching rules in ODE for classification and extraction based on combined UNSPSC and Federal INC taxonomies at XSB, Inc. Recursion is used extensively in the super-tokenizer, for text parsing and processing. The implementation uses tabled grammars and trie-based indexing in fundamental ways.

Super-tokenizer is just one particular application that relies on recursive rules for text processing and, more generally, language processing. Indeed, the original application of Prolog, the first and main logic programming language, was natural language processing (NLP) [Pereira and Shieber 2002], and a more recent application in NLP helped the IBM Watson question answering system win the Jeopardy Man vs. Machine Challenge by defeating two former grand champions in 2011 [Lally and Fodor 2011, Lally et al. 2012].

Program Analysis—Pointer Analysis. Pointer analysis statically determines the set of objects that a pointer variable or expression in a program can refer to. It is a fundamental program analysis with wide applications and has been studied extensively, e.g., Hind [2001] and Sridharan et al. [2013]. The studies especially include significantly simplified specifications using Datalog in more recent years, e.g., Smaragdakis and Balatsouras [2015], and powerful systems such as bddbddb [Whaley et al. 2005] and Doop [Bravenboer and Smaragdakis 2009], the latter built using LogicBlox [Green et al. 2012, Aref et al. 2015].

Different kinds of program constructs and analysis results relevant to pointers are relations. Datalog rules capture the analysis directly as recursively defined relations. For example, the well-known Andersen’s pointer analysis for C programs defines a points-to relation based on four kinds of assignment statements [Andersen 1994], leading directly to four Datalog rules [Saha and Ramakrishnan 2005]. Efficient implementation critically depends on tabling, indexing, and demand-driven computation [Saha and Ramakrishnan 2005, Tekle and Liu 2011]. Such techniques were in fact followed by hand to arrive at the first ultra-fast analysis [Heintze and Tardieu 2001b, Heintze and Tardieu 2001a].

Indeed, efficient implementations can be generated from Datalog rules giving much better, more precise complexity guarantees [Liu and Stoller 2009, Tekle and Liu 2011, Tekle and Liu 2016] than the worst-case complexities, e.g., the well-known cubic time for Andersen’s analysis. Such efficient implementation with complexity guarantees can be obtained for program analysis in general [McAllester 1999]. Commercial tools for general program analysis based on Datalog have also been built, e.g., by Semmle based on CodeQuest [Hajiyev et al. 2006].

Security Policy Frameworks—Trust Management (TM). TM is a unified approach to specifying and enforcing security policies in distributed systems [Blaze et al. 1996, Grandison and Sloman 2000, Ruohomaa and Kutvonen 2005]. It has become increasingly important as systems become increasingly interconnected, and logicbased languages have been used increasingly for expressing TM policies [Bonatti 2010], e.g., SD3 [Jim 2001], RT [Li et al. 2002], Binder [DeTreville 2002], Cassandra [Becker and Sewell 2004], and many extensions, e.g., [Becker et al. 2012] and Sultana et al. [2013].

Certification, delegation, authorization, etc. among users, roles, permissions, etc. are relations. Policy rules correspond directly to logic rules. The relations can be transitively defined, yielding recursive rules. For example, one of the earliest TM frameworks, SPKI/SDSI [Ellison et al. 1999], for which various sophisticated methods have been studied, corresponds directly to a few recursive rules [Hristova et al. 2007], and efficient implementations with necessary indexing and tabling were generated automatically.

TM studies have used many variants of Datalog with restricted constraints [Li and Mitchell 2003], not unrestricted negation. A unified framework with efficient implementations is still lacking. For example, based on the requirements of the U.K. National Health Service, a formal electronic health records (EHR) policy was written, as 375 rules in Cassandra [Becker 2005a], heavily recursive. As the largest case study in the TM literature, its implementation was inefficient and incomplete—techniques like indexing were deemed needed but missing [Becker 2005b].

10.5  Constraint and Combinatorial Search

Constraints are the most general form of logic specifications, which easily captures the most challenging problem-solving activities such as planning and resource allocation.

10.5.1  Constraint Satisfaction

A constraint is, in general, a relationship among objects but especially refers to cases when it can be satisfied with different choices of objects and the right choice is not obvious.

For example, the rule below says that X is a winning position if there is a move from X to Y and Y is not a winning position. It states a relationship among objects, but its meaning is not obvious, because the concluding predicates are recursively defined using a negation of the predicate itself.

In general, constraints can capture any real-world or conceptual-world problems, e.g., rules for moves in any game—whether recreational, educational, or otherwise; actions with conditions and effects for any planning activities; participants and resource constraints in scheduling—whether for university courses or manufacturer goods production or hospital surgeries; real-world constraints in engineering design; as well as knowledge and rules for puzzles and brain teasers.

Given constraints may have implications that are not completely explicit. For example, the win rule implies not just the first constraint below, but also the second, by negating the conclusion and hypotheses in the given rule, following the closed-world assumption; the second constraint makes the constraint about not win explicit:

Indeed, with general constraints, objects can be related in all ways using all constructs together with join and recursion: unrestricted negation, other connectives, predefined relationships, aggregates, and general quantifiers in any scope.

However, due to negation in dependency cycles, the meaning of the rules and constraints is not universally agreed on anymore.

•  Well-founded semantics (WFS) gives a single, three-valued model, where relationships that are true or false are intended to be supported from given facts, i.e., well-founded, and the remaining ones are undefined.

•  Stable model semantics (SMS) gives zero or more two-valued models, where each model stays the same, i.e., is stable, when it is used to instantiate all the rules; in other words, applying the rules to each model yields the same model.

For example, for the win example:

•  if there is only one move, move(a,b), not forming a cycle, then WFS and SMS both give that win(b) is false and win(a) is true;

•  if there is only one move, move(a,a), forming a self cycle, then WFS gives that win(a) is undefined, and SMS gives that there is no model; and

•  if there are only two moves, move(a,b) and move(b,a), forming a two-move cycle, then WFS gives that win(a) and win(b) are both undefined, and SMS gives two models: one with win(a) true and win(b) false, and one with the opposite results.

Despite the differences, WFS and SMS can be computed using some shared techniques.

10.5.2  Implementation of Constraint Satisfaction

Constraint solving could in general use straightforward generate-and-test—generate each possible combination of objects for solutions and test whether they satisfy the constraints—but backtracking is generally used, as it is much more efficient.

Backtracking. Backtracking incrementally builds variable assignments for the solutions, and abandons each partial assignment as soon as it determines that the partial assignment cannot be completed to a satisfying solution, going back to try a different value for the last variable assigned; this avoids trying all possible ways of completing those partial assignments or naïvely enumerating all complete assignments.

For example, the win(X) query can basically try a move at each next choice of moves and backtrack to try a different move as soon as the current move fails. Expressed using recursive functions, this corresponds basically to the following:

This backtracking answers the query correctly when the moves do not form a cycle. However, it might not terminate when the moves form a cycle, and the implementation depends on the semantics used. Both WFS and SMS can be computed by using and extending the basic backtracking:

•  WFS computation could track cycles, where executing a call requires recursively making the same call, and infer undefined for those queries that have no execution paths to infer the query result to be true or false.

•  SMS computation could generate possible partial or complete variable assignments, called grounding, and check them, possibly with the help of an external solver like Boolean satisfiability (SAT) solvers or satisfiability modulo theories (SMT) solvers.

For efficient implementations, techniques for join and recursion are critical as before, especially tabling to avoid repeated states in the search space. Additionally, good heuristics for pruning the search space can make drastic performance difference in computing SMS, e.g., as implemented in answer set programming (ASP) solvers.

Backjumping. One particular optimization of backtracking in SMS computation is backjumping. Backtracking always goes back one level in the search tree when all values for a variable have been tested. Backjumping may go back more levels, by realizing that a prefix of the partial assignment can lead to all values for the current variable to fail. This helps prune the search space.

For extensions that include additional constraints, such as integer constraints, as well as aggregates and quantifiers, an efficient solver such as one that supports mixed integer programming (MIP) can be used.

Efficient implementation techniques for constraint solving have been studied extensively, e.g., for ASP solvers [Leone et al. 2006, Gebser et al. 2012].

10.5.3  Applications of Constraint Satisfaction

The generality and power of constraints allow them to be used for all applications described previously, but constraints are particularly important for applications beyond those and that require combinatorial search. Common kinds of search problems include planning and scheduling, resource allocation, games and puzzles, and well-known NP-complete problems such as graph coloring, k-clique, set cover, Hamiltonian cycle, and SAT.

We describe three example applications, in the domains of decision making, resource allocation, and games and puzzles. They all require substantial use of general constraints and efficient constraint solvers exploiting backtracking, backjumping, and other optimizations.

Enterprise Decision Making—Prescriptive Analysis. Prescriptive analysis suggests decision options that lead to optimized future actions. It is an advanced component of enterprise software. For example, for planning purposes, LogicBlox supports prescriptive analysis using the same Datalog-based language as for BI and OLTP [Green et al. 2012, Aref et al. 2015].

The data are objects and relations, same as used for BI, but may include, in particular, costs and other objective measures. Constraints capture restrictions among the objects and relations. When all data values are provided, constraints can simply be checked. When some data values are not provided, different choices for those values can be explored, and values that lead to certain maximum or minimum objective measures may be prescribed for deciding future actions. Efficient implementations can utilize the best constraint solvers based on the kinds of constraints used.

LogicBlox’s integrated solution to decision making based on BI and OLTP has led to significant success. For example, for a Fortune 50 retailer with over $70 billion in revenue and with products available through over 2,000 stores and digital channels, the solution processes 3 terabytes of data on daily, weekly, and monthly cycles, deciding exactly what products to sell in what stores in what time frames; this reduces a multi-year cycle of a challenging task for a large team of merchants and planners to an automatic process and significantly increases profit margins [LogicBlox 2015a].

Resource Allocation—Workforce Management (WFM) in Port of Gioia Tauro. WFM handles activities needed to maintain a productive workforce. The WFM system for automobile logistics in the Port of Gioia Tauro, the largest trans-shipment terminal in the Mediterranean, allocates available personnel of the seaport such that cargo ships mooring in the port are properly handled [Ricca et al. 2012, Leone and Ricca 2015]. It was developed using the DLV system [Leone et al. 2006].

The data include employees of different skills, cargo ships of different sizes and loads, teams and roles to be allocated, and many other objects to be constrained, e.g., workload of employees, heaviness of roles, and contract rules. Constraints include matching of available and required skills, roles, hours, etc., fair distribution of workload, turnover of heavy or dangerous roles, and so on. The constraints are expressed using rules with disjunction in the conclusion, general negation, and aggregates. The DLV system uses backtracking and a suite of efficient implementation techniques.

This WFM system was developed by Exeura s.r.l. and has been adopted by the company ICO BLG operating automobile logistics in the Port of Gioia Tauro [Leone and Ricca 2015], handling every day several ships of different sizes that moor in the port [Ricca et al. 2012].

Games and Puzzles—N-queens. We use a small example in a large class of problems. The n-queens puzzle is the problem of placing n queens on a chessboard of n-by-n squares so that no two queens threaten each other, i.e., no two queens share the same row, column, or diagonal. The problem is old, well-studied, and can be computationally quite expensive [Bell and Stevens 2009].

The allowed placements of queens can be specified as logic rules with constraints. Naïvely enumerating all possible combination of positions and checking the constraints is prohibitively expensive. More efficient solutions use backtracking, and furthermore backjumping, to avoid impossible placement of each next queen as soon as possible. Stronger forms of constraints may also be specified to help prune the search space further [Gebser et al. 2012]. For example, backtracking can solve for one or two scores of queens in an hour, but backjumping and additional constraints help an ASP system like Clingo solve for 5000 queens in 3758.320 seconds of CPU time [Schaub 2014].

Many other games and puzzles can be specified and solved in a similar fashion. Examples are all kinds of crossword puzzles, Sudoku, Knight’s tour, nonograms, magic squares, dominos, coin puzzles, graph coloring, palindromes, among many others, e.g., Demoen et al. [2005], Edmunds [2015], Hett [2015], Kjellerstrand [2015], and Malita [2015].

10.6  Further Extensions, Applications, and Discussion

We discuss additional language extensions and applications, summarize applications based on the key abstractions used, touching on example logic programming systems, and finally put the abstractions into the perspective of programming paradigms.

10.6.1  Extensions

Many additional extensions to logic languages have been studied. Most of them can be viewed as abstractions that capture common patterns in classes of applications, to allow applications to be expressed more easily. Important extensions include:

•  regular-expression paths, a higher-level abstraction for commonly-used linear recursion;

•  updates, for real-world applications that must handle changes;

•  time, for expressing changes over time, as an alternative to supporting updates directly;

•  probability, to capture uncertainty in many challenging applications; and

•  higher-order logic, to support applications that require meta-level reasoning.

We discuss two of the most important extensions below.

Regular-expression paths. A regular-expression path relates two objects using regular expressions and extensions. It allows repeated joins of a binary relation to be expressed more easily and clearly than using recursion; such joins capture reachability and are commonly used. For example, is_ancestor(X,Y), defined in Section 10.4 using two rules including a recursive rule, can now be defined simply as below; it indicates that there are one or more is_parent relationships in a path from X to Y:

This is also higher level than using recursion, because the recursive rule has to pick one of three possible forms below: with is_parent on the left, as seen before; with is_parent on the right; and with both conjuncts using is_ancestor.

Depending on the data, the performance of these forms can be asymptotically different in most implementations.

Regular-expression paths have many important applications including all those in Section 10.4, especially graph queries, with also parametric extensions for more general relations, not just binary relations [de Moor et al. 2003, Liu et al. 2004, Liu and Stoller 2006, Tekle et al. 2010].

Updates. An update, or action, can be expressed as a predicate that captures the update, e.g., by relating the values before and after the update and the change in value. The effect of the update could be taken immediately after the predicate is evaluated, similar to updates in common imperative languages, but this leads to lower-level control flows that are harder to reason about. Instead, it is better for the update to take effect as part of a transaction of multiple updates that together satisfy high-level logic constraints. For example, with this approach, the following rule means that adopted_by_from holds if the updates add_child and del_child and the check adoption_check happen as a transaction:

It ensures at a high level that certain bad things won’t happen, e.g., no child would end with one fewer parent or one more parent than expected. Transaction logic is an extension of logic rules for reasoning about and executing transactional state changes [Bonner and Kifer 1994]. LPS, a Logic-based approach to Production Systems, captures state changes by associating timestamps with facts and events, and this is shown to correspond to updating facts directly [Kowalski and Sadri 2015].

Logic languages with updates have important applications in enterprise software [Green et al. 2012, Aref et al. 2015]. Transaction logic can also help in planning [Basseda et al. 2014].

Additional implementation support can help enhance applications and enable additional applications. A particular helpful feature is to record justification or provenance information during program execution [Roychoudhury et al. 2000, Damásio et al. 2013], providing explanations for how a result was obtained. The recorded information can be queried to improve understanding and help debugging.

10.6.2  Additional Applications

Many additional applications have been developed using logic programming, especially including challenging applications that need recursion and those that furthermore need constraint.

Table 10.2 lists example application areas with example application problems organized based on the main abstractions used. Note that application problems can often be reduced to each other, and many other problems can be reduced to the problems in the table. For example, model checking a property of a system [Clarke et al. 1994, Clarke et al. 1999] can be reduced to planning, where the goal state is a state violating the property specified, so a plan found by a planner corresponds to an error trace found by a model checker [Edelkamp et al. 2014, Cimatti et al. 2014]. Administrative policy analysis also has correspondences to planning, by finding a sequence of actions to achieve the effect of a security breach [Stoller et al. 2011].

Table 10.2 is only a small sample of the application areas, with example application problems or kinds of application problems in those areas. Many more applications have been developed, in many more areas, using systems that support variants of the abstractions with different implementations. Some examples are:

•  XSB has also been used to develop applications for immunization survey [Burton et al. 2012], standardizing data, spend analysis, etc. [XSB 2015], and it is discussed in many publications.¹

•  LogicBlox has also been used to create solutions for predicting consumer demand, optimizing supply chain, etc. [LogicBlox 2015b], and more [Green et al. 2012].

•  ASP systems have been used in bioinformatics, hardware design, music composition, robot control, tourism, and many other application areas [Group 2005, Schaub 2011], including part of a decision support system for the Space Shuttle flight controller [Nogueira et al. 2001, Balduccini and Gelfond 2005].

Table 10.2  Example application areas with example application problems organized based on the main abstractions used

a. Applications discussed in some detail in this chapter.

•  Logic systems have been developed for additional applications, e.g., PRISM [Sato and Kameya 1997] and ProbLog [De Raedt et al. 2007] for probabilistic models; XMC [Ramakrishnan et al. 2000] and ProB [Leuschel and Butler 2008] for verification; and NDlog [Loo et al. 2009], Meld [Ashley-Rollman et al. 2009], Overlog [Alvaro et al. 2010], and Bloom [Berkeley Orders of Magnitude 2013] for network and distributed algorithms.

Languages and systems with more powerful features such as constraints for general applications are often also used in less challenging application areas such as those that need only join queries. For example, DLV has also been used in ontology management [Ricca et al. 2009].

10.6.3  Additional Discussion on Abstractions

We give an overview of the main abstractions in the larger picture of programming paradigms, to help put the kinds of applications supported into broader perspective.

The three main abstractions—join, recursion, and constraint—correspond generally to more declarative programming paradigms. Each is best known in its corresponding main programming community.

•  Join in database programming. Database systems have join at the core but support restricted recursion and constraints in practice.

•  Recursion in functional programming. Functional languages have recursion at the core but do not support high-level join or constraints.

•  Constraint in logic programming. Logic engines support both join and recursion at the core, and have increasingly supported constraints at the core as well.

The additional extensions help further raise the level of abstraction and broaden the programming paradigms supported.

•  Regular-expression paths raise the level of abstraction over lower-level linear recursion.

•  Updates, or actions, are the core of imperative programming; they help capture real-world operations even when not used in low-level algorithmic steps.

•  Time, probability, higher-order logic, and many other features correspond to additional arguments, attributes, or abstractions about objects and relationships.

One main paradigm not yet discussed is object-oriented programming. Orthogonal to data and control abstractions, objects in common object-oriented languages provide a kind of module abstraction, encapsulating both data structures and control structures in objects and classes. Similar abstractions have indeed been added to logic languages as well. For example, F-logic extends traditional logic programming with objects [Kifer et al. 1995] and is supported in Flora-2 [Kifer et al. 2014]; it was also the basis of a highly scalable commercial system, Ontobroker [Semafora 2012], and a recent industry suite, Ergo [Grosof et al. 2015]. For another example, ASP has been extended with object constructs in OntoDLV [Ricca et al. 2009].

Finally, building practical applications requires powerful libraries and interfaces for many standard functionalities. Many logic programming systems provide various such libraries. For example, SWI-Prolog has libraries for constraint logic programming, multithreading, interface to databases, GUI, a web server, etc., as well as development tools and extensive documentation.

10.7  Related Literature and Future Work

There are many overview books and articles about logic programming in general and applications of logic programming in particular. This chapter differs from prior works by studying the key abstractions and their implementations as the driving force underlying vastly different application problems and application areas.

Kowalski [2014] provides an extensive overview of the development of logic programming. It describes the historical root of logic programming, starting from resolution theorem-proving; the procedural interpretation and semantics of rules with no negated hypotheses, called Horn clause programs; negation as failure, including completion semantics, stratification, well-founded semantics, stable model semantics, and ASP; as well as logic programming involving abduction, constraints, and argumentation. It focuses on three important issues: logic programming as theorem proving vs. model generation, with declarative vs. procedural semantics, and using top-down vs. bottom-up computation. Our description of abstractions and implementations aims to separate declarative semantics from procedural implementations.

Other overviews and surveys about logic programming in general include some that cover a collection of topics together and some that survey different topics separately. Example collections discuss the first 25 years of logic programming from 1974 [Apt et al. 1999] and the first 25 years of the Italian Association of Logic Programming from 1985 [Dovier and Pontelli 2010]. Example topics surveyed separately include logic programming semantics [Fitting 2002], complexity and expressive power [Dantsin et al. 2001], constraints [Jaffar and Maher 1994], ASP and DLV [Grasso et al. 2013], deductive databases [Ceri et al. 1990, Abiteboul et al. 1995, Ramakrishnan and Ullman 1995, Minker et al. 2014], and many more. Our description of abstractions and implementations is only a highly distilled overview of the core topics.

Overviews and surveys about logic programming applications in particular are spread across many forums. Example survey articles include an early article on Prolog applications [Roth 1993], DLV applications [Grasso et al. 2009, Grasso et al. 2011, Leone and Ricca 2015], applications in Italy [Dal Palù and Torroni 2010], emerging applications [Huang et al. 2011], and a dedicated workshop AppLP—Applications of Logic Programming [Warren and Liu 2017]. For example, the early article [Roth 1993] describes six striking practical applications of Prolog that replaced and drastically improved over systems written previously using Fortran, C++, and Lisp. Example collections of applications on the Web include one at TU Wien [Group 2005], one by Schaub [Schaub 2011], and some of the problems in various competitions, e.g., as described by Gebser et al. [2017]. We try to view the applications by the abstractions and implementations used, so as to not be distracted by specific details of very different applications.

There are also many articles on specific applications or specific classes of applications. Examples of the former include team building [Ricca et al. 2012], program pointer analysis [Smaragdakis and Balatsouras 2015], and others discussed in this chapter. Examples of the latter include applications in software engineering [Ciancarini and Sterling 1995], DLV applications in knowledge management [Grasso et al. 2009], and IDP applications in data mining and machine learning [Bruynooghe et al. 2014]. We used a number of such specific applications as examples and described some of them in slightly more detail to illustrate the common technical core in addition to the applications per se.

Directions for Future Work

There are several main areas for future study: (1) more high-level abstractions that are completely declarative; (2) more efficient implementations with complexity guarantees; and (3) more unified and standardized languages and frameworks with rich libraries. These will help many more applications to be created in increasingly complex problem domains.

Acknowledgments

I would like to thank David S. Warren for his encouragement over the years at Stony Brook, and his patient and stimulating explanations about logic programming in general and XSB implementation in particular. I am grateful to Molham Aref, Francesco Ricca, and David Warren for helpful suggestions and additional information about applications using LogicBlox, DLV, and XSB, respectively. I thank Molham Aref and others at LogicBlox, Jon Brandvein, Christopher Kane, Michael Kifer, Bob Kowalski, Bo Lin, Francesco Ricca, Scott Stoller, Tuncay Tekle, David Warren, Neng-Fa Zhou, and anonymous reviewers for helpful comments on drafts of this chapter. This work was supported in part by NSF under grants CCF-0964196, CCF-1248184, CCF-1414078, and IIS-1447549; and ONR under grant N00014-15-1-2208.

References

S. Abiteboul, R. Hull, and V. Vianu. 1995. Foundations of Databases: The Logical Level. Addison-Wesley. 534, 546

P. Alvaro, T. Condie, N. Conway, J. Hellerstein, and R. Sears. 2010. I do declare: Consensus in a logic language. ACM SIGOPS Operating Systems Review, 43(4): 25–30. DOI: 10.1145/1713254.1713261. 544

L. O. Andersen. 1994. Program Analysis and Specialization for the C Programming Language. Ph.D. thesis, DIKU, University of Copenhagen. http://www.diku.dk/forskning/topps/bibliography/1994.html. 535

ANSI INCITS, February 2004. Role-Based Access Control. ANSI INCITS 359-2004, American National Standards Institute, International Committee for Information Technology Standards. 529, 531

K. R. Apt, D. S. Warren, and M. Truszczynski, editors. 1999. The Logic Programming Paradigm: A 25-Year Perspective. Springer. 546

M. Aref, B. ten Cate, T. J. Green, B. Kimelfeld, D. Olteanu, E. Pasalic, T. L. Veldhuizen, and G. Washburn. 2015. Design and implementation of the LogicBlox system. In Proceedings of the 2015 ACM SIGMOD International Conference on Management of Data, pp. 1371–1382. DOI: 10.1145/2723372.2742796. 531, 535, 539, 542

M. P. Ashley-Rollman, P. Lee, S. C. Goldstein, P. Pillai, and J. D. Campbell. 2009. A language for large ensembles of independently executing nodes. In Proceedings of the 25th International Conference on Logic Programming, pp. 265–280. Springer. DOI: 10.1007/978-3-642-02846-5_24. 544

M. Balduccini and M. Gelfond. 2005. Model-based reasoning for complex flight systems. In Proceedings of the 5th AIAA Conference on Aviation, Technology, Integration, and Operations. 543

S. Barker and M. Ferńandez. 2006. Term rewriting for access control. In Data and Applications Security XX, pp. 179–193. Springer. DOI: 10.1007/11805588_13. 532

S. Barker, M. Leuschel, and M. Varea. 2004. Efficient and flexible access control via logic program specialisation. In Proceedings of the 2004 ACM SIGPLAN Symposium on Partial Evaluation and Semantics-Based Program Manipulation, pp. 190–199. DOI: 10.1145/1014007.1014026. 532

R. Basseda, M. Kifer, and A. J. Bonner. 2014. Planning with transaction logic. In Proceedings of the 8th International Conference on Web Reasoning and Rule Systems, pp. 29–44. Springer. DOI: 10.1007/978-3-319-11113-1_3. 542

M. Y. Becker. 2005a. A formal security policy for an NHS electronic health record service. Technical Report UCAM-CL-TR-628, Computer Laboratory, University of Cambridge. http://www.cl.cam.ac.uk/TechReports/UCAM-CL-TR-628.html. 536

M. Y. Becker. 2005b. Cassandra: Flexible trust management and its application to electronic health records. Ph.D. dissertation, Technical Report UCAM-CL-TR-648, Computer Laboratory, University of Cambridge. http://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-648.html. 536

M. Y. Becker and P. Sewell. 2004. Cassandra: Flexible trust management, applied to electronic health records. In Proceedings of the 17th IEEE Computer Security Foundations Workshop, pp. 139–154. IEEE CS Press. DOI: 10.1109/CSFW.2004.7. 536

M. Y. Becker, A. Russo, and N. Sultana. 2012. Foundations of logic-based trust management. In Proceedings of the 2012 IEEE Symposium on Security and Privacy, pp. 161–175. IEEE CS Press. DOI: 10.1109/SP.2012.20. 536

J. Bell and B. Stevens. 2009. A survey of known results and research areas for n-queens. Discrete Mathematics, 309(1): 1–31. DOI: 10.1016/j.disc.2007.12.043. 540

Berkeley Orders of Magnitude. 2013. Bloom Programming Language. http://www.bloom-lang.net. Lastest release April 23, 2013. Accessed January 14, 2017. 544

M. Blaze, J. Feigenbaum, and J. Lacy. 1996. Decentralized trust management. In Proceedings of the 1996 IEEE Symposium on Security and Privacy, pp. 164–173. DOI: 10.1109/SECPRI.1996.502679. 535

P. A. Bonatti. 2010. Datalog for security, privacy and trust. In Proceedings of the 1st International Conference on Datalog Reloaded, pp. 21–36. Springer. DOI: 10.1007/978-3-642-24206-9_2. 536

A. J. Bonner and M. Kifer. 1994. An overview of transaction logic. Theoretical Computer Science, 133(2): 205–265. DOI: 10.1016/0304-3975(94)90190-2. 542

M. Bravenboer and Y. Smaragdakis. 2009. Strictly declarative specification of sophisticated points-to analyses. In Proceedings of the 24rd ACM SIGPLAN Conference on Object Oriented Programming Systems Languages and Applications, pp. 243–262. DOI: 10.1145/1640089.1640108. 535

M. Bruynooghe, H. Blockeel, B. Bogaerts, B. De Cat, S. De Pooter, J. Jansen, A. Labarre, J. Ramon, M. Denecker, and S. Verwer. 2014. Predicate logic as a modeling language: Modeling and solving some machine learning and data mining problems with IDP3. Theory and Practice of Logic Programming, pp. 1–35. DOI: 10.1017/S147106841400009X. 547

A. Burton, R. Kowalski, M. Gacic-Dobo, R. Karimov, and D. Brown. October 2012. A formal representation of the WHO and UNICEF estimates of national immunization coverage: A computational logic approach. PLOS ONE. DOI: 10.1371/journal.pone.0047806. 543

S. Ceri, G. Gottlob, and L. Tanca. 1990. Logic Programming and Databases. Springer. 546

P. Ciancarini and L. Sterling. 1995. Report on the Workshop: Applications of Logic Programming in Software Engineering. The Knowledge Engineering Review, 10(01): 97–100. DOI: 10.1017/S0269888900007335. 547

A. Cimatti, S. Edelkamp, M. Fox, and E. Plaku, November 23–28, 2014. Dagstuhl Seminar 14482: Automated Planning and Model Checking. http://www.dagstuhl.de/no_cache/en/program/calendar/semhp/?semnr=14482. Accessed June 6, 2015. 543

E. M. Clarke, O. Grumberg, and D. E. Long. 1994. Model checking and abstraction. ACM Transactions on Programming Languages and Systems, 16(5): 1512–1542. DOI: 10.1145/186025.186051. 543

E. M. Clarke, Jr., O. Grumberg, and D. A. Peled. 1999. Model Checking. MIT Press. 543

A. Dal Palù and P. Torroni. 2010. 25 years of applications of logic programming in Italy. In A 25-Year Perspective on Logic Programming, pp. 300–328. Springer. DOI: 10.1007/978-3-642-14309-0_14. 547

C. V. Damásio, A. Analyti, and G. Antoniou. 2013. Justifications for logic programming. In Proceedings of the 12th International Conference on Logic Programming and Nonmonotonic Reasoning, pp. 530–542. Springer. DOI: 10.1007/978-3-642-40564-8_53. 543

E. Dantsin, T. Eiter, G. Gottlob, and A. Voronkov. 2001. Complexity and expressive power of logic programming. ACM Computing Surveys, 33(3): 374–425. DOI: 10.1145/502807.502810. 546

O. de Moor, D. Lacey, and E. V. Wyk. 2003. Universal regular path queries. Higher-Order and Symbolic Computation, 16(1–2): 15–35. DOI: 10.1023/A:1023063919574. 542

L. De Raedt, A. Kimmig, and H. Toivonen. 2007. ProbLog: A probabilistic Prolog and its application in link discovery. In Proceedings of the 20th International Joint Conference on Artifical Intelligence, pp. 2468–2473. Morgan Kaufman. 544

B. Demoen, P.-L. Nguyen, T. Schrijvers, and R. Troncon, 2005. The first 10 Prolog programming contests. http://dtai.cs.kuleuven.be/ppcbook/. Accessed May 20, 2015. 541

M. Denecker and E. Ternovska. 2008. A logic of nonmonotone inductive definitions. ACM Transactions on Computational Logic, 9(2): 14. DOI: 10.1145/1342991.1342998. 525

J. DeTreville. 2002. Binder, a logic-based security language. In Proceedings of the 2002 IEEE Symposium on Security and Privacy, pp. 105–113. IEEE CS Press. DOI: 10.1109/SECPRI.2002.1004365. 536

A. Dovier and E. Pontelli, editors 2010. A 25-year Perspective on Logic Programming: Achievements of the Italian Association for Logic Programming, GULP. Springer. 546

S. Edelkamp, D. Magazzeni, and E. Plaku. June 23, 2014. Workshop on Model Checking and Automated Planning (MOCHAP’14), Portsmouth, NH. http://icaps14.icapsconference.org/workshops_tutorials/mochap.html. Accessed June 6, 2015. 543

D. Edmunds, 2015. Learning constraint logic programming—finite domains with logic puzzles. http://brownbuffalo.sourceforge.net/. Accessed May 20, 2015. 541

C. Ellison, B. Frantz, B. Lampson, R. L. Rivest, B. Thomas, and T. Ylonen, September 1999. RFC 2693: SPKI Certificate Theory. http://www.ietf.org/rfc/rfc2693.txt. Accessed June 4, 2015. 536

D. Ferraiolo and R. Kuhn. 1992. Role-based access control. In Proceedings of the 15th NIST-NSA National Computer Security Conference, pp. 554–563. Baltimore, MD. 531

D. F. Ferraiolo, R. Sandhu, S. Gavrila, D. R. Kuhn, and R. Chandramouli. 2001. Proposed NIST standard for role-based access control. ACM Transactions on Information and Systems Security, 4(3): 224–274. DOI: 10.1145/501978.501980. 531

M. Fitting. 2002. Fixpoint semantics for logic programming: A survey. Theoretical Computer Science, 278(1): 25–51. DOI: 10.1016/S0304-3975(00)00330-3. 546

H. Ganzinger and D. A. McAllester. 2001. A new meta-complexity theorem for bottom-up logic programs. In Proceedings of the 1st International Joint Conference on Automated Reasoning, pp. 514–528. Springer. DOI: 10.1007/3-540-45744-5_44. 534

A. Gavrila and J. Barkley. 1998. Formal specification for RBAC user/role and role relationship management. In Proceedings of the 3rd ACM Workshop on Role Based Access Control, pp. 81–90. DOI: 10.1145/286884.286902. 531

M. Gebser, R. Kaminski, B. Kaufmann, and T. Schaub. 2012. Answer Set Solving in Practice. Synthesis Lectures on Artificial Intelligence and Machine Learning. Morgan & Claypool. DOI: 10.2200/S00457ED1V01Y201211AIM019. 539, 540

M. Gebser, M. Maratea, and F. Ricca. 2017. The sixth answer set programming competition. Journal of Artificial Intelligence Research, 60: 41–95. DOI: 10.1613/jair.5373. 547

M. Gelfond and V. Lifschitz. 1988. The stable model semantics for logic programming. In Proceedings of the 5th International Conference and Symposium on Logic Programming, pp. 1070–1080. MIT Press. 525

A. S. Gomes, J. J. Alferes, and T. Swift. 2010. Implementing query answering for hybrid MKNF knowledge bases. In Proceedings of the 12th International Conference on Practical Aspects of Declarative Languages, pp. 25–39. Springer. DOI: 10.1007/978-3-642-11503-5_4. 530

T. Grandison and M. Sloman. 2000. A survey of trust in Internet applications. IEEE Communications Surveys and Tutorials, 3(4): 2–16. DOI: 10.1109/COMST.2000.5340804. 536

G. Grasso, S. Iiritano, N. Leone, and F. Ricca. 2009. Some DLV applications for knowledge management. In E. Erdem, F. Lin, and T. Schaub, editors, Proceedings of the 10th International Conference on Logic Programming and Nonmonotonic Reasoning, pp. 591–597. Springer. DOI: 10.1007/978-3-642-04238-6_63. 547

G. Grasso, N. Leone, M. Manna, and F. Ricca. 2011. ASP at work: Spin-off and applications of the DLV system. In Logic Programming, Knowledge Representation, and Nonmonotonic Reasoning—Essays Dedicated to Michael Gelfond on the Occasion of His 65th Birthday, pp. 432–451. Springer. DOI: 10.1007/978-3-642-20832-4_27. 547

G. Grasso, N. Leone, and F. Ricca. 2013. Answer set programming: Language, applications and development tools. In Proceedings of the 7th International Conference on Web Reasoning and Rule Systems, pp. 19–34. Springer. DOI: 10.1007/978-3-642-39666-3_3. 546

T. J. Green, M. Aref, and G. Karvounarakis. 2012. LogicBlox, platform and language: A tutorial. In Proceedings of the 2nd International Conference on Datalog in Academia and Industry, Datalog 2.0, pp. 1–8. Springer. DOI: 10.1007/978-3-642-32925-8_1. 531, 535, 539, 542, 543

B. Grosof, J. Bloomfield, P. Fodor, M. Kifer, I. Grosof, M. Calejo, and T. Swift. 2015. Automated decision support for financial regulatory/policy compliance, using textual Rulelog. In Proceedings of the RuleML 2015 Challenge, the Special Track on Rule-based Recommender Systems for the Web of Data, the Special Industry Track and the RuleML 2015 Doctoral Consortium. http://ceur-ws.org/Vol-1417/. 546

T. W. K.-B. S. Group, Aug. 2005. WP5 report: Model applications and proofs-of-concept. http://www.kr.tuwien.ac.at/research/projects/WASP/report.pdf. Accessed May 20, 2015. 543, 547

E. Hajiyev, M. Verbaere, and O. D. Moor. 2006. CodeQuest: Scalable source code queries with Datalog. In Proceedings of the 20th European Conference on Object-Oriented Programming, pp. 2–27. Springer. DOI: 10.1007/11785477_2. 535

N. Heintze and O. Tardieu. 2001a. Demand-driven pointer analysis. In Proceedings of the ACM SIGPLAN 2001 Conference on Programming Language Design and Implementation, pp. 24–34. DOI: 10.1145/381694.378802. 535

N. Heintze and O. Tardieu. 2001b. Ultra-fast aliasing analysis using CLA: A million lines of C code in a second. In Proceedings of the ACM SIGPLAN 2001 Conference on Programming Language Design and Implementation, pp. 254–263. DOI: 10.1145/378795.378855. 535

W. Hett, 2015. Prolog Site—Prolog Problems. http://sites.google.com/site/prologsite/prologproblems/. Accessed May 28, 2015. 541

M. Hind. 2001. Pointer analysis: Haven’t we solved this problem yet? In Proceedings of the 2001 ACM SIGPLAN-SIGSOFT Workshop on Program Analysis for Software Tools and Engineering, pp. 54–61. DOI: 10.1145/379605.379665. 535

P. Hou, B. De Cat, and M. Denecker. 2010. FO(FD): Extending classical logic with rule-based fixpoint definitions. Theory and Practice of Logic Programming, 10(4–6): 581–596. DOI: 10.1017/S1471068410000293. 525

K. Hristova, K. T. Tekle, and Y. A. Liu. 2007. Efficient trust management policy analysis from rules. In Proceedings of the 9th ACM SIGPLAN International Conference on Principles and Practice of Declarative Programming, pp. 211–220. DOI: 10.1145/1273920.1273950. 536

S. S. Huang, T. J. Green, and B. T. Loo. 2011. Datalog and emerging applications: An interactive tutorial. In Proceedings of the 2011 ACM SIGMOD International Conference on Management of data, pp. 1213–1216. DOI: 10.1145/1989323.1989456. 547

Y. E. Ioannidis. March 1996. Query optimization. ACM Computing Surveys, 28(1): 121–123. 529

J. Jaffar and M. J. Maher. 1994. Constraint logic programming: A survey. Journal of Logic Programming, 19: 503–581. DOI: 10.1016/0743-1066(94)90033-7. 546

T. Jim. 2001. SD3: A trust management system with certified evaluation. In Proceedings of the 2001 IEEE Symposium on Security and Privacy, pp. 106–115. IEEE CS Press. DOI: 10.1109/SECPRI.2001.924291. 536

M. Kifer, G. Lausen, and J. Wu. 1995. Logical foundations of object-oriented and framebased languages. Journal of the ACM, 42(4): 741–843. DOI: 10.1145/210332.210335. 545

M. Kifer, A. Bernstein, and P. M. Lewis. 2006. Database Systems: An Application Oriented Approach, Complete Version, 2nd. Addison-Wesley. 529

M. Kifer, G. Yang, H. Wan, and C. Zhao. July 2014. Flora-2: User’s Manual Version 1.0. Stony Brook University. http://flora.sourceforge.net/. Accessed June 6, 2015. 545

H. Kjellerstrand, 2015. My Picat page. http://www.hakank.org/picat/. Accessed May 29, 2015. 541

R. Kowalski. 2014. Logic programming. In D. M. Gabbay, J. H. Siekmann, and J. Woods, editors, Computational Logic, vol. 9 of Handbook of the History of Logic, pp. 523–569. Elsevier. 546

R. Kowalski and F. Sadri. 2015. Reactive computing as model generation. New Generation Computing, 33(1): 33–67. DOI: 10.1007/s00354-015-0103-z. 542

A. Lally and P. Fodor. March 31, 2011. Natural language processing with Prolog in the IBM Watson system. Association for Logic Programming (ALP) Issue, Featured Articles. http://www.cs.nmsu.edu/ALP/2011/03/natural-language-processing-with-prolog-in-the-ibm-watsonsystem/. Accessed April 23, 2015. 535

A. Lally, J. M. Prager, M. C. McCord, B. K. Boguraev, S. Patwardhan, J. Fan, P. Fodor, and J. Chu-Carroll. 2012. Question analysis: How Watson reads a clue. IBM Journal of Research and Development, 56(3/4): 2:1–2:13. DOI: 10.1147/JRD.2012.2184637. 535

C. E. Landwehr, C. L. Heitmeyer, and J. McLean. 1984. A security model for military message systems. ACM Transactions on Computer Systems, 2(3): 198–222. DOI: 10.1145/989.991. 531

N. Leone and F. Ricca. 2015. Answer Set Programming: A tour from the basics to advanced development tools and industrial applications. In Proceedings of the 11th International Summer School on Reasoning Web, pp. 308–326. Springer. DOI: 10.1007/978-3-319-21768-0_10. 540, 547

N. Leone, G. Pfeifer, W. Faber, T. Eiter, G. Gottlob, S. Perri, and F. Scarcello. July 2006. The DLV system for knowledge representation and reasoning. ACM Transactions on Computational Logic, 7(3): 499–562. DOI: 10.1145/1149114.1149117. 539, 540

M. Leuschel and M. Butler. 2008. ProB: An automated analysis toolset for the B method. International Journal on Software Tools for Technology Transfer, 10(2): 185–203. DOI: 10.1007/s10009-007-0063-9. 544

M. Ley. 2002. The DBLP computer science bibliography: Evolution, research issues, perspectives. In Proceedings of the 9th International Symposium on String Processing and Information Retrieval, pp. 1–10. Springer. DOI: 10.1007/3-540-45735-6_1. 529

N. Li and J. C. Mitchell. 2003. Datalog with constraints: A foundation for trust management languages. In Proceedings of the 5th International Symposium on Practical Aspects of Declarative Languages, pp. 58–73. Springer. DOI: 10.1007/3-540-36388-2_6. 536

N. Li, J. C. Mitchell, and W. H. Winsborough. 2002. Design of a role-based trust-management framework. In IEEE Symposium on Security and Privacy, pp. 114–130. DOI: 10.1109/SECPRI.2002.1004366. 536

Y. A. Liu and S. D. Stoller. 2006. Querying complex graphs. In Proceedings of the 8th International Symposium on Practical Aspects of Declarative Languages, pp. 199–214. Springer. DOI: 10.1007/11603023_14. 542

Y. A. Liu and S. D. Stoller. 2007. Role-based access control: A corrected and simplified specification. In Department of Defense Sponsored Information Security Research: New Methods for Protecting Against Cyber Threats, pp. 425–439. Wiley. 532

Y. A. Liu and S. D. Stoller. 2009. From Datalog rules to efficient programs with time and space guarantees. ACM Transactions on Programming Languages and Systems, 31(6): 1–38. 534

Y. A. Liu and S. D. Stoller. Jan. 2018. Founded semantics and constraint semantics of logic rules. In International Symposium on Logical Foundations of Computer Science, vol. 10703 of Lecture Notes in Computer Science, pp. 221–241. Springer. DOI: 10.1007/978-3-319-72056-2_14. 525

Y. A. Liu, T. Rothamel, F. Yu, S. Stoller, and N. Hu. 2004. Parametric regular path queries. In Proceedings of the ACM SIGPLAN 2004 Conference on Programming Language Design and Implementation, pp. 219–230. DOI: 10.1145/996893.996868. 542

Y. A. Liu, C. Wang, M. Gorbovitski, T. Rothamel, Y. Cheng, Y. Zhao, and J. Zhang. 2006. Core role-based access control: Efficient implementations by transformations. In Proceedings of the ACM SIGPLAN 2006 Workshop on Partial Evaluation and Program Manipulation, pp. 112–120. DOI: 10.1145/1111542.1111562. 532

Y. A. Liu, J. Brandvein, S. D. Stoller, and B. Lin. 2016. Demand-driven incremental object queries. In Proceedings of the 18th International Symposium on Principles and Practice of Declarative Programming, pp. 228–241. ACM Press. DOI: 10.1145/2967973.2968610. 527, 529

LogicBlox. 2015a. Assortment planning and management. http://www.logicblox.com/solution-four.html. Accessed May 18, 2015. 540

LogicBlox. 2015b. Solutions. http://www.logicblox.com/solutions.html. Accessed May 18, 2015. 543

B. T. Loo, T. Condie, M. Garofalakis, D. E. Gay, J. M. Hellerstein, P. Maniatis, R. Ramakrishnan, T. Roscoe, and I. Stoica. 2009. Declarative networking. Communications of the ACM, 52: 87–95. DOI: 10.1145/1592761.1592785. 544

M. Malita, 2015. Logic puzzles in Prolog. http://www.anselm.edu/internet/compsci/faculty_staff/mmalita/HOMEPAGE/logic/index.html. Accessed May 28, 2015. 541

D. A. McAllester. 1999. On the complexity analysis of static analyses. In Proceedings of the 6th International Static Analysis Symposium, pp. 312–329. Springer. DOI: 10.1007/3-540-48294-6_21. 534, 535

J. Minker, D. Seipel, and C. Zaniolo. 2014. Logic and databases: History of deductive databases. In D. Gabbay, J. Siekmann, and J. Woods, editors, Handbook of Computational Logic, chap. 17, pp. 571–628. North-Holland. DOI: 10.1016/B978-0-444-51624-4.50013-7. 546

M. Nogueira, M. Balduccini, M. Gelfond, R. Watson, and M. Barry. 2001. An A-Prolog decision support system for the Space Shuttle. In Practical Aspects of Declarative Languages, pp. 169–183. Springer. DOI: 10.1007/3-540-45241-9_12. 543

F. C. Pereira and S. M. Shieber. 2002. Prolog and Natural-Language Analysis. Microtome Publishing. http://mtome.com/Publications/PNLA/pnla.html. Revision of October 5, 2005. 535

T. C. Przymusinski. 1994. Well-founded and stationary models of logic programs. Annals of Mathematics and Artificial Intelligence, 12(3): 141–187. DOI: 10.1007/BF01530784. 525

C. Ramakrishnan, I. Ramakrishnan, S. A. Smolka, Y. Dong, X. Du, A. Roychoudhury, and V. Venkatakrishnan. 2000. XMC: A logic-programming-based verification toolset. In Proceedings of the 12th International Conference on Computer Aided Verification, pp. 576–580. Springer. DOI: 10.1007/10722167_48. 544

R. Ramakrishnan and J. D. Ullman. 1995. A survey of deductive database systems. Journal of Logic Programming, 23(2): 125–149. DOI: 10.1016/0743-1066(94)00039-9. 546

F. Ricca, L. Gallucci, R. Schindlauer, T. Dell’Armi, G. Grasso, and N. Leone. 2009. OntoDLV: An ASP-based system for enterprise ontologies. Journal of Logic and Computation, 19(4): 643–670. DOI: 10.1093/logcom/exn042. 545, 546

F. Ricca, G. Grasso, M. Alviano, M. Manna, V. Lio, S. Iiritano, and N. Leone. 2012. Teambuilding with answer set programming in the Gioia-Tauro Seaport. Theory and Practice of Logic Programming, 12(3): 361–381. DOI: 10.1017/S147106841100007X. 540, 547

A. Roth. 1993. The practical application of Prolog. AI Expert, 8: 24–24. In Dr. Dobb’s, http://www.drdobbs.com/parallel/the-practical-application-of-prolog/184405220, December 10, 2002. Accessed June 6, 2015. 547

T. Rothamel and Y. A. Liu. 2007. Efficient implementation of tuple pattern based retrieval. In Proceedings of the ACM SIGPLAN 2007 Workshop on Partial Evaluation and Program Manipulation, pp. 81–90. DOI: 10.1145/1244381.1244394. 527

A. Roychoudhury, C. Ramakrishnan, and I. Ramakrishnan. 2000. Justifying proofs using memo tables. In Proceedings of the 2nd ACM SIGPLAN International Conference on Principles and Practice of Declarative Programming, pp. 178–189. DOI: 10.1145/351268.351290. 543

S. Ruohomaa and L. Kutvonen. 2005. Trust management survey. In Proceedings of the Third international conference on Trust Management, pp. 77–92. Springer. DOI: 10.1007/11429760_6. 536

D. Saha and C. R. Ramakrishnan. 2005. Incremental and demand-driven points-to analysis using logic programming. In Proceedings of the 7th ACM SIGPLAN International Conference on Principles and Practice of Declarative Programming, pp. 117–128. DOI: 10.1145/1069774.1069785. 535

T. Sato and Y. Kameya. 1997. PRISM: A language for symbolic-statistical modeling. In Proceedings of the 15th International Joint Conference on Artifical Intelligence-Vol. 2, pp. 1330–1335. Morgan Kaufman. 544

T. Schaub, March 2011. Collection on Answer Set Programming (ASP) and more. http://www.cs.uni-potsdam.de/~torsten/asp/. Accessed May 18, 2015. 543, 547

T. Schaub, Dec. 23, 2014. Answer set solving in practice. http://www.cs.uni-potsdam.de/~torsten/Potassco/Slides/asp.pdf. Accessed May 20, 2015. 541

Semafora, 2012. Semantic infrastructure: OntoBroker. http://www.semafora-systems.com/en/products/ontobroker/. Accessed May 18, 2015. 545, 546

Y. Smaragdakis and G. Balatsouras. 2015. Pointer analysis. Foundations and Trends in Programming Languages, 2(1): 1–69. DOI: 10.1561/2500000014. 535, 547

M. Sridharan, S. Chandra, J. Dolby, S. J. Fink, and E. Yahav. 2013. Alias analysis for object-oriented programs. In Aliasing in Object-Oriented Programming: Types, Analysis and Verification, pp. 196–232. Springer. DOI: 10.1007/978-3-642-36946-9_8. 535

S. D. Stoller, P. Yang, M. I. Gofman, and C. Ramakrishnan. 2011. Symbolic reachability analysis for parameterized administrative role-based access control. Computers & Security, 30(2): 148–164. DOI: 10.1016/j.cose.2010.08.002. 543

N. Sultana, M. Y. Becker, and M. Kohlweiss. 2013. Selective disclosure in Datalog-based trust management. In Proceedings of the 9th International Workshop on Security and Trust Management, pp. 160–175. Springer. DOI: 10.1007/978-3-642-41098-7_1. 536

T. Swift and D. S. Warren. 2012. XSB: Extending Prolog with tabled logic programming. Theory and Practice of Logic Programming, 12(1-2): 157–187. DOI: 10.1017/S1471068411000500. 531, 534

T. Swift, D. S. Warren, et al. June 2014. The XSB System Version 3.5.x. http://xsb.sourceforge.net. Accessed June 6, 2015. 530

K. T. Tekle and Y. A. Liu. 2011. More efficient Datalog queries: Subsumptive tabling beats magic sets. In Proceedings of the 2011 ACM SIGMOD International Conference on Management of Data, pp. 661–672. DOI: 10.1145/1989323.1989393. 534, 535

K. T. Tekle and Y. A. Liu. 2016. Precise complexity guarantees for pointer analysis via Datalog with extensions. Theory and Practice of Logic Programming, 16(5–6): 916–932. 535

K. T. Tekle, M. Gorbovitski, and Y. A. Liu. 2010. Graph queries through Datalog optimizations. In Proceedings of the 12th International ACM SIGPLAN Symposium on Principles and Practice of Declarative Programming, pp. 25–34. DOI: 10.1145/1836089.1836093. 542

A. Van Gelder. 1993. The alternating fixpoint of logic programs with negation. Journal of Computer and System Sciences, 47(1): 185–221. DOI: 10.1016/0022-0000(93)90024-Q. 525

A. Van Gelder, K. Ross, and J. S. Schlipf. 1991. The well-founded semantics for general logic programs. Journal of the ACM, 38(3): 620–650. DOI: 10.1145/116825.116838. 525

D. S. Warren and Y. A. Liu. Apr. 2017. AppLP: A dialogue on applications of logic programming. Computing Research Repository, arXiv:1704.02375 [cs.PL]. 547

J. Whaley, D. Avots, M. Carbin, and M. S. Lam. 2005. Using Datalog with binary decision diagrams for program analysis. In Programming Languages and Systems, pp. 97–118. Springer. DOI: 10.1007/11575467_8. 535

D. E. Willard. 2002. An algorithm for handling many relational calculus queries efficiently. Journal of Computer and System Sciences, 65: 295–331. DOI: 10.1006/jcss.2002.1848. 529

XSB, 2015. Case Studies. http://www.xsb.com/case-studies. Accessed May 18, 2015. 543

1. A Google Scholar search with +XSB +“logic programming” returns about 2500 results. Last searched on February 27, 2018.

Index

The index that appeared in the print version of this title was intentionally removed from the eBook. Please use the search function on your eReading device to search for terms of interest. For your reference, the terms that appear in the print index are listed below.

2DHP-PSP problem

A Modeling Language for Mathematical Programming (AMPL)

Abducible predicates

Abductive reasoning

Abstractions and implementations

constraint satisfaction

control abstractions

data abstractions

join queries

recursive rules and queries

Accepting states in Büchi PDS

ACID properties

Action Description Languages

Actions

data-independent systems

Datalog

labeled transition systems

planning problems

Activation Records (ARs)

Active programs in LogicBlox

Acyclic Datalog LPADs

Acyclic logic programs

Additive probability space in distribution semantics

Adenine in DNA

Aditi database project

Aditi-Prolog language

Advanced Integrated Multidimensional Modeling Software (AIMMS)

Aggregation and aggregates

Answer Set Programming

CTL model checking

Datalog

Datomic

declarative networking

IDP system

join queries

LDL language

Prolog

Agreement in natural language processing

AI (artificial intelligence)

Datalog

Stable-Model Semantics

AI Winter

Ailog2 system

AIMMS (Advanced Integrated Multidimensional Modeling Software)

Alaska prototype

Algebraic Modeling Languages (AMLs). See SolverBox

Algebras

distribution semantics

finite-state model checking

AllegroGraph system

Alleles

allocate instruction in WAM

Alloy system

Alternating fixed points in modal mucalculus

Alternation depth in modal mu-calculus

Ambiguity in natural language processing

Amino acids

AMLs (Algebraic Modeling Languages). See SolverBox

AMPL (A Modeling Language for Mathematical Programming)

Anaphora in natural language processing

Andersen’s pointer analysis

Annotated disjunctive clauses

Annotated Probabilistic Logic Programming

Answer Set Programming (ASP)

applications

constraint satisfaction

distribution semantics

gene regulatory networks

Haplotype inference

metabolic networks

phylogenetic trees

RNA secondary structure prediction

from Stable Model semantics

tabled logic programs

Answer-set solvers

Answer subsumption

Binary Decision Diagrams

deterministic planning

infinite-state model checking

PITA systems

Antagonism toward Datalog

Antimonotonicity

Horn programs

logic programming

well-founded semantics

append instruction in WAM

Approximation

ground-and-solve

inferencing in PLP

Approximation intuition in Herbrand interpretations

Approximation revision operator in wellfounded semantics

Arbitrary logic programs

Architecture in IDP system

Arginine in DNA

Arity

deterministic Prolog records

first-order logic

ARs (Activation Records)

Artificial intelligence (AI)

Datalog

Stable-Model Semantics

ASP. See Answer Set Programming (ASP)

ASP language

Assertions

control abstractions

join queries

Associativity in natural language processing

Assumption Grammars

Assumption of exclusion in query evaluation

Assumption of independence in query evaluation

Atomic choices in distribution semantics

atomic_constraint predicate

Atomic constraints

Atomic formulas in logic programming

Atomicity in transactions

Atoms

deterministic Datalog

first-order logic

Herbrand interpretations

Horn programs

logic programming

well-founded semantics

Attractors in gene regulatory networks

Attributes in Datalog rules

Autoepistemic logic

Automated symmetry breaking in IDP system

Automated translation in IDP system

B language

B-Prolog language

natural language processing

query evaluation for restricted programs

Backbones in DNA

Backjumping in constraint satisfaction

Backtrackable updates

Backtracking in constraint satisfaction

Backward anaphora

Backward Fixpoint Procedure (BFP)

BANG files

Barber paradox

Barman planning domain

Base pairing in RNA

Baum-Welch algorithm

Bayes classifier

Bayesian Logic Programs (BLPs)

Bayesian networks

conversions

Knowledge Base Model Construction

BDDs (Binary Decision Diagrams)

ProbLog

query evaluation for unrestricted programs

Belnap logic

BERMUDA system

BFP (Backward Fixpoint Procedure)

Bifurcations in gene regulatory networks

Big data in Datalog

BigDatalog

Binary Decision Diagrams (BDDs)

ProbLog

query evaluation for unrestricted programs

Binder language in trust management

Binding requirements in Datalog

BinProlog language

BIOCHAM system

Bioinformatics

Answer Set Programming

biology overview

Haplotype inference

instances

logic programming approaches

phylogenetics

protein structure prediction

RNA secondary structure prediction

systems biology

Biological species concept

BioSigNet-RR tool

Bits in data abstractions

bldcon instruction in WAM

Blocks

LogicBlox

LogiQL clauses

Bloom system

BLPs (Bayesian Logic Programs)

Bodies

Answer Set Programming rules

Datalog rules

logic programming rules

LogiQL clauses

natural language processing constraints

Bottom-up evaluation in Datalog

Bounded left-recursive shortest path (SPLB)

deterministic planning

grid planning

Box operator

BPDS (Büchi PDS)

Branching time logics

Büchi acceptance conditions

Büchi automatons

Büchi PDS (BPDS)

Buffers in data-independent systems

Business intelligence (BI)

C language

call instruction in WAM

Camin-Sokal requirement

Carbon atoms in amino acids

Cardinality

Haplotype inference

IDP system

Cardinality constraint literals in Answer Set Programming

Cardinality-minimal repairs in metabolic networks

CASP program

Cassandra framework

Cataphora in natural language processing

Cavediving planning domain

CBC (COIN-OR Branch and Cut) solver

CDAO (Comparative Data Analysis Ontology)

CDF (Coherent Definition Framework)

Central dogma of biology

Certain atoms

Herbrand interpretations

well-founded semantics

ceval predicate in infinite-state model checking

CFGs (context-free grammars)

natural language processing

tabled logic programs

Character compatibility in phylogenetic trees

Chart parsing in natural language processing

Chase process

Chat-80 system

CheckAccess function

Checkpoints in nondeterministic Prolog

Chlamydomonas reinhardtii

Choice points in nondeterministic Prolog

Chomsky Normal Form

Chord overlay algorithm

CHR Grammars (CHRGs)

Chromosomes

CHRs (Constraint Handling Rules)

grammars

definition

CIAO system

Clark’s completion

Horn programs

Prolog

supported models

Clasp system

Classes in Coherent Definition Framework

Clausal Normal Form (CNF) in IDP system

Clauses

logic programming

LogiQL

Clingcon system

Clingo system

Closed-world assumptions for databases

CLP (Constraint Logic Programming)

CLP(BN) program

CNF (Clausal Normal Form) in IDP system

Coalescent model in Haplotype inference

CodeQuest system

Codons in RNA

Coelom

Haplotype inference

phylogenetic trees

Coherent Definition Framework (CDF)

COIN-OR Branch and Cut (CBC) solver

Coin tosses

Collatz conjecture in data-independent systems

Colmerauer, Alain

Colon-dash (:-) in Datalog rules

Combined complexity in Datalog

Combining rule in Bayesian Logic Programs

Commas (,)

conjunction connectives

Datalog rules

IDP system

LogicBlox

Comments in IDP system

Common Table Expressions

Compactness theorem

Comparative Data Analysis Ontology (CDAO)

Compatible characters in phylogenetic trees

Compatible worlds in distribution semantics

Compilers in finite-state model checking

Compiling nondeterministic Prolog

Complementary strings in DNA

Complete lattices in logic programming

Completion of definitions in IDP system

Completion stacks in WAM

Complex objects

Complexity

CTL model checking

Datalog

query evaluation in PLP

Composite atomic choices in distribution semantics

Compositionality

Computation in Stable Model semantics

Computation Tree Logic (CTL)

finite-state model checking

vs. Linear Temporal Logic

modal mu-calculus

Computing with Logic (Maier and Warren)

Conditional literals

Answer Set Programming

metabolic networks

Conditional probability in distribution semantics

Conjunction connectives in logic programming

Conjunction of constraints in infinite-state model checking

Conjunctions

control abstractions

LogicBlox

Conjunctive external support formulas

Conjunctive loop formulas

Consistency in regulatory networks

Consistent atoms

distribution semantics

well-founded semantics

Constant symbols in logic programming

Constants in deterministic Datalog

Constraint Handling Rules (CHRs)

grammars

definition

Constraint Logic Programming (CLP)

Constraints

Answer Set Programming

bioinformatics

constraint satisfaction

control abstractions

Datalog

EKS

infinite-state model checking

LogicBlox

LogiQL

maintenance

natural language processing

Constructed types in IDP system

Construction process in IDP system

Context dependencies

Context-free grammars (CFGs)

natural language processing

tabled logic programs

Context-sensitive points-to analyses

Contextual independence in query evaluation for unrestricted programs

Continuous operators in complete lattices

Control abstractions

Control locations in Timed Safety Automata

Conversions in Bayesian networks

CORAL deductive system

Cost terms in IDP system

CP integration in ground-and-solve

CP-logic

cpgroundatoms option in IDP system

cplint system

cpsupport option in IDP system

CTL (Computation Tree Logic)

finite-state model checking

vs. Linear Temporal Logic

modal mu-calculus

Curly braces ({ }) in natural language processing

CVE inferencing

Cytosine in DNA

DADM databases

Dahl, Veronica

Data abstractions

Data complexity in Datalog

Data-independent systems

Data management applications

Database systems

deductive

evaluation methods

IDP system

LogicBlox

schema

Datalog

aggregation and sets

algebraic modeling. See SolverBox

application areas

arithmetic and evaluable predicates

artificial intelligence

big data

bottom-up evaluation

bottom-up vs. top-down evaluation

coining of name

conclusions

contributions

data and queries

database system evaluation methods

database systems

in Datomic

declarative networking

decline

destructive updates in rule bodies

deterministic. See Deterministic Datalog

distribution semantics

early systems

emergence

evaluation techniques

existential variables

experiments

explicit state identifiers

extensions overview

in Flora-2 and Ergo

higher-order extensions

introduction

Logic Programming

in LogicBlox

negation

object-oriented logic programming

program analysis

query optimization

resurgence

Semantic Web

top-down evaluation

typing and constraints

updates

in XSB

Dates in logenetic trees

Datomic

DBMs (Difference bound matrices)

DCA (Domain closure axiom)

DCG. See Definite Clause Grammar (DCG) notation

dDatalog

Deadlock freedom in al mu-calculus

deallocate instruction in WAM

DeALS system

Decision nodes in Binary Decision Diagrams

Decision support applications

Declarative language in IDP system

Declarative networking in Datalog

Declarative semantics

DECLARE language

DEDUCE 2 databases

Deduction in IDP system

Deductive database systems

Default negation in Answer Set Programming rules

Defeasibility

Definability of relations for Horn programs

Definite Clause Grammar (DCG) notation

assumption grammars

Hyprolog

natural language processing

push-down systems

toy DCG

Definite Horn clauses

Definite programs in Answer Set Programming

Definitional implication in IDP system

Definitions

Horn programs

IDP system

well-founded semantics

Definitions of concepts, IDP system as

Delay transitions in Timed Safety Automata

Delta predicates in LogicBlox

Demand-driven computation

join queries

recursive queries

Demand transformation in bottom-up evaluation

Denial axioms

Deoxyribonucleic Acid (DNA) sequences

bioinformatics

diploid organisms

Dependencies

context

natural language processing

TGDs and EGDs

Dependency cycles in Horn programs

Dependency graphs

Bayesian networks

Stable Model semantics

Dereferencing deterministic Datalog

Derivation rules in LogicBlox

Derivations vs. answers in Datalog

Derived predicates in LogicBlox

Derived relations in Datalog

Description logic

Datalog

Semantic Web

Design decisions in IDP system

Destructive updates

rule bodies

rule heads

Deterministic Datalog

examples

ground facts

instruction summary

new variables

simple programs

StackTop pointer

temporary variables

variables and constants

Deterministic planning

answer subsumption and shortest-path problem

tabled logic programs

Deterministic Prolog

DFJ model

DIADEM project

Diamond operator in labeled transition systems

Difference bound matrices (DBMs)

Difference operator in Datalog

Diploid organisms

Directed graphs

Binary Decision Diagrams

CTL model checking

labeled transition systems

Disjoint-statements in Probabilistic Horn Abduction

Disjoint types in IDP system

Disjunctions

control abstractions

LogicBlox

Disjunctive Datalog

Disjunctive external support formulas in Stable Model semantics

Disjunctive logic programs (DLPs)

Disjunctive loop formulas in Stable Model semantics

Distribution semantics

algebras and probability measures

bioinformatics

examples

expressive power

Logic Programs with Annotated Disjunctions

non-stratified programs

Probabilistic Horn Abduction

ProbLog

Sato and Kameya’s definition

Stable Model semantics

stratified programs

stratified programs with function symbols

well defined

DLOG system

DLPs (disjunctive logic programs)

DLV language

DNA (Deoxyribonucleic Acid) sequences

bioinformatics

diploid organisms

Dollo requirement

Haplotype inference

phylogenetic trees

Domain atoms in first-order logic

Domain closure axiom (DCA)

Domain specific languages

Domains

datatypes

first-order logic

Double helix in DNA

Downward closed constraints

Dynamic filtering in bottom-up evaluation

Dynamic logic

Dynamic predicates in Prolog

Dynamic stratification

Datalog

negation

Early Datalog systems

ECA (event-condition-action) rules

Ectocarpus Siliculosus

EDBs (extensional databases)

Datalog

LogicBlox

Edges

gene regulatory networks

phylogenetic trees

EDS (Expert Database Systems)

EFA (extended finite automata)

EGDs (equality-generating dependencies)

EKS system

Elog language

EMBLEM system

Encoding knowledge in IDP system

Enterprise decision making in constraint satisfaction

Enterprise management in join queries

Entities in LogicBlox

Environment trimming in WAM

Enzymes in DNA

Equality-generating dependencies (EGDs)

Equilibrium logic in Stable Model semantics

Equivalence in Stable Model semantics

Equivalent composite choices in distribution semantics

Erase relation in Büchi PDS

Ergo system

vs. Datalog

F-logic

HiLog

Escherichia coli

ET (Extension Table) evaluation

Evaluable predicates in Datalog

Event-B language

Event calculus

Event-condition-action (ECA) rules

Evidential probability

Evolutionary theory in phylogenetics

Exclamation points (!) in LogicBlox

Exclusion axiom in query evaluation for restricted programs

execute instruction in WAM

Executing blocks in LogicBlox

Existential variables in Datalog

EXODUS storage manager

Expert Database Systems (EDS)

Explanations

distribution semantics

IDP system

query evaluation for unrestricted programs

Explicit constraints

Explicit state identifiers

Expression complexity in Datalog

Expressive power in distribution semantics

Expressiveness in database systems

EXPTIME-complete data complexity

Extended finite automata (EFA)

Extension Table (ET) evaluation

Extensional databases (EDBs)

Datalog

LogicBlox

External support formulas in Stable Model semantics

Extra arguments in natural language processing

EZ system

F-logic

objects

Semantic Web

Facts

control abstractions

Datalog

FAD language

Fages Lemma

False atoms

first-order logic

Herbrand interpretation grounds

Horn programs

well-founded semantics

Fields in deterministic Prolog records

Fifth-Generation Computer Systems (FGCS)

findall predicate in Prolog

Finitary operators

complete lattices

Horn programs

Finite directed graphs

CTL model checking

labeled transition systems

Finite Domain

Finite-state model checking

CTL

linear-time vs. branching time logics

modal mu-calculus

First-order (FO) logic

aggregates

arithmetic

control abstractions

definitions

IDP system

partial functions

types

Fixed points

Backward Fixpoint Procedure

CTL model checking

Datalog

modal mu-calculus

Fixpoints

Horn programs

logic programming

well-founded semantics

FlatZinc

Floortile planning domain

FLOPC++ (Formulation of Linear Optimization Problems in C++)

Flora-2 system

vs. Datalog

transaction logic

FLORID system

Flux balance analysis in metabolic networks

FO(ID). See First-order (FO) logic

Folding in protein structure prediction

For-loops in join queries

Foreign keys

Formal definitions in IDP system

Formal semantics

Formulas

first-order logic

IDP system

LogicBlox

partial functions

Formulation of Linear Optimization Problems in C++ (FLOPC++)

Founded semantics

Four-valued models in well-founded semantics

Four-valued one-step provability operator

FPspace complete problem

Frame axioms

Frame-based systems

Frame problems

Frame representation in F-logic

Function detection in IDP system

Function-free logic

Function symbols

logic programming

stratified programs with

Functional dependencies in IDP system

functiondetection option in IDP system

Functions in IDP system

Gambler program

Games and puzzles

applications

constraint satisfaction

GAMS (General Algebraic Modeling System)

Gecode system

Gene regulatory networks

Answer Set Programming encoding

instances

modeling

systems biology

General Algebraic Modeling System (GAMS)

Generalized counting

bottom-up evaluation

SALAD prototype

Generate-define-test methodology

Genes

DNA

phylogenetic trees

Genomes

Genomics

Genotypes

getcon instruction in WAM

getnum instruction in WAM

getstr instruction in WAM

gettval instruction in WAM

getvar instruction in WAM

Global memory in natural language processing

Globalizing variables in WAM

Glue language

Grammar induction in natural language processing constraints

GraphDB system

GraphX

Greater-than comparisons in Datalog

Greatest upper bounds (gubs) in complete lattices

Grids planning example

Gringo language

Ground-and-solve optimization in IDP system

Ground atoms

distribution semantics

Herbrand interpretations

Ground facts in deterministic Datalog

Ground terms in logic programming

Grounding and ground instances

Answer Set Programming rules

Bayesian networks

Datalog rules

IDP system

logic programming

LogiQL

query evaluation for restricted programs

Grounding phase in IDP system

Grounding with bounds in IDP system

groundpropagate procedure in IDP system

groundwithbounds option in IDP system

Guanine in DNA

Guards

natural language processing

Timed Safety Automata

gubs (greatest upper bounds) in complete lattices

Hairpin loops in RNA

Haplotype inference

Answer Set Programming encoding

bioinformatics

instances

modeling

Head constraints in natural language processing

Heads

Answer Set Programming rules

Datalog rules

IDP rules

logic programming rules

LogiQL clauses

Heap in deterministic Prolog

Herbrand base

Bayesian networks

ground atoms

Horn programs

logic programming

Herbrand interpretations

Horn programs

IDP system

logic programming

one-step provability operator

Stable Model semantics

well-founded semantics

Herbrand model for stratified programs

Herbrand universe

Here-and-there logic in Stable Model semantics

Heterozygous sites

Hidden Markov Models (HMMs)

distribution semantics

inferencing in PLP

query evaluation for restricted programs

HiLog

Semantic Web

HIPP-DEC

HMMs (Hidden Markov Models)

distribution semantics

inferencing in PLP

query evaluation for restricted programs

Homozygous sites

Horn clauses

IDP system

KBS systems

LDL language

logic programming

Magic Templates

Prolog

Horn programs

extensions

logic programming

one-step provability operator

Stable Model semantics

well-founded semantics

Horn rules

Human Genome Project

Hybrid Annotated PLPs

Hypotheses

control abstractions

join queries

Hypothetical reasoning in natural language processing

Hyprolog language

ICL. See Independent Choice Logic (ICL)

IDBs (intensional databases)

Datalog

IDP system

LogicBlox

IDLP (Immediate Dominance/ Linear Precedence) formalism

IDP (Imperative-Declarative Programming)

aggregates

arithmetic

component operations

constructed types

definitions

first-order logic

ground-and-solve

inference methods

input*- definitions

KBS

language

logic

optimization workflow

output*- definitions

output vocabulary

partial functions

post-processing

preprocessing

procedures

quantification depth

scalability and infinity

structure consistency

structures

structuring components

symmetries

terms

theory

types

uses

vocabulary

IDP3 tool

If-statements in join queries

IGlue language

IGlue-to-IGlue static optimizer

ILOG Concert

ILP (Inductive Logic Programming)

Immediate consequence operator in Datalog

Immediate Dominance/ Linear Precedence (IDLP) formalism

Imperative-Declarative Programming. See IDP (Imperative-Declarative Programming)

Imperative programming languages in knowledge base systems

Implication arrows (->) in LogicBlox

Impossible atoms in well-founded semantics

Inca system

Inclusion dependencies

Inclusion-exclusion principle in inferencing in PLP

Incompatible characters in phylogenetic trees

Incompatible worlds in distribution semantics

Inconsistent atoms

Herbrand interpretations

well-founded semantics

Incremental completion algorithm in top-down evaluation

Incremental computation in recursive queries

Incrementality in LogicBlox

Independence axiom

Independence in query evaluation for restricted programs

Independent and identically distributed (iid) variables

Independent Choice Logic (ICL)

composite choices

disjoint-statements

distribution semantics

query evaluation for unrestricted programs

well defined distribution semantics

Indexing

join queries

LogiQL

WAM

Induction process in IDP system

Inductive definitions in IDP system

Inductive Logic Programming (ILP)

Inference engines

IDP system

LogicBlox

XSB system

Inference in recursive queries

Inference methods

IDP system

knowledge base systems

Inference rules in Datalog

Inferencing in PLP

approximation and other inferencing

tasks

distribution semantics

query evaluation complexity

query evaluation for restricted programs

query evaluation for unrestricted programs

Infinitary propositional logic

Infinite loops in natural language processing

Infinite sites model

Infinite-state model checking

data-independent systems

push-down systems

real-time systems

tabled evaluation with constraints

Infinite words in Linear Temporal Logic

Infinity in IDP system

Influence graphs in gene regulatory networks

Informal semantics

Inheritance rules

Inner fixed points in modal mu-calculus

Input data load in Datalog

Input*- definitions in IDP system

Instances in Datalog rules

Integrity constraints in natural language processing

Intelligent backtracking in LDL language

Intensional databases (IDBs)

Datalog

IDP system

LogicBlox

Interaction graphs in gene regulatory networks

Interior nodes in Binary Decision Diagrams

Intermediate code in WAM

Interpretation in first-order logic

Interrogative clauses in natural language processing

Intractable languages in IDP system

Intractable problems in bioinformatics

Intuitionistic assumptions in natural language processing

Invariant locations in Timed Safety Automata

Inverse scope problem in metabolic networks

Invocation code in procedural languages

IRIS prototype

Irrelevant results in bottom-up evaluation

Iterative computation in recursive queries

Iterative QSQ (QSQI)

Jena system

Jeopardy Man vs. Machine Challenge

Join queries

Aditi

applications

control abstractions

implementation

K-incompatibility problem

KBMC (Knowledge Base Model Construction)

KBMS (Knowledge-Base Management System)

KBSs (knowledge base systems)

EDS relationship

IDP system

Keys

Knaster-Tarski theorem

complete lattices

well-founded semantics

Knowledge-Base Management System (KBMS)

Knowledge Base Model Construction (KBMC)

Knowledge base systems (KBSs)

EDS relationship

IDP system

Knowledge bases

Knowledge management applications

Knowledge representation (KR) languages

Knuth’s Attribute Grammars

Kripke-Kleene model

Horn programs

three-valued semantics

well-founded semantics

Kripke structures in CTL model checking

Labeled transition systems (LTSs)

Lambda-calculus in natural language processing, in

Lambda Prolog

Large fact bases

Last call optimization in WAM

Lattices

Datalog

logic programming

Lazy clause generation (LCG)

Lazy Grounding

LDL language

LDL++ language

Least fixed points

CTL model checking

Datalog

Least models

CTL model checking

Datalog

Stable Model semantics

Least sets in IDP system

Least upper bounds (lubs) in complete lattices

Left-recursive grammars

Left-recursive shortest path (SPL)

deterministic planning

grid planning

LeProbLog system

Leucine in DNA

LFI-ProbLog system

Libraries for Algebraic Modeling Languages

LIFE language

Lifted unit propagation in ground-and-solve

liftedunitpropagation option in IDP system

Ligands in bioinformatics

Linear assumptions in natural language processing

Linear Datalog

Linear resolution in Datalog

Linear tabling in Extension Table algorithm

Linear Temporal Logic (LTL)

Linear time calculus (LTC)

Linearity in natural language processing constraints

Linguistic applications

LINQ

Lisp for natural language processing

Lists in data abstractions

Literals

Answer Set Programming

first-order logic

logic programming

metabolic networks

Lixto system

Local stratification

Datalog

Stable Model semantics

Location-specifier variables in NDlog

Locations in push-down systems

Logarithmic space (LOGSPACE) data complexity

Logging in nondeterministic Prolog

Logic in IDP system

Logic Programming

Datalog

Logic Programs with Annotated Disjunctions (LPADs)

Logical variables in Datalog rules

LogicBlox

applications

concepts

constraint satisfaction

vs. Datalog

experiments

join queries

LogiQL by example

LOGIN language

LogiQL language

components

LogiQL by example

mathematical programming

optimization

production-transportation model

Traveling Salesman Problem

LOGSPACE (logarithmic space) data complexity

Logtalk

LOLA system

Long-distance dependencies in natural language processing

Loop formulas in Stable Model semantics

LPADs (Logic Programs with Annotated

Disjunctions)

LPS system

LTC (linear time calculus)

LTSs (labeled transition systems)

lubs (least upper bounds) in complete

lattices

Lunar Science System in natural language processing

Machine learning in Semantic Web

Magic Sets

declarative networking

bottom-up vs. top-down

SALAD prototype

Starburst

Magic Templates

bottom-up evaluation

CORAL

Maier, David

Markov Logic Networks (MLNs)

Mathematical programming in LogiQL

Maximum A Posteriori inference

Maximum functions in IDP system

Maximum likelihood criteria in Haplotype inference

Maximum quartet consistency (MQC)

Measurable sets in distribution semantics

MegaLog system

Meld applications

MELD language

Membership relations in F-logic

Memo-ization in WAM

Memoing

natural language processing

top-down evaluation

Memory

deterministic Datalog

deterministic Prolog

nondeterministic Prolog

Mendelian rules of inheritance

Meta-interactions in gene regulatory networks

Metabolic networks

Answer Set Programming encoding

completion

instances

modeling

systems biology

Methionine in DNA

Metropolis-Hastings algorithm

Minimal languages in logic programming

Minimal models

Horn programs

Stable Model semantics

Minimal repairs

gene regulatory networks

metabolic networks

Minimization inference in IDP system

Minimum-cardinality in Haplotype inference

Minimum functions in IDP system

MiniZinc system

Minus signs (-) in Datalog rules

Mixed integer programming (MIP)

constraint satisfaction

LogiQL

MLNs (Markov Logic Networks)

Modal mu-calculus

model checking

timed

Model checking in IDP system

Model checking problems

finite-state model checking

linear-time vs. branching time logics

modal mu-calculus

tabled logic programs

Model expansions in IDP system

Model generation in IDP system

Model-theoretic database views

modelexpand procedure in IDP system

models function in CTL model checking

Modular languages in IDP system

Monadic Datalog

Monotonicity

Horn programs

logic programming

Stable Model semantics

well-founded semantics

Montague grammar

Monte Carlo simulations

Most precise structure in ground-and-solve

Most Probable Explanation inference

movreg instruction in WAM

MQC (maximum quartet consistency)

mRNA synthesis in systems biology

MRRPS 3.0 databases

MTZ model

Multiple inference methods in IDP system

Mutual embedding

Myria system

n-ary symbols in first-order logic

N-queens puzzle

Nail language

NailLog system

Naïve approach to bottom-up evaluation

Names

Datalog variables

IDP system

Namespaces in IDP system

Native state in proteins

Natural language processing (NLP)

assumption grammars

constraints

history

hypothetical reasoning

probabilistic logic programming

recursive queries

semantic structures

syntactic features and agreement

syntax trees

tabled logic programming and Definite Clause Grammars

tabling origins

toy DCG

Natural-language questions in Chat-80 system

Natural languages in IDP system

Natural models in IDP system

nbmodels option in IDP system

NDlog language

applications

declarative networking

NED-2 Intelligent Information System

Negation

Answer Set Programming rules

constraint satisfaction

control abstractions

CORAL

CTL model checking

Datalog

EKS

Horn programs

IDP system

join queries

logic programming

LogicBlox

Prolog

recursive queries

Nested Relation model

Networks

Bayesian

declarative

gene regulatory

metabolic. See Metabolic networks

phylogenetics

systems biology

Nilsson’s probabilistic logic

NLP. See Natural language processing (NLP)

Non-First-Normal-Form model

Non-ground rules in Answer Set Programming

Non-monotonicity

Answer Set Programming

Stable Model semantics

Non-recursive Datalog

Non-stratified programs

Nondeterministic Prolog

Nonmonotonic reasoning in stable-model semantics

Normalized SLP

Notational convenience in Datalog rules

NP-complete problem

Answer Set Programming

phylogenetic trees

RNA secondary structure prediction

Stable Model semantics

NP-hard problem in Datalog

NU-Prolog system

Nucleotides in DNA

Nulls

O-logic language

Object-logic (OLOG)

Object-oriented programming

Datalog

description

Object-oriented Prolog (OOP)

Objects

Coherent Definition Framework

data abstractions

Oblivious chases

Ockham’s principle of parsimony

ODBC interface

ODC (ontology-directed classifier)

OLDT resolution

natural language processing

top-down evaluation

OLOG (object-logic)

OLTP (Online transaction processing)

One-step provability operator

Horn programs

Online transaction processing (OLTP)

Ontobroker system

Ontology-directed classifier (ODC)

Ontology management in join queries

OOP (object-oriented Prolog)

Open symbols in IDP system

Open-world assumptions for databases

Operators

complete lattices

CTL model checking

Horn programs

logic programming

Operons in gene regulatory networks

OPL Technologies

Optimal plan generation problem in tabled logic programs

Optimization

Answer Set Programming

Datalog

IDP system

LogiQL

WAM

Optimization inferences in IDP system

Optimization Services Instance Language (OSiL)

Orchestra

Order sorted logic in IDP system

Ordering

Binary Decision Diagrams

join queries

Ordinal numbers in Knaster-Tarski theorem

OSiL (Optimization Services Instance Language)

Out-of-order message delivery in extended finite automata

Output*- definitions in IDP system

Output vocabulary in IDP system

Overlay networks in declarative networking

Overlog

OWL in Semantic Web

P-log

P2 facility

P2Ps (predicate to predicate mappings)

Pairwise incompatible composite choices

Parallelism in Aditi

Parameterized systems in infinite-state model checking

Parameters

IDP system

procedural languages

Parsimony in Haplotype inference

Parsing natural language processing

Partial bottom-up evaluation

Partial functions in IDP system

Partial stable model for well-founded semantics

Partial structures for first-order logic

Partial supported models for well-founded semantics

Passing parameters in procedural languages

Path quantifiers in CTL model checking

pD language

PDSs (push-down systems)

Peptidic bonds in DNA

Pereira, Fernando

Perfect-model semantics

Perfect models

Datalog programs

Horn programs

Perfect phylogeny in Haplotype inference

Periods (.) in IDP system

Persistent data in XSB

Petri nets in metabolic networks

PHA. See Probabilistic Horn Abduction (PHA)

Phylogenetics

Answer Set Programming encoding

inference

instances

modeling

Phyloinformatics

Picat-based planners

domains

grids

tabled logic programs

Pigeonhole problem

PITA systems

query evaluation for restricted programs

query evaluation for unrestricted programs

Planning examples

domains

grids

Planning via tabled search

PLP. See Probabilistic logic programming (PLP)

PODS (Principals of Database Systems)

Pointer analysis in recursive queries

Points-to analyses

Polymeric strands in DNA

Polynomial time (PTIME) data complexity

bioinformatics

Datalog

Polytomies

Porter, Harry

Positive dependency graphs in Stable Model semantics

Possible atoms

Herbrand interpretations

well-founded semantics

Post-processing in IDP system

postprocessdefs option in IDP system

Practical limitations in Datalog

Pre-fixpoints in logic programming

Pre-images in timed modal mu-calculus

Precision order

first-order logic

Herbrand interpretations

Predicate logic in IDP system. See IDP (Imperative-Declarative Programming)

Predicate stratification in Datalog

Predicate symbols in logic programming

Predicate to predicate mappings (P2Ps)

Predicates

Datalog

IDP system

LogicBlox

LogiQL

Prolog

Prediction problem in gene regulatory networks

Prefix language in push-down systems

Preprocessing in IDP system

Prescriptive analysis in constraint satisfaction

Primary keys

Primary sequences of proteins in RNA

Principals of Database Systems (PODS)

printmodels procedure in IDP system

PRISM system

applications

bioinformatics

inferencing in PLP

natural language processing

PRISM language

query evaluation for restricted programs

well defined distribution semantics

PRISMAlog language

ProB language

Probabilistic Context-Free Grammars

inferencing in PLP

natural language processing

Probabilistic facts in ProbLog

Probabilistic Horn Abduction (PHA)

composite choices

distribution semantics

query evaluation for restricted programs

well defined distribution semantics

Probabilistic logic programming (PLP)

Annotated Probabilistic Logic Programming

background and assumptions

Bayesian networks

distribution semantics. See Distribution semantics

evidential probability

inferencing

Logic Programs with Annotated Disjunctions

Markov Logic Networks

natural language processing

Nilsson’s probabilistic logic

PRISM

Probabilistic Horn Abduction

ProbLog

Stochastic Logic Programs

Probability atoms in P-log

Probability distributions in Markov Logic Networks

Probability measures in distribution semantics

Probability of pairwise incompatible sets of composite choices

Probability space in distribution semantics

PROBE system

ProbLog system

applications

Binary Decision Diagrams

bioinformatics

inferencing in PLP

Nilsson’s probabilistic logic

query evaluation for unrestricted

programs

ProbLog

Procedural integration

IDP system

knowledge base systems

Procedural languages run-time environments

Procedures in IDP system

proceed instruction in WAM

Process calculi in metabolic networks

Process logic

Product functions in IDP system

Production-transportation model

Products of reaction in metabolic networks

Program analysis

applications

Datalog

recursive queries

Program completion

Program points in push-down systems

Programs in Datalog

project predicate in infinite-state model checking

Prolog

aggregation

Constraint Handling Rules

CTL model checking

Datalog relationship

deterministic

natural language processing

negation

nondeterministic

predicates

variables and constants

WAM

Prolog++

Pronoun references in natural language processing

Proof-theoretic database views

propagate procedure in IDP system

Propagation inference in IDP system

Propagation rules

EKS

natural language processing

well-founded semantics

Properties for natural language processing constraints

Property grammars

Propositional logic in Stable Model semantics

Propositions in CTL model checking

Protein interaction networks

Protein structure prediction

bioinformatics

instances

modeling

Proteins

Pseudo-knots in RNA secondary structure prediction

PTIME (polynomial time) data complexity

bioinformatics

Datalog

Pure SLP

Push-down systems (PDSs)

putcon instruction in WAM

putnum instruction in WAM

putstr instruction in WAM

puttval instruction in WAM

puttvar instruction in WAM

putuval instruction in WAM

putval instruction in WAM

putvar instruction in WAM

Puzzles

applications

constraint satisfaction

QBF (Quantified Boolean Form)

QSQ (Query-SubQuery) approach

QSQI (iterative QSQ)

QSQR (recursive QSQ)

Quantification

IDP system

natural language processing

Quantified Boolean Form (QBF)

Quantifiers in join queries

Queries

Datomic

Flora-2

LogicBlox

minimization inference

recursion

Stochastic Logic Programs

XSB

Query complexity in Datalog

Query evaluation

inferencing in PLP

restricted programs

unrestricted programs

Query inferences in IDP system

Query optimization

Datalog

XSB

Query-SubQuery (QSQ) approach

Question-answering system QA

Question mark–dash (?-) in Datalog rules

Radial restraints

Random selection rules in P-log

Random switch names in PRISM

Ranges in Answer Set Programming

RBAC (role-based access control)

RCP register in WAM

RCPheaptop register in WAM

RDBMSs (relational database management systems)

RDF format

RDL system

Re-computations in natural language processing

Reachability

bottom-up evaluation

extended finite automata

push-down systems

Timed Safety Automata

Reachable metabolites

Reactants of reaction

Reactive rules

description

LogicBlox

Real-time systems in infinite-state model checking

Reasoning in Semantic Web

Records in deterministic Prolog

Recursion

aggregation

control abstractions

Datalog rules

natural language processing

PROBE system

push-down systems

rules and queries

Recursive definitions in IDP system

Recursive QSQ (QSQR)

reducedgrounding option in IDP system

Reduct program

Answer Set Programming

Stable Model semantics

Reduction in Binary Decision Diagrams

References in evidential probability

Referential integrity

Refinements in IDP system

Regular-expression paths

Regulatory graphs

Regulatory networks in systems biology

Reiter’s hitting set algorithm

Relation areas in Datalog

Relation symbols in Stable Model semantics

Relational database management systems (RDBMSs)

Relational semantics for partial functions

Relationships

control abstractions

data abstractions

Datalog rules

Relative clauses in natural language processing

Relativized Fages Lemma

Repairs

gene regulatory networks

metabolic networks

Repeated derivation in bottom-up evaluation

Resets in Timed Safety Automata

Residual programs

modal mu-calculus

Stable Model semantics

Residues

Resolution theorem proving in Logic Programming

Resource allocation in constraint satisfaction

Restricted chases

Restricted programs, query evaluation for

retrymeelse instruction in WAM

retrymeelsefail instruction in WAM

Reusing knowledge in IDP system

Rewriting natural language processing rules

Rheaptop register in WAM

Ribonucleic Acid (RNA) sequences

RIF (Rule Interchange Format)

Right-recursive shortest path (SPR)

Rmode register in WAM

RMSD (root-mean-square deviations)

RNA (Ribonucleic Acid) sequences

RNA secondary structure prediction

Answer Set Programming encoding

bioinformatics

instances

modeling

Robetta prediction

Rodin toolset

Role-based access control (RBAC)

Root-mean-square deviations (RMSD)

Rooted trees in phylogenetics

Rsreg register in WAM

RT language in trust management

RTrail register in WAM

Rule-based reasoning in Semantic Web

Rule connectives in logic programming

Rule Interchange Format (RIF)

Rules

Answer Set Programming

control abstractions

Datalog

destructive updates in

IDP system

logic programming

LogicBlox

LogiQL

natural language processing constraints

program analysis

recursion

Stable Model semantics

Rules of inheritance

Run-time environments in procedural languages

Run-time stacks in C language

Safe Datalog rules

SALAD prototype

Sample space in distribution semantics

Satisfiability checking in IDP system

Satisfiability solvers in Stable Model semantics

Sato and Kameya’s definition in distribution semantics

Scalability in IDP system

Scope in metabolic networks

SD3 language

SDS (Smart Data System)

Se-models in Stable Model semantics

Search in ground-and-solve

Search-space pruning mechanism

Second-order existential quantifiers in LogiQL

Secondary structure prediction in RNA

Security applications

Security policy frameworks

join queries

recursive queries

Seed metabolites in metabolic networks

Selections in distribution semantics

Self-justified models in Stable Model semantics

SEM-CP-logic system

Semantic equivalence parsing

Semantic networks

Semantic query optimization

Semantic Web

Semantics

distribution. See Distribution semantics

natural language processing

Stable Model. See Stable Model semantics (SMS)

well-founded. See Well-founded semantics (WFS)

Semi-naïve approach in bottom-up evaluation

Semi-structured data

Semicolons (;) in LogicBlox

Sentences in first-order logic

Serial conjunction

Serine in DNA

Sets

Datalog

IDP system

Sets of actions

data abstractions

labeled transition systems

Sets of equivalent states in tabled logic programs

Shortest-path problem in deterministic planning

SICStus

Side chains in amino acids

Sideways information passing in bottom-up evaluation

Sign Consistency Model in gene regulatory networks

Signaling networks in systems biology

Simpagation rules in natural language processing

Simple planning via tabled search

answer subsumption and the shortestpath problem

planning examples

tabled logic programs

Simplification

ground-and-solve

natural language processing

Stable Model semantics splitting

Single Nucleotide Polymorphism (SNP)

Single quotes (’) in Datalog

Situation calculus

Skolem constants

SLD resolution and trees

Datalog

Logic Programming

query evaluation

SLDNF

proof procedure

query evaluation for unrestricted programs

SLG algorithm

natural language processing

top-down evaluation

SLIPCASE system

SLIPCOVER system

SLPs (Stochastic Logic Programs)

Smart Data System (SDS)

SMS. See Stable Model semantics (SMS)

SNP (Single Nucleotide Polymorphism)

SociaLite big data

Sokoban planning domain

solve procedure in LogiQL

SolverBox. See also LogiQL language

Datalog relation

Traveling Salesman Problem

Soundness in probabilistic logic programming

Spark

SPARQLlanguage

Spatial model in protein structure prediction

Speciation in phylogenetic trees

Specificity in evidential probability

SPL (left-recursive shortest path)

deterministic planning

grid planning

SPLB (bounded left-recursive shortest path)

deterministic planning

grid planning

splitdefs option in IDP system

Splitting

composite choices in distribution semantics

Stable Model semantics

Splitting Algorithm in query evaluation for unrestricted programs

Splitting Lemma

SPR (right-recursive shortest path)

SQL in program analysis

Stable Model semantics (SMS)

aggregation

Answer Set programming

bioinformatics

constraint satisfaction

control abstractions

Datalog

definition and basic properties

distribution semantics

equivalence and strong equivalence

loop formulas

one-step provability operator

stratification and splitting

terminology and notation

tightness

StackTop pointer in deterministic Datalog

Starburst project

State identifiers

State quantifiers in CTL model checking

State space

deterministic planning

grids

searches in tabled logic programs. See Tabled logic programs

States

Büchi PDS

gene regulatory networks

Timed Safety Automata

Static filtering in bottom-up evaluation

Static models in bioinformatics

Static predicates in Prolog

Statistical approach in natural language processing

stdoptions components in IDP system

Steady state in gene regulatory networks

Stem loops in RNA

Stochastic Logic Programs (SLPs)

Stored predicates

Stored procedures

Stratification

Datalog

Stable Model semantics

Stratified negation

Horn programs

recursive queries

Stratified programs

CTL model checking

Datalog

distribution semantics

with function symbols

Horn programs

negation

Strict refinements in IDP system

Strong equivalence in Stable Model semantics

Strong propagation rule in well-founded semantics

Structural studies in bioinformatics

Structures in IDP system

components

consistency

Subclasses in F-logic

Subroutines

Subsets in distribution semantics

Subsumptive demand transformation in bottom-up evaluation

Subsumptive tabling

bottom-up evaluation

top-down evaluation

Subtours in LogiQL

Sum functions in IDP system

Super-tokenizer tool

Supplementary Magic Sets

Supported models

Clark’s completion

Stable Model semantics

well-founded semantics

SWI Prolog

Switch names in PRISM

switch_on_constant instruction in WAM

switch_on_structure instruction in WAM

switch_on_type instruction in WAM

Syllog system

Symbolic unit propagation in ground-and-solve

Symbols in IDP system

Symmetries

Horn programs

IDP system

Symmetry breaking in IDP system

Symmetry detection in IDP system

symmetrybreaking option in IDP system

Syntax in natural language processing

features

trees

Systems biology

gene regulatory networks

metabolic networks

overview

Systems studies in bioinformatics

Table functions in Starburst

Tabled evaluation with constraints

Tabled logic programs

discussion

finite-state model checking

infinite-state model checking. See Infinite-state model checking

natural language processing

simple planning via tabled search

Tabling

Extension Table algorithm

join queries

origins

top-down evaluation

WAM extensions

XSB

Tags in deterministic Prolog records

Target metabolites

Targets in evidential probability

Taxonomic units in phylogenetics

Teaching applications

Temporal operators in CTL model checking

Terminal well-founded inductions in IDP system

Terms

first-order logic

IDP system

logic programming

Ternary predicate models in timed modal mu-calculus

Text processing in recursive queries

TGDs (tuple-generating dependencies)

Theoretical limitations in Datalog

Theories

first-order logic

IDP system

Three-valued interpretation in well-founded semantics

Three-valued setting in Horn programs

Three-valued stable model in well-founded semantics

Thymine in DNA

Tightness

Stable Model semantics

well-founded semantics

Timed modal mu-calculus

Timed Safety Automata (TSA)

Timed systems in tabled logic programs

timeFunc function

Timeless assumptions in natural language processing

timeOf function

TM (trust management) for recursive queries

tnot operation in CTL model checking

Top-down evaluation in Datalog

Topicalization in natural language processing

Toy DCG

Trail stacks in nondeterministic Prolog

Transaction Logic

extensions

rule updates

Transactions in LogicBlox

Transcription in biology

Transcriptional regulatory networks

Transfinite induction in Knaster-Tarski theorem

Transfinite sequences in Knaster-Tarski theorem

Transformation

Datalog

query evaluation for unrestricted programs

Transitions

labeled transition systems

Timed Safety Automata

Transitive closure in IDP system

Translation in biology

Translators in Prolog

Traveling Salesman Problem (TSP)

Traversal recursion in PROBE system

Tree reconstruction in phylogenetics

Triggers for reactive rules

True atoms

first-order logic

Herbrand interpretations

Horn programs

well-founded semantics

Trust management (TM) for recursive queries

trustmeelsefail instruction in WAM

Truth order in first-order logic

trymeelse instruction in WAM

trymeelsefail instruction in WAM

Trytophan in DNA

TSA (Timed Safety Automata)

TSP (Traveling Salesman Problem)

Tuple-generating dependencies (TGDs)

Tuples in IDP system

Turing’s computability for Horn programs

Two-input one-step provability operator

Two-valued structures in first-order logic

Type groups in LOLA system

Types

Datalog

IDP system

UDAs (user-defined aggregates)

UNA (unique names axiom)

Unbounded dependencies in natural language processing

Unbounded planner for grids

Uncertain inferences

Undecidable languages

Unfounded sets

Stable Model semantics

well-founded semantics

unicon instruction in WAM

Unidirectional Grid domain in grid planning

Uniform equivalence

Datalog

Stable Model semantics

Union of conjunctive queries in Datalog

Unique names axiom (UNA)

Unique stable models

Stable Model semantics

well-founded semantics

Uniqueness constraints

unitval instruction in WAM

unitvar instruction in WAM

unival instruction in WAM

univar instruction in WAM

Universal models

Unknown (truth value of) atoms

Herbrand interpretations

Horn programs

well-founded semantics

Unreachable nodes in Datalog

Unrestricted programs, query evaluation for

Unrooted trees in phylogenetics

Unsat-core extraction in IDP system

Updates

in Datalog

extensions

rule bodies

rule heads

Uracil in DNA

User-defined aggregates (UDAs)

VALIDITY database

Value-passing automata in dataindependent systems

Value types in LogicBlox

Variables

Datalog

Datalog rules

deterministic Datalog

IDP system

NDlog

Stable Model semantics

WAM

well-founded semantics

Variant tabling

bottom-up evaluation

top-down evaluation

verbosity option in IDP system

Versioned predicates in LogicBlox

View definitions

Virtual machines. See Warren Abstract Machine (WAM)

Virtual relations in Datalog

Visualization inference in IDP system

Viterbi paths

Vocabulary

first-order logic

IDP system

logic programming

Warren, David H. D.

Warren, David Scott

Warren Abstract Machine (WAM)

deterministic Datalog

deterministic Prolog

environment trimming

examples

ground facts

indexing

instruction summary

last call optimization

natural language processing

nondeterministic Prolog

procedural languages

Prolog features

simple programs

StackTop pointer

tabling extensions

temporary variables

variables and constants

Watson-Crick pairs

wCSP in bioinformatics

WebDamlog language

WebLog

Well defined distribution semantics

Well-founded induction in IDP system

Well-founded semantics (WFS)

aggregation

constraint satisfaction

control abstractions

Datalog

distribution semantics

IDP system

one-step provability operator

definition

terminology and notation

WFM (workforce management) in constraint satisfaction

WFS. See Well-founded semantics (WFS)

Womb Grammars

Workforce management (WFM) in constraint satisfaction

Workspaces in LogicBlox

Worlds in distribution semantics

XMC applications

XSB Logic Programming System

aggregation

applications

Coherent Definition Framework

vs. Datalog

experiments

Flora-2

grid planning

natural language processing

planning domains

SLG algorithm

variant tabling

xsb option in IDP system

YAP Prolog

natural language processing

probability computations

Yedalog

Zinc language

Zones in Timed Safety Automata

Zucker’s algorithm

Biographies

Editors

Michael Kifer is a professor with the Department of Computer Science, Stony Brook University, USA. He received his Ph.D. in Computer Science in 1984 from the Hebrew University of Jerusalem, Israel, and the M.S. degree in Mathematics in 1976 from Lomonosov Moscow State University, Russia. Since 2012, Dr. Kifer has served as the President of the Rules and Reasoning Association (RRA). His work spans the areas of knowledge representation and reasoning (KRR), logic programming, Web information systems, and databases. He published four textbooks and numerous articles in these areas as well as co-invented F-logic, HiLog, Annotated Logic, and Transaction Logic, which are among the most widely cited works in Computer Science and Semantic Web research, in particular. Twice, in 1999 and 2002, he was a recipient of the prestigious ACM-SIGMOD “Test of Time” awards for his works on F-logic and object-oriented database languages. In 2008, he received SUNY Chancellor’s Award for Excellence in Scholarship. In 2013, Dr. Kifer received another prestigious award: The 20-year “Test of Time” award from the Association for Logic Programming (ALP) for his work on Transaction Logic. In 2013, Kifer co-founded Coherent Knowledge Systems, a startup that commercializes semantic and KRR technologies.

Yanhong Annie Liu is a professor of Computer Science at Stony Brook University. She received her B.S. from Peking University, M.Eng. from Tsinghua University, and Ph.D. from Cornell University, all in Computer Science. Her primary research is in languages and algorithms, especially on systematic design and optimization, centered around incrementalization—the discrete counterpart of differentiation in calculus. Her current research focus is on languages and efficient implementations for secure distributed programming and for declarative system specifications. She has published in many prestigious venues, taught in a wide range of computer science areas, and presented over 100 conferences and invited talks worldwide. She serves on the ACM Books Editorial Board as the Area Editor for Programming Languages, and she is a member of IFIP WG 2.1 on Algorithmic Languages and Calculi. Her awards include a State University of New York Chancellor’s Award for Excellence in Scholarship and Creative Activities.

Contributors

Molham Aref earned a Bachelor’s degree in Computer Engineering (1989) and two Master’s degrees in Electrical Engineering (1990) and Computer Science (1991) from the Georgia Institute of Technology. He has more than 27 years of experience developing high-value enterprise analytical solutions across various industries, including retail, telco, and financial services. He started his career as a software engineer and scientist at AT&T and founded Relational AI, LogicBlox, Predictix, Optimi, and Brickstream.

Bart Bogaerts studied mathematics at the University of Leuven (KU Leuven), Belgium. His Master’s thesis was titled “Unieke factorisatie in reguliere lokale ringen (Unique Factorisation in Regular Local Rings)” and was supervised by Dr. Jan Schepers. He graduated summa cum laude in July 2011. In September 2011, he joined the DTAI (Declaratieve Talen en Artificiele Intelligentie/Declarative Languages and Artificial Intelligence) research group in the Department of Computer Science at KU Leuven to investigate knowledge representation and reasoning techniques, supervised by Prof. Dr. Marc Denecker.

As his research interests evolved, Prof. Dr. Joost Vennekens and Prof. Dr. Jan Van den Bussche became his co-supervisors. He defended his Ph.D. thesis, entitled “Groundedness in Logics with a Fixpoint Definition” in June 2015. He graduated with the congratulations of the examination board, which consisted among others of renowned researches Thomas Eiter and Gerhard Brewka. In September 2015, Bart Bogaerts joined the Computational Logic group of Aalto University (Espoo, Finland) to work with Tomi Janhunen, among others, on Logic Programming, SAT and QBF. In October 2016, he returned to his alma mater, KU Leuven, where he currently works as an FWO post-doctoral fellow.

Dr. Conrado Borraz-Sánchez has over 10 years of mathematical modeling experience, solving real-life decision-making problems with extensive computational experience in optimization methods, high-performance computing, and experimental design. After obtaining his doctorate from the University of Bergen, Norway, in 2010, Dr. Borraz-Sánchez held a postdoctoral position at Northwestern University (2011–2014) where he was engaged in multiple projects sponsored by the U.S. Department of Transportation and U.S. Class-I railroad companies on data analytics for track maintenance, scheduling and routing problems, infrastructure deployment of electric vehicle charging station problems, and WDM optical network problems. He also held a postdoctoral position at Los Alamos National Laboratory (2014–2016) where he developed mathematical-model-based approaches for Energy Infrastructure Planning projects sponsored by the U.S. Department of Energy, including natural gas and grid-power transmission, expansion, and design problems. Since 2016, Dr. Borraz-Sánchez has been part of an R&D group in one of the Big Four firms, KPMG, where his wide range of engagement projects includes developing and deploying solutions for Professional Sport Leagues like the National Basketball Association (NBA), the Women’s National Basketball Association (WNBA), the Major League Baseball (MLB), and the National Basketball League (NBL, Australia, and New Zealand).

Maurice Bruynooghe has been professor emeritus at the Katholieke Universiteit Leuven since October 2015. His Ph.D. work on logic programming was completed in 1979. It provided the foundation for starting a research group on Declarative Languages and Artificial Intelligence in the 1980s and for participating in several European ESPRIT projects. He supervised Luc De Raedt’s Ph.D. work on inductive logic programming and together they initiated the machine learning subgroup. His research interests cover the three research areas of the group: design, analysis, and implementation of declarative programming languages; knowledge representation and reasoning; and machine learning and data mining. He was Editor-in-Chief of the Journal of Logic Programming (1991–2000) and of Theory and Practice of Logic Programming (2001—2005); the latter journal started as a protest against the excessive price policy of Elsevier. He is a fellow of ECCAI, the European Coordinating Committee for Artificial Intelligence.

Henning Christiansen is a full professor of Computer Science at Roskilde University, Denmark. He obtained his Master’s degree from Aarhus University, Denmark, in 1981 and his Ph.D. from Roskilde University in 1988. His main interests include logic and constraint programming, abductive reasoning, probabilistic-logic models, language analysis, and artificial intelligence. He also works with artistic interactive installations and robots in scenic contexts.

Verónica Dahl is an Argentine/Canadian mother, computer scientist, musician, and writer, recognized as one of the 15 founders of the field of logic programming. She has contributed over 120 scientific publications in computational linguistics, logic programming, deductive knowledge bases, computational molecular biology and web-based virtual worlds. She received several awards for her scientific results in AI and three first prizes for her literary work.

Alessandro Dal Palù, Ph.D., is an Associate Professor and head of the Bachelor’s degree program in Computer Science at the University of Parma, Italy. Over the last 15 years, he has conducted research on protein structure prediction and constraint programming applications and has published over 40 papers on these topics. His research interests span from bioinformatics to high-performance computing and logic programming. He is one of the editors of the Constraint in Bioinformatics series of the Algorithms for Molecular Biology journal. He has conducted the Workshop on Constraint-Based Methods in Bioinformatics since 2005.

Broes De Cat is a researcher at Flanders Make (Belgium), working on automated reasoning in the context of industrial robotics and flexible assembly applications. Previously, he developed and analyzed software at OM Partners, a major supply chain software company. During his Ph.D., he worked on model expansion, focusing specifically on lazy approaches to increase scalability. He holds a Master’s degree in Civil Engineering-Computer Science (2009) and a Ph.D. in Computer Science (2014), both from KU Leuven.

Marc Denecker is a professor at KU Leuven and head of the Knowledge Representation and Reasoning research group in the department Computer Science. His research is on foundations for Knowledge Representation, logics for logic programming, nonmonotonic reasoning, and knowledge representation. His research is concerned with formal and informal semantics, methodology, inference, and applications. His group develops the IDP knowledge base system.

Agostino Dovier received his Ph.D. in Computer Science from the University of Pisa and is a professor of Computer Science at the University of Udine, Italy, where he is coordinating the bachelor and master’s degree programs in computer science. His research interests include logic and constraint programming, and computational biology. He served as general and program chair of the international conference of logic programming (2008, 2012) and as president of the Italian Association for Logic Programming (2012–2018). Since 2005, he has contributed to the organization of the Workshops on Constraint-Based Methods in Bioinformatics. He is a member of the editorial board of Theory and Practice of Logic Programming and of the constraints series of Algorithms for Molecular Biology.

Andrea Formisano is an associate professor of Computer Science in the Department of Mathematics and Computer Science at the University of Perugia, Italy. He received his Ph.D. in Computer Science at the University “La Sapienza” in Rome. His main research interests include computational logics, automated reasoning, knowledge representation and nonmonotonic reasoning, multi-agent systems, and GPU computing.

Gerda Janssens is a professor in the Department of Computer Science at KU Leuven. She has been a member of the Logic Programming group since the start of her research career. She obtained her Ph.D. in Computer Science (KU Leuven) in March 1990. She is a member of the Knowledge Representation and Reasoning group and is actively involved in the development of the FO(.)-KBS.

Diego Klabjan is a professor at Northwestern University, Department of Industrial Engineering and Management Sciences. He is also Founding Director of the Master of Science in Analytics program. After obtaining his doctorate in Algorithms, Combinatorics, and Optimization from the School of Industrial and Systems Engineering at the Georgia Institute of Technology in 1999, he joined the University of Illinois at Urbana-Champaign that same year. In 2007, he became an associate professor at Northwestern and, in 2012, was promoted to a full professor. His research is focused on machine learning, deep learning, and analytics with concentrations in finance, transportation, sport, and bioinformatics. Professor Klabjan has led projects with large companies such as Intel, Baxter, Allstate, AbbVie, FedEx Express, General Motors, and United Continental, among many others, and is assisting numerous start-ups with their analytics needs. He is also a founder of Opex Analytics LLC.

David Maier is the Maseeh Professor of Emerging Technologies at Portland State University. Prior to his current position, he was on the faculty at SUNY-Stony Brook and the Oregon Graduate Institute. He has spent extended visits with INRIA, University of Wisconsin–Madison, Microsoft Research, and the National University of Singapore. He is the author of books on relational databases, logic programming, and object-oriented databases, as well as papers in database theory, object-oriented technology, scientific databases, and data streams. He is a recognized expert on the challenges of large-scale data in the sciences. He received an NSF Young Investigator Award in 1984, the 1997 SIGMOD Innovations Award for his contributions in objects and databases, and a Microsoft Research Outstanding Collaborator Award in 2016. He is also an ACM Fellow and IEEE Senior Member. He holds a dual B.A. in Mathematics and Computer Science from the University of Oregon (Honors College, 1974) and a Ph.D. in Electrical Engineering and Computer Science from Princeton University (1978).

Emir Pasalic is a Director of Software Development at Infor. He has worked in the areas of type theory, programming languages, mathematical programming, databases, and machine learning. He was a postdoctoral fellow at the Rice University Department of Computer Science (2004–2007) and has worked at LogicBlox Inc. on implementing in-database linear programming systems (2007–present). He holds a Ph.D. in Computer Science from Oregon Health and Sciences University (OGI School of Engineering, 2004).

Enrico Pontelli is a Regents Professor of Computer Science and Dean of the College of Arts & Sciences at New Mexico State University. He received a Ph.D. in Computer Science from NMSU in 1997. His research interests are in computational logic, constraint programming, high-performance computing, knowledge representation and reasoning, bioinformatics, and assistive technologies. He is the recipient of a NSF CAREER award and he has raised over $16M in research funding in the last 15 years. He has published over 250 peer-reviewed papers and serves on the editorial boards of several journals.

C. R. Ramakrishnan is a professor in the Department of Computer Science at Stony Brook University. His research interests revolve around logic programming and formal methods. He works on various aspects of inference in logic programs, ranging from query evaluation in probabilistic logic programs to incremental evaluation. He also works on model checking concurrent systems, such as mobile systems, and expressive logics for specifying properties of such systems. His research has been consistently funded by grants from the NSF and the ONR.

Fabrizio Riguzzi is an associate professor of Computer Science in the Department of Mathematics and Computer Science at the University of Ferrara. He was previously an assistant professor at the same university. He earned his Master’s degree and Ph.D. in Computer Engineering from the University of Bologna. Dr. Riguzzi is the Editor-in-Chief of Intelligenza Artificiale, the official journal of the Italian Association for Artificial Intelligence. He is the author of more than 150 papers in the areas of machine learning, inductive logic programming, and statistical relational learning. His aim is to develop intelligent systems by combining in novel ways techniques from artificial intelligence, logic, and statistics.

K. Tuncay Tekle is a research assistant professor at Stony Brook University with a research focus on high-level programming languages and efficient implementations. After completing his Ph.D. thesis on the analysis and efficient implementation of Datalog queries under the supervision of Prof. Annie Liu, he has worked at LogicBlox, a company whose state-of-the-art Datalog engine helps solve complex enterprise problems. Apart from his research work, he is a software consultant solving database-centric problems for top retail companies.

Miroslaw Truszczynski is a professor of computer science at the University of Kentucky. Truszczynski’s research interests include knowledge representation, nonmonotonic reasoning, logic programming, and constraint satisfaction and programming. He has authored and co-authored more than 190 technical papers in journals, conference proceedings, and books, and is a co-author of the research monograph Nonmonotonic Logic on mathematical foundations of nonmonotonic reasoning, which marked a milestone in the development of that area. He is one of the founders of the field of answer-set programming. In 2013, Truszczynski was elected Fellow of the Association for the Advancement of Artificial Intelligence (AAAI).

Dr. Theresa Swift has over 25 years of experience in computational logic research and the design and development of major computer systems. She led the development of the XSB Programming system, a major open-source Prolog. As a researcher, Dr. Swift has published more than 75 articles in major refereed journals and conferences and edited three books. Her research interests include high-performance logic systems, nonmonotonic reasoning and reasoning under uncertainty, and knowledge representation.

David S. Warren is Professor Emeritus at Stony Brook University and Vice President of Sciences at XSB, Inc. His entire research career has been in the area of logic programming, including theory, systems, and applications. He is the author of more than 100 technical papers in the area and has served as President of the Association for Logic Programming. He is the leader of the XSB project that has developed and supported the open source XSB Tabled Prolog system, which has been the leading tabled logic programming system for the last 25 years. He is a Fellow of the ACM, past chair of the Stony Brook Computer Science Department, and advisor of 20 Ph.D. students. He is co-founder of XSB, Inc., a 20-year-old software company that commercializes applications supported by the XSB Prolog system.