logical reasoning and inference - cau ai labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 ·...

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

Upload: others

Post on 10-Apr-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Logical Reasoning and Inference

School of Computer Science & Engineering Chung-Ang University

Artificial Intelligence

Dae-Won Kim

Page 2: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Wumpus World

Page 7: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Exploring a Wumpus World

Page 10: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Exploring a Wumpus World

Page 11: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Exploring a Wumpus World

Page 12: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Exploring a Wumpus World

Page 13: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Exploring a Wumpus World

Page 14: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Exploring a Wumpus World

Page 15: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Exploring a Wumpus World

Page 16: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Exploring a Wumpus World

Page 17: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Entailment

Entailment means that one thing follows from another:

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-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Question:

Sound vs Complete: Which one is better?

Page 25: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 26: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 27: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 28: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Inference by Enumeration

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

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

Page 29: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Truth Table for Inference

Page 30: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Logical Equivalence

Page 31: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 some model, e.g., A B

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

Page 32: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 33: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 34: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Forward Chaining

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

Page 35: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Forward Chaining

Page 36: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Forward Chaining: Example

Page 37: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Forward Chaining: Example

Page 38: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Forward Chaining: Example

Page 39: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Forward Chaining: Example

Page 40: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Forward Chaining: Example

Page 41: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Forward Chaining: Example

Page 42: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Forward Chaining: Example

Page 43: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 44: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Backward Chaining: Example

Page 45: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Backward Chaining: Example

Page 46: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Backward Chaining: Example

Page 47: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Backward Chaining: Example

Page 48: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Backward Chaining: Example

Page 49: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Backward Chaining: Example

Page 50: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Backward Chaining: Example

Page 51: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Backward Chaining: Example

Page 52: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Backward Chaining: Example

Page 53: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Backward Chaining: Example

Page 54: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Backward Chaining: Example

Page 55: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 56: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 57: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 58: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Conversion to CNF

Page 59: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Resolution Algorithm

Idea: proof by contradiction;

it shows that KB is unsatisfiable.

Page 60: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 61: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

First-order Logic

School of Computer Science & Engineering Chung-Ang University

Artificial Intelligence

Dae-Won Kim

Page 62: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Outline

• Why First-order logic?

• Syntax and semantics of FOL

• Wumpus word in FOL

• Inference in FOL

Page 63: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 64: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 65: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Logics in General

Page 66: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Syntax

• Constants: KingJohn, 2, CAU, …

• Predicates: Brother, >, …

• Functions: Sqrt, LeftLegOf, …

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

• Connectives/Equality: , , , =, …

• Quantifiers: ,

Page 67: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Atomic Sentences

• Atomic sentence

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

• Term

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

E.g., Brother(KingJohn, RichardTheLionheart)

Page 68: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 69: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Models for FOL: Example

Page 70: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 71: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 72: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 73: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 74: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 some possible object in the model.

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

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

Page 75: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 76: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 77: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 78: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 79: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 80: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 81: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 82: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 83: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Inference

• Reducing first-order inference to propositional inference

• Unification

• Generalized Modus Ponens

• Forward and backward chaining

• Resolution

Page 84: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 85: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 86: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 87: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

GMP: Generalized Modus Ponens

Page 88: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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 89: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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)

• 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-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Forward Chaining

Incomplete (infinite loops).

Widely used for logic programming.

Page 91: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Forward Chaining

Page 92: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Forward Chaining

Page 93: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Forward Chaining

Page 94: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Backward Chaining

Sound and complete vs. expensive (NP-hard)

Page 95: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Backward Chaining

Page 96: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Backward Chaining

Page 97: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Backward Chaining

Page 98: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Backward Chaining

Page 99: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Backward Chaining

Page 100: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Backward Chaining

Page 101: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Backward Chaining

Page 102: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

Resolution

• = {x/Ken}

• Apply resolution steps to CNF(KB )

Page 104: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang

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)

• 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 105: Logical Reasoning and Inference - CAU AI Labai.cau.ac.kr/teaching/ai-2014/07.pdf · 2014-10-16 · Logical Reasoning and Inference School of Computer Science & Engineering Chung-Ang