CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture...

47
CS 416 Artificial Intelligence Lecture 10 Lecture 10 Reasoning in Propositional Logic Reasoning in Propositional Logic Chapters 7 and 8 Chapters 7 and 8

Transcript of CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture...

Page 1: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

CS 416Artificial Intelligence

Lecture 10Lecture 10

Reasoning in Propositional LogicReasoning in Propositional Logic

Chapters 7 and 8Chapters 7 and 8

Lecture 10Lecture 10

Reasoning in Propositional LogicReasoning in Propositional Logic

Chapters 7 and 8Chapters 7 and 8

Page 2: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Midterm

9 days from now (Mar 29 days from now (Mar 2ndnd)?)?

Immediately following Spring Break (Mar 14Immediately following Spring Break (Mar 14thth)?)?

9 days from now (Mar 29 days from now (Mar 2ndnd)?)?

Immediately following Spring Break (Mar 14Immediately following Spring Break (Mar 14thth)?)?

Page 3: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Curling in the news (Wall Street Journal)

It’s like chess on ice It’s like chess on ice (Roy Sinclair, World Curling Federation)(Roy Sinclair, World Curling Federation)

• The essence of Olympic befuddlementThe essence of Olympic befuddlement

• Inexplicably, it was a cable TV hit in 2002Inexplicably, it was a cable TV hit in 2002

• 70 hours on NBC (larger audience than 70 hours on NBC (larger audience than other events)other events)

• US Men go for US Men go for GOLD on GOLD on WednesdayWednesday

It’s like chess on ice It’s like chess on ice (Roy Sinclair, World Curling Federation)(Roy Sinclair, World Curling Federation)

• The essence of Olympic befuddlementThe essence of Olympic befuddlement

• Inexplicably, it was a cable TV hit in 2002Inexplicably, it was a cable TV hit in 2002

• 70 hours on NBC (larger audience than 70 hours on NBC (larger audience than other events)other events)

• US Men go for US Men go for GOLD on GOLD on WednesdayWednesday

Page 4: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

ReviewStore information in a knowledge baseStore information in a knowledge base

• Backus-Naur Form (BNF)Backus-Naur Form (BNF)

• Use equivalences to isolate what you wantUse equivalences to isolate what you want

• Use inference to relate sentencesUse inference to relate sentences

– Modus PonensModus Ponens

– And-EliminationAnd-Elimination

Store information in a knowledge baseStore information in a knowledge base

• Backus-Naur Form (BNF)Backus-Naur Form (BNF)

• Use equivalences to isolate what you wantUse equivalences to isolate what you want

• Use inference to relate sentencesUse inference to relate sentences

– Modus PonensModus Ponens

– And-EliminationAnd-Elimination

Page 5: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Constructing a proofProving Proving is like is like searchingsearching

• Find sequence of logical inference rules that lead to desired Find sequence of logical inference rules that lead to desired resultresult

• Note the explosion of propositionsNote the explosion of propositions

– Good proof methods ignore the countless irrelevant Good proof methods ignore the countless irrelevant propositionspropositions

The two inference rules areThe two inference rules are sound sound but notbut not complete! complete!

Proving Proving is like is like searchingsearching

• Find sequence of logical inference rules that lead to desired Find sequence of logical inference rules that lead to desired resultresult

• Note the explosion of propositionsNote the explosion of propositions

– Good proof methods ignore the countless irrelevant Good proof methods ignore the countless irrelevant propositionspropositions

The two inference rules areThe two inference rules are sound sound but notbut not complete! complete!

Page 6: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Recall that a Recall that a completecomplete inference algorithm is one inference algorithm is one that can derive any sentence that is entailedthat can derive any sentence that is entailed

ResolutionResolution is a single inference rule is a single inference rule

• Guarantees the ability to derive any sentence that is entailedGuarantees the ability to derive any sentence that is entailed

– i.e. it is completei.e. it is complete

• It must be partnered with a complete search algorithmIt must be partnered with a complete search algorithm

Recall that a Recall that a completecomplete inference algorithm is one inference algorithm is one that can derive any sentence that is entailedthat can derive any sentence that is entailed

ResolutionResolution is a single inference rule is a single inference rule

• Guarantees the ability to derive any sentence that is entailedGuarantees the ability to derive any sentence that is entailed

– i.e. it is completei.e. it is complete

• It must be partnered with a complete search algorithmIt must be partnered with a complete search algorithm

Completeness

Page 7: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Resolution

Unit Resolution Inference RuleUnit Resolution Inference Rule

• If If mm and and llii are are

complementarycomplementaryliteralsliterals

Unit Resolution Inference RuleUnit Resolution Inference Rule

