65
CS:4420 Artificial Intelligence Spring 2017 Propositional Logic Cesare Tinelli The University of Iowa Copyright 2004–17, Cesare Tinelli and Stuart Russell a a These notes were originally developed by Stuart Russell and are used with permission. They are copyrighted material and may not be used in other course settings outside of the University of Iowa in their current or modified form without the express written consent of the copyright holders. CS:4420 Spring 2017 – p.1/49

Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

CS:4420 Artificial IntelligenceSpring 2017

Propositional Logic

Cesare Tinelli

The University of Iowa

Copyright 2004–17, Cesare Tinelli and Stuart Russell a

aThese notes were originally developed by Stuart Russell and are used with permission. They are

copyrighted material and may not be used in other course settings outside of the University of Iowa in their

current or modified form without the express written consent of the copyright holders.

CS:4420 Spring 2017 – p.1/49

Page 2: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Readings

• Chap. 7 of [Russell and Norvig, 2012]

CS:4420 Spring 2017 – p.2/49

Page 3: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Logics

A logic is a triple 〈L,S,R〉 where

• L, the logic’s language, is a class of sentences described by aformal grammar

• S, the logic’s semantics is a formal specification of how to assignmeaning in the“real world” to the elements of L

• R, the logic’s inference system, is a set of formal derivation rules

over L

There are several logics: propositional, first-order, higher-order, modal,temporal, intuitionistic, linear, equational, non-monotonic, fuzzy, . . .

We will concentrate on propositional logic and first-order logic

CS:4420 Spring 2017 – p.3/49

Page 4: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Propositional Logic

Each sentence is made of

• propositional variables (A,B, . . . , P,Q, . . .)

• logical constants (True,False)

• logical connectives (∧,∨,⇒, . . .)

Every propositional variable stands for a basic fact

Examples: I’m hungry, Apples are red, Joe and Jill are married

CS:4420 Spring 2017 – p.4/49

Page 5: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Propositional Logic

Ontological CommitmentsPropositional Logic is about facts in the world that are either true orfalse, nothing else

Semantics of Propositional LogicSince each propositional variable stands for a fact about the world, itsmeaning ranges over the Boolean values {true, false}

Note: Do note confuse

• true, false, which are values (i.e., semantical entities) here with

• True, False, which are logical constants (i.e., symbols of thelanguage)

CS:4420 Spring 2017 – p.5/49

Page 6: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Propositional Logic

The Language

• Each propositional variable (A,B, . . . , P,Q, . . .) is a sentence

• Each logical constant (True,False) is a sentence

• If ϕ and ψ are sentences, all of the following are also sentences

(ϕ) ¬ϕ ϕ ∧ ψ ϕ ∨ ψ ϕ⇒ ψ ϕ⇔ ψ

• Nothing else is a sentence

CS:4420 Spring 2017 – p.6/49

Page 7: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

The Language of Propositional Logic

More formally, it is the language generated by the following grammar

Symbols:

• Propositional variables: A,B, . . . , P,Q, . . .

• Logical constants:

True (true) ∧ (and) ⇒ (implies) ¬ (not)

False (false) ∨ (or) ⇔ (equivalent)

Grammar Rules:

Sentence ::= AtomicS | ComplexS

AtomicS ::= True | False | A | B | . . . | P | Q | . . .

ComplexS ::= (Sentence) | Sentence Connective Sentence | ¬Sentence

Connective ::= ∧ | ∨ | ⇒ | ⇔

CS:4420 Spring 2017 – p.7/49

Page 8: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

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]

“Pits cause breezes in adjacent squares”

¬P1,1

¬A

B2,1

CS:4420 Spring 2017 – p.8/49

Page 9: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

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]

“Pits cause breezes in adjacent squares”

¬P1,1

¬A

B2,1

“A square is breezy if and only if there is an adjacent pit”

A ⇔ (B ∨ C)

