0% found this document useful (0 votes)
2K views27 pages

Logic & Theorem Proving Guide

The document describes logical agents and propositional theorem proving. It discusses inference rules like modus ponens and and-elimination that can be used to derive proofs without enumerating models. Validity, satisfiability, and logical equivalences are key concepts. As an example, it shows how to use the rules and equivalences to prove there is no pit in the cell [1,2] in the Wumpus world knowledge base.

Uploaded by

Suresh Mummina
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views27 pages

Logic & Theorem Proving Guide

The document describes logical agents and propositional theorem proving. It discusses inference rules like modus ponens and and-elimination that can be used to derive proofs without enumerating models. Validity, satisfiability, and logical equivalences are key concepts. As an example, it shows how to use the rules and equivalences to prove there is no pit in the cell [1,2] in the Wumpus world knowledge base.

Uploaded by

Suresh Mummina
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

AA 0,0"

~!!!J

' "

, , -

: .. ".

,

.. . .

>:

PEARSON

~ r~· ~. ~. _~

:~~~: ~ g 978-0 13-604259' 4

, 0-13 -604259- 7

,lllilOlir

a 335 .RB6 2010

248

Chapter 7.

Logical Agents

81.1 82.] p],! P],2 P2,! P2,2 P3,1 Rl R2 R3 14
R5 KB
fal,~e false faL~e false false false false true true true
false true false false
false false false false false true true true false
true false false
[alse true false false false false false true true
false true true false
faL~e true false false false false true true
faL~e true false false false true true true true true
false true false true true true true
true false false true true
false true true true true true
true true true
faL,e true false false true false false
true false false true true false
tnw true true true true true
true false true true false true false
~Igure 7.9 A truth table constructed for the k . .
if R] through Rs are true which occ .. 3 nowledge base given In the text. KB is true
. • urs 10 Just of the 128 (
nght-hand column). In all 3 rows P . f 1 rows the ones underlined in the
h . ' 1,2 IS a se so there is .. [
t ere might (or might not) be a pit in [2,2].' no pit in 1,2]. On the other hand, Figure 7.10 A truth-table e .

(IT stands for truth numeratIon algorithm f d "

variabl d I table.) PL- TRUE? returns t if or eciding propositional entailment.

e mo e represents a T\lU't;al rue! a sentence h ld ithi I Th

word "and" .r-~ model-an as . 0 s WI m a mode. e

IS used here as a logical operatI'on s].gnment to SOme of the symbols. The keyon Its two

arguments, returning true or false.

function TT-ENTAILS?(KB 0:) retu

i ,rns true or fals

nputs: KB, the knowledge base, a sentence i e ..

0, the query a sentenc . .. n proposItlonallogic

, em propos't]onallogic

symbols <- a list of the pro "

return TT_CHECK_ALL(issltIOn symbols in KB and 0:

. __ ._ .____ __ ,0:, symbols, { })

function TT-CHECK-ALL(KB

If EM PTY'?( symbols) then ' 0:, symbols, model) returns true or false

If PL- TRUE?(KB, model) then re

else return true /I when KB isfi I turn PL- TRUE?( 0:, model)

else do a se, always return true

p <- FJRST(.~ymbols)

n~st <- REST(symbols)

