125
Explorations in Artificial Intelligence Prof. Carla P. Gomes [email protected] Module 3 Logic Representations

Explorations in Artificial Intelligence Prof. Carla P. Gomes [email protected] Module 3 Logic Representations

Embed Size (px)

Citation preview

Page 1: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Explorations in Artificial Intelligence

Prof. Carla P. [email protected]

Module 3Logic Representations

Page 2: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Logical Agents

Agents that are able to:

– Form representations of the world

– Use a process to derive new representations of the world inference of new

– Use these new representations to deduce what to do

Page 3: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Knowledge-based Agents

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 knowledgeReasoning processes

Page 4: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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(*)

Page 5: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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…)

Page 6: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Outline

1. General principles of logic – main vehicle for representing knowledge2. Wumpus World - a toy world; how a knowledge based agent operates3. Propositional logic4. Predicate logic

5. Satisfiability as an Encoding language

6. NP-Completeness

– Worst case vs. practice

Page 7: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

1 - Logic in General

Page 8: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Logic in general

Logics are formal languages 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

Page 9: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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

Page 10: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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.

Systems as Constrained Featured Sets

Page 11: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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 (0 or 1 or True or False)Feature 2 BlockLiftable (0 or 1 or True or False)Feature 3 RobotMoves (0 or 1 or True or False)

Page 12: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Simple Robot Domain

Feature 1 BatIsOk (0 or 1)Feature 2 BlockLiftable (0 or 1)Feature 3 RobotMoves (0 or 1)

BatIsOk and BlockLiftable implies RobotMOves

block

We need a language to express the values of features and constraints among features; also inference mechanisms, i.e,principled ways of performing reasoning.

Page 13: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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

Page 14: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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);

• 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);

• 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?

Page 15: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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”.

Page 16: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Sudoku

9 8 4 2 6 3

4 3 9 7 5 2

2 3 1 5 8 4 9

1 6 2 7 3 4 9 5

8 6 1 5 3

5 3 4 2 6 7 1

3 1 6 2 8 9

2 4 9 8 3

8 9 3 2

Page 17: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Sudoku

9 8 5 4 2 6 3 1 7

4 1 6 3 9 7 5 2 8

7 2 3 1 5 8 4 6 9

1 6 2 7 3 4 9 8 5

8 9 7 6 1 5 2 4 3

5 3 4 2 8 9 6 7 1

3 7 1 5 6 2 8 9 4

2 4 9 8 7 3 1 5 6

6 5 8 9 4 1 7 3 2

Page 18: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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

Page 19: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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 of numbers to the

variables x and y, satisfying the conctrints; 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 α ).

Page 20: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Models

KB ╞ α iff M(KB) M(α)

– E.g. KB = Giants won and Redswon α = 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.

Page 21: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

2 - Wumpus World

Page 22: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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, ScreamActuators: Left turn, Right turn, Forward, Grab, Release, Shootnnnnnnnn

Page 23: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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]

Page 24: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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 hasthe information that [2,1] and [1,2]are okay.

Page 25: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Exploring a wumpus world

Stench, Breeze, Glitter, Bump, Scream

None, none, none, none, none

V

A – AgentV – visitedB - Breeze

A/B P?

P?

Pit in (2,2) or (3,1)

None, breeze, none, none, none

Page 26: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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?

P?

1 2 3 4

1

2

3

4

S = (Stench, none, none, none, none)

P

W

P

Page 27: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Exploring a wumpus world

Difficult inference, because it combinesknowledge gained at different times indifference places; the inference is beyondthe 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 informationand draw conclusions?

none, none, none, none, none

Page 28: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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

Page 29: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Wumpus models

KB = wumpus-world rules + observations

Why is KB falsein these models?

Page 30: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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

Page 31: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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

Page 32: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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).

Page 33: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Inference

KB ├i α = 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.

Page 34: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

3 - Propositional Logic

Page 35: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Syntax