• If If mm and and llii are are

complementarycomplementaryliteralsliterals

Page 8: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Resolution Inference RuleAlso works with clausesAlso works with clauses

But make sure each literal appears only onceBut make sure each literal appears only once

We really just want the resolution to return AWe really just want the resolution to return A

Also works with clausesAlso works with clauses

But make sure each literal appears only onceBut make sure each literal appears only once

We really just want the resolution to return AWe really just want the resolution to return A

Page 9: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Resolution and completenessAny complete search algorithm, applying only the Any complete search algorithm, applying only the resolution rule, can derive any conclusion resolution rule, can derive any conclusion entailed by any knowledge base in propositional entailed by any knowledge base in propositional logiclogic

• More specifically, refutation completenessMore specifically, refutation completeness

– Able to confirm or refute any sentenceAble to confirm or refute any sentence

– Unable to enumerate all true sentencesUnable to enumerate all true sentences

Any complete search algorithm, applying only the Any complete search algorithm, applying only the resolution rule, can derive any conclusion resolution rule, can derive any conclusion entailed by any knowledge base in propositional entailed by any knowledge base in propositional logiclogic

• More specifically, refutation completenessMore specifically, refutation completeness

– Able to confirm or refute any sentenceAble to confirm or refute any sentence

– Unable to enumerate all true sentencesUnable to enumerate all true sentences

Page 10: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

What about “and” clauses?Resolution only applies to “or” clauses (disjunctions)Resolution only applies to “or” clauses (disjunctions)

• Every sentence of propositional logic can be transformed to a Every sentence of propositional logic can be transformed to a logically equivalent conjunction of disjunctions of literals logically equivalent conjunction of disjunctions of literals (recall literal can be negated atomic sentence)(recall literal can be negated atomic sentence)

Conjunctive Normal Form (CNF)Conjunctive Normal Form (CNF)

• A sentence expressed as conjunction of disjunction of literalsA sentence expressed as conjunction of disjunction of literals

Resolution only applies to “or” clauses (disjunctions)Resolution only applies to “or” clauses (disjunctions)

• Every sentence of propositional logic can be transformed to a Every sentence of propositional logic can be transformed to a logically equivalent conjunction of disjunctions of literals logically equivalent conjunction of disjunctions of literals (recall literal can be negated atomic sentence)(recall literal can be negated atomic sentence)

Conjunctive Normal Form (CNF)Conjunctive Normal Form (CNF)

• A sentence expressed as conjunction of disjunction of literalsA sentence expressed as conjunction of disjunction of literals

Page 11: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

CNF

Page 12: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

An algorithm for resolutionWe wish to prove KB entails We wish to prove KB entails • That is, will some sequence of inferences create new That is, will some sequence of inferences create new

sentence in knowledge base equal to sentence in knowledge base equal to ??

• Proof by contradictionProof by contradiction

– Show that assuming ~Show that assuming ~ invalidates KB invalidates KB

– Must show (KB ^ ~Must show (KB ^ ~) is ) is unsatisfiableunsatisfiable

produces the empty clauseproduces the empty clause

We wish to prove KB entails We wish to prove KB entails • That is, will some sequence of inferences create new That is, will some sequence of inferences create new

sentence in knowledge base equal to sentence in knowledge base equal to ??

• Proof by contradictionProof by contradiction

– Show that assuming ~Show that assuming ~ invalidates KB invalidates KB

– Must show (KB ^ ~Must show (KB ^ ~) is ) is unsatisfiableunsatisfiable

produces the empty clauseproduces the empty clause

Page 13: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

An algorithm for resolutionAlgorithmAlgorithm

