11 artificial intelligence cs 165a thursday, october 25, 2007 knowledge and reasoning (ch 7)...

27
1 Artificial Intelligence CS 165A Thursday, October 25, 2007 Knowledge and reasoning (Ch 7) Propositional logic 1

Upload: karen-strickland

Post on 19-Jan-2016

215 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

11

Artificial Intelligence

CS 165A

Thursday, October 25, 2007

Knowledge and reasoning (Ch 7)

• Propositional logic

1

Page 2: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

2

Who is this key historical AI figure?

• Built a calculating machine that could add and subtract (which Pascal’s couldn’t)

• But his dream was much grander – to reduce human reasoning to a kind of calculation and to ultimately build a machine capable of carrying out such calculations

• Co-inventor of the calculus

“For it is unworthy of excellent men to lose hours like slaves in the labor of calculation which could safely be relegated to anyone else if the machine were used.”

Gottfried Leibniz (1646-1716)

Page 3: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

33

Notes

• HW#2 posted, due Tuesday– 5x5 Tic Tac Toe game

– Can work in teams of two, but different partner than in HW#1

– Can use your (or your team’s) code from HW#1 as starting point

– You’ll need to use a heuristic to evaluate positions and go down N ply in your search so that the program returns an answer in a “short” amount of time

About 10 seconds maximum....

___________

|X|O|X|X|X| 

| |O|O|X| | 

| | |O|X| |

| | | |O| | 

| | | | |O| 

¯¯¯¯¯¯¯¯¯¯¯ 

3 in a row : 1 point

4 in a row : 3 points

5 in a row : 5 points

X : 2 points

O : 3 points

Page 4: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

4

Knowledge Base

Inference engine

Domain specific content; facts

ASK

TELL

Domain independent algorithms; can deduce new facts from the KB

KB AgentsTrue sentences

Page 5: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

5

Thursday Quiz

1. If KB is the knowledge base and is a logical sentence, what is the meaning of this statement?

KB

2. Propositions P and Q are both true. Is this sentence true or false:

P Q

Briefly explain.

Page 6: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

6

Syntax and semantics example

• The PQ system – Syntax – A correct sentence must have the form

{0 or more dashes} p {0 or more dashes} q {0 or more dashes}

– For example

--p---q-----

-p-q-

pq

--p-q-

--p---q----

-p-q--

p-q

--pq--

--p---q--p--

-q-p--

-p--

--p-p-q----

• The PQ system – Semantics – # plus # equals #

– Which of the above sentence are TRUE?

Not allowable

LEGAL sentences and TRUE sentences are not the same thing!

Page 7: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

7

Semantics

Representation (abstraction)

World

Sentences

FactsS

emantics

Note: Facts may or may not be trueIf sentence P is false, then sentence P is true

--p---q-----

-pq-

--p--q-----

2 + 3 = 5

1 + 0 = 1

2 + 2 = 5

Page 8: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

8

Inference and Entailment

• Given a set of (true) sentences, logical inference generates new sentences– Sentence follows from sentences { i }

– Sentences { i } entail sentence – The classic example is modus ponens: P Q and P entail what?

• An inference procedure i can derive from KB

KB i

KB

• A knowledge base (KB) entails sentences

Page 9: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

9

Inference and Entailment (cont.)

Representation

World

FactFOLLOWS

ENTAILS

Facts

Sentences

Sem

antics

Sentence

Sem

antics

Page 10: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

10

Using propositional logic: rules of inference

• Inference (n.): a. The act or process of deriving logical conclusions from premises

known or assumed to be true.

b. The act of reasoning from factual knowledge or evidence.

• Inference rules capture patterns of sound inference– Once established, we don’t need to show the truth table every time

• Examples of inference rules:– ((P H) H) P

I.e., if ((P H) H) is in the KB, then we can conclude P

– ((P Q) P) Q I.e., if ((P Q) P) is in the KB, then we can conclude Q

Page 11: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

11

Inference engine

• An inference engine is a program that applies inference rules to knowledge– Goal: To infer new (and useful) knowledge

• Separation of– Knowledge

– Rules

– Control

Which rules should we apply when?

Inference engine

Page 12: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

12

Inference procedures

• An inference procedure– Generates new sentences that purport to be entailed by the

knowledge base…or...

– Reports whether or not a sentence is entailed by the knowledge base

• Not every inference procedure can derive all sentences that are entailed by the KB

• A sound or truth-preserving inference procedure generates only entailed sentences

• Inference derives valid conclusions independent of the semantics (i.e., independent of the interpretation)

Page 13: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

13

Inference procedures (cont.)

• Soundness of an inference procedure– i is sound if whenever KB i , it is also true that KB

– I.e., the procedure only generates entailed sentences

• Completeness of an inference procedure– i is complete if whenever KB , it is also true that KB i

