logical reasoning and inference - cau ai labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfcan be used...

104
Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang University Artificial Intelligence Dae-Won Kim

Upload: trinhthu

Post on 16-Mar-2019

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Logical Reasoning and Inference

School of Computer Science & EngineeringChung-Ang University

Artificial Intelligence

Dae-Won Kim

Page 2: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

AI Scope Revisited

• Agents, AI Problems and Modeling

• Solving Problems by Searching

• Learning (ML, PR, DM)

• Knowledge, Logic, Reasoning, and Inference

• Uncertain and Probabilistic Acting

• Alife, Affective Computing, Planning, Robotics …

Page 3: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Outline

• Knowledge-based agents

• Wumpus world

• Logic in general – models and entailment

• Propositional logic

• Inference rules and theorem proving

Page 4: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Knowledge Base

KB = set of sentences in a formal language

• TELL it what it needs to know

• Then it can ASK itself what to do: answers should follow from the KB.

Page 5: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

A Simple Knowledge-based Agent

Agents can be viewed at the knowledge level; what they know, regardless of how implemented.

Page 6: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Wumpus World

Page 7: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Wumpus World: PEAS

• Environment

Squares adjacent to wumpus are smelly

Squares adjacent to pit are breezy

Glitter iff gold is in the same square

Shooting kills wumpus if you are facing it

Shooting uses up the only arrow

Grabbing picks up gold if in same square

Releasing drops the gold in the square

Page 8: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Wumpus World: PEAS

• Performance measure

gold (+100), death (-100), -1 per step

-10 for using the arrow

• Actuators

Forward, Grab, Release, Shoot

• Sensors

Smell, Glitter, Breeze

Page 9: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Exploring a Wumpus World

Page 10: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Exploring a Wumpus World

Page 11: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Exploring a Wumpus World

Page 12: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Exploring a Wumpus World

Page 13: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Exploring a Wumpus World

Page 14: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Exploring a Wumpus World

Page 15: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Exploring a Wumpus World

Page 16: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Exploring a Wumpus World

Page 17: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Logic in General

• Logics are formal language for representing information such that conclusions can be drawn

• Syntax defines the sentences in the language

• Semantics define the meaning of sentences; define the truth of a sentence in a world

Page 18: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Logic in General: Example

The language of arithmetic

• x+2>y is a sentence; x2+y> is not a sentence

• x+2>y is true in a world where x=7,y=1

• x+2>y is false in a world where x=0,y=6

Page 19: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Entailment

Entailment means that one thing follows fromanother:

KB

Knowledge base KB entails sentence

if and only if

is true in all worlds where KB is true

Page 20: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Entailment: Example

• The KB containing “the Giants won” and “the Reds won” entails “Either the Giants won or the Reds won”

• x+y=4 entails 4=x+y

Entailment is a relationship between sentences (i.e., syntax) that is based on semantics.

Page 21: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Entailment in the Wumpus World

Situation after detecting nothing in [1,1], moving right, breeze in [2,1]

KB = wumpus world rules + observations

= [1,2] is safe (o)

= [2,2] is safe (x)

Page 22: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Inference

KB i : sentence can be derived from KB by inference procedure i.

The procedure will answer any question whose answer follows from what is known by the KB.

• Soundness

• Completeness

Page 23: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Inference

KB i : sentence can be derived from KB by inference procedure i.

The procedure will answer any question whose answer follows from what is known by the KB.

• Soundness

whenever KB i , it is also true that KB

• Completeness

whenever KB , it is also true that KB i

Page 24: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Propositional Logic: Syntax

Propositional logic is the simplest logic.

The proposition symbols P1, P2 are sentences.

• If S is a sentence, S is a sentence (negation)

• If S1 and S2 are sentences,

S1 S2 is a sentence (conjunction)

S1 S2 is a sentence (disjunction)

S1 S2 is a sentence (implication)

S1 S2 is a sentence (biconditional)

Page 25: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Propositional Logic: Semantics

Specifies true/false for each proposition symbol.

• S1 (true), S2 (true), S3 (false)

• S1 is true and S2 is true iff S1 S2 is true.

Page 26: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Wumpus World Sentences

• Let P(i,j) be true if there is a pit in [i,j].

• Let B(i,j) be true if there is a breeze in [i,j].

P(1,1), B(1,1), B(2,1)

• “Pits cause breezes in adjacent squares”

B(1,1) P(1,2) P(2,1)

B(2,1) P(1,1) P(2,2) P(3,1)

Page 27: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Inference by Enumeration

Depth-first enumeration of all models is sound and complete.

O(2n) for n symbols; problem is NP-complete.

Page 28: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Truth Table for Inference

Page 29: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Logical Equivalence

Page 30: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Validity and Satisfiability

• A sentence is valid if it is true in all models, e.g., true, A A, A A

• Validity is connected to inference via the Deduction Theorem: KB iff KB is valid.

• A sentence is satisfiable if it is true in somemodel, e.g., A B

• A sentence is unsatisfiable if it is true in nomodels, e.g., A A

Page 31: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Forward and Backward Chaining

