Top Banner
1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning
39

1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

Dec 29, 2015

Download

Documents

Myrtle Warner
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

1

CS 2710, ISSP 2610

Chapter 7 Propositional Logic

Reasoning

Page 2: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

2

Knowledge Based Agents

• Central component: knowledge base, or KB.• A set of sentences in a knowledge representation language• Generic Functions

– TELL (add a fact to the knowledge base)– ASK (get next action based on info in KB)

• [Inference?]

Page 3: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

Note

• We’re all familiar with logic from mathematics• In AI, we need to think about things we usually take for granted• To use the notion of prime number, you don’t have to think about what

prime means … or number, for that matter• In AI, we create knowledge representation schemes, which define the

objects, predicates, and functions which exist

3

Page 4: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

4

The Wumpus World

• Game is played in a MxN grid• One player, one wumpus, one or more pits• The wumpus eats anyone who enters its room• A pit traps anyone who moves into its room• (The wumpus can be shot by an agent, but the agent has only one

arrow; this and some other details won’t come up in these notes)• Player starts in 0,0• Forward, turn left, turn right• If player tries to move forward and bumps into a wall, the player does

not move• Player can grab the gold if they are in the same room• Goal: find gold while avoiding wumpus and pits

Page 5: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

Sensors

• 5 sensors, each which gives one bit of information– Stench (if wumpus and player in adjacent, not diagonal, squares)– Breeze (if a pit and player in adjacent squares)– Glitter (if gold and player in the same room)– Bump (when the agent walks into a wall)– Scream (when wumpus is killed; sound can be perceived

everywhere)• Percepts: 5-tuples

– [stench, breeze, glitter, bump, scream]

5

Page 6: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

Environment?

• Discrete, static, single-agent (wumpus doesn’t move)• Sequential (player’s decisions can affect future ones)• Partially observable (locations of pits and wumpus are unobservable)

6

Page 7: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

7

stench [Wumpus]

stench

Glitter[gold]

stench,breeze

[start] breeze [Pit] breeze

0

0

Page 8: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

8

Wumpus

• Main difficulty: player doesn’t know locations of pits, gold, and wumpus

• Reason about configuration• Knowledge evolves as new percepts arrive and actions are taken.

Page 9: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

9

Examples of reasoning [diagram in lecture]

1. Player starts in (0,0). No stench or breeze. So, no pit or wumpus in (1,0) or (0,1). Player still alive, so no pit or wumpus in (0,0). Player moves to (1,0)

2. Breeze in (1,0). So, there must be a pit in (0,0), (2,0) or (1,1). Player already ruled out (0,0)

3. Since there is danger in moving to (2,0) and (1,1), player moves back to (0,0)

4. Player moves to (0,1). No positive percepts. Now player knows there is no pit in (1,1) yeah! and there is a pit in (2,0) (pit-def in diagram)

Player combines knowledge gained at different times to make inferences

Page 10: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

10

Fundamental Concepts of logical representation and reasoning