• (KB ^ ~(KB ^ ~is put in CNFis put in CNF

• For each pair of sentences with a pair of clauses containing For each pair of sentences with a pair of clauses containing complementary literalscomplementary literals

– ResolveResolve to produce new clause which is added to KB (if novel) to produce new clause which is added to KB (if novel)

– Cease if no new clauses to add (~Cease if no new clauses to add (~ is not entailed) is not entailed)

– Cease if resolution rule derives empty clauseCease if resolution rule derives empty clause

If resolution generates If resolution generates … … ^ ~ ^ ~ = empty clause = empty clause

(( is entailed) is entailed)

AlgorithmAlgorithm

• (KB ^ ~(KB ^ ~is put in CNFis put in CNF

• For each pair of sentences with a pair of clauses containing For each pair of sentences with a pair of clauses containing complementary literalscomplementary literals

– ResolveResolve to produce new clause which is added to KB (if novel) to produce new clause which is added to KB (if novel)

– Cease if no new clauses to add (~Cease if no new clauses to add (~ is not entailed) is not entailed)

– Cease if resolution rule derives empty clauseCease if resolution rule derives empty clause

If resolution generates If resolution generates … … ^ ~ ^ ~ = empty clause = empty clause

(( is entailed) is entailed)

Page 14: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Example of resolution

Prove ~PProve ~P1,21,2 (there is not a pit in P (there is not a pit in P1,21,2):):• KB ^ PKB ^ P1,21,2 leads to empty clause leads to empty clause

• Therefore ~PTherefore ~P1,21,2 is true is true

Prove ~PProve ~P1,21,2 (there is not a pit in P (there is not a pit in P1,21,2):):• KB ^ PKB ^ P1,21,2 leads to empty clause leads to empty clause

• Therefore ~PTherefore ~P1,21,2 is true is true

Page 15: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Formal Algorithm – It’s “complete”

Page 16: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

A complete resolution algorithm

Inference using resolution is completeInference using resolution is complete

• Can be slow (it was the first problem shown to be NP Can be slow (it was the first problem shown to be NP Complete)Complete)

• Real-world knowledge bases contain a restricted type of Real-world knowledge bases contain a restricted type of clause, implicationsclause, implications

– (a conjunction of positive literals) (a conjunction of positive literals) single positive literalsingle positive literal

Inference using resolution is completeInference using resolution is complete

• Can be slow (it was the first problem shown to be NP Can be slow (it was the first problem shown to be NP Complete)Complete)

• Real-world knowledge bases contain a restricted type of Real-world knowledge bases contain a restricted type of clause, implicationsclause, implications

– (a conjunction of positive literals) (a conjunction of positive literals) single positive literalsingle positive literal

Page 17: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Horn ClausesHorn ClauseHorn Clause

• Disjunction of literals where at most one is positiveDisjunction of literals where at most one is positive

– (~a V ~b V ~c V d)(~a V ~b V ~c V d)

– (~a V b V c V ~d) (~a V b V c V ~d) Not a Horn ClauseNot a Horn Clause

Horn ClauseHorn Clause

• Disjunction of literals where at most one is positiveDisjunction of literals where at most one is positive

– (~a V ~b V ~c V d)(~a V ~b V ~c V d)

– (~a V b V c V ~d) (~a V b V c V ~d) Not a Horn ClauseNot a Horn Clause

Page 18: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

What’s good about Horn Clauses• Two new inference algorithms are possibleTwo new inference algorithms are possible

– Forward chainingForward chaining

– Backward chainingBackward chaining

• Entailment computation is linear in size of KBEntailment computation is linear in size of KB

• Two new inference algorithms are possibleTwo new inference algorithms are possible

– Forward chainingForward chaining

– Backward chainingBackward chaining

• Entailment computation is linear in size of KBEntailment computation is linear in size of KB

Page 19: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Forward Chaining

Does KB (Horn clauses) entail q (single symbol)?Does KB (Horn clauses) entail q (single symbol)?

• Keep track of known facts (positive literals)Keep track of known facts (positive literals)

• If the If the premisespremises of an implication are known of an implication are known

– Add the Add the conclusionconclusion to the known set of facts to the known set of facts

• Repeat process until no further inferences or q is addedRepeat process until no further inferences or q is added

Does KB (Horn clauses) entail q (single symbol)?Does KB (Horn clauses) entail q (single symbol)?

• Keep track of known facts (positive literals)Keep track of known facts (positive literals)

• If the If the premisespremises of an implication are known of an implication are known

– Add the Add the conclusionconclusion to the known set of facts to the known set of facts

• Repeat process until no further inferences or q is addedRepeat process until no further inferences or q is added

Page 20: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Forward Chaining

Page 21: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Forward Chaining

PropertiesProperties

• SoundSound

• CompleteComplete

– All entailed atomic sentences will be derivedAll entailed atomic sentences will be derived

Data DrivenData Driven

• Start with what we knowStart with what we know

• Derive new info until we discover what we wantDerive new info until we discover what we want

PropertiesProperties

• SoundSound

• CompleteComplete

– All entailed atomic sentences will be derivedAll entailed atomic sentences will be derived

Data DrivenData Driven

• Start with what we knowStart with what we know

• Derive new info until we discover what we wantDerive new info until we discover what we want

Page 22: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Backward ChainingStart with what you want to know, a query (q)Start with what you want to know, a query (q)

• Look for implications that conclude qLook for implications that conclude q

– Look at the premises of those implicationsLook at the premises of those implications

Look for implications that conclude those premises…Look for implications that conclude those premises…

Goal-Directed ReasoningGoal-Directed Reasoning

• Can be less complex search than forward chainingCan be less complex search than forward chaining

Start with what you want to know, a query (q)Start with what you want to know, a query (q)

• Look for implications that conclude qLook for implications that conclude q

– Look at the premises of those implicationsLook at the premises of those implications

Look for implications that conclude those premises…Look for implications that conclude those premises…

Goal-Directed ReasoningGoal-Directed Reasoning

• Can be less complex search than forward chainingCan be less complex search than forward chaining

Page 23: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Making it fastExampleExample

• Problem to solve is in CNFProblem to solve is in CNF

– Is Marvin a Martian given --- M == 1 (true)?Is Marvin a Martian given --- M == 1 (true)?

Marvin is green --- G=1Marvin is green --- G=1

Marvin is little --- L=1Marvin is little --- L=1

(little and green) implies Martian --- (L ^ G) => M(little and green) implies Martian --- (L ^ G) => M ~(L^G) V M ~(L^G) V M ~L V ~G V M ~L V ~G V M

– Proof by contradiction… are there true/false values for G, L, and M that are Proof by contradiction… are there true/false values for G, L, and M that are consistent with knowledge base and Marvin not being a Martian?consistent with knowledge base and Marvin not being a Martian?

G ^ L ^ (~L V ~G V M) ^ ~M == empty? G ^ L ^ (~L V ~G V M) ^ ~M == empty?

ExampleExample

• Problem to solve is in CNFProblem to solve is in CNF

– Is Marvin a Martian given --- M == 1 (true)?Is Marvin a Martian given --- M == 1 (true)?

Marvin is green --- G=1Marvin is green --- G=1

Marvin is little --- L=1Marvin is little --- L=1

(little and green) implies Martian --- (L ^ G) => M(little and green) implies Martian --- (L ^ G) => M ~(L^G) V M ~(L^G) V M ~L V ~G V M ~L V ~G V M

– Proof by contradiction… are there true/false values for G, L, and M that are Proof by contradiction… are there true/false values for G, L, and M that are consistent with knowledge base and Marvin not being a Martian?consistent with knowledge base and Marvin not being a Martian?

G ^ L ^ (~L V ~G V M) ^ ~M == empty? G ^ L ^ (~L V ~G V M) ^ ~M == empty?

Page 24: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Searching for variable valuesWant to find values such that:Want to find values such that:

• Randomly consider all true/false assignments to variables Randomly consider all true/false assignments to variables until we exhaust them all or find match (until we exhaust them all or find match (model checkingmodel checking))

– (G, L, M) = (1, 0, 0)… no(G, L, M) = (1, 0, 0)… no = (0, 1, 0)… no = (0, 1, 0)… no = (0, 0, 0)… no = (0, 0, 0)… no = (1, 1, 0)… no = (1, 1, 0)… no

• Alternatively…Alternatively…

Want to find values such that:Want to find values such that:

• Randomly consider all true/false assignments to variables Randomly consider all true/false assignments to variables until we exhaust them all or find match (until we exhaust them all or find match (model checkingmodel checking))

– (G, L, M) = (1, 0, 0)… no(G, L, M) = (1, 0, 0)… no = (0, 1, 0)… no = (0, 1, 0)… no = (0, 0, 0)… no = (0, 0, 0)… no = (1, 1, 0)… no = (1, 1, 0)… no

• Alternatively…Alternatively…

G ^ L ^ (~L V ~G V M) ^ ~M == 0G ^ L ^ (~L V ~G V M) ^ ~M == 0

Page 25: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Backtracking AlgorithmDavis-Putnam Algorithm (DPLL)Davis-Putnam Algorithm (DPLL)

• Search through possible assignments to (G, L, M) via depth-Search through possible assignments to (G, L, M) via depth-first search (0, 0, 0) to (0, 0, 1) to (0, 1, 0)…first search (0, 0, 0) to (0, 0, 1) to (0, 1, 0)…

– Each clause of CNF must be trueEach clause of CNF must be true

Terminate consideration when clause evaluates to falseTerminate consideration when clause evaluates to false

– Some culling of tree is possible using heuristics/logicSome culling of tree is possible using heuristics/logic

Variable appears with same “sign” in all clausesVariable appears with same “sign” in all clauses

Davis-Putnam Algorithm (DPLL)Davis-Putnam Algorithm (DPLL)

• Search through possible assignments to (G, L, M) via depth-Search through possible assignments to (G, L, M) via depth-first search (0, 0, 0) to (0, 0, 1) to (0, 1, 0)…first search (0, 0, 0) to (0, 0, 1) to (0, 1, 0)…

– Each clause of CNF must be trueEach clause of CNF must be true

Terminate consideration when clause evaluates to falseTerminate consideration when clause evaluates to false

– Some culling of tree is possible using heuristics/logicSome culling of tree is possible using heuristics/logic

Variable appears with same “sign” in all clausesVariable appears with same “sign” in all clauses

GL

M

Page 26: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Searching for variable valuesOther ways to find (G, L, M) assignments for:Other ways to find (G, L, M) assignments for: G ^ L ^ (~L V ~G V M) ^ ~M == 0G ^ L ^ (~L V ~G V M) ^ ~M == 0

• Simulated Annealing (WalkSAT)– Start with initial guess (0, 1, 1)– With each iteration, pick an unsatisfied clause and flip one

symbol in the clause– Evaluation metric is the number of clauses that evaluate to true– Move “in direction” of guesses that cause more clauses to be

true– Many local mins, use lots of randomness

Page 27: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

WalkSAT termination

How do you know when simulated annealing is How do you know when simulated annealing is done?done?

• No way to know with certainty that an answer is not possibleNo way to know with certainty that an answer is not possible

– Could have been bad luckCould have been bad luck

– Could be there really is no answerCould be there really is no answer

– Establish a max number of iterations and go with best Establish a max number of iterations and go with best answer to that pointanswer to that point

How do you know when simulated annealing is How do you know when simulated annealing is done?done?

• No way to know with certainty that an answer is not possibleNo way to know with certainty that an answer is not possible

– Could have been bad luckCould have been bad luck

– Could be there really is no answerCould be there really is no answer

– Establish a max number of iterations and go with best Establish a max number of iterations and go with best answer to that pointanswer to that point

Page 28: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Vary clauses and number of symbols

Higher m/n means fewer Higher m/n means fewer assignments will workassignments will work

If fewer assignments workIf fewer assignments work it is harder for DPLL and it is harder for DPLL and WalkSAT WalkSAT

Higher m/n means fewer Higher m/n means fewer assignments will workassignments will work

If fewer assignments workIf fewer assignments work it is harder for DPLL and it is harder for DPLL and WalkSAT WalkSAT

Page 29: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Combining it all4x4 Wumpus World4x4 Wumpus World

• The “physics” of the gameThe “physics” of the game

• At least one wumpus on boardAt least one wumpus on board

• A most one wumpus on board (for any two squares, one is free)A most one wumpus on board (for any two squares, one is free)

– n(n-1)/2 rules like: ~Wn(n-1)/2 rules like: ~W1,11,1 V ~W V ~W1,21,2

• Total of 155 sentences containing 64 distinct symbolsTotal of 155 sentences containing 64 distinct symbols

4x4 Wumpus World4x4 Wumpus World

• The “physics” of the gameThe “physics” of the game

• At least one wumpus on boardAt least one wumpus on board

• A most one wumpus on board (for any two squares, one is free)A most one wumpus on board (for any two squares, one is free)

– n(n-1)/2 rules like: ~Wn(n-1)/2 rules like: ~W1,11,1 V ~W V ~W1,21,2

• Total of 155 sentences containing 64 distinct symbolsTotal of 155 sentences containing 64 distinct symbols

Page 30: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Wumpus World

Time is not taken into accountTime is not taken into account• ““Rules” must have a temporal variableRules” must have a temporal variable

Inefficiencies as world becomes largeInefficiencies as world becomes large• Knowledge base must expand if size of world expandsKnowledge base must expand if size of world expands

Prefer to have sentences that apply to all squares Prefer to have sentences that apply to all squares and timesand times• We brought this subject up last weekWe brought this subject up last week

• Next chapter addresses this issueNext chapter addresses this issue

Time is not taken into accountTime is not taken into account• ““Rules” must have a temporal variableRules” must have a temporal variable

Inefficiencies as world becomes largeInefficiencies as world becomes large• Knowledge base must expand if size of world expandsKnowledge base must expand if size of world expands

Prefer to have sentences that apply to all squares Prefer to have sentences that apply to all squares and timesand times• We brought this subject up last weekWe brought this subject up last week

• Next chapter addresses this issueNext chapter addresses this issue

Page 31: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Chapter 8: First-Order Logic

Page 32: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

What do we like about propositional logic?

It is:It is:• DeclarativeDeclarative

– Relationships between variables are describedRelationships between variables are described

– A method for propagating relationshipsA method for propagating relationships

• ExpressiveExpressive

– Can represent partial information using disjunctionCan represent partial information using disjunction

• CompositionalCompositional

– If If A A means foo and means foo and B B means bar, means bar, A ^ BA ^ B means foo and bar means foo and bar

It is:It is:• DeclarativeDeclarative

– Relationships between variables are describedRelationships between variables are described

– A method for propagating relationshipsA method for propagating relationships

• ExpressiveExpressive

– Can represent partial information using disjunctionCan represent partial information using disjunction

• CompositionalCompositional

– If If A A means foo and means foo and B B means bar, means bar, A ^ BA ^ B means foo and bar means foo and bar

Page 33: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

What don’t we like about propositional logic?

Lacks expressive power to describe the Lacks expressive power to describe the environment conciselyenvironment concisely

• Separate rules for every square/square relationship in Separate rules for every square/square relationship in Wumpus worldWumpus world

Lacks expressive power to describe the Lacks expressive power to describe the environment conciselyenvironment concisely

• Separate rules for every square/square relationship in Separate rules for every square/square relationship in Wumpus worldWumpus world

Page 34: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Natural LanguageEnglish appears to be expressiveEnglish appears to be expressive

• Squares adjacent to pits are breezySquares adjacent to pits are breezy

But natural language is a medium of communication, not a But natural language is a medium of communication, not a knowledge representationknowledge representation

• Much of the information and logic conveyed by language is dependent on Much of the information and logic conveyed by language is dependent on contextcontext

• Information exchange is not well definedInformation exchange is not well defined

• Not compositional (combining sentences may mean something different)Not compositional (combining sentences may mean something different)

• It is ambiguousIt is ambiguous

English appears to be expressiveEnglish appears to be expressive

• Squares adjacent to pits are breezySquares adjacent to pits are breezy

But natural language is a medium of communication, not a But natural language is a medium of communication, not a knowledge representationknowledge representation

• Much of the information and logic conveyed by language is dependent on Much of the information and logic conveyed by language is dependent on contextcontext

• Information exchange is not well definedInformation exchange is not well defined

• Not compositional (combining sentences may mean something different)Not compositional (combining sentences may mean something different)

• It is ambiguousIt is ambiguous

Page 35: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

But we borrow representational ideas from natural language

Natural language syntaxNatural language syntax• Nouns and noun phrases refer to Nouns and noun phrases refer to objectsobjects

– People, houses, carsPeople, houses, cars

• Properties Properties and verbs refer to object and verbs refer to object relationsrelations

– Red, round, nearby, eatenRed, round, nearby, eaten

• Some relationships are clearly defined Some relationships are clearly defined functions functions where there is only one where there is only one output for a given inputoutput for a given input

– Best friend, first thing, plusBest friend, first thing, plus

We build first-order logic around objects and relationsWe build first-order logic around objects and relations

Natural language syntaxNatural language syntax• Nouns and noun phrases refer to Nouns and noun phrases refer to objectsobjects

– People, houses, carsPeople, houses, cars

• Properties Properties and verbs refer to object and verbs refer to object relationsrelations

– Red, round, nearby, eatenRed, round, nearby, eaten

• Some relationships are clearly defined Some relationships are clearly defined functions functions where there is only one where there is only one output for a given inputoutput for a given input

– Best friend, first thing, plusBest friend, first thing, plus

We build first-order logic around objects and relationsWe build first-order logic around objects and relations

Page 36: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Ontology• a “a “specification of a conceptualizationspecification of a conceptualization””

• A description of the objects and relationships that can existA description of the objects and relationships that can exist

– Propositional logic had only true/false relationshipsPropositional logic had only true/false relationships

– First-order logic has many more relationshipsFirst-order logic has many more relationships

• The The ontological commitmentontological commitment of languages is different of languages is different

– How much can you infer from what you know?How much can you infer from what you know?

Temporal logicTemporal logic defines additional ontological defines additional ontological commitments because of timing constraintscommitments because of timing constraints

• a “a “specification of a conceptualizationspecification of a conceptualization””

• A description of the objects and relationships that can existA description of the objects and relationships that can exist

– Propositional logic had only true/false relationshipsPropositional logic had only true/false relationships

– First-order logic has many more relationshipsFirst-order logic has many more relationships

• The The ontological commitmentontological commitment of languages is different of languages is different

– How much can you infer from what you know?How much can you infer from what you know?

Temporal logicTemporal logic defines additional ontological defines additional ontological commitments because of timing constraintscommitments because of timing constraints

Page 37: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Formal structure of first-order logicModels of first-order logic contain:Models of first-order logic contain:

• DomainDomain: a set of objects : a set of objects

– Alice, Alice’s left arm, Bob, Bob’s hat Alice, Alice’s left arm, Bob, Bob’s hat

• RelationshipsRelationships between objects between objects

– Represented as Represented as tuplestuples

Sibling (Alice, Bob), Sibling (Bob, Alice)Sibling (Alice, Bob), Sibling (Bob, Alice)

On head (Bob, hat)On head (Bob, hat)

Person (Bob), Person (Alice)Person (Bob), Person (Alice)

– Some relationships are Some relationships are functionsfunctions if a given object is related to exactly if a given object is related to exactly one object in a certain wayone object in a certain way

leftArm(Alice) leftArm(Alice) Alice’s left arm Alice’s left arm

Models of first-order logic contain:Models of first-order logic contain:

• DomainDomain: a set of objects : a set of objects

– Alice, Alice’s left arm, Bob, Bob’s hat Alice, Alice’s left arm, Bob, Bob’s hat

• RelationshipsRelationships between objects between objects

– Represented as Represented as tuplestuples

Sibling (Alice, Bob), Sibling (Bob, Alice)Sibling (Alice, Bob), Sibling (Bob, Alice)

On head (Bob, hat)On head (Bob, hat)

Person (Bob), Person (Alice)Person (Bob), Person (Alice)

– Some relationships are Some relationships are functionsfunctions if a given object is related to exactly if a given object is related to exactly one object in a certain wayone object in a certain way

leftArm(Alice) leftArm(Alice) Alice’s left arm Alice’s left arm

Page 38: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

First-order logic models– Unlike in propositional logic, models in FOL are more than Unlike in propositional logic, models in FOL are more than

just truth assignments to the objects… they are just truth assignments to the objects… they are relationships among the objectsrelationships among the objects

– Unlike in propositional logic, models in FOL are more than Unlike in propositional logic, models in FOL are more than just truth assignments to the objects… they are just truth assignments to the objects… they are relationships among the objectsrelationships among the objects

Page 39: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

First-order logic syntaxConstant SymbolsConstant Symbols

• A, B, Bob, Alice, HatA, B, Bob, Alice, Hat

Predicate SymbolsPredicate Symbols

• is, onHead, hasColor, personis, onHead, hasColor, person

Function SymbolsFunction Symbols

• Mother, leftLegMother, leftLeg

Each predicate and function symbol has an arityEach predicate and function symbol has an arity

• A constant the fixes the number of argumentsA constant the fixes the number of arguments

Constant SymbolsConstant Symbols

• A, B, Bob, Alice, HatA, B, Bob, Alice, Hat

Predicate SymbolsPredicate Symbols

• is, onHead, hasColor, personis, onHead, hasColor, person

Function SymbolsFunction Symbols

• Mother, leftLegMother, leftLeg

Each predicate and function symbol has an arityEach predicate and function symbol has an arity

• A constant the fixes the number of argumentsA constant the fixes the number of arguments

Names of things are arbitraryNames of things are arbitraryKnowledge base adds meaningKnowledge base adds meaning

Page 40: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Semantics

Semantics defines the objects and relationshipsSemantics defines the objects and relationships• Father (John, Jim) … John is Jim’s father (or Jim is John’s Father (John, Jim) … John is Jim’s father (or Jim is John’s

father)father)

• This amounts to an This amounts to an interpretationinterpretation

Number of possible domain elements (objects) is Number of possible domain elements (objects) is unbounded… integers for exampleunbounded… integers for example• Number of Number of modelsmodels is unbounded and many is unbounded and many interpretationsinterpretations for for

each modeleach model

– Checking entailment by enumeration is usually impossibleChecking entailment by enumeration is usually impossible

Semantics defines the objects and relationshipsSemantics defines the objects and relationships• Father (John, Jim) … John is Jim’s father (or Jim is John’s Father (John, Jim) … John is Jim’s father (or Jim is John’s

father)father)

• This amounts to an This amounts to an interpretationinterpretation

Number of possible domain elements (objects) is Number of possible domain elements (objects) is unbounded… integers for exampleunbounded… integers for example• Number of Number of modelsmodels is unbounded and many is unbounded and many interpretationsinterpretations for for

each modeleach model

– Checking entailment by enumeration is usually impossibleChecking entailment by enumeration is usually impossible

Page 41: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Term

A logical expression that refers to an objectA logical expression that refers to an object• ConstantsConstants

– We could assign names to all objects, like providing a We could assign names to all objects, like providing a name for every shoe in your closetname for every shoe in your closet

• Function symbolsFunction symbols

– Replaces the need to name all the shoesReplaces the need to name all the shoes

– OnLeftFoot(John))OnLeftFoot(John))

Refers to a shoe, some shoeRefers to a shoe, some shoe

A logical expression that refers to an objectA logical expression that refers to an object• ConstantsConstants

– We could assign names to all objects, like providing a We could assign names to all objects, like providing a name for every shoe in your closetname for every shoe in your closet

• Function symbolsFunction symbols

– Replaces the need to name all the shoesReplaces the need to name all the shoes

– OnLeftFoot(John))OnLeftFoot(John))

