Declarative semantics

In this section we will investigate the model-theoretic properties of logic programs, that is how a logic program P is related to the world it is intended to describe.

Interpretations

\semindex{interpretations} For giving an interpretation I to a logic program P we have to define a domain of discourse D that contains the individuals of the world about which our program speaks and over which the variables occurring in our program range. Formally, we then have to define an assignment that assigns to each constant name a specific individual. Moreover, we must define for each function-symbol f a corresponding mapping and for each predicate-symbol p a relation on the domain D. Finally, we must then define an assignment of variables to bind variables to elements of D.

Models

\prologindex{models} \semindex{models} A given interpretation I is a model for a clause if it makes the clause true. Now, when is a clause true for a given interpretation? A clause [] A <- B1,...,B_n is true for an interpretation I if A is true for I whenever B1,...,B_n are true for I. To establish the truth of a literal, for example [] number(s(0)) we must relate the constant 0 to its intended interpretation, for which we take zero. Likewise we assign the functional expression s(0) the value one and check whether one is a natural number, which is our interpretation of the predicate number.

Quantification

\semindex{quantification} When variables occur in a literal the situation is slightly more complicated. Since we are not able to find a model for a clause that contains free variables we assume that each clause is universally quantified, since clauses are meant to express general statements. So, for example, the clause [] number(s(X)) <- number(X) must be read as [] \A X.(number(s(X)) <- number(X)) which generalizes the clause to hold for all X. In order to establish the truth of the clause we have to check for all elements of our domain, which are the natural numbers in this case, whether the clause holds when substituting this element for X. An extra complication arises when variables occur in the body of a clause that do not occur in the head of the clause. For example, the clause [] p(X) <- q(X,Y) stands for [] \A X Y.( p(X) <- q(X,Y)) generalizing the clause to hold for all X and Y. However, by another law of logic, this may be rewritten to [] \A X.(p(X) <- \E Y.q(X,Y)) where the variable Y that occurs only in the body of the clause is existentially quantified. This clause is true when for each assignment to X the literal p(X) holds whenever there is some assignment to Y that makes q(X,Y) true. Hence, a goal clause of the form [] <- G must be read as being existentially quantified. To establish the falsity of a goal clause containing variables it suffices to find some assignment of values to variables that makes G true.

Logical consequence

\semindex{logical consequence} Having defined when a clause is true for a given interpretation we may characterize a model of a program P as an interpretation that makes each clause in P true. If there exists a model for P we say that P is satisfiable. We call a formula G a logical consequence of P if every model of P is also a model of G. This is equivalent to saying that G is a logical consequence of P, if and only if P \u { \- G } is unsatisfiable, which is equivalent to saying that there is no interpretation that makes each clause in P \u { <- G } true. Hence, if we have a goal <- B1,...,B_n with variables Y1,...,Y_k then showing that P \u { <- B1,...,B_n } is unsatisfiable is exactly the same as showing that \E Y1 ... Y_k.(B1 /\ ... /\ B_n) is a logical consequence of P.

Herbrand models

