Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Explorations in Artificial Intelligence Prof. Carla P. Gomes Module 3-1 Logic Based Reasoning.

Similar presentations


Presentation on theme: "1 Explorations in Artificial Intelligence Prof. Carla P. Gomes Module 3-1 Logic Based Reasoning."— Presentation transcript:

1 1 Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3-1 Logic Based Reasoning

2 Knowledge and Reasoning Knowledge and Reasoning  humans are very good at acquiring new information by combining raw knowledge, experience, with reasoning; Examples:  diagnosis –e.g., a physician diagnoses a patient, i.e., it infers what disease he/she has, based on the knowledge he/she acquired as a student, textbooks, prior cases and also some reasoning process (patterns of association, or other process) that he/she may not be able to describe.  car repair diagnosis  Common sense reasoning  Inventions, new ideas Key issues: Representation of knowledge Reasoning processes

3 Knowledge-base Agents Key issues: –Representation of knowledge  knowledge base –Reasoning processes  inference/reasoning mechanisms to query what is known, to derive new information, to make decisions. (*) called knowledge representation language Knowledge base = set of sentences in a formal language representing facts about the world(*)

4 Knowledge bases Key aspects: –How to add sentences to the knowledge base –How to query the knowledge base Both tasks may involve inference – i.e. how to derive new sentences from old sentences Logical agents – inference must obey the fundamental requirement that when one asks a question to the knowledge base, the answer should follow from what has been told to the knowledge base previously. (In other words the inference process should not “make things” up…)

5 Logic: Outline 1.General principles of logic – main vehicle for representing knowledge 2.Wumpus World - a toy world; how a knowledge based agent operates 3.Propositional logic 4.Predicate logic 5.Proof Methods 1.Inference Rules (including induction) 2.Model Checking Algorithmic approaches 6.Satisfiability as an Encoding language

6 Logic in general Logics are formal languages for formalizing reasoning, in particular for representing information such that conclusions can be drawn A logic involves: –A language with a syntax for specifying what is a legal expression in the language; syntax defines well formed sentences in the language –Semantics for associating elements of the language with elements of some subject matter. Semantics defines the "meaning" of sentences (link to the world); i.e., semantics defines the truth of a sentence with respect to each possible world –Inference rules for manipulating sentences in the language Original motivation: Early Greeks, settle arguments based on purely rigorous (symbolic/syntactic) reasoning starting from a given set of premises.

7 7 Example of a formal language: Arithmetic 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

8 8 Several systems – biological, mechanical, electric, etc --- can be represented by appropriate sets of “features” with constraints among the features encoding physical or other laws relevant to the organism or device; Reasoning can then be used among other purposes, to diagnose malfunctions in these systems; for example, features associated with “causes” can be inferred from features associated with “symptoms”. This general approach is key to an important class of AI applications. Language to Specify Systems as Constrained Featured Sets

9 9 Simple Robot Domain Consider a robot that is able to lift a block, if that block is liftable (i.e., not too heavy), and if the robot’s battery power is adequate. If both of these conditions are satisfied, then when the robot tries to lift a block it is holding, its arm moves. block Feature 1: BatIsOk (True or False) Feature 2: BlockLiftable (True or False) Feature 3: RobotMoves (True or False)

10 10 Simple Robot Domain (BatIsOk and BlockLiftable) implies RobotMoves block We need a language to express the features/properties/assertions and constraints among them; also inference mechanisms, i.e, principled ways of performing reasoning. Example logical statement about the robot:

11 11 Binary valued featured descriptions Consider the following description: –The router can send packets to the edge system only if it supports the new address space. For the router to support the new address space it is necessary that the latest software release be installed. The router can send packets to the edge system if the latest software release is installed. The router does not support the new address space. –Features: Router –Feature 1 – router can send packets to the edge of system –Feature 2 – router supports the new address space Latest software release –Feature 3 – latest software release is installed

12 12 Binary valued featured descriptions –Constraints: The router can send packets to the edge system only if it supports the new address space. (constraint between feature 1 and feature 2); It is necessary that the latest software release be installed for the router to support the new address space. (constraint between feature 2 and feature 3); The router can send packets to the edge system if the latest software release is installed. (constraint between feature 1 and feature 3); How can we write these specifications in a formal language and reason about the system?

