RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we...

85
RESOLUTION AND FIRST ORDER LOGIC

Transcript of RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we...

Page 1: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

RESOLUTION AND FIRST ORDER LOGIC

Page 2: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Introduction

• In the last class we talked about logic.

• In particular we talked about why logic would be useful.

•We covered propositional logic — the simplest kind of logic.

•We talked about proof using the rules of natural deduction.

• This week we will look at some other aspects of proof.

•We will also look at a more expressive kind of logic.

cisc3410-fall2012-parsons-lect06 2

Page 3: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Logic and proof

• Need to be clear that logics exist separate from any proofmethod that they use.

• Can have one logic with many proof methods.

• Those same methods may work for many logics.

• So far we have looked at one logic (propositional logic) and oneproof system (natural deduction).

•We will look at:

– More proof systems for propositional logic

– Another logic.

cisc3410-fall2012-parsons-lect06 3

Page 4: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

• New proof systems:

– Forward chaining

– Backward chaining

– Resolution

• New logic

– Predicate logic

cisc3410-fall2012-parsons-lect06 4

Page 5: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

New proof systems

• One of the good things about natural deduction is that it is easyto understand.

– Proofs are often intuitive

• However, there is lots to decide:

– Which sentence to use

– Which rule to apply

• Can be hard to program a system to use it.

• Q: How to make it easier?

cisc3410-fall2012-parsons-lect06 5

Page 6: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Horn clauses

• A: Restrict the language

– Horn clauses

• A Horn clause is:

– An atomic proposition; or

– A conjunction of atomic propositions⇒ atomic proposition

• For example:C ∧ D ⇒ B

• KB = conjunction of Horn clauses

• For example:C ∧ (B ⇒ A) ∧ (C ∧ D ⇒ B)

cisc3410-fall2012-parsons-lect06 6

Page 7: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

•Modus ponens is then:

α1, . . . , αn, α1 ∧ · · · ∧ αn ⇒ β

β

• Sometimes called “generalized modus ponens”.

• For Horn clauses, modus ponens is all you need

– Complete

• Can be used with forward chaining or backward chaining.

• These algorithms are very natural and run in linear time

cisc3410-fall2012-parsons-lect06 7

Page 8: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Forward chaining

• Idea: “fire” any rule whose premises are satisfied in the KB,add its conclusion to the KB, until query is found

P ⇒ Q

L ∧M ⇒ P

B ∧ L ⇒ M

A ∧ P ⇒ L

A ∧ B ⇒ L

A

B

Q

P

M

L

BA

• How does this work?

cisc3410-fall2012-parsons-lect06 8

Page 9: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Q

P

M

L

BA

2 2

2

2

1

cisc3410-fall2012-parsons-lect06 9

Page 10: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Q

P

M

L

B

2

1

A

1 1

2

cisc3410-fall2012-parsons-lect06 10

Page 11: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Q

P

M

2

1

A

1

B

0

1L

cisc3410-fall2012-parsons-lect06 11

Page 12: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Q

P

M

1

A

1

B

0

L0

1

cisc3410-fall2012-parsons-lect06 12

Page 13: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Q

1

A

1

B

0

L0

M

0

P

cisc3410-fall2012-parsons-lect06 13

Page 14: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Q

A B

0

L0

M

0

P

0

0

cisc3410-fall2012-parsons-lect06 14

Page 15: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Q

A B

0

L0

M

0

P

0

0

cisc3410-fall2012-parsons-lect06 15

Page 16: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

A B

0

L0

M

0

P

0

0

Q

cisc3410-fall2012-parsons-lect06 16

Page 17: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

function PL-FC-ENTAILS?(KB, q) returns true or falseinputs: KB, the knowledge base, q the querylocal variables: count, a table, indexed by clause,

initially the number of premisesinferred, table of symbols, initially all falseagenda, list of symbols, initially whole KB

while agenda is not empty dop← POP(agenda)unless inferred[p] do

inferred[p]← truefor each Horn clause c in whose premise p appears do

decrement count[c]if count[c] = 0 then do

if HEAD[c] = q then return truePUSH(HEAD[c], agenda)

return false

cisc3410-fall2012-parsons-lect06 17

Page 18: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Proof of completeness

• FC derives every atomic sentence that is entailed by KB

1. FC reaches a fixed point where no new atomic sentences arederived

2. Consider the final state as a model m, assigning true/false tosymbols

