Peter Flach | http://www.cs.bris.ac.uk/~flach/SimplyLogical.html

Interactive lab examples

Simply Logical

Chapter 2: Clausal logic and resolution:
theoretical backgrounds

Syntax, semantics, and proof theory

In this chapter we develop a more formal view of Logic Programming by means of a rigorous treatment of clausal logic and resolution theorem proving. Any such treatment has three parts: syntax, semantics, and proof theory.

  • Syntax defines the logical language we are using, i.e. the alphabet, different kinds of ‘words’, and the allowed ‘sentences’.

Syntax, semantics, and proof theory (ctd.)

  • Semantics defines, in some formal way, the meaning of words and sentences in the language. As with most logics, semantics for clausal logic is truth-functional, i.e. the meaning of a sentence is defined by specifying the conditions under which it is assigned certain truth values (in our case: true or false).
  • Finally, proof theory specifies how we can obtain new sentences (theorems) from assumed ones (axioms) by means of pure symbol manipulation (inference rules).
  • Soundness and completeness

    Of these three, proof theory is most closely related to Logic Programming, because answering queries is in fact no different from proving theorems. In addition to proof theory, we need semantics for deciding whether the things we prove actually make sense. For instance, we need to be sure that the truth of the theorems is assured by the truth of the axioms. If our inference rules guarantee this, they are said to be sound.

    Soundness and completeness (ctd.)

    But this will not be enough, because sound inference rules can be actually very weak, and unable to prove anything of interest. We also need to be sure that the inference rules are powerful enough to eventually prove any possible theorem: they should be complete.

    Meta-theory

    Concepts like soundness and completeness are called meta-theoretical, since they are not expressed in the logic under discussion, but rather belong to a theory about that logic (‘meta’ means above). Their significance is not merely theoretical, but extends to logic programming languages like Prolog. For example, if a logic programming language is unsound, it will give wrong answers to some queries; if it is incomplete, it will give no answer to some other queries.

    Meta-theory (ctd.)

    Ideally, a logic programming language should be sound and complete; in practice, this will not be the case. For instance, in the next chapter we will see that Prolog is both unsound and incomplete. This has been a deliberate design choice: a sound and complete Prolog would be much less efficient. Nevertheless, any Prolog programmer should know exactly the circumstances under which Prolog is unsound or incomplete, and avoid these circumstances in her programs.

    What this chapter is about

    The structure of this chapter is as follows. We start with a very simple (propositional) logical language, and enrich this language in two steps to full clausal logic. For each of these three languages, we discuss syntax, semantics, proof theory, and meta-theory. We then discuss definite clause logic, which is the subset of clausal logic used in Prolog. Finally, we relate clausal logic to Predicate Logic, and show that they are essentially equal in expressive power.

    2.1 Propositional clausal logic

    Propositions

    Informally, a proposition is any statement which is either true or false, such as ‘2 + 2 = 4’ or ‘the moon is made of green cheese’. These are the building blocks of propositional logic, the weakest form of logic.

    Propositional Syntax

    Atoms and clauses

    Propositions are abstractly denoted by atoms, which are single words starting with a lowercase character. For instance, married is an atom denoting the proposition ‘he/she is married’; similarly, man denotes the proposition ‘he is a man’. Using the special symbols ‘ :- ’ (if), ‘ ; ’ (or) and ‘ , ’ (and), we can combine atoms to form clauses.

    Atoms and clauses (ctd.)

    For instance,

    married;bachelor:-man,adult
    

    is a clause, with intended meaning: ‘somebody is married or a bachelor if he is a man and an adult’ [2] . The part to the left of the if-symbol ‘ :- ’ is called the head of the clause, and the right part is called the body of the clause. The head of a clause is always a disjunction (or) of atoms, and the body of a clause is always a conjunction (and).

    Atoms and clauses (ctd.)

    Exercise 2.1.

    Translate the following statements into clauses, using the atoms person, sad and happy:

    1. persons are happy or sad;
    2. no person is both happy and sad;
    3. sad persons are not happy;
    4. non-happy persons are sad.

    Programs

    A program is a set of clauses, each of them terminated by a period. The clauses are to be read conjunctively; for example, the program

    woman;man:-human.
    human:-woman.
    human:-man.
    

    has the intended meaning ‘(if someone is human then she/he is a woman or a man) and (if someone is a woman then she is human) and (if someone is a man then he is human)’, or, in other words, ‘someone is human if and only if she/he is a woman or a man’.

    Propositional Semantics

    Herbrand base and interpretation

    The Herbrand base of a program P is the set of atoms occurring in P. For the above program, the Herbrand base is { woman, man, human }. A Herbrand interpretation (or interpretation for short) for P is a mapping from the Herbrand base of P into the set of truth values { true, false }. For example, the mapping { womantrue, manfalse, humantrue } is a Herbrand interpretation for the above program. A Herbrand interpretation can be viewed as describing a possible state of affairs in the Universe of Discourse (in this case: ‘she is a woman, she is not a man, she is human’).

    Herbrand base and interpretation (ctd.)

    Since there are only two possible truth values in the semantics we are considering, we could abbreviate such mappings by listing only the atoms that are assigned the truth value true; by definition, the remaining ones are assigned the truth value false. Under this convention, which we will adopt in this book, a Herbrand interpretation is simply a subset of the Herbrand base. Thus, the previous Herbrand interpretation would be represented as { woman, human }.

    Truth conditions

    Since a Herbrand interpretation assigns truth values to every atom in a clause, it also assigns a truth value to the clause as a whole. The rules for determining the truth value of a clause from the truth values of its atoms are not so complicated, if you keep in mind that the body of a clause is a conjunction of atoms, and the head is a disjunction. Consequently, the body of a clause is true if every atom in it is true, and the head of a clause is true if at least one atom in it is true.

    Truth conditions (ctd.)

    In turn, the truth value of the clause is determined by the truth values of head and body. There are four possibilities:

    1. the body is true, and the head is true;
    2. the body is true, and the head is false;
    3. the body is false, and the head is true;
    4. the body is false, and the head is false.

    The intended meaning of the clause is ‘ if body then head’, which is obviously true in the first case, and false in the second case.

    Positive and negative literals

    What about the remaining two cases? They cover statements like ‘ if the moon is made of green cheese then 2 + 2 = 4’, in which there is no connection at all between body and head. One would like to say that such statements are neither true nor false. However, our semantics is not sophisticated enough to deal with this: it simply insists that clauses should be assigned a truth value in every possible interpretation. Therefore, we consider the clause to be true whenever its body is false.

    Positive and negative literals (ctd.)

    It is not difficult to see that under these truth conditions a clause is equivalent with the statement ‘head or not body’. For example, the clause married;bachelor:-man,adult can also be read as ‘someone is married or a bachelor or not a man or not an adult’. Thus, a clause is a disjunction of atoms, which are negated if they occur in the body of the clause. Therefore, the atoms in the body of the clause are often called negative literals, while those in the head of the clause are called positive literals.

    Summary so far

    To summarise: a clause is assigned the truth value true in an interpretation, if and only if at least one of the following conditions is true: (a) at least one atom in the body of the clause is false in the interpretation (cases (3) and (4)), or (b) at least one atom in the head of the clause is true in the interpretation (cases (1) and (3)). If a clause is true in an interpretation, we say that the interpretation is a model for the clause.

    Summary so far (ctd.)

    An interpretation is a model for a program if it is a model for each clause in the program. For example, the above program has the following models: ∅ (the empty model, assigning false to every atom), { woman, human }, { man, human }, and { woman, man, human }. Since there are eight possible interpretations for a Herbrand base with three atoms, this means that the program contains enough information to rule out half of these.

    Logical consequence

    Adding more clauses to the program means restricting its set of models. For instance, if we add the clause woman (a clause with an empty body) to the program, we rule out the first and third model, which leaves us with the models { woman, human }, and { woman, man, human }. Note that in both of these models, human is true. We say that human is a logical consequence of the set of clauses. In general, a clause C is a logical consequence of a program P if every model of the program is also a model of the clause; we write PC.

    Logical consequence (ctd.)

    Exercise 2.2.

    Given the program

    married;bachelor:-man,adult. man. :-bachelor. determine which of the following clauses are logical consequences of this program:
    1. married:-adult; 2. married:-bachelor; 3. bachelor:-man; 4. bachelor:-bachelor.

    Intended model

    Of the two remaining models, obviously { woman, human } is the intended one; but the program does not yet contain enough information to distinguish it from the non-intended model { woman, man, human }. We can add yet another clause, to make sure that the atom man is mapped to false. For instance, we could add

    :-man
    

    (it is not a man) or

    :-man,woman
    

    (nobody is both a man and a woman).

    Intended model (ctd.)

    However, explicitly stating everything that is false in the intended model is not always feasible. Consider, for example, an airline database consulted by travel agencies: we simply want to say that if a particular flight (i.e., a combination of plane, origin, destination, date and time) is not listed in the database, then it does not exist, instead of listing all the dates that a particular plane does not fly from Amsterdam to London.

    Minimal model

    So, instead of adding clauses until a single model remains, we want to add a rule to our semantics which tells us which of the several models is the intended one. The airline example shows us that, in general, we only want to accept something as true if we are really forced to, i.e. if it is true in every possible model. This means that we should take the intersection of every model of a program in order to construct the intended model. In the example, this is { woman, human }. Note that this model is minimal in the sense that no subset of it is also a model. Therefore, this semantics is called a minimal model semantics.

    Indefinite clauses

    Unfortunately, this approach is only applicable to a restricted class of programs. Consider the following program:

    woman;man:-human.
    human.
    

    This program has three models: { woman, human }, { man, human }, and { woman, man, human }. The intersection of these models is { human }, but this interpretation is not a model of the first clause! The program has in fact not one, but two minimal models, which is caused by the fact that the first clause has a disjunctive head. Such a clause is called indefinite, because it does not permit definite conclusions to be drawn.

    Definite clauses

    On the other hand, if we would only allow definite clauses, i.e. clauses with a single positive literal, minimal models are guaranteed to be unique. We will deal with definite clauses in section 2.4, because Prolog is based on definite clause logic. In principle, this means that clauses like woman;man:-human are not expressible in Prolog. However, such a clause can be transformed into a ‘pseudo-definite’ clause by moving one of the literals in the head to the body, extended with an extra negation.

    Definite clauses (ctd.)

    This gives the following two possibilities:

    woman:-human,not(man).
    man:-human,not(woman).
    

    In Prolog, we have to choose between these two clauses, which means that we have only an approximation of the original indefinite clause. Negation in Prolog is an important subject with many aspects. In Chapter 3, we will show how Prolog handles negation in the body of clauses. In Chapter 8, we will discuss particular applications of this kind of negation.

    Propositional Proof theory

    Computing logical consequence

    Recall that a clause C is a logical consequence of a program P (PC) if every model of P is a model of C. Checking this condition is, in general, unfeasible. Therefore, we need a more efficient way of computing logical consequences, by means of inference rules. If C can be derived from P by means of a number of applications of such inference rules, we say that C can be proved from P. Such inference rules are purely syntactic, and do not refer to any underlying semantics.

    Resolution

    The proof theory for clausal logic consists of a single inference rule called resolution. Resolution is a very powerful inference rule. Consider the following program:

    married;bachelor:-man,adult.
    has_wife:-man,married.
    

    This simple program has no less than 26 models, each of which needs to be considered if we want to check whether a clause is a logical consequence of it.

    Resolution (ctd.)

    Exercise 2.3.

    Write down the six Herbrand interpretations that are not models of the program.

    Resolving upon a literal

    The following clause is a logical consequence of this program:

    has_wife;bachelor:-man,adult
    

    By means of resolution, it can be produced in a single step. This step represents the following line of reasoning: ‘if someone is a man and an adult, then he is a bachelor or married; but if he is married, he has a wife; therefore, if someone is a man and an adult, then he is a bachelor or he has a wife’.

    Resolving upon a literal (ctd.)

    In this argument, the two clauses in the program are related to each other by means of the atom married, which occurs in the head of the first clause (a positive literal) and in the body of the second (a negative literal). The derived clause, which is called the resolvent, consists of all the literals of the two input clauses, except married (the literal resolved upon). The negative literal man, which occurs in both input clauses, appears only once in the derived clause. This process is depicted in fig. 2.1.

    Resolving upon a literal (ctd.)

    Figure 2.1.

    A resolution step.

    Unfolding

    Resolution is most easily understood when applied to definite clauses. Consider the following program:

    square:-rectangle,equal_sides.
    rectangle:-parallelogram,right_angles.
    

    Applying resolution yields the clause

    square:-parallelogram,right_angles,equal_sides
    

    Unfolding (ctd.)

    That is, the atom rectangle in the body of the first clause is replaced by the body of the second clause (which has rectangle as its head). This process is also referred to as unfolding the second clause into the first one (fig. 2.2).

    Figure 2.2.

    Resolution with definite clauses.

    Derivation

    A resolvent resulting from one resolution step can be used as input for the next. A proof or derivation of a clause C from a program P is a sequence of clauses such that each clause is either in the program, or the resolvent of two previous clauses, and the last clause is C. If there is a proof of C from P, we write PC.

    Derivation (ctd.)

    Exercise 2.4.

    Give a derivation of friendly from the following program:

    happy;friendly:-teacher. friendly:-teacher,happy. teacher;wise. teacher:-wise.

    Propositional Meta-theory

    Soundness of propositional resolution

    It is easy to show that propositional resolution is sound: you have to establish that every model for the two input clauses is a model for the resolvent. In our earlier example, every model of married;bachelor:-man,adult and has_wife:-man,married must be a model of has_wife;bachelor:-man,adult.

    Soundness of propositional resolution (ctd.)

    Now, the literal resolved upon (in this case married) is either assigned the truth value true or false. In the first case, every model of has_wife:-man,married is also a model of has_wife:-man; in the second case, every model of married;bachelor:-man,adult is also a model of bachelor:-man,adult. In both cases, these models are models of a subclause of the resolvent, which means that they are also models of the resolvent itself.

    Incompleteness of propositional resolution

    In general, proving completeness is more complicated than proving soundness. Still worse, proving completeness of resolution is impossible, because resolution is not complete at all!

    Incompleteness of propositional resolution (ctd.)

    For instance, consider the clause a:-a. This clause is a so-called tautology: it is true under any interpretation. Therefore, any model of an arbitrary program P is a model for it, and thus P = a:-a for any program P. If resolution were complete, it would be possible to derive the clause a:-a from some program P in which the literal a doesn’t even occur! It is clear that resolution is unable to do this.

    A form of completeness

    However, this is not necessarily bad, because although tautologies follow from any set of clauses, they are not very interesting. Resolution makes it possible to guide the inference process, by implementing the question ‘is C a logical consequence of P?’ rather than ‘what are the logical consequences of P?’.

    A form of completeness (ctd.)

    We will see that, although resolution is unable to generate every logical consequence of a set of clauses, it is complete in the sense that resolution can always determine whether a specific clause is a logical consequence of a set of clauses.

    Reduction to the absurd

    The idea is analogous to a proof technique in mathematics called ‘reduction to the absurd’. Suppose for the moment that C consists of a single positive literal a; we want to know whether Pa, i.e. whether every model of P is also a model of a. It is easily checked that an interpretation is a model of a if, and only if, it is not a model of :-a.

    Reduction to the absurd (ctd.)

    Therefore, every model of P is a model of a if, and only if, there is no interpretation which is a model of both :-a and P. In other words, a is a logical consequence of P if, and only if, :-a and P are mutually inconsistent (don’t have a common model). So, checking whether Pa is equivalent to checking whether P ∪ { :-a } is inconsistent.

    Proof by refutation

    Resolution provides a way to check this condition. Note that, since an inconsistent set of clauses doesn’t have a model, it trivially satisfies the condition that any model of it is a model of any other clause; therefore, an inconsistent set of clauses has every possible clause as its logical consequence. In particular, the absurd or empty clause, denoted by □ [3] , is a logical consequence of an inconsistent set of clauses. Conversely, if □ is a logical consequence of a set of clauses, we know it must be inconsistent.

    Proof by refutation (ctd.)

    Now, resolution is complete in the sense that if P set of clauses is inconsistent, it is always possible to derive □ by resolution. Since resolution is sound, we already know that if we can derive □ then the input clauses must be inconsistent. So we conclude: a is a logical consequence of P if, and only if, the empty clause can be deduced by resolution from P augmented with :-a. This process is called proof by refutation, and resolution is called refutation complete.

    Proving a clause by refutation

    This proof method can be generalised to the case where B is not a single atom. For instance, let us check by resolution that a:-a is a tautology, i.e. a logical consequence of any set of clauses. Logically speaking, this clause is equivalent to ‘ a or not a ’, the negation of which is ‘ not a and a ’, which is represented by two separate clauses :-a and a. Since we can derive the empty clause from these two clauses in a single resolution step without using any other clauses, we have in fact proved that a:-a is a logical consequence of an empty set of clauses, hence a tautology.

    Proving a clause by refutation (ctd.)

    Exercise 2.5.

    Prove by refutation that friendly:-has_friends is a logical consequence of the following clauses:

    happy:-has_friends. friendly:-happy.

    Proving consistency is harder

    Finally, we mention that although resolution can always be used to prove inconsistency of a set of clauses it is not always fit to prove the opposite, i.e. consistency of a set of clauses. For instance, a is not a logical consequence of a:-a; yet, if we try to prove the inconsistency of :-a and a:-a (which should fail) we can go on applying resolution forever!

    Proving consistency is harder (ctd.)

    The reason, of course, is that there is a loop in the system: applying resolution to :-a and a:-a again yields :-a. In this simple case it is easy to check for loops: just maintain a list of previously derived clauses, and do not proceed with clauses that have been derived previously.

    Decidability

    However, as we will see, this is not possible in the general case of full clausal logic, which is semi-decidable with respect to the question ‘is B a logical consequence of A ’: there is an algorithm which derives, in finite time, a proof if one exists, but there is no algorithm which, for any A and B, halts and returns ‘no’ if no proof exists. The reason for this is that interpretations for full clausal logic are in general infinite. As a consequence, some Prolog programs may loop forever (just like some Pascal programs).

    Decidability (ctd.)

    One might suggest that it should be possible to check, just by examining the source code, whether a program is going to loop or not, but, as Alan Turing showed, this is, in general, impossible (the Halting Problem). That is, you can write programs for checking termination of programs, but for any such termination checking program you can write a program on which it will not terminate itself!

    2.2 Relational clausal logic

    Why we need variables

    Propositional clausal logic is rather coarse-grained, because it takes propositions (i.e. anything that can be assigned a truth value) as its basic building blocks. For example, it is not possible to formulate the following argument in propositional logic:

    Peter likes all his students
    Maria is one of Peter’s students
    Therefore, Peter likes Maria

    Why we need variables (ctd.)

    In order to formalise this type of reasoning, we need to talk about individuals like Peter and Maria, sets of individuals like Peter’s students, and relations between individuals, such as ‘likes’. This refinement of propositional clausal logic leads us into relational clausal logic.

    Relational Syntax

    Constants, variables, and terms

    Individual names are called constants; we follow the Prolog convention of writing them as single words starting with a lowercase character (or as arbitrary strings enclosed in single quotes, like 'this is a constant'). Arbitrary individuals are denoted by variables, which are single words starting with an uppercase character. Jointly, constants and variables are denoted as terms. A ground term is a term without variables [4] .

    Predicates

    Relations between individuals are abstractly denoted by predicates (which follow the same notational conventions as constants). An atom is a predicate followed by a number of terms, enclosed in brackets and separated by commas, e.g. likes(peter,maria). The terms between brackets are called the arguments of the predicate, and the number of arguments is the predicate’s arity. The arity of a predicate is assumed to be fixed, and predicates with the same name but different arity are assumed to be different. A ground atom is an atom without variables.

    Clauses and programs

    All the remaining definitions pertaining to the syntax of propositional clausal logic, in particular those of literal, clause and program, stay the same. So, the following clauses are meant to represent the above statements:

    likes(peter,S):-student_of(S,peter).
    student_of(maria,peter).
      

    Clauses and programs (ctd.)

    The intended meaning of these clauses are, respectively, ‘ if S is a student of Peter then Peter likes S ’, ‘Maria is a student of Peter’, and ‘Peter likes Maria’. Clearly, we want our logic to be such that the third clause follows logically from the first two, and we want to be able to prove this by resolution. Therefore, we must extend the semantics and proof theory in order to deal with variables.

    Relational Semantics

    Herbrand universe and Herbrand base

    The Herbrand universe of a program P is the set of ground terms (i.e. constants) occurring in it. For the above program, the Herbrand universe is { peter, maria }. The Herbrand universe is the set of all individuals we are talking about in our clauses. The Herbrand base of P is the set of ground atoms that can be constructed using the predicates in P and the ground terms in the Herbrand universe. This set represents all the things we can say about the individuals in the Herbrand universe.

    Herbrand interpretation

    The Herbrand base of the above program is

    { likes(peter,peter), likes(peter,maria),
      likes(maria,peter), likes(maria,maria),
      student_of(peter,peter), student_of(peter,maria),
      student_of(maria,peter), student_of(maria,maria) }
    

    As before, a Herbrand interpretation is the subset of the Herbrand base whose elements are assigned the truth value true. For instance,

    {likes(peter,maria), student_of(maria,peter)}
    

    is an interpretation of the above program.

    Substitutions

    Clearly, we want this interpretation to be a model of the program, but now we have to deal with the variables in the program. A substitution is a mapping from variables to terms. For example, { Smaria } and { SX } are substitutions. A substitution can be applied to a clause, which means that all occurrences of a variable occurring on the lefthand side in a substitution are replaced by the term on the righthand side.

    Substitutions (ctd.)

    For instance, if C is the clause

    likes(peter,S):-student_of(S,peter)
    

    then the above substitutions yield the clauses

    likes(peter,maria):-student_of(maria,peter)
    likes(peter,X):-student_of(X,peter)
    

    Notice that the first clause is ground; it is said to be a ground instance of C, and the substitution { Smaria } is called a grounding substitution. All the atoms in a ground clause occur in the Herbrand base, so reasoning with ground clauses is just like reasoning with propositional clauses.

    Substitutions (ctd.)

    An interpretation is a model for a non-ground clause if it is a model for every ground instance of the clause. Thus, in order to show that

    M = {likes(peter,maria), student_of(maria,peter)}
    

    is a model of the clause C above, we have to construct the set of the ground instances of C over the Herbrand universe { peter, maria }, which is

    { likes(peter,maria):-student_of(maria,peter),
      likes(peter,peter):-student_of(peter,peter) }
    

    and show that M is a model of every element of this set.

    Substitutions (ctd.)

    Exercise 2.6.

    How many models does C have over the Herbrand universe { peter, maria }?

    Relational Proof theory

    The need to avoid grounding

    Because reasoning with ground clauses is just like reasoning with propositional clauses, a naive proof method in relational clausal logic would apply grounding substitutions to every clause in the program before applying resolution. Such a method is naive, because a program has many different grounding substitutions, most of which do not lead to a resolution proof. For instance, if the Herbrand universe contains four constants, then a clause with two distinct variables has 16 different grounding substitutions, and a program consisting of three such clauses has 4096 different grounding substitutions.

    Resolution with variables

    Instead of applying arbitrary grounding substitutions before trying to apply resolution, we will derive the required substitutions from the clauses themselves. Recall that in order to apply propositional resolution, the literal resolved upon should occur in both input clauses (positive in one clause and negative in the other). In relational clausal logic, atoms can contain variables. Therefore, we do not require that exactly the same atom occurs in both clauses; rather, we require that there is a pair of atoms which can be made equal by substituting terms for variables.

    Resolution with variables (ctd.)

    For instance, let P be the following program:

    likes(peter,S):-student_of(S,peter).
    student_of(maria,T):-follows(maria,C),teaches(T,C).
    

    The second clause is intended to mean: ‘Maria is a student of any teacher who teaches a course she follows’. From these two clauses we should be able to prove that ‘Peter likes Maria if Maria follows a course taught by Peter’. This means that we want to resolve the two clauses on the student_of literals.

    Unification and unifiers

    The two atoms student_of(S,peter) and student_of(maria,T) can be made equal by replacing S by maria and T by peter, by means of the substitution { Smaria, Tpeter }. This process is called unification, and the substitution is called a unifier. Applying this substitution yields the following two clauses:

    likes(peter,maria):-student_of(maria,peter).
    student_of(maria,peter):-follows(maria,C),
                             teaches(peter,C).
    

    (Note that the second clause is not ground.)

    Unification and unifiers (ctd.)

    We can now construct the resolvent in the usual way, by dropping the literal resolved upon and combining the remaining literals, which yields the required clause

    likes(peter,maria):-follows(maria,C),teaches(peter,C).
    

    Unification and unifiers (ctd.)

    Exercise 2.7.

    Write a clause expressing that Peter teaches all the first-year courses, and apply resolution to this clause and the above resolvent.

    Logical consequence

    Consider the following two-clause program P′:

    likes(peter,S):-student_of(S,peter).
    student_of(X,T):-follows(X,C),teaches(T,C).
    

    which differs from the previous program P in that the constant maria in the second clause has been replaced by a variable. Since this generalises the applicability of this clause from Maria to any of Peter’s students, it follows that any model for P′ over a Herbrand universe including maria is also a model for P, and therefore P′ ⊧ P.

    Logical consequence (ctd.)

    In particular, this means that all the logical consequences of P′ are also logical consequences of P. For instance, we can again derive the clause

    likes(peter,maria):-follows(maria,C),teaches(peter,C).
    

    from P′ by means of the unifier { Smaria, Xmaria, Tpeter }.

    Generality

    Unifiers are not necessarily grounding substitutions: the substitution { XS, Tpeter } also unifies the two student_of literals, and the two clauses then resolve to

      likes(peter,S):-follows(S,C),teaches(peter,C).
    

    Generality (ctd.)

    The first unifier replaces more variables by terms than strictly necessary, while the second contains only those substitutions that are needed to unify the two atoms in the input clauses. As a result, the first resolvent is a special case of the second resolvent, that can be obtained by means of the additional substitution { Smaria }. Therefore, the second resolvent is said to be more general than the first [5] . Likewise, the second unifier is called a more general unifier than the first.

    Most general unifier

    As it were, more general resolvents summarise a lot of less general ones. It therefore makes sense to derive only those resolvents that are as general as possible, when applying resolution to clauses with variables. This means that we are only interested in a most general unifier (mgu) of two literals. Such an mgu, if it exists, is always unique, apart from an arbitrary renaming of variables (e.g. we could decide to keep the variable X, and replace S by X). If a unifier does not exist, we say that the two atoms are not unifiable. For instance, the atoms student_of(maria,peter) and student_of(S,maria) are not unifiable.

    Proof by refutation

    As we have seen before, the actual proof method in clausal logic is proof by refutation. If we succeed in deriving the empty clause, then we have demonstrated that the set of clauses is inconsistent under the substitutions that are needed for unification of literals.

    Proof by refutation (ctd.)

    For instance, consider the program

    likes(peter,S):-student_of(S,peter).
    student_of(S,T):-follows(S,C),teaches(T,C).
    teaches(peter,ai_techniques).
    follows(maria,ai_techniques).
      

    If we want to find out if there is anyone whom Peter likes, we add to the program the negation of this statement, i.e. ‘Peter likes nobody’ or :-likes(peter,N); this clause is called a query or a goal. We then try to refute this query by finding an inconsistency by means of resolution. A refutation proof is given in fig. 2.3.

    Proof by refutation (ctd.)

    Figure 2.3.

    A refutation proof which finds someone whom Peter likes.

    Proof by refutation (ctd.)

    In this figure, which is called a proof tree, two clauses on a row are input clauses for a resolution step, and they are connected by lines to their resolvent, which is then again an input clause for a resolution step, together with another program clause. The mgu’s are also shown. Since the empty clause is derived, the query is indeed refuted, but only under the substitution { Nmaria }, which constitutes the answer to the query.

    Multiple answers

    In general, a query can have several answers. For instance, suppose that Peter does not only like his students, but also the people his students like (and the people those people like, and …):

    likes(peter,S):-student_of(S,peter).
    likes(peter,Y):-likes(peter,X),likes(X,Y).
    likes(maria,paul).
    student_of(S,T):-follows(S,C),teaches(T,C).
    teaches(peter,ai_techniques).
    follows(maria,ai_techniques).
      

    The query

    ?-likes(peter,N).
      

    will now have two answers.

    Multiple answers (ctd.)

    Exercise 2.8.

    Draw the proof tree for the answer { Npaul }.

    Relational Meta-theory

    Everything is still finite

    As with propositional resolution, relational resolution is sound (i.e. it always produces logical consequences of the input clauses), refutation complete (i.e. it always detects an inconsistency in a set of clauses), but not complete (i.e. it does not always generate every logical consequence of the input clauses). An important characteristic of relational clausal logic is that the Herbrand universe (the set of individuals we can reason about) is always finite. Consequently, models are finite as well, and there are a finite number of different models for any program.

    Everything is still finite (ctd.)

    This means that, in principle, we could answer the question ‘is C a logical consequence of P?’ by enumerating all the models of P, and checking whether they are also models of C. The finiteness of the Herbrand universe will ensure that this procedure always terminates. This demonstrates that relational clausal logic is decidable, and therefore it is (in principle) possible to prevent resolution from looping if no more answers can be found. As we will see in the next section, this does not hold for full clausal logic.

    2.3 Full clausal logic

    Abstract names

    Relational logic extends propositional logic by means of the logical variable, which enables us to talk about arbitrary un-named individuals. However, consider the following statement:

    Everybody loves somebody.

    The only way to express this statement in relational clausal logic, is by explicitly listing every pair of persons such that the first loves the second, e.g.

    loves(peter,peter).
    loves(anna,paul).
    loves(paul,anna).
    

    Abstract names (ctd.)

    First of all, this is not a precise translation of the above statement into logic, because it is too explicit (e.g. the fact that Peter loves himself does not follow from the original statement). Secondly, this translation works only for finite domains, while the original statement also allows infinite domains. Many interesting domains are infinite, such as the set of natural numbers.

    Abstract names (ctd.)

    Full clausal logic allows us to reason about infinite domains by introducing more complex terms besides constants and variables. The above statement translates into full clausal logic as

    loves(X,person_loved_by(X))
    

    The fact loves(peter,person_loved_by(peter)) is a logical consequence of this clause. Since we know that everybody loves somebody, there must exist someone whom Peter loves.

    Abstract names (ctd.)

    We have given this person the abstract name

    person_loved_by(peter)
    

    without explicitly stating whom it is that Peter loves. As we will see, this way of composing complex names from simple names also gives us the possibility to reflect the structure of the domain in our logical formulas.

    Abstract names (ctd.)

    Exercise 2.9.

    Translate to clausal logic:

    1. every mouse has a tail;
    2. somebody loves everybody;
    3. every two numbers have a maximum.

    Full Clausal Syntax

    Complex terms

    A term is either simple or complex. Constants and variables are simple terms. A complex term is a functor (which follows the same notational conventions as constants and predicates) followed by a number of terms, enclosed in brackets and separated by commas, e.g. eldest_child_of(anna,paul). The terms between brackets are called the arguments of the functor, and the number of arguments is the functor’s arity. Again, a ground term is a term without variables. All the other definitions (atom, clause, literal, program) are the same as for relational clausal logic.

    Full Clausal Semantics

    Herbrand universe

    Although there is no syntactic difference in full clausal logic between terms and atoms, their meaning and use is totally different, a fact which should be adequately reflected in the semantics. A term always denotes an individual from the domain, while an atom denotes a proposition about individuals, which can get a truth value. Consequently, we must change the definition of the Herbrand universe in order to accomodate for complex terms: given a program P, the Herbrand universe is the set of ground terms that can be constructed from the constants and functors in P (if P contains no constants, choose an arbitrary one).

    Herbrand universe (ctd.)

    For instance, let P be the program

    plus(0,X,X).
    plus(s(X),Y,s(Z)):-plus(X,Y,Z).
      

    then the Herbrand universe of P is { 0, s(0), s(s(0)), s(s(s(0))), …}. Thus, as soon as a program contains a functor, the Herbrand universe (the set of individuals we can reason about) is an infinite set.

    Herbrand universe (ctd.)

    Exercise 2.10.

    Determine the Herbrand universe of the following program:

    listlength([],0).
    listlength([_X|Y],s(L)):-listlength(Y,L).
      

    (Hint: recall that [] is a constant, and that [X|Y] is an alternative notation for the complex term .(X,Y) with binary functor ‘ . ’!)

    Herbrand base

    The Herbrand base of P remains the set of ground atoms that can be constructed using the predicates in P and the ground terms in the Herbrand universe. For the above program, the Herbrand base is

    { plus(0,0,0), plus(s(0),0,0), …,
      plus(0,s(0),0), plus(s(0),s(0),0), …,
      …,
      plus(s(0),s(s(0)),s(s(s(0)))), … }
    

    Herbrand base (ctd.)

    As before, a Herbrand interpretation is a subset of the Herbrand base, whose elements are assigned the truth value true. For instance,

    { plus(0,0,0), plus(s(0),0,s(0)), plus(0,s(0),s(0)) }
    

    is an interpretation of the above program.

    Models

    Is this interpretation also a model of the program? As in the propositional case, we define an interpretation to be a model of a program if it is a model of every ground instance of every clause in the program. But since the Herbrand universe is infinite, there are an infinite number of grounding substitutions, hence we must generate the ground clauses in a systematic way, e.g.

    Models (ctd.)

    plus(0,0,0)
    plus(s(0),0,s(0)):-plus(0,0,0)
    plus(s(s(0)),0,s(s(0))):-plus(s(0),0,s(0))
    plus(s(s(s(0))),0,s(s(s(0)))):-plus(s(s(0)),0,s(s(0)))
    …
    plus(0,s(0),s(0))
    plus(s(0),s(0),s(s(0))):-plus(0,s(0),s(0))
    plus(s(s(0)),s(0),s(s(s(0)))):-plus(s(0),s(0),s(s(0)))
    …
    plus(0,s(s(0)),s(s(0)))
    plus(s(0),s(s(0)),s(s(s(0)))):-plus(0,s(s(0)),s(s(0)))
    plus(s(s(0)),s(s(0)),s(s(s(s(0))))):-plus(s(0),s(s(0)),s(s(s(0))))
    …
    

    Models (ctd.)

    Now we can reason as follows: according to the first ground clause, plus(0,0,0) must be in any model; but then the second ground clause requires that plus(s(0),0,s(0)) must be in any model, the third ground clause requires plus(s(s(0)),0,s(s(0))) to be in any model, and so on.

    Models (ctd.)

    Likewise, the second group of ground clauses demands that

    plus(0,s(0),s(0))
    plus(s(0),s(0),s(s(0)))
    plus(s(s(0)),s(0),s(s(s(0))))
    …
    

    are in the model; the third group of ground clauses requires that

    plus(0,s(s(0)),s(s(0)))
    plus(s(0),s(s(0)),s(s(s(0))))
    plus(s(s(0)),s(s(0)),s(s(s(s(0)))))
    …
    

    are in the model, and so forth.

    Infinite models

    In other words, every model of this program is necessarily infinite. Moreover, as you should have guessed by now, it contains every ground atom such that the number of s ’s in the third argument equals the number of s ’s in the first argument plus the number of s ’s in the second argument. The way we generated this infinite model is particularly interesting, because it is essentially what was called the naive proof method in the relational case: generate all possible ground instances of program clauses by applying every possible grounding substitution, and then apply (propositional) resolution as long as you can.

    Infinite models (ctd.)

    While, in the case of relational clausal logic, there inevitably comes a point where applying resolution will not give any new results (i.e. you reach a fixpoint), in the case of full clausal logic with infinite Herbrand universe you can go on applying resolution forever. On the other hand, as we saw above, we get a clear idea of what the infinite model [6] we’re constructing looks like, which means that it is still a fixpoint in some sense. There are mathematical techniques to deal with such infinitary fixpoints, but we will not dive into this subject here.

    Models can be finite

    Although the introduction of only a single functor already results in an infinite Herbrand universe, models are not necessarily infinite. Consider the following program:

    reachable(oxford,charing_cross,piccadilly).
    reachable(X,Y,route(Z,R)):-
      connected(X,Z,_L),
      reachable(Z,Y,R).
    connected(bond_street,oxford,central).
      

    with intended meaning ‘Charing Cross is reachable from Oxford Circus via Piccadilly Circus’, ‘ if X is connected to Z by line L and Y is reachable from Z via R then Y is reachable from X via a route consisting of Z and R ’ and ‘Bond Street is connected to Oxford Circus by the Central line’.

    Models can be finite (ctd.)

    The minimal model of this program is the finite set

    { connected(bond_street,oxford,central),
      reachable(oxford,charing_cross,piccadilly),
      reachable(bond_street,charing_cross,route(oxford,piccadilly)) }
    

    Full Clausal Proof theory

    Unification for complex terms

    Resolution for full clausal logic is very similar to resolution for relational clausal logic: we only have to modify the unification algorithm in order to deal with complex terms. For instance, consider the atoms

    plus(s(0),X,s(X))
    

    and

    plus(s(Y),s(0),s(s(Y)))
    

    Their mgu is { Y0, Xs(0) }, yielding the atom

    plus(s(0),s(0),s(s(0)))
    

    Unification for complex terms (ctd.)

    In order to find this mgu, we first of all have to make sure that the two atoms do not have any variables in common; if needed some of the variables should be renamed. Then, after making sure that both atoms contain the same predicate (with the same arity), we scan the atoms from left to right, searching for the first subterms at which the two atoms differ. In our example, these are 0 and Y.

    Unification for complex terms (ctd.)

    If one of these subterms is not a variable, then the two atoms are not unifiable; otherwise, substitute the other term for all occurrences of the variable in both atoms, and remember this partial substitution (in the above example: { Y0 }), because it is going to be part of the unifier we are constructing. Then, proceed with the next subterms at which the two atoms differ. Unification is finished when no such subterms can be found (the two atoms are made equal).

    The occur check

    Although the two atoms initially have no variables in common, this may change during the unification process. Therefore, it is important that, before a variable is replaced by a term, we check whether the variable already occurs in that term; this is called the occur check. If the variable does not occur in the term by which it is to be replaced, everything is in order and we can proceed; if it does, the unification should fail, because it would lead to circular substitutions and infinite terms.

    The occur check (ctd.)

    To illustrate this, consider again the clause

    loves(X,person_loved_by(X))
    

    We want to know whether this implies that someone loves herself; thus, we add the query :-loves(Y,Y) to this clause and try to apply resolution. To this end, we must unify the two atoms. The first subterms at which they differ are the first arguments, so we apply the partial substitution YX to the two atoms, resulting in

    loves(X,person_loved_by(X))
    

    and

    loves(X,X)
    

    The occur check (ctd.)

    The next subterms at which these atoms differ are their second arguments, one of which is a variable. Suppose that we ignore the fact that this variable, X, already occurs in the other term; we construct the substitution Xperson_loved_by(X). Now, we have reached the end of the two atoms, so unification has succeeded, we have derived the empty clause, and the answer to the query is

    X → person_loved_by(person_loved_by(person_loved_by(…)))
    

    which is an infinite term.

    Resolution without occur check is unsound

    Now we have two problems. The first is that we did not define any semantics for infinite terms, because there are no infinite terms in the Herbrand base. But even worse, the fact that there exists someone who loves herself is not a logical consequence of the above clause! That is, this clause has models in which nobody loves herself. So, unification without occur check would make resolution unsound.

    Resolution without occur check is unsound (ctd.)

    Exercise 2.11.

    If possible, unify the following pairs of terms:

    1. plus(X,Y,s(Y)) and plus(s(V),W,s(s(V)));
    2. length([X|Y],s(0)) and length([V],V);
    3. larger(s(s(X)),X) and larger(V,s(V)).

    Occur check omitted for practical reasons

    The disadvantage of the occur check is that it can be computationally very costly. Suppose that you need to unify X with a list of thousand elements, then the complete list has to be searched in order to check whether X occurs somewhere in it. Moreover, cases in which the occur check is needed often look somewhat exotic. Since the developers of Prolog were also taking the efficiency of the Prolog interpreter into consideration, they decided to omit the occur check from Prolog’s unification algorithm.

    Occur check omitted for practical reasons (ctd.)

    On the whole, this makes Prolog unsound; but this unsoundness only occurs in very specific cases, and it is the duty of the programmer to avoid such cases. In case you really need sound unification, most available Prolog implementations provide it as a library routine, but you must build your own Prolog interpreter in order to incorporate it. In Chapter 3, we will see that this is in fact amazingly simple: it can even be done in Prolog!

    Full Clausal Meta-theory

    Sound, refutation complete, semi-decidable

    Most meta-theoretical results concerning full clausal logic have already been mentioned. Full clausal resolution is sound (as long as unification is performed with the occur check), refutation complete but not complete. Moreover, due to the possibility of infinite interpretations full clausal logic is only semi-decidable: that is, if A is a logical consequence of B, then there is an algorithm that will check this in finite time; however, if A is not a logical consequence of B, then there is no algorithm which is guaranteed to check this in finite time for arbitrary A and B.Consequently, there is no general way to prevent Prolog from looping if no (further) answers to a query can be found.

    2.4 Definite clause logic

    Why definite clauses?

    In the foregoing three sections, we introduced and discussed three variants of clausal logic, in order of increasing expressiveness. In this section, we will show how an additional restriction on each of these variants will significantly improve the efficiency of a computational reasoning system for clausal logic. This is the restriction to definite clauses, on which Prolog is based.

    Why definite clauses? (ctd.)

    On the other hand, this restriction also means that definite clause logic is less expressive than full clausal logic, the main difference being that clausal logic can handle negative information. If we allow negated literals in the body of a definite clause then we obtain a so-called general clause, which is probably the closest we can get to full clausal logic without having to sacrifice efficiency.

    Indefinite clause example

    Consider the following program:

    married(X);bachelor(X):-man(X),adult(X).
    man(peter).
    adult(peter).
    :-married(maria).
    :-bachelor(maria).
    man(paul).
    :-bachelor(paul).
    

    There are many clauses that are logical consequences of this program. In particular, the following three clauses can be derived by resolution:

    married(peter);bachelor(peter)
    :-man(maria),adult(maria)
    married(paul):-adult(paul)
    

    Indefinite clause example (ctd.)

    Exercise 2.12.

    Draw the proof tree for each of these derivations.

    Direction in which clause is used

    In each of these derivations, the first clause in the program is used in a different way. In the first one, only literals in the body are resolved away; one could say that the clause is used from right to left. In the second derivation the clause is used from left to right, and in the third one literals from both the head and the body are resolved away. The way in which a clause is used in a resolution proof cannot be fixed in advance, because it depends on the thing we want to prove (the query in refutation proofs).

    Fixing direction from right to left

    On the other hand, this indeterminacy substantially increases the time it takes to find a refutation. Let us decide for the moment to use clauses only in one direction, say from right to left. That is, we can only resolve the negative literals away in a clause, as in the first derivation above, but not the positive literals. But now we have a problem: how are we going to decide whether Peter is married or a bachelor? We are stuck with a clause with two positive literals, representing a disjunctive or indefinite conclusion.

    Definite clause logic

    This problem can in turn be solved by requiring that clauses have exactly one positive literal, which leads us into definite clause logic. Consequently, a definite clause

    $$ A :- B_1,\ldots,B_n $$

    will always be used in the following way: $A$ is proved by proving each of $B_1$,…,$B_n$. This is called the procedural interpretation of definite clauses, and its simplicity makes the search for a refutation much more efficient than in the indefinite case. Moreover, it allows for an implementation which limits the amount of memory needed, as will be explained in more detail in Chapter 5.

    General clauses

    But how do we express in definite clause logic that adult men are bachelors or married? Even if we read the corresponding indefinite clause from right to left only, it basically has two different procedural interpretations:

    1. to prove that someone is married, prove that he is a man and an adult, and prove that he is not a bachelor;
    2. to prove that someone is a bachelor, prove that he is a man and an adult, and prove that he is not married.

    General clauses (ctd.)

    We should first choose one of these procedural interpretations, and then convert it into a ‘pseudo-definite’ clause. In case (1), this would be

    married(X):-man(X),adult(X),not bachelor(X)
    

    and case (2) becomes

    bachelor(X):-man(X),adult(X),not married(X)
    

    These clauses do not conform to the syntax of definite clause logic, because of the negation symbol not. We will call them general clauses.

    Dealing with negated literals

    If we want to extend definite clause logic to cover general clauses, we should extend resolution in order to deal with negated literals in the body of a clause. In addition, we should extend the semantics. This topic will be addressed in section 8.2. Without going into too much detail here, we will demonstrate that preferring a certain procedural interpretation corresponds to preferring a certain minimal model.

    Dealing with negated literals (ctd.)

    Reconsider the original indefinite clause

    married(X);bachelor(X):-man(X),adult(X)
    

    Supposing that john is the only individual in the Herbrand universe, and that man(john) and adult(john) are both true, then the models of this clause are

    {man(john),adult(john),married(john)}
    {man(john),adult(john),bachelor(john)}
    {man(john),adult(john),married(john),bachelor(john)}
    

    Dealing with negated literals (ctd.)

    Note that the first two models are minimal, as is characteristic for indefinite clauses. If we want to make the clause definite, we should single out one of these two minimal models as the intended model. If we choose the first model, in which John is married but not a bachelor, we are actually preferring the general clause

    married(X):-man(X),adult(X),not bachelor(X)
    

    Likewise, the second model corresponds to the general clause

    bachelor(X):-man(X),adult(X),not married(X)
    

    Dealing with negated literals (ctd.)

    Exercise 2.13.

    Write a clause for the statement ‘somebody is innocent unless proven guilty’, and give its intended model (supposing that john is the only individual in the Herbrand universe).

    Negation as failure

    An alternative approach to general clauses is to treat not as a special Prolog predicate, as will be discussed in the next chapter. This has the advantage that we need not extend the proof theory and semantics to incorporate general clauses. However, a disadvantage is that in this way not can only be understood procedurally.

    2.5 The relation between clausal logic and Predicate Logic

    Predicate Logic

    Clausal logic is a formalism especially suited for automated reasoning. However, the form of logic usually presented in courses on Symbolic Logic is (first-order) Predicate Logic. Predicate logic is more expressive in the sense that statements expressed in Predicate Logic often result in shorter formulas than would result if they were expressed in clausal logic.

    Predicate Logic (ctd.)

    This is due to the larger vocabulary and less restrictive syntax of Predicate Logic, which includes quantifiers (‘for all’ (∀) and ‘there exists’ (∃)), and various logical connectives (conjunction (∧), disjunction (∨), negation (¬), implication (→), and equivalence (↔)) which may occur anywhere within a formula.

    Semantic equivalence

    Being syntactically quite different, clausal logic and Predicate Logic are semantically equivalent in the following sense: every set of clauses is, after minor modifications, a formula in Predicate Logic, and conversely, every formula in Predicate Logic can be rewritten to an ‘almost’ equivalent set of clauses.

    Semantic equivalence (ctd.)

    Why then bother about Predicate Logic at all in this book? The main reason is that in Chapter 8, we will discuss an alternative semantics of logic programs, defined in terms of Predicate Logic. In this section, we will illustrate the semantic equivalence of clausal logic and Predicate Logic. We will assume a basic knowledge of the syntax and semantics of Predicate Logic.

    Propositional case

    We start with the propositional case. Any clause like

    married;bachelor:-man,adult
    

    can be rewritten by reversing head and body and replacing the ‘:-’ sign by an implication ‘→’, replacing ‘,’ by a conjunction ‘∧’, and replacing ‘;’ by a disjunction ‘∨’, which yields

    man ∧ adult → married ∨ bachelor
    

    Propositional case (ctd.)

    By using the logical laws AB ≡ ¬ AB and ¬ (CD) ≡ ¬ C ∨¬ D, this can be rewritten into the logically equivalent formula

    ¬man ∨ ¬adult ∨ married ∨ bachelor
    

    which, by the way, clearly demonstrates the origin of the terms negative literal and positive literal!

    Conjunctive normal form

    A set of clauses can be rewritten by rewriting each clause separately, and combining the results into a single conjunction, e.g.

    married;bachelor:-man,adult.
    has_wife:-man,married.
    

    becomes

    (¬man ∨ ¬adult ∨ married ∨ bachelor) ∧
    (¬man ∨ ¬married ∨ has_wife)
    

    Formulas like these, i.e. conjunctions of disjunctions of atoms and negated atoms, are said to be in conjunctive normal form (CNF).

    CNF is unique

    The term ‘normal form’ here indicates that every formula of Predicate Logic can be rewritten into a unique equivalent formula in conjunctive normal form, and therefore to a unique equivalent set of clauses.

    CNF is unique (ctd.)

    For instance, the formula

    (married ∨ ¬child) → (adult ∧ (man ∨ woman))
    

    can be rewritten into CNF as (replace AB by ¬AB, push negations inside by means of De Morgan’s laws: ¬(CD) ≡ ¬C ∨ ¬D and ¬(CD) ≡ ¬C ∧ ¬D, and distribute ∧ over ∨ by means of (AB) ∨ C ≡ (AC) ∧ (BC)):

    (¬married ∨ adult) ∧ (¬married ∨ man ∨ woman) ∧
    (child ∨ adult) ∧ (child ∨ man ∨ woman)
    

    and hence into clausal form as

    adult:-married.
    man;woman:-married.
    child;adult.
    child;man;woman.
    

    Full clausal logic

    For rewriting clauses from full clausal logic to Predicate Logic, we use the same rewrite rules as for propositional clauses. Additionally, we have to add universal quantifiers for every variable in the clause.

    Full clausal logic (ctd.)

    For example, the clause

    reachable(X,Y,route(Z,R)):-
        connected(X,Z,L),
        reachable(Z,Y,R).
    

    becomes

    XYZRL: ¬connected(X,Z,L) ∨ ¬reachable(Z,Y,R)reachable(X,Y,route(Z,R))

    From Predicate Logic to clauses

    The reverse process of rewriting a formula of Predicate Logic into an equivalent set of clauses is somewhat complicated if existential quantifiers are involved (the exact procedure is given as a Prolog program in Appendix B.1). An existential quantifier allows us to reason about individuals without naming them.

    From Predicate Logic to clauses (ctd.)

    For example, the statement ‘everybody loves somebody’ is represented by the Predicate Logic formula

    ∀X ∃Y: loves(X,Y)
    

    Recall that we translated this same statement into clausal logic as

    loves(X,person_loved_by(X))
    

    These two formulas are not logically equivalent! That is, the Predicate Logic formula has models like { loves(paul,anna) } which are not models of the clause.

    From Predicate Logic to clauses (ctd.)

    The reason for this is, that in clausal logic we are forced to introduce abstract names, while in Predicate Logic we are not (we use existential quantification instead). On the other hand, every model of the Predicate Logic formula, if not a model of the clause, can always be converted to a model of the clause, like { loves(paul,person_loved_by(paul)) }. Thus, we have that the formula has a model if and only if the clause has a model (but not necessarily the same model).

    Skolemisation

    So, existential quantifiers are replaced by functors. The arguments of the functor are given by the universal quantifiers in whose scope the existential quantifier occurs. In the above example, ∃ Y occurs within the scope of ∀ X, so we replace Y everywhere in the formula by person_loved_by(X), where person_loved_by should be a new functor, not occurring anywhere else in the clause (or in any other clause). This new functor is called a Skolem functor, and the whole process is called Skolemisation.

    Skolemisation (ctd.)

    Note that, if the existential quantifier does not occur inside the scope of a universal quantifier, the Skolem functor does not get any arguments, i.e. it becomes a Skolem constant. For example, the formula

    ∃X ∀Y: loves(X,Y)
    

    (‘somebody loves everybody’) is translated to the clause

    loves(someone_who_loves_everybody,X)
    

    An example

    Finally, we illustrate the whole process of converting from Predicate Logic to clausal logic by means of an example. Consider the sentence ‘Everyone has a mother, but not every woman has a child’. In Predicate Logic, this can be represented as

    ∀Y∃X: mother_of(X,Y) ∧ ¬∀Z∃W: woman(Z)→mother_of(Z,W)
    

    An example (ctd.)

    First, we push the negation inside by means of the equivalences ¬∀X: F ≡ ∃X: ¬F and ¬∃Y: G ≡ ∀Y: ¬G, and the previously given propositional equivalences, giving

    ∀Y∃X: mother_of(X,Y) ∧ ∃Z∀W: woman(Z) ∧ ¬mother_of(Z,W)
    

    An example (ctd.)

    The existential quantifiers are Skolemised: X is replaced by mother(Y), because it is in the scope of the universal quantifier ∀Y. Z, however, is not in the scope of a universal quantifier; therefore it is replaced by a Skolem constant childless_woman. The universal quantifiers can now be dropped:

    mother_of(mother(Y),Y) ∧
    woman(childless_woman) ∧ ¬mother_of(childless_woman,W)
    

    An example (ctd.)

    This formula is already in CNF, so we obtain the following set of clauses:

    mother_of(mother(Y),Y).
    woman(childless_woman).
    :-mother_of(childless_woman,W).
    

    An example (ctd.)

    Exercise 2.14.

    Translate to clausal logic:

    1. XY: mouse(X)tail_of(Y,X);
    2. XY: loves(X,Y)(Z: loves(Y,Z));
    3. XYZ: number(X)number(Y)maximum(X,Y,Z).

    Peter Flach | http://www.cs.bris.ac.uk/~flach/SimplyLogical.html