Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

40
Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    223
  • download

    2

Transcript of Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Page 1: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Propositional Logic

Reading: Ch. 7, AIMA 2nd Ed.

(skip 7.6-7.7)

Page 2: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Logic for knowledge representation

• Important problem: knowledge representation = solving the problems of– How to represent knowledge about problem domain

– How to reason using this knowledge in order to answer queries or make decisions

• Knowledge-based agents– Have knowledge representation in a formal language

– Can reason about world using inference in the language

– Can decide what action to take by inferring that the action is good

• Declarative agents– Declare to agents facts about world

– Pose questions to get answers

Page 3: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Declarative knowledge-based agents

Page 4: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Wumpus world

• Performance measureGold +1000, death –1000, step –1, arrow –10

• Environment- squares adjacent to wumpus are smelly- squares adjacent to pits 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 the same square- releasing drops the gold in same square

• SensorsBreeze, glitter, smell

• ActuatorsLeft, right turn, forward, grab, release, shoot

Page 5: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Wumpus world characterization

• Observable– No – only local perception

• Deterministic– Yes – outcomes explicite

• Episodic– No – sequential actions

• Discrete– Yes

• Single-agent– Yes

Page 6: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Exploring wumpus world

A

ok

ok

ok

Page 7: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Exploring wumpus world

B

A

ok

ok

ok

P?

P?

Page 8: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Exploring wumpus world

B

A

ok

ok

ok

P?

P?

Page 9: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Exploring wumpus world

B

S

A

ok

ok

ok

P?

P? W?

W?

Page 10: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Exploring wumpus world

B

S

A

ok

ok

ok

P?

P? W?

W?

ok

P

W

How can we make these inferences automatically?

Page 11: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Logic

• Logic is a formal language for representing information such that conclusions can be drawn

• A logic includes– Syntax: specifies symbols in the language and how they can be

combined to form sentences

– Semantics: specifies what facts in the world a semantics refers to.Assigns truth values to sentences based on their meaning in the world.

– Inference procedure: mechanical method for computing (deriving) new (true) sentences from existing sentences

entailsSentences Sentences

Facts Facts

Representation:

World:

semanticsfollows

Page 12: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Example

• Language of arithmetic

– 4x+y > 0 is a sentence, 4x<y0 is not

– 4x+y > 0 is true iff number 4x+y is greater than zero

– 4x+y > 0 is true in a world where x=0, y = 1

– 4x+y > 0 is false in a world where x=0, y = 0

• Hence, to build a logic-based representation:1. Define a set of primitive symbols and the associated semantics

2. Logic defines the ways of putting there symbols together in order to represent true facts about world

3. Logic defines ways of inferring new sentences from existing ones

Page 13: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Propositional (Boolean) logic

• Simple language (but useful for key ideas and definitions)• Language syntax

– Atoms/Symbols: P12, B11, W33,, IS_HOT, IS_BREEZY, , …User defines meaning of symbols.

– Connectives: (and), (or), (implies), (iff), (not)

– Sentences or Well-formed-formulae (wff):1. A symbol is a sentence

2. If S is a sentence, S (negation) is a sentence

3. If S and T are sentences, ST (conjunction), ST (disjunction), ST (implication), ST (equivalence) are sentences

4. A finite number of applications of (1)-(3) is a sentence

Page 14: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Symbols & Sentences of Wumpus world

• Pij is “pit in (i,j)”

• Bij is “breeze in (i,j)”

• Wij is “wumpus in (i,j)”

B11

• “Pits cause breezes in adjacent squares”– B11 ( P12 P21 )

– B12 ( P11 P22 P13 )

– …

Page 15: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Semantics

• Association of elements of logical language (atoms & sentences) with real world

• Propositional logic = associate atoms with propositionsE.g., – P12 is associated with “pit is in cell (1,2)”

– B11 is associated with “breeze is felt in cell (1,1)”

– W33 is associated with “wumpus is in (3,3)”

– IS_HOT is associated with “I am taking cs440”

• Association of atoms with propositions = interpretation

If atom has value TRUE (1), then its interpretation P is true in the world; otherwise has value FALSE (0)

• E.g., P12 = 1 means “pit is in cell (1,2) is true”

Page 16: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Propositional truth tables

• Used to compute values of any sentence, given values of atoms• Establishes meaning of propositional connectives

A B A AB AB AB AB

0 0 1 0 0 1 1

0 1 1 1 0 1 0

1 0 0 1 0 0 0

1 1 0 1 1 1 1

• The basic truth table can be used to evaluate any sentence by applying the rules recursively

A ( AB ) = 0 ( 01 ) = 1 ( 01 ) = 1 1 = 1

Page 17: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Models

• A model is an interpretation of a set of sentences such that each sentence is True:

is a model of a sentence S if S is true in ( an interpretation of S satisfies )

• A mathematical structure that represents the (problem in) real world.

• Some other notions:– Unsatisfiable: there is no interpretation that satisfies S

Page 18: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Models of Wumpus world