3. Every clause in the original KB is true in mProof: Suppose a clause a1 ∧ . . . ∧ ak ⇒ b is false in mThen a1 ∧ . . . ∧ ak is true in m and b is false in mTherefore the algorithm has not reached a fixed point!

4. Hence m is a model of KB

5. If KB |= q, q is true in everymodel of KB, including m

• General idea: construct any model of KB by sound inference,check α

cisc3410-fall2012-parsons-lect06 18

Page 19: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Backward chaining

• Idea: work backwards from the query q

– to prove q by BC,

– check if q is known already, or

– prove by BC all premises of some rule concluding q

• Avoid loops: check if new subgoal is already on the goal stack

• Avoid repeated work: check if new subgoal

1. has already been proved true, or

2. has already failed

cisc3410-fall2012-parsons-lect06 19

Page 20: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Q

P

M

L

A B

cisc3410-fall2012-parsons-lect06 20

Page 21: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

P

M

L

A

Q

B

cisc3410-fall2012-parsons-lect06 21

Page 22: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

M

L

A

Q

P

B

cisc3410-fall2012-parsons-lect06 22

Page 23: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

M

A

Q

P

L

B

cisc3410-fall2012-parsons-lect06 23

Page 24: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

M

A

Q

P

L

B

cisc3410-fall2012-parsons-lect06 24

Page 25: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

M

A

Q

P

L

B

cisc3410-fall2012-parsons-lect06 25

Page 26: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

A

Q

P

L

B

M

cisc3410-fall2012-parsons-lect06 26

Page 27: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

A

Q

P

L

B

M

cisc3410-fall2012-parsons-lect06 27

Page 28: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Forward v. backward chaining

• FC is data-driven, cf. automatic, unconscious processing

– e.g., object recognition, routine decisions

•May do lots of work that is irrelevant to the goal

• BC is goal-driven, appropriate for problem-solving,

– e.g., Where are my keys? How do I get into a PhD program?

• Complexity of BC can be much less than linear in size of KB

cisc3410-fall2012-parsons-lect06 28

Page 29: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Resolution

• Resolution is another proof system.

– Sound and complete for propositional logic.

• Just one inference rule:

ℓ1 ∨ · · · ∨ ℓk, m1 ∨ · · · ∨ mn

ℓ1 ∨ · · · ∨ ℓi−1 ∨ ℓi+1 ∨ · · · ∨ ℓk ∨ m1 ∨ · · · ∨ mj−1 ∨ mj+1 ∨ · · · ∨ mn

where ℓi and mj are complementary literals.

• Eh?

cisc3410-fall2012-parsons-lect06 29

Page 30: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

• As an example, here:

OK

OK OK

A

A

B

P?

P?

A

S

OK

P

W

A

•We might resolve:

P1,3 ∨ P2,2, ¬P2,2

P1,3

• So, if we know P1,3 ∨ P2,2 and ¬P2,2 then we can conclude P1,3

cisc3410-fall2012-parsons-lect06 30

Page 31: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

• Only issue — resolution only works for KB in conjunctive normalform

• conjunction of disjunctions of literals︸ ︷︷ ︸

clauses

• Such as:

(A ∨ ¬B) ∧ (B ∨ ¬C ∨ ¬D)

• Have to convert sentences to CNF.

cisc3410-fall2012-parsons-lect06 31

Page 32: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

• Example: B1,1⇔ (P1,2 ∨ P2,1)

cisc3410-fall2012-parsons-lect06 32

Page 33: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

1. Eliminate⇔, replacing α⇔ β with (α ⇒ β) ∧ (β ⇒ α).

(B1,1 ⇒ (P1,2 ∨ P2,1)) ∧ ((P1,2 ∨ P2,1) ⇒ B1,1)

2. Eliminate⇒, replacing α⇒ β with ¬α ∨ β.

(¬B1,1 ∨ P1,2 ∨ P2,1) ∧ (¬(P1,2 ∨ P2,1) ∨ B1,1)

3. Move ¬ inwards using de Morgan’s rules and double-negation:

(¬B1,1 ∨ P1,2 ∨ P2,1) ∧ ((¬P1,2 ∧ ¬P2,1) ∨ B1,1)

4. Apply distributivity law (∨ over ∧):

(¬B1,1 ∨ P1,2 ∨ P2,1) ∧ (¬P1,2 ∨ B1,1) ∧ (¬P2,1 ∨ B1,1)