B2,1 ⇔ (P1,1 ∨ P2,2 ∨ P3,1)

CS:4420 Spring 2017 – p.8/49

Page 10: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Semantics of Propositional Logic

The meaning of True is always trueThe meaning of False is always false

The meaning of the other sentences depends on the meaning of thepropositional variables

• Base cases: truth tables

P Q ¬P P ∧Q P ∨Q P⇒Q P⇔Q

false false true false false true true

false true true false true true false

true false false false true false false

true true false true true true true

• Non-base Cases: given by reduction to the base cases

Ex: the meaning of (P ∨Q) ∧R is the same as the meaning ofA ∧R where A has the same meaning as P ∨Q

CS:4420 Spring 2017 – p.9/49

Page 11: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Semantics of Propositional Logic

An assignment of Boolean values to the propositional variables of asentence is an interpretation of the sentence

P H P _H (P _H) ^:H ((P _H) ^ :H) ) P

False False False False TrueFalse True True False TrueTrue False True True TrueTrue True True False True

Interpretations: {P 7→ false, H 7→ false}, {P 7→ false, H 7→ true}, . . .

The semantics of Propositional Logic is compositional:the meaning of a sentence is defined recursively in terms of themeaning of the sentence’s components

CS:4420 Spring 2017 – p.10/49

Page 12: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Semantics of Propositional Logic

The meaning of a sentence in general depends on its interpretation

Some sentences, however, have always the same meaning

P H P _H (P _H) ^:H ((P _H) ^ :H) ) P

False False False False TrueFalse True True False TrueTrue False True True TrueTrue True True False True

A sentence is

• satisfiable if it is true in some interpretation

• unsatisfiable if it is true in no interpretation

• valid if it is true in every possible interpretation

• invalid if it is false in some possible interpretation

CS:4420 Spring 2017 – p.11/49

Page 13: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

A Warning

Disjunction

• A ∨B is true when A or B or or both are true (inclusive or)

• A⊕B is sometimes used to mean“either A or B but not both”(exclusive or)

Implication

• A⇒ B does not require a causal connection between A and BEx: Sky-is-blue ⇒ Snow-is-white

• When A is false, A⇒ B is always true regardless of BEx: Two-equals-four ⇒ Apples-are-red

• Beware of negations in implicationsEx: Is-a-female-bird ⇒ Lays-eggs

¬Is-a-female-bird ⇒ ¬lays-eggs

CS:4420 Spring 2017 – p.12/49

Page 14: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Entailment in Propositional Logic

Given

• a set Γ of sentences and

• a sentence ϕ,

we write

Γ |= ϕ

iff every interpretation that makes all sentences in Γ true makes ϕ alsotrue

Γ |= ϕ is read as“Γ entails ϕ”or“ϕ logically follows from Γ”

CS:4420 Spring 2017 – p.13/49

Page 15: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Entailment in Propositional Logic

Examples

{A,A⇒ B} |= B

{A} |= A ∨B

{A,B} |= A ∧B

{} |= A ∨ ¬A

{A} 6|= A ∧B

{A ∨ ¬A} 6|= A

A B A⇒ B A ∨B A ∧B A ∨ ¬A

1. false false true false false true

2. false true true true false true

3. true false false true false true

4. true true true true true true

CS:4420 Spring 2017 – p.14/49

Page 16: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Properties of Entailment

• Γ |= ϕ, for all ϕ ∈ Γ (inclusion property of PL)

• if Γ |= ϕ, then Γ′ |= ϕ for all Γ′ ⊇ Γ (monotonicity of PL)

• ϕ is valid iff { } |= ϕ (also written as |= ϕ)

• ϕ is unsatisfiable iff ϕ |= False

• Γ |= ϕ iff the set Γ ∪ {¬ϕ} is unsatisfiable

CS:4420 Spring 2017 – p.15/49

Page 17: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Logical Equivalence

Two sentences ϕ1 and ϕ2 are logically equivalent, written