13 13 Truth of Sentence vs. Satisfaction of Constraints Truth of a sentence vs. Satisfaction of Constraints - we can think of a logic sentence, e.g., an arithmetic sentence or a general logic sentence, as a constraint; the sentence is true if and only if the constraint is “satisfied”. We will talk more about “constraint languages”, particular kinds of logics, and constraint solving as a form of logical reasoning. Standard logics  every sentence must be either true or false in each possible world – there is no “in between”.

14 14 Sudoku: “A constraint language” 984263 439752 2315849 16273495 86153 5342671 316289 24983 8932

15 15 Sudoku: Solving Sudoku by logic inference 985426317 416397528 723158469 162734985 897615243 534289671 371562894 249873156 658941732

16 16 Logical Reasoning: Entailment Entailment means that one thing follows from another: KB ╞ α A Knowledge base KB entails sentence α iff (if and only if) α is true in all worlds where KB is true –E.g., the KB containing “Giants won” and “Reds won” entails “Either the Giants won or the Reds Won” –E.g., x+y = 4 entails 4 = x+y –Entailment is a relationship between sentences (i.e., syntax) that is based on semantics

17 17 Models Logicians typically think in terms of models, which are formally structured worlds with respect to which truth can be evaluated; Example: – x + y >= 7, is true in all the models in which x >= 7 - y, assuming that we are dealing with real numbers, in particular x = 7 and y = 0 or x = 8 and y = 1, etc ; –Basically, each model corresponds to a different assignment to the variables satisfying the constraints; note each assignment determines the truth or falsehood of the arithmetic sentence. We say m is a model of a sentence α if α is true in m M(α) is the set of all models of α (i.e., models that assign true to α ).

18 18 Models KB ╞ α iff M(KB)  M(α) –E.g. KB = Giants won and Reds won α = Giants won –Other ways of talking about entailment: KB ╞ α If α is true, then KB must be true; (Informally – the truth of α is contained in the truth of KB) We can think of a knowledge base as a statement and we talk about a knowledge base entailing a sentence.

19 19 2 - Wumpus World

20 20 Wumpus World Performance measure –gold +1000, –death -1000 (falling into a pit or being eaten by the wumpus) –-1 per step, -10 for using the arrow 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 Sensors: Stench, Breeze, Glitter, Bump, Scream Actuators: Left turn, Right turn, Forward, Grab, Release, Shootnnnnnnnn

21 21 Exploring a wumpus world Stench, Breeze, Glitter, Bump, Scream None, none, none, none, none The knowledge base of the agent consists of the rules of the Wumpus world plus the percept nothing in [1,1]

22 22 Exploring a wumpus world Stench, Breeze, Glitter, Bump, Scream None, none, none, none, none The knowledge base of the agent consists of the rules of the Wumpus world plus the percept nothing in [1,1]; by inference, the agent’s knowledge base also has the information that [2,1] and [1,2] are okay.

23 23 Exploring a wumpus world Stench, Breeze, Glitter, Bump, Scream None, none, none, none, none V A – Agent V – visited B - Breeze A/B P? Pit in (2,2) or (3,1) None, breeze, none, none, none

24 24 Exploring a wumpus world S S  Wumpus nearby Wumpus cannot be in (1,1) or in (2,2) (Why?)  Wumpus in (1,3) Not breeze in (1,2)  no pit in (2,2); but we know there is a pit in (2,2) or (3,1)  pit in (3,1) P? 1 2 3 4 1 2 3 4 S = (Stench, none, none, none, none) P W P

25 25 Exploring a wumpus world Difficult inference, because it combines knowledge gained at different times in difference places; the inference is beyond the abilities of most animals. A Assumption: the agent turns and go to square (2,3) ! In each case where the agent draws a conclusion from the available information, that conclusion is guaranteed to be correct if the initial information is correct - fundamental property of logical reasoning! How to build logical agents that can represent the necessary information and draw conclusions? none, none, none, none, none

26 26 Entailment in the wumpus world Situation after detecting nothing in [1,1], moving right, breeze in [2,1] Consider possible models for KB with respect to the cells (1,2), (2,2) and (3,1), with respect to the existence or non existence of pits 3 Boolean choices  8 possible models (enumerate all the models) Knowledge Base in the Wumpus World  Rules of the wumpus world + new percepts

27 27 Wumpus models KB = wumpus-world rules + observations Why is KB false in these models?

28 28 Wumpus models KB = wumpus-world rules + observations α 1 = "[1,2] has no pit", KB ╞ α 1, –In every model in which KB is true, α 1 is True (proved by model checking) Models of the KB and α1