Horn Form

• KB = conjunction of Horn clauses

• Horn clause =

proposition symbol; or

(conjunction of symbols) symbol

• E.g., C (B A) (C D B)

Page 32: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Forward and Backward Chaining

Modus Ponens (for Horn Form): complete for Horn KBs.

Can be used with forward chaining or backward chaining.

These inference algorithms are very natural and run in linear time.

Page 33: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Forward Chaining

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

Page 34: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Forward Chaining

Page 35: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Forward Chaining: Example

Page 36: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Forward Chaining: Example

Page 37: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Forward Chaining: Example

Page 38: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Forward Chaining: Example

Page 39: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Forward Chaining: Example

Page 40: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Forward Chaining: Example

Page 41: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Forward Chaining: Example

Page 42: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Backward Chaining

Idea: work backwards from the query q: to prove q, check if q is known already, or prove it by 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 been proved true, or

2) has already failed.

Page 43: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Backward Chaining: Example

Page 44: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Backward Chaining: Example

Page 45: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Backward Chaining: Example

Page 46: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Backward Chaining: Example

Page 47: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Backward Chaining: Example

Page 48: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Backward Chaining: Example

Page 49: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Backward Chaining: Example

Page 50: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Backward Chaining: Example

Page 51: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Backward Chaining: Example

Page 52: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Backward Chaining: Example

Page 53: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Backward Chaining: Example

Page 54: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Forward vs. Backward

• Forward chaining

Data-driven; e.g., object recognition.

• Backward chaining

Goal-driven, appropriate for problem-solving; e.g., how do I get into a PhD program?

Page 55: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Preliminary Summary

Logical agents apply inference to a KB to derive new information and make decision.

Basic concepts of logic:1. syntax: formal structure of sentences

2. semantics: truth of sentences

3. entailment: necessary truth of one sentence given another

4. inference: deriving sentences from other sentences

5. soundness: derivations produce only entailed sentences

6. completeness: derivations can produce all entailed sentences

Forward, backward chaining are complete for Horn clauses.

Page 56: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Resolution

Q: Are FC/BC complete for propositional logic?

Conjunctive Normal Form (CNF):

conjunction of disjunctions of literals.

E.g., (A B) (B C D)

Resolution inference rule (for CNF) is sound and complete for propositional logic.

Page 57: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Conversion to CNF

Page 58: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Resolution Algorithm

Idea: proof by contradiction;

it shows that KB is unsatisfiable.

Page 59: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Resolution: Example

KB = (B(1,1) P(1,2) P(2,1)) B(1,1)

We want to infer P(1,2)

= P(1,2)

Page 60: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

First-order Logic

School of Computer Science & EngineeringChung-Ang University

Artificial Intelligence

Dae-Won Kim

Page 61: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Outline

• Why First-order logic?

• Syntax and semantics of FOL

• Wumpus word in FOL

• Inference in FOL

Page 62: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Propositional Logic

Advantages:

• Declarative: pieces of syntax for facts

• Compositional: P(1,2) P(2,1)

• Context-independent

Disadvantages:

• Limited expressive power

(unlike natural language)

Page 63: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

First-order Logic

Whereas propositional logic assumes world contains facts,

first-order logic (like natural language) assumes the world contains

• Objects: people, houses, numbers, colors, …

• Relations: red, round, bigger than, …

• Functions: father of, best friend, …

Page 64: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Logics in General

Page 65: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Syntax

• Constants: KingJohn, 2, CAU, …

• Predicates: Brother, >, …

• Functions: Sqrt, LeftLegOf, …

• Variables: x, y, a, b, …

• Connectives/Equality: , , , =, …

• Quantifiers: ,

Page 66: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Atomic Sentences

• Atomic sentence

= predicate(term1, …, termn) or term1 = term2

• Term

= function(term1, …, termn) or constant or variable

E.g., Brother(KingJohn, RichardTheLionheart)

Page 67: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Complex Sentences

Complex sentences are made from atomic sentences using connectives.

S1 S2, S1 S2, S1 S2, S1 S2

E.g.,

Brother(KingJohn, Richard)

Sibling(Richard, KingJohn)

Page 68: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Models for FOL: Example

Page 69: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

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 in case Richard the Lionheart and the evil King John are in the brotherhood relation in the model.

Page 70: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Models for FOL

Entailment in propositional logic can be computed by enumerating models.

We can enumerate the FOL models for a given KB vocabulary.

Computing entailment by enumerating FOL models is not easy!

Page 71: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Universal Quantification

<variable> <sentence>

• Everyone at Berkeley is smart:

x At(x, Berkeley) Smart(x)

• x P is true iff P is true with x being each possible object in the model.

At(KingJohn, Berkeley) Smart(KingJohn)

At(Richard, Berkeley) Smart(Richard) …

Page 72: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

A Common Mistake to Avoid

Typically, is the main connective with

• Common mistake: using as the main connective with :

x At(x, Berkeley) Smart(x)

means “Everyone is at Berkeley and everyone is smart”

Page 73: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Existential Quantification