\prologindex{Herbrand models} \semindex{Herbrand interpretations} \semindex{Herbrand models} The basic problem that we are confronted with to establish that a conjunction of literals G is a logical consequence of a program P is to determine whether P \u { <- G } is unsatisfiable, which amounts to showing that every interpretation of P \u { <- G } is not a model! Since there are arbitrarily many interpretations for each logical theory this seems to be an infeasible task. To manage the complexity of this task, we restrict our attention to a much smaller and more convenient class of interpretations, called Herbrand interpretations.\ftn{ After the logician Herbrand. See  [Ro65]. } As our domain of discourse we take the so-called Herbrand universe of a program P which are all the ground terms that can be constructed from the terms occurring in P. \semindex{ground terms} Ground terms are variable-free terms. We construct these ground terms by substituting constants and already-created ground terms for variables. There may be infinitely many ground terms. In case the program contains no constant we use an arbitrary constant to construct the Herbrand universe. \semindex{Herbrand universe} As an example, the Herbrand universe of the program \oprog{number}{
     number(0) <- 
     number(s(X)) <- number(X)
  
} is the set [] { 0, s(0), s(s(0)), ... } consisting of all the terms representing natural numbers. For defining the relations that correspond to the predicate-symbols occurring in the program we introduce the so-called Herbrand base which is the collection of all ground atoms that can be constructed from the literals occurring in the program. An atom is just a positive literal, that is a literal without negation sign. A ground atom is a variable-free atom. These atoms may be regarded as representing all possible facts. \semindex{Herbrand base} The Herbrand base corresponding to the program above, defining the natural numbers, is [] { number(0), number(s(0)), number(s(s(0))), ... } containing all possible atoms that express that a term is a number. A Herbrand model for a program P is a Herbrand interpretation that is a model for P. An important property of Herbrand models is that if a program P has a model then P also has a Herbrand model, since in a way Herbrand models are the least committing models. Because of this property, showing that a collection of clauses P \u { <- G } is unsatisfiable reduces to the task of showing that P \u { <- G } has no Herbrand model.

Answer substitutions

\prologindex{answer substitutions} \semindex{answer substitutions} When a goal G contains variables we are not only interested in whether P \u { G <- } is unsatisfiable, but also in what variables must be assigned to the variables to achieve this. A substitution %h is a set of the form { X1/t1,...,X_k/t_k} that binds each variable X_i to a value t_i, for i ranging from 1 to k. We say that %h is a ground substitution if each t_i is a ground term. When we apply a substitution to a conjunction of literals G, which we write as G%h, then each variable X_i occurring in G is replaced by the term t_i. Now, if we find a substitution %h for which { P \u { <- G%h } } has no Herbrand model then accordingly we have proven that G%h is a logical consequence of P. We call such a substitution a correct answer substitution. In general there may be more than one such substitution. From a logic programming point of view we are interested in all these bindings since they represent the output of evaluating a goal <- G.

Fixed points

\semindex{fixed points} A Herbrand interpretation of a program P may be thought of simply as a subset of the Herbrand base for P, since typically ground terms are assigned to themselves. The Herbrand models of Horn clause programs have a very special property, the so-called model intersection property that states: if { M_i } is the collection of Herbrand models for P then the intersection M_P = \cap _i M_i is also a Herbrand model of P. Moreover, M_P is the smallest model satisfying P. Herbrand models for programs consisting of general clauses do not have this property since, intuitively, the occurrence of multiple positive literals in a clause may give rise to multiple disjoint models. \semindex{least model} The least model M_P represents all the positive information that can be derived from a logic program P. This intuition allows us to characterize the least model in a convenient way by means of the so-called immediate consequence operator T_P. Let I stand for Herbrand interpretations, that is subsets of the Herbrand base for a particular program P. Then the immediate consequence operator T_P is defined as \semindex{\immediateconsequence} Applying T_P to a Herbrand interpretation I results in all the facts that can be derived by applying rules for which the premises are contained in the given interpretation I. We have that an interpretation I is a model of P whenever T_P(I) \subseteq I, that is I is a model when I already contains every fact that can be derived using I. We are looking for the least I satisfying this property or, which amounts to the same, for the least I satisfying T_P(I) = I, that is the least fixed point of T_P. The least fixed point of an operator T_P that is associated with a logic program P can intuitively be characterized by a bottom-up computation of all the (given and derivable) facts contained in the program P, that is by iterating the application of T_P, starting with the empty interpretation, until no more facts are added. The interested reader is referred to  [AvE82] for a more detailed treatment. As a last remark, this bottom-up characterization of the declarative semantics of a logic program P provides a link with the procedural interpretation of P that characterizes how facts may be proven in a top-down manner. See also  [EK76].