• Information is represented in sentences, which must have correct syntax( 1 + 2 ) * 7 = 21 vs. 2 ) + 7 = * ( 1 21

• The semantics of a sentence defines its truth with respect to each possible world – an interpretation assigning T or F to all propositions

• W is a model of S means that sentence S is true under interpretation W

• [What do the following mean?]– X |= Y– X entails Y– Y logically follows from X

Page 11: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

11

Which are true?Which are not true but useful?

1. {Man, Man Mortal} |= Mortal2. {Raining,Dog Mammal} |= Mammal3. {Raining,Raining Wet} |= Wet4. {Smoke, Fire Smoke} |= Fire5. {Tall ^ Silly} |= Tall6. {Tall v Silly} |= Silly7. {Tall, Silly} |= Tall ^ Silly[Wumpus world EG illustrating possible worlds and entailment]

Page 12: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

12

Entailment (reminder)

• A |= B• Under all interpretations in which A is true, B is true as well• All models of A are models of B• Whenever A is true, B is true as well• A entails B• B logically follows from A

Page 13: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

13

Inference

KB |-i A

Inference algorithm i can derive A from KBA can be inferred from KB using i

Page 14: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

14

Inference Algorithm Examples

1. {A,B} |- (^intro) A ^ B2. {A, AB} |- (MP) B3. {A, B A} |- (abduction) B4. Internet says P|- (gullibility) P5. Professor says P |- (trust in authority) P

Page 15: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

15

Inference Algorithms

• Notes: implication, piece of syntax|= entailment, used to describe semantics|- can be derived from*Inference algorithm, inference procedure, rule of inference, inference

rule: procedure that derives sentences from sentences• [Definition of soundness of inference algorithm i]• [Definition of completeness of inference algorithm i]

• * Though it can mean different things in different math/logic contexts; see “turnstile” in Wikipedia

Page 16: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

16

Monotonicity

• [A logic is monotonic if…]

Page 17: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

17

Propositional Logic Syntax

• Sentence -> AtomicSent | complexSentAtomicSent -> true|false| P, Q, R …ComplexSent ->sentence | ( sentence sentence ) |( sentence sentence ) |( sentence sentence ) |( sentence sentence ) |( sentence )

[no predicate or function symbols]

Page 18: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

18

Propositional Logic Sentences

• If there is a pit at [1,1], there is a breeze at [1,0]P11 B10

• There is a breeze at [2,2], if and only if there is a pit in the neighborhoodB22 ( P21 P23 P12 P32 )

• There is no breeze at [2,2]B22

Page 19: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

19

Semantics of Prop Logic

• In model-theoretic semantics, an interpretation assigns elements of the world to sentences, and defines the truth values of sentences

• Propositional logic: easy! Assign T or F to each proposition symbol; then assign truth values to complex sentences in the obvious way

Page 20: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

20

Logical Equivalences

• Sentences A and B are logically equivalent if:• they are true under exactly the same interpretations• A |= B and B |= A

Page 21: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

21

Validity

• A sentence (or set of sentences) is valid if • it is true under all interpretations• Example: P v ~P

Page 22: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

22

Satisfiability

• A sentence (or set of sentences) is satisfiable if there exists some interpretation that makes it true

• An interpretation satisfies a set of sentences if it makes them true

Page 23: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

23

Entailment

• A |= B• All interpretations that satisfy A also satisfy B

Page 24: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

24

Propositional Logic Inference

• Question: Does KB entail S?• Method 1: Truth Table Entailment• Method 2: Proof

– Proof by deduction, induction, contradiction, etc.

Page 25: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

25

A B C A B A C B C

F F F F F F

F F T F F F

F T F F F F

F T T F F T

T F F F F F

T F T F T F

T T F T F F

T T T T T T

A,B, EntailsAB

A^C, Cdoes not entailBC

Page 26: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

26

Example Proof by Deduction

• KnowledgeS1: B22 ( P21 P23 P12 P32 ) rule

S2: B22 observation• Inferences

S3: (B22 (P21 P23 P12 P32 )) ((P21 P23 P12 P32 ) B22) S1,bi elim

S4: ((P21 P23 P12 P32 ) B22) S3, and elim

S5: (B22 ( P21 P23 P12 P32 )) S4,contrapos

S6: (P21 P23 P12 P32 ) S2,S5, MP

S7: P21 P23 P12 P32 S6, DeMorg

Page 27: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

27

Proofs

• A derivation• A sequence of applications of rules of inference• Reasoning by search• Successor function: all possible applications of inference rules• Monotonicity means search can be local, and more efficient

Page 28: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

28

Resolution

• Resolution allows a complete inference mechanism (search-based) using only one rule of inference

Page 29: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

29

Resolution

• winter v summer• ~winter v cold• Either winter or ~winter is true, so we know that summer or cold is

true• Resolution rule:

– Given: P1 P2 P3 … Pn, and P1 Q1 … Qm

– Conclude: P2 P3 … Pn Q1 … Qm

Complementary literals P1 and P1 “cancel out”

Page 30: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

30

Resolution in Wumpus World

• There is a pit at 2,1 or 2,3 or 1,2 or 3,2– P21 P23 P12 P32

• There is no pit at 2,1 P21

• Therefore (by resolution) the pit must be at 2,3 or 1,2 or 3,2– P23 P12 P32

Page 31: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

31

Resolution

• Any complete search algorithm, applying only the resolution rule, can derive any conclusion entailed by any KB in propositional logic.

Page 32: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

32

Proof using Resolution

• To try to prove P from KB:– Convert KB and P into CNF– To prove P, prove KB P is contradictory (empty clause)– Specifically, apply resolution using a complete search algorithm

until:• No new clauses can be added, (KB does not entail P)• The empty clause is derived (KB does entail P).

Page 33: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

33

B22 ( P21 P23 P12 P32 )Conversion to CNF

1. Eliminate , replacing with two implications

(B22 ( P21 P23 P12 P32 )) ((P21 P23 P12 P32 ) B22)• Replace implication (A B) by A B

(B22 ( P21 P23 P12 P32 )) ((P21 P23 P12 P32 ) B22)1. Move “inwards” (unnecessary parens removed)

(B22 P21 P23 P12 P32 ) ( (P21 P23 P12 P32 ) B22)4. Distributive Law

(B22 P21 P23 P12 P32 ) (P21 B22) (P23 B22) (P12 B22) (P32 B22)

Page 34: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

34

Previous Slide: Sentence is in CNF

• Next step (with simpler example):• (P1 v P2 v ~P3) ^ P4 ^ ~P5 ^ (P2 v P3)• Create a separate clause corresponding to each conjunct

– P1 v P2 v ~P3– P4– ~P5– P2 v P3

Page 35: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

35

Finally…

– Add the negation of the goal to the set of clauses, and perform resolution. If you reach the empty clause, you have proved the goal

Page 36: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

36

Simple Resolution EG

• When the agent is in 1,1, there is no breeze, so there can be no pits in neighboring squares

• (B11 (P12 v P21)); ~B11• Prove: ~P12. [lecture]• [What if P and ~P are both in the KB?]

Page 37: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

37

Horn Clauses

• A Horn Clause is a CNF clause with at most one positive literal• Horn Clauses form the basis of forward and backward chaining• The Prolog language is based on Horn Clauses• Deciding entailment with Horn Clauses is linear in the size of the

knowledge base

Page 38: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

38

Reasoning with Horn Clauses

• Forward Chaining– For each new piece of data, generate all new facts, until the

desired fact is generated– Data-directed reasoning

• Backward Chaining– To prove the goal, find a clause that contains the goal as its head,

and prove the body recursively– Goal-directed reasoning

• The state space is an AND-OR graph; see 7.5.4

Page 39: 1 CS 2710, ISSP 2610 Chapter 7 Propositional Logic Reasoning.

Wrap-up

• You are responsible for everything in Chapter 7 through 7.6-2– Note: we didn’t cover 7.5.4 or 7.6 in lecture

• We will return to topics in 7.7 when we cover planning

39