return (TT-CHECK-ALL(KB

and ,0:, rest, model u {P =0; true})

TT-CHECK-ALL(KB

,0:, rest, model u {P - false})

Section 7.5.

NO OVERNIGHT

R ... rve Area Usa ONLYIJ

Propositional Theorem Proving

249

(0: A {3) (0: V {3) ( (0: A {3) A --y ) ((0: V {3) V"),)

-, ( -,a)

(0: => {3) - (a => {3) - (0: {:} {3) -

-'(O:A{3)

-,(a V {3)

(0: A ({3 V ")' ) ) (0: V ({3 A --y))

((3 A 0:) commutativity of A ((3 V 0:) commutativity of V

(0: A ({3 A ")')) associativity of A (0: V ({3 V --y)} associativity of V 0: double-negation elimination (-,{3 => -'0:) contraposition

( -'0: V {3) implication elimination

( (0: => {3) A ({3 => a)) biconditional elimination ( -'0: V -,{3) De Morgan

(-'0: A -,(3) De Morgan

( (0: A {3) V (0: A --y)) distributivity of A over V ( (a V {3) A (0: V --y)) distributivity of V over A

Figure 7.11 Standard logical equivalences. The symbols 0:, (3, and ")' stand for arbitrary sentences of propositional logic.

7.S PROPOSITIONAL THEOREM PROVING

Tl£ORe.. PFIOVING

VAl.Jorrv TItJToi.ooy

So far, we have shown how to determine entailment by model checking: enumerating models and showing that the sentence must hold in all models. In this section, we show how entailment can be done by theorem proviog--applying rules of inference directly to the sentences in our know ledge base to construct a proof of the desired sentence without consulting models. If the number of models is large but the length of the proof is short, then theorem proving can

be more efficient than model checking.

Before we plunge into the details of theorem-proving algorithms, we will need some

additional concepts related to entailment. The first concept is logical equivalence: two sentences 0: and {3 are logically equivalent if they are true in the same set of models. We write this as 0: == {3. For example, we can easily show (using truth tables) that P A Q and Q A P are logically equivalent; other equivalences are shown in Figure 7.11. These equivalences play much the same role in logic as arithmetic identities do in ordinary mathematics. An alternative definition of equivalence is as follows: any two sentences 0: and {3 are equivalent

only if each of them entails the other:

0: == {3 if and only if 0: F {3 and 13 F 0: •

The second concept we will need is validity. A sentence is valid if it is true in all models. For example, the sentence P V -,p is valid. Valid sentences are also known as tautologies-they are necessarily true. Because the sentence True is true in all models, every valid sentence is logically equivalent to True. What good are valid sentences? From our definition of entailment, we can derive the deduction theorem, which was known to the ancient Greeks:

For any sentences 0: and {3, 0: F {3 if and only if the sentence (0: => 13) is valid. (Exercise 7.5 asks for a proof.) Hence, we can decide if 0: F 13 by checking that (0: => 13) is true in every model-which is essentially what the inference algorithm in Figure 7.10 does-

, •

I !

: !

, !

, f': ':1' ,

11" :

!i_' :

,I .

! I, · ~

:I I '

. i ' '

:··i· :

• I·· L

!

I

I

l ~ i

, '

i

!

I

I

, I

I

!

I

i I I j

i

250

Chapter 7.

Logical Agents

INFERENCE FlIlES PAOOF

MOOUS PONENS

AND-ELIMINATION

or by proving that (a :::} {3) is equivaJent to True. Conversely, the deduction theorem states that every valid implication sentence describes a legitimate inference.

The final concept we will need is satisfiability. A sentence is satisfiable if it is true in, or satisfied by, some model. For example, the knowledge base given earlier, (RI A R2 II R:l A R4 A R5), is satisfiable because there are three models in which it is true as shown in Figure 7.9. Satisfiability can be checked by enumerating the possible models until one is found that satisfies the sentence. The problem of determining the satisfiability of sentences in propositional logic-the SAT problem-was the first problem proved to be NP-complete. Many ~roble~s in computer science are really satisfiability problems. For example, all the conslram~ satisfaction problems in Chapter 6 ask whether the constraints are satisfiable by some assignment,

Validity and satisfiability are of course connected: 0: is valid iff -'0: is unsatisfiable; contrapositively, 0: is satisfiable iff -'0: is not valid. We also have the following useful result:

n F ,8 if and only if the sentence (0: A. -,{3) is unsatisfiable.

~ving (j from 0: .by checking the unsatisfiability of (0: A -'13) corresponds exactly to the standard mathematical proof technique of reductio ad absurdum (literally "reduction to an absurd thing"), It is also called proof by refutation or proof by contradiction. One assumes a sentence /3 to be false and shows that this leads to a contradicti ith kn . This

dicti . uon WI own axioms 0:.

contra tenon IS exactly what is meant by saying that the sentence (0: 1\ -,(3) is unsatisfiable.

7.S.1 Inference and proofs

This section covers inference rules that be .

sions that leads to the desi can applied to .derive a proof-a chain of cO,nclu-

mode that rffi ) d i ~ goal. The best-known rule IS called Modus Ponens (Latm for

a rms an IS wntten

Q =? (3, 0:

(j

The notation means that whenever an

the sentence {3 can be inf d F Y sentences of the form 0: =:} 13 and 0: are given, then

and ( WumpusAhead A eWrre. orAel~ample, if ( WumpusAhead A WumpusAlive) :::? Shoot

I \ umpus we) are gi th S

Another useful inference rule is And.E . v~n, . en h~t can be inferred. ,

any of the conjuncts can be inferred: limination, which says that, from a conjunctIOn,

n.A(3

Q

For example, from ( WumpusAhead A. W '

By considering the passibl tru h umpusA lzve ), WumpusAlive can be inferred,

Ponens and And-Elimination e t dValues of 0: and {3, one can show easily that Modus

. are soun once and tIlTh d .

any particular instances Where the a 1 . or a. ese rules can then be use In

enumerating models. y pp y, generabng sound inferences without the need for

All of, the logical equivalences in Fi ure 7 .

pIe, the equivalence for biconditi aJ I. g. . .11 can be used as inference rules. For exam-

on e IffiJnabon vield th .

0: '¢:} {3 J. s e two mference rules

(Q :::} (3) 1\ ({3 :::} 0:) and (0: =? {3) 1\ (j3 :::} 0:)

0:'¢:}j3

Section 7.5.

NO OVERNIGHT

Re.erve Area Use ONLYI1

Propositional Theorem Proving

251

~ICITV

Not all inference rules work in both directions like this. For example, we cannot run Modus Ponens in the opposite direction to obtain 0: ~ {3 and 0: from (3.

Let us see how these inference rules and equivalences can be used in the wumpus world.

We start with the knowledge base containing R, through R5 and show how to prove -,Pt,2, that is, there is no pit in [1,2]. First, we apply biconditional elimination to R2 to obtain

I4> : (BI,1 =:} (PI,2 V P2,d) A. ((P1,2 V P2,d ~ Bl,tl .

Then we apply And-Elimination to Ru to obtain R7 : ({P1,2 V P2,1) ~ BI,I).

Logical equivalence for contrapositives gives Rg : (-,B1,1 =} -,(P1,2 V P2,d) .

Now we can apply Modus Ponens with Rs and the percept R4 (i.e., -,Bl,l), to obtain

Rg: -,(P1,2 V P2,d '

Finally, we apply De Morgan's rule, giving the conclusion

RIO: -,P1,2 1\ -,P2,1 •

That is, neither [1,2] nor [2,1] contains a pit.

We found this proof by hand, but we can apply any of the search algorithms in Chapter 3

to find a sequence of steps that constitutes a proof. We just need to define a proof problem as

follows:

• INITIAL STATE: the initial knowledge base.

• ACTIONS: the set of actions consists of all the inference rules applied to all the sentences that match the top half of the inference rule.

• RESULT: the result of an action is to add the sentence in the bottom half of the inference

rule.

• GOAL: the goal is a state that contains the sentence we are trying to prove.

Thus, searching for proofs is an alternative to enumerating models. In many practi~~ cases finding a proof can be more efficient because the proof can ignore irrelevant propositums, no matter how many of them there are. For example, the proof given earlier leading to -:,Pl,2 A. -'P2 1 does not mention the propositions B2,1o Pt,l, P2,2, or P3,1. They can be Ignored because the goal proposition, Pt,2, appears only in sentence R2; the other propositions in R2

ap I, R dR· so R R3 and R5 have no bearing on the proof. The same would

pear on y m 4 an 2, 1" .

hold even if we added a million more sentences to the knowledge base; the slm~le truth-table

algorithm, on the other hand, would be overwhelmed by ~: expon~ntial explosion of models.

One final property of logical systems is ,mo~otoDlcltY, which says that the :et of en-

t ·1 d I . crease as infonnatIon IS added to the knowledge base, For any

at e sentences can on y In

sentences 0: and {3,

if KB F 0: then KB A {3 F 0: '

S N . I' hi h 'late the monotonicity property, capture a common property of human rea-

onmoDotoDic ogres, W IC VIO "2 6

soning: changing one's mind. They are discussed m Section I . '

252

Chapter 7.

Logical Agents

For ex.ample: sup~ the knowledge base contains the additional assertion f3 statin that there are ~xactly eight pus III the world. This knowledge might help the agent draw dd';' nal elusions, but it cannot invalidate any conclusion 0: already inferred h ah I 10 c~nthat there i . . [ 2 -suc as t e conclusion

. ere IS no pit In I, J. Monotonicity means that inference rules can be a I' d h

suitable premises are found in the knowledge base-th I' pp ie w enever regardless of what else is in the knowledge base. e cone usion of the rule must follow

7.5.2 Proof by resolution

We have argued that the inference rules covered so f

the question of completeness for th ._&: ar are sound, but we have not discussed

. e mrerence algorithms that u th S .

such as Iterative deepening search ( a e 89 . . se em. earch algonthms

any reachable goal but if the avail bPI g. e. ) are complete In. the sense that they will find

, I a e mrerence rules are . ad h

reachable-no proof exists that I those i III equate, t en the goal is not

h uses on y ose inference rul F

t e biconditional elimination rule th f . es. or example, if we removed

Th ' e proo III the precedin ti I

e current section introduces . I . g sec on wou d not go through.

. f a smg e inference rule resol ti h .

rn erence algorithm when coupled ith ,u on, t at Yields a complete

We be' b . . WI any complete search algorithm

. gm y using a Simple version of the r I' . .

consider the steps leading up to Figure 74()' eso ution rule In the wumpus world. Let us

goes to 11.2 J, where it perceives a ste h:' the agent returns from [2, I] to [1,1] and then knowledge base: nc, ut no breeze. We add the following facts to the

RII: --.BI,2 .

R12: B1.2 {:} (PI,I V P2,2 V PI,a) .

By the same process that led to R li

and [I 31 ( 10 ear ter, we can now deri h

, remember that [1.1 J is alread kn . enve t e absence of pits in [2,2]

R. . Y own to be pitless):

1.1· --,P2•2 •

RI.l: --'P1.3 .

We can also apply biconditional I' . .

b . e Immauon to R D 11

o tam the fact that there is a pit in [I IJ [22J 3, 0 owed by Modus Ponens with R5, to

R ' , , ,or[3,1]:

is : PI,I V P2,2 V P3.l .

~~~i comes th~ first application of the resolution nne: .

teral P2.2 III RI5 to give the resolvent Ie. the literal ......,P2,2 in RI3 resolves with

RIIi: PI,1 V J\l .

In English: if. there' s a pit in one of [1, I J [2 2

or [3.1]. Similarly, the literal =P . R' , J, and [3,1] and it's not in [2 2J then it's in [1 11

R 1,1 III I resolves with th I' ' , •

17: P3.I. e iteral PI,I in RI6 to give

In E I' h: . .

ng IS • If there s a pit in [1 I]

t . f , or [3 I] ad' ,

wo III erence steps are examples of the ~nit n It I s ~ot i~ [1, I J, then it's in [3.1 J. These last

(1 V ... V Ck, m reso utlon Inference rule,

E} V ... V £. V IJ

I-I {.i+} V '" V £ '

where each £ is a literal and £. k

! and m are compl

ementary literals (i.e., one is the negation

RESOlVENT

UNIT RESOlUTION

COMPlEMENTARY LITERALS

Section 7.5.

NO OVERNIGHT

Reserve Area Use ONLYII

Propositional Theorem Proving

253

UNrTClJJJSE RESOll1OON

of the other). Thus, the unit resolution rule takes a clause-a disjunction of literals-and a literal and produces a new clause. Note that a single literal can be viewed as a disjunction of

one literal, also known as a unit clause.

The unit resolution rule can be generalized to the full resolution rule,

£1 V ... V £k, ml V ... V mn

€1 V ... V €i-I V £HI V ... V £k V ml V ... V mj-l V mj+1 V ... V mn '

where €i and mj are complementary literals. This says that resolution takes two clauses and produces a new clause containing all the literals of the two original clauses except the two complementary literals. For example, we have

P1,1 V P3,1, --.PI,1 V ,P2,2

F\I V --.P2,2

There is one more technical aspect of the resolution rule: the resulting clause should contain

only one copy of each literal." The removal of multiple copies of literals is called factoring. For example, if we resolve (A VB) with (A V --.B), we obtain (A VA), which is reduced to

just A.

The soundness of the resolution rule can be seen easily by considering the literal £i that

is complementary to literal mj in the other clause. If £i is true, then mj is false. and hence ml V ... V mj_1 V mj+1 V .. ' V mn must be true, because ml V ... V mn is given. If €i is false, then £1 V ... V €i-l V €i+1 V ... V £k must be true because £1 V ... V £k is given. Now £i is either true or false, so one or other of these conclusions holds--exactly as the resolution

rule states.

What is more surprising about the resolution rule is that it forms the basis for a family

of complete inference procedures. A resolution-based theorem prover can, for any sentences Q and /3 in propositional logic, decide whether 0: 1= /3. The next two subsections explain

how resolution accomplishes this.

Conjunctive normal form

The resolution rule applies only to clauses (that is, disjunctions of literals), so it would seem to be relevant only to knowledge bases and queries consisting of clauses. How, then, can it lead to a complete inference procedure for all of propositional logic? The answer is that every sentence of propositional logic is logically equivalent to a conjunction of clauses. A sentence expressed as a conjunction of clauses is said to be in conjunctive normal fonn or CNF (see Figure 7.14). We now describe a procedure for converting to CNF. We illustrate the procedure by converting the sentence BI,l -{:} (PI,2 V P2,1) into CNF. The steps are as

follows:

I. Eliminate -{:}, replacing 0: -{:} /3 with (a :::} /3) 1\ (/3 :::} a}.

(Bl,l :::} (Pt,2 V P2,t)} 1\ ((Pt,2 V P2,1) :::} Bl,l)' 2. Eliminate=e-, replacing 0: :::} /3 with --'0: V /3:

(.,BI,I V Pt,2 V P2,1) 1\ (,,(PI,2 V P2,t) V BI,I} .

9 If a clause is viewed as a set of literals, then this restriction is automatically respected. Using set notation for clauses makes the resolution rule much cleaner, at the cost of introducing additional notation.

254

Chapter 7.

Logical Agents

3. CNF requires. to appear only in literals, so we "move. inwards" by repeated appli-

cation of the following equivalences from Figure 7.11:

• ( '0:) == 0: (double-negation elimination)

--,( 0: A fi) == ("'0: V .(3) (De Morgan)

..,( 0: V (3) == (.0' A .(3) (De Morgan)

In the example, we require just one application of the last rule: (.Bl,1 V Pt,2 V P2,t) A. ((..,P1,2 A. .P2,t) V B1,1) .

4. Now we have a sentence containing nested A. and V operators applied to literals. We appl y the distributivity law from Figure 7.11, distributing V over A wherever possible.

(.BI, 1 V Pt,2 V P2,1) A (.Pl,2 V B1,1) A (.P2,1 V B1,t) .

The original sentence is now in CNF, as a conjunction of three clauses. It is much harder to read, but it can be used as input to a resolution procedure.

A resolution algorithm

Inference procedures based on resolution work by using the principle of proof by contradiction introduced on page 250. That is, to show that KB F 0:, we show that (KB A. --,a) is unsatisfiable. We do this by proving a contradiction.

A resolution algorithm is shown in Figure 7.12. First, (KB A. '0) is converted into CNF. Then, the resolution rule is applied to the resulting clauses. Each pair that contains complementary literals is resolved to produce a new clause, which is added to the set if it is not already present. The process continues until one of two things happens:

• there are no new clauses that can be added, in which case KB does not entail a; or,

• two clauses resolve to yield the empty clause, in which case KB entails Q.

The empty c1ause-a disjunction of no disjuncts-is equivalent to False because a disjunction is true only if at least one of its disjuncts is true. Another way to see that an empty clause represents a contradiction is to observe that it arises only from resolving two complementarY unit clauses such as P and ..,P.

We can apply the resolution procedure to a very simple inference in the wumpus world.

When the agent is in [I, I], there is no breeze, so there can be no pits in neighboring squares. The relevant knowledge base is

KB == R2 A R~ == (B1,1 {;} (PI,2 V P2,t)) 1\ ..,B1,1

and ,!"e wish to prove 0: which is, say, ..,P1,2. When we convert (KB 1\ .0) into CNF, we obtain the c.lauses shown at the top of Figure 7.13. The second row of the figure showS clauses ?btamed by resolving pairs in the first row. Then, When PI 2 is resolved with .H,z, we obtain th~ empty clause,. shown as a small square. Inspection of Figure 7.13 reveals that many resolution steps are pomtless. For example, the clause B V..,B V P , is equivalent to Tru V P hi h ' . 1,1 1,1 1,2 ful

e 1,2 w c IS eqUIvalent to True. Deducing that True is true is not very help ,

Therefore, any clause in which two complementary literals appear can be discarded.

Section 7.5.

NO OVERNIGHT

Reserve Area Use ONLYI1

Propositional Theorem Proving

255

ion PL-RESOLUTION(KB,a) returns true or fals~ . .

fu~ct ts: KB the knowledge base, a sentence in prop,osltlOnalloglc

IOpU. , iti I logic

(t, the query, a sentence in proposi ona

. CNF tation of KB 11---.0

clauses <-- the set of clauses m the represen

new <-- {}

loop do C C· louses do

for each pair of clauses i, j m c

resolvents <-- PL-RESOLVE(Ci, Cj}

if resolvents contains the empty clause then return true

new <-- new U resolvents

if new ~ clauses then return false clauses <-- clauses U new

. . al orithm for propositional logic. Th: function

Figure 7.12 A Simple resolution ,g I btained by resolving its two Inputs.

PL-RESOLVE returns the set of all possible causes 0

, , fPL RESOLUTION to a simple inference in the wumpus

. 13 Partial appitcatton 0 - , h

Figure 7. =1..1 f th first fourc1auses m t e top row,

world, -,Pt,2 is shown to follow rom e

Completeness of resolution h PL-RESOLUTION is complete.

. f 1 tion we now show w y . h i h t

To conclude our diSCUSSIon 0 reso ~ Josure RC(5) of a set of clauses 5, whic IS t e s~

To do this we introduce the resolution c. . f the resolution rule to clauses in 5 or their

' t d apphcaUon 0 I I f

of all clauses derivable by repea e. hat PL-RESOLUTION computes as the tina va ~e 0

derivatives. The resolution closure IS w RC(S) ust be finite, because there are only fin.ltely the variable clauses. It is easy to see that d ut:fthe symbols Pi, .. , Pk that appear 10 5, many distinct clauses that can be con~tructeth° f ctoring step that removes multiple copies of

ld t be true Without e a

(Notice that this wou no terminates.

literals) Hence PL-RESOLUTlON always. ' propositional logic is called the ground

. , h for resolution III

The completeness t eorern

resolution theorem: then the resolution closure of those clauses

If a set of clauses is unsatisfiable,

contains the empty clause. ,. . if the closure RC(S) does not

. onstrating its contrapoSluve,

This theorem IS proved by dem

256

Chapter 7.

Logical Agents

co~tain the empty clause, then S is satisfiable. In fact, we can construct a model for S with suitable truth values for Pt, ... .Pi, The construction procedure is as follows:

For i from I to k

,

- If a cla~se in RC(S) contains the literal -P; and all its other literals are false under the assl~nment chosen for PI, ... , ~-I' then assign false to Pi.

- Otherwise, assign true to Pi.

This assignment to PI, . .. Pk is a model f S T .

some stage i in the s uence .. o. 0 see this, assume the opposite-that, at

For this t h . eq , asslgnmg symbol P; causes some clause C to become false

o appen, It must be the case th tilth he' . .

falsified by assignments to Pi ... B a a e ot r hterals m ? m~st already have been

... false V l{) or like (faI8eVf~lse~ .. t~}~IThU~ C mus.t now look like either (false V false V the algorithm will assign th . seV Pd· If Just one of these two is in RC(S), then

falsified if both of these cla::~:~~~~ ~th value t~ ~ to make, C true, so C can only be it will contain the resolvent of th I( ), Now, since RC (S) IS closed under resolution,

ese two causes and th t I .

already falsified by th . ' a reso vent WIll have all of its literals

e assignments to P F,- . ,

the first falsified clause appears t t . lH'" ., t-l, This contradicts our assumption that

, a sage z. ence we hav d h .

falsifies a clause in RC(S)' th t i . ' e prove t at the construction never

" ' a IS, It produces a mod I f RC(S)

Itself (since S is contained in RC(S), e 0 and thus a model of S

7.5.3 Hom clauses and definite clauses The completeness of resolution make it .

situations, however the full fS I a ve~ irnportent inference method. In many practical

, power 0 resolution is t d

bases satisfy certain restrictions 0 th f no nee ed. Some real-world knowledge

t n e orm of sentences th . .

o use a more restricted and efficient infi ey contain, which enables them

o erence algorithm

. ne such restricted form is the definite la '.,

which exactly one is positive. For exam le th c use, which IS a disjunction of literals of

clause, whereas (...,B 1 I V PI 2 V P. ) ,p , e clause (...,L 1, 1 V..., Breeze V B 1 1) is a definite

S . ,,2,1 IS not '

hghtly more general is the Horn cIa . "

most one is positive, So all definite I use, WhICh IS a disjunction of literals of which at

I' I causes are H I

itera s; these are called goal clauses H om causes, as are clauses with no positive

two HI' om clauses are cl d d

om causes, you get back a H I ose un er resolution' if you resolve

Kid omcause .

nowe ge bases containin I d .-

g on y efimte clause ' .

I. Every definite clause can be . s are interesting for three reasons:

f . . . wntten as an irnpli u

o posmve literals and whose co I " rca on whose premise is a conjunction

For example, the definite clausenc( uLslon IS a single positive literal, (See Exercise 7.13.)

I' . ( ..., 11 V...,B

P icatron L 1,1 /I.. Breeze) =? B ' . re.eze V Bl,1) can be written as the im-

understand: it says that if the age~~ is ~: ~e tlmphcation . form, the sentence is easier to In Hom fOI1O,. ~e premise is caned the bod] and there IS a breeze, then [1,1) is breezy. sentence consisnng of a single POSt't' I' Y and the conclusion is called the head. A

be 'n . . ive iteral s h

wn en 10 Implication form as me =? L ' uc .a~ L~,l' is called a fact. It too can

1,1, but It IS Simpler to write just Ll, 1.

DEF~TE CLAUSE

IiOANCUUse

GOAl ClAUSES

BOO!' HEAD FACT

Section 7.5.

NO OVERNIGHT

Reserve Area Use ONLYII

Propositional Theorem Proving

257

CNFSentence - Clausel /\' .. /\ Clausen
Clause --> Literal, V·" V Literalm
Literal ---+ Symbol I -,symbol
Symbol - PI QI RI ...
Hom Claus eFo rm - DefiniteClauseForm I G oalClaus e Form
Definite Clause Form ---+ (Symboll /\ ... /\ Symboll) =:} Symbol
G oal Claus e Form - (Symboll /\ ... /\ Symboll) =:} False Figure 7.14 A grammar for conjunctive normal fonn, Hom clauses, and definite clauses. A clause such as A /\ B =:} C is still a definite clause when it is written as -,A V -,B V C but only the former is considered the canonical form for definite clauses. One more class is the k-CNF sentence, which is a CNF sentence where each clause has at most k literals.

2. Inference with Horn clauses can be done through the forward-chaining and backwardchaining algorithms, which we explain next. Both of these algorithms are natural, in that the inference steps are obvious and easy for humans to follow, This type of inference is the basis for logic programming, which is discussed in Chapter 9.

3. Deciding entailment with Hom clauses can be done in time that is linear in the size of the knowledge base-a pleasant surprise,

7.5.4 Forward and backward chaining

The forward-chaining algorithm PL-FC-ENTAILS?(KB, q) determines if a single proposition symbol q-the query-is entailed by a knowledge base of definite clauses. It begins from known facts (positive literals) in the knowledge base, If all the premises of an implication are known, then its conclusion is added to the set of known facts. For example, if L1.1 and Breeze are known and (Ll,1 /I.. Breeze) :::} B1,1 is in the knowledge base, then BLl can be added. This process continues until the query q is added or until no further inferences can be made. The detailed algorithm is shown in Figure 7.15; the main point to remember is that

it runs in linear time.

The best way to understand the algorithm is through an example and a picture, Fig-

ure 7,16(a) shows a simple knowledge base of Hom clauses with A and B as known facts. Figure 7,16(b) shows the same knowledge base drawn as an AND-OR graph (see Chapter 4). In AND-OR graphs, multiple links joined by an arc indicate a conjunction--every link must be proved-while multiple links without an arc indicate a disjunction-any link can be proved. It is easy to see how forward chaining works in the graph. The known leaves (here, A and B) are set, and inference propagates up the graph as far as possible, Wherever a conjunction appears, the propagation waits until all the conjuncts are known before proceeding, The reader is encouraged to work through the example in detail.

258

Chapter 7.

Logical Agents

FIXED POINT

DAT .... DfWEN

function PL- FC- ENTA ILS?( K B, q) returns true or false

inputs: K B, the knowledge base, a set of propositional definite clauses

q. the query. a proposition symbol

~ount +--- a table, where count[cJ is the number of symbols in c's premise mfr~TTed +--- a table, where infeTTed[sJ is initially false for all symbols aqeuda +--- a queue of symbols. initially symbols known to be true in KB

while agenda is not empty do

p +--- POP(agenda)

if p = q then return true If inff!ffi'A[p J = false then

inferred[pJ ..... true

for each clause c in KB where p is in c.PREMISE do decrement count[ c]

return fals~ count[cJ = 0 then add c.CONCLUSION to agenda

Figure 7.15 The forward-chainin al orithm ..

track of symbols known to be tru bg g for proposnional logic. The agenda keeps

e ut not yet "proc ed," Th

how many premises of each implicati essec, e count table keeps track of

h. Ion are as yet unkno Wh

t e agenda IS processed the count i d ed b wn. enever a new symbol p from

p appears (easily identified in constanS ret b~c .y one for each implication in whose premise

1 me With approp . t . d .

zero. a I the premises of the I'm I' . na e m exing.) If a count reaches

. . p icanon are kno . .

agenda. Finally, we need to keep tea k f hi wn, so Its conclusion can be added to the

is already in the set of inferred b 10 w ich symbols have been processed' a symbol that

d sym 0 s need not be dded '

re undant work and prevents loops caused bv i . a. to the agenda again. This avoids

y implications such as P::::} Q and Q ::} P.

It is easy to see that forward h " .

. c alnlDg IS sound' . c.

canon of Modus Ponens Forward h ". . every mrerence is essentially an appli-

'11' . c ammg IS als I

WI be denved. The easiest way to se this i 0 comp ete: every entailed atomic sentence

(after the algorithm reaches a fixed e. IS IS to consider the final state of the inferred table

t . potnt where no '-~

con runs true for each symbol inf d d . new inrerences are possible). The table

w,' terre unng the p

e can VIew the table as a logical oct I' recess, and false for all other symbols.

tr. . hi me, moreover e detini . . ue In t IS model. To see this, assume the 0 .' very ejmue clause in the original KB IS

IS false in the model. Then a 1\ PPOSlte, namely that some clause alA ... I\ak =? b

th od I 1 ... 1\ ak must be tru .

em e. But this contradicts our a . e In the model and b must be false in

We can conclude, therefore that the ssumfPlIon that the algorithm has reached a fixed point!

od ' set 0 atomi .

am el of the original KB Furth c sentences Inferred at the fixed point defines

. . ermore, an to'

must be true ID all its models and' thi y a . rruc sentence q that is entailed by the KB

sent ID s model In .

ence q must ~ i.nferred by the algorithm. PartIcular. Hence, every entailed atomic

Forward chaining is an ex I

is reasonino i amp e of the general c

• nlng In which the focus of attenti oncept of data-driven reasoning-that

a~ agent to derive conclusions from' Ion ~tarts with the known data. It can be used within

mind F mconung pe . .

. or example, the wumpus agent might TELL~Pts, often Without a specific query to

Its percepts to the knowledge base using

NO OVERNIGHT

Re.erve Area Use ONLYI1

Section 7.6.

Effective Propositional Model Checking

259

Q

P==}Q

L 1\ Jl,f ==} P BI\L==}M AAP==}L AI\B==}L A

B

(a)

A (b)

B

Figure 7.16 (a) A set of Hom clauses. (b) The corresponding AND-OR graph.

an incremental forward-chaining algorithm in which new facts can be added to the agenda to initiate new inferences. In humans, a certain amount of data-driven reasoning occurs as new information arrives. For example, if I am indoors and hear rain starting to fall, it might occur to me that the picnic will be canceled. Yet it will probably not occur to me that the seventeenth petal on the largest rose in my neighbor's garden will get wet; humans keep forward chaining under careful control, lest they be swamped with irrelevant consequences.

The backward-chaining algorithm, as its name suggests, works backward from the query. If the query q is known to be true, then no work is needed. Otherwise, the algorithm finds those implications in the knowledge base whose conclusion is q. If all the premises of one of those implications can be proved true (by backward chaining), then q is true. When applied to the query Q in Figure 7.16, it works back down the graph until it reaches a set of known facts, A and B, that forms the basis for a proof. The algorithm is essentially identical to the AND-OR-GRAPH-SEARCH algorithm in Figure 4.11. As with forward chaining, an

efficient implementation runs in linear time.

Backward chaining is a fonn of goal-directed reasoning. It is useful for answering

specific questions such as "What shall I do now?" and "Where are my keys?" Often, the cost of backward chaining is much less than linear in the size of the knowledge base. because the

process touches only relevant facts.

1_6 EFFECTIVE PROPOSITIONAL MODEL CHECKING

In this section, we describe two families of efficient algorithms for general propositional inference based on model checking: One approach based on backtracking search, and one on local hill-climbing search. These algorithms are part of the "technology" of propositional logic. This section can be skimmed on a first reading of the chapter.

264

Chapter 7.

Logical Agents

most such underc~nstrained problems. On the other hand, an overconstrained problem has many clauses relative to the number of variables and is likely to have no solutions

To go beyond thes~ basic intuitions, we must define exactly how random' sentences ~ :nleratehd. The notation cs Fk (m, n) denotes a k-CNF sentence with m clauses and n

sym s, w ere the clauses are chosen unifi I . d d

from among all clauses with k different lite~:m:hl~~ epen e.~tly, and wi~out replacement symbol rna not a .. ,are posinve or negative at random. (A

G. Y ppear twice m a clause, nor maya clause appear twice in a sentence)

iven a source of random se te .

Figure 7.19(a) plots the robabili n fo:ces, we can measure ~e probability ?f satisfiability.

and 3 literals per cia p f ty. eN F3 (m, 50), that IS, sentences With 50 variables

use, as a unction of the clause/symb I . I

small min the probability of satisfi bili . I 0 rano, m n. As we expect, for

is close to O. The probability dro ; .. :ty ~s c ose to I, and at large min the probability that the "cliff' stays in roughl thPs arr y IS arply around min = 4.3. Empirically, we find

. y e same p ace (for k - 3) a d ts h

mcreases, Theoretically the satisfi bTt - n ge s arper and sharper as n

~here is a threshold ratio'rk such tha~ ~Sl ~ thresh~ld c~njecture say~ .that for every k 2: 3, IS sati sfiable becomes 1 for all I' f goes to infinity, the probabi lity that CN Fk (n, rn)

va ues 0 r below th thre h ld

The conjecture remains unproven. e so, and 0 for all values above.

2000
1800
1600
140()
e 1200
.-5 1000
"
"'- 800
600
40()
200
0
7 8 0 0.8

u

~ 0.6

...: .~

; 0.4 it"

0.2

o ~:--"---';"""_~=+:±=t::::!=!"

o 2 3 4 5 6

Clause/symbol ratio mill (a)

2345678 Clause/symbol ratio m/II

(b)

F'

igure ':19 . (a) Graph Showing the ro ..

symbols IS satisfiable, as a function of ~ b~biltty that a random 3-CNF sentence with n = 50

run time (measured in number of rec .e cause/symbol ratio min. (b) Graph of the median

sentences The mosr a: ursive calls to DPLL

. e most difficult problems h ' a good proxy) on random 3-CNF

ave a clause/symbol ratio of about 4.3.

Now that we have a good idea h

next q f . w ere the sati fi bl

ues IOn IS, Where are the hard bl s a e and unsatisfiable problems are, the

::::hOld valu~. Figure 7 .19(b) ShowsP:t ~~ss? It turns out that they are also often at the bout 20 times more difficult to s I th ymbol problems at the threshold value of 4.3

problems. 0 ve an th .

are easiest to solve (because it . ose at a ratio of 3.3. The underconstraincd

problems are t 1 IS so easy to . cd

t th thre no as easy as the underconstrai d guess a solution); the overconstrmn

a e shold. ne , hut still are much easier than the ones right

NO OVERNIGHT

Reserve Area Use ONLVn

Section 7.7.

Agents Based on Propositional Logic

265

7.7 AGENTS BASED ON PROPOSITIONAL LOGIC

In this section, we bring together what we have learned so far in order to construct wumpus world agents that use propositional logic. The first step is to enable the agent to deduce, to the extent possible, the state of the world given its percept history. This requires writing down a complete logical model of the effects of actions. We also show how the agent can keep track of the world efficiently without going back into the percept history for each inference. Finally, we show how the agent can use logical inference to construct plans that are guaranteed to

achieve its goals.

7.7.1 The current state of the world

As stated at the beginning of the chapter, a logical agent operates by deducing what to do from a knowledge base of sentences about the world. The knowledge base is composed of axioms-general knowledge about how the world works-and percept sentences obtained from the agent's experience in a particular world. In this section, we focus on the problem of deducing the current state of the wumpus world-where am I, is that square safe, and so on.

We began collecting axioms in Section 7.4.3. The agent knows that the starting square contains no pit (--PI,d and no wumpus (--WI,l)' Furthermore, for each square, it knows that the square is breezy if and only if a neighboring square has a pit; and a square is smelly if and only if a neighboring square has a wumpus. Thus, we include a large collection of sentences

of the following form:

BI,1 {:} (PI,2 V P2,1) 81,1 {:} (WI,2 V W2,1)

The agent also knows that there is exactly one wumpus. This is expressed in two parts. First, we have to say that there is at least one wumpus:

Wl,1 V Wl,2 V ... V W4,3 V W4,4 .

Then, we have to say that there is at most one wumpus. For each pair of locations, we add a sentence saying that at least one of them must be wumpus-free:

--WI,I V --Wl,2

--WI,l V --WI,3

--W4,3 V --W4,4 .

So far, so good. Now let's consider the agent's percepts. If there is currently a stench, one might suppose that a proposition Stench should be added to the knowledge base. This is not quite right, however: if there was no stench at the previous time step. then <Stench. would already be asserted, and the new assertion would simply result in a contradiction. The problem is solved when we realize that a percept asserts something only about the current time. Thus, if the time step (as supplied to MAKE_PERCEPT-SENTENCE in Figure 7.1) is 4, then we add

266

Chapter 7.

Logical Agents

R.UEHT

EFFECT AXIOM

FRAME PR06LEM

~~nCh4 ;0 the knowledge base, rather than Stench-neatly avoiding any contradiction with r: : The same g~~ for the b~~ze, bu~p, glitter, and scream percepts.

h h e Idea of ~ssoclatmg propositrons with time steps extends to any aspect of the world

t at c anges over time. For example, the initial knowledge base includes LO the t i .

. [1 IJ . 1 1- agen Ism

square , at time O-as well as FacingEastO, HaveArrowo and W ' Al' 0

the word fluent (from th L . fl' ' umpus we. We use "Fluent" . e ann uens, flowing) to refer an aspect of the world that changes

represent:~i:~;~~":::~~ '~~t; Variable,'~~n the sense descri~ed in the discussion of factored the world d t d . .. on page . Symbols associated with permanent aspects of

a no nee a time supersc . t d .

W np an are sometimes called atemporal variables

e can connect stench and breeze nercents di . where they are experienced thrau reeze pe~epts directly to the properties of the squares

any square [x, yJ, we assert gh the locatIOn fluent as follows.!" For any time step t and

L~,y ~ (Breezel {:} B )

LI x,y

X,Y ~ (Stencht {:} S )

x,y •

Now, of course, we need axioms that allow th

These fluents change as the res It f . e agent to keep track of ftuents such as L~ y'

u 0 actions taken b th . .'

Chapter 3, we need to write do th . . y e agent, so, III the terminology of

. wn e transition m d I f h

logical sentences. 0 e 0 t e wumpus world as a set of

First, we need proposition symbols £

these symbols are indexed by time' th D or the ooccurrences of actions. As with percepts,

" ' us, Foruiard mean th th

action at time O. By convention th s at e agent executes the FotWard

h . ' e percept for a' .

t e action for that time step, followed b a .. given time step happens first, followed by

To describe how the world h y transition to the next time step.

c anges we can try ..

outcome of an action at the next t" wntmg effect axioms that specify the

. . . Ime step. For exam I if he asenr i .

east at time 0 and goes Fo rd th P e, I t e agent IS at location [1 1J facmg

. . TWa , e result i th th '

IS In [1. 1]: s at e agent is in square [2, 1 J and no longer

L~,! 1\ FacingEastO 1\ Forward0 ~ Ll 1

We would need one such sent " ( 2,1 1\ ,L1,1) . (7.1)

, d ence lor each po ibl .

an each of the four orientations Ul SSl e time step, for each of the 16 squares,

G b Sh . we would also ne d . '1

ran, oot, Climb, TumLeft and 11 R' e SImI ar sentences for the other actions:

Let us s ' urn ight.

. . . uppose that the agent does deci

fact Into Its knowledge base O' th de to move Forward at time 0 and asserts this

. . . I' " Iven e eff . .

~ mtia assertions about the state at time 0 ect axiom III Equation (7.1), combined with the

~s, ASK(KB, L~,l) = true. So far so gO(~t~ agent can now deduce that it is in [2,1]. That If we ASK(KB, HaveArrow1) t~e .. nfortunately, the news elsewhere is less good: has the arro . . ' answer IS false th . . . 1

w, nor can 11 prove it does 'h . ' at IS, the agent cannot prove It sui

effect axi f '1 n t ave It' Th . f .

. . am ai s to state what remai . e III ormation has been lost becaUse the

this gi . ams unchang d

ves nse to the frame problem 11 0 e . as the result of an action. The need to do

JO S . . ne pOSSible sol t' Id

ectron 7.4.3 convenient! I U Ion to the frame problem WoU

II Th Y g ossed over this .

e name "frame problem" requIrement.

w ith comes from "f

I respect to which motion . rame of reference" in .

most of the background ta IS measured. It also has an I phYSics-the assumed stationary background

s ys constant while changes ace ~a ogy to the frames of a movie in which norma1ly

ur m the foreground. '

Section 7.7.

NO OVERNIGHT

Re.erve Area Use ONLYII

Agents Based on Propositional Logic

267

REPRESENTATiONAL FRAIoIE PROBlEM

LOCAUlY

INFERE~ FRAME PFiOBlBd

be to add frame axioms explicitly asserting all the propositions that remain the same. For example, for each time t we would have

Forwardt :::} (HaveArrowt {::} HaveArrowt+1) Forwardt :::} (WumpusAlivet {::} WumpusAlivet+1)

where we explicitly mention every proposition that stays unchanged from time t to time t + 1 under the action Forward. Although the agent now knows that it still has the arrow after moving forward and that the wumpus hasn't died or come back to life, the proliferation of frame axioms seems remarkably inefficient. In a world with m different actions and n ftuents, the set of frame axioms will be of size O(mn). This specific manifestation of the frame problem is sometimes called the representational frame problem. Historically, the problem was a significant one for AI researchers; we explore it further in the notes at the end

of the chapter.

The representational frame problem is significant because the real world has very many

fiuents, to put it mildly. Fortunately for us humans, each action typically changes no more than some small number k of those ftuents-the world exhibits locality. Solving the representational frame problem requires defining the transition model with a set of axioms of size O(mk) rather than size O(mn). There is also an inferential frame problem: the problem of projecting forward the results of a t step plan of action in time 0 (kt) rather than a (nt ).

The solution to the problem involves changing one's focus from writing axioms about actions to writing axioms about jluents. Thus, for each fiuent F, we will have an axiom that defines the truth value of r+ 1 in terms of fluents (inel uding F itself) at time t and the actions that may have occurred at time t. Now, the truth value of Ft+l can be set in one of two ways: either the action at time t causes F to be true at t + 1, or F was already true at time t and the action at time t does not cause it to be false. An axiom of this form is called a successor-state

axiom and has this schema:

Ft+! {::} ActionCausesFt V (Ft 1\ ,ActionCausesNotFt) .

One of the simplest successor-state axioms is the one for HaveArrow. Because there is no action for reloading, the ActionCausesFt part goes away and we are left with

HaveArrowt+1 {::} (HaveArrowt 1\ ,Shoott) . (7.2)

For the agent's location, the successor-state axioms are more elaborate. For example, LiV is true if either (a) the agent moved Forward from [1,2] when facing south, or from [2,1] when facing west; or (b) L\ 1 was already true and the action did not cause movement (either because the action was not Forward or because the action bumped into a wall). Written out

in propositional logic, this becomes

Lij 1 {:} (Li,l 1\ (,Forwardt V Bumpt+1))

V (Li 21\ (Southt 1\ Forwardt))

,

V (L~ 11\ (Westt 1\ Forwardt)) .

,

(7.3)

Exercise 7 .26 asks you to write out axioms for the remaining wumpus world fiuents.

280

Chapter 7.

Logical Agents

each of the following sentences is true: 0:2 = ''There is no pit in [2,2]."

0:.1 = ''There is a wumpus in [1,3]."

Hence show that KB F 0:2 and KB F 0:3.

7.2 (Adapted from Barwise and Etchemend (1993» G'

that the unicorn is mythical? How about magi~al? Ho~ed;ven the following, can you prove

If the unicorn is mythical th it i rtal ..

I ' , en I IS immo , but If It is not mythical then it is a

marta mammal. If the unicorn is either immortal or a rnamm : ,

The unicorn is mag' I if i . h ai, then It IS homed.

tea I It IS orned.

7.3 Consider the problem of deciding wheth r . . .

given model. e a propositional lOgIC sentence is true in a

a. Write a recursive algorithm PL- TRUE?( .

tence s is true in the model (h . s, m) that returns true If and only if the sen-

The algorithm should run i t~ WI' ere ~ assigns a truth value for every symbol in s).

n une inear m the size of th (

version of this function from th nfi . e sentence. Alternatively, use a

b . e a me code repository )

. Give three examples of sentences th t . .

model that does not specify a truth ~ can be determined to be true or false in a partial

c Sh h th v ue for some of the symbols

. ow t at e truth value (if any) of a sen . . .

efficiently in general. tence in a partial model cannot be detennined

d. Modify your PL-TRUE? algorithm so .

models, while retaining its . that It can sometimes judge truth from partial

f recursive structure and l' . .

o sentences whose truth '. mear run time. GIve three examples

III a partial model is d

e. Investigate whether the difi d . not etected by your algorithm.

rno I e algonthm makes TT-ENTAILS? more efficient.

7.4 Which of the following are correct? a. False F True.

h. True F False.

c. (A 1\ B) F (A {:} B).

d. A {::} BFA VB.

e. A {::} B F -,A V B.

f. (A 1\ B) =? C F (A =? C) V (B

g. (CV(-,AI\-,B))=(( ~ C).

h (A - A =? 0) 1\ (B ~ C))

I. V B) 1\ (-,0 V -,D V E) F (A V B). .

. (A V B) 1\ (-,C V -,D V E) L

j. (A V B) 1\ -'(A ,I' (A V B) 1\ (-,D V E).

k. (A {:::} B =? B) IS satisfiable,

l. (A {::} _j 1\ (-,A V B) is satisfiable.

) {:::} 0 has the same nu be

Proposition symbols th t i I m r of models as (A {:} B) for any fixed set of

a me udes A, B, C.

Exercises

281

NO OVERNIGHT

Re.erve Area Use ONLYII

7.5 Prove each of the following assertions:

a. 0: is valid if and only if True F Q.

b. For any Q, False F 0:.

C. Q F 13 if and only if the sentence (Q =? 13) is valid.

d. 0: == [3 if and only if the sentence (Q {:} 13) is valid.

e. 0: 1= [3 if and only if the sentence (0: 1\ -'13) is unsatisfiable.

7.6 Prove, or find a counterexample to, each of the following assertions:

a. If 0: 1= 'Y or [3 F ''/ (or both) then (0: 1\ 13) 1= ,

b. If 0: F ([31\ ,) then 0: 1= 13 and 0: F ,.

c. If 0: 1= (13 V 'Y) then 0: 1= 13 or 0: 1= 'Y (or both).

7.7 Consider a vocabulary with only four propositions, A, B, C, and D. How many models are there for the following sentences?

a. BVe.

b. -,A V -,B V -c V -,D.

c. (A ::::} B) /\ A 1\ ..,B 1\ e 1\ D.

7.8 We have defined four binary logical connectives.

a. Are there any others that might be useful?

b. How many binary connectives can there be?

c. Why are some of them not very useful?

7.9 Using a method of your choice, verify each of the equivalences in Figure 7.11 (page 249).

7.10 Decide whether each of the following sentences is valid, unsatisfiable, or neither. Verify your decisions using truth tables or the equivalence rules of Figure 7.11 (page 249).

a. Smoke =? Smoke

b. Smoke ::::} Fire

c. (Smoke ::::} Fire) ::::} (-, Smoke ::::} ..,Fire)

d. Smoke V Fire V +Fire

e. (( Smoke 1\ Heat) ::::} Fire) {::} ( (Smoke ::::} Fire) V (H ea t =? Fire))

f. (Smoke ::::} Fire) ::::} (( Smoke 1\ Heat) =? Fire)

g. Big V Dumb V (Big ::::} Dumb)

7.11 Any propositional logic sentence is logically equivalent to the assertion that each possible world in which it would be false is not the case. From this observation, prove that any

sentence can be written in CNF.

7.12 Use resolution to prove the sentence -,A 1\ -,B from the clauses in Ex.ercise 7.20.

7.13 This exercise looks into the relationship between clauses and implication sentences.

282

Chapter 7.

Logical Agents

8. Show that the clause (""'H V ... V ""'Pm V Q) is logical I e uivale '"

sentence (H 1\ ... 1\ Pm) ~ Q. y q nt to the implicadon

b. thShofW that every clause (regardless of the number of positive literals) can be written in

e orm (PI 1\ ... 1\ P, ) ~ (Q V V Q) h

s mbols mI. :.. n , w ere the Ps and Qs are proposition

/ "KA kno~ledge base consisting of such sentences is in implicative normal onn or owalski fonn (Kowalski, 1979).

c. Write down the full resolution rule for sentences in implicative normal f orm.

7.14 According to some political pundits a rs .. .

he/she is conservative (C) but oth . .' pe on who IS radical (R) IS electable (E) if

, erwrse IS not electable.

B. W~ich of the following are correct representations of this assertion? (I) (RI\E) {::::} C

(ii) R ~ (E {::::} C)

(iii) R ~ ((C ~ E) V....,E)

b. Which of the sentences in (a) can be expre d i H

sse III om form?

7.1S This question considers representing satisfiability (SAT) problems as CSPs

B. Draw the constraint graph corresponding to the SAT problem .

("",XI V X2) 1\ ("",X2 V X3) 1\ 1\ ( X

'" ...., n-l V Xn)

for the particular case n = 5.

b. How many solutions are there for this ral

c. Suppose we apply BACKTR gene SAT problem as a function of n?

C ACKING-SEARCH ( 21

S: of the type given in (a). (To find all p~ge 5) to find all solutions to a SAT

basic algorithm so it continues se hi solutions to a CSP, we simply modify the variables are ordered X X arc ng after each solution is found.) Assume that will the algornhm take to tei . '. n and false is ordered before true How much time

rmmate? (Write an O( ) . .

d. We know that SAT probl . . expression as a function of n.)

h . '. ems m Hom form can b I . .

c. ammg (unit propagation). We also kno e so ved In linear time by forward

discrete, finite domains can be solved i ":' that every tree-structured binary CSP with

ti 6 0 ve In time Ii .

on .5). Are these two facts con t d? D' mear ID the number of variables (See-

nee e. ISCUSS.

~ .J 1

716 E I'

or xp am why every nonempty Propositional .

rously that every set of five 3-SAT I . . clause, by Itself, is satisfiable. Prove rig-

exactly th di causes IS sattsfiabl .

ree istmcr variables Wh t i h e, provided that each clause mentions

Construct such a set. . a IS t e smallest set of such clauses that is unsatisfiable?

7.17 A propositional2-CNF '.

2 literal expreSSIon IS a coniun .

s, e.g., ~ elton of clauses, each containing exactly

(A V B) /\ (....,A V C) /\ (-,B V D) 1\ (....,C V G

B. Prove using resolution that the bo ) 1\ (-,D V G) .

a ve sentence entails G.

Exercises

NO OVERNIGHT

Reserve Area Use ONLYI1

283

1lISJUNCT1'lE I«lRW.L FORt.1

b. Two clauses are semantically distinct if they are not logically equivalent. How many semantically distinct 2-CNF clauses can be constructed from n proposition symbols?

c. Using your answer to (b), prove that propositional resolution always terminates in time polynomial in n given a 2-CNF sentence containing no more than n distinct symbols.

d. Explain why your argument in (c) does not apply to 3-CNF.

7.18 Consider the following sentence:

[(Food => Party) V (Drinks => Party)] => [(Food 1\ Drinks) => Party}.

8. Determine, using enumeration, whether this sentence is valid, satisfiable (but not valid), or unsatisfiable.

b. Convert the left-hand and right-hand sides of the main implication into CNF, showing

each step, and explain how the results confinn your answer to (a).

c. Prove your answer to (a) using resolution.

7.19 A sentence is in disjunctive nonnal fonn (DNF) if it is the disjunction of conjunctions of literals. For example, the sentence (A 1\ B 1\ ..,C) V (....,A 1\ C) V (B 1\ -,C) is in D NF.

8. Any propositional logic sentence is logically equivalent to the assertion that some possible world in which it would be true is in fact the case. From this observation, prove

that any sentence can be written in DNF.

b. Construct an algorithm that converts any sentence in propositional logic into DNF. (Hint: The algorithm is similar to the algorithm for conversion to CNF given in Sec-

tion 7.5.2.)

c. Construct a simple algorithm that takes as input a sentence in DNF and returns a satis-

fying assignment if one exists, or reports that no satisfying assignment exists.

d. Apply the algorithms in (b) and (c) to the following set of sentences:

A=>B B=>C

C => ..,A.

e. Since the algorithm in (b) is very similar to the algorithm for conversion to CNF, and since the algorithm in (c) is much simpler than any algorithm for solving a set of sentences in CNF, why is this technique not used in automated reasoning?

7.20 Convert the following set of sentences to clausal fonn.

S I: A {:} (B V E). S2: E => D.

S3: C /\ F => ....,B. S4: E ~ B.

S5: B => F.

S6: B => C

Give a trace of the execution of DPLL on the conjunction of these clauses.

290

Chapter 8.

First-Order Logic

can have any degree of belief, ranging from 0 (total disbelief) to I (total beliefj.' For example, a probabilistic wurnpus-world agent might believe that the wumpus is in [1,3] with probability 0.75. The ontological and epistemological commitments of five different logics are summarized in Figure 8.1.

Language Ontological Commitment Epistemological Commitment
(What exists in the world) (What an agent believes about facts)
Propositional logic facts true/false/unknown
First-order logic facts, objects, relations true/false/unknown
Temporaiiogic facts, objects, relations, times true/false/unknown
Probability theory facts degree of belief E [0,1]
Fuzzy logic facts with degree of truth E [0, 1 J known interval value
Figure 8.1 Formal languages and their ontological and epistemological commitments. . In the ~ext section, we will launch into the details of first-order logic. Just as a student of physl.cs ~U1res ~ome familiarity with mathematics, a student of AI must develop a talent for w?rkmg With ~oglcal notation. On the other hand, it is also important not to get too concerned with the specifics of logical notation-after all, there are dozens of different versions. The ~ain thin~s to keep hold of are how the language facilitates concise representations and how Us semantics leads to sound reasoning procedures.

8.2 SYNTAX AND SEMANTICS OF FIRST-ORDER LOGIC

We begin this section by spec if . .

f fi . ying more precisely the way in which the possible worlds

o rst-order logic reflect the ant I . al .

. . a ogre comrmtment to objects and relations. Then we

introduce the vanous elements of th I . .

e anguage, explaining their semantics as we go along.

8.2.1 Models for first-order logic

Recall from Chapter 7 that the mod If'

. he oossi e s 0 a logical language are the formal structures that

constitute t e possible Worlds unde iderari

I . al r consi eration, Each model links the vocabulary of the

ogle sentences to elements of the po ibl I

be determined Th od ~s.. e wor d, so that the truth of any sentence can

truth values Mode~\ m fi els for prop~sJtlOnal logic link proposition symbols to predefined in them I Th~ domai: 0; rstod·Ordl ~r logic are much more interesting. First, they have objects

. a a m e IS the set of objects d . Th do-

main is required to be nonem -eve . or ommn elements it contains. e

Exercise 8.7 for a diSCUSSiO:Z em ry POSSible World mu~t contain at least one object. (See what these objects are-all th t pty ~orlds.) Mathemancally speaking, it doesn't matter

a matters IS how many there are l . d I but

for pedagogical purposes we'll ere are In each particular rno e-

use a concrete example. Figure 8.2 shows a model with five

3 It is important not 10 confuse the degree of belief in . . .

Indeed, some fuzzy systems allow uncertaint (de Pro~llity theory with the degree of truth in fuzzy logiC.

y gree of behet) about degrees of truth.

NO OVERNIGHT

Re.erve Area Use ONLYII

Section 8.2.

Syntax and Semantics of First-Order Logic

291

objects: Richard the Lionheart, King of England from 1189 to 1199; his younger brother, the evil King J ohn, who ruled from 1199 to 1215; the left legs of Richard and John; and a crown.

The objects in the model may be related in various ways. In the figure, Richard and John are brothers. Formally speaking, a relation is just the set of tuples of objects that are related. (A tuple is a collection of objects arranged in a fixed order and is written with angle brackets surrounding the objects.) Thus, the brotherhood relation in this model is the set

{ (Richard the Lionheart, King John), (King John) Richard the Li onhe art ) }. (8.1)

(Here we have named the objects in English, but you may, if you wish, mentally substitute the pictures for the names.) The crown is on King John's head, so the "on head" relation contains just one tuple, (the crown) King John). The "brother" and "on head" relations are binary relations-that is, they relate pairs of objects. The model also contains unary relations, or properties: the "person" property is true of both Richard and John; the "king" property is ~e only of John (presumably because Richard is dead at this point); and the "crown" property IS

true only of the crown. .' . .

Certain kinds of relationships are best considered as functions, m that a given object

must be related to exactly one object in this way. For example, each person has one left leg, so the model has a unary "left leg" function that includes the following mappings:

(Richard the Lionheart) --+ Richard's left leg (8.2)

(King John) --+ John's left leg.

lOfALFUNCTIOOS Strictly speaking, models in first-order logic require total functions, that is, there must be a value for every input tuple. Thus, the crown must have a I~ft leg ~nd so mu.s~ each,,~f t~~ le~! legs. There is a technical solution to this awkward problem involving an additional invisible

F· 82 A d It' ing five obiects two binary relations, three unary relations

sgure . mo e can aim J' .

(indicated by labels on the objects), and one f_u_n_ct_lO_n_,_le_ft_.I_e_g_. _..l

292

Chapter 8.

First-Order Logic

object that is the left leg of everything that has no left leg: including itself. Fortunately, as long as one makes no assertions about the left legs of thmgs that have no left legs, these technicalities are of no import.

So far, we have described the elements that populate models for first-order logic. The other essential part of a model is the link between those elements and the vocabulary of the logical sentences, which we explain next.

8.2.2 Symbols and interpretations

We tum now to the syntax of first-order logic. The impatient reader can obtain a complete description from the formal grammar in Figure 8.3.

The basic syntactic elements of first-order logic are the symbols that stand for objects, relations. and functions. The symbols, therefore, come in three kinds: constant symbols, which stand for objects: predicate symbols, which stand for relations; and function symbois. which stand for functions. We adopt the convention that these symbols will begin with uppercase letters. For example, we might use the constant symbols Richard and John; the predicate symbols Brother, OnHead, Person, King, and Crown; and the function symbol LeftLt~g. As with proposition symbols, the choice of names is entirely up to the user. Each predicate and function symbol comes with an arity that fixes the number of arguments.

As in propositional logic, every model must provide the information required to determine if any given sentence is true or false. Thus, in addition to its objects, relations, and functions, each model includes an interpretation that specifies exactly which objects, relations and functions are referred to by the constant, predicate, and function symbols. One possible interpretation for our example-which a logician would call the intended interpretation-is as follows:

'-AITY

MERPRETATION

I'ffl:NDEO MERPRETATION

• Rirhard refers to Richard the Lionheart and John refers to the evil King John.

• Bmtlu~r refers to the brotherhood relation, that is, the set of tuples of objects given in Equation (8.1); OnHead refers to the "on head" relation that holds between the crown and King John; Person, King, and Crown refer to the sets of objects that are persons, kings, and crowns.

• L(~ft:Leg refers to the "left leg" function, that is, the mapping given in Equation (8.2).

There ~ many other possible interpretations. of course. For example, one interpretati~n maps Richard to the crown and John to King John's left leg. There are five objects 10 the model, so ~ere are 25 possible interpretations just for the constant symbols Richarrl ~d John: Notice that not all the objects need have a name-for example, the intended interpretatIOn does nO.t nam.e the crown or the legs. It is also possible for an object to have several names; there IS an mterpretation under which both Richard and John refer to ~e crown." If y~u find this possibility confusing, remember that, in propositional logic, it IS perfectly possible to have a model in which Cloudy and Sunny are both true; it is the job of the knowledge base to rule out models that are inconsistent with our knowledge.

4 Later, in Section 8.2.8, we examine a semantics in which ev bi has

cry 0 ~ect exactly one name.

Section 8.2.

293

NO OVERNIGHT

Re.erve Area Use ONLYII

Syntax and Semantics of First-Order Logic

Sentence AtomicS entence ComplexSentence

-+ AtomicSentence I ComplexSentenre

-+ Predicate I Predicate(Term, ... ) I Term = Term

-+ (Sentence) I [Sentence]

I --, Sentence

I Sentence /\ Sentence

I Sentence V Sentence

I Sentence =? Sentence

I Sentence ¢:> Sentence

I Quantifier Variable, ... Sentence

Term

-+ Function ( Term, ... ) Constant

Variable

Quantifier -+ VI ::3
Constant -+ A I XI I John I ...
Variable -+ a I x I s I ... Raining I ...
True I False I After I Loves I
Predicate -+
Function -+ Mother I LejtLeg I
OPERATOR PRECEDENCE --'!, =, /\, V, =>, ¢:> 10 ic with equality, specified in Backus-Naur !orrn

F)'gore 8 3 The syntax: of first-order g. ion) Operator precedences are specified,

• T ith thtS notation .

(see page 1060 if you are not famt iar WI of uantifiers is such that a quantifier holds over

from highest to lowest. The precedence q

everything to the right of it.

R J

R J

R J

et of all models for a language with two constant sy~-

Figure 8.4 Some members of t~e s b 1 The interpretation of each constant syrnbol is

bols Rand J, and one binary relatton sYdml °h' related objects are connected by arrows.

' W' h' each mo e, t e

shown by a gray arrow. It m

•••

294

Chapter 8.

First-Order Logic

In summary, a model in first-.order logic consists of a set of objects and an interpretation that ~aps constant symbols to objects, predicate symbols to relations on those objects and function symbols to functions on those objects. Just as with propositional logic e tail'

lidit d. ,n ment,

va I I y, an ~ on are defined In terms of all possible models. To get an idea of what the

set. of all possible ~odels looks like, see Figure 8.4. It shows that models vary in how many objects they contam-from one up to infinity-and in the wa th

b. Y e constant symbols map

:~ ~h~esc~eI~:e7 : t:? cons~t symbols and one object, then both symbols must refer

b. th jeer; t IS can still happen even with more objects. When there are more

o ~ects an constant symbols f th bi .

of possible models is unbou~d:me 0 .e 0 ~ect~ will have no names. Because the number

mod I· ~. ' checking entailment by the enumeration of all possible

e s IS not feasible for first-order I . (unlik ..

objects is restricted th be f oglc. un. I e proPOSI tional logic). Even if the number of

, e num r 0 combinauons can be v I (5 .

the example in Figure 8.4, there are 137 ery ~e.. ee Exercise 8.5.) For

,506,194,466 models WIth SIX or fewer objects.

8.2.3 Terms

TERM

A tenn is a logical expression that refe .

but it is not always convenient to h rs~? ~n object. Constant symbols are therefore terms,

in English we might use the ex av~ a ~,Stl~ct symt:"l to name every object. For example, to his leg. This is what functi pressl~n I King Jo~ s left leg" rather than giving a name use LeftLeg( John) In the on slym a s are for: Instead of using a constant symbol, we

. genera case a comple t . c.

followed by a parenthesized list f t' x erm IS formed by a function symbol

to remember that a complex to. e~s as arguments to the function symbol. It is important

" erm IS Just a complicated ki d f . .

call that "returns a value" Th . n 0 name. It IS not a "subrounre

. ere IS no LejtLeg subro t· th

returns a leg. We can reason about left Ie s e . u me at takes a person as input and

and then deducing that John m t h g ( .g.: stating the general rule that everyone has one

Thi . us ave one) WIthout ..

IS IS something that cannot be d. ever providing a definition of LeftLeg,

one With subroutin . 5

The formal semantics of terms is sn-s es m programming languages.

function symbol f refers to some f s ISti s~ghtforward. Consider a term f (it, ... ,tn)· The to o~jects in the domain (call them u~c on In th_e model (call it F); the argument terms refer that IS the value of the function F Iii· , ,tin), and the term as a whole refers to the object function symbol refers to the f tJ·app ed to.dI, ... .a; For example, suppose the LejtLeg

th unc on shown 10 E .

en LejtLeg(John) refers to King J h ' quatlon (8.2) and John refers to King John,

ref f 0 n s left leg I tho

erent 0 every term. . n IS way, the interpretation fixes the

8.2.4 Atomic sentences

Now that we have both terms for ref .

I . I' ernng to bi

re auons, we can put them togethe to 0 ~ects and predicate symbols for referring to

r make atomic t '

5 A.expressions provid f sen ences that state facts. An atoJlllC

leauseulntti .

example, the functi th 0 a on m which new fu .

just like any oth ~n .at squares its argument can be w itt nction symbols are constructed "on the fly." For

er runcuon symbol A \ n en as (AX X x ) d ments

Chapter 22 ) The 1 mb . ,,-expression can ai be de x an can be applied to argu

not increase the fi a al da operator in Lisp plays exactly th so fined and used as a predicate symbol. (See can be rewritten bon;: I ex~res~i~e. power of first-Order 10 .; s:me role. Notice that the use of A in this way ~s

y p uggmg rn us arguments to Yield::' .ecause any sentence that includes a A_expression eqwvaient sentence.

Section 8.2.

NO OVERNIGHT

Re.erve Area Use ONLYIf

Syntax and Semantics of First-Order Logic

295

mucSENTENCE sentence (or atom for short) is formed from a predicate symbol optionally followed by a

W,I parenthesized list of terms, such as

Brother (Richard, John}.

This states, under the intended interpretation given earlier, that Richard the Lionheart is the brother of King John." Atomic sentences can have complex terms as arguments. Thus,

Married (Father( Richard), M other( John)}

states that Richard the Lionheart's father is married to King John's mother (again, under a suitable interpretation).

An atomic sentence is true in a given model if the relation referred to by the predicate

symbol holds among the objects referred to by the arguments.

IlWmFIER

-NDTERM

8.2.5 Complex sentences

We can use logical connectives to construct more complex sentences, with the same syntax and semantics as in propositional calculus. Here are four sentences that are true in the model of Figure 8.2 under our intended interpretation:

-,Brother (LeftLeg (Richard), John)

Brother (Richard , John) 1\ Brother ( John, Richard) King(Richard) V King(John)

-,King(Richard} =? King(John).

8.2.6 Quantifiers

Once we have a logic that allows objects, it is only natural to want to express properties of entire collections of objects, instead of enumerating the objects by name. Quantifiers let us do this. First-order logic contains two standard quantifiers, called universal and existential.

Universal quantification M

Recall the difficulty we had in Chapter 7 with the expression of general rules in propositional logic. Rules such as "Squares neighboring the wumpus are smelly" and "All kings are persons" are the bread and butter of first-order logic. We deal with the first of these in Section 8.3. The second rule, "All kings are persons," is written in first-order logic as

V x King(x} =? Person(x).

V is usually pronounced "For all ... ". (Remember that the upside-down A stands for "a11.") Thus, the sentence says, "For all x, if x is a king, then x is a person." The symbol x is called a variable. By convention, variables are lowercase 1etters. A variable is a term all by itself, and as such can also serve as the argument of a function-for example, LeftLeg (x). A term

with no variables is called a ground term.

Intuitively, the sentence V x P, where P is any logical expression, says that P is true

for every object x. More precisely, V x P is true in a given model if P is true in all possible extended interpretations constructed from the interpretation given in the model, where each

6 We usually follow the argument-ordering convention that P(x, y) is read as "x is a P of y.'.

296

Chapter 8.

First-Order Logic

extended interpretation specifies a domain element to which x refers

. Thi~ sounds com~lica~ed, but it is really just a careful way of stating the intuitive mean~ng of unI:ersaJ quantification. Consider the model shown in Figure 8.2 and the intended mterpretation that goes with it. We can extend the interpretation in five ways:

x - Richard the Lionheart

,

x - King John,

x - Richard's left leg, x - John's left leg,

x - the crown.

The universally quantified sentence V x K· () .

if the sentence King(x) => Perso ( ) . zng x =} Person(x) IS true in the original model

tions. That is, the universall uan.n x IS true ~nder ~ach of the five extended interpretasentences: y q tified sentence IS equivalent to asserting the following five

Richard the Lionheart is a kin R·

King John i ki . g =} ichard the Lionheart is a person.

. ,IS a ng => King John is a person.

Richard s left leg is a king => Richard' I ft I .

J h ' I ~ I . s e eg IS a person

o n s ett eg IS a king =} John's left 1 . .

The crown i eg IS a person

e crown IS a king => the crown i .

IS a person.

~t us look carefully at this set of assertions .. .

king, the second sentence asserts th t h . . Since, 10 our model, King John is the only

the other four sentences which a e IS a person, as we would hope. But what about of the meaning of "All lei'· appear to make claims about legs and crowns? Is that part

ngs are persons"? In:E th

model, but make no claim wh t . act, e other four assertions are true in the

or indeed Richard This is bee a soever about the personhood qualifications of legs crowns, for => (Figure 7.8· on page 2~)use none of these objects is a king. Looking at the ~th table

:E I ' we see that the impli ti . .

a se--regardless of the truth of th . ca on IS true whenever its premise IS

. t. e conclusIon Thus bv asserri . d

sen ence, which is equivalent to . . ,y assertmg the universally quanbfie

. assertmg a whole 1· t f i di . d

up assertmg the conclusion of th I. IS a 10 VIdual implications, we en

and . e ru e Just for those b· c

saying nothing at all about th ... 0 jeers lor whom the premise is true

truth-table definition of =} t ose mdividuals for whom the premise is false Thus the

if urns out to be perfecr j . . .'

quanti ers. eet lor WTItIng general rules with univer:;al

A common mistak

. e, made frequently eve b ..

graph several times, is to use coniu ti . n y dihgent readers who have read this para-

~ nc on instead of . r .

V x K. () Imp rcation. The sentence

zng x II Person(x)

would be equivalent to asserting

Richard the Lio h .

. . n eart IS a king II Richar .

K.lDg John IS a king II King John is d the Lionheart is a person,

Richard's left leg is a ki . a person,

ng II Richard's left leg is a

and so on. Obviously thi d person,

, IS oes not capture what

we want.

Section 8.2.

NO OVERNIGHT

Re.erve Area Use ONLYII

Syntax and Semantics of First-Order Logic

297

Existential quantification (3)

Universal quantification makes statements about every object. Similarly, we can make a statement about some object in the universe without naming it, by using an existential quantifier. To say, for example, that King John has a crown on his head, we write

3x Crown(x) II OnHead(x, John) .

3x is pronounced "There exists an x such that ... " or "For some x ... ".

Intuitively, the sentence 3 x P says that P is true for at least one object x. More precisely, 3 x P is true in a given model if P is true in at least one extended interpretation that assigns x to a domain element. That is, at least one of the following is true:

Richard the Lionheart is a crown II Richard the Lionheart is on John's head; King John is a crown /\ King John is on John's head;

Richard's left leg is a crown II Richard's left leg is on John's head; John's left leg is a crown /\ John's left leg is on John's head;

The crown is a crown 1\ the crown is on John's head.

The fifth assertion is true in the model, so the original existentially quantified sentence is true in the model. Notice that, by our definition, the sentence would also be true in a model in which King John was wearing two crowns. This is entirely consistent with the original

sentence "King John has a crown on his head." 7

Just as ::?- appears to be the natural connective to use with 'r:/, II is the natural connective

to use with 3. Using /\ as the main connective with 'r:/ led to an overly strong statement in the example in the previous section; using '* with 3 usually leads to a very weak statement,

indeed. Consider the following sentence:

3x Crown(x) '* OnHead(x,John).

On the surface, this might look like a reasonable rendition of our sentence. Applying the semantics, we see that the sentence says that at least one of the following assertions is true:

Richard the Lionheart is a crown =* Richard the Lionheart is on John's head; King John is a crown =* King John is on John's head;

Richard's left leg is a crown =* Richard's left leg is on John's head;

and so on. Now an implication is true if both premise and conclusion are true, or if its premise is false. So if Richard the Lionheart is not a crown, then the first assertion is true and the existential is satisfied. So, an existentially quantified implication sentence is true whenever any object fails to satisfy the premise; hence such sentences really do not say much at all.

Nested quantifiers

We will often want to express more complex sentences using multiple quantifiers. The simplest case is where the quantifiers are of the same type. For example, "Brothers are siblings"

can be written as

'r:/x 'r:/y Brother(x,y) =* Sibling(x,y).

7 There is a variant of the existential quantifier, usually written 31 or :J!, that means "There exists exactly one." The same meaning can be expressed using equality statements.

298

Chapter 8.

First-Order Logic

Consecutive quantifiers of the same type can be written as one quantifier with several vari. abies. For example, to say that siblinghood is a symmetric relationship, we can write

V x, y Sibling (x, y) {:} Sibling(y, x) .

In other case~ we will have mixtures. "Everybody loves somebody" means that for every person, there IS someone that person loves:

V x :3 y Loves (x, y) .

On the other hand, to say ''There is someone who is loved by everyone," we write

:3 y V x Loves(x, y) .

The order of quantification is therefore ve .

theses V x (3 L ( )) ry Important. It becomes clearer if we insert paren-

erty that they l~veo:~::;:e ~?~ tha~veryone has a particular property, namely, the propthe world has a particular· e 0 er hand, 3 y (\:/ x Loves (z, y)) says that someone in

Some confusi p~perty, namely the property of being loved by everybody.

usion can anse when two q tifi .

Consider the sentence uan ers are used WIth the same variable name.

"Ix (.Croum(x) V (:3 x Brother(Richard,x))).

Here the x m Brother(Richard ). .

belongs to the innennost quanni x :a exlSte~tiall~ quantified. The rule is that the variable

quantification. Another way t~ :nk !~~~non~ ~t; then it will not. be subject to any other about Richard (that he has a b th ) IS this. :3 x Brother ( Richard, x) is a sentence

co er, not about X' so p tti w .. 1

could equally well have been itten B ,u ng a v X outside It has no effect. t

wn ten d z Broth (R· h rd )

of confusion, we will always use diffi . er sc a ,z. Because this can be a source

erent variable names with nested quantifiers.

Connections between V and :3

The two quantifiers are actually' ti

rti th 10 mately connected with h A

se 109 at everyone dislikes parsni . I eae other, through negation. s-

h I' ..... snips IS the same as .

w 0 ikes them, and vice versa: assertmg there does not exist someone

V x .Likes(x, Parsnips) is equivalent to .3 x . .

We can go one step further' "E '. Lzkes (x, P arsmps) .

not like ice cream: . veryone likes Ice cream" means that there is no one who does

Y x Likes(x,IceCream) is equivalent to. .

Because V is really a coni ti 3 x .L~kes(x, IceCream) .

be . . "unc on over the unive f bi

not surpnsmg that they obey De M rse 0 0 ~ects and :3 is a disjunction it should

. fi organ's rules Th ' d

unquann ed sentences are as follows: . e De Morgan rules for quantified an

Vx =P = .:3x P

.Y x P -:::J P .(P V Q) - .p 1\ -,Q

V x P =:::J X -, .(P 1\ Q)

:3 =: .3 x =P P 1\ Q - -,p V .Q

x P =: .Yx =P P - '(,PV'Q)

Thus, we do not really need b th V : Q =:.(.P 1\ .Q) .

readability is more important::.an an~ 3, Just as we do not really need both 1\ and V. Still, parsimony so we will kee

' 1 P both of the quantifiers.

Section 8.2.

NO OVERNIGHT

Reserve Area Use ONLYII

Syntax. and Semantics of First-Order Logic

299

8.2.7 Equality

First-order logic includes one more way to make atomic sentences, other than using a predicate and terms as described earlier. We can use the equality symbol to signify that two terms refer to the same object. For example,

Father(John) = Henry

says that the object referred to by Father(John) and the object referred to by Henry are the same. Because an interpretation fixes the referent of any term, determining the truth of an equality sentence is simply a matter of seeing that the referents of the two terms are the same

object.

The equality symbol can be used to state facts about a given function, as we just did for

the Father symbol. It can also be used with negation to insist that two terms are not the same object. To say that Richard has at least two brothers, we would write

3 x, y Brother (x, Richard) 1\ Brother (y, Richard) 1\ -, (x = y) .

The sentence

3 x, y Brotheri», Richard) 1\ Brother(y, Richard)

does not have the intended meaning. In particular, it is true in the model of Figure 8.2, where Richard has only one brother. To see this, consider the extended interpretation in which both x and y are assigned to King John. The addition of --.(x = y) rules out such models. The notation x #- y is sometimes used as an abbreviation for --.(x = y).

8.2.8 An alternative semantics?

Continuing the example from the previous section, suppose that we believe that Richard has two brothers, John and Geoffrey.8 Can we capture this state of affairs by asserting

Brother (John, Richard) 1\ Brother ( Geoffrey, Richard) ? (8.3)

Not quite. First, this assertion is true in a model where Richard has only one brotherwe need to add John #- Geoffrey. Second, the sentence doesn't rule out models in which Richard has many more brothers besides John and Geoffrey. Thus, the correct translation of

"Richard's brothers are John and Geoffrey" is as follows:

Brother( John, Richard) 1\ Brother( Geoffrey, Richard) 1\ John #- Geoffrey

1\ V x Brother(x, Richard) ~ (x = John V x = Geoffrey) .

For many purposes, this seems much more cumbersome than the corresponding naturallanguage expression. As a consequence, humans may make mistakes in translating their knowledge into first-order logic, resulting in unintuitive behaviors from logical reasoning systems that use the knowledge. Can we devise a semantics that allows a more straightfor-

ward logical expression?

One proposal that is very popular in database systems works as follows. First, we insist

that every constant symbol refer to a distinct object-the so-called unique-names assumption. Second, we assume that atomic sentences not known to be true are in fact false-the closed-world assumption. Finally, we invoke domain closure, meaning that each model

8 Actually he had four, the others being William and Henry.

314

Chapter 8.

First-Order Logic

Leopold Lowenheim (I 915) gave a systematic treatment of model theory for first -order logic, including the first proper treatment of the equality symbol. Lowenheirri's results w~~ further extended by Thoralf Skolem (1920). Alfred Tarski (1935, 1956) gave an explicit definition of truth and model-theoretic satisfaction in first-order logic, using set theory.

McCarthy ( 1958) was primarily responsible for the introduction of first -order logic as a tool for building AI systems. The prospects for logic-based AI were advanced significantly by Robinson's (1965) development of resolution, a complete procedure for first-order inference described in Chapter 9. The logicist approach took root at Stanford University. Cordell Green (1969a, I 969b ) developed a first-order reasoning system, Q A 3, leading to the first attempts to build a logical robot at SRI (Fikes and Nilsson, 1971). First-order logic was applied by Zohar Manna and Richard Waldinger (1971) for reasoning about programs and later by Michael Genesereth (1984) for reasoning about circuits. In Europe, logic programming (a restricted form of first-order reasoning) was developed for linguistic analysis (Colmerauer et 01., 1973) and for general declarative systems (Kowalski, 1974). Computational logic was also well entrenched at Edinburgh through the LCF (Logic for Computable Functions) project (Gordon et al .• 1979). These developments are chronicled further in Chapters 9 and 12.

Practical applications built with first-order logic include a system for evaluating the manufacturing requirements for electronic products (Mannion, 2(02), a system for reasoning about policies for file access and digital rights management (Halpern and Weissman, 2(08), and a system for the automated composition of Web services (McIlraith and Zeng, 2001).

Reactions to the Whorf hypothesis (Whorf, 1956) and the problem of language and thought in general, appear in several recent books (Gumperz and Levinson, 1996; Bowerman and Levinson, 200 I; Pinker, 2003; Gentner and Goldin-Meadow, 2003). The "theory" theOl)' (Gopnik and Glymour, 2002; Tenenbaum et aI., 2007) views children's learning about the world as analogous to the construction of scientific theories. Just as the predictions of a machine learning algorithm depend strongly on the vocabulary supplied to it, so will the chi Id' s formulation of theories depend on the linguistic environment in which learning occurs.

There are a number of good introductory texts on first-order logic, including some by leading figures in the history of logic: Alfred Tarski (1941), Alonzo Church (1956), and W. V. Quine (1982) (which is one of the most readable). Enderton (1972) gives a more mathematically oriented perspective. A highly formal treatment of first-order logic, along with many more advanced topics in logic, is provided by Bell and Machover (1977). Manna and ~aldinger (1985) give a readable introduction to logic from a computer science perspective, as do Huth and Ryan (2004), who concentrate on program verification. Barwise and Etchemendy. (2002) ~ake an approach similar to the one used here. Smullyan (1995) presents results co~clsely, u~l~g the tableau format. Gallier (1986) provides an extremely rigoro~s mathematical ex~sltton of first-order logic, along with a great deal of material on its use In autom~ted reasom~g .. Logical ~oundations of Artijiciallntelligence (Genesereth and Nilsson, 1 ~87) IS both a solid Introductton to logic and the first systematic treatment of logical agents With percepts and actions, and there are two good handbooks: van Bentham and ter Meulen (199:) and ~o~inson and Voronkov (2001). The journal of record for the field of pure mathe~atIcallogIc IS the Journal of Symbolic Logic, whereas the Journal of Applied Logic deals With concerns closer to those of artificial intelligence.

NO OVERNIGHT

Reserve Are. Use ONLYII

315

Exercises

EXERCISES

ld usi t of sentences with no explicit

8.1 A logical knowledge base repn:sents th~ wo~ u~:~ ahs~ physical structure that corre-

structure. An analogical representation, on e 0 ~d C~nsider a road map of your country sponds directly to the structure of the thing rePhresen try. it represents facts with a map lan-

. t t" n of facts about t e coun -

as an analogical represen a 10 d to the two-dimensional surface

guage. The two-dimensional structure of the map correspon s

of the area.

a. Give five examples of symbols in the map langUage·f th representation actually writes

. ntence that the creator 0 e

h. An explicit sentence IS a se th It from explicit sentences because

. 1·· te e is a sentence at resu s

down. An Imp ictt sen nc . G e three examples each of implicit and

of properties of the analogical representatlOn. IV

explicit sentences in the map language. . I structure of your country that cannot be

c. Give three examples of facts about the physlca

represented in the map language. . ess in the map language than in

d. Give two examples of facts that are much easier to expr

first-order logic. al tations What are the advantages

e Give two other examples of useful analogic represen .

. 1 es?

and disadvantages of each of these anguag .

PC) d P(b) Does this

.. iust two sentences: a an .

8.2 Consider a knowledge base contammg J wer in terms of models.

knowledge base entail \;j x P(x)? Explain your ans

- vali d? Explain.

8.3 Is the sentence "3 x, y x - y . . . .

rld in which It IS true contains exactly 8.4 Write down a logical sentence such that every wo

one object. b I' predicate symbols

I h t ontains c constant sym 0 s, Pk .

8.S Consider a symbol vocabu ary t a c . k here 1 < k < A. Let the domain

. yrnbols of each amy , w --

of each arity k, and Jk [uncnon s h edicate or function symbol is mapped onto a

size be fixed at D. For any given model, eac P~t You may assume that the functions in the relation or function, respectively, of the same an£; y. th function (i e the value is the invisible model allow some input tuples to have no value slbl e ad Is for a domain with D elements.

h mber of POSSi e m e

object). Derive a formula for t e nu ..

.. d ndant combmattons.

Don't worry about elimmatmg re u

. arily true) sentences?

8.6 Which of the following are valid (necess

a. (3x x=x) :=} (\ly 3z y=z).

h. \I x P(x) V ----.P(x).

c. \I x Smart(x) V (x = x). .

. or first-order logic in which models w~th empty

8 7 Consider a version of the semantics f f that are valid accordmg to the

• amples 0 sentences

domains are allowed. Give at least two ex

316

Chapter 8.

First-Order Logic

standard semantics but not according to the new semantics. Discuss which outcome makes more intuitive sense for your examples.

8.8 Doe~ the fact -,Spouse(.George, Laura) follow from the facts Jim of:. George and Spouse( Jam, Laura)? If so, give a proof; if not, supply additional axioms as needed. What happens if we use Spouse as a unary function symbol instead of a binary predicate?

8.9 This exercise uses the function MapCoior and predicates In(x, y), Borders(x,y), and Co~ntry(x.). whose arguments are geographical regions, along with constant symbols for v~ous re~iOns. In each of the following we give an English sentence and a number of candidate logical exp~ssions. For each of the logical expressions, state whether it (I) correctly ~xpresses. the Engl~sh sentence; (2) is syntactically invalid and therefore meaningless; or (3) IS syntactically valid but does not express the meaning of the English sentence.

8. Paris and Marseilles are both in France. (i) In(Paris 1\ Marseilles,Prance).

(ii) In (Paris , Prance} A In(Marseilles, Prance). (iii) In (Paris , Prance) V In (Marseilles , Prance}.

b. There is a country that borders both Iraq and Pakistan.

(i) "3 c Country ( c) 1\ Border( c, Iraq) 1\ Border( c, Pakistan}.

~~~) "3 c Country(c) => [Border(c, Iraq) 1\ Border(c, Pakistan )]. (1lI) [3c Country (c)] => [Border(c, Iraq) A Border(c, Pakistan)]. (iv)"3c Border(Country(c),Iraq 1\ Pakistan).

c. All countries that border Ecuador are in South America.

~~) V c Country(c) 1\ Border(c, Ecuador) => In(c SouthAmerica).

(~~~» ~ C [CCountry(c} => [Border(c, Ecuador) => I~{c SouthAmerica}].

111 v C ountry(c) => Bord ( Ed)] ,

C ) 'r;j C er c, cua or => In(c SouthAmerica).

IV ~ .ountry(c) 1\ Border(c, Ecuador} 1\ In(c, Sou;hAmerica).

d. No region In South America borders an . .

. y region m Europe.

(I) -,[3 C, d In(c, SouthAmeTica) 1\ I (d

(ii) V c d [In(c S thA. n ,Europe) A Borders{c, d)].

, ,ou mertca) 1\ In(d E )]

(iii) -,V c In( c, SouthA merica) =} , urope => ,Borders (c, d) J.

(iv) V c In (c, SouthA meTica) => V "3 d In (d, Europe) 1\ +Borders (c, d).

. d In(d, Europe) => -'Borders(c d).

e. No two adjacent countries have the s '

arne map color

(i) V x, y -,Country(x) V -'Country(y) V B ~

-'(MapColor(x) = MapC l ()) -, 0 ers(x, y) V

C) 0 or y

II 'r;j X, Y (Country(x) 1\ Country( ) I\. B'

... -'(MapColor(x) = MapCol~r(y))Orders(x,y) A -,(x = y)) =>

(Ill) V x, y Country(x) I\. Country( ) A B .

. -,(MapCo[or(x) = MapC:Zor(y)}rders(x, y) A

(IV) V x, Y (Country(x) 1\ Country(y) I\. B~rders(x, y)) => Map Color (x f: y).

Exercises

NO OVERNIGHT

Reserve Area Use ONLYIJ

WGNos"nc RULE

tN.lSAL RULE

8.10 Consider a vocabulary with the following symbols:

Occupation (p, 0): Predicate. Person p has occupation o.

Customer (p 1, p2): Predicate. Person pI is a customer of person p2. Boss (p 1, p2): Predicate. Person pI is a boss of person p2.

Doctor, Surgeon, Lawyer, Actor: Constants denoting occupations.

Emily, Joe: Constants denoting people.

Use these symbols to write the following assertions in first-order logic:

3. Emily is either a surgeon or a lawyer.

b. Joe is an actor, but he also holds another job.

c. All surgeons are doctors.

d. Joe does not have a lawyer (i.e., is not a customer of any lawyer).

e. Emily has a boss who is a lawyer.

f. There exists a lawyer all of whose customers are doctors.

g. Every surgeon has a lawyer.

8.11 Complete the following exercises about logical senntences: 3. Translate into good, natural English (no xs or ys!):

'if x, y, 1 SpeaksLanguage (x, l) 1\ SpeaksLanguage (y, l) => Understands (x, y) 1\ Understands(y, x).

b. Explain why this sentence is entailed by the sentence

'if x, y, I Speaks Language (x, l) 1\ Speaks Language (y, l) =? Understands (z, y).

c. Translate into first-order logic the following sentences: (i) Understanding leads to friendship.

(ii) Friendship is transitive.

Remember to define all predicates, functions, and constants you use.

8.12 Rewrite the first two Peano axioms in Section 8.3.3 as a single axiom that defines N atN um (x) so as to exclude the possibility of natural numbers except for those generated by

the successor function.

8.13 Equation (8.4) on page 306 defines the conditions under which a square is breezy. Here

we consider two other ways to describe this aspect of the wumpus world.

a. We can write diagnostic rules leading from observed effects to hidden causes. For finding pits, the obvious diagnostic rules say that if a square is breezy, some adiacent squ~e must contain a pit; and if a square is not breezy, then no adjacent s~uan: co~talDs.a PIt. Write these two rules in first-order logic and show that their conJunctlon 1S loglcally

equivalent to Equation (8.4).

b. We can write causal rules leading from cause to effect. One obvious causal rule is that

a pit causes all adjacent squares to be breezy. Write this rule in first~or~er lo~ic. explain why it is incomplete compared to Equation (8.4), and supply the missmg axiom.

318

Chapter 8.

First-Order Logic

George H Mum

.r>:

Elizabeth 114 Philip Margaret

S"~7KYdrl

D'7\~J"

William Harry

ATk A'7\ EdWAh',

Peter Zara Beatrice Eugenie Louise James

Figure 8.7 children.

A typical family tree. The symbol "1><1" connects spouses and arrows point to

8.14 Write axioms describing the di G

Broth S' t D pre icates ran dchild , Greatgrandparent Ancestor

cr. ss er, aughter Son FirstG . B h "

Uncle Find out the 'd fi : . ousm, rot erlnLaw, Sisterlnl.aui; Aunt, and

. .. proper e muon of mth co' .

inition in first-order logic N' usm n times removed, and write the def-

Figure 87 Using a suit I b'l lOW. wnl te down the basic facts depicted in the family tree in

. . a e ogica reasoning syst T . all

written down and ASK't ho are Eli em, ELL It the sentences you have

great-grandp~ents and EI W o.ar: hzabeth's grandchildren, Diana's brothers-in-law, Zara's

, ugeme s ancestors.

8.1S Explain what is wrong with the f II .

predicate E: 0 owmg proposed definition of the set membership

'<Ix,s XE{xls}

'<Ix,s xEs::} Vy XE{yls}.

8.16 Using the set axioms as exam les w '. .

constants, functions and predi p'. nteaxioms for the list domain, including all the

. ' tcates mentioned in the chapter.

8.17 Explain what is wrong with the folio . . . .

the wumpus world: wmg proposed definition of adjacent squares In

'<I x, y Adjacent([x y] [ + 1 ])

8' ' , x ,y /\ Adjacent([x,yj, [x,V + 1]) .

. 18 Wnte out the axioms required for . .

const~t symbol Wumpus and a bin re~somng about the wumpuss location, usmg a

there IS only one wumpus. my predicate At ( Wumpus, Location). Remember that

8.19 Assuming predicates P

with the obvious meanings ex arent(p, q) and Female(p) and constants Joan and Kevin, , press each of the foil .

may use the abbreviation 31 to m" . owing sentences in first-order logic. (You

Jean there exists exactly one")

a. oan has a daught ( . .

er possibly more than on .

h. Joan has exactly one d h e, and possibly sons as well).

c. Joan has exactl a~g ter (but may have sons as well).

y one child, a daughter

d. Joan and Kevin h .

e J h ave exactly one child together

. oan as at least one child ith K . .

WI evm and n hildre

, 0 c 1 n with anyone else.

NO OVERNIGHT

Reserve Are. Use ONLYIJ

Exercises

319

8.20 Arithmetic assertions can be written in first-order logic with the predicate symbol <, the function symbols + and x, and the constant symbols 0 and 1. Additional predicates can

also be defined with biconditionals.

a. Represent the property "x is an even number." h. Represent the property "x is prime."

c. Goldbach's conjecture is the conjecture (unproven as yet) that every even number is equal to the sum of two primes. Represent this conjecture as a logical sentence.

8.21 In Chapter 6, we used equality to indicate the relation between a variable and its value. For instance, we wrote W A = red to mean that Western Australia is colored red. Representing this in first-order logic, we must write more verbosely ColorOf( WA) = red. What incorrect inference could be drawn if we wrote sentences such as WA = red directly as logical

assertions?

8.22 Write in first-order logic the assertion that every key and at least one of every pair of socks will eventually be lost forever, using only the following vocabulary: Key (x), x is a key; Sock(x), x is a sock; Pair(x, y), x and yare a pair; Now, the current time; Bejoreit«, t2)' time tl comes before time t2; Lost(x, t), object x is lost at time t.

8.23 For each of the following sentences in English, decide if the accompanying first-order logic sentence is a good translation. If not, explain why not and correct it. (Some sentences

may have more than one error!)

a. No two people have the same social security number.

,3 x, y, n Person(x) A Person(y) ==> [HasSS#(x, n) A HasSS#(y, n)J.

h. John's social security number is the same as Mary's.

3 n HasSS#(John, n) /\ HasSS#(Mary, n).

c. Everyone's social security number has nine digits.

V z, n Person(x) ==> [HasSS#(X, n) /\ Digits(n, 9)].

d. Rewrite each of the above (uncorrected) sentences using a function symbol SS # instead of the predicate HasSS#.

8.24 Represent the following sentences in first-order logic, using a consistent vocabulary (which you must define):

a. Some students took French in spring 2001. h. Every student who takes French passes it.

c. Only one student took Greek in spring 200 1.

d. The best score in Greek is always higher than the best score in French.

e. Every person who buys a policy is smart.

f. No person buys an expensive policy.

g. There is an agent who sells policies only to people who are not insured.

320

Chapter 8.

First-Order Logic

177-1~

Figure 8.8 A four-bit adder. Each Ad, is a one-bit adder, as in Figure 8.6 on page 309.

h. There is a barber who shaves all men in town who do not shave themselves.

i. A person born in the UK, each of whose parents is a UK citizen or a UK resident, is a UK citizen by birth.

j. A person born outside the UK, one of whose parents is a UK citizen by birth, is a UK citizen by descent.

k. Politicians can fool some of the people all of the time, and they can fool all of the people some of the time, but they can't fool all of the people all of the time.

I. All Greeks speak the same language. (Use Speaks (x, 1) to mean that person x speaks

language l.)

8.25 Write a general set of facts and axioms to represent the assertion "Wellington heard about Napoleon's death" and to correctly answer the question "Did Napoleon hear about Wellington's death?"

8.26 Extend the vocabulary from Section 8.4 to define addition for n-bit binary numbers. Then encode the description of the four-bit adder in Figure 8.8, and pose the queries needed to verify that it is in fact correct.

8.27 Obtain a passport application for your country, identify the rules determining eli~' bility for a passport, and translate them into first-order logic, following the steps outlined In Section 8.4.

8.28 Consider a first-order logical knowledge base that describes worlds containing people, songs, albums (e.g., "Meet the Beatles") and disks (i.e., particular physical instances of CDs). The vocabulary contains the following symbols:

CopyOf(d, a): Predicate. Disk d is a copy of album a. Owns(p, d): Predicate. Person p owns disk d.

Sings(p, s, a): Album a includes a recording of song s sung by person p. Wrote(p, s): Person p wrote song s.

McCartney: Gershwin, BHoliday, Joe, EleanorRigby, TheManILove, Revolver:

Constants With the obvious meanings.

Exercises

321

NO OVERNIGHT

Reserve Area Use ONLY!!

Express the following statements in first-order logic:

a. Gershwin wrote "The Man I Love."

b. Gershwin did not write "Eleanor Rigby." "

c. Either Gershwin or McCartney wrote "The Man I Love.

d. Joe has written at least one song.

e. Joe owns a copy of Revolver. .

f. Every song that McCartney sings on Revolver was wntten by McCartney.

g Gershwin did not write any of the songs on Revolver. ibl diff t

h. Every song that Gershwin wrote has been recorded on some album. (POSSI y I eren

songs are recorded on different albums.) .

i. There is a single album that contains every song that J~ ~s ~ntten. "

j Joe owns a copy of an album that has Billie Holiday smgmg 'The Man I Love. h

k, Joe owns a copy of every album that has a song .sung by McCartney. (Of course, eac

different album is instantiated in a different physical CD.) ..'

hi h all the songs are sung by Billie Holiday, I. Joe owns a copy of every album on w IC

344

Chapter 9.

Inference in First-Order Logic

by the knowledge base. There is no way to assert that a sentence is false in Prolo T' Prolog less expressive than first-order logic, but it is part of what makes Prolo g. his makes and more concise. Consider the following Prolog assertions about some cour:e ~~~rt:;.lenl

Course(CS,lOl), Course (CS, 102), Course(CS, 106), Course(EE, 101). (9'.11)

Under the umque names assumption CS and EE diff

so this means that there are four disti'nct courses ;;ed I ~ren~ (as are 101. 102, and 106),

are no other courses, so there are exactl . n er e. c osed-world assumption there rather than in Prolog then all IdY fou~ courses. But If these were assertions in POL

, we cou say IS that there h b

infinity courses. That's because th .. are somew ere etween one and

unmentioned courses are also offe~:sertl~nsh(m FOL) do not deny the possibility that other from each other. If we wanted to tr ' ~or : t e~ say that the courses mentioned are different

ans ate quation (9.11) into FOL, we would get this:

Course(d, n) ¢} (d= CS /\ n = 101) V (d = CS /\ n = 102)

. . V(d=CS/\n=106)V(d=EE/\n=101) 12

ThIs IS called the completion of E uatio .' (9. )

at most four courses To express 'nqpOL thn (9: 11). It expresses m FOL the idea that there are

. . I e Idea that there I {:

to wnte the completion of the ali are at east lOur courses, we need

equ tty predicate:

x = y ¢} (x = CS /\ - CS)

Y - V (x = EE /\ Y = EE) V (x = 101/\ Y = 101)

. . V (x = 102 /\ Y = 102) V (x = 106/\ Y = 106)

The completion IS useful for understandin d t b . .

your problem can be described with d b a a ase semantics, but for practical purposes, if

Plata ase semanti ..

rolog or some other database' ICS, It IS more efficient to reason with

soning with a full FOL the semantics system, rather than translating into POL and reaorem prover.

9.4.6 Constraint logic programming

In our discussion of forward ch . . .

hi ammg (Section 9 3) h .' .

pro ems (CSPs) can be encoded d fi . " we s owed how constraint sattsfacnon

in e I th as e mte clauses St dard P

xact y e same way as the backtra ki .' an rolog solves such problems

Because backtracking en c ng algorithm given in Figure 6.5.

do . C umerates the domains f th . .

main SPs. In Prolog terms th 0 e variables, it works only for finite-

with bo d ' ere must be a finit be

un un variables. (For exam I h e num r of solutions for any goal

and South Australia must be diff P e, t e goal d i, f f (Q, SA) , w hieh says that Queensland

I fi '. erent colors has si .

n nite-domain CSPs-for example . h i ' as SIX solutions if three colors are allowed.)

ferent al ith ' WIt integer or real at ed . if

gon ms, such as bounds pro a' . -v u vanables-require quite di -

Consider the following ex I p gallon or hnear programming.

holds if the three arguments are ::!bee. Whe defi~e triangle (X, Y I Z) as a predicate that

. rs t at satisfy the tri I'

t r L angle (X I Y, Z) : _ ang e inequality:

X>O, Y>O, Z>O X+Y-Z

I ' >-, Y+Z>-X

f we ask Prolog th . - , X+Z>=Y.

k' e query tn.angle (3 .

~s d~ nang 1 e (3 , 4 , Z) , no solution will '~ ',5 ) , It succeeds. On the other hand, if we

an ed by Prolog; we can't compare ound, because the subgoal Z > = 0 cannot be

an unbound value to O.

NO OVERNIGHT

R ••• "'" Are. Use ONLYJI

345

Section 9.5.

Resolution

Constraint logic programming (CLP) allows variables to be constrained rather than bound. A CLP solution is the most specific set of constraints on the query variables that can be derived from the knowledge base. For example, the solution to the triangle (3 14 I Z) query is the constraint 7 >= Z >= 1. Standard logic programs are just a special case of CLP in which the solution constraints must be equality constraints-that is, bindings.

CLP systems incorporate various constraint-solving algorithms for the constraints allowed in the language. For example, a system that allows linear inequalities on real-valued variables might include a linear programming algorithm for solving those constraints. CLP systems also adopt a much more flexible approach to solving standard logic programming queries. For example, instead of depth-first, left-to-right backtracking, they might use any of the more efficient algorithms discussed in Chapter 6, including heuristic conjunct ordering, backjumping, cutset conditioning, and so on. CLP systems therefore combine elements of constraint satisfaction algorithms, logic programming, and deductive databases.

Several systems that allow the programmer more control over the search order for inference have been defined. The MRS language (Genesereth and Smith, 1981; Russell, 1985) allows the programmer to write metaruIes to determine which conjuncts are tried first. The user could write a rule saying that the goal with the fewest variables should be tried first or

could write domain-specific rules for particular predicates.

9.5 RESOLUTION

The last of our three families of logical systems is based on resolution. We saw on page 250 that propositional resolution using refutation is a complete inference procedure for propositionallogic. In this section, we describe how to extend resolution to first-order logic.

9.5.1 Conjunctive normal form for first-order logic

As in the propositional case, first-order resolution requires that sentences be in conjunctive normal form (CNF}--that is, a conjunction of clauses, where each clause is a disjunction of literals." Literals can contain variables, which are assumed to be universally quantified. For

example, the sentence

Vx American(x) /\ Weapon(y) /\ Sells(x,y,z) /\ Hostile(z) ===> Criminal (x)

becomes, in CNF,

-.American(x) V -. Weapon(y) V _,Sells(x, y, z) V -.Hostile(z) V Criminal(x) .

Every sentence of first-order logic can be converted into an inferentially equivalent CNF sentence. In particular, the CNF sentence will be unsatisfiable just when the original sentence is unsatisfiable, so we have a basis for doing proofs by contradiction on the CNF sentences.

6 A clause can also be represented as an implication with a conj unction of atoms in the premise and a disjunction of atoms in the conclusion (Exercise 7.13). This is called implicative normal fonn or Kowalski fonn (especially when written with a right-to-Ieft implication symbol (Kowalski, 1979)) and is often much easier to read.

346

Chapter 9.

Inference in First-Order Logic

The procedure. fo~ conv.ersion to CNF is similar to the proposi tional case, which we saw ~eP~r:s~~~ -::ee pnn:al d~fference ~ses from the need to eliminate existential quantifiers. loved by someone.tor ure y translating the sentence "Everyone who loves all animals is

"Ix ["Iy Animal(y) => Loves(x,y)] => [3y Loves(y,x)].

The steps are as follows:

• Eliminate implications:

"Ix [-Ny -,Animal(y) V Loves(x,y)] V [::3y Loves(y,x)].

• Move..., inwards: In addition to the us al I

for negated quantifiers Th h u ru es for negated connectives, we need rules

. us, we ave

...,"1 x p becomes ::3 x ""p

...,::3x p becomes "Ix +p .

OUf sentence goes through the following transform u' .

V [::3' a ons.

x y...,( ""A~tmal(y) V Loves (x, V))] V [3 Loves ( )]

V x [3 y ...,...,Ammal( ) /\ L ( y y, x .

Vx [3y A' l() Y ..., oves x,y)] V [::3y Loves(y,x)].

. mma y /\ ...,Loves(x, y)] V [3 y Loves( x

NotJc~ how a universal quantifier (V in . y, . )] . . .

an existential quantifier Th y) the premise of the implication has become

. e sentence now reads "Eith th .

doesn't love, or (if this is not th I er ere IS some animal that x

original sentence has been pres e cadse) someone loves x." Clearly, the meaning of the erve .

• Standardize variables: For sentences like (::3

variable name twice change th x P( x) } V (3 x Q (x)) which use the same

I ' e name of one of the . bl .. .

ater when we drop the quantifi Th vana es. ThIS avoids confusion

ers. us, we have

V x [3 y A nimal(y) /\ ...,Loves( )] [

• Skolemlze: Skolemizati . th x, Y V 3 z Loves (z, x)] .

. on IS e process of . . . .

nation, In the simple case it is' t lik removing existential quantifiers by eltnu-

translate ::3 x P (x) into P(' A) JUhS I Ae ~e Existential Instantiation rule of Section 9.1:

. . ,were IS a new co ta H

istential Instantiation to our se t ns nt. owever, we can't apply Ex-

I n ence above beca it d '

on y parts of the sentence match th use I oesn t match the pattern 3 v 0';

matching parts we get e pattern. If we blindly apply the rule to the tWO

V x [Animal{A) /\ ...,Loves(x A)] V L

hi h h ,oves(B x)

w IC as the wrong meani .. "

ticular ani ng entirely: It says th t

ICU ar animal A or is loved b . a everyone either fails to love a par-

II y some parncular entity B I

a ows each person to fail to love a differen . 1 . n fact, our original sentence

Thus, we want the Skolem entities to d t animal or to be loved by a different person. epend on x and .

'r/ x [Animal(F(x)) /\ L z.

Here F and G are Sk I f"" o~es(x, F(x))] V Loves(G(z), x) .

Sk 0 em unctions Th

olem function are al1 the. . e general rule is that the arguments of the

.. umversally uantifi . .

tential quanufier appears As with E' q .anu ed vanables in whose scope the eX1S-

satisfi bl . xistential Instanti . .

a e exactly when the origi al . anon, the Skolemized sentence IS

10 sentence IS satisfiable.

SKQLEM FUNCTION

NO OVERNIGHT

Reserve Area Use ONLYIJ

347

Section 9.5.

Resolution

• Drop universal quantifiers: At this point, all remaining variables must be universal1y quantified. Moreover, the sentence is equivalent to one in which all the universal quantifiers have been moved to the left. We can therefore drop the universal quantifiers:

[Animal(F(x)) /\ ...,Loves(x,F{x))] V Loves(G(z),x) .

• Distribute V over /\:

[Animal(F(x}} V Loves(G(z),x)1 /\ [...,Loves(x,F(x)) V Loves(G(z},x)].

This step may also require flattening out nested conjunctions and disjunctions.

The sentence is now in CNF and consists of two clauses. It is quite unreadable. (It may help to explain that the Skolem function F(x) refers to the animal potentially unloved by x, whereas G(z) refers to someone who might love x.) Fortunately, humans seldom need look at CNF sentences-the translation process is easily automated.

9.5.2 The resolution inference rule

The resolution rule for first-order clauses is simply a lifted version of the propositional resolution rule given on page 253. Two clauses, which are assumed to be standardized apart so that they share no variables, can be resolved if they contain complementary literals. Propositionalliterals are complementary if one is the negation of the other; first-order literals are complementary if one unifies with the negation of the other. Thus, we have

£1 V ... V £kl ffil V ... V ffin

SUBST(O, £1 V '.' V £i-1 V £i+l V ... V £k V ml V .. ' V mj-l V ffij+l V .' . V mn) where UNIFY (£i' ...,m j) = O. For example, we can resolve the two clauses

[Animal(F(x)) V Loves(G(x),x)] and [...,Loves(u,v) v...,Kills(u,v)]

by eliminating the complementary literals Loves(G(x}, x) and -.Loves(u, v), with unifier o = { u I G (x), v I x }, to produce the resolvent clause

[Animal(F(x)) V ...,Kills(G(x),x)].

BlNARv~ESOLIJTION This rule is caned the binary resolution rule because it resolves exactly two literals. The binary resolution rule by itself does not yield a complete inference procedure. The fun resolution rule resolves subsets ofliterals in each clause that are unifiable. An alternative approach is to extend factoring-the removal of redundant literals-to the first-order case. Propositional factoring reduces two literals to one if they are identical; first-order factoring reduces two literals to one if they are unifiable. The unifier must be applied to the entire clause. The

combination of binary resolution and factoring is complete.

9.5.3 Example proofs

Resolution proves that KB F 0: by proving KB /\ ...,0: unsatisfiable, that is, by deriving the empty clause. The algorithmic approach is identical to the propositional case, described in

348

Chapter 9.

Inference in First-Order Logic

l ~,4 ..... rk"n(A) V ~W""pon'y) v ~S'II$(q'.:.1 v ~H/J<I;k(1.J v CriIIrinal(..,!l l-.crimiJrdl(West)l ,I

l ,4.m.....(W.,,)1 l.~"""ie.m(Wffl) V ~WeQponlyJ V ~S,/Is(WeSl.y.l) V ~Hostile(<.Il I ~Miss;k(xJ V Wuptln(xil I ~WUjJOII(J) v ~Sells(WeSl.y.:.) v ~H"'tile(lil

J

lO"~S(N""".MV~ ..,(}wns(N/JIIO,M,) V ~HOSI;k(NonoJ l I ~E""my(x.Amn;m) V "",IW(XJ~"Q!tih(NOIW)l

I E ..... J'!N_,A .... riea) .l-.E~e"'JiN""",A .... riea~

'2]

Figure 9.11 are in bold.

A resolution proof that W. t i "

es IS a criminal, At each step, the literals that unify

Figure 7.12, so we need not repeat it here I .

the crime example from Section 93Th . nstead, ~e give two example proofs, The first is

.. e sentences III CNF are

..,American(x) V.., Weapon(y) V..,S lls( ,

..,Missile(x) V..,Oums(N ) e z , y, z) V ..,Hostzle{z} V Criminal(x)

E ono,x V Sells{West N )

.., nemy(x, America) V Hostile(x) ,x, ono

..,Missile(x) V Weapon(x)

Owns(Nono, Mt}

American( West} Missile{M1)

We also include th ed Enemy (Nono, America) .

e negat goal ..,Criminal{ W t) Th .

ure 9.11. Notice the structure' singl " . es. e resolution proof is shown in Fig-

I . e spine" beginni . th th

causes from the knowledge base til th ng WI e goal clause, resolving against

f I, un e empty clau '

o reso ution on Horn clause kn I d se IS generated. This is characteristic

owe ge bases In f t th

correspond exactly to the consecuti al . ac, e clauses along the main spine

I . h rve v ues of the ls .

a gont m of Figure 9.6. This is b goa vanable in the backward-chaining

.. I' ecause we always h

posinve iteral unified with the I ftmost Ii c oose to resolve with a clause whose

ex tl h e ost hteral of the " " .

ac y w at happens in backward chai ' current clause on the spine; this IS

of resolution with a particular control nmg, Thus, backward chaining is just a special case

o strategy to decid hi h

.. ur second example makes use of Skolemi . e w IC resolution to perform next.

mrte clauses, This results in a so ha ization and involves clauses that are not def-

P bl . mew t more co I

ro em IS as follows: mp ex proof structure. In English, the

Everyone who loves all animals is I

Anyone who kills an animal is loved by someone.

J~ck loves all animals. oved by no one.

E~ther lack or Curiosity killed th '

Old Curiosity kill the cat? e cat, who IS named Tuna.

NO OVERNIGHT

R •• e",. Area Use ONLYJI

349

Section 9.5.

Resolution

First, we express the original sentences, some background knowledge, and the negated goal G in first-order logic:

A. v « [Vy Animal(y) ~ Loves(x,y)] ~ [3y Loves(y,x)]

B, "Ix [3z Animal(z)/\Kills(x,z)] ~ [\iy --,Loves(y,x}]

C. V x Animal(x} ~ Loves (Jack, x)

D. Kills(Jack, Tuna} V Kills ( Curiosity, Tuna)

E, Cat ( Tuna)

F. V x Cat(x} ~ Animal(x}

..,G. ..,Kills( Curiosity, Tuna)

Now we apply the conversion procedure to convert each sentence to CNF:

AI. Animal{F(x)) V Loves(G(x),x)

A2. --,Loves(x,F(x)) V Loves(G(x),x)

B. -.Loves(y, x) V ..,Animal(z} V ..,Kills(x, z}

C. -.Animal(x) V Loves (Jack , x)

D. Kills(Jack, Tuna} V Kills ( Curiosity, Thna)

E, Cat ( Thna}

F. ..,Cat(x) V Animal(x}

..,G, ..,Kills( Curiosity, Tuna}

The resolution proof that Curiosity killed the cat is given in Figure 9.12. In English, the proof

could be paraphrased as follows:

Suppose Curiosity did not kill Tuna, We know that either Jack or Curiosity did; thus Jack must have, Now, Tuna is a cat and cats are animals, so Tuna is an animal. Because anyone who kills an animal is loved by no one, we know that no one loves Jack. On the other hand. Jack loves all animals, so someone loves him; so we have a contradiction.

Therefore, Curiosity killed the cat.

Anim<rl(F(x» v wv.s(G{x). x)

Figure 9.12 A resolution proof that Curiosity killed the cat. Notice the use of factoring in the derivation of the clause Loves(G(Jack), Jack), Notice also in the upper right, the unification of Loves (x, F (x)) and Loves (J ack, x) can only succeed after the variables have

been standardized apart.

350

Chapter 9.

Inference in First-Order Logic

ANSWER lITERAl.

REFUTATION COMPI.ETENESS

The proof answers the question "Did Curiosity kill the cat?" but often we want to pose more general questions, such as "Who killed the cat?" Resolution can do this, but it takes a little more work to obtain the answer. The goal is :lw Kills(w, Tuna), which, when negated, becomes -, Kills (w, Tuna) in CNF. Repeating the proof in Figure 9.12 with the new negated goal, we obtain a similar proof tree, but with the substitution {w / Curiosity} in one of the steps. So, in this case, finding out who killed the cat is just a matter of keeping track of the bindings for the query variables in the proof.

Unfortunately, resolution can produce nonconstructive proofs for existential goals.

For example, -,Kills(w, Tuna) resolves with Kills(Jack, Tuna) V Kills ( Curiosity, Thna) to give Kills(Jack, Tuna), which resolves again with ..,Kills(w, Tuna) to yield the empty clause. Notice that w has two different bindings in this proof; resolution is telling us that, yes, someone killed Tuna--either Jack or Curiosity. This is no great surprise! One SI)lution is to restrict the allowed resolution steps so that the query variables can be bound only once in a given proof; then we need to be able to backtrack over the possible bindings. Another solution is to add a special answer literal to the negated goal, which becomes -'Kills(w, Tuna) V Answer(w). Now, the resolution process generates an answer whenever a clause is generated containing just a single answer literal. For the proof in Figure 9.12, this is Answer( Curiosity). The nonconstructive proof would generate the clause Answer( Curiosity) V Answer(Jack), which does not constitute an answer.

9.5.4 Completeness of resolution

This section gives a completeness proof of resolution. It can be safely skipped by those who are willing to take it on faith.

We show that resolution is refutation-complete, which means that if a set of sentences is unsatisfiable, then resolution will always be able to derive a contradiction. Resolution cannot be used to generate all logical consequences of a set of sentences, but it can be used to establish that a given sentence is entailed by the set of sentences. Hence, it can be used to find all answe~ to a.given question, Q(x), by proving that KB 1\ ..,Q(x) is unsatisfiable ..

We take It as given that any sentence in first-order logic (without equality) can be rewntten as a set of clauses in CNF. This can be proved by induction on the form of the sentence, using atomic sentences as the base case (Davis and Putnam, 1960). Our goal therefore is to prove the following: if S is an unsatisfiable set of clauses, then the application of a finite number of resolution steps to S will yield a contradiction.

Our proof sketch follows Robinson's original proof with some simplifications from Genesereth and Nilsson (1987). The basic structure of the proof (Figure 9.13) is as follows:

1. ~irst, we observe that if S is unsatisfiable, then there exists a particular set of ground instances of the clauses of S such that this set is also unsatisfiable (Herbrand's theorem).

2. We thenappeal to the ground resolution theorem given in Chapter 7, which states that propositional resolution is complete for ground sentences.

3. We then use a lifting lemma to show that, for any propositional resolution proof using the set of ground sentences, there is a corresponding first-order resolution proof using the first-order sentences from which the ground sentences were obtained.

Section 9.5.

NO OVERNIGHT

Re.erve Area Use ONLYII

351

Resolution

Any se of sentences S Is 'rre"ntoblo in clausal form Assume Sis unsatisfiable. and in clausal form

Some set S' of ground il'''"c" i, "n,,'i,fi,blo

Resolution "n find i contradiction tn S' . S' There is a resolution proof for the contradiction ill

Herbrand's theorem

Ground resolution theorem

Lifting lemma

Figure 9.13

Structure of a completeness proof for resolution.

eed three new concepts:

To carry out the first step, we n H the Herbrand universe of 8, is

H brand universe: If 8 is a set of clauses, then s,. .

• the set of all ground terms constructable from the following:

a. The function symbols in S, ~f any. if then the constant symbol A.

I . 8 f any' I none

b. The constant symbo Sill, 1 , (' F(x A)) V --,Q(x, A) V R(x, B), then

I if S contains just the clause -sP x, ,

For examp e, I .' f nd terms:

Hs is the following infinite set 0 grau F B B) F(A F(A, A)), ... } .

{A,B,F(A:A),F(A,B),F~~~)~ ~ ~ set' of gr~und terms, then P(S), ~he

• Saturation: If S IS a set of claus.e th t f all ground clauses obtained by apply 109

S itn pect to P IS e se 0 . 8

saturation of WI res . .' f d terms in P with variables 10 •

all possible consistent substItutIons 0 gro8un f I ses with respect to its Herbrand uni-

. of a set 0 c au .

• Herbrand base: The saturatIon . H (8) For example, if S contains

b d base of 8 wntten as s .

verse is called th~ Her. ran H (S') is the infinite set of clauses

solely the clause Just given, then s

{-,P(A, F(A, A)) V -,Q(A, A) V R(~~'

..,P(B, F(B, A)) V -,Q(B, A) V R~(F(~ A) A) V R(F(A, A), B), -,P(F(A, A), ~(~(~' 1; ~)) ~ ~Q(F(A', B), A) V R(F(A, B), B), ... }

-,P(F(A, B), ( (,' b d's theorem (Herbrand, 1930):

te a form of Her ran

These definitions allow us to sta ihere exi sts a finite subset of H s (8) that

. . fi bl then ere eXI

If a set S of clauses IS unsans a e,

is also unsatisfiable. appeal to the ground resolution

d tences Now, we can

Let 8' be this finite subset of groun sen .' I ure RC(S') contains the empty clause.

th th resolution cos. .

theorem (page 255) to show at e 1 tion on 8' will derive a contradiction.

. . I I tion to camp e 1 . .

That is running proposltlOna reso u . lways a resolution proof mvolvmg some

, li h d that there IS a . I .

Now that we have estab IS e t p is to show that there IS a reso unon

base of 8 the next s e

finite subset of the Herbrand '

356

Chapter 9,

Inference in First-Order Logic

original knowledge base is consistent. (After all, if it is not consistent th th f

query follows from it is vacuous.) The set-of-su ort strate ' ,~n e act that the generating goal-directed proof trees that ftpp"gYhaStheaddIuonaladvantageOf

are 0 en easy lor humans to understand,

IHP\IT RESCX.li1lON Input resolution' In this strat '

the KB or the qu~ry) with somegeYo' ethvery resolution combines one of the input sentences (from

er sentence The pro f i F 9

only input resolutions and has the charact isti. ha 0 m, igure .l l on page 348 uses

ens IC s pe of a single "soi " ith si

tences combining onto the spine CI I th pme WI single senthan the space of all proof graph lear J' e space of proof trees of this shape is smaller

input resolution strategy because ~~ n boom kn~wledge bases, Modus Ponens is a kind of other sentences, Thus .'t' I'S no I ~omthlO~s an Implication from the original KB with some

• surpnse at mput re I ti '

lINEARRESCUTlION that are in Hom form but incompl t ' th so u on IS complete for knowledge bases

I' h • e e in e general case Th li I .

s Ig t generalization that allows PdQ be ,e mear reso ution strategy is a

KB if P . an to resolved togethe ith ·f P' . . .

or I IS an ancestor of Q i th f' r ei er I IS m the original

n e proo tree. Linear resolution is complete.

Subsumptlon: Th b .

, . e su sumption method elimi

IS, more specific than) an existin . nates all sentences that are subsumed by (thai

th . g sentence m the KB Fo I' f

ere IS no sense in adding P( A) and even I . . r e~amp e, 1 P (x) is in the KB, then

helps keep the KB small and thus hel kess sense madding P(A) V Q(B}. Subsumption ps eep the search space small.

Practical uses of resolution theorem

provers

Theorem provers can be applied to the .

of both hardware and software Th problems involved in the synthesis and verification

hard desi . us, theorem-proving r h ' .

ware esign programmi I esearc IS carried out in the fields of

I • ng anguages and soft ..

n the case of hardware th . ' . ware engmeenng-not just in AI.

c it I ' e axioms descnbe the i .

Ul e ements. (See Section 842 e interactions between signals and cir-

. 11 ., on page 309 f

specra y for verification have been bl ' or an example.) Logical reasoners designed

erties (S . a e to venfy entire CPU .

. , nvas and Bickford, 1990) The s, including their timing prop-

circuits that are more compact th~ A~RA the~rem prover has been applied to design

In the case of software rea a~y previous design (Wojciechowski and Wojcik, 1983).

actio' • sonmg about progr . .

ns, as In Chapter 7' axio descri ams IS quite similar to reasoning about

The f I . ms escnbe the pre di .

orma synthesis of algorith con nons and effects of each statement.

by Cordell Green (1969a) Whombs .wI as one of the first uses of theorem provers as outlined

. ' ut t on e r . d '

IS to .constructively prove a theore t h ar rer I eas by Herbert Simon (1963), The idea

certam s . fi . mot e effect that ''tb ' '

. peci cation." Although f 11 ere exists a program p satisfymg a

yet become feasible for general- u y automated deductive synthesis, as it is called, has not

been succe f I'. purpose programming h d . .

ss u in deSigning several I • an -guided deductive synthesIs has

purpose p nove and sophisti t d al . ial

rograms, such as scientific . ca e gonthms. Synthesis of speCl .

Simil t hni computmg code' I

ar ec mques are now be. . ' IS a so an active area of research,

S PIN model h k mg applied to soft ., th

c ec er (Holzmann 1997) F ware verification by systems such as e

program was if ,. or example th R I

ven ed before and afte fl' h ' e emote Agent spacecraft conlfO

encryption algorithm and the Brig t (Havelund et at. 2(00) The RSA public key

way (B oyer-Moore tri "

oyer and Moore, 1984), s ng-matching algorithm have been verified this

SUBSUMPTION

SYNniESIS

VERIFICATION

DEDUCTIVE SYNTHESIS

NO OVERNIGHT

Re.erve Area Use ONLYII

357

Section 9.6.

Summary

9.6 SUMMARY

We have presented an analysis of logical inference in first-order logic and a number of algorithms for doing it.

• A first approach uses inference rules (universal instantiation and existential instantiation) to propositionalize the inference problem, Typically, this approach is slow,

unless the domain is small.

• The use of unification to identify appropriate substitutions for variables eliminates the

instantiation step in first-order proofs, making the process more efficient in many cases,

• A lifted version of Modus Ponens uses unification to provide a natural and powerful inference rule, generalized Modus Ponens. The forward-chaining and backwardcbaining algorithms apply this rule to sets of definite clauses.

• Generalized Modus Ponens is complete for definite clauses, although the entailment problem is semidecidable. For Datalog knowledge bases consisting of function-free

definite clauses, entailment is decidable.

• Forward chaining is used in deductive databases, where it can be combined with re-

lational database operations, It is also used in production systems, which perform efficient updates with very large rule sets, Forward chaining is complete for Datalog

and runs in polynomial time,

• Backward chaining is used in logic programming systems, which employ sophisti-

cated compiler technology to provide very fast inference. Backward chaining suffers from redundant inferences and infinite loops; these can be alleviated by memoization.

• Prolog, unlike first -order logic, uses a closed world with the unique names assumption and negation as failure. These make Prolog a more practical programming language,

but bring it further from pure logic.

• The generalized resolution inference rule provides a complete proof system for first-

order logic. using knowledge bases in conjunctive normal form.

• Several strategies exist for reducing the search space of a resolution system without compromising completeness. One of the most important issues is dealing with equality;

we showed how demodulation and paramodulation can be used,

• Efficient resolution-based theorem provers have been used to prove interesting mathematical theorems and to verify and synthesize software and hardware.

BIBLIOGRAPHICAL AND HISTORICAL NOTES

Gottlob Frege, who developed full first-order logic in 1879, based his system of inference on a collection of valid schemas plus a single inference rule. Modus Ponens. Whitehead and Russell (1910) expounded the so-called rules of passage (the actual term is from Herbrand (1930)) that are used to move quantifiers to the front of formulas. Skolem constants

360

Chapter 9.

Inference in First-Order Logic

ROBBI~ ALGEBRA

equational solver (Schulz, 2004) have also proven to be valuabl~ tools for ~roving correctness. Theorem provers have been used to automatically synthesize and venfy software for controlling spacecraft (Denney et al., 2006), including NASA's new Orion capsule (Lowry, 2008). The design of the FM900 I 32-bit microprocessor was proved correct by the N QTHM system (Hunt and Brock, 1992). The Conference on Automated Deduction (CADE) runs an annual contest for automated theorem provers. From 2002 through 2008, the most successful system has been VAMPIRE (Riazanov and Voronkov, 2(02). Wiedijk (2003) compares the strength of 15 mathematical provers. TPTP (Thousands of Problems for Theorem Provers) is a library of theorem-proving problems, useful for comparing the performance of systems (S utcli ffe and Suttner, 1998; Sutcliffe et al., 2006).

Theorem provers have come up with novel mathematical results that eluded human mathematicians for decades, as detailed in the book Automated Reasoning and the Discovery of Missing Elegant Proofs (Wos and Pieper, 2003). The SAM (Semi-Automated Mathematics) program was the first, proving a lemma in lattice theory (Guard et al., 1969). The AURA program has also answered open questions in several areas of mathematics (Wos and Winker, 1983). The Boyer-Moore theorem prover (Boyer and Moore, 1979) was used by Natarajan Shankar to give the first fully rigorous formal proof of Godel's Incompleteness Theorem (Shankar, 1986). The NUPRL system proved Girard's paradox (Howe, 1987) and Higman's Lemma (Murthy and Russell, 1990). In 1933, Herbert Robbins proposed a simple set of axioms-the Robbins algebra-that appeared to define Boolean algebra, but no proof could be found (despite serious work by Alfred Tarski and others). On October 10, 1996, after eight days of computation, EQP (a version of OTTER) found a proof (McCune, 1997).

Many early papers in mathematical logic are to be found in From Frege to GOdeI:

A Source Book in Mathematical Logic (van Heijenoort, 1967). Textbooks geared toward automated deduction include the classic Symbolic Logic and Mechanical Theorem Proving (Chang and Lee, 1973), as well as more recent works by Duffy (1991), Wos et al. (1992), Bibel (1993), and Kaufmann et al. (2000). The principal journal for theorem proving is the Journal of Automated Reasoning; the main conferences are the annual Conference on Automated Deduction (CADE) and the International Joint Conference on Automated Reasoning (lJCAR). The Handbook of Automated Reasoning (Robinson and Voronkov, 2001) collects papers in the field. MacKenzie' s Mechanizing Proof (2004) covers the history and technology of theorem proving for the popular audience.

EXERCISES

EXISTENTIAL INTRODUCTION

9.1 Prove that Universal Instantiation is sound and that Existential Instantiation produces an inferentially equivalent knowledge base.

9.2. From Likes (Jerry , Ice Cream ) it seems reasonable to infer :3 x Likes(x,IceCream). Wnte down a general inference rule, Existential Introduction, that sanctions this inference. State carefully the conditions that must be satisfied by the variables and terms involved.

NO OVERNIGHT

Reserve Area Use ONLYII

Exercises

361

. . t one sentence, '3 x AsH ighA s (x, Everest).

9.3 Suppose a knowledge b~~ contam~ JU~ pplying Existential Instantiation?

Which of the following are leglumate resu ts 0 a

8. AsHighAs(Everest, Everest).

b AsHighAs(Kilimanjaro, Everest). N . E rest)

. A H' hAs(Ben evtS, ve

c. AsHighAs(Kilimanjaro, Everest) A s 19

(after two applications).

. . the most general unifier if it exists:

9.4 For each pair of atomic sentences, give

a. P(A,B,B),P(x,y,z).

b. Q(y, G(A, B)), Q(G(x,x), y).

c. Older(Father(y), y), Older(Father(x), John).

d. Knows (Father(y) , y), Knows (x, x).

. 1 ices shown in Figure 9.2 (page 329).

9.5 Consider the subsumpnon aID h (J h ) Father(Richam)).

I . f r the sentence Employs ( Mot er 0 n , ffiM")

8. Construct the attice 0 (IBM ) ("Everyone works for .

th t nee Employs , y

b. Construct the lattice for e s~n e that unifies with the sentence.

Remember to include every kind of query d node in its subsumption lattice.

h sentence un er every . bl

c Assume that STORE indexes eac f these sentences contain vana es; Use

. h ld work when some 0 Po h ())

Explain how FETCH s au . b) and the query Employs (x, at er x .

as examples the sentences m (a) and (

11 . sentences, suitable for use with

. for the fa owmg

9.6 Write down logical representatIons

Generalized Modus Ponens:

8. Horses, cows, and pigs are mammals.

b. An offspring of a horse is a horse.

c. Bluebeard is a horse.

d. Bluebeard is Charlie's parent. .

. erse relatlOns.

e. Offspring and parent are mv

f. Every mammal has a parent.

. ith substitution and Skolemization.

. oncern concern Issues WI

9.7 These questions c . . alid to conclude that 3 q P ( q. q). Give

P( ) It IS not v .

8. Given the premise V x '3 y z, y, fi t is true but the second IS false.

d· P where the rs,

an example of a pre icate . . t1 written with the occurs check omitted,

. ngine IS mcorrec y . P( ) (A .

b. Suppose that an mference .e F x)) to be unified With q, q . s me " "".n ..... ,

so that it allows a literal h~e P(x, (10 actually do allow this.) Show that such most standard implementatIons of Pro. g '3 P( q q) to be inferred from the

. 11 the concluslOn Y )

inference engine Will a ow

v « 3y P(x,y).

<.'

362

Chapter 9. Inference in First-Order Logic

c. Suppose that a procedu th t

Skolemizes V x :3 v P re( a) copnverts first-order logic to clausal form incorrectly

x, y to (x SkO)-that is't I

stant rather than by a Skolem function' f Sh ' I rep. aces y by a Skolem con-

such a procedure will likewise allow ~ x. p( ow)that an .mference engine that uses

Vx 3y P(x,y). q q,q to be inferred from the premise

d. A common error among students is to su 0 ...

substitute a term for a Skolem co tan . pp se that, In unification, one is allowed to ns t Instead of for a variabl F .

say that the formulas P{ S k 1) and P( A) be . e. or instance, they will

Give an example where this 1 ad .can. ~mfied under the substitution {Ski/A}. e s to an invalid Inference.

9.8 Explain how to write any given 3-SAT bl .

definite clause and no more than 30 d pro em of arbitrary size using a single first-order

groun facts.

9.9

Suppose you are given the following axioms:

I. 0 < 3.

2. 7 < 9.

3. Vx x ~ x.

4. Vx x ~ x + O.

5. Vx x + 0 ~ x.

6.Vx,y x+y~y+x. 7.Vw,x,y,z w~yl\x<z

8 V-==} w + x S y + z.

. X,Y,z =s vr-v s » ==} x<z

B. Give a backward-chaining proof f h-

only th . 0 t e sentence 7 < 3 + 9 (B

e axioms given here, not an thin -' e sure, of course, to use

only the steps that leads to succ y g e~se you may know about arithmetic.) Show

b. Give a forward-ch . . ess, not the Irrelevant steps.

h ammg proof of the sentenc 7

t at lead to success. e S 3 + 9. Again, show only the steps

?10 A popular children's riddle is "Brothe .

IS my father's son." Use the rules of the f .7 and sl~ters have I none, but that man's father

;hO that ~an is. You may apply any of th~l i domain (Section 8.3.2 on page 30 I) to show

o you think that this riddle is difficult? m erence methods described in this chapter. Why

?11 Suppose we put into a logical knowled b

mg. the age, city of residence date of birth ge ase a segment of the U.S. census data list-

cunty numbe . ..' I , and mothe f .'

A rs as identifying constants" r 0 every person usmg SOCial se-

qe{443-65-1282 ). lor each perso Th ' .

'1 ,56 . Which of the foil '. n. us, George's age is given by

so ution for which of the queries Q l-Q4 (owmg .mdexing schemes S 1-55 enable an efficient

S assummg normal b

• 1: an index for each ato . . . ackward chaining)?

• . . m m each posItIon

S2. an index for each first argum .

• S3 . ent.

: an index for each predicate atom

• S4' . d .

. an In ex for each combination of predi

reate and first argument.

Exercises

NO OVERNIGHT

R ••• rve Area Use ONLYI1

363

• S5: an index for each combination of predicate and second argument and an index for

each first argument.

• Ql: Age (443-44-432 I , x)

• Q2: Residesln(x, Houston)

• Q3: Mother(x, y)

• Q4: Age(x,34) /\ Residesln{x, Tiny Town USA)

9.12 One might suppose that we can avoid the problem of variable conflict in unification during backward chaining by standardizing apart all of the sentences in the knowledge base once and for al1. Show that, for some sentences, this approach cannot work. (Hint: Consider

a sentence in which one part unifies with another.)

9.13 In this exercise, use the sentences you wrote in Exercise 9.6 to answer a question by using a backward-chaining algorithm.

a. Draw the proof tree generated by an exhaustive backward-chaining algorithm for the

query :3 h Horse (h), where clauses are matched in the order given.

b. What do you notice about this domain?

c. How many solutions for h actually follow from your sentences?

d. Can you think of a way to find all of them? (Hint: See Smith et al. (1986).)

9.14 Trace the execution of the backward~chaining algorithm in Figure 9.6 (page 338) when it is applied to solve the crime problem (page 330). Show the sequence of values taken on by

the goals variable, and arrange them into a tree.

9.15 The following Prolog code defines a predicate P. (Remember that uppercase terms are variables, not constants, in Prolog.)

P{X, [Xly]) • p{X,(yIZ]) :- P{X,Z).

a. Show proof trees and solutions for the queries P {A, (2, I, 3] ) and P {2, (1, A, 31 ) .

b. What standard list operation does P represent?

9.16 This exercise looks at sorting in Prolog.

a. Write Prolog clauses that define the predicate sorted (L) , which is true if and only if

list L is sorted in ascending order.

h. Write a Prolog definition for the predicate perm (L, M) , which is true if and only if L

is a permutation of M.

c. Define sort (L, M) (M is a sorted version of L) using perm and sorted.

d. Run sort on longer and longer lists until you lose patience. What is the time complex-

ity of your program?

e. Write a faster sorting algorithm, such as insertion sort or quicksort, in Prolog.

You might also like