Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

41
Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Transcript of Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Page 1: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Computer Science CPSC 322

Lecture 22

Logical Consequences,

Proof Procedures

(Ch 5.2.2)

Page 2: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Announcements

• Practice Exercise on Planning as CSP (can help with Assign 3 Q2

• Practice exercise on logic is available on the class syllabus

Pay special attention to “Directed Questions”. They can really help you do well on the conceptual questions

part of the finalShow you how to be precise when you define concepts

• After today you can do Q3a in assign 3

Slide 2

Page 3: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Lecture Overview

• Recap Lecture 21• Logical Consequences • Proof Procedures

• Bottom-Up Proof Procedure

Slide 3

Page 4: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Where Are We?Environment

Problem Type

Query

Planning

Deterministic Stochastic

Constraint Satisfaction Search

Arc Consistency

Search

Search

Logics

STRIPS

Vars + Constraints

Value Iteration

Variable

Elimination

Belief Nets

Decision Nets

Markov Processes

Static

Sequential

Representation

ReasoningTechnique

Variable

EliminationBack to static

problems, but with richer

representation Slide 4

Page 5: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Logic: a framework for representation & reasoning

• When we represent a domain about which we have only partial (but certain) information, we need to represent….• Objects, properties, sets, groups, actions, events, time, space, …

• All these can be represented as • Objects• Relationships between objects

• Logic is the language to express knowledge about the world this way

5

We will start with a simple logicPrimitive elements are propositions: Boolean variables that can be {true, false}

Two kinds of statements:that a proposition is truethat a proposition is true if one or more other propositions are true

Page 6: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

To Define a Logic We Need

• Syntax: specifies the symbols used, and how they can be combined to form legal sentences • Knowledge base is a set of sentences in the language

• Semantics: specifies the meaning of symbols and sentences

• Reasoning theory or proof procedure: a specification of how an answer can be produced.• Sound: only generates correct answers with respect to

the semantics

• Complete: Guaranteed to find an answer if it exists

Slide 6

Page 7: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Propositional Definite Clauses: Syntax

Definition (atom)

An atom is a symbol starting with a lower case letter

Definition (body)

A body is an atom or is of the form b1 ∧ b2 where b1 and b2 are bodies.

Definition (definite clause)

A definite clause is

- an atom or

- a rule of the form h ← b where h is an

atom (“head”) and b is a body. (Read this as “h if b”.)

Definition (KB)

A knowledge base (KB) is a set of definite clauses

Examples: p1; live_l1

Examples: p1 ∧ p2; ok_w1 ∧ live_w0

Examples: p1 ← p2; live_w0 ← live_w1 ∧ up_s2

Slide 7

Page 8: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Propositional Definite Clauses: SemanticsDefinition (interpretation)

An interpretation I assigns a truth value to each atom.

Definition (truth values of statements)• A body b1 ∧ b2 is true in I if and only if b1 is true in

I and b2 is true in I.• A rule h ← b is false in I if and only if b is true in I

and h is false in I.• A knowledge base KB is true in I if and only if

every clause in KB is true in I.

Page 9: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

PDC Semantics: Knowledge Base (KB)

p q r s

I1 true true false false

prs ← q p∧

pqs ← q

pq ← r s∧

A. KB1 B. KB2C. KB3

Which of the three KB above is True in I1

• A knowledge base KB is true in I if and only if every clause in KB is true in I.

Slide 9

Page 10: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Slide 10

PDC Semantics: Knowledge Base (KB)

p q r s

I1 true true false false

pq ← r s∧

KB3

Which of the three KB above are True in I1 ?KB3

• A knowledge base KB is true in I if and only if every clause in KB is true in I.

Page 11: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Propositional Definite Clauses: Semantics

Definition (model)A model of a knowledge base KB is an interpretation in

which KB is true.

Similar to CSPs: a model of a set of clauses is an interpretation that makes all of the clauses true

Definition (interpretation)

An interpretation I assigns a truth value to each atom.

Definition (truth values of statements)• A body b1 ∧ b2 is true in I if and only if b1 is true in

I and b2 is true in I.• A rule h ← b is false in I if and only if b is true in I

and h is false in I.• A knowledge base KB is true in I if and only if

every clause in KB is true in I.

Page 12: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

PDC Semantics: Example for models

p ← q

KB = q

r ← s

Definition (model)A model of a knowledge base KB is an interpretation in

which every clause in KB is true.

p q r s

I1 T T T T

I2 F F F F

I3 T T F F

I4 T T T F

I5 F T F T

Which of the interpretations below are models of KB?

B. I1 , I3

C. I1, I3, I4

D. All of them

A. I3

Slide 12

Page 13: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

PDC Semantics: Example for models

p q r s p ← q q r ← s KB

I1 T T T T T T T T

I2 F F F F T F T F

I3 T T F F T T T T

I4 T T T F T T T T

I5 F T F T F T F F

Definition (model)A model of a knowledge base KB is an interpretation in

which every clause in KB is true.

p ← q

KB = q

r ← s

Which of the interpretations below are models of KB? All interpretations where KB is true: I1, I3, and I4

Slide 13

Page 14: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Slide 14

OK but….…. Who cares? Where are we going with this?

Remember what we want to do with Logic

1) Tell the system knowledge about a task domain.• This is your KB• which expresses true statements about the world

