Planning and search Logical agents; FOL Logical agents; FOL 1 Outline ♦ Knowledge-based agents ♦ Wumpus world knowledge in propositional logic Logical agents; FOL 2 Knowledge bases Inference engine domain−independent algorithms Knowledge base domain−specific content Knowledge base = set of sentences in a formal language Declarative approach to building an agent (or other system): Tell it what it needs to know Then it can Ask itself what to do—answers should follow from the KB Agents can be viewed at the knowledge level i.e., what they know, regardless of how implemented Or at the implementation level i.e., data structures in KB and algorithms that manipulate them Logical agents; FOL 3 A simple knowledge-based agent function KB-Agent( percept) returns an action static: KB, a knowledge base t, a counter, initially 0, indicating time Tell(KB, Make-Percept-Sentence( percept, t)) action ← Ask(KB, Make-Action-Query(t)) Tell(KB, Make-Action-Sentence(action, t)) t←t + 1 return action The agent must be able to: Represent states, actions, etc. Incorporate new percepts Update internal representations of the world Deduce hidden properties of the world Deduce appropriate actions Logical agents; FOL 4 Wumpus World 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 same square 4 Breeze Stench Breeze 3 Stench PIT Breeze PIT Gold 2 Breeze Stench Breeze 1 Breeze PIT START 1 2 3 4 Actions Left turn, Right turn, Forward, Grab, Release, Shoot Percepts Breeze, Glitter, Smell (in this square) Logical agents; FOL 5 Wumpus world characterization Observable?? Deterministic?? Logical agents; FOL 6 Wumpus world characterization Observable?? No—only local perception Deterministic?? Yes—outcomes exactly specified Logical agents; FOL 7 Exploring a wumpus world OK OK OK A Logical agents; FOL 8 Exploring a wumpus world B OK A OK OK A Logical agents; FOL 9 Exploring a wumpus world P? B OK P? OK OK A A Logical agents; FOL 10 Exploring a wumpus world P? B OK P? OK S OK A A A Logical agents; FOL 11 Exploring a wumpus world P? P B OK P? OK OK S OK A A A W Logical agents; FOL 12 Exploring a wumpus world P? P B OK A P? OK A OK S A OK A W Logical agents; FOL 13 Exploring a wumpus world P? OK OK P? OK P B A A OK S A OK OK A W Logical agents; FOL 14 Exploring a wumpus world P? OK P B OK A P? BGS OK OK A A OK S A OK A W Logical agents; FOL 15 Logic in general Logics are formal languages for representing information such that conclusions can be drawn Syntax defines the sentences in the language Semantics define the “meaning” of sentences; i.e., define truth of a sentence in a world E.g., the language of arithmetic x + 2 ≥ y is a sentence; x2 + y > is not a sentence x + 2 ≥ y is true iff the number x + 2 is no less than the number y 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 Logical agents; FOL 16 Entailment Entailment means that one thing follows from another: KB |= α Knowledge base KB entails sentence α if and only if α is true in all worlds where KB is true E.g., x + y = 4 entails 4 = x + y Entailment is a relationship between sentences (i.e., syntax) that is based on semantics Logical agents; FOL 17 Models Logicians typically think in terms of models, which are formally structured worlds with respect to which truth can be evaluated (in propositional logic - assignments) We say m is a model of a sentence α if α is true in m M (α) is the set of all models of α Then KB |= α if and only if M (KB) ⊆ M (α) x E.g. KB = it is raining and it is cold α = it is cold x x x x M( x x ) x x x x x xx x x x x x x x x x x x xx x x x x x x x x M(KB) x x x x x x x x x x x x Logical agents; FOL 18 Entailment in the wumpus world Situation after detecting nothing in [1,1], moving right, breeze in [2,1] ? ? B Consider possible models for ?s assuming only pits A A ? 3 Boolean choices ⇒ 8 possible models Logical agents; FOL 19 Wumpus models PIT 2 2 Breeze Breeze 1 1 PIT 1 1 2 2 3 3 2 PIT PIT 2 2 Breeze PIT 1 Breeze 1 Breeze 1 1 2 1 2 3 3 1 2 3 2 PIT PIT PIT 2 Breeze Breeze 1 1 PIT 2 PIT PIT 1 1 2 2 3 3 Breeze 1 1 2 PIT 3 Logical agents; FOL 20 Wumpus models PIT 2 2 Breeze Breeze 1 1 PIT 1 1 KB 2 2 3 3 2 PIT PIT 2 2 Breeze PIT 1 Breeze 1 Breeze 1 1 2 1 2 3 3 1 2 3 2 PIT PIT PIT 2 Breeze Breeze 1 1 PIT 2 PIT PIT 1 1 2 2 3 3 Breeze 1 1 2 PIT 3 KB = wumpus-world rules + observations Logical agents; FOL 21 Wumpus models PIT 2 2 Breeze Breeze 1 1 PIT 1 1 KB 2 2 3 3 1 2 PIT PIT 2 2 Breeze PIT 1 Breeze 1 Breeze 1 1 2 1 2 3 3 1 2 3 2 PIT PIT PIT 2 Breeze Breeze 1 1 PIT 2 PIT PIT 1 1 2 2 3 3 Breeze 1 1 2 PIT 3 KB = wumpus-world rules + observations α1 = “[1,2] is safe”, KB |= α1, proved by examining all models of KB Logical agents; FOL 22 Wumpus models PIT 2 2 Breeze Breeze 1 1 PIT 1 1 KB 2 2 3 3 2 PIT PIT 2 2 Breeze PIT 1 Breeze 1 Breeze 1 1 2 1 2 3 3 1 2 3 2 PIT PIT PIT 2 Breeze Breeze 1 1 PIT 2 PIT PIT 1 1 2 2 3 3 Breeze 1 1 2 PIT 3 KB = wumpus-world rules + observations Logical agents; FOL 23 Wumpus models PIT 2 2 Breeze Breeze 1 1 2 PIT 1 1 KB 2 2 3 3 2 PIT PIT 2 2 Breeze PIT 1 Breeze 1 Breeze 1 1 2 1 2 3 3 1 2 3 2 PIT PIT PIT 2 Breeze Breeze 1 1 PIT 2 PIT PIT 1 1 2 2 3 3 Breeze 1 1 2 PIT 3 KB = wumpus-world rules + observations α2 = “[2,2] is safe”, KB 6|= α2 Logical agents; FOL 24 Wumpus world sentences Let Pi,j be true if there is a pit in [i, j]. Let Bi,j be true if there is a breeze in [i, j]. ¬P1,1 ¬B1,1 B2,1 “Pits cause breezes in adjacent squares” Logical agents; FOL 25 Wumpus world sentences Let Pi,j be true if there is a pit in [i, j]. Let Bi,j be true if there is a breeze in [i, j]. ¬P1,1 ¬B1,1 B2,1 “Pits cause breezes in adjacent squares” B1,1 B2,1 ⇔ ⇔ (P1,2 ∨ P2,1) (P1,1 ∨ P2,2 ∨ P3,1) “A square is breezy if and only if there is an adjacent pit” Can reason about Wumpus world using truth tables (as for 2-queens) Logical agents; FOL 26 Pros and cons of propositional logic Propositional logic is declarative: pieces of syntax correspond to facts Propositional logic allows partial/disjunctive/negated information (unlike most data structures and databases) Propositional logic is compositional: meaning of B1,1 ∧ P1,2 is derived from meaning of B1,1 and of P1,2 Meaning in propositional logic is context-independent (unlike natural language, where meaning depends on context) Propositional logic has very limited expressive power (unlike natural language) E.g., cannot say “pits cause breezes in adjacent squares” except by writing one sentence for each square Logical agents; FOL 27
© Copyright 2026 Paperzz