Propositional Logic

Louis Oliphant

oliphant@cs.wisc.edu

cs540 section 2

Logic Defined
(by dictionary.com)

Logic - The study of the principles of reasoning, especially of the structure of propositions as distinguished from their content and of method and validity in deductive reasoning.

Several types of logic:

propositional logic (boolean logic)

first order logic (first order predicate calculus)

Important Concepts

Structure of Propositions

syntax : what is a correctly formed string

semantics : What do correctly formed strings “mean”

Principles of Reasoning

entailment : Given some knowledge() what logically follows()

Socrates is a man

All men are mortal

Socrates is mortal

╞ 

Syntax

((P  ((True  R)Q))  S) well formed

((P  Q)   S) not well formed

Sentence		AtomicSentence | ComplexSentence

AtomicSentence		True | False | Symbol

Symbol		P | Q | R | . . .

ComplexSentence		Sentence

|	( Sentence  Sentence )

|	( Sentence  Sentence )

|	( Sentence  Sentence )

|	( Sentence  Sentence )

BNF grammar in propositional logic

Semantics

((P  ((True  R)Q))  S)

Means True

Means “Not”

Means “Or” -- disjunction

Means “And” -- conjunction

Means “iff” -- biconditional

Means “if” -- implication

() control the order of operations

Propositional symbols must be specified

Semantics—Order of Operations

You can leave off parenthesis if the order of operations is clear

Order precedence is (from highest to lowest):
, , , , 

P  True  RQ  S	ok

P  Q  S	not ok

Semantics – Propositional Symbols

Propositional Symbols must be specified by a model

Model: specified directly

Calculated using the meaning of connectives

Figuring out the meaning of Sentences

P  Q R  Q

Satisfiable: Sentences that are true under some model

Note:This is an NP-hard problem O(2n)

n=number of

symbols

Figuring out the meaning of Sentences

(P  R  Q)  P  R  Q

unsatisfiable: Sentences that are false under all models

Figuring out the meaning of Sentences

(P  Q)  P  Q

You Figure It Out

Figuring out the meaning of Sentences

(P  Q)  P  Q

valid: Sentences that are true under all models (tautology)

Logical Equivalences

Know and use these equivalences to modify sentences

Inference

The act or process of deriving logical conclusions from premises known or assumed to be true. (dictionary.com)

  , 



Modus Ponens

a  b

a

And-Elimination

All Logical Equivalences can be used as inference mechanism

Proof

Series of inference steps that lead from an initial state to the goal state (one method of proving)

given a: B1,1  (P1,2  P2,1)

given b: B1,1

goal: P1,2

Knowledge Base (KB)

Query

Proof

Series of inference steps that lead from an initial state to the goal state (one method of proving)

given a: B1,1  (P1,2  P2,1)

given b: B1,1

goal: P1,2

1) (B1,1  (P1,2  P2,1))  ((P1,2  P2,1)  B1,1 )	biconditional elimination to (a)

2) ((P1,2  P2,1)  B1,1 )	and-elimination to (1)

3) B1,1 (P1,2  P2,1)	controposition to (2)

4) (P1,2  P2,1)	modus ponens to (3 and b)

5) P1,2  P2,1)	de Morgan's rule to (4)

and-elimination to (5)

How would a computer go about this? Can we simplify inference and still find the goal?

Maintaining Accuracy

Sound – inference algorithm that derives only “true” sentences

Complete – inference algorithm that can derive any “true” sentence

Resolution is all you need

Resolution is another inference rule

It alone is sound and complete*
(but you have to get your sentences in the right form)
(luckily all sentences can be converted to this form)

* -- refutation complete – it can answer any question you ask it,

but it can't list out all things that are true.

Conjunctive Normal Form (CNF)

Here's how you convert any sentence to CNF:

Replace all  using biconditional elimination

Replace all  using implication elimination

Move all negations inward using
-double-negation elimination
-de Morgan's rule

Apply distributivity of  over 

Let's Try It!

Converting to CNF

B1,1  (P1,2  P2,1)	starting sentence

(B1,1  (P1,2  P2,1))  ((P1,2  P2,1)  B1,1 )	biconditional elimination

(B1,1  P1,2  P2,1)  ((P1,2  P2,1)  B1,1 )	implication elimination

(B1,1  P1,2  P2,1)  ((P1,2  P2,1)  B1,1 )	move negations inward

(B1,1  P1,2  P2,1)  (P1,2  B1,1)  (P2,1  B1,1)	distribute  over 

This is in Conjunctive Normal Form

(now why did we do this again?)

To use resolution

clauses

Resolution

Remember Resolution is refutation complete. You have to ask a question (query) of the given knowledge base.

The query needs to be in CNF form

Resolution works using proof by contradiction

KB	 knoweldge base

a	 query

KB╞ a	 does the knowledge base entail a

show KBa leads to a contradiction

Proof

Series of inference steps that lead from an initial state to the goal state (one method of proving)

given a: B1,1  (P1,2  P2,1)

given b: B1,1

goal: P1,2

Proof

Series of resolution inference steps that lead from an initial state(KB  a) to the False state (proof by contradiction)

given a: (B1,1  P1,2  P2,1)  (P1,2  B1,1)  (P2,1  B1,1)

given b: B1,1

given c: P1,2

goal: □

False

in CNF form

Write this as three

seperate clauses

Proof

Series of resolution inference steps that lead from an initial state(KB  a) to the False state (proof by contradiction)