29 29 Wumpus models KB = wumpus-world rules + observations α2 = "[2,2] has no pit", this is only True in some of the models for which KB is True, therefore KB ╞ α2 Inference algorithm used to reason about α 1 and α 2  Model Checking Models of the KB and α2

30 30 Inference: Model Checking Inference by Model checking – we enumerate all the KB models and check if α 1 and α 2 are True in all the models (which implies that we can only use it when we have a finite number of models).

31 31 Inference KB ├ i α we say sentence α can be derived from KB by procedure i Soundness (or Truth preservation): i is sound if whenever KB ├ i α, it is also true that KB╞ α; an unsound procedure can conclude statements that are not true. Completeness: i is complete if whenever KB╞ α, it is also true that KB ├ i α; a complete procedure is able to derive any sentence that is entailed. That is, the procedure will answer any question whose answer follows from what is known by the KB. Note: first-order logic which is expressive enough to say almost anything of interest, and for which there exists a sound and complete inference procedure.

32 32 Propositional Logic

33 33 Syntax: Elements of the language Primitive propositions --- statements like: Bob loves Alice Alice loves Bob Compound propositions Bob loves Alice and Alice loves Bob P Q Propositional Symbols (atomic propositions) P  Q (  - stands for and)

34 34 Connectives ¬ - not  - and  - or  - implies  - equivalent (if and only if)

35 35 Syntax of Well Formed Formulas (wffs) or sentences –Atomic sentences are wffs: Propositional symbol (atom); Example: P, Q, R, BlockIsRed; SeasonIsWinter; –Complex or compound wffs. Given w1 and w2 wffs: –  w1 (negation) –(w1  w2) (conjunction) –(w1  w2) (disjunction) –(w1  w2) (implication; w1 is the antecedent; w2 is the consequent) –(w1  w2) (biconditional) Syntax

36 36 P  Q (P  Q)  R P  Q  P (P  Q)  (  Q   P)   P P   this is not a wff. Examples of wffs Propositional logic: Examples Note1: atoms or negated atoms are called literals; examples p and  p are literals. P  Q is a “compound statement or proposition”. Note2: parentheses are important to ensure that the syntax is unambiguous. Quite often parentheses are omitted; The order of precedence in propositional logic is (from highest to lowest): , , , , 

37 37 Propositional Logic: Syntax vs. Semantics Semantics has to do with “meaning”:  it associates the elements of a logical language with the elements of a domain of discourse. Propositional Logic – we associate atoms with propositions / assertions about the world (therefore propositional logic).

38 38 Propositional Logic: Semantics Interpretation or Truth Assignment Assignment of truth values (True or False) to every proposition. So if for n atomic propositions, there are 2 n truth assignments or interpretations. This makes the representation powerful: the propositions implicitly capture 2 n possible states of the world.