Atoms:– Truth Symbols: True and False;– Propositional Symbols – (Strings of characters that begin with a capital letter: P, Q, R,…, P1, P2, ColorOfBlock,

etc)

Connectives: (negation) (and) (or) (implication) (biconditional)

Elements of the Language

Page 36: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Syntax of Well Formed Formulas (wffs) or sentences

– Atomic sentences are wffs: True, False, and propositional symbol;Example: True; False; P, 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

Page 37: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

– P Q

– (P Q) R

– P Q P

– (P Q) (Q P) P

– P this is not a wff.

P

Examples of wffs

Propositional logic: Examples

Note1: atoms or negated atoms are called literals; examples p and p are literals.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): ,, , ,

Page 38: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Syntax

While an inference process operates on “syntax” --- internal physical configurations such as bits in registers or patterns of electrical blips in brains --- the process corresponds to the real-world via semantics –the process of assigning truth or falsehood to every sentence in a possible world;

Page 39: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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 about the world (therefore propositional logic);

Page 40: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Propositional Logic:Semantics

Interpretation –

Association of atoms with propositions about the world;

Association of truth values to atoms: The truth value of a proposition is true, if it is a true proposition in the domain of discourse and false, if it is a false proposition in the domain of discourse;

Denotation of an atom -- the proposition associated with an atom in a given interpretation;

Page 41: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Propositional Logic:Semantics

Example:We might associate the atom 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.

Which ones are propositions?

– Cornell University is in Ithaca NY;– 1 + 1 = 2;– what time is it?– 2 + 3 = 10;– watch your step!

Page 42: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Propositional logic: Semantics

Rules for evaluating truth with respect to a model m:S is true iff S is false S1 S2 is true iff S1 is true and S2 is trueS1 S2 is true iff S1is true or S2 is trueS1 S2 is true iff S1 is false or S2 is true i.e., is false iff S1 is true and S2 is falseS1 S2 is true iff S1S2 is true and S2S1 is true

Simple recursive process evaluates an arbitrary sentence, e.g.,

P1,2 (P2,2 P3,1) = true (true false) = true true = true

Page 43: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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 atomin the wff.

Page 44: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Related implications:

Given p q

– Converse: q p;– Contra-positive: q p; – Inverse p q;

(*) assuming the statement true, for p to be true, q has to be true

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)

Page 45: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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 that the mathematical concept of implication is independent of a cause and effect relationship between the hypothesis (p) and the conclusion (q), that is normallypresent when we use implication in English;

Implication (p q)

Page 46: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Variety of terminology :

(*) assuming the statement true, for p to be true, q has to be true

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)

Page 47: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Logical equivalence

Two sentences are logically equivalent if they have the same truth value in all the interpretations, i.e., α ≡ ß iff α╞ β and β╞ α

Note: logical equivalence (or iff) allows us to make statements about PL, pretty much like we use = in in ordinary mathematics.

Page 48: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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 atomin 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 an agent describes its world using n features (corresponding to propositions), and these featuresare represented in the agent’s model of the world by a corresponding set of n atoms, then there are2n different ways its world can be. Why? Each of the ways the world can be corresponds to an interpretation. Therefore there are , i.e., 2n interpretations.

Given an interpretation (i.e., the truth values for the n atoms) the agent can use the truth table tofind the values of any wffs.

Page 49: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Example: Knowledge Base forSystems of Specifications

Translating sentences in natural language (e.g., English) into logical expressions is an essential part of specifying hardware and software systems.

Example:– The automated reply cannot be sent when the file system is full;

• p – the automated reply can be sent;

• q – the file system is full;

– q p

The KB with the system specifications should not contain conflicting requirements; i.e., the KB should be consistent: there must be at least a model that makes the system true.

Page 50: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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

Page 51: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Example: 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);

– If Feature 2 (Q) (router supports the new address space ) P => Q; – Feature 1 (P) (The router can send packets to the edge system)

• 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 supports the new address space); R => P

