0% found this document useful (0 votes)
68 views

Artificial Intelligence Chapter 7: Logical Agents

This document discusses different types of logical reasoning that can be used in artificial intelligence systems. It introduces propositional logic and describes how logical sentences can be represented. It then discusses different reasoning techniques like forward chaining, backward chaining, and resolution that allow logical inferences to be made from a knowledge base. Forward chaining works by applying rules to derive new facts from existing knowledge, while backward chaining works backwards from a goal to find rules that can prove it. Resolution provides a complete inference method using a single inference rule.

Uploaded by

Tushar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Artificial Intelligence Chapter 7: Logical Agents

This document discusses different types of logical reasoning that can be used in artificial intelligence systems. It introduces propositional logic and describes how logical sentences can be represented. It then discusses different reasoning techniques like forward chaining, backward chaining, and resolution that allow logical inferences to be made from a knowledge base. Forward chaining works by applying rules to derive new facts from existing knowledge, while backward chaining works backwards from a goal to find rules that can prove it. Resolution provides a complete inference method using a single inference rule.

Uploaded by

Tushar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 85

Artificial Intelligence

Chapter 7: Logical Agents


Contents
• Knowledge Based Agents
• Wumpus World
• Logic in General – models and entailment
• Propositional (Boolean) Logic
• Equivalence, Validity, Satisfiability
• Inference Rules and Theorem Proving
– Forward Chaining
– Backward Chaining
– Resolution
Logical Agents
• Humans can know “things” and “reason”
– Representation: How are the things stored?
– Reasoning: How is the knowledge used?
• To solve a problem…
• To generate more knowledge…

• Knowledge and reasoning are important to artificial


agents because they enable successful behaviors
difficult to achieve otherwise
– Useful in partially observable environments

• Can benefit from knowledge in very general forms,


combining and recombining information
Knowledge-Based Agents
• Central component of a Knowledge-Based Agent
is a Knowledge-Base
– A set of sentences in a formal language
• Sentences are expressed using a knowledge representation
language

• Two generic functions:


– TELL - add new sentences (facts) to the KB
• “Tell it what it needs to know”
– ASK - query what is known from the KB
• “Ask what to do next”
Knowledge-Based Agents
• The agent must be able
Domain-
to: Independent
Algorithms
– Represent states and Inference Engine
actions
Knowledge-Base
– Incorporate new percepts
– Update internal Domain-
representations of the Specific
Content
world
– Deduce hidden properties
of the world
– Deduce appropriate actions
Knowledge-Based Agents
Knowledge-Based Agents
• Declarative
– You can build a knowledge-based agent
simply by “TELLing” it what it needs to know

• Procedural
– Encode desired behaviors directly as program
code
• Minimizing the role of explicit representation and
reasoning can result in a much more efficient
system
Wumpus World
• Performance Measure
– Gold +1000, Death – 1000
– Step -1, Use arrow -10

• Environment
– Square adjacent to the Wumpus are smelly
– Squares adjacent to the 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 the gold if in the same
square
– Releasing drops the gold in the same square

• Actuators
– Left turn, right turn, forward, grab, release,
shoot

• Sensors
– Breeze, glitter, and smell

• See page 197-8 for more details!


Wumpus World
• Characterization of Wumpus World
– Observable
• partial, only local perception
– Deterministic
• Yes, outcomes are specified
– Episodic
• No, sequential at the level of actions
– Static
• Yes, Wumpus and pits do not move
– Discrete
• Yes
– Single Agent
• Yes
Wumpus World
Wumpus World
Logic
• Entailment in Wumpus
World

• Situation after detecting


nothing in [1,1], moving
right, breeze in [2,1]

• Consider possible models


for ? assuming only pits

• 3 Boolean choices => 8


possible models
Propositional Logic
• AKA Boolean Logic
• False and True
• Proposition symbols P1, P2, etc are sentences

• NOT: If S1 is a sentence, then ¬S1 is a sentence (negation)

• AND: If S1, S2 are sentences, then S1  S2 is a sentence (conjunction)

• OR: If S1, S2 are sentences, then S1  S2 is a sentence (disjunction)

• IMPLIES: If S1, S2 are sentences, then S1  S2 is a sentence (implication)

• IFF: If S1, S2 are sentences, then S1  S2 is a sentence (biconditional)


Propositional Logic
P Q ¬P PQ PQ PQ PQ

False False True False False True True

False True True False True True False

True False False False True False False

True True False True True True True


Wumpus World Sentences
• Let Pi,j be True if there • “Pits cause breezes in
is a pit in [i,j] adjacent squares”
• Let Bi,j be True if there
is a breeze in [i,j] B1,1  (P1,2  P2,1)

• ¬P1,1 B2,1  (P1,1  P2,1  P3,1)


