04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic...

30
Recap: Syntax and Semantics of Propositional Logic Questions Conjunctive Normal Form Algorithms for Satisfiability 04a—Propositional Logic II CS 3234: Logic and Formal Systems Martin Henz September 2, 2010 Generated on Thursday 2 nd September, 2010, 11:39 CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Transcript of 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic...

Page 1: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

04a—Propositional Logic II

CS 3234: Logic and Formal Systems

Martin Henz

September 2, 2010

Generated on Thursday 2nd September, 2010, 11:39

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 2: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

1 Recap: Syntax and Semantics of Propositional Logic

2 Questions

3 Conjunctive Normal Form

4 Algorithms for Satisfiability

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 3: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Propositional AtomsSyntax of Propositional LogicEvaluation of Formulas

1 Recap: Syntax and Semantics of Propositional LogicPropositional AtomsSyntax of Propositional LogicEvaluation of Formulas

2 Questions

3 Conjunctive Normal Form

4 Algorithms for Satisfiability

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 4: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Propositional AtomsSyntax of Propositional LogicEvaluation of Formulas

Atoms

ConventionWe usually use p, q, p1, etc, instead of sentences like “The sunis shining today”.

AtomsMore formally, we fix a set A of propositional atoms.

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 5: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Propositional AtomsSyntax of Propositional LogicEvaluation of Formulas

Meaning of Atoms

Models assign truth valuesA model assigns truth values (F or T ) to each atom.

More formallyA model (valuation) for a propositional logic for the set A ofatoms is a mapping from A to {T ,F}.

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 6: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Propositional AtomsSyntax of Propositional LogicEvaluation of Formulas

Inductive Definition

DefinitionFor a given set A of propositional atoms, the set of well-formedformulas in propositional logic is the least set F that fulfills thefollowing rules:

The constant symbols ⊥ and > are in F .Every element of A is in F .If φ is in F , then (¬φ) is also in F .If φ and ψ are in F , then (φ ∧ ψ) is also in F .If φ and ψ are in F , then (φ ∨ ψ) is also in F .If φ and ψ are in F , then (φ→ ψ) is also in F .

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 7: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Propositional AtomsSyntax of Propositional LogicEvaluation of Formulas

Parse trees

A formula(((¬p) ∧ q)→ (p ∧ (q ∨ (¬r))))

...and its parse tree: →

¬

p

q

p ∨

q ¬

r

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 8: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Propositional AtomsSyntax of Propositional LogicEvaluation of Formulas

Evaluation of Formulas

DefinitionThe result of evaluating a well-formed propositional formula φwith respect to a valuation v , denoted v(φ) is defined asfollows:

If φ is the constant ⊥, then v(φ) = F .If φ is the constant >, then v(φ) = T .If φ is an propositional atom p, then v(φ) = pv .If φ has the form (¬ψ), then v(φ) = \v(ψ).If φ has the form (ψ ∧ τ), then v(φ) = v(ψ)&v(τ).If φ has the form (ψ ∨ τ), then v(φ) = v(ψ) | v(τ).If φ has the form (ψ → τ), then v(φ) = v(ψ)⇒ v(τ).

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 9: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Propositional AtomsSyntax of Propositional LogicEvaluation of Formulas

Valid and Satisfiable Formulas

DefinitionA formula is called valid if it evaluates to T with respect to everypossible valuation.

DefinitionA formula is called satisfiable if it evaluates to T with respect toat least one valuation.

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 10: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

1 Recap: Syntax and Semantics of Propositional Logic

2 Questions

3 Conjunctive Normal Form

4 Algorithms for Satisfiability

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 11: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Questions about Propositional Formula

Is a given formula valid?Is a given formula satisfiable?Is a given formula invalid?Is a given formula unsatisfiable?Are two formulas equivalent?

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 12: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Decision Problems

DefinitionA decision problem is a question in some formal system with ayes-or-no answer.

ExamplesThe question whether a given propositional formula issatisifiable (unsatisfiable, valid, invalid) is a decision problem.

The question whether two given propositional formulas areequivalent is also a decision problem.

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 13: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

How to Solve the Decision Problem?

QuestionHow do you decide whether a given propositional formula issatisfiable/valid?

The good newsWe can construct a truth table for the formula and check ifsome/all rows have T in the last column.

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 14: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Satisifiability is Decidable

An algorithm for satisifiabilityUsing a truth table, we can implement an algorithm that returns“yes” if the formula is satisifiable, and that returns “no” if theformula is unsatisfiable.

DecidabilityDecision problems for which there is an algorithm computing“yes” whenever the answer is “yes”, and “no” whenever theanswer is “no”, are called decidable.

Decidability of satisfiabilityThe question, whether a given propositional formula issatisifiable, is decidable.

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 15: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

The Bad News

ConcernIn practice, propositional formulas can be large. Example:http://www.comp.nus.edu.sg/˜cs3234/prop.txt

Techniques so far inadequateProving satisfiability/validity using truth tables or naturaldeduction is impractical for large formulas.

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 16: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Is there a practical way of deciding satisfiability?

QuestionIs there an efficient algorithm that decides whether a givenformula is satisfiable?

More precisely...Is there a polynomial-time algorithm that decides whether agiven formula is satisfiable?

AnswerWe do not know!

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 17: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

What do we know about satisfiability?

Truth assignment as witnessIf the answer is “yes”, then a satisfying truth assignment canserve as a proof that the answer is indeed “yes”.

Witness for satisfiabilitySuch a proof is called a witness.

Checking the witnessWe can quickly check whether indeed the witness assignmentmakes the formula true. This can be done in time proportionalto the size of the formula.

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 18: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