Page 52: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Propositional Logic:Satisifability and Models

Satisfiability and Models

An interpretation 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 agent can use the truth table to find the values of any wffs.

Page 53: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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

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- True; 3 - (P P); 4 - Q True; 5 - [P (Q P)]; 6 - [(P Q) P) P]

Page 54: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

block

BatIsOk BlockLiftable RobotMOves

If we have this rule in our KB, (therefore we want it to be true) interpretations that assign the value True to BatIsOk and BlockLiftable and False to RobotMoves can be ruled out as Models.

Page 55: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Inference

Page 56: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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

Page 57: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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].Sentence 1 (R1): P1,1

Sentence 2 (R2): B1,1

Sentence 3 (R3): B2,1

"Pits cause breezes in adjacent squares"Sentence 4 (R4): B1,1 (P1,2 P2,1)

Sentence 5 (R5): B2,1 (P1,1 P2,2 P3,1)

Page 58: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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 P22

entailed?

Relevant propositional symbols: R1: P1,1

R2: B1,1

R3: B2,1

"Pits cause breezes in adjacent squares"R4: B1,1 (P1,2 P2,1)

R5: B2,1 (P1,1 P2,2 P3,1)

Inference by enumeration we have 7 symbols therefore 27 models;

Page 59: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Propositional logic: Wumpus World

Each model specifies true/false for each proposition symbolE.g. P1,2 P2,2 P3,1

false true false

With these symbols, 8 interpretations, can be enumerated automatically.

P12 P22 P31P12 P22 P31P12 P22 P31etc

Page 60: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Is P12 Entailed from KB?Is P22 Entailed from KB?Given R1, R2, R3, R4, R5

P11 P12 P21 P22 P31 B11 B21 R1:P11 R2:B11 R3:B21 R4:B11(P12 P21)

R5:B21P11 P22P31

KB

False False False True True True True False

False False False True True True True

False False False True True True True

False False False True True True True

False False False True True True True

False False False True True True True

False False False True True True True

False False False True True True True

Consider all possible truth assignments to P12, P22, P31, and check which assignmentslead to models for the KB; then check if P12 and P22 is true in all the models

Page 61: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Is P12 Entailed from KB?Is P22 Entailed from KB?Given R1, R2, R3, R4, R5

P11 P12 P21 P22 P31 B11 B21 R1:P11 R2:B11 R3:B21 R4:B11(P12 P21)

R5:B21P11 P22P31

KB

False False False False False False True True True True True False False

False False False False True False True True True True True True True

False False False True False False True True True True True True True

False True False False False False True True True True False False False

False False False True True False True True True True True True True

False True False True False False True True True True False False False

False True False False True False True True True True False True False

False True False True True False True True True True False True False

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 pointwe cannot tell whether P22 is true or not.

Page 62: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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

Page 63: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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.

Page 64: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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(2n), 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;

Page 65: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

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 modele.g., A B, C

A sentence is unsatisfiable if it is true in no modelse.g., AA

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)

Page 66: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Rules of Inferenceand

Proofs

Page 67: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Proof methods

Proof methods divide into (roughly) two kinds:

– 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

• Typically require transformation of sentences into a normal form

– Model checking• truth table enumeration (always exponential in n)

• improved backtracking, e.g., Davis--Putnam-Logemann-Loveland (DPLL)

• heuristic search in model space (sound but incomplete)e.g., min-conflicts-like hill-climbing algorithms

we’ve talked about this approach

Nextlecture

Current lecture

Page 68: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Proof

The sequence of wffs (w1, w2, …, wn) is called a proof (or deduction) of wn from a set of wffs Δ iff each wi in the sequence is either in Δ or can be inferred from a wff (or wffs) earlier in the sequence by using a valid rule of inference.

If there is a proof of wn from Δ, we say that wn is a theorem of the set Δ.

Δ├ wn

(read: wn can be proved or inferred from Δ)