ϕ1 ≡ ϕ2

if ϕ1 |= ϕ2 and ϕ2 |= ϕ1

Note:

• ϕ1 ≡ ϕ2 if and only if every interpretation assigns the sameBoolean value to ϕ1 and ϕ2

• Implication and equivalence (⇒, ⇔), which are syntacticalentities, are intimately related to entailment and logicalequivalence (|=, ≡), which are semantical notions:

ϕ1 |= ϕ2 iff |= ϕ1 ⇒ ϕ2

ϕ1 ≡ ϕ2 iff |= ϕ1 ⇔ ϕ2

CS:4420 Spring 2017 – p.16/49

Page 18: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Properties of Logical Connectives

• ∧ and ∨ are commutativeϕ1 ∧ ϕ2 ≡ ϕ2 ∧ ϕ1

ϕ1 ∨ ϕ2 ≡ ϕ2 ∨ ϕ1

• ∧ and ∨ are associative

ϕ1 ∧ (ϕ2 ∧ ϕ3) ≡ (ϕ1 ∧ ϕ2) ∧ ϕ3

ϕ1 ∨ (ϕ2 ∨ ϕ3) ≡ (ϕ1 ∨ ϕ2) ∨ ϕ3

• ∧ and ∨ are mutually distributive

ϕ1 ∧ (ϕ2 ∨ ϕ3) ≡ (ϕ1 ∧ ϕ2) ∨ (ϕ1 ∧ ϕ3)

ϕ1 ∨ (ϕ2 ∧ ϕ3) ≡ (ϕ1 ∨ ϕ2) ∧ (ϕ1 ∨ ϕ3)

• ∧ and ∨ are related by ¬ (DeMorgan’s Laws)

¬(ϕ1 ∧ ϕ2) ≡ ¬ϕ1 ∨ ¬ϕ2

¬(ϕ1 ∨ ϕ2) ≡ ¬ϕ1 ∧ ¬ϕ2

CS:4420 Spring 2017 – p.17/49

Page 19: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Properties of Logical Connectives

∧, ⇒, and ⇔ are actually redundant:

ϕ1 ∧ ϕ2 ≡ ¬(¬ϕ1 ∨ ¬ϕ2)

ϕ1 ⇒ ϕ2 ≡ ¬ϕ1 ∨ ϕ2

ϕ1 ⇔ ϕ2 ≡ (ϕ1 ⇒ ϕ2) ∧ (ϕ2 ⇒ ϕ1)

We keep them all mainly for convenience

Exercise Use the truth tables to verify all the logical equivalences seenso far

CS:4420 Spring 2017 – p.18/49

Page 20: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Inference Systems for Propositional Logic

An inference system I for PL is a procedure that

given a set Γ = {α1, . . . , αm} of sentences and a sentence ϕ,may reply“yes”,“no”, or run forever

If I replies positively to input (Γ, ϕ), we say that Γ derives ϕ in I (or,I derives ϕ from Γ, or, ϕ derives from Γ in I) and write

Γ ⊢I ϕ

Intuitively, I should be such that it replies“yes”on input (Γ, ϕ)only if ϕ is in fact entailed by Γ

CS:4420 Spring 2017 – p.19/49

Page 21: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

All These Fancy Symbols!

Note:

A ∧B ⇒ C is a sentence, a bunch of symbols manipulated by aninference system I

A∧B |= C is a mathematical abbreviation standing for the statement:“every interpretation that makes A ∧B true, makes C also true”

A ∧B ⊢I C is a mathematical abbreviation standing for thestatement: “I derives C from A ∧B”

In other words,

⇒ is a formal symbol of the logic, which is used by the inferencesystem

|= is a shorthand we use to talk about the meaning of formalsentences

⊢I is a shorthand we use to talk about the output of the inferencesystem I

CS:4420 Spring 2017 – p.20/49

Page 22: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

All These Fancy Symbols!