The Complexity Class NP

DefinitionDecision problems for which the “yes” answer has a proof thatcan be checked in polynomial time, are called NP.

Origin of nameNP stands for “Non-deterministic Polynomial time”.

Original definitionNP is the set of decision problems solvable in polynomial timeby a non-deterministic Turing machine.

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 19: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Some History

The class NP was introduced by Stephen Cook in 1971 atthe 3rd Annual ACM Symposium on Theory of Computing.At the conference, there was a fierce debate whether therecould be a polynomial time algorithm to solve suchproblems.John Hopcroft convinced the delegates that the problemshould be put off to be solved at some later date.In 1972, Richard Karp presented 21 mutually equivalentproblems in NP, for which no polynomial time algorithmswas known.Cook and Leonid Levin proved independently thatpropositional satisifiability is in this class (calledNP-complete).

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 20: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

P = NP?

Clearly P ⊆ NP. Why?But does NP ⊆ P hold?To date, no proof of P = NP or P 6= NP has beendiscovered.Many computer scientists assume P 6= NP, and thereforeconsider NP-complete problems as “intractable”.Many “proofs” for one or the other answer have beenproposed, and subsequently rejected, most recently byVinay Deolalikar (a researcher at HP), in August 2010.

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 21: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

1 Recap: Syntax and Semantics of Propositional Logic

2 Questions

3 Conjunctive Normal Form

4 Algorithms for Satisfiability

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 22: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Conjunctive Normal Form

DefinitionA literal L is either an atom p or the negation of an atom ¬p.A formula C is in conjunctive normal form (CNF) if it is aconjunction of clauses, where each clause is a disjunction ofliterals:

L ::= p|¬pD ::= L|L ∨ DC ::= D|D ∧ C

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 23: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Examples

(¬p ∨ q ∨ r) ∧ (¬q ∨ r) ∧ (¬r) is in CNF.(¬p ∨ q ∨ r) ∧ ((p ∧ ¬q) ∨ r) ∧ (¬r) is not in CNF.(¬p ∨ q ∨ r) ∧ ¬(¬q ∨ r) ∧ (¬r) is not in CNF.

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 24: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Usefulness of CNF

LemmaA disjunction of literals L1 ∨ L2 ∨ · · · ∨ Lm is valid iff there are1 ≤ i , j ≤ m such that Li is ¬Lj .

How to disprove

|= (¬q ∨ p ∨ q) ∧ (¬p ∨ r) ∧ q

Use lemma to disprove any of:

|= (¬q ∨ p ∨ r) |= (¬p ∨ r) |= q

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 25: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Usefulness of CNF

LemmaA disjunction of literals L1 ∨ L2 ∨ · · · ∨ Lm is valid iff there are1 ≤ i , j ≤ m such that Li is ¬Lj .

How to prove

|= (¬q ∨ p ∨ q) ∧ (p ∨ r¬p) ∧ (r ∨ ¬r)

Use lemma to prove all of:

|= (¬q ∨ p ∨ q) |= (p ∨ r¬p) |= (r ∨ ¬r)

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 26: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Usefulness of CNF

PropositionLet φ be a formula of propositional logic. Then φ is satisfiable iff¬φ is not valid.

Satisfiability testWe can test satisfiability of φ by transforming ¬φ into CNF, andshow that some clause is not valid.

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 27: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Transformation to CNF

TheoremEvery formula in the propositional calculus can be transformedinto an equivalent formula in CNF.

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 28: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Algorithm for CNF Transformation

1 Eliminate implication using:A→ B ≡ ¬A ∨ B

2 Push all negations inward using De Morgan’s laws:¬(A ∧ B) ≡ (¬A ∨ ¬B)¬(A ∨ B) ≡ (¬A ∧ ¬B)

3 Eliminate double negations using the equivalence ¬¬A ≡ A4 The formula now consists of disjunctions and conjunctions

of literals. Use the distributive lawsA ∨ (B ∧ C) ≡ (A ∨ B) ∧ (A ∨ C)(A ∧ B) ∨ C ≡ (A ∨ C) ∧ (B ∨ C)to eliminate conjunctions within disjunctions.

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 29: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Example

(¬p → ¬q)→ (p → q) ≡ ¬(¬¬p ∨ ¬q) ∨ (¬p ∨ q)≡ (¬¬¬p ∧ q) ∨ (¬p ∨ q)≡ (¬p ∧ q) ∨ (¬p ∨ q)≡ (¬p ∨ ¬p ∨ q) ∧ (q ∨ ¬p ∨ q)

CS 3234: Logic and Formal Systems 04a—Propositional Logic II

Page 30: 04a Propositional Logic IIcs3234/slides/slides_04a.bw.pdf · Syntax of Propositional Logic Evaluation of Formulas Meaning of Atoms Models assign truth values A model assigns truth

Recap: Syntax and Semantics of Propositional LogicQuestions

Conjunctive Normal FormAlgorithms for Satisfiability

Algorithms for Proving Satisfiability of ψ

Transform ¬ψ into Conjunctive Normal Form ncnf andprove validity (non-validity) of ncnfTransform ψ into Conjunctive Normal Form cnf and searchfor a satisfying valuation

Complete algorithms: guaranteed to terminate with correctanswerexample: DPLLIncomplete algorithms: Return “yes” for some satisfiableformulas, and run forever for other satisfiable formulas andall unsatisfiable formulas; example: WalkSAT

Transform ψ into DAG; return “yes” for some satisfiableformulas, return “no” for some unsatisfiable formulas,return “don’t know” otherwise; example:propagation-based linear solver

CS 3234: Logic and Formal Systems 04a—Propositional Logic II