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

Post on 16-Mar-2019

222 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Logical Reasoning and Inference

School of Computer Science & EngineeringChung-Ang University

Artificial Intelligence

Dae-Won Kim

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 …

Outline

• Knowledge-based agents

• Wumpus world

• Logic in general – models and entailment

• Propositional logic

• Inference rules and theorem proving

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.

A Simple Knowledge-based Agent

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

Wumpus World

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

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

Exploring a Wumpus World

Exploring a Wumpus World

Exploring a Wumpus World

Exploring a Wumpus World

Exploring a Wumpus World

Exploring a Wumpus World

Exploring a Wumpus World

Exploring a Wumpus World

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

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

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

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.

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)

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

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

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)

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.

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)

Inference by Enumeration

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

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

Truth Table for Inference

Logical Equivalence

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

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)

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.

Forward Chaining

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

Forward Chaining

Forward Chaining: Example

Forward Chaining: Example

Forward Chaining: Example

Forward Chaining: Example

Forward Chaining: Example

Forward Chaining: Example

Forward Chaining: Example

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.

Backward Chaining: Example

Backward Chaining: Example

Backward Chaining: Example

Backward Chaining: Example

Backward Chaining: Example

Backward Chaining: Example

Backward Chaining: Example

Backward Chaining: Example

Backward Chaining: Example

Backward Chaining: Example

Backward Chaining: Example

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?

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.

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.

Conversion to CNF

Resolution Algorithm

Idea: proof by contradiction;

it shows that KB is unsatisfiable.

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)

First-order Logic

School of Computer Science & EngineeringChung-Ang University

Artificial Intelligence

Dae-Won Kim

Outline

• Why First-order logic?

• Syntax and semantics of FOL

• Wumpus word in FOL

• Inference in FOL

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)

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, …

Logics in General

Syntax

• Constants: KingJohn, 2, CAU, …

• Predicates: Brother, >, …

• Functions: Sqrt, LeftLegOf, …

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

• Connectives/Equality: , , , =, …

• Quantifiers: ,

Atomic Sentences

• Atomic sentence

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

• Term

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

E.g., Brother(KingJohn, RichardTheLionheart)

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)

Models for FOL: Example

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.

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!

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

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”

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

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.

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)

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)

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)

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.

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)

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)

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

Inference

• Reducing first-order inference to propositional inference

• Unification

• Generalized Modus Ponens

• Forward and backward chaining

• Resolution

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.

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

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}

GMP: Generalized Modus Ponens

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.

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)

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)

Forward Chaining

Incomplete (infinite loops).

Widely used for logic programming.

Forward Chaining

Forward Chaining

Forward Chaining

Backward Chaining

Sound and complete vs. expensive (NP-hard)

Backward Chaining

Backward Chaining

Backward Chaining

Backward Chaining

Backward Chaining

Backward Chaining

Backward Chaining

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

Resolution

• = {x/Ken}

• Apply resolution steps to CNF(KB )

top related