cisc3410-fall2012-parsons-lect06 33

Page 34: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Resolution example

• KB = (B1,1 ⇔ (P1,2 ∨ P2,1)) ∧ ¬B1,1

α = ¬P1,2

• First we have to convert the KB into conjunctive normal form.

• That is what we just did (here’s one I made earlier):

¬P2,1 ∨ B1,1

¬B1,1 ∨ BP1,2 ∨ P2,1

¬P1,2 ∨ B1,1

¬B1,1

• To this we add the negation of the thing we want to prove.

P1,2

cisc3410-fall2012-parsons-lect06 34

Page 35: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

• Resolution works by repeatedly combining these formulaetogether until we get nothing (the empty set).

• This represents the contradiction.

•When we find this we can conclude the negation of the thing weadded to the KB.

– This is just the thing we want to prove.

• So we might combine:

¬P2,1 ∨ B1,1, ¬B1,1

¬P2,1

cisc3410-fall2012-parsons-lect06 35

Page 36: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

• Similarly we might infer:

¬P1,2 ∨ B1,1, ¬B1,1

P1,2

andP1,2 ¬P1,2

⊥thus finding the contradiction and concluding the proof.

•Many of the possible inferences are summarised by:

P1,2

P1,2

P2,1

P1,2 B1,1

B1,1 P2,1 B1,1 P1,2 P2,1 P2,1P1,2B1,1 B1,1

P1,2B1,1 P2,1B1,1P2,1 B1,1

P1,2 P2,1 P1,2

cisc3410-fall2012-parsons-lect06 36

Page 37: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

function PL-RESOLUTION(KB,α) returns true or falseinputs: KB, the knowledge base, a sentence in propositional

logicα, the query, a sentence in propositional logic

clauses← the set of clauses in the CNF representation of KB∧¬αnew←{}loop do

for each Ci, Cj in clauses doresolvents← PL-RESOLVE(Ci,Cj)if resolvents contains the empty clause then return truenew← new ∪ resolvents

if new ⊆ clauses then return falseclauses← clauses ∪ new

cisc3410-fall2012-parsons-lect06 37

Page 38: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

In favor of propositional logic

• Propositional logic is declarative

– Pieces of syntax correspond to facts

• Propositional logic allows partial/disjunctive/negatedinformation

– Unlike most data structures and databases

• Propositional logic is compositional

– Meaning of B1,1 ∧ P1,2 is derived from meaning of B1,1 and ofP1,2

•Meaning in propositional logic is context-independent

– Unlike natural language, where meaning depends on context

cisc3410-fall2012-parsons-lect06 38

Page 39: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Against propositional logic

• Propositional logic has very limited expressive power

– Unlike natural language

• For example, cannot say:

“pits cause breezes in adjacent squares”

except by writing one sentence for each square.

cisc3410-fall2012-parsons-lect06 39

Page 40: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

First order logic

•Whereas propositional logic assumes world contains facts,first-order logic (like natural language) assumes the worldcontains:

– Objects: people, houses, numbers, theories, Barack Obama,colors, baseball games, wars, centuries . . .

– Relations: red, round, bogus, prime, multistoried . . ., brother of,bigger than, inside, part of, has color, occurred after, owns,comes between, . . .

Relations are statements that are true or false.

– Functions: father of, best friend, third inning of, one morethan, end of . . .

Functions return values.

cisc3410-fall2012-parsons-lect06 40

Page 41: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

• The line between functions and relations is sometimes confusing.

• This is a relation:

PresidentOf (UnitedStates,BarakObama)

which is currently true.

• This is a function:

PresidentOf (UnitedStates)

which currently returns the value BarackObama.

cisc3410-fall2012-parsons-lect06 41

Page 42: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Logics in general

Language Ontological Epistemological

Commitment Commitment

Propositional logic facts true/false/unknown

First-order logic facts, objects, relations true/false/unknown

Temporal logic facts, objects, relations, times true/false/unknown

Probability theory facts degree of belief

Fuzzy logic facts + degree of truth known interval value

cisc3410-fall2012-parsons-lect06 42

Page 43: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Syntax of FOL: Basic elements

Constants KingJohn, 2, UCB, . . .Predicates Brother, >, . . .Functions Sqrt, LeftLegOf , . . .Variables x, y, a, b, . . .Connectives ∧ ∨ ¬ ⇒ ⇔Equality =Quantifiers ∀ ∃