The connective ⇒ and the shorthand |= are related as follows

The sentence ϕ1 ⇒ ϕ2 is valid (always true) if and only if ϕ1 |= ϕ2

Example: A⇒ (A ∨B) is valid and A |= (A ∨B)

A B A ∨B A⇒ (A ∨B)

1. false false false true

2. false true true true

3. true false true true

4. true true true true

CS:4420 Spring 2017 – p.21/49

Page 23: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

All These Fancy Symbols!

The shorthands |= and ⊢I are related as follows

• A sound inference system can derive only sentences that logicallyfollow from a given set of sentences:

if Γ ⊢I ϕ then Γ |= ϕ

• A complete inference system can derive all sentences thatlogically follow from a given set of sentences:

if Γ |= ϕ then Γ ⊢I ϕ

CS:4420 Spring 2017 – p.22/49

Page 24: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Inference systems for PL

Divided into (roughly) two kinds:

Rule-based

• Sound generation of new sentences from old

• Proof = a sequence of inference rule applicationsCan use inference rules as operators as in a standard searchprocedures

• Typically require translation of sentences into some normal form

Model-based

• Truth table enumeration (always exponential in n)

• Improved backtracking, e.g., Davis–Putnam–Logemann–Loveland

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

CS:4420 Spring 2017 – p.23/49

Page 25: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Truth table enumeration

The proof system T T is specified as follows:

{α1, . . . , αm} ⊢T T ϕ iff all the values in the truth table of

(α1 ∧ · · · ∧ αm)⇒ ϕ are true

CS:4420 Spring 2017 – p.24/49

Page 26: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Inference by Truth Tables• The truth-tables-based inference system is sound:

α1, . . . , αm ⊢T T ϕ implies truth table of (α1 ∧ · · · ∧ αm) ⇒ ϕ all true

implies (α1 ∧ · · · ∧ αm) ⇒ ϕ is valid

implies |= (α1 ∧ · · · ∧ αm) ⇒ ϕ

implies (α1 ∧ · · · ∧ αm) |= ϕ

implies α1, . . . , αm |= ϕ

• It is also complete (exercise: prove it)

• Its time complexity is O(2n) where n is the number ofpropositional variables in α1, . . . , αm, ϕ

• We cannot hope to do better in general because the dualproblem: determining the satisfiability of a sentence, isNP-complete

• However, really hard cases of propositional inference aresomewhat rare in practice

CS:4420 Spring 2017 – p.25/49

Page 27: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Rule-Based Inference in PL

An inference system in Propositional Logic can also be specified as aset R of inference (or derivation) rules

• Each rule is just a pattern premises/conclusion

• A rule applies to Γ and derives ϕ if• some of the sentences in Γ match with the premises of the

rule and

• ϕ matches with the conclusion

• A rule is sound it the set of its premises entails its conclusion

CS:4420 Spring 2017 – p.26/49

Page 28: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Some Inference Rules

• And-Introduction

α β

α ∧ β

• And-Eliminationα ∧ β

α

α ∧ β

β

• Or-Introductionα

α ∨ β

α

β ∨ α

CS:4420 Spring 2017 – p.27/49

Page 29: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Some Inference Rules (cont’d)

• Implication-Elimination (aka Modus Ponens)

α⇒ β α

β

• Unit Resolutionα ∨ β ¬β

α

• Resolutionα ∨ β ¬β ∨ γ

α ∨ γor, equivalently,

¬α⇒ β, β ⇒ γ

¬α⇒ γ

CS:4420 Spring 2017 – p.28/49

Page 30: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Some Inference Rules (cont’d)

• Double-Negation-Elimination

¬¬α

α

• False-Introductionα ∧ ¬α

False

• False-Elimination

False

β

CS:4420 Spring 2017 – p.29/49

Page 31: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Inference by Proof

We say there is a proof of ϕ from Γ in an inference system R if wecan derive ϕ by applying the rules of R repeatedly to Γ and its derivedsentences

