Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 40

Chapter 7

Logical Agents

Supervised BY prof. Abass Al-bakri

Prepared by :
Noor Saad Thura Jamal Zainab Malik
OUTLINES

• 7.1 Knowledge-Based Agents


• 7.2 The Wumpus World
• 7.3 Logic
• 7.4 Propositional Logic
• 7.5 Propositional Theorem Proving
• 7.6 Effective Propositional Model Checking
• 7.7 Propositional Logic Agents
7.1 Knowledge-Based Agents

• Knowledge-based agents are best understood as agents that know about their
world and reason about their courses of action.
Basic concepts :
• The knowledge-base (KB): a set of representations of facts about the
world.
• The knowledge representation language: a language whose sentences
represent facts about the world.
• TELL and ASK interface: operations for adding new sentences to the KB and
querying what is known. This is similar to updating and querying in databases.
We can describe a knowledge-based agent at three levels:
1. The knowledge level: In this level the agent is specified by saying what it knows about
the world and what its goals are .
2. The logical level: This is the level at which the knowledge is encoded into sentences of
some logical language .
3. The implementation level: This is the level where sentences are implemented. This level
runs on the agent architecture.

• Declarative approach –designing the representation language to make it easily


express knowledge for the world the language is being implemented for .
• Procedural approach – encodes desired behaviors directly in program code.

* A successful agent must combine both Declarative & procedural elements in its
design.
7.2 THE WUMPUS WORLD

The Wumpus world is a cave consisting of rooms connected by passageways.


Lurking somewhere in the cave is the Wumpus, a beast that eats anyone who
enters its room.
- The Wumpus can be shot by an agent, but the agent has only one arrow .
The task environment for Wupus World :
 Performance measure : gold +1000, death -1000 , -1 per step,
-10 for using the arrow

 Environment : 4x4 grid of rooms with agent, wumpus, gold and pits.
o Squares adjacent to wumpus are smelly
o Squares adjacent to pit are breezy
o Glitter if gold is in the same square
o Shooting kills wumpus if you are facing it
o Shooting uses up the only arrow
o Grabbing picks up gold if in same square
o Releasing drops the gold in same square

 Actuators : Forward, Turn Left (90°),, Turn Right (90°),, Grab, Release, Shoot .

 Sensors: Stench, Breeze, Glitter, Bump, Scream .


Wumpus world characterization :

• Fully Observable No – only local perception


• Deterministic Yes – outcomes exactly specified
• Episodic No – sequential at the level of actions
• Static Yes – Wumpus and Pits do not move
• Discrete Yes
• Single-agent? Yes – Wumpus is essentially a natural feature
If the Wumpus were
here, stench should be
here. Therefore it is
here.
Since, there is no breeze
here, the pit must be
there
Figure 7.3 The first step taken by the agent in the Wumpus world. (a) The initial situation, after percept [None,
None, None, None, None]. (b) After one move, with percept [None, Breeze, None, None, None].
Figure 7.4 Two later stages in the progress of the agent. (a) After the third move, with percept [Stench, None, None,
None, None]. (b) After the fifth move, with percept [Stench, Breeze,Glitter, None, None].
7.3 Logic
• Logics : formal languages for representing information such that conclusions can
be drawn .

• Syntax : description of a representative language in terms of well-formed sentences


of the language.
• Semantics : defines the “meaning” (truth) of a sentence in the representative
language each possible world.

• Truth : A sentence will be called true under a particular interpretation if the state of
affairs it represents is the case.

• Model : the world being described by a KB.


• Satisfaction : model m satisfies a sentence α, if α is true in m.
Entailment : A sentence follows logically from another sentence .
-In mathematical notation, we write as :
α ╞ β (Read α entails β)
-if α is true then β must also be true.

Example :
X+Y = 4 entails the sentence 4 = X+Y
Logical inference : the process of using entailment to derive conclusions .
Model checking : enumerates all possible models to check that a sentence α is true
in all models in which KB is true .
-Model checking works if the space of models is finite .
* There are 23 =8 possible models

KB = wumpus-world rules + observations

α1 = “there is no pit in [1,2]", KB ╞ α1, proved by α2 = “there is no pit in [2,2]", KB ╞ α2