The concept of proof is relative to a particular set of inference rules used. If we denote the set of inference rules used by R, we can write the fact that wn can be derived from Δ using the set of inference rules in R:

Δ├ R wn

(read: wn can be proved from Δ using the inference rules in R)

Page 69: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Propositional logic: Rules of Inference or Methods of Proof

How to produce additional wffs (sentences) from other ones? What steps can we perform to show that a conclusion follows logically from a set of hypotheses?

ExampleModus Ponens

PP Q______________ Q

The hypotheses are written in a column and the conclusions below the bar;The symbol denotes “therefore”. Given the hypotheses, the conclusion follows.The basis for this rule of inference is the tautology (P (P Q)) Q)

Page 70: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Propositional logic: Rules of Inference or Method of Proof

Rule of Inference Tautology (Deduction Theorem) Name

P

P QP (P Q) Addition

P Q P

(P Q) P Simplification

P

Q

P Q

[(P) (Q)] (P Q) Conjunction

P

P Q

P Q

[(P) (P Q)] (P Q) Modus Ponens

Q

P Q

P

[(Q) (P Q)] P Modus Tollens

P Q

Q R

P R

[(PQ) (Q R)] (PR) Hypothetical Syllogism

P Q P

Q

[(P Q) (P)] Q Disjunctive syllogism

P Q P R Q R

[(P Q) (P R)] (Q R) Resolution

Page 71: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Proof Tree

Proofs can also be based on partial orders – we can represent them using a tree structure:– Each node in the proof tree is labeled by a wff, corresponding to a wff in

Δ or be inferable from its parents in the tree using one of the rules of inference;

– The labeled tree is a proof of the label of the root node.

Example:Given the set of wffs:

P, R, P QGive a proof of Q R

Page 72: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Tree Proof

P PQ R

Q

Q R

P, P Q, Q, R, Q R

Page 73: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Propositional Logic:Entailment

Entailment means that one thing follows from another:KB ╞ α

A Knowledge base KB logically entails a wff α, or α logically follows from KB, or α is a logical consequence of KB, if and only if α is true in all worlds where KB is true

– {P} ╞ P– {P, P Q} ╞ Q– False ╞ W (where w is any wff)– P Q ╞ P– x+y = 4 ╞ 4 = x+y

Entailment is a relationship between sentences (i.e., syntax) that is based on semantics

Let a Knowledge Base (KB) be a set of wffs and α be a wff:

Page 74: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Entailment vs. Inference

When inference rules are sound and complete we can determine whether one wff follows from a knowledge base, KB, by searching for a proof instead of using the truth table;

When the set of rules are sound, if we find a proof of α from KB, we know that α logically follows from KB.

When the set of inference rules are complete we know that we will eventually be able to

prove that α follows from KB by using a complete search procedure for the proof.

Using proof methods instead of truth table methods, usually gives great computational advantage – however, to determine whether or not a wff logically follows from a set of wffs is in general an NP-Complete problem.

There are special cases that are tractable.

Page 75: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Resolution in Propositional Logic

Page 76: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Resolution (for CNF)

P Q P R Q R

Soundness of rule (validity of rule): [(P Q) (P R)] (Q R)

Very important inference rule – several other inference rulescan be seen as special cases of resolution.

Resolution for CNF – applied to a special type of wffs: conjunction of clauses.

Literal – either an atom (e.g., P) or its negation (P).Clause – disjunction of of literals (e.g., (P Q R)).

Note: Sometimes we use the notation of a set for a clause: e.g. {P,Q,R} correspondsto the clause (PQ R); the empty clause (sometimes written as Nil or {}) is equivalentto False;

Page 77: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

CNF

Conjunctive Normal Form (CNF)

A wff is in CNF format when it is a conjunction of disjunctions of literals.

Resolution for CNF – applied to wffs in CNF format.

(P Q R) (S P T R) (Q S)

{λ} Σ1

{ λ} Σ2

Σ1 Σ2

Σi- sets of literals i =1 ,2λ – atom;