<variable> <sentence>

• Someone at Stanford is smart:

x At(x, Stanford) Smart(x)

• x P is true iff P is true with x being somepossible object in the model.

(At(KingJohn, Stanford) Smart(KingJohn))

(At(Richard, Stanford) Smart(KingJohn)) …

Page 74: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

A Common Mistake to Avoid

Typically, is the main connective with

• Common mistake: using as the main connective with :

x At(x, Stanford) Smart(x)

is true if there is anyone who is not at Stanford.

Page 75: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Properties of Quantifiers

• x y is the same as y x

• x y is the same as y x

• x y is not the same as y x

x y Loves(x,y) vs. y x Loves(x,y)

• Quantifier duality

x Likes(x, Ice) x Likes(x, Ice)

x Likes(x, Water) x Likes(x, Water)

Page 76: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Sentences: Example

• 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)

Page 77: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Interacting with FOL KBs

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

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

ASK(KB, a Action(a, 5)

i.e., does KB entail any particular actions at t=5?

Answer: Yes, {a/Shoot} (substitution)

Page 78: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Interacting with FOL KBs

Given a sentence S and a substitution r,

Sr denotes the result of plugging r into S;

S = Smarter(x,y)

r = {x/Hillary, y/Bill}

Sr = Smarter(Hillary, Bill)

ASK(KB, S) returns some/all r such that KB Sr.

Page 79: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

KB for Wumpus World

“Perception”

b,g,t Percept([Smell, b, g], t) Smelt(t)

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

Reflex: t AtGold(t) Action(Grab, t)

Reflex with internal state:

t AtGold(t) Holding(Gold, t) Action(Grab,t)

Page 80: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Deducing Hidden Properties

Definition of the Breezy predicate:

y Breezy(y) x Pit(x) Adjacent(x,y)

• 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)

Page 81: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Planning

• Initial condition in KB:

At(Agent, [1,1], S0)

At(Gold, [1,2], S0)

• Query: ASK(KB, s Holding(Gold, s))

• Answer: {s/Result(Grab, Result(Forward, S0))}

Page 82: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Inference

• Reducing first-order inference to propositional inference

• Unification

• Generalized Modus Ponens

• Forward and backward chaining

• Resolution

Page 83: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Reduction to Propositional Inference

• Suppose the KB contains just the following:

x King(x) Greedy(x) Evil(x)

King(John), Greey(John)

Brother(Richard, John)

• Instantiating the sentence in all possible ways:

King(John) Greedy(John) Evil(John)

King(Richard) Greedy(Richard) Evil(Richard)

King(John), Greedy(John)

Brother(Richard, John)

• The new proposition symbols + resolution.

Page 84: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Problem with Propositionalization

• It generates lots of irrelevant sentences.

x King(x) Greedy(x) Evil(x)

King(John)

y Greedy(y)

Brother(Richard, John)

• Evil(John) is obvious

• Greedy(Richard) is irrelevant

Page 85: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Unification

1. Find a substitution such that King(x) and Greedy(x) match King(John) and Greedy(y).

= {x/John, y/John}

2. Given Knows(John, x) and Knows(y, OJ)

= {x/OJ, y/John}

Page 86: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

GMP: Generalized Modus Ponens

Page 87: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Example KB

The law says that it is a crime for an American to sell weapons to hostile nations. The country Nono, an enemy of America, has some missiles, and all of its missiles were sold to it by Colonel West, who is American.

Prove that Col. West is a criminal.

Page 88: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

KB Construction

• A crime for an American to sell weapons to hostile nations:

American(x) Weapon(y) Sells(x,y,z) Hostile(z) Criminal(x)

• Nono … has some missiles:

Owns(Nono, M1) and Missle(M1)

• … all of its missiles were sold to it by C. West:

x Missile(x) Owns(Nono,x) Sells(West,x,Nono)

Page 89: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

KB Construction

• Missiles are weapons:

Missile(x) Weapon(x)

• An enemy of America counts as “hostile”:

Enemy(x, America) Hostile(x)

• West, who is America …:

American(West)

• The country Nono, an enemy of America …:

Enemy(Nono, America)

Page 90: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Forward Chaining

Incomplete (infinite loops).

Widely used for logic programming.

Page 91: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Forward Chaining

Page 92: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Forward Chaining

Page 93: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Forward Chaining

Page 94: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Backward Chaining

Sound and complete vs. expensive (NP-hard)

Page 95: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Backward Chaining

Page 96: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Backward Chaining

Page 97: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Backward Chaining

Page 98: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Backward Chaining

Page 99: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Backward Chaining

Page 100: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Backward Chaining

Page 101: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Backward Chaining

Page 102: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Logic Programming

• Vs. ordinary programming

• Encode information KB, ask queries, and find false facts

• Prolog systems

• Widely used in Europe, Japan

• Backward chaining with Horn clauses

Page 103: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural

Resolution

• = {x/Ken}

• Apply resolution steps to CNF(KB )

Page 104: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2011/06a-logic.pdfCan be used with forward chaining or backward chaining. These inference algorithms are very natural