• Predicates express relations between things.

cisc3410-fall2012-parsons-lect06 43

Page 44: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Atomic sentences

Atomic sentence = predicate(term1, . . . , termn)or term1 = term2

Term = function(term1, . . . , termn)or constant or variable

E.g., Brother(KingJohn,RichardTheLionheart)> (Length(LeftLegOf (Richard)), Length(LeftLegOf (KingJohn)))

cisc3410-fall2012-parsons-lect06 44

Page 45: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

• The brothers we are talking about:

cisc3410-fall2012-parsons-lect06 45

Page 46: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Complex sentences

• Complex sentences are made from atomic sentences usingconnectives

¬S, S1 ∧ S2, S1 ∨ S2, S1 ⇒ S2, S1 ⇔ S2

E.g. Sibling(KingJohn,Richard) ⇒ Sibling(Richard,KingJohn)>(1, 2) ∨ ≤(1, 2)>(1, 2) ∧ ¬>(1, 2)

cisc3410-fall2012-parsons-lect06 46

Page 47: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Truth in first-order logic

• Sentences are true with respect to a model and an interpretation

(Remember that in propositional logic, these ideas wereinterchangeable)

•Model contains ≥ 1 objects (domain elements) and relationsamong them

• Interpretation specifies referents for:

– constant symbols→ objects

– predicate symbols→ relations

– function symbols→ functional relations

• An atomic sentence predicate(term1, . . . , termn) is true iff theobjects referred to by term1, . . . , termn are in the relation referredto by predicate

cisc3410-fall2012-parsons-lect06 47

Page 48: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Models for FOL: Example

R J$

left leg left leg

on headbrother

brother

personpersonking

crown

cisc3410-fall2012-parsons-lect06 48

Page 49: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Truth example

• Consider the interpretation in which

– Richard→ Richard the Lionheart

– John→ the evil King John

– Brother→ the brotherhood relation

• Under this interpretation, Brother(Richard, John) is true just incase Richard the Lionheart and the evil King John are in thebrotherhood relation in the model.

• If the model is Northern Europe in the years 1166 to 1199, thenthe interpretation is true.

cisc3410-fall2012-parsons-lect06 49

Page 50: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Models for FOL: Lots!

• Entailment in propositional logic can be computed byenumerating models

•We can enumerate the FOL models for a given KB vocabulary:

– For each number of domain elements n from 1 to∞

– For each k-ary predicate Pk in the vocabulary

– For each possible k-ary relation on n objects

– For each constant symbol C in the vocabulary

– For each choice of referent for C from n objects . . .

• Computing entailment by enumerating FOL models is not easy!

cisc3410-fall2012-parsons-lect06 50

Page 51: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Decidability

• In fact, it is worse than “not easy”.

• Is there any procedure that we can use, that will be guaranteedto tell us, in a finite amount of time, whether a FOL formula is,or is not, valid?

• The answer is no.

• FOL is for this reason said to be undecidable.

cisc3410-fall2012-parsons-lect06 51

Page 52: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Universal quantification

• ∀ 〈variables〉 〈sentence〉

• Everyone at Brooklyn College is smart:

∀ x At(x,BC) ⇒ Smart(x)

• ∀ x P is true in a model m iff P is true with x being each possibleobject in the model

• Roughly speaking, equivalent to the conjunction of instantiationsof P

(At(KingJohn,BC) ⇒ Smart(KingJohn))∧ (At(Richard,BC) ⇒ Smart(Richard))∧ (At(BC,BC) ⇒ Smart(BC))∧ . . .

cisc3410-fall2012-parsons-lect06 52

Page 53: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

A common mistake to avoid

• Typically, ⇒ is the main connective with ∀

• Common mistake: using ∧ as the main connective with ∀:

∀ x At(x,BC) ∧ Smart(x)

means “Everyone is at Brooklyn College and everyone is smart”

cisc3410-fall2012-parsons-lect06 53

Page 54: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Existential quantification

• ∃ 〈variables〉 〈sentence〉

• Someone at City College is smart:

∃ x At(x,City) ∧ Smart(x)

• ∃ x P is true in a model m iff P is true with x being some possibleobject in the model

• Roughly speaking, equivalent to the disjunction of instantiationsof P:

(At(KingJohn,City) ∧ Smart(KingJohn))∨ (At(Richard,City) ∧ Smart(Richard))∨ (At(City,City) ∧ Smart(City))∨ . . .