• ¬ B1,1
• B2,1 • A square is breezy if
and only if there is an
adjacent pit
A Simple Knowledge Base
A Simple Knowledge Base

• R1: ¬P1,1 • KB consists of sentences


• R2: B1,1  (P1,2  P2,1) R1 thru R5
• R3: B2,1 (P1,1  P2,2 
P3,1) • R1  R2  R3  R4  R5
• R4: ¬ B1,1
• R5: B2,1
Equivalence, Validity, Satisfiability
Reasoning Patterns
• Inference Rules
– Patterns of inference that can be applied to derive chains of conclusions
that lead to the desired goal.

• Modus Ponens
– Given: S1  S2 and S1, derive S2

• And-Elimination
– Given: S1  S2, derive S1
– Given: S1  S2, derive S2

• DeMorgan’s Law
– Given: ( A  B) derive A  B
– Given: ( A  B) derive A  B
Reasoning Patterns
• And Elimination • Modus Ponens
𝛼∧𝛽 𝛼 ⇒ 𝛽, 𝛼
𝛼 𝛽

• From a conjunction, • Whenever sentences


any of the conjuncts of the form    and
can be inferred  are given, then
sentence  can be
• (WumpusAhead  WumpusAlive), inferred
WumpusAlive can be inferred • (WumpusAhead  WumpusAlive)
 Shoot and (WumpusAhead 
WumpusAlive), Shoot can be
inferred
Example Proof By Deduction
• Knowledge
S1: B22  ( P21  P23  P12  P32 ) rule
S2: B22 observation

• Inferences
S3: (B22  (P21  P23  P12  P32 ))
((P21  P23  P12  P32 )  B22) [S1,bi elim]
S4: ((P21  P23  P12  P32 )  B22) [S3, and elim]
S5: (B22  ( P21  P23  P12  P32 )) [contrapos]
S6: (P21  P23  P12  P32 ) [S2,S6, MP]
S7: P21  P23  P12  P32 [S6, DeMorg]
Evaluation of Deductive
Inference
• Sound
– Yes, because the inference rules themselves are
sound. (This can be proven using a truth table
argument).
• Complete
– If we allow all possible inference rules, we’re
searching in an infinite space, hence not complete
– If we limit inference rules, we run the risk of leaving
out the necessary one…
• Monotonic
– If we have a proof, adding information to the DB will
not invalidate the proof
Resolution
• Resolution allows a complete inference
mechanism (search-based) using only one rule
of inference
• Resolution rule:
– Given: P1  P2  P3 … Pn, and P1  Q1 … Qm
– Conclude: P2  P3 … Pn  Q1 … Qm
Complementary literals P1 and P1 “cancel out”
• Why it works:
– Consider 2 cases: P1 is true, and P1 is false
Resolution in Wumpus World
• There is a pit at 2,1 or 2,3 or 1,2 or 3,2
– P21  P23  P12  P32
• There is no pit at 2,1
 P21
• Therefore (by resolution) the pit must be at
2,3 or 1,2 or 3,2
– P23  P12  P32
Horn Clauses
• A Horn Clause is a CNF clause with exactly one positive
literal
– The positive literal is called the head
– The negative literals are called the body
– Prolog: head:- body1, body2, body3 …
– English: “To prove the head, prove body1, …”
– Implication: If (body1, body2 …) then head
• Horn Clauses form the basis of forward and backward
chaining
• The Prolog language is based on Horn Clauses
• Deciding entailment with Horn Clauses is linear in the
size of the knowledge base
Reasoning with Horn Clauses
• Forward Chaining
– For each new piece of data, generate all new
facts, until the desired fact is generated
– Data-directed reasoning
• Backward Chaining
– To prove the goal, find a clause that contains
the goal as its head, and prove the body
recursively
– (Backtrack when you chose the wrong clause)
– Goal-directed reasoning
Forward Chaining
• Fire any rule whose premises are satisfied in the KB
• Add its conclusion to the KB until the query is found
Forward Chaining
• AND-OR Graph
– multiple links joined by an arc indicate conjunction – every link must be proved
– multiple links without an arc indicate disjunction – any link can be proved
Forward Chaining
Forward Chaining
Forward Chaining
Forward Chaining
Forward Chaining
Forward Chaining
Forward Chaining
Forward Chaining
Backward Chaining
• Idea: work backwards from the query q:
– To prove q by BC,
• Check if q is known already, or
• Prove by BC all premises of some rule concluding q

• Avoid loops
– Check if new subgoal is already on the goal stack

• Avoid repeated work: check if new subgoal


– Has already been proved true, or
– Has already failed
Backward Chaining
Backward Chaining
Backward Chaining
Backward Chaining
Backward Chaining
Backward Chaining
Backward Chaining
Backward Chaining
Backward Chaining
Backward Chaining
Backward Chaining
Forward chaining
(Data driven reasoning)

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

