M03 - 03 Logical Agents
M03 - 03 Logical Agents
Logical Agents
• An agent can represent knowledge of its world, its goals and the
current situation.
• Logical Agent has a collection of sentences in logic By using these
logical sentences, the agent decides what to do by inferring
knowledge (conclusion(s))
• The conclusions are achieved by certain action or set of actions, is
appropriate to achieve its goals.
• Knowledge and reasoning are important to logical agents because
they enable successful behaviors to achieve a desired goal.
KNOWLEDGE-BASED AGENTS
(1, 1), (1, 2), (1, 3), (2,1), (2, 2), (2, 3), (3,1), (3,2) and (3, 3)
is true when x is 1 and y is 3, x is 2 and y is 2 & x is 3 and y is 1
• We can apply the same kind of
analysis to the wumpus-world
reasoning example.
• Consider the situation in
Figure: the agent has detected
nothing in [1,1] and a breeze in
[2,1].
• These percepts, combined with
the agent's knowledge of the
rules of the wumpus world,
constitute the KB.
• The agent is interested in
whether the adjacent squares
[1,2], [2,2], and [3,1] contain
pits.
• Each of the three squares
might or might not contain
pits.
• So there are 23 = 8 possible
models
• Let us consider two possible conclusions:
– 1 = "There is no pit in [1, 2]."
– 2 = "There is no pit in [2, 2]."
• KB |= 1
• KB |= 2
PROPOSITIONAL LOGIC: A VERY SIMPLE LOGIC
Syntax:
• defines valid sentences
• The atomic sentences consist of a single proposition
symbol.
• Each such symbol stands for a proposition that can be
true or false.
• We use symbols that start with an uppercase letter
and may contain other letters or subscripts, for
example: P, Q, R, W1,3 and North.
• There are two proposition symbols with fixed
meanings: True is the always-true proposition and
False is the always-false proposition.
• Complex sentences are constructed from simpler
sentences, using parentheses and logical connectives.
• Five Connectives:
Semantics:
• The semantics defines the rules for determining the
truth of a sentence with respect to a particular model.
• In propositional logic, a model simply fixes the truth
value true or false for every proposition symbol.
• one possible model is m1 = {P1,2 = false, P2,2 = false,
P3,1 = true}.
• With three proposition symbols, there are 23 = 8
possible models.
• All sentences are constructed from atomic sentences
and the five connectives; therefore, we need to specify
how to compute the truth of atomic sentences and
how to compute the truth of sentences formed with
each of the five connectives.
• Atomic sentences are easy:
– True is true in every model and False is false in every model.
– The truth value of every other proposition symbol must be
specified directly in the model.
– For example, in the model m1 given earlier, P1,2 is false.
• For complex sentences, we have five rules, which hold
for any sub sentences P and Q in any model m
• the sentence ¬P1,2 ∧ (P2,2 ∨ P3,1), evaluated in m1, gives
true ∧ (false ∨ true) = true ∧ true = true.
• The truth table for ⇒ may not quite fit one’s intuitive understanding
of “P implies Q” or “if P then Q.” For one thing, propositional logic
does not require any relation of causation or relevance between P and
Q.
• The sentence “5 is odd implies Tokyo is the capital of Japan” is a true
sentence of propositional logic (under the normal interpretation), even
though it is a decidedly odd sentence of English.
• Another point of confusion is that any implication is true whenever
its antecedent is false. For example, “5 is even implies Sam is smart”
is true, regardless of whether Sam is smart. This seems bizarre, but it
makes sense if you think of “P ⇒ Q” as saying, “If P is true, then I am
claiming that Q is true. Otherwise I am making no claim.”
• The only way for this sentence to be false is if P is true but Q is false.
• The biconditional, P ⇔ Q, is true whenever both P ⇒ Q
and Q ⇒ P are true.
• In English, this is often written as “P if and only if Q.”
• Many of the rules of the wumpus world are best
written using ⇔.
• For example, a square is breezy if a neighboring
square has a pit, and a square is breezy only if a
neighboring square has a pit.
• So we need a biconditional, B1,1 ⇔ (P1,2 ∨ P2,1) , where
B1,1 means that there is a breeze in [1,1].
A simple Knowledge base:
• We can construct a knowledge base for the wumpus
world.
• We focus first on the immutable aspects of the
wumpus world.
• We need the following symbols for each [x, y] location:
– Px,y is true if there is a pit in [x, y].
– Wx,y is true if there is a wumpus in [x, y], dead or
alive.
– Bx,y is true if the agent perceives a breeze in [x, y].
– Sx,y is true if the agent perceives a stench in [x, y].
• There is no pit in [1,1]:
– R1 : ¬P1,1.
• A square is breezy if and only if there is a pit in a
neighboring square.
– R2 : B1,1 ⇔ (P1,2 ∨ P2,1).
– R3 : B2,1 ⇔ (P1,1 ∨ P2,2 ∨ P3,1).
• The preceding sentences are true in all wumpus worlds.
• Now we include the breeze percepts for the first two
squares visited in the specific world the agent is in,
leading up to the situation in Figure 7.3(b).
– R4 : ¬B1,1.
– R5 : B2,1.
• The KB consists of R1 through R5
• It can also be considered as single
sentence
• The conjunction R1R2 R3 R4 R5
• Because it asserts all sentences are true
A simple Inference Procedure:
• Our goal now is to decide whether KB |= for some
sentence .
• For example, is ¬P1,2 entailed by our KB?
• In wumpus-world example:
• the relevant proposition symbols are B1,1, B2,1, P1,1,
P1,2, P2,1, P2,2, and P3,1.
• With seven symbols, there are 27 = 128 possible
models; in three of these, KB is true.
• In those three models, ¬P1,2 is true, hence there is no
pit in [1,2].
• On the other hand, P2,2 is true in two of the three
models and false in one, so we cannot yet tell whether
there is a pit in [2,2].
• TT-ENTAILS? performs a recursive enumeration of a
finite space of assignments to symbols.
• The algorithm is sound because it implements directly
the definition of entailment, and complete because it
works for any KB and α and always terminates—there
are only finitely many models to examine.
• the time complexity of the algorithm is O(2n).
• The space complexity is only O(n)
PROPOSITIONAL THEOREM PROVING
Equivalence, Validity and Satisfyability:
• logical equivalence: two sentences and are
logically equivalent if they are true in the same set of
models.
• We write this as ≡ β.
• ≡ β if and only if |= β and β |= .
• Validity: A sentence is valid if it is true in all models.
For example, the sentence P ∨ ¬P is valid. Valid
sentences are also known as tautologies. They are
necessarily true.
• A sentence is satisfiable if it is true in, or satisfied by,
some model. (Example: P Q is satisfiable), (P ¬Q) is not satisfiabl e)
• For example, the knowledge base given earlier, (R1 ∧
R2 ∧ R3 ∧ R4 ∧ R5), is satisfiable because there are
three models in which it is true,
Inference and Proofs:
• Standard patterns of inference that can be applied to derive
chains of conclusions that lead to the desired goal. These
patterns of inferences are called inference rules.
• The useful inference rules are:
– Modes Ponens
– And Elimination
• Modes Ponens:
α ⇒ β, α
β
• The above notation means that, whenever any sentences of the
form ⇒ β and are given, then the sentence β can be inferred.
• For example, if (WumpusAhead ∧ WumpusAlive) ⇒ Shoot and
(WumpusAhead ∧ WumpusAlive) are given, then Shoot can be
inferred. αβ
• And Elimination: α
• For example, from (WumpusAhead ∧ WumpusAlive), WumpusAlive
can be inferred.
• All of the logical equivalences in Figure 7.11 can be used as
inference rules.
• For example, the equivalence for biconditional elimination yields
the two inference rules
• Not all inference rules work in both directions like this. For
example, we cannot run Modus Ponens in the opposite direction
to obtain α ⇒ β and α from β.
• Let us see how these inference rules and equivalences can be
used in the wumpus world.
• We start with the knowledge base containing R1 through R5 and
show how to prove ¬P1,2, that is, there is no pit in [1,2].
• First, we apply biconditional elimination to R2 to obtain
• 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.