Example: a proof of P from {(P ∨H) ∧ ¬H}

1. (P ∨H) ∧ ¬H by assumption

2. P ∨H by ∧-elimination applied to (1)

3. ¬H by ∧-elimination applied to (1)

4. P by unit resolution applied to (2),(3)

We can represent a proof more visually as a proof tree:

Example:

(P ∨H) ∧ ¬H

P ∨H

(P ∨H) ∧ ¬H

¬H

P

CS:4420 Spring 2017 – p.30/49

Page 32: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Rule-Based Inference in Propositional Logic

More precisely, there is a proof of ϕ from Γ in R if

1. ϕ ∈ Γ or,

2. there is a rule in R that applies to Γ and produces ϕ or,

3. there is a proof of each ϕ1, . . . , ϕm from Γ in R anda rule that applies to {ϕ1, . . . , ϕm} and produces ϕ

Then, the inference system R is specified as follows:

Γ ⊢R ϕ iff there is a proof of ϕ from Γ in R

CS:4420 Spring 2017 – p.31/49

Page 33: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

An Inference System R

α β

α ∧ β

α

α ∨ β

α

β ∨ α

α ∧ β

α

α ∧ β

β

α⇒ β α

β

α ∨ β ¬β

α

α ∨ β ¬β ∨ γ

α ∨ γ

¬¬α

α

α ∧ ¬α

False

False

β

CS:4420 Spring 2017 – p.32/49

Page 34: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Soundness of R

The given system R is sound because all of its rules are

Example: the Resolution ruleα ∨ β, ¬β ∨ γ

α ∨ γ

α β γ ¬β α ∨ β ¬β ∨ γ α ∨ γ

1. false false false true false true false

2. false false true true false true true

3. false true false false true false false

4. false true true false true true true

5. true false false true true true true

6. true false true true true true true

7. true true false false true false true

8. true true true false true true true

All the interpretations that satisfy both α ∨ β and ¬β ∨ γ (4,5,6,8) satisfy α ∨ γ as well

CS:4420 Spring 2017 – p.33/49

Page 35: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Soundness of R

The given system R is sound because all of its rules are

Exercise: prove that the other inference rules are sound as well

Is R also complete?

CS:4420 Spring 2017 – p.33/49

Page 36: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Resolution

Literal: prop. symbol (P ) or negated prop. symbol (¬P )

Clause: set of literals {l1, . . . , lk} (understood as l1 ∨ · · · ∨ lk)

Conjunctive Normal Form: set of clauses {C1, . . . , Cn} (understood asC1 ∧ · · · ∧ Cn)

Resolution rule for CNF:

l1 ∨ · · · ∨ lk ∨ P ¬P ∨m1 ∨ · · · ∨mn

l1 ∨ · · · ∨ lk ∨m1 ∨ · · · ∨mn

E.g.,

P ∨Q ¬Q

P

P ∨Q R ∨ ¬Q ∨ ¬S

P ∨R ∨ ¬S

P ∨Q ¬Q ∨ P ∨R

P ∨R

Resolution is sound and complete for CNF KBs

CS:4420 Spring 2017 – p.34/49

Page 37: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Conversion to CNF

Ex.: A⇔ (B ∨ C)

1. Eliminate ⇔, replacing α⇔ β with (α⇒ β) ∧ (β ⇒ α)

(A⇒ (B ∨ C)) ∧ ((B ∨ C)⇒ A)

2. Eliminate ⇒, replacing α⇒ β with ¬α ∨ β

(¬A ∨B ∨ C) ∧ (¬(B ∨ C) ∨ A)

3. Move ¬ inwards using de Morgan’s rules and double-negation

(¬A ∨B ∨ C) ∧ ((¬B ∧ ¬C) ∨ A)

4. Apply distributivity law (∨ over ∧) and flatten

(¬A ∨B ∨ C) ∧ (¬B ∨A) ∧ (¬C ∨A)