Refers to a shoe, some shoeRefers to a shoe, some shoe

Page 42: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Atomic SentencesFormed by a Formed by a predicatepredicate symbolsymbol followed by parenthesized followed by parenthesized list of list of termsterms

• Sibling (Alice, Bob)Sibling (Alice, Bob)

• Married (Father(Alice), Mother(Bob))Married (Father(Alice), Mother(Bob))

An atomic sentence is true in a given model, under a An atomic sentence is true in a given model, under a given interpretation, if the relation referred to by the given interpretation, if the relation referred to by the predicate symbol holds among the objects referred to by predicate symbol holds among the objects referred to by the argumentsthe arguments

Formed by a Formed by a predicatepredicate symbolsymbol followed by parenthesized followed by parenthesized list of list of termsterms

• Sibling (Alice, Bob)Sibling (Alice, Bob)

• Married (Father(Alice), Mother(Bob))Married (Father(Alice), Mother(Bob))

An atomic sentence is true in a given model, under a An atomic sentence is true in a given model, under a given interpretation, if the relation referred to by the given interpretation, if the relation referred to by the predicate symbol holds among the objects referred to by predicate symbol holds among the objects referred to by the argumentsthe arguments

Page 43: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Complex sentences

We can use logical connectivesWe can use logical connectives

