Lecture 20 Reminders: Project 2 and research paper outline with references due today. Posted: Homework 4, due in two weeks Questions? Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 1 Outline Chapter 7 – Logical Agents Agents Based on Propositional Logic Chapter 8 – First-Order Logic Representation Revisited Syntax and Semantics Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 2 Recall: Knowledge-Based Agents Simple KB-Agent: Receives: percept; Returns: action Static data: KB – knowledge base t – time counter initially 0 1. Tell (KB, Make-Percept-Sentence (percept, t)) 2. action = Ask (KB, Make-Action-Query (t)) 3. Tell (KB, Make-Action-Sentence (action, t)) 4. Increment t 5. Return action Thursday, March 15 CS 430 Artificial Intelligence - Lecture 18 3 Current State of WW A logical agent operates by deducing what to do from a KB of sentences about the world. In particular, need to deduce the current state of the world – where am I, is that square safe, etc. Previously, started collecting axioms. Starting square has no pit (P1,1) and no wumpus (W1,1). Collection of sentences about breezy and smelly squares of the form: B1,1 P1,2 P2,1 Thursday, March 22 S1,1 W1,2 W2,1 CS 430 Artificial Intelligence - Lecture 20 4 Current State of WW Exactly one wumpus: At least one wumpus: W1,1 W1,2 … W4,3 W4,4 For every pair of squares, at least one of them must be wumpus-free: W1,1 W1,2 W1,1 W1,3 … W4,3 W4,4 Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 5 Current State of WW How are percepts translated into sentences? Suppose currently there is a stench. Might propose proposition Stench be added to KB. But this may contradict previous step where there was no stench asserting Stench. Problem is that a percept asserts something only about the current time. This is why MakePercept-Sentence receives both percept and a time. E.g., if t=4 above, adds Stench4, which does not contradict previous step that added Stench3 Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 6 Fluents Aspects of the world that changes are called fluents and require a time superscript. Can think of them as state variables. Aspects of the world that are permanent do not need a time superscript and are called atemporal variables. Initial location of agent is L01,1– agent is in [1,1] at time 0 – and FacingEast 0, HaveArrow 0, and 0 WumpusAlive . Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 7 Fluents Connect the percepts directly to properties of squares where they are experienced through the location fluent. For any time step t and any square [x,y]: Ltx,y (Breeze t Bx,y) Ltx,y (Stench t Sx,y) Now need to keep track of fluents by writing the transition model as a set of logical sentences. Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 8 Effect Axioms Define proposition symbols for the occurrence of actions. E.g., Forward 0 means agent executes Forward action at time 0. To describe how world changes, define effect axioms that specify the outcome of an action in the next time step. E.g., if agent is at [1,1] facing east at time 0 and goes Forward, the result is that agent is in [2,1] and no longer in [1,1] L01,1 FacingEast0 Forward0 (L12,1 L11,1) Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 9 Frame Problem Works as far as it goes, but what if we want to know if the agent has an arrow in time t=1? 1 Cannot prove or disprove HasArrow ! Effect axiom does not state what has not changed between time steps. Called the frame problem. One possible solution is to add frame axioms: Forward t (HaveArrow t HaveArrow t+1) Forward t (WumpusAlive t WumpusAlive t+1) Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 10 Frame Problem Proliferation of frame axioms is inefficient. For m different actions and n fluents, the set of frame axioms is O(mn). Fortunately, each action typically changes only a small number k fluents, i.e., the world exhibits locality. Want to define transition model with set of axioms of size O(mk). Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 11 Fluent Axioms Solution is to write axioms about fluents rather than about actions. For each fluent F, have an t+1 axiom that defines value of F in terms of fluents at time t and actions that may have occurred at time t. t+1 Truth value of F is set either because action at t caused it to become true, or it was already true and the action at t does not cause it to become false: F t+1 ActionCausesF t (F t ActionCausesNotF t) Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 12 Fluent Axioms Axiom of this form is called a successor-state axiom. Simple example is for HaveArrow, since once it is shot, arrow disappears: HaveArrow t+1 (HaveArrow t Shoot t) Location fluent is more complex: Lt+11,1 (Lt1,1 (Forward t Bump t+1 )) (Lt1,2 (South t Forward t )) (Lt2,1 (West t Forward t )) Relevant fluent axioms are added at each time step. Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 13 Hybrid Agent Logical deduction can be combined with problem-solving algorithms in a fairly straightforward manner to create a hybrid agent (Fig. 7.20). Propositional knowledge is used to infer the state of the world, domain specific code is used to determine what kind of plan to make, problem-solving search is used to create plan of actions. Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 14 Representation Revisited Propositional logic has many advantages as a representation for knowledge. It is declarative. Its syntax corresponds to facts and inference is separate and domain-independent It allows partial, disjunctive, and negated information unlike programming languages. It is compositional. The meaning of B1,1 P1,2 is derived from the meanings of B1,1 and P1,2. It is context independent and unambiguous unlike natural languages. Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 15 Representation Revisited Main problem with propositional logic is that it is not expressive enough. E.g., "physics" of WW must be input as a sentence per square for Breeze and Smell. Add representational ideas from natural language: Objects: nouns and noun phrases Relations: verb and verb phrases Functions: relations that specify a particular "value" for a given "input" Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 16 First-Order Logic: Models First-order logic (FOL) is built around objects and relations. It can also express facts about some or all of the objects in the universe. An FOL model contains objects. The domain of a model is the set of object (domain elements) it contains. The domain is required to be nonempty, i.e., every possible world must contain at least one object. Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 17 First-Order Logic: Models Example model with five objects: Richard the Lionhearted King John Crown Richard the Lionheart's left leg King John's left leg Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 18 Relations Object in a model may be related in some way. Formally, a relation is a set of tuples of objects that are related. Previous picture indicates that Richard is the brother of John. The "brother" relation is { < Richard the Lionhearted, King John >, < King John, Richard the Lionhearted > } The crown is on John's head, so the "on head" relation is { < The Crown, King John > } Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 19 Relations "brother" and "on head" are binary relations. Model also has unary relations (or properties). E.g., "person" property is true of both Richard the Lionhearted and King John. "king" property is true only of King John. "crown" property is true only of the The Crown. Some relations are best considered as functions – a given object must be related to exactly one object in this way. E.g., each person has one left leg. Model has a "left leg" function. Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 20 Symbols and Interpretations FOL has three kinds of symbols constant symbols representing objects, e.g., Richard, John, TheCrown predicate symbols representing relations, e.g., Brother, OnHead, Person, King, Crown function symbols representing functions, e.g., LeftLeg By convention, these symbols start with uppercase letter Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 21 Symbols and Interpretations Each model includes an interpretation that specifies exactly which objects, relations and functions are referred to by the constant, predicate, and function symbols. Usually use the intended interpretation, e.g., John refers to King John, etc., but model may have a different interpretation. Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 22 Terms A term is a logical expression that refers to an object. A constant symbol is a term, but it is not convenient to a constant symbol to name every objects. A function symbol followed by an "argument" list is a term. E.g. LeftLeg(John) refers to King John's left leg under the intended interpretation, but this object has no other name. Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 23 Atomic Sentences An atomic sentence (or atom for short) is formed from a predicate symbol optionally followed by a list of terms as "arguments". E.g., Brother (Richard, John). Atoms can have complex terms as arguments. E.g. Married (Father(Richard), Mother(John)) An atomic sentence is true in a given model if the relation referred to by the predicate symbol holds among the objects referred to by the arguments. Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 24 Complex Sentences Can construct more complex sentences by using logical connectives. These have the same syntax and semantics as in propositional logic. Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 25 Universal Quantification () "For all" Express properties of entire collections objects using quantifiers. Universal quantification makes statements about every object. E.g., x King(x) Person(x) "If x is a king, x is a person" x is a variable, by convention starting with lowercase, and is a term all by itself. Can use as an argument to a function. E.g. LeftLeg(x). A term with no variables is a ground term. Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 26 Universal Quantification () "For all" Intuitively, x P(x) means that P is true for every object x. More precisely, x P(x) is true in a given model if P is true in all possible extended interpretations constructed from the interpretation given in the model, where each extended interpretation specifies a domain element to which x refers. Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 27 Universal Quantification () "For all" E.g., x can be 5 possible objects, so equivalent is asserting following sentences are true: King(Richard) Person(Richard) King(John) Person(John) King(LeftLeg(Richard)) Person(LeftLeg(Richard)) King(LeftLeg(John)) Person(LeftLeg(John)) King(TheCrown) Person(TheCrown) Second one is true since both sides are true. Rest are vacuously true with false premises. Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 28 Universal Quantification () "For all" Common mistake is to use conjunction instead of implication: x King(x) Person(x) King(Richard) Person(Richard) King(John) Person(John) King(LeftLeg(Richard)) Person(LeftLeg(Richard)) King(LeftLeg(John)) Person(LeftLeg(John)) King(TheCrown) Person(TheCrown) Says that every object is a King and a Person. Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 29 Existential Quantification () "There exists" Existential quantification makes a statement about some object in the universe without naming it. E.g., x Crown(x) OnHead(x, John) "King John has a crown on his head" Intuitively, x P says P is true for at least one object x. More precisely, P is true in at least one extended interpretation that assigns x to a domain element. Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 30 Existential Quantification () "There exists" E.g. one of the following sentences must be true Crown(Richard) OnHead(Richard, John) Crown(John) OnHead(John, John) Crown(LeftLeg(Richard)) OnHead(LeftLeg(Richard), John) Crown(LeftLeg(John)) OnHead(LeftLeg(John), John) Crown(TheCrown) OnHead(TheCrown, John) The last sentence is true in this model, so the original existentially quantified sentence is true in this model. Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 31 Existential Quantification () "There exists" The natural connective to use with is . Using with leads to an overly strong statement; using with leads to a very weak statement. Consider: x Crown(x) OnHead(x, John) Crown(Richard) OnHead(Richard, John) Crown(John) OnHead(John, John) … Existentially quantified implications are true whenever any object fails to satisfy the premise, so not very interesting. Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 32 Nested Quantifiers Consecutive quantifiers of the same type can be written as one quantifier with several variables. Order matters for quantifiers of different type x, y Brother(x,y) Sibling(x,y) x y Loves(x,y) "Everybody loves somebody" y x Loves(x,y) "Someone is loved by everyone" Variables bind to the innermost quantifier that uses it x (Crown(x) (x Brother(Richard, x))) Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 33 Connections between and is a conjunction of all extended interpretations, while is a disjunction of all extended interpretations, so DeMorgan's rule applies x P x P x P x P x P x P x P x P Thursday, March 22 Example: x Likes(x, IceCream) x Likes(x, IceCream) CS 430 Artificial Intelligence - Lecture 20 34 Equality Last type of atomic sentence uses the equality symbol to signify that two terms refer to the same object. Father(John) = Henry Also used with negation to insist that two terms are not the same object. E.g. "Richard has at least two brothers" x,y Brother(x,Richard) Brother(y,Richard) (x=y) Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 35 Using First-Order Logic Sentences, called assertions, are added to a KB using Tell as in propositional logic. Questions, called queries or goals, are made using Ask. When query has a variable, would like to know what values make query sentence true. E.g. AskVars(KB, Person(x)) Response is a substitution or binding list { x/John }, { x/Richard } Thursday, March 22 CS 430 Artificial Intelligence - Lecture 20 36