cisc3410-fall2012-parsons-lect06 54

Page 55: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

A common mistake to avoid (2)

• Typically, ∧ is the main connective with ∃

• Common mistake: using ⇒ as the main connective with ∃:

∃ x At(x,City) ⇒ Smart(x)

is true if there is anyone who is not at City College!

cisc3410-fall2012-parsons-lect06 55

Page 56: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Properties of quantifiers

• ∀ x ∀ y is the same as ∀ y ∀ x (why?)

• ∃ x ∃ y is the same as ∃ y ∃ x (why?)

• ∃ x ∀ y is not the same as ∀ y ∃ x

• ∃ x ∀ y Loves(x, y)“There is a person who loves everyone in the world”

• ∀ y ∃ x Loves(x, y)“Everyone in the world is loved by at least one person”

• Quantifier duality: each can be expressed using the other

∀ x Likes(x, IceCream) ¬∃ x ¬Likes(x, IceCream)

∃ x Likes(x,Broccoli) ¬∀ x ¬Likes(x,Broccoli)

cisc3410-fall2012-parsons-lect06 56

Page 57: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Fun with sentences

• Brothers are siblings

cisc3410-fall2012-parsons-lect06 57

Page 58: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Fun with sentences

• Brothers are siblings

∀ x, y Brother(x, y) ⇒ Sibling(x, y)

cisc3410-fall2012-parsons-lect06 58

Page 59: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Fun with sentences

• Brothers are siblings

∀ x, y Brother(x, y) ⇒ Sibling(x, y)

• “Sibling” is symmetric

cisc3410-fall2012-parsons-lect06 59

Page 60: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Fun with sentences

• Brothers are siblings

∀ x, y Brother(x, y) ⇒ Sibling(x, y)

• “Sibling” is symmetric

∀ x, y Sibling(x, y) ⇔ Sibling(y, x)

cisc3410-fall2012-parsons-lect06 60

Page 61: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Fun with sentences

• Brothers are siblings

∀ x, y Brother(x, y) ⇒ Sibling(x, y)

• “Sibling” is symmetric

∀ x, y Sibling(x, y) ⇔ Sibling(y, x)

• One’s mother is one’s female parent

cisc3410-fall2012-parsons-lect06 61

Page 62: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Fun with sentences

• Brothers are siblings

∀ x, y Brother(x, y) ⇒ Sibling(x, y)

• “Sibling” is symmetric

∀ x, y Sibling(x, y) ⇔ Sibling(y, x)

• One’s mother is one’s female parent

∀ x, y Mother(x, y) ⇔ (Female(x) ∧ Parent(x, y))

cisc3410-fall2012-parsons-lect06 62

Page 63: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Fun with sentences

• Brothers are siblings

∀ x, y Brother(x, y) ⇒ Sibling(x, y)

• “Sibling” is symmetric

∀ x, y Sibling(x, y) ⇔ Sibling(y, x)

• One’s mother is one’s female parent

∀ x, y Mother(x, y) ⇔ (Female(x) ∧ Parent(x, y))

• A first cousin is a child of a parent’s sibling

cisc3410-fall2012-parsons-lect06 63

Page 64: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Fun with sentences

• Brothers are siblings

∀ x, y Brother(x, y) ⇒ Sibling(x, y)

• “Sibling” is symmetric

∀ x, y Sibling(x, y) ⇔ Sibling(y, x)

• One’s mother is one’s female parent

∀ x, y Mother(x, y) ⇔ (Female(x) ∧ Parent(x, y))

• A first cousin is a child of a parent’s sibling

∀ x, y FirstCousin(x, y) ⇔∃ p, ps Parent(p, x) ∧ Sibling(ps, p) ∧ Parent(ps, y)

cisc3410-fall2012-parsons-lect06 64

Page 65: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Equality

• term1 = term2 is true under a given interpretation if and only ifterm1 and term2 refer to the same object

E.g., 1 = 2 and ∀ x ×(Sqrt(x), Sqrt(x)) = x are satisfiable2 = 2 is valid

• E.g., definition of (full) Sibling in terms of Parent:

∀ x, y Sibling(x, y) ⇔ [¬(x= y) ∧ ∃m, f ¬(m= f ) ∧

Parent(m, x) ∧ Parent(f , x) ∧ Parent(m, y) ∧ Parent(f , y)]