• Situation after detecting nothing in (1,1), moving up, breeze in (2,1)

• What are the possible models for P?, assuming only pits?

• P12, P22, P31 {0,1}

• 8 possible models

B

A

P?

P?

P?

Page 19: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Models of Wumpus world

PB

A

B

A

PB

A

P

B

A

P

PB

A

P

P

P

B

A

P

P

B

A

P

P

B

A

Are these themodels of Wumpusworld?

Page 20: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Wumpus Knowledge Base (KB)

• KB = { S1, S2, …, SN } – set of all sentences describing our current knowledge of the world, where each sentence is in propositional logic

• Wumpus world KB

S1: B11

S2: B21

S3: B11 ( P12 P21 )

S4: B21 ( P11 P22 P31 )S5: P11

• Remember, models are interpretations where all Si are true

• How to find models?

Page 21: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Model checking: Enumeration of symbols in sentences

• Check for valid models by enumerating all possible symbols interpretations: KB = S1 S2 S3 S4 S5

B11 B21 P11 P12 P21 P22 P31 S1 S2 S3 S4 S5 KB

0 0 0 0 0 0 0 1 0 1 1 1 0

0 0 0 0 0 0 1 1 0 1 0 1 0

… … … …

0 1 0 0 0 0 0 1 1 1 0 1 0

0 1 0 0 0 0 1 1 1 1 1 1 1

0 1 0 0 0 1 0 1 1 1 1 1 1

0 1 0 0 0 1 1 1 1 1 1 1 1

0 1 0 0 1 0 0 1 1 0 0 1 0

… … … …

1 1 1 1 1 1 1 0 1 1 1 0 0

Page 22: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Model checking: Enumeration of symbols in sentences

• Models are shown in red!• How many enumerations? 27

B11 B21 P11 P12 P21 P22 P31 S1 S2 S3 S4 S5 KB

0 0 0 0 0 0 0 1 0 1 1 1 0

0 0 0 0 0 0 1 1 0 1 0 1 0

… … … …

0 1 0 0 0 0 0 1 1 1 0 1 0

0 1 0 0 0 0 1 1 1 1 1 1 1

0 1 0 0 0 1 0 1 1 1 1 1 1

0 1 0 0 0 1 1 1 1 1 1 1 1

0 1 0 0 1 0 0 1 1 0 0 1 0

… … … …

1 1 1 1 1 1 1 0 1 1 1 0 0

Page 23: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Models of Wumpus world

• Rows of the truth table where the last column (KB) is true (I.e., all sentences are true)

PB

A B

A

PB

A

P

BA

PP

BA

PPP

BA

PP

BA

P

P

BA

KB

Page 24: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Inference & entailment

• Given KB, what else can we conclude about the world?E.g., does a goal (a.k.a. query, conclusion, theorem) sentence G follow from KB?

• Note: we do not know semantics.Hence: we have to determine if all models of KB are models of G.

• I.e., KB entails G, ( KB |= G ) iff G is true whenever KB is true

• KB |= G iff KB G is valid(A sentence is valid iff it is true under all possible interpretations)

• KB |= G iff KB G is unsatisfiable

Page 25: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Wumpus world entailment

• G = “(1,2) is safe”• Does KB |= G ?

PB

A B

A

PB

A

P

BA

PP

BA

PPP

BA

PP

BA

P

P

BA

KB

G

YES!

M(KB)M(G)

Page 26: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Wumpus world entailment (II)

• G: P12

• Column KBG is all 1, hence it is valid. Thus, KB |= G.• Conclusion G follows from KB no matter what the

interpretations

B11 B21 P11 P12 P21 P22 P31 S1 S2 S3 S4 S5 KB G KBG

0 0 0 0 0 0 0 1 0 1 1 1 0 1 1

0 0 0 0 0 0 1 1 0 1 0 1 0 1 1

… … … … …

0 1 0 0 0 0 0 1 1 1 0 1 0 1 1

0 1 0 0 0 0 1 1 1 1 1 1 1 1 1

0 1 0 0 0 1 0 1 1 1 1 1 1 1 1

0 1 0 0 0 1 1 1 1 1 1 1 1 1 1

0 1 0 0 1 0 0 1 1 0 0 1 0 1 1

… … … … …

1 1 1 1 1 1 1 0 1 1 1 0 0 0 1

Page 27: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Inference by enumeration properties

• The truth table method of inference is complete for Propositional Logic because we can always enumerate all 2N rows for the N propositional symbols that occur.

• But this is exponential in N. In general, it has been shown that the problem of checking if a set of sentences in PL is satisfiable is NP-complete.

• Can be implemented using which search procedure?– Depth-first search.

• (The truth table method of inference is not complete for First-Order Logic.)

Page 28: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Inference procedures

• Inference methods1. Model checking

– Enumeration (seen previously)– Improved backtracking & local search

2. Inference using sound rules of inference• Derive new sentences that are true in all cases where premises are true.

E.g., ( P = 1 and PQ = 1 ) Q = 1• Construct a proof that a given sentence G can be derived from KB using