AND-OR graph
Forward Chaining vs. Backward
Chaining
• Forward Chaining is data driven
– Automatic, unconscious processing
– E.g. object recognition, routine decisions
– May do lots of work that is irrelevant to the goal

• Backward Chaining is goal driven


– Appropriate for problem solving
– E.g. “Where are my keys?”, “How do I start the car?”

• The complexity of BC can be much less than


linear in size of the KB
Propositional logic:
Rules of Inference or Method of Proof
Rule of Inference Tautology (Deduction Theorem) Name

P P  (P  Q) Addition
PQ
PQ (P  Q)  P Simplification
P
P [(P)  (Q)]  (P  Q) Conjunction
Q
PQ

P [(P)  (P Q)]  (P  Q) Modus Ponens


PQ
Q

Q [(Q)  (P Q)]  P Modus Tollens


PQ
 P

PQ [(PQ)  (Q  R)]  (PR) Hypothetical Syllogism


QR (“chaining”)
 P R
PQ [(P  Q)  (P)]  Q Disjunctive syllogism
P
Q

PQ [(P  Q)  (P  R)]  (Q  R) Resolution


P  R
QR
Backward chaining

Idea: work backwards from the query q:


to prove q by BC,
check if q is known already, or
prove by BC all premises of some rule concluding q

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

Avoid repeated work: check if new subgoal


1. has already been proved true, or
2. has already failed
Forward vs. backward chaining

FC is data-driven, automatic, unconscious processing,


– e.g., object recognition, routine decisions

May do lots of work that is irrelevant to the goal

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


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

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


Inference in first-order logic
Outline
• Reducing first-order inference to
propositional inference
• Unification
• Generalized Modus Ponens
• Forward chaining
• Backward chaining
• Resolution
Universal instantiation (UI)
• Every instantiation of a universally quantified sentence is entailed by
it:
v α
Subst({v/g}, α)
for any variable v and ground term g

• E.g., x King(x)  Greedy(x)  Evil(x) yields:


King(John)  Greedy(John)  Evil(John)
King(Richard)  Greedy(Richard)  Evil(Richard)
King(Father(John))  Greedy(Father(John))  Evil(Father(John))
.
.
.
Existential instantiation (EI)
• For any sentence α, variable v, and constant
symbol k that does not appear elsewhere in the
knowledge base:
v α
Subst({v/k}, α)

• E.g., x Crown(x)  OnHead(x,John) yields:

Crown(C1)  OnHead(C1,John)

provided C1 is a new constant symbol, called a


Skolem constant
»
»
Reduction to propositional
inference
Suppose the KB contains just the following:
x King(x)  Greedy(x)  Evil(x)
King(John)
Greedy(John)
Brother(Richard,John)

• Instantiating the universal sentence in all possible ways, we have:


King(John)  Greedy(John)  Evil(John)
King(Richard)  Greedy(Richard)  Evil(Richard)
King(John)
Greedy(John)
Brother(Richard,John)

• The new KB is propositionalized: proposition symbols are


King(John), Greedy(John), Evil(John), King(Richard), etc.

»

»
Reduction contd.
• Every FOL KB can be propositionalized so as to
preserve entailment

• (A ground sentence is entailed by new KB iff entailed by


original KB)

• Idea: propositionalize KB and query, apply resolution,


return result

• Problem: with function symbols, there are infinitely many


ground terms,
– e.g., Father(Father(Father(John)))
Reduction contd.
Theorem: Herbrand (1930). If a sentence α is entailed by an FOL KB, it
is entailed by a finite subset of the propositionalized KB

Idea: For n = 0 to ∞ do
create a propositional KB by instantiating with depth-$n$ terms
see if α is entailed by this KB

Problem: works if α is entailed, loops if α is not entailed

Theorem: Turing (1936), Church (1936) Entailment for FOL is


semidecidable (algorithms exist that say yes
to every entailed sentence, but no
algorithm exists that also says no to every
nonentailed sentence.)
Problems with propositionalization
• Propositionalization seems to generate lots of irrelevant sentences.

• E.g., from:
x King(x)  Greedy(x)  Evil(x)
King(John)
y Greedy(y)
Brother(Richard,John)

• it seems obvious that Evil(John), but propositionalization produces


lots of facts such as Greedy(Richard) that are irrelevant

• With p k-ary predicates and n constants, there are p·nk


instantiations.


Unification
• We can get the inference immediately if we can find a substitution θ
such that King(x) and Greedy(x) match King(John) and Greedy(y)

θ = {x/John,y/John} works

• Unify(α,β) = θ if αθ = βθ
p q θ
Knows(John,x) Knows(John,Jane)
Knows(John,x) Knows(y,OJ)
Knows(John,x) Knows(y,Mother(y))
Knows(John,x) Knows(x,OJ)