given a1: (B1,1  P1,2  P2,1)

given a2: (P1,2  B1,1)

given a3: (P2,1  B1,1)

given b: B1,1

given c: P1,2

goal: □

Setup Complete.

(Now all you need to know is resolution

to fill in the missing lines.)

Resolution (finally)

Take any two clauses that have a symbol and its complement (negative)
PQR	QST

Combine the two clauses into one clause, omitting the symbol and its complement
PRST

If two clauses resolve and there are no symbols left then you have reached □, False.

Proof

Series of resolution inference steps that lead from an initial state(KB  a) to the False state (proof by contradiction)

given a1: (B1,1  P1,2  P2,1)

given a2: (P1,2  B1,1)

given a3: (P2,1  B1,1)

given b: B1,1

given c: P1,2

goal: □

1. P1,2	resolved a2 with b

resolved 1 with c

Can we turn this into an

algorithm a computer can do?

What if the KB doesn't entail a?

Resolution Algorithm

function resolution(KB,a) returns true or false

inputs:	KB, the knowledge base
a, the query

clauses  convert_to_CNF(KB  a)

new  {}

loop do
for each Ci,Cj in clauses do
resolvents  resolve(Ci,Cj)
if resolvents contains the empty clause then return true
new  new  resolvents
if new  clauses then return false
clauses  clauses  new

Evaluating Algorithm

Run Time

In worst case is still exponential

Often much faster

factoring: If a clause contains two of the same symbol, just delete one of them (keeps search tree finite)
PRPT gets changed to PRT

No need to resolve clauses that result in a symbol and its complement (these clauses will never help)

Horn Clauses

Disjunction of literals with at most one positive

Not as general as full propositional logic

Still can represent many real world problems

Reasoning is linear in the size of input

Uses Forward chaining or Backward chaining algorithm to reason

Only can ask atomic queries

Forward Chaining

Fire any rule whose premises are satisfied in the KB.

Add its conclusion to the KB until query is found.

Forward Chaining Example

P  Q

L  M  P

B  L  M

A  P  L

A  B  L

A

B

Forward Chaining Example

P  Q

L  M  P

B  L  M

A  P  L

A  B  L

A

B

Forward Chaining Example

P  Q

L  M  P

B  L  M

A  P  L

A  B  L

A

B

Forward Chaining Example

P  Q

L  M  P

B  L  M

A  P  L

A  B  L

A

B

Forward Chaining Example

P  Q

L  M  P

B  L  M

A  P  L

A  B  L

A

B

Forward Chaining Example

P  Q

L  M  P

B  L  M

A  P  L

A  B  L

A

B

Forward Chaining Example

P  Q

L  M  P

B  L  M

A  P  L

A  B  L

A

B

Forward Chaining Example

P  Q

L  M  P

B  L  M

A  P  L

A  B  L

A

B

Backward Chaining

Motivation: Need goal-directed reasoning in order to keep from getting overwhelmed with irrelevant consequences

Main idea:

Work backwards from query q

To prove q:

Check if q is known already

Prove by backward chaining all premises of some rule concluding q

Backward Chaining Example

P  Q

L  M  P

B  L  M

A  P  L

A  B  L

A

B

Backward Chaining Example

P  Q

L  M  P

B  L  M

A  P  L

A  B  L

A

B

Backward Chaining Example

P  Q

L  M  P

B  L  M

A  P  L

A  B  L

A

B

Backward Chaining Example

P  Q

L  M  P

B  L  M

A  P  L

A  B  L

A

B

Backward Chaining Example

P  Q

L  M  P

B  L  M

A  P  L

A  B  L

A

B

Backward Chaining Example

P  Q

L  M  P

B  L  M

A  P  L

A  B  L

A

B

Backward Chaining Example

P  Q

L  M  P

B  L  M

A  P  L

A  B  L

A

B

Backward Chaining Example

P  Q

L  M  P

B  L  M

A  P  L

A  B  L

A

B

Backward Chaining Example

P  Q

L  M  P

B  L  M

A  P  L

A  B  L

A

B

Backward Chaining Example

P  Q

L  M  P

B  L  M

A  P  L

A  B  L

A

B

Backward Chaining Example

P  Q

L  M  P

B  L  M

A  P  L

A  B  L

A

B

Forward Chaining vs. Backward Chaining

FC is data-driven—it may do lots of work irrelevant to the goal

BC is goal-driven—appropriate for problem-solving

What You Should Know

A ton of terms

Truth tables

Proofs

Converting to Conjunctive Normal Form

Proofs with Resolution (Proof by Contradiction)

Horn Clauses

Forward chaining algorithm

Backward chaining algorithm

Proving Satisfiability

DPLL (Davis-Putnam-Logemann, and Loveland)

Terminate search if you know it won't work

Fix symbols that only appear in one form

(all P or all ~P)

Fix symbols that appear alone in clauses

[P^(PvR)] -- Fix P to be true

GSAT (local search)

Works with complete solutions

Flip variable that decreases number of unsatisfied clauses the most

WalkSAT (local search)

Works with complete solutions

Picks clause that is not satisfied and flips a variable in clause (randomly or decreasing unsatisified clauses the most)

Comparing DPLL and WalkSAT
(on hard problems)

Project Ideas

Davis-Putnam with RRR, compare to DBLL, WalkSAT, and GSAT algorithms

2005-09-02T11:02:45