CS:4420 Spring 2017 – p.35/49

Page 38: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Resolution Procedure

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

function PL-Resolution(KB,α) returns true or false

clauses← the set of clauses in the CNF representation of KB ∧ ¬α

new←{}

loop do

for each Ci, Cj in clauses do

resolvents←PL-Resolve(Ci,Cj)

if resolvents contains the empty clause then return true

new←new ∪ resolvents

if new ⊆ clauses then return false

clauses← clauses ∪ new

CS:4420 Spring 2017 – p.36/49

Page 39: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Resolution example

KB = { B1,1 ⇔ (P1,2 ∨ P2,1), ¬B1,1 }

α = ¬P1,2

CNF = { ¬P1,2 ∨B1,1, ¬B1,1 ∨ P1,2 ∨ P2,1, ¬P1,2 ∨B1,1,

¬B1,1, P1,2}

P1,2

P1,2

P2,1

P1,2 B1,1

B1,1 P2,1 B1,1 P1,2 P2,1 P2,1P1,2B1,1 B1,1

P1,2B1,1 P2,1B1,1P2,1 B1,1

P1,2 P2,1 P1,2

CS:4420 Spring 2017 – p.37/49

Page 40: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Forward and backward chaining

Horn clause: prop. symbol (p) or implication p1 ∧ · · · ∧ pn ⇒ p

Horm Form: set of Horn clauses {C1, . . . , Cn} (understood asC1 ∧ · · · ∧ Cn)

E.g., { C, B ⇒ A, C ∧D ⇒ B }

Modus Ponens for Horn Form

α1 · · · αn α1 ∧ · · · ∧ αn ⇒ β

β

Sound and complete for Horn Form KBs

Can be used with forward chaining or backward chaining

These algorithms are very natural and run in linear time

CS:4420 Spring 2017 – p.38/49

Page 41: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Forward chaining

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

Ex.:

P =⇒ Q

L ∧M =⇒ P

B ∧ L =⇒ M

A ∧ P =⇒ L

A ∧B =⇒ L

A

B

Q

P

M

L

BA

CS:4420 Spring 2017 – p.39/49

Page 42: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Forward chaining algorithm

function PL-FC-Entails?(KB, q) returns true or false

count, a table, indexed by clause, initially the number of premises

inferred, a table, indexed by symbol, each entry initially false

agenda, a list of symbols, initially the symbols known to be true

while agenda is not empty do

p←Pop(agenda)

unless inferred[p] do

inferred[p]← true

for each Horn clause c in whose premise p appears do

decrement count[c]

if count[c] = 0 then do

if Head[c] = q then return true

Push(Head[c],agenda)

return false

CS:4420 Spring 2017 – p.40/49

Page 43: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Forward chaining example

Q

P

M

L

BA

2 2

2

2

1

CS:4420 Spring 2017 – p.41/49

Page 44: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Forward chaining example

Q

P

M

L

B

2

1

A

1 1

2

CS:4420 Spring 2017 – p.41/49

Page 45: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Forward chaining example

Q

P

M

2

1

A

1

B

0

1L

CS:4420 Spring 2017 – p.41/49

Page 46: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Forward chaining example

Q

P

M

1

A

1

B

0

L0

1

CS:4420 Spring 2017 – p.41/49

Page 47: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Forward chaining example

Q

1

A

1

B

0

L0

M

0

P

CS:4420 Spring 2017 – p.41/49

Page 48: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Forward chaining example

Q

A B

0

L0

M

0

P

0

0

CS:4420 Spring 2017 – p.41/49

Page 49: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Proof of completeness

FC derives every atomic sentence that is entailed by KB

1. FC reaches a fixed point where no new atomic sentences(prop. symbols) are inferred

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

3. Claim: Every clause in the original KB is satisfied by m