39 Propositional Logic: Semantics Example: We might associate the atom (just a symbol!) BlockIsRed with the proposition: “The block is Red”, but we could also associate it with the proposition “The block is Black” even though this would be quite confusing… BlockIsRed has value True just in the case the block is red; otherwise BlockIsRed is False. (Aside: computers manipulate symbols. The string “BlockIsRed” does not “mean” anything to the computer. Meaning has to come from how to come from relations to other symbols and the “external world”. Hmm. How can a computer / robot obtain the meaning ``The block is Red’’? The fact that computers only “push around symbols” led to quite a bit of confusion in the early days or Artificial Intelligence, Robotics, and natural language understanding. Which ones are propositions? – Cornell University is in Ithaca NY –1 + 1 = 2 –what time is it? –2 + 3 = 10 –watch your step!

40 40 Propositional Logic: Semantics Truth table for connectives Given the values of atoms under some interpretation, we can use a truth table to compute the value for any wff under that same interpretation; the truth table establishes the semantics (meaning) of the propositional connectives. We can use the truth table to compute the value of any wff given the values of the constituent atom in the wff. Note: In table, P and Q can be compound propositions themselves. Note: implication not necessarily aligned with English usage. 

41 41 This is only False (violated) when q is False and p is True. Related implications: –Converse: q  p; –Contra-positive:  q   p; –Inverse  p   q; Important: only the contra-positive of p  q is equivalent to p  q (i.e., has the same truth values in all models); the converse and the inverse are equivalent; Implication (p  q)

42 42 Implication plays an important role in reasoning a variety of terminology is used to refer to implication: conditional statement if p then q if p, q p is sufficient for q q if p q when p a necessary condition for p is q (*) p implies q p only if q (*) a sufficient condition for q is p q whenever p q is necessary for p (*) q follows from p (*) assuming the statement true, for p to be true, q has to be true Note: the mathematical concept of implication is independent of a cause and effect relationship between the hypothesis (p) and the conclusion (q), that is normally present when we use implication in English. Note: Focus on the case, when is the statement False. I.e., p is True and q is False, should be the only case that makes the statement false. Implication (p  q)

43 43 Variety of terminology : Note: the if and only if construction used in biconditionals is rarely used in common language; Example: “if you finish your meal, then you can play;” what is really meant is: “If you finish your meal, then you can play” and ”You can play, only if you finish your meal”. p is necessary and sufficient for q if p then q, and conversely p if and only if q p iff q p  q is equivalent to (p  q)  (q  p) Propositional Logic: Semantics Notes: Bi-conditionals (p  q)

44 44 Exclusive Or Truth Table PQP  Q _____________ TT F TF T F T T FF F P  Q is equivalent to (P  ¬Q)  (¬P  Q) and also equivalent to ¬ (P  Q) Use a truth table to check these equivalences.

45 45 Propositional Logic: Satisfiability and Models Satisfiability and Models An interpretation or truth assignment satisfies a wff, if the wff is assigned the value True, under that interpretation. An interpretation that satisfies a wff is called a model of that wff. Given an interpretation (i.e., the truth values for the n atoms) the one can use the truth table to find the value of any wff.

46 46 The truth table method (Propositional) logic has a “truth compositional semantics”: Meaning is built up from the meaning of its primitive parts (just like English text).

47 47 It is possible that no interpretation satisifies a set of wffs  In that case we say that the set of wffs is inconsistent or unsatisfiable or a contradiction Examples: 1 – {P   P} 2 – { P  Q, P  Q,  P  Q,  P  Q} (use the truth table to confirm that this set of wffs is inconsistent) Propositional Logic: Inconsistency (Unsatisfiability) and Validity Inconsistent or Unsatisfiable set of Wffs Validity (Tautology) of a set of Wffs If a wff is True under all the interpretations of its constituents atoms, we say that the wff is valid or it is a tautology. Examples: 1- P  P; 2 -  (P   P); 3 - [P  (Q  P)]; 4- [(P  Q)  P)  P]

48 48 Logical equivalence Two sentences p an q are logically equivalent (  or  ) iff p  q is a tautology (and therefore p and q have the same truth value for all truth assignments) Note: logical equivalence (or iff) allows us to make statements about PL, pretty much like we use = in in ordinary mathematics.    

49 49 Truth Tables Truth table for connectives We can use the truth table to compute the value of any wff given the values of the constituent atom in the wff. Example: Suppose P and Q are False and R has value True. Given this interpretation, what is the truth value of [( P  Q)  R ]  P? If a system is described using n features (corresponding to propositions), and these features are represented by a corresponding set of n atoms, then there are 2 n different ways the system can be. Why? Each of the ways the system can be corresponds to an interpretation. Therefore there are, i.e., 2 n interpretations. False

50 50 Example: Binary valued featured descriptions Consider the following description: –The router can send packets to the edge system only if it supports the new address space. For the router to support the new address space it is necessary that the latest software release be installed. The router can send packets to the edge system if the latest software release is installed. The router does not support the new address space. –Features: Router –P - router can send packets to the edge of system –Q - router supports the new address space Latest software release –R – latest software release is installed

51 Formal: The router can send packets to the edge system only if it supports the new address space. (constraint between feature 1 and feature 2) –If Feature 1 (P) (router can send packets to the edge of system) then P  Q Feature 2 (Q) (router supports the new address space ) For the router to support the new address space it is necessary that the latest software release be installed. (constraint between feature 2 and feature 3); –If Feature 2 (Q) ( router supports the new address space ) then Feature 3 (R) (latest software release is installed) Q  R The router can send packets to the edge system if the latest software release is installed. (constraint between feature 1 and feature 3); If Feature 3 (R) (latest software release is installed) then Feature 1 (P) (router can send packets to the edge of system ) R  P The router does not support the new address space. ¬ Q

52 52 Inference

