• Aucun résultat trouvé

The Logic of Prolog

Dans le document Prolog and Natural-Language Analysis D (Page 23-26)

This digital edition of Prolog and Natural-Language Analysis is distributed at no charge for noncommercial use by Microtome Publishing.

13

Exercise 2.2 Consider the following augmentation of the sample database:

professor(terry).

professor(roger).

professor(bertrand).

professor(gottlob).

concerns(shrdlu, blocks).

concerns(lunar, rocks).

concerns(sam, stories).

concerns(principia, logic).

concerns(principia, mathematics).

concerns(begriffsschrift, logic).

Write a Prolog clause that defines a logician as a professor who wrote a book con-cerning logic.

2.3 The Logic of Prolog

We have alluded to the relationship between database Prolog and first-order logical languages. In this section we describe this relationship in more detail, although still at an informal level.

First-order logic (FOL) is a logical language that includes predicate and function symbols and constants, from which are formed atomic formulas representing primitive propositions. An atomic formula is an expression of the form p(t1, . . . ,tk), where p is a predicate symbol of arity k applied to terms ti. A term is a constant, a variable, or a compound term f (t1, . . . ,tm), where f is a function symbol of arity m and the ti

are terms. Following standard practice, we will use letters p, q, r, etc. and upper case letters for predicate symbols and letters f, g, h, etc. for function symbols. Variables will be denoted by (possibly subscripted) x, y, z, etc. A term without variables is called a ground term. For the nonce, we will ignore the role of function symbols and compound terms in FOL, returning to them when we discuss the relation between FOL and full Prolog in the next chapter.

The well-formed formulas of FOL are defined inductively, starting with the atomic formulas and combining simpler formulas into larger formulas with operators from some sufficiently rich set, e.g., conjunction (∧), disjunction (∨), negation (¬), impli-cation (⇒), and universal (∀) and existential (∃) quantifiimpli-cation. Ifφandψare well-formed formulas and x is a variable, φ∧ψ(φ andψ), φ∨ψ(φ orψ),¬φ(not φ), φ ⇒ ψ (φimplies ψ) (∀x)φ(for every x, φ) and (∃x)φ(there is an x such that φ), with extra parenthesization to avoid ambiguity if necessary, are well-formed formulas.

Both in (∀x)φand (∃x)φ, the formulaφis the scope of the quantifier, and x is the vari-able bound by the quantifier. Closed well-formed formulas are those in which every variable occurrence is within the scope of a quantifier binding that variable.

Many important automated deduction methods, and in particular those from which Prolog is derived, do not operate on general FOL formulas, but only on formulas in clausal form (clauses). A formula is in clausal form if it is a disjunction of literals,

where a literal is an atomic formula or the negation of an atomic formula. All variables in the disjunction are universally quantified by quantifiers whose scope includes the whole disjunction. Thus, a clause can be written in the form

P0P1∨ · · · ∨ ¬N0∨ ¬N1∨ · · · .

The Piare positive literals; the¬Ni are negative literals. Note that we have left off the quantifiers, under the convention that all variables are quantified universally at the outermost level unless specified otherwise. The usefulness of clausal form stems from the fact that any closed formulaφcan be mechanically transformed into a conjunction of clausesPsuch thatφis inconsistent if and only ifPis. Notice that in generalφ andPare not equivalent, because the transformation into clausal form may require the introduction of auxiliary functions to remove existential quantifiers (so-called Skolem functions).3 However, as we will see below, the intended use of clausal form is in proofs by contradiction, so preservation of inconsistency is all we need.

Using deMorgan’s law

¬P∨ ¬Q if and only if¬(P∧Q)

and the definition of implication in terms of negation and disjunction, i.e., PQ if and only if¬P∨Q ,

we can reexpress clauses as a single implication

(N0N1∧ · · ·)⇒(P0P1∨ · · ·) .

The left-hand side of the implication is its antecedent, the right-hand side its conse-quent. Henceforth, we will refer to the Niand Pias the literals composing the clause, although, strictly speaking, the negative literals in the clause are of the form¬Ni, rather than Ni.

By expressing a clause as an implication as explained above, we see that a clause states that at least one of the atomic formulas in the consequent holds whenever all the atomic formulas in the antecedent hold. In particular, if a clause contains no negative literals, it will have an empty antecedent when written as an implication. Therefore an empty antecedent should be interpreted as standing for truth: The clause states that under all conditions at least one of the atomic formulas in the consequent holds. Con-versely, if a clause has no positive literals, it asserts that at least one of the formulas in its antecedent is false, that is, the conjunction of the atomic formulas in the antecedent is false. When written as an implication, such a clause has an empty consequent. An implication is equivalent to the negation of its antecedent provided that its consequent is false. Thus an empty consequent corresponds to falsity. Finally, the empty clause, with empty antecedent and consequent, corresponds to the implication truefalse, which is equivalent to false.