model checking
Propositional Logic
• Atomic sentence : consists of a single propositional symbol,
which is True or False
• Complex sentence :constructed from simpler sentences using
parentheses and logical connectives:
• Five connectives common used:
• ¬ S (negation) • ¬ P is true iff P is false in m.
• S1 ˄ S2 (conjunction) (and) • P ∧ Q is true iff both P and Q are true in m.
• P ∨ Q is true iff either P or Q is true in m.
• S1 ˅ S2 (disjunction) (or) • P ⇒ Q is true unless P is true and Q is false in m.
• S1 ⇒ S2 (implication) • P ⇔ Q is true iff P and Q are both true or
• S1 ⇔ S2 (biconditional) both false in m.
Truth tables for the five logical connectives
Wumpus World Symbols and Sentences Ri
• P x,y is true if there is a pit in [x,y]
• W x,y is true if there is a Wumpus in [x,y]
• B x,y is true if there is a breeze in [x,y]
• S x,y is true if there is a stench in [x,y]

• No pit in [1,1]
• R1: ¬P1,1
• Pits cause breezes in adjacent squares
• R2: B1,1 (P1,2 ˅ P2,1)
• R3: B2,1 (P1,1 ˅ P2,2 ˅ P3,1)
• For first two squares
• R4: ¬B1,1
• R5: B2,1
Wumpus World Symbols and Sentences Ri
Equivalence, validity, and satisfiability
Some logical additional concepts related to entailment:
• Logical equivalence – two sentences α and β are
logically equivalent if they are true in the same set of
models.
• Validity – a sentence is valid if it is true in all
models.
• Valid sentences are also called tautologies –
sentences that are necessarily true.
Equivalence, validity, and satisfiability
• Satisfiability a sentence is satisfiable if it is true in
some model.
• Determining satisfiability in propositional logic is
was proved to be Np-complete.
Standard logical equivalences
You need to
know these !
Reasoning Patterns in Propositional Logic
• Inference rules used to derive chains of conclusions that lead
to the desired goal

• Common Patterns:

• And Elimination    • Modus Ponens


• From a conjunction, any of • Whenever sentences of the


the conjuncts can be inferred form a  b and a are given,
then sentence b can be
inferred
Modus Ponens example

• "If you have a current password, then you can log on to the network"
• "You have a current password“

Therefore

• "You can log on to the network“

• “You can't log into the network”


• “If you have a current password, then you can log into the network”

Therefore

• You don't have a current password.


23

Reasoning Patterns in Propositional Logic

Inference and Proofs


Example to prove ¬P1,2 from R1 through R5:
R1: ¬ P1,1
R2: B1,1 ⇔ (P1,2 ∨ P2,1)
R3: B2,1 ⇔(P1,1 ∨ P2,2 ∨ P3,1)
R4: ¬B1,1
R5: B2,1
Inference And Proofs
• Applying biconditional elimination to R2 to obtain
R6: (B1,1 ⇒ (P1,2 ˅ P2,1)) ˄ ((P1,2 ˅ P2,1) ⇒ B1,1)
• Applying And-Elimination to obtain
R7: ((P1,2 ˅ P2,1) ⇒ B1,1)
• Apply Contraposition gives
R8: (¬B1,1 ⇒ ¬(P1,2 ˅ P2,1))
• Modus Ponens with R8 and the percept ¬B1,1 gives
R9: ¬(P1,2 ˅ P2,1)
• De Morgan’s rule gives
R10: ¬P1,2 ˄ ¬P2,1
that is, neither P12 nor P21 contains a pit.
7.5.2 Resolution
• yields a complete inference algorithm when coupled
with any complete search algorithm
• 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
7.5.2 proof by resolution
• consider the agent goes to [1,2], where it
perceives a stench, but no breeze. We add the
following facts to the knowledge base:
R11 : ¬ B1,2 .
R12 : B1,2 ⇔ (P1,1 ∨ P2,2 ∨ P1,3) .
• By the same process that led to R10 earlier, we
can now derive the absence of pits
R13 : ¬ P2,2 .
R14 : ¬ P1,3 .
7.5.2 proof by resolution
• We can also apply biconditional elimination to R3,
followed by Modus Ponens with R5, to obtain the
fact that there is a pit in [1,1], [2,2], or [3,1].
R15 : P1,1 ∨ P2,2 ∨ P3,1 .
• Now comes the first application of the resolution
rule: the literal ¬ P2,2 in R13 resolves with the
literal P2,2 in R15 to give the resolvent
R16 : P1,1 ∨ P3,1 .
• Similarly, the literal ¬ P1,1 in R1 resolves with the
literal P1,1 in R16 to give
R17 : P3,1 .
Resolution
To apply resolution mechanically, facts need to be in Conjunctive Normal Form (CNF)
conjunction of disjunctions of literals clauses