Proof: Suppose a clause a1 ∧ . . . ∧ ak ⇒ b is falsified by mThen a1 ∧ . . . ∧ ak is satisfied by m while b is notBut then b what not inferred, contradicting the assumption thatthe algorithm had reached a fixed point!

4. Hence m is a model of KB

5. 5. If KB |= q, q is true in every model of KB, including m

CS:4420 Spring 2017 – p.42/49

Page 50: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Backward chaining

Idea: work backwards from the query q

to infer q by BC,check if q is known already, orinfer 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 subgoal

1. has already been inferred, or

2. has already failed

CS:4420 Spring 2017 – p.43/49

Page 51: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Backward chaining example

Q

P

M

L

A B

CS:4420 Spring 2017 – p.44/49

Page 52: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Backward chaining example

P

M

L

A

Q

B

CS:4420 Spring 2017 – p.44/49

Page 53: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Backward chaining example

M

L

A

Q

P

B

CS:4420 Spring 2017 – p.44/49

Page 54: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Backward chaining example

M

A

Q

P

L

B

CS:4420 Spring 2017 – p.44/49

Page 55: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Backward chaining example

M

A

Q

P

L

B

CS:4420 Spring 2017 – p.44/49

Page 56: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Backward chaining example

M

A

Q

P

L

B

CS:4420 Spring 2017 – p.44/49

Page 57: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Backward chaining example

A

Q

P

L

B

M

CS:4420 Spring 2017 – p.44/49

Page 58: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Backward chaining example

A

Q

P

L

B

M

CS:4420 Spring 2017 – p.44/49

Page 59: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Backward chaining example

A

Q

P

L

B

M

CS:4420 Spring 2017 – p.44/49

Page 60: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Backward chaining example

A

Q

P

L

B

M

CS:4420 Spring 2017 – p.44/49

Page 61: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Forward vs. Backward Chaining

FC is data-driven, cf. 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

CS:4420 Spring 2017 – p.45/49

Page 62: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

Model Checking methods

The most effective procedures for propositional satisfiability are basedon CSP techniques

Variable domain: {true, false}

Constraints: sets of clauses

Heuristic Improvements:

• unit propagation

• variable and value ordering

• intelligent backtracking

• clause learning

• random restarts

• clever indexing

• subproblem decomposition

CS:4420 Spring 2017 – p.46/49

Page 63: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

DPLL Procedure

function DPLL-Satisfiable?(s) returns true or false

inputs: s, a sentence in propositional logic

clauses← the set of clauses in the CNF representation of s

symbols← a list of the proposition symbols in s

return DPLL(clauses, symbols, [ ])

CS:4420 Spring 2017 – p.47/49

Page 64: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

DPLL Procedure (cont.)

function DPLL(clauses, symbols,model) returns true or false

if every clause in clauses is satisfied by model then return true

if some clause in clauses is falsified by model then return false

P, value←Find-Pure-Symbol(symbols, clauses,model)

if P is non-null then

return DPLL(clauses, symbols - P, (P 7→ value) :: model)

P, value←Find-Unit-Clause(clauses,model)

if P is non-null then

return DPLL(clauses, symbols - P, (P 7→ value) :: model)

P←First(symbols)

rest←Rest(symbols)

return DPLL(clauses, rest, (P 7→ true) :: model) or

DPLL(clauses, rest, (P 7→ false) :: model)

CS:4420 Spring 2017 – p.48/49

Page 65: Propositional Logic - University of Iowahomepage.cs.uiowa.edu/~tinelli/classes/4420/Spring17/notes/7.1-logic.pdf · Logics A logic is a triple hL,S,Riwhere •L, the logic’s language,

DPLL Exercise

(1) ¬p1 ∨ p2 (2) ¬p3 ∨ p4 (3) ¬p6 ∨ ¬p5 ∨ ¬p2

(4) ¬p5 ∨ p6 (5) p5 ∨ p7 (6) ¬p1 ∨ p5 ∨ ¬p7

CS:4420 Spring 2017 – p.49/49