Theorem-proving in first-order logic—and hence clausal form FOL—is a compu-tationally difficult task and an area of active research. As we indicated in Section 1.2, for computational feasibility Prolog is not based on full clausal form, but on a strictly less expressive subset, Horn clauses, which are clauses with at most one positive lit-eral. Thus there are only three types of Horn clauses:

3Thus even a formula without function symbols may be transformed into a clause with function symbols, outside the database subset we have been considering. But since the subset is just a stopping-offpoint to full Prolog, and the arguments are meant to be indicative only, we will ignore this subtlety.

2.3. The Logic of Prolog

This digital edition of Prolog and Natural-Language Analysis is distributed at no charge for noncommercial use by Microtome Publishing.

15

Unit clauses: with one positive literal, no negative literals, i.e., of the form P0

(or, equivalently,⇒P0).

Nonunit clauses: with one positive literal, one or more negative literals, i.e., of the form P0∨ ¬N0∨ ¬N1∨ · · ·(or, equivalently, N0N1∧ · · · ⇒P0).

Negative clauses: with no positive literals, one or more negative literals, i.e., of the form¬N0∨ ¬N1∨ · · ·(or, equivalently, N0N1∧ · · · ⇒).

The first two types of Horn clauses are collectively referred to as definite clauses because they have exactly one positive literal—a single definite conclusion to the implication—unlike general clauses with their potentially disjunctive, indefinite, con-sequent.

Each type of Horn clause plays a different role in an axiomatization of a particular problem. Unit clauses, of the form P0, assert the truth of their consequents. We might call such clauses facts.

A nonunit clause states that its consequent is true if its antecedent is true. Such clauses thus serve as general rules by which the consequent can be determined to hold.

Finally, a negative clause

N0N1∧ · · · ⇒ has the equivalent form

¬(N0N1∧ · · ·) .

That is, a negative clause denies the truth of its antecedent. Negative clauses can be seen as queries as to under what conditions their antecedent is true, by the following reasoning. Suppose we have a set of facts and rulesP(a program) and a conjunction

N0N1∧ · · · . (2.1)

We want to determine values for the variables in (2.1) that make it a consequence of P. In other words, we want a constructive proof, fromP, of

(∃x0, . . . ,xk)(N0N1∧ · · ·) . (2.2) One way of attempting to prove (2.2) is by contradiction, that is, by showing that the conjunction of the clauses inPand the negation of (2.2) is inconsistent. From the inconsistency of the conjunction, we can infer that (2.2) follows fromPbecause P itself, being a set of definite clauses, cannot be inconsistent on its own.

Now, the negation of (2.2) can be put in the form

(∀x0, . . . ,xk)¬(N0N1∧ · · ·) (2.3)

which is just another notation for the negative clause

N0N1∧ · · · ⇒ . (2.4)

A constructive proof of the inconsistency of (2.3) withPwill provide a counterexam-ple for the universal statement (2.3). It will yield values v0, . . . ,vkfor the variables x0, . . . ,xksuch that

P ∧ ¬(N0N1∧ · · ·) (2.5)

with each visubstituted for xiis false.

The proof of falsity comes about because we are proving inconsistency of (2.3) withP. The actual values for the variables follows from the fact that the proof is constructive. It is easy to see from the proof of the falsity of (2.5) that (2.1) under that same substitution of values for variables is a consequence ofP. AssumePis true.

Then¬(N0N1∧ · · ·) must be false, and therefore (2.1) true, under the given values for variables. This concludes the constructive proof of the original existential query (2.2) from the programP. Thus (2.4) can be seen as a query about the truth of its antecedent (2.1) relative to the program.

This method of proving an existential statement is called refutation, because the proof proceeds by refuting the negation of the statement.

As we have seen, Prolog programs follow this paradigm exactly. Facts and rules, presented with the Prolog implication and conjunction operators “:-” and “,” respec-tively, are queried using a negative clause. The only difference is that the Prolog :-operator puts its antecedent and consequent “backwards”, that is,:-corresponds to

⇐, so that P⇒ Q is written as Q :- P and P⇒is written as:- P. A Prolog proof of a goal includes an assignment of values to variables in the goal which makes it a consequence of the program. It becomes apparent, then, why the notation “:- G” was chosen for queries. We are merely presenting the goal statement to Prolog directly in its negated form.

Exercise 2.3 (For the logically inclined.) Recall that the discussion above assumed that any set of definite clauses is consistent. Why is this so?

Dans le document Prolog and Natural-Language Analysis D (Page 23-26)