2) Ask the system whether new statements about the domain are true or false.• We want the system responses to be

– Sound: only generates correct answers with respect to the semantics– Complete: Guaranteed to find an answer if it exists

Page 15: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

For Instance

1) Tell the system knowledge about a task domain.

2) Ask the system whether new statements about the domain are true or false

• live_w4? lit_l2?

Slide 15

Page 16: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Slide 16

To Obtain This We Need One More Definition

Page 17: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Lecture Overview

• Recap Lecture 21• Logical Consequences • Proof Procedures

• Bottom-Up Proof Procedure

Slide 17

Page 18: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Slide 18

To Obtain This We Need One More Definition

Definition (logical consequence)If KB is a set of clauses and G is a conjunction of atoms, G is a logical consequence of KB, written KB ⊧ G, if G is true in every model of KB.

• we also say that G logically follows from KB, or that KB entails G.• In other words, KB ⊧ G if there is no interpretation in which KB is true and G is false.

• when KB is TRUE, then G must be TRUE

• We want a reasoning procedure that can find all and only the logical consequences of a knowledge base

Page 19: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

.

.

q

rqpKB

Example of Logic Entailment

How many models are there?

A. 1 B. 2 C. 3 D. 4

E. 5

Slide 19

Page 20: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

.

.

q

rqpKB

Interpretationsr q p

T T T

T T F

T F T

T F F

F T T

F T F

F F T

F F F

Example of Logic Entailment

How many models are there?

A. 1 B. 2 C. 3 D. 4

E. 5

Slide 20

Page 21: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

.

.

q

rqpKB

Interpretationsr q p

T T T

T T F

T F T

T F F

F T T

F T F

F F T

F F F

Models

Which atoms are logically entailed? q

Example of Logic Entailment

• We want a reasoning procedure that can find all and only the logical consequences of a knowledge base Slide 21

Page 22: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Example: Logical Consequences

.

.

.

sr

q

qp

KB

p q r s

I1 true true true true

I2 true true true false

I3 true true false false

I4 true true false true

I5 false true true true

I6 false true true false

I7 false true false false

I8 false true false true

I9 true false true true

I10 true false true false

I11 true false false false

I12 true false false false

….. …… ….. …… …….

Which of the following is true?

A. KB ⊧ q and KB ⊧ rB. KB ⊧ q, and KB ⊧ s

C. KB ⊧ q, and KB ⊧ pD. KB ⊧ r, KB ⊧ s,

E. None of the above

Page 23: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Example: Logical Consequences

.

.

.

sr

q

qp

KB

p q r s

I1 true true true true

I2 true true true false

I3 true true false false

I4 true true false true

I5 false true true true

I6 false true true false

I7 false true false false

I8 false true false true

I9 true false true true

I10 true false true false

I11 true false false false

I12 true false false false

….. …… ….. …… …….

Which of the following is true?

• KB ⊧ q,

• KB ⊧ p,

• KB ⊧ s,

• KB ⊧ r

Slide 23

Page 24: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Example: Logical Consequences

.

.

.

sr

q

qp

KB

p q r s

I1 true true true true

I2 true true true false

I3 true true false false

I4 true true false true

I5 false true true true

I6 false true true false

I7 false true false false

I8 false true false true

I9 true false true true

I10 true false true false

I11 true false false false

I12 true false false false

….. …… ….. …… …….

Which of the following is true?

• KB ⊧ q,

• KB ⊧ p,

• KB ⊧ s,

• KB ⊧ r

T

T

F

FSlide 24

Page 25: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Example: Logical Consequences

.

.

.

sr

q

qp

KB

p q r s

I1 true true true true

I2 true true true false

I3 true true false false

I4 true true false true

I5 false true true true

I6 false true true false

I7 false true false false

I8 false true false true

I9 true false true true

I10 true false true false

I11 true false false false

I12 true false false false

….. …… ….. …… …….

Which of the following is true?

C. KB ⊧ q, and KB ⊧ p

Page 26: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

User’s View of Semantics

• Choose a task domain: intended interpretation.

• For each proposition you want to represent, associate a proposition symbol in the language.

• Tell the system clauses that are true in the intended interpretation: axiomatize the domain.

• Ask questions about the intended interpretation.

• If KB |= g , then g must be true in the intended interpretation.

Slide 26

Page 27: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Computer’s View of Semantics

• The computer doesn’t have access to the intended interpretation.

• All it knows is the knowledge base.

• The computer can determine if a formula is a logical consequence of KB.

• If KB |= g then g must be true in the intended interpretation.

• Otherwise, there is a model of KB in which g is false. This could be the intended interpretation.

The computer wouldn't know!

Slide 27

Page 28: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Computer’s View of Semantics

• Otherwise, there is a model of KB in which g is false. This could be the intended interpretation.

The computer wouldn't know