cisc3410-fall2012-parsons-lect06 65

Page 66: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Interacting with FOL KBs

• Suppose a wumpus-world agent is using an FOL KB andperceives a smell and a breeze (but no glitter) at t = 5:

• Tell(KB,Percept([Smell,Breeze,None], 5))

Ask(KB, ∃ a Action(a, 5))

• Does KB entail any particular actions at t = 5?

• Answer: Yes, {a/Shoot} ← substitution (binding list)

• Given a sentence S and a substitution σ, Sσ denotes the result ofplugging σ into S

cisc3410-fall2012-parsons-lect06 66

Page 67: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

• For example:

S = Smarter(x, y)

σ = {x/Hillary, y/Bill}

Sσ = Smarter(Hillary,Bill)

• Ask(KB, S) returns some/all σ such that KB |= Sσ

cisc3410-fall2012-parsons-lect06 67

Page 68: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Knowledge base for the wumpus world

• “Perception”

∀ b, g, t Percept([Smell, b, g], t) ⇒ Smell(t)

∀ s, b, t Percept([s, b,Glitter], t) ⇒ AtGold(t)

• Reflex

∀ t AtGold(t) ⇒ Action(Grab, t)

• Reflex with internal state: do we have the gold already?

∀ t AtGold(t) ∧ ¬Holding(Gold, t) ⇒ Action(Grab, t)

• Holding(Gold, t) cannot be observed⇒ keeping track of change isessential

cisc3410-fall2012-parsons-lect06 68

Page 69: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

function KB-AGENT( percept) returns an actionstatic: KB, a knowledge base

t, a counter, initially 0, indicating time

TELL(KB,MAKE-PERCEPT-SENTENCE( percept, t))action←ASK(KB,MAKE-ACTION-QUERY(t))TELL(KB,MAKE-ACTION-SENTENCE(action, t))t← t + 1return action

cisc3410-fall2012-parsons-lect06 69

Page 70: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Deducing hidden properties• Properties of locations:

∀ x, t At(Agent, x, t) ∧ Smelt(t) ⇒ Smelly(x)∀ x, t At(Agent, x, t) ∧ Breeze(t) ⇒ Breezy(x)

• Squares are breezy near a pit.

• Diagnostic rule—infer cause from effect

∀ y Breezy(y) ⇒ ∃ x Pit(x) ∧ Adjacent(x, y)

• Causal rule—infer effect from cause

∀ x, y Pit(x) ∧ Adjacent(x, y) ⇒ Breezy(y)

• Neither of these is complete—e.g., the causal rule doesn’t saywhether squares far away from pits can be breezy

• Definition for the Breezy predicate:

∀ y Breezy(y) ⇔ [∃ x Pit(x) ∧ Adjacent(x, y)]

cisc3410-fall2012-parsons-lect06 70

Page 71: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Proof in FOL

• Proof in FOL is similar to propositional logic; we just need anextra set of rules, to deal with the quantifiers.

• FOL inherits all the rules of PL.

• To understand FOL proof rules, need to understand substitution.

• The most obvious rule, for ∀-E.

Tells us that if everything in the domain has some property, thenwe can infer that any particular individual has the property.

⊢ ∀x · P(x); ∀-E⊢ P(a)

for any a in the domain

Going from general to specific.

• If all Brooklyn College students are smart, then anyone in theclass is smart.

cisc3410-fall2012-parsons-lect06 71

Page 72: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

• Example 1.

Let’s use ∀-E to get the Socrates example out of the way.

Person(s); ∀x · Person(x)⇒ Mortal(x) ⊢ Mortal(s)

1. Person(s) Given2. ∀x · Person(x)⇒ Mortal(x) Given3. Person(s)⇒ Mortal(s) 2, ∀-E4. Mortal(s) 1, 3,⇒-E

cisc3410-fall2012-parsons-lect06 72

Page 73: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

•We can also go from the general to the slightly less specific!

⊢ ∀x · P(x); ∃-I(1)⊢ ∃x · P(x)

if domain not empty

Note the side condition.

The ∃ quantifier asserts the existence of at least one object.

The ∀ quantifier does not.

• So, while we can say “All unicorns have horns” irrespective ofwhether unicorns are real or not, we can only say “There’s aunicorn living on my street whose name is Fred and he has ahorn” if there is at least one unicorn.

cisc3410-fall2012-parsons-lect06 73

Page 74: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

• This is Fred.