atom resolved upon

Resolvent of thetwo clauses

Resolution

Page 78: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Resolution:Notes

1 – Rule of Inference: Chaining

R P P Q R Q

R P P Q R Q

can be re-written

Rule of Inference Chaining

2 – Rule of Inference: Modus Ponens

P P Q Q

P P Q Q

can be re-written

Rule of Inference: Modus Ponens

Page 79: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Resolution:Notes

3 – Unit Resolution

P P Q Q

P

P Q Q

Page 80: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Resolution:Notes

4 – No duplications in the resolvent set

P Q R S P Q W Q R S W

5 – Resolving one pair at a time

only one instance of Qappears in the resolvent,which is a set!

Resolving on Q

Resolving on R

P Q R P W Q R P R R W

P Q R P W Q R P Q Q W

True

P Q R P W Q R P W

DO NOT Resolve on Q and R

Page 81: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Resolution:Notes

6 – Same atom with opposite signs

{P} {P} {}

False – any set of wffs containing two contradictory clauses is unsatisfiable. However, a clause {P, P} is True.

Page 82: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Soundness of Resolution:Validity of the Resolution Inference Rule

P Q R (PQ) (PR) (PQ)(PR) (QR) (P Q) (P R) (Q R)

0 0 0 0 1 0 0 1

0 0 1 0 1 0 1 1

0 1 0 1 1 1 1 1

1 0 0 1 0 0 0 1

1 1 0 1 0 0 1 1

1 0 1 1 1 1 1 1

0 1 1 1 1 1 1 1

0 0 0 0 1 0 0 1

P Q P R Q R

resolving on P

Validity (Tautology): (P Q) (P R) (Q R) ;

Page 83: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Conversion to CNF

P (Q R)

1.Eliminate , replacing α β with (α β)(β α).(P (Q R)) ((Q R) P)

2. Eliminate , replacing α β with α β.(P Q R) ((Q R) P)

3. Move inwards using de Morgan's rules and double-negation:(P Q R) ((Q R) P)

4. Apply distributivity law ( over ) and flatten:(P Q R) (Q P) (R P)–

Page 84: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Converting DNF (Disjunctions of conjunctions) into CNF

1 – create a table – each row corresponds to the literals in each conjunct;

2 - Select a literal in each row and make a disjunction of these literals;

P Q R

S R P

Q S P

Example:

(PQ R ) (S R P) (Q S P)

(P S Q) (P R Q) (P P Q) (P S S)(P R S) (P P S) (P P Q)…

How many clauses?

Page 85: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Resolution:Wumpus World

P31 P2,2, P2,2

P31

P?

P?

Page 86: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Resolution:Robot Domain

Example:

BatIsOk

RobotMoves

BatIsOk BlockLiftable RobotMoves KBShow that KB ╞ BlockLiftable

BatIsOk RobotMovesBatIsOk BlockLiftable RobotMoves BlockLiftable

KB’

BlockLiftableBatIsOk BlockLiftable RobotMoves

BatIsOk RobotMovesRobotMoves

BatIsOk BatIsOk

Nil

Page 87: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Satisfiability is connected to inference via the following:

KB ╞ α if and only if (KB α) is unsatisfiable

One assumes α and shows that this leads to a contradiction with the facts in KB

Propositional Logic:Proof by refutation or contradiction:

Page 88: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Resolution Refutation

Resolution is sound – but resolution is not complete – e.g., (P R) ╞ (P R) but we cannot infer (P R) using resolution

we cannot use resolution directly to decide all logical entailments.

Resolution is Refutation Complete:We can show that a particular wff W is entailed from a given KB how? Proof by contradiction:

Write the negation of what we are trying to prove (W) as a conjunction of clauses;Add those clauses (W) to the KB (also a set of clauses), obtaining KB’; prove

inconsistency for KB’, i.e.,

Apply resolution to the KB’ until:• No more resolvents can be added• Empty clause is obtained