Conjunctive Normal Form (CNF)


E.g., (A  B)  (B  C  D)

• Resolution inference rule (for CNF):


• li …  lk , m1  …  mn

li  …  li-1  li+1  …  lk  m1  …  mj-1  mj+1 ...  mn


where li and mj are complementary literals.
E.g. P1,3  P2,2 , P2,2

P1,3
7.5.2 proof by resolution

• every sentence of propositional logic is logically


equivalent to a conjunction of clauses.
• E.g. Convert B1,1 ⇔ (P1,2 ˅ P2,1) to CNF:

1. Eliminate ⇔ , replacing α ⇔ β with (α ⇒ β) ˄ (β ⇒ α)


(B1,1 ⇒ (P1,2 ˅ P2,1)) ˄ ((P1,2 ˅ P2,1) ⇒ B1,1)
2. Eliminate ⇒ , replacing α ⇒ β with ¬ α ˅ β
(¬B1,1 ˅ P1,2 ˅ P2,1) ˄ (¬(P1,2 ˅ P2,1) ˅ B1,1)
3. Move ¬ inwards using de Morgan's rules and double
negation
(¬B1,1 ˅ P1,2 ˅ P2,1) ˄ ((¬P1,2 ˄ ¬P2,1) ˅ B1,1)
4. Apply distributivity law (˅ over ˄) and flatten
(¬B1,1 ˅ P1,2 ˅ P2,1) ˄ (¬P1,2 ˅ B1,1) ˄ (¬P2,1 ˅ B1,1)
7.5.2 proof by resolution
A resolution algorithm
• First, (KB ∧ ¬ α) is converted into CNF.
• Then, the resolution rule is applied to the
resulting clauses.
• Each pair that contains complementary literals
is resolved to produce a new clause, which is
added to the set if it is not already present.
• The process continues until one of two things
happens:
• there are no new clauses that can be added
• two clauses resolve to yield the empty clause.
Resolution example
• KB = (B1,1  (P1,2 P2,1))  B1,1
KB  
• α = P1,2

True!
False in
all worlds
A resolution algorithm
7.5.3 Horn clauses and definite clauses
• Some real-world knowledge bases satisfy certain
restrictions on the form of sentences they contain.
which enables them to use a more restricted and
efficient inference algorithm.
Such restricted forms are :
• Definite clause – disjunction of literals, of which exactly
one is positive e.g. ¬P1 ˅ ¬P2 ˅ ¬P3 ˅ P4
• Horn clause – a disjunction of literals at most one of
which is positive e.g. ¬P1 ˅ ¬P2, or ¬P3 ˅ P4
- Can be used with forward chaining or backward chaining
- Deciding entailment is linear in the size of KB
• Goal clause – a clause with no positive literals, ¬P1˅¬P2
7.5.3 Horn clauses and definite clauses

• Every definite clause can be written as an implication


whose premise is a conjunction of positive literals and
whose conclusion is a single positive literal
• For example, the definite clause ( ¬ L1,1 ∨ ¬ Breeze ∨
B1,1) can be written as the implication (L1,1 ∧ Breeze) ⇒
B1,1.
• In the implication form, the sentence is easier to
understand
7.5.4 Forward and backward chaining

Forward chaining
• It begins from known facts (positive literals) in the KB. If
all the premises of an implication are known, then its
conclusion is added to the set of known facts. For example,
if L1,1 and Breeze are known and (L1,1 ∧ Breeze) ⇒ B1,1 is in
the KB, then B1,1 can be added.
• a sound and complete inference algorithm that is essentially
Modus Ponens
7.5.4 Forward and backward chaining
37

Example of forward chaining


We’ve proved that Q is true

KB
AND-OR graph

Agenda

A
B
L
M
P
A  B  L, A  B Q
Every step is Modus Ponens, e.g.
L
38

Example of backward chaining

KB
39

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

You might also like