cisc3410-fall2012-parsons-lect06 74

Page 75: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

•We can also go from the very specific to less specific.

⊢ P(a); ∃-I(2)⊢ ∃x · P(x)

• In other words once we have a concrete example, we can inferthere exists something with the property of that example.

• If I find a student at City College who is smart, I can say “Thereis a smart student at City College”.

cisc3410-fall2012-parsons-lect06 75

Page 76: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

• There’s a ∃ elimintaion rule also.

•We often informally make use of arguments along the lines. . .

1. We know somebody is the murderer.

2. Call this person a.

3. a must have been in the library with the lead pipe.

4. . . .

(Here, a is called a Skolem constant.)

Thoralf Skolem

cisc3410-fall2012-parsons-lect06 76

Page 77: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

•We have a rule which allows this, but we have to be careful howwe use it!

⊢ ∃x · P(x); ∃-E⊢ P(a)

a doesn’t occur elsewhere

cisc3410-fall2012-parsons-lect06 77

Page 78: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

• Here is an invalid use of this rule:

1. ∃x · Boring(x) Given2. Lecture(AI) Given3. Boring(AI) 1, ∃-E

• (The conclusion may be true, the argument isn’t sound.)

cisc3410-fall2012-parsons-lect06 78

Page 79: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

• Another kind of reasoning:

– Let a be arbitrary object.

– . . . (some reasoning) . . .

– Therefore a has property P

– Since a was arbitrary, it must be that every object has propertyP.

• Common in mathematics:

Consider a positive integer n . . . so n is either a primenumber or divisible by a smaller prime number . . . thusevery positive integer is either a prime number or divisibleby a smaller prime number.

cisc3410-fall2012-parsons-lect06 79

Page 80: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

• If we are careful, we can also use this kind of reasoning:

⊢ P(a); ∀-I⊢ ∀x · P(x)

a is arbitrary

• Here’s an invalid use of this rule:

1. Boring(AI) Given2. ∀x · Boring(x) 1, ∀-I

cisc3410-fall2012-parsons-lect06 80

Page 81: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

•With this we have a full set of rules for handling quantifiers.

• Adding them to the rules we had before, we have enough to donatural deduction with predicate logic.

• Let’s look at an example.

cisc3410-fall2012-parsons-lect06 81

Page 82: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

• An example:

1. Everybody is either happy or rich.

2. Simon is not rich.

3. Therefore, Simon is happy.

Predicates:

– H(x)means x is happy;

– R(x)means x is rich.

• Formalisation:

∀x.H(x) ∨ R(x);¬R(Simon) ⊢ H(Simon)

cisc3410-fall2012-parsons-lect06 82

Page 83: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

1. ∀x.H(x) ∨ R(x) Given2. ¬R(Simon) Given3. H(Simon) ∨ R(Simon) 1, ∀-E4. ¬H(Simon)⇒ R(Simon) 3, defn⇒5. ¬H(Simon) As. |6. R(Simon) 4, 5,⇒-E |7. R(Simon) ∧ ¬R(Simon) 2, 6, ∧-I |8. ¬¬H(Simon) 5, 7, ¬-I9. H(Simon)⇔ ¬¬H(Simon) PL axiom10. (H(Simon)⇒ ¬¬H(Simon))

∧(¬¬H(Simon)⇒ H(Simon)) 9, defn⇔11. ¬¬H(Simon)⇒ H(Simon) 10,∧-E12. H(Simon) 8, 11,⇒-E

cisc3410-fall2012-parsons-lect06 83

Page 84: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

• To summarise where we stand with logics and proof systems:

Propositional Logic Predicate LogicNatural Deduction X XForward Chaining XBackward Chaining XResolution X

•We could, quite easily, extend FC, BC and resolution forpredicate logic.

– We already know how to handle quantifiers, and that is thehardest bit.

cisc3410-fall2012-parsons-lect06 84

Page 85: RESOLUTION AND FIRST ORDER LOGIC · •In the last class we talked about logic. •In particular we talked about why logic would be useful. •We covered propositional logic — the

Summary

• This lecture completes our treatment of logic.

•We have added some new proof techniques:

– Forward chaining

– Backward chaining

– Resolution

to our treatment of propositional logic; and

• Covered the basics of first order logic.

• There is plenty more to logic (a whole other chapter in thetextbook) but we will look at other things next week.

cisc3410-fall2012-parsons-lect06 85