To show that (P R) ╞Res (P R) do: (1) negate (P R), i.e.: (P) (R) ; (2) prove that (P R) (P) (R) is inconsistent

!

!

Page 89: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Resolution

Resolution is refutation complete (Completeness of resolution refutation):

If KB ╞ W, the resolution refutation procedure, i.e., applying resolution on KB’, will produce the empty clause.

Decidability of propositional calculus by resolution refutation:

If KB is a set of finite clauses and if KB ╞ W, then the resolution refutation procedure will terminate without producing the empty clause.

Ground Resolution Theorem– If a set of clauses is not satisfiable, then resolution closure of those

clauses contains the empty clause.

In general, resolution for propositional logic is exponential !

The resolution closure of a set of clauses W in CNF, RC(W), is the set of all clauses derivable by repeated applicationof the resolution rule to clauses in W or their derivatives.

Page 90: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Resolution algorithm

Proof by contradiction, i.e., show KBα unsatisfiable

Any complete search algorithm applying only the resolution rule, can derive any conclusion entailed by any knowledge base in propositional logic – resolution can always be used to either confirm or refute a sentence – refutation completeness (Given A, it’s true we cannot use resolution to derive A OR B; butwe can use resolution to answer the question of whether A OR B is true.)

Page 91: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Resolution example:Wumpus World

KB = (B1,1 (P1,2 P2,1)) B1,1 α = P1,2

Page 92: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Resolution example:Wumpus World

KB = (B1,1 (P1,2 P2,1)) B1,1 α = P1,2

KB = (B11 (P1,2 P2,1)) ^ ((P1,2 P2,1) B11) B1,1

=(B11 P1,2 P2,1) ^ ((P1,2 P2,1) B11) B1,1 =(B11 P1,2 P2,1) ^(( P1,2 ^ P2,1) B11)) B1,1 =(B11 P1,2 P2,1) ^( P1,2 B11) ^ ( P2,1 B11) B1,1

Page 93: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Resolution Refutation – Ordering Search Strategies

Original clauses – 0th level resolvents– Depth first strategy

• Produce a 1st level resolvent;

• Resolve the 1st level resolvent with a 0th level resolvent to produce a 2nd level resolvent, etc.

• With a depth bound, we can use a backtrack search strategy;

– Breadth first strategy • Generate all 1st level resolvents, then all

2nd level resolvents, etc.

BlockLiftableBatIsOk BlockLiftable RobotMoves

BatIsOk RobotMovesRobotMoves

BatIsOk BatIsOk

Nil

BatIsOk RobotMovesBatIsOk BlockLiftable RobotMoves BlockLiftable

0th level resolvents

Depth first strategy

Page 94: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Refinement Resolution Strategies

Definitions:

A clause γ2 is a descendant of a clause γ1 iif:– Is a resolvent of γ1 with some other clause – Or is a resolvent of a descendant of γ1 with some

other clause;

If γ2 is a descendant of γ1, γ1 is an ancestor of γ2;

Set-of-support – set of clauses that are either clauses coming from the negation of the theorem to be proved or descendants of those clauses.

Set-of-support Strategy – it allows only refutations in which one of the clauses being resolved is in the set of support.

Set-of-support Strategy is refutation complete.

Set-of-support Resolution Strategy

BlockLiftableBatIsOk BlockLiftable RobotMoves

BatIsOk RobotMovesRobotMoves

BatIsOk BatIsOk

Nil

Set-of-support Strategy

Page 95: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Refinement Strategies

Ancestry-filtered strategy – allows only resolutions in which at least one member of the clauses being resolved either is a member of the original set of clauses or is an ancestor of the other clause being resolved;

The ancestry-filtered strategy is refutation complete.

Page 96: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Refinement Strategies

Linear Input Resolution Strategy – at least one of the clauses being resolved is a member of the original set of clauses (including the theorem being proved).

Linear Input Resolution Strategy is not refutation complete.

Example:

(P Q) (P Q) (P Q) (P Q)