.

.

.

sr

q

qp

KBp q r s

I1 true true true true

I2 true true true false

Slide 28

Page 29: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

To Define a Logic We Need

• Syntax: specifies the symbols used, and how they can be combined to form legal sentences • Knowledge base is a set of sentences in the language

• Semantics: specifies the meaning of symbols and sentences

• Reasoning theory or proof procedure: a specification of how an answer can be produced (sound and complete)• Bottom-up and Top-Down Proof Procedure for Finding

Logical Consequence

Slide 29

Page 30: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Lecture Overview

• Recap Lecture 21• Logical Consequences • Proof Procedures

• Bottom-Up Proof Procedure

Slide 30

Page 31: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Proof Procedures• A proof procedure is a mechanically derivable demonstration that

a formula logically follows from a knowledge base.• Given a proof procedure P, KB ⊦ P g means g can be derived

from knowledge base KB with the proof procedure.

• If I tell you I have a proof procedure for PDCL• What do I need to show you in order for you to trust my

procedure?

That is sound and complete

Slide 31

Page 32: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Soundness and Completeness

• Completeness of proof procedure P: need to prove that

If g is true in all models of KB (KB g)⊧ then g is derived by the procedure (KB ⊦P g)

Definition (completeness)

A proof procedure P is complete if KB g implies KB ⊧ ⊦P g.

complete: every atom that logically follows from KB is derived by P

• Soundness of proof procedure P: need to prove that

Definition (soundness)

A proof procedure P is sound if KB ⊦P g implies KB g.⊧

If g can be derived by the procedure (KB ⊦P g) then g is true in all models of KB (KB g)⊧

sound: every atom derived by P follows logically from KB (i.e. is true in every model)

Slide 32

Page 33: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Simple Proof Procedure

problem with this approach?

• If there are n propositions in the KB, must check all the interpretations!

Goal of proof theory • find sound and complete proof procedures that allow us to

prove that a logical formula follows from a KB avoiding to do the above

Simple proof procedure S• Enumerate all interpretations• For each interpretation I, check whether it is a model of KB

i.e., check whether all clauses in KB are true in I

• KB ⊦S g if g holds in all such models

Slide 33

Page 34: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Lecture Overview

• Recap Lecture 21• Logical Consequences • Proof Procedures

• Bottom-Up Proof Procedure

Slide 35

Page 35: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Bottom-up proof procedure

• One rule of derivation, a generalized form of modus ponens:

• If “h ← b1 … bm" is a clause in the knowledge base, and

each bi has been derived,

then h can be derived.

• This rule also covers the case when m = 0.

Slide 36

Page 36: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Bottom-up proof procedure

C :={};repeat

select clause “h ← b1 ∧ … ∧ bm” in KB such that bi ∈ C for all i, and h ∉ C;

C := C ∪ { h }until no more clauses can be selected.

KB ⊦ G if G ⊆ C at the end of this procedure

Slide 37

The C at the end of BU procedure is a fixed point:• Further applications of our rule of derivation will not

change C!

Page 37: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

C := {};

repeat

select clause h ← b1 … bm in KB such that bi C for all i, and h C;

C := C {h}

until no more clauses can be selected.

Bottom-up proof procedure: example

a ← b c

a ← e f

b ← f k

c ← e

d ← k

e.

f ← j e

f ← c

j ← c

{}

Slide 38

Page 38: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

C := {};

repeat

select clause h ← b1 … bm in KB such that bi C for all i, and h C;

C := C {h}

until no more clauses can be selected.

Bottom-up proof procedure: example

a ← b c

a ← e f

b ← f k

c ← e

d ← k

e.

f ← j e

f ← c

j ← c

{}

{e}

{c,e}

{c,e,f}

{c,e,f,j}

{c,e,f,j, a}

Done.Slide 39

Page 39: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Bottom-up proof procedure: Example

z ← f ∧ e

q ← f ∧ g ∧ z

e ← a ∧ babrf A. KB ⊦ {z , q , a}

KBC := {};

repeat

select clause h ← b1 … bm in KB such that bi C for all i, and h C;

C := C {h}

until no more clauses can be selected.

Which of the following is true?

B. KB ⊦ {r , z , b}

C. KB ⊦ {q,a}

Slide 40

Page 40: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Bottom-up proof procedure: Example

z ← f ∧ e

q ← f ∧ g ∧ z

e ← a ∧ babrf

KBC := {};

repeat

select clause h ← b1 … bm in KB such that bi C for all i, and h C;

C := C {h}

until no more clauses can be selected.

Which of the following is true?

B. KB ⊦ {r , z , b}

Slide 41

Page 41: Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)

Learning Goals Up To Here

• PDCL syntax & semantics- Verify whether a logical statement belongs to the language of

propositional definite clauses

‾ Verify whether an interpretation is a model of a PDCL KB. ‾ Verify when a conjunction of atoms is a logical consequence

of a knowledge base

• Bottom-up proof procedure• Define/read/write/trace/debug the Bottom Up (BU) proof

procedure

Next Time: we will prove soundness and completenessSlide 42