Ai-Module 3
Ai-Module 3
Logical Agents
• Knowledge-Based Agents
• Logic
• Inference: Logical agents perform inference by applying logical rules and deduction to draw
conclusions from known facts and information.
• They use mechanisms such as modus ponens, resolution, and backward chaining to derive new
information from existing knowledge.
• In some cases, logical agents may employ search algorithms to explore the space of possible
solutions or states.
• Based on the conclusions drawn from logical inference, logical agents select actions to achieve
their goals or objectives.
Knowledge Based Agents
• The idea is that an agent can represent knowledge of its world, its goals and the
current situation by sentences in logic and decide what to do by inferring that a
certain action or course of action is appropriate to achieve its goals.”
• Intelligent agents need knowledge about the world to choose
• good actions/decisions.
– Query what is known: Ask itself what to do - answers should follow from the KB
When knowledge-based agent runs it:
– Tells KB about its latest perception
• MAKE-PERCEPT-SENTENCE
• MAKE-ACTION-QUERY
• MAKE-ACTION-SENTENCE
The Wumpus World
• 4 X 4 grid of rooms
• Squares adjacent to Wumpus are smelly and squares adjacent to pit are breezy
• Wumpus emits a horrible scream when it is killed that can be hear anywhere
Environment:
– 4 X 4 grid of rooms
– Locations of the gold, and Wumpus are chosen randomly with a uniform distribution from
all squares except [1,1]
– Each square other than the start can be a pit with probability of 0.
Actuators:
– Left turn, Right turn, Forward, Grab, Release, Shoot
Sensors:
– In the squares directly (not diagonally) adjacent to the wumpus, the agent will
perceive a Stench. 1
– In the squares directly adjacent to a pit, the agent will perceive a Breeze.
– In the square where the gold is, the agent will perceive a Glitter.
– When the wumpus is killed, it emits a woeful Scream that can be perceived anywhere
in the cave.
Logic
• Knowledge bases consist of sentences.
• The semantics for arithmetic specifies that the sentence “x+y=4” is true in a
world where x is 2 and y is 2, but false in a world where x is 1 and y is 1.
• The semantics defines the truth of each sentence with respect to each possible world.
• This involves the relation of logical entailment between sentences—the idea that a sentence
follows logically from another sentence. α |= β to mean that the sentence α entails the
sentence β.
• α |= β if and only if, in every model in which α is true, β is also true. Using the notation just
• An inference algorithm that derives only entailed sentences is called sound or truth
preserving.
• “How are you?” or “Hello!” are not propositions. In general, statement that are
questions, commands, or opinions are not propositions.
• Complex sentences are constructed from simpler sentences, using parentheses and
operators called logical connectives.
There are five connectives in common use:
• ¬ (not). A sentence such as ¬W1,3 is called the negation of W1,3. A literal is either an atomic sentence
(a positive literal) or a negated atomic sentence (a negative literal).
• ∧ (and). A sentence whose main connective is ∧, such as W1,3 ∧ P3,1, is called a conjunction; its
parts are the conjuncts. (The ∧ looks like an “A” for “And”.)
• ∨ (or). A sentence whose main connective is ∨, such as (W1,3 ∧ P3,1) ∨ W2,2, is a disjunction; its
parts are disjuncts—in this example, (W1,3 ∧P3,1) and W2,2.
• ⇒ (implies). A sentence such as (W1,3 ∧P3,1) ⇒ ¬W2,2 is called an implication (or conditional). Its
premise or antecedent is (W1,3 ∧P3,1), and its conclusion or consequent is ¬W2,2. Implications are
also known as rules or if–then statements. The implication symbol is sometimes written in other books
as ⊃ or →.
• It's sound because it adheres to the rules of logical entailment, ensuring that only valid
conclusions are drawn.
• However, the time complexity is exponential in the worst case, specifically O(2^n), where n
is the number of symbols in the knowledge base and α.
• Despite the exponential time complexity, the space complexity remains manageable at O(n)
due to the depth-first nature of the enumeration.
• Efficient algorithms exist to mitigate the exponential complexity, offering better performance
in many cases.
Propositional Theorem Proving
• The first concept is logical equivalence: two sentences α and β are logically equivalent if they are true
in the same set of models.
• An alternative definition of equivalence is as follows: any two sentences α and β are equivalent if and
only if each of them entails the other:
• The second concept we will need is 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. Because the sentence True is
true in all models, every valid sentence is logically equivalent to True.
• What good are valid sentences? From our definition of entailment, we can derive the deduction
theorem, which was known to the ancient Greeks:
• Validity and satisfiability are of course connected: α is valid if ¬α is unsatisfiable; contra
positively, α is satisfiable if ¬α is not valid. We also have the following useful result: α |
= β if and only if the sentence (α∧ ¬β) is unsatisfiable.
Inference and Proofs
• This section covers inference rules that can be applied to derive a proof—a chain of
conclusions that leads to the desired goal. The best-known rule is called Modus Ponens
(Latin for mode that affirms) and is written
• The 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.
Another useful inference rule is And-Elimination, which says that, from a
conjunctionany of the conjuncts 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
Proof by Resolution
• If we removed the biconditional elimination rule, the proof in the preceding section would
not go through. The current section introduces a single inference rule, resolution, that
yields a complete inference algorithm when coupled with any complete search algorithm.
Conjunctive normal form
• A sentence expressed as a conjunction of clauses is said to be in conjunctive normal form
or CNF (see Figure 7.12). We now describe a procedure for converting to CNF. We
illustrate the procedure by converting the sentence B1,1 ⇔ (P1,2 ∨P2,1) into CNF. The
steps are as follows:
A resolution algorithm
• The empty clause—a disjunction of no disjuncts—is equivalent to False
because a disjunction is true only if at least one of its disjuncts is true.
Moreover, the empty clause arises only from resolving two contradictory unit
clauses such as P and ¬P.