290 likes | 565 Views
Logic. Introduction to Artificial Intelligence CS440/ECE448 Lecture 9 SECOND HOMEWORK DUE MONDAY. Last lecture. Nondeterministic games Logic The Wumpus world Entailment Today Logic Entailment and inference Propositional logic: Syntax and semantics Inference rules Reading
E N D
Logic Introduction to Artificial Intelligence CS440/ECE448 Lecture 9 SECOND HOMEWORK DUE MONDAY
Last lecture • Nondeterministic games • Logic • The Wumpus world • Entailment Today • Logic • Entailment and inference • Propositional logic: Syntax and semantics • Inference rules Reading • Chapters 7 and 8
Minimax for nondeterministic games • For min node, compute min of children. • For chance node, compute weighted average of children. • For max node, compute max of children. 3
Function MINIMAX-VALUE (state, game) returns a utility value If TERMINAL-TEST[game](state) then return UTILITY[game](state) else if MAX is to move in state then return the highest MINIMAX-VALUE of Successors[state] else return the lowest MINIMAX-VALUE of Successors[state] Function EXPECTIMINIMAX-VALUE (state, game) returns a utility value If TERMINAL-TEST[game](state) then return UTILITY[game](state) else ifstate is a chance node then return average of EXPECTIMINMAX-VALUE of Successors(state) else if MAX is to move in state then return the highest EXPECTIMINIMAX-VALUE of Successors[state] else return the lowest EXPECTIMINIMAX-VALUE of Successors[state]
Knowledge bases Inference Engine Knowledge Base Domain-independent knowledge 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 • Alternative is a learning approach, but we will do that later. • Answers should follow from the KB. • Agents or systems 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.
Goals: Get gold back to the start without entering it or wumpus square. Percepts: Breeze, Glitter, Smell. Actions: Left turn, Right turn, Forward, Grab, Release, Shoot. Environment Squares adjacent to wumpus are smelly. Squares adjacent to pit are breezy. Glitter if and only if gold is in the same square. Shooting kills the wumpus if you are facing it. Shooting uses up the only arrow. Grabbing picks up the gold if in the same square. Releasing drops the gold in the same square. The Wumpus World
Logic in general • Logicsare 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. • For example, the language of arithmetic • x + 2 y is a sentence. • x + y > is not a sentence. • x + 2 yis true iff the number x+2 is no less than the number y. • x + 2 yis true in a world where x = 7, y =1. • x + 2 y is false in a world where x = 0, y= 6.
Types of logic • Logics are characterized by what they commit to as ``primitives'' • Ontological commitment: what exists - facts? objects? time? beliefs? • Epistemological commitment: what states of knowledge?
Entail Sentences KB Semantics Follows Facts Facts Entailment Sentences Logical Representation Semantics World A knowledge base is a collection of sentences. An entailed sentence is true, given that the old sentences in the knowledge base are true.
Potential models of the Wumpus world A model is an instance of the world. A model of a set of sentences is an instance of the world where these sentences are true.
Inference • A knowledge base is a collection of sentences. • Knowledge base KB entails sentence if and only if is true whenever KB is true (i.e. all sentences in KB are true). • An inference procedure i can do two things: • Given KB, generate new sentence purported to be entailed by KB. • Given KB and , report whether or not is entailed by KB. • A sound inference procedure only produces entailed sentences. • Every entailed sentence can be generated by a complete inference procedure.
Propositional logic: Syntax • Propositional logic is the simplest logic. • Logical constants TRUE and FALSE are sentences. • Proposition symbols P1, P2 etc. are sentences. • Symbols P1 and negated symbols P1 are called literals. • If S is a sentence, S is a sentence (NOT). • If S1 and S2 is a sentence, S1 S2 is a sentence (AND). • If S1 and S2 is a sentence, S1 S2 is a sentence (OR). • If S1 and S2 is a sentence, S1 S2 is a sentence (Implies). • If S1 and S2 is a sentence, S1 S2 is a sentence (Equivalent).
Order of Precedence From highest to lowest: parenthesis ( Sentence ) NOT AND OR Implies Equivalent
Model of P Q Propositional logic: Semantics Most sentences are sometimes true. P Q Some sentences are always true (valid). P P Some sentences are never true (unsatisfiable). P P
Propositional logic: Semantics Implication: P Q “If P is True, then Q is true; otherwise I’m making no claims about the truth of Q.” (Or: P Q is equivalent to Q) Under this definition, the following statement is true Pigs_fly Everyone_gets_an_A Since “Pigs_Fly” is false, the statement is true irrespective of the truth of “Everyone_gets_an_A”. [Or is it? Correct inference only when “Pigs_Fly” is known to be false.]
Propositional Inference: Enumeration Method • Let and KB = ( C) B C) • Is it the case that KB ? • Check all possible models -- must be true whenever KB is true
Propositional Inference: Enumeration Method • Let and KB = ( C) B C) • Is it the case that KB ? • Check all possible models -- must be true whenever KB is true
KB Propositional Inference: Enumeration Method • Let and KB = ( C) B C) • Is it the case that KB ? • Check all possible models -- must be true whenever KB is true
Propositional Logic: Proof methods • Model checking • Truth table enumeration (sound and complete for propositional logic). • Application of inference rules • Legitimate (sound) generation of new sentences from old. • Proof = a sequence of inference rule applications. Can use inference rules as operators in a standard search algorithm.
Inference rules An inference rule is sound if the conclusion is true in all cases where the premises are true. Premise _____ Conclusion
An Inference Rule: Modus Ponens • From an implication and the premise of the implication, you can infer the conclusion. Premise ___________ Conclusion • An inference rule is sound if the conclusion is true in all cases where the premises are true.
An Inference Rule: And - Elimination • From a conjunction, you can infer any of the conjuncts. 1 2 … n Premise _______________ i Conclusion • An inference rule is sound if the conclusion is true in all cases where the premises are true.
And-Introduction & Double Negation • And-Introduction 1, 2, …, n Premise _______________ 1 2 … n Conclusion • Double Negation Premise _______ Conclusion
Knowledge Base in Wumpus World Percept Sentences S1,1 B1,1 S2,1 B2,1 S1,2 B1,2 … Environment Knowledge (can be written before any sensing) R1: S1,1 W1,1 W2,1 W1,2 R2: S2,1 W1,1 W2,1 W2,2 W3,1 R3: B1,1 P1,1 P2,1 P1,2 R4: B2,1 P1,1 P2,1 P2,2 P3,1 R5: B1,2 P1,1 P1,2 P2,2 P1,3 ... Si,j: Stench in cell i,j Bi,j: Breeze in cell i,j Wi,j: Wumpus in cell i,j
Inference in Wumpus World Some inferences: Apply Modus Ponens to R1 Add to KB W1,1 W2,1 W1,2 Apply to this AND-Elimination Add to KB W1,1 W2,1 W1,2 Initial KB Percept Sentences S1,1 B1,1 S2,1 B2,1 S1,2 B1,2 … Environment Knowledge R1: S1,1 W1,1 W2,1 W1,2 R2: S2,1 W1,1 W2,1 W2,2 W3,1 R3: B1,1 P1,1 P2,1 P1,2 R4: B2,1 P1,1 P2,1 P2,2 P3,1 R5: B1,2 P1,1 P1,2 P2,2 P1,3 ...
Summary of Propositional Logic • Logical agents apply inference to a knowledge base to derive new information and make decisions. • Basic concepts of logic: • Syntax: formal structure of sentences. • Semantics: truth of sentences wrt models. • Entailment: necessary truth of one sentence given another. • Inference: deriving sentences from other sentences. • Soundess: derivations produce only entailed sentences. • Completeness: derivations can produce all entailed sentences. • Truth table method is sound and complete for propositional logic. • Cumbersome in Wumpus world.