a sequence of inference rules• Rules R are sound if, for a KB and sentence G, KB |- G under rules R

implies KB |= G• If when KB |= G there exists a proof of G from KB using R, then the R is

complete• If R is sound and complete we can prove entailment by searching

for a proof

Page 29: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

(Some) Sound rules of inference

Name Premise(s) Derived sentence

Modus ponens(mode that affirms)

A, AB B

And introductions A, B AB

And elimination AB A

Double negations A A

Unit resolutions AB, B A

Resolution AB, B C A C

Equivalence elimination

AB (A B) (B A)

Page 30: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Using SRI in Wumpus world

1. S1: B11

S2: B21

S3: B11 ( P12 P21 ) KB

S4: B21 ( P11 P22 P31 )S5: P11

2. S6: (B11(P12P21))( P12P21)B11) S3 & equivalence elimin.

3. S7: (P12P21)B11 S6 & and elimination

4. S8: B11 ( P12 P21 ) S7 & negation

5. S9: ( P12 P21 ) S1, S8, & modus ponens

6. S10: P12 P21 S9 & DeMorgan

• Monotonicity property: • adding new sentences to a KB does not change entailment

( KB |= G KB S |= G ). It can only lead to new conclusions.

Page 31: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Inference using Resolution

• A single rule sufficient for complete inference procedure, when coupled with a complete search algorithm

( A B, A) leads to B ( A B, A C) leads to B C

Page 32: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Resolution in Wumpus world

• Continue from previous example by moving A into (1,2) and not feeling breeze

1. S1: B11, S2: B21, S3: B11 ( P12 P21 ), S4: B21 ( P11 P22 P31 ), S5: P11 KB

2. S10: P12 P21 previously inferred

3. S11: B12 percept

4. S12: B12 ( P11 P22 P13 ) rule

5. S13: P22 S11 & S12 & equiv. elim., add elim, modus ponens

6. S14: P13

7. S15: P11 P22 P31 S4 & S2 & equiv. elim. & modus ponens

8. S16: P11 P31 S15, S13 & resolution

9. S17: P31 S16, S5 & resolution

Page 33: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Resolution algorithm & CNF

• How to effectively use resolution? It only applies to disjunctions of symbols.

• CNF: conjunctive normal forms– Every KB can be represented as a CNF

– Every sentence can be represented as a conjunction of disjunctions of literals

• Method:1. Eliminate equivalences (conjunction of implications)

2. Eliminate implications (disjunctions of negation & symbols/sent)

3. Propagate negations to literals (DeMorgan)

4. Done!

Page 34: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

CNF in Wumpus world

1. S3: B11 ( P12 P21 )

2. ( B11 ( P12 P21 ) ) ( ( P12 P21 ) B11 )

3. ( B11 ( P12 P21 ) ) (( P12 P21 ) B11 )

4. ( B11 P12 P21 ) ( ( P12 P21 ) B11 )

5. ( B11 P12 P21 ) ( P12 B11 ) ( P21 B11 )

6. :CNF

Page 35: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Resolution refutation algorithm

• Relies on proof by contradiction (refutation):Assume goal sentence is false, prove KB does not hold.

• Remember, KB |= G iff KB G is unsatisfiable, i.e., KB G = {}

• Algorithm:1. Convert all sentences in KB to CNFs

2. Resolve all pairs of CNFs into new clauses

3. Check for contradiction

– Resolution refutation is complete

Page 36: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Resolution refutation in Wumpus world

KB G

Page 37: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Special case: Horn clauses and forward- backward chaining

• Restricted set of clauses: Horn clauses

disjunction of literals where at most one is positive, e.g.,A B C or A B

• Why Horn clauses?– Every Horn clause can be written as an implication, e.g.,

A B C = ( A B ) C = ( A B ) C A B = ( A B ) = ( A B ) 0 (integrity constraint)

– Inference in Horn clauses can be done using forward-backward (F-B) chaining in linear time

Page 38: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Example of FC

Page 39: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

How good is PL as a representational language?

• Not very expressive

– Cannot express complex environments concisely

– E.g., need to write separate rules for every square in Wumpus world even though they do not change from square to square

Bij ( Pi,j-1 Pi,j+1 Pi-1,j Pi+1,j ), for all (i,j)

– E.g., to specify there is exactly one wumpus in the world, need to specify• There is at least one: ?

• There is at most one: ?

Page 40: Rutgers CS440, Fall 2003 Propositional Logic Reading: Ch. 7, AIMA 2 nd Ed. (skip 7.6-7.7)

Rutgers CS440, Fall 2003

Announcement

• New assignment type: mini project-presentations

• Prepared by a team of two students• Related to a topic discussed in class• Presented in class, 15-20 mins• Will be graded, 15% of total grade

(new grade distribution: final 30%, midterm 30%, hw 25%, presentation 15%)

• First presentation:Oct 15, Bayesian network software

• Prepare slides and handouts (web page, pdf file is ok) for the class