53 53 Entailment in the wumpus world Situation after detecting nothing in [1,1], moving right, breeze in [2,1] Consider possible models for KB with respect to the cells (1,2), (2,2) and (3,1), with respect to the existence or non existence of pits 3 Boolean choices  8 possible models (enumerate all the models) Knowledge Base in the Wumpus World  Rules of the wumpus world + new percepts

54 54 Wumpus world sentences Let P i,j be true if there is a pit in [i, j]. Let B i,j be true if there is a breeze in [i, j]. Sentence 1 (R1):  P 1,1 Sentence 2 (R2):  B 1,1 Sentence 3 (R3): B 2,1 "Pits cause breezes in adjacent squares" Sentence 4 (R4): B 1,1  (P 1,2  P 2,1 ) Sentence 5 (R5): B 2,1  (P 1,1  P 2,2  P 3,1 )

55 55 Inference by enumeration The goal of logical inference is to decide whether KB╞ α, for some sentence . For example, given the rules of the Wumpus World is P 22 entailed? Relevant propositional symbols: R1:  P 1,1 R2:  B 1,1 R3: B 2,1 "Pits cause breezes in adjacent squares" R4: B 1,1  (P 1,2  P 2,1 ) R5: B 2,1  (P 1,1  P 2,2  P 3,1 ) Inference by enumeration  we have 7 symbols therefore 2 7 models;

56 56 Propositional logic: Wumpus World Each model specifies true/false for each proposition symbol E.g. P 1,2 P 2,2 P 3,1 falsetruefalse With these symbols, 8 interpretations, can be enumerated automatically. P12  P22  P31 P12  P22   P31 P12   P22  P31 etc

57 57 Is P12 Entailed from KB? Is P22 Entailed from KB? Given R1, R2, R3, R4, R5 P11P12P21 P22 P31B11B21 R1:  P11R2:  B11 R3:B21 R4:  B11  (P12  P21) R5:B21  P11  P22  P31 KB False True False True False True False True False True False True False True False True Consider all possible truth assignments to P12, P22, P31, and check which assignments lead to models for the KB; then check if P12 and P22 is true in all the models

58 58 Is P12 Entailed from KB? Is P22 Entailed from KB? Given R1, R2, R3, R4, R5 P11P12P21 P22 P31B11B21 R1:  P11R2:  B11 R3:B21 R4:  B11  (P12  P21) R5:B21  P11  P22  P31 KB False True False TrueFalseTrue False TrueFalse True FalseTrueFalse True False True FalseTrue FalseTrueFalseTrueFalse True False TrueFalse TrueFalseTrue FalseTrueFalse TrueFalseTrue FalseTrue FalseTrueFalse There are only 3 models for the KB: i.e., for which R1, R2, R3, R4, R5 are True; In all of them P12 is false, so there is not pit in [1,2] – the KB entails  P12; on the other hand P22 is true in two of the three models and false in the other one – so at this point we cannot tell whether P22 is true or not.

59 59 Inference by enumeration TT – Truth Table; PL-True returns true if a sentence holds within a model; Model – represents a partial model – an assignment to some of the variables; EXTEND(P,true,model) – returns a partial model in which P has the value True; TT-Entails – Truth Table enumeration algorithm for deciding propositional entailment; Processed all symbols

60 60 Models KB ╞ α iff M(KB)  M(α) Note: The empty set or null set ( Ø ) is a subset of every set. An inconsistent KB entails every possible sentence.

61 61 Inference by enumeration This is a recursive enumeration of a finite space of assignments to variables; depth-first algorithm: it enumerates all models and checks if the sentence is true in all the models;  sound  complete; For n symbols, time complexity is O(2 n ), space complexity is O(n). Worst-case complexity is exponential for any algorithm. But in practice we can do better. More later… TT-Entails – Truth Table enumeration algorithm for deciding propositional entailment;

62 62 Validity and Satisfiability A sentence is valid (or is a tautology) if it is true in all interpretations, e.g., True,A  A, A  A, (A  (A  B))  B Validity is connected to inference via the Deduction Theorem: KB ╞ α if and only if (KB  α) is valid A sentence is satisfiable if it is true in some model e.g., A  B, C A sentence is unsatisfiable if it is true in no models e.g., A  A Satisfiability is connected to inference via the following: KB ╞ α if and only if (KB  α) is unsatisfiable (Reductio ad absurdum; Proof by refutation or Proof by contradiction)


Download ppt "1 Explorations in Artificial Intelligence Prof. Carla P. Gomes Module 3-1 Logic Based Reasoning."

Similar presentations


Ads by Google