• Standardizing apart eliminates overlap of variables, e.g.,


Knows(z17,OJ)
»
Unification
• We can get the inference immediately if we can find a substitution θ
such that King(x) and Greedy(x) match King(John) and Greedy(y)

θ = {x/John,y/John} works

• Unify(α,β) = θ if αθ = βθ
p q θ
Knows(John,x) Knows(John,Jane) {x/Jane}}
Knows(John,x) Knows(y,OJ)
Knows(John,x) Knows(y,Mother(y))
Knows(John,x) Knows(x,OJ)

• Standardizing apart eliminates overlap of variables, e.g.,


Knows(z17,OJ)
»
Unification
• We can get the inference immediately if we can find a substitution θ
such that King(x) and Greedy(x) match King(John) and Greedy(y)

θ = {x/John,y/John} works

• Unify(α,β) = θ if αθ = βθ
p q θ
Knows(John,x) Knows(John,Jane) {x/Jane}}
Knows(John,x) Knows(y,OJ) {x/OJ,y/John}}
Knows(John,x) Knows(y,Mother(y))
Knows(John,x) Knows(x,OJ)

• Standardizing apart eliminates overlap of variables, e.g.,


Knows(z17,OJ)
»
Unification
• We can get the inference immediately if we can find a substitution θ
such that King(x) and Greedy(x) match King(John) and Greedy(y)

θ = {x/John,y/John} works

• Unify(α,β) = θ if αθ = βθ
p q θ
Knows(John,x) Knows(John,Jane) {x/Jane}}
Knows(John,x) Knows(y,OJ) {x/OJ,y/John}}
Knows(John,x) Knows(y,Mother(y)) {y/John,x/Mother(John)}}
Knows(John,x) Knows(x,OJ)

• Standardizing apart eliminates overlap of variables, e.g.,


Knows(z17,OJ)
»
Unification
• We can get the inference immediately if we can find a substitution θ
such that King(x) and Greedy(x) match King(John) and Greedy(y)

θ = {x/John,y/John} works

• Unify(α,β) = θ if αθ = βθ
p q θ
Knows(John,x) Knows(John,Jane) {x/Jane}}
Knows(John,x) Knows(y,OJ) {x/OJ,y/John}}
Knows(John,x) Knows(y,Mother(y)) {y/John,x/Mother(John)}}
Knows(John,x) Knows(x,OJ) {fail}

• Standardizing apart eliminates overlap of variables, e.g.,


Knows(z17,OJ)
»
Unification
• To unify Knows(John,x) and Knows(y,z),
θ = {y/John, x/z } or θ = {y/John, x/John, z/John}

• The first unifier is more general than the second.

• There is a single most general unifier (MGU) that


is unique up to renaming of variables.
MGU = { y/John, x/z }
Example knowledge base
• 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


Example knowledge base contd.
... it is 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, i.e., x Owns(Nono,x)  Missile(x):
Owns(Nono,M1) and Missile(M1)
… all of its missiles were sold to it by Colonel West
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 American …
American(West)
The country Nono, an enemy of America …
Enemy(Nono,America)

»
»
Forward chaining proof
Forward chaining proof
Forward chaining proof
Properties of forward chaining
• Sound and complete for first-order definite clauses

• Datalog = first-order definite clauses + no functions


• FC terminates for Datalog in finite number of iterations

• May not terminate in general if α is not entailed

• This is unavoidable: entailment with definite clauses is


semidecidable
»
»


Efficiency of forward chaining
Incremental forward chaining: no need to match a rule on
iteration k if a premise wasn't added on iteration k-1
 match each rule whose premise contains a newly added positive
literal

Matching itself can be expensive:


Database indexing allows O(1) retrieval of known facts
– e.g., query Missile(x) retrieves Missile(M1)

Forward chaining is widely used in deductive databases



Hard matching example
Diff(wa,nt)  Diff(wa,sa)  Diff(nt,q) 
Diff(nt,sa)  Diff(q,nsw)  Diff(q,sa) 
Diff(nsw,v)  Diff(nsw,sa)  Diff(v,sa) 
Colorable()

Diff(Red,Blue) Diff (Red,Green)


Diff(Green,Red) Diff(Green,Blue)
Diff(Blue,Red) Diff(Blue,Green)

• Colorable() is inferred iff the CSP has a solution


Backward chaining example
Backward chaining example
Backward chaining example
Backward chaining example
Backward chaining example
Backward chaining example
Backward chaining example
Backward chaining example
Properties of backward chaining
• Depth-first recursive proof search: space is
linear in size of proof
• Incomplete due to infinite loops
  fix by checking current goal against every goal on
stack
• Inefficient due to repeated subgoals (both
success and failure)
  fix using caching of previous results (extra space)
• Widely used for logic programming


Thank You

You might also like