This set of clauses is inconsistent; but there is no linear-input refutation strategy; but there is a resolution refutation strategy;

(P Q) (P Q)

Q

(P Q) (P Q)

Q

Nil

This is NOT Linear Input

Resolution Strategy

Page 97: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Horn Clauses

Page 98: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Horn Clauses

Definition:

A Horn clause is a clause that has at most one positive literal.

Examples:

P; P Q; P Q; P Q R;

Types of Horn Clauses:Fact – single atom – e.g., P;Rule – implication, whose antecendent is a conjunction of positive literals and whose consequent consists of a single positive literal – e.g., PQ R;Set of negative literals - in implication form, the antecedent is a conjunction of positive literals and the consequent is empty.

e.g., PQ ; equivalent to P Q.

Inference with propositional Horn clauses can be done in linear time !

Page 99: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Forward chaining

HORN (Expert Systems and Logic Programming)

Horn Form (restricted)KB = conjunction of Horn clauses

– Horn clause = • proposition symbol; or• (conjunction of symbols) symbol

– E.g., C (B A) (C D B)

Modus Ponens (for Horn Form): complete for Horn KBsα1, … ,αn, α1 … αn β

β

Can be used with forward chaining

Deciding entailment with Horn clauses can be done in linear time, in the size of the KB

!

Page 100: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Forward Chaining:Diagnosis systems

Example: diagnostic systemIF the engine is getting gas and the engine turns over

THEN the problem is spark plugs

IF the engine does not turn over and the lights do not come onTHEN the problem is battery or cables

IF the engine does not turn over and the lights come onTHEN the problem is starter motor

IF there is gas in the fuel tank and there is gas in the carburator

THEN the engine is getting gas

Page 101: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Forward chaining(Data driven reasoning)

Idea: fire any rule whose premises are satisfied in the KB,– add its conclusion to the KB, until query is found

AND-OR graph

Page 102: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Forward chaining algorithm

Forward chaining is sound and complete for Horn KB

Page 103: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Forward chaining example

Page 104: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Forward chaining example

Page 105: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Forward chaining example

Page 106: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Forward chaining example

Page 107: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Forward chaining example

Page 108: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Forward chaining example

Page 109: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Forward chaining example

Page 110: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Forward chaining example

Page 111: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Proof of completeness

FC derives every atomic sentence that is entailed by KB

1. FC reaches a fixed point where no new atomic sentences are derived

2. Consider the final state as a model m, assigning true/false to symbols

3. Every clause in the original KB is true in m a1 … ak b

4. Hence m is a model of KB5. If KB╞ q, q is true in every model of KB, including m

Page 112: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Backward chaining

Idea: work backwards from the query q:to prove q by BC,

check if q is known already, orprove by BC all premises of some rule concluding q

Avoid loops: check if new subgoal is already on the goal stack

Avoid repeated work: check if new subgoal1. has already been proved true, or2. has already failed

Page 113: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Backward chaining example

Page 114: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Backward chaining example

Page 115: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Backward chaining example

Page 116: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Backward chaining example

Page 117: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Backward chaining example

Page 118: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Backward chaining example

Page 119: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Backward chaining example

Page 120: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Backward chaining example

Page 121: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Backward chaining example

Page 122: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Backward chaining example

Page 123: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Forward vs. backward chaining

FC is data-driven, automatic, unconscious processing,– e.g., object recognition, routine decisions

May do lots of work that is irrelevant to the goal

BC is goal-driven, appropriate for problem-solving,– e.g., Where are my keys? How do I get into a PhD program?

Complexity of BC can be much less than linear in size of KB

Page 124: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

Depth First Search

Expand deepest unexpanded node;

Implementation:Fringe is a LIFO queue, i.e., new successors go at the front

Symbol 1

Page 125: Explorations in Artificial Intelligence Prof. Carla P. Gomes gomes@cs.cornell.edu Module 3 Logic Representations

After a few more expansions…

And so on…