• ~Sibling(LeftLeg(Alice), Bob)~Sibling(LeftLeg(Alice), Bob)

• Sibling(Alice, Bob) ^ Sibling (Bob, Alice)Sibling(Alice, Bob) ^ Sibling (Bob, Alice)

We can use logical connectivesWe can use logical connectives

• ~Sibling(LeftLeg(Alice), Bob)~Sibling(LeftLeg(Alice), Bob)

• Sibling(Alice, Bob) ^ Sibling (Bob, Alice)Sibling(Alice, Bob) ^ Sibling (Bob, Alice)

Page 44: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

QuantifiersA way to express properties of entire collections A way to express properties of entire collections of objectsof objects

• Universal quantificationUniversal quantification (forall, ) (forall, )

– The power of first-order logicThe power of first-order logic

– ForallForallxx King(x) => Person(x) King(x) => Person(x)

– xx is a variable is a variable

A way to express properties of entire collections A way to express properties of entire collections of objectsof objects

• Universal quantificationUniversal quantification (forall, ) (forall, )

– The power of first-order logicThe power of first-order logic

– ForallForallxx King(x) => Person(x) King(x) => Person(x)

– xx is a variable is a variable )()(: xPersonxKingx

Page 45: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Universal QuantificationForall x, PForall x, P

• P is true for every object xP is true for every object x

• Forall x, King(x) => Person(x)Forall x, King(x) => Person(x)

• x = x =

– Richard the LionheartRichard the Lionheart

– King JohnKing John

– Richard’s left legRichard’s left leg

– John’s left legJohn’s left leg

– The crownThe crown

Forall x, PForall x, P

• P is true for every object xP is true for every object x

• Forall x, King(x) => Person(x)Forall x, King(x) => Person(x)

• x = x =

– Richard the LionheartRichard the Lionheart

– King JohnKing John

– Richard’s left legRichard’s left leg

– John’s left legJohn’s left leg

– The crownThe crown

Page 46: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

Universal Quantification

Note that all of these are trueNote that all of these are true

• Implication is true even if the premise is falseImplication is true even if the premise is false

• is the right connective to use for is the right connective to use for

By asserting a universally quantified sentence, you By asserting a universally quantified sentence, you assert a whole list of individual implicationsassert a whole list of individual implications

Note that all of these are trueNote that all of these are true

• Implication is true even if the premise is falseImplication is true even if the premise is false

• is the right connective to use for is the right connective to use for

By asserting a universally quantified sentence, you By asserting a universally quantified sentence, you assert a whole list of individual implicationsassert a whole list of individual implications

)()(: xPersonxKingx

Page 47: CS 416 Artificial Intelligence Lecture 10 Reasoning in Propositional Logic Chapters 7 and 8 Lecture 10 Reasoning in Propositional Logic Chapters 7 and.

There exists,There exists,• There exists an x such that Crown(x) ^ OnHead(x, John)There exists an x such that Crown(x) ^ OnHead(x, John)

• It is true for It is true for at leastat least one object one object

• ^ is the right connective for ^ is the right connective for

There exists,There exists,• There exists an x such that Crown(x) ^ OnHead(x, John)There exists an x such that Crown(x) ^ OnHead(x, John)

• It is true for It is true for at leastat least one object one object

• ^ is the right connective for ^ is the right connective for

Existential Quantification