– I.e., the procedure can find a proof for any sentence that is entailed

• The derivation of a sentence by a sound inference procedure is called a proof– Hence, the proof theory of a logical language specifies the

reasoning steps that are sound

Page 14: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

14

Logics

• We will soon define a logic which is expressive enough to say most things of interest, and for which there exists a sound and complete inference procedure– I.e., the procedure will be able to derive anything that is derivable

from the KB

– This is first-order logic, a.k.a. first-order predicate calculus

– But first, we need to define propositional logic

Page 15: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

15

Propositional (Boolean) Logic

• Symbols represent propositions (statements of fact, sentences)– P means “San Francisco is the capital of California”– Q means “It is raining in Seattle”

• Sentences are generated by combining proposition symbols with Boolean (logical) connectives

Page 16: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

16

Propositional Logic

• Syntax– True, false, propositional symbols

– ( ) , (not), (and), (or), (implies), (equivalent)

• Examples of sentences in propositional logic

P1, P2, etc. (propositions)

( S1 )

S1

S1 S2

S1 S2

S1 S2

S1 S2

true

P1 true ( P2 false )

P Q Q P

Page 17: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

17

Propositional (Boolean) Logic (cont.)

• Semantics– Defined by clearly interpreted symbols and straightforward

application of truth tables

– Rules for evaluating truth: Boolean algebra

– Simple method: truth tables

2N rows for N propositions

Page 18: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

18

Propositional (Boolean) Logic (cont.)

• Make sure you know simple Boolean logic

Associative, commutative, and distributive laws

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

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

P P

(P Q) P Q

(P Q) P Q

P Q P Q

DeMorgan’s Laws

Important!

Page 19: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

19

Basic logical equivalences

Equivalent Sentences

P Q P Q

P True P

P Q True P Q

P False P

P P False

Page 20: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

20

Satisfiability and Validity

• Is this true: ( P Q ) ?– It depends on the values of P and Q– This is a satisfiable sentence – there are some interpretations for

which it is true – In other words, it depends: it could be true or false

• Is this true: ( P P ) ?– No, it is never true– This is an unsatisfiable sentence (self-contradictory) – there is no

interpretation for which it is true

• Is this true: ( ((P Q) Q) P ) ?– Yes, independent of the values of P and Q– This is a valid sentence – it is true under all possible

interpretations (a.k.a. a tautology)– Truth tables can test for validity

Page 21: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

21

Propositional logic (cont.)

• A C– The premise implies the conclusion ... or ...

The antecedent implies the consequent

– What if A C is always true? Example:

Then we can say that the antecedent entails the consequent.

In other words, P and H can be seen as variables – this is true for any statements P and Q.

Page 22: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

22

• One can say that the premise entails the conclusion– ((P H) H) entails P

– ((P H) H) P

• Have we also shown that ((P H) H) P ?

Well, yes and no....

We still don’t have a method to derive this.

But if we add this inference rule explicitly to our system, with P and H as variables representing any two propositions, then we do have such a procedure.

Page 23: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

23

Using propositional logic: rules of inference

• Inference rules capture patterns of sound inference– Once established, don’t need to show the truth table every time

– E.g., we can define an inference rule: ((P H) H) P for variables P and H

“If we know , then we can conclude ”

• Alternate notation for inference rule :

(where and are propositional logic sentences)

Page 24: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

24

Inference

KB1

KB, 1

2

KB, 1, 2

3

• Inference steps

KB

1, 2, …

or

• We’re particularly interested in

So we need a mechanism to do this!

Inference rules that can be applied to sentences in our KB

Page 25: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

25

Important Inference Rules for Propositional Logic

Page 26: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

26

Resolution Rule: one rule for all inferences

rprqqp

,

Propositional calculus resolution

rp

rqqp

,

ca

cbba

,or

Remember: p q p q, so let’s rewrite it as:

Resolution is really the “chaining” of implications.

Would like to show that resolution is sound and (essentially) complete (use Deduction Rule for proof)

Page 27: 11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1

27

Inference in Propositional Logic

• Three ways to answer: “Is Mary the grandparent of Ann?”– One way:

Find sentence P (“Mary is the grandparent of Ann”) in KB

– Another way: Put sentence P in the KB, and use inference rules to prove a

contradiction (false)

– Yet another way: Find sentence Q (“Mary is parent of Frank”), sentence R

(“Frank is the parent of Ann”), and sentence Q R S, where S is the proposition “Mary is grandparent of Ann”

Then apply modus ponens: Q R S, Q Rto conclude S (“Mary is the grandparent of Ann”)

“If Mary is the parent of Frank and Frank is the parent of Ann, then Mary is the grandparent of Ann”“If Mary is the parent of Frank and Frank is the parent of Ann, then Mary is the grandparent of Ann”