CS510 Software Engineering Propositional Logic Asst. Prof. Mathias - - PowerPoint PPT Presentation

cs510 software engineering
SMART_READER_LITE
LIVE PREVIEW

CS510 Software Engineering Propositional Logic Asst. Prof. Mathias - - PowerPoint PPT Presentation

CS510 Software Engineering Propositional Logic Asst. Prof. Mathias Payer Department of Computer Science Purdue University TA: Scott A. Carr Slides inspired by Xiangyu Zhang http://nebelwelt.net/teaching/15-CS510-SE Spring 2015 Additional


slide-1
SLIDE 1

CS510 Software Engineering

Propositional Logic

  • Asst. Prof. Mathias Payer

Department of Computer Science Purdue University TA: Scott A. Carr Slides inspired by Xiangyu Zhang http://nebelwelt.net/teaching/15-CS510-SE

Spring 2015 Additional slides credit: Michael Reniers, Julia Lawall, and Neil Jones.

slide-2
SLIDE 2

Motivation

Many static analysis techniques rely on proofing that some set of conditions hold. We need to come up with a way to express these conditions and reason about them. SAT solving allows to test the satisfiablity of propositional formulas in the domain of Boolean values. SAT solving is used for, e.g., formal equivalence checking, model checking, formal verification, automatic test pattern generation, scheduling problems, and symbolic execution. We need to understand propositional logic and SAT solving to follow the techniques listed above.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 2 / 60

slide-3
SLIDE 3

History of Logic

Philosophical Logic (500BC to 19th century) Symbolic Logic (mid to late 19th century) Mathematical Logic (late 19th century to mid 20th century) Logic in Computer Science (now)

Mathias Payer (Purdue University) CS510 Software Engineering 2015 3 / 60

slide-4
SLIDE 4

Syntax of propositional logic

Table of Contents

1

Syntax of propositional logic

2

Semantics of propositional logic

3

Semantic entailment Natural deduction of proof system Soundness and completeness

4

Validity and Satisfiability Conjunctive normal forms

5

SAT Solver

Mathias Payer (Purdue University) CS510 Software Engineering 2015 4 / 60

slide-5
SLIDE 5

Syntax of propositional logic

Syntax

F :== (P)|(¬F)|(F ∨ F)|(F ∧ F)|(F → F) P :== p|q|r|... Propositional atoms (p, q, r, ...) are used to describe declarative sentences like “1037 is a prime number”, “Every even number > 2 is the sum of two prime numbers”, or “All Martians like pepperoni on their pizza” (i.e., they can be evaluated to true or false). Connective Symbol Alternative Symbols negation (not) = disjunction (or) ∨ | conjunction (and) ∧ & mplication (implies) → ⇒, ⊃, ⊆

Mathias Payer (Purdue University) CS510 Software Engineering 2015 5 / 60

slide-6
SLIDE 6

Syntax of propositional logic

Syntax for propositional logic

Binding priorities: ¬, ∨, ∧, →, ↔ (These help reduce the amount of brackets needed. Also, outermost brackets are often omitted.)

Mathias Payer (Purdue University) CS510 Software Engineering 2015 6 / 60

slide-7
SLIDE 7

Semantics of propositional logic

Table of Contents

1

Syntax of propositional logic

2

Semantics of propositional logic

3

Semantic entailment Natural deduction of proof system Soundness and completeness

4

Validity and Satisfiability Conjunctive normal forms

5

SAT Solver

Mathias Payer (Purdue University) CS510 Software Engineering 2015 7 / 60

slide-8
SLIDE 8

Semantics of propositional logic

Semantics for Propositional Logic

The meaning of a formula depends on: The meaning of the propositional atoms (occurring in the formula) The meaning of the connectives (occurring in the formula)

Mathias Payer (Purdue University) CS510 Software Engineering 2015 8 / 60

slide-9
SLIDE 9

Semantics of propositional logic

Semantics: Propositional Atoms

The meaning of the propositional atoms (occurring in the formula): A declarative sentence is either true or false Captured as an assignment of truth values (B = {T, F}) to the propositional atoms a valuation v : P → B

Mathias Payer (Purdue University) CS510 Software Engineering 2015 9 / 60

slide-10
SLIDE 10

Semantics of propositional logic

Semantics: Connectives

The meaning of an n-ary connective ⊕ is captured by a function f⊕ : Bn → B Usually, such functions are specified by a truth table. A B ¬ A A ∧ B A ∨ B A → B T T F T T T T F F F T F F T T F T T F F T F F T

Mathias Payer (Purdue University) CS510 Software Engineering 2015 10 / 60

slide-11
SLIDE 11

Semantics of propositional logic

Example: Formula Evaluation

Evaluate the following formula: (p → q) ∧ (q → r) → (p → r) p q r p → q q → r . . . ∧ . . . p → r A ∧ B → C T T T T T T T T T T F T F F F T T F T F T F T T T F F F T F F T F T T T T T T T F T F T F F T T F F T T T T T T F F F T T T T T

Mathias Payer (Purdue University) CS510 Software Engineering 2015 11 / 60

slide-12
SLIDE 12

Semantic entailment

Table of Contents

1

Syntax of propositional logic

2

Semantics of propositional logic

3

Semantic entailment Natural deduction of proof system Soundness and completeness

4

Validity and Satisfiability Conjunctive normal forms

5

SAT Solver

Mathias Payer (Purdue University) CS510 Software Engineering 2015 12 / 60

slide-13
SLIDE 13

Semantic entailment

Areas of Interest

Semantic entailment. Many logical arguments are of the form: from the assumptions φ1, φ2, . . . φn we know ψ. This is formalised by the semantic entailment relation | =. E.g., M | = A describes that a situation M satisfies a formula A. Formally, φ1, φ2, . . . φn | = ψ iff for all valuations v such that φi(v) = T for all 1 ≤ i ≤ n we have ψ(v) = T Validity: a formula φ is valid if | = φ holds. Satisfiability: a formula φ is sat if there exists a valuation v so that φ(v) = T.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 13 / 60

slide-14
SLIDE 14

Semantic entailment

Semantic Entailment

How do we establish semantic entailment φ1, φ2, . . . φn | = ψ? Option 1: Construct a truth table. If formulas contain m propositional atoms, the truth table contains 2m lines! Option 2: Give a proof. Suppose that (p → q) ∧ (q → r). Suppose that p. Then, as p → q follows from (p → q) ∧ (q → r), we have q. Finally, as q → r follows from (p → q) ∧ (q → r), we have r. Thus the formula holds (i.e., there is no contradiction).

Mathias Payer (Purdue University) CS510 Software Engineering 2015 14 / 60

slide-15
SLIDE 15

Semantic entailment

Semantic Entailment

Proof rules for inferring a conclusion ψ from a list of premises φ1, φ2, . . . φn (x ⊢ y means that y is provable from x): φ1, φ2, . . . φn ⊢ ψ(sequent) What is a proof of a sequent φ1, φ2, . . . φn ⊢ ψ? Proof rules may be instantiated: consistent replacement of variables with formulas. Constructing the proof is filling the gap between the premises and the conclusion by applying a suitable sequence of proof rules.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 15 / 60

slide-16
SLIDE 16

Semantic entailment Natural deduction of proof system

Natural Deduction: Conjunction

Proof rules for conjunction: proofs of ψ ∧ φ are a concatenation of proofs for ψ and proofs of φ. ∧ introduction: ψ φ ψ ∧ φ ∧ i ∧ elimination: ψ ∧ φ ψ ∧ e1 ψ ∧ φ φ ∧ e2

Mathias Payer (Purdue University) CS510 Software Engineering 2015 16 / 60

slide-17
SLIDE 17

Semantic entailment Natural deduction of proof system

Conjunction: Exercise

Prove (p ∧ q) ∧ r, s ∧ t ⊢ q ∧ s. Given that we have (p ∧ q) ∧ r and s ∧ t we can prove q ∧ s. Linear representation: 1 (p ∧ q) ∧ r premise 2 s ∧ t premise 3 p ∧ q ∧e1 1 4 q ∧e2 3 5 s ∧e1 2 6 q ∧ s ∧i 4,5

Mathias Payer (Purdue University) CS510 Software Engineering 2015 17 / 60

slide-18
SLIDE 18

Semantic entailment Natural deduction of proof system

Conjunction: Exercise (2)

Prove (p ∧ q) ∧ r, s ∧ t ⊢ q ∧ s. Given that we have (p ∧ q) ∧ r and s ∧ t we can prove q ∧ s. Tree representation: (p ∧ q) ∧ r p ∧ q ∧ e1 q ∧ e2 s ∧ t s ∧ e1 q ∧ s ∧ i

Mathias Payer (Purdue University) CS510 Software Engineering 2015 18 / 60

slide-19
SLIDE 19

Semantic entailment Natural deduction of proof system

Natural Deduction: Disjunction

Proof rules for disjunction: ∨ introduction: ψ ψ ∨ φ ∨ i1 φ ψ ∨ φ ∨ i2 ∨ elminiation: φ ∨ ψ φ . . . χ ψ . . . χ χ ∨ e

Mathias Payer (Purdue University) CS510 Software Engineering 2015 19 / 60

slide-20
SLIDE 20

Semantic entailment Natural deduction of proof system

Disjunction: Exercise

Prove (p ∧ q) ∨ (p ∧ r) ⊢ p ∧ (q ∨ r): 1 (p ∧ q) ∨ (p ∧ r) premise 2 p ∧ q assumption (1) 3 p ∧e1 2 4 q ∧e2 2 5 q ∨ r ∨i1 4 6 p ∧ (q ∨ r) ∧i 3, 5 7 p ∧ r assumption (2) 8 p ∧e1 7 9 r ∧e2 7 10 q ∨ r ∨i2 9 11 p ∧ (q ∨ r) ∧i 8,10 12 p ∧ (q ∨ r) ∨e 1, 2-6, 7-11

Mathias Payer (Purdue University) CS510 Software Engineering 2015 20 / 60

slide-21
SLIDE 21

Semantic entailment Natural deduction of proof system

Natural Deduction: Implication

Proof rules for implication: → introduction φ . . . ψ φ → ψ → i → elminiation φ φ → ψ ψ → e

Mathias Payer (Purdue University) CS510 Software Engineering 2015 21 / 60

slide-22
SLIDE 22

Semantic entailment Natural deduction of proof system

Implication: Exercise

Prove p → q, q → r ⊢ p → r: 1 p → q premise 2 q → r premise 3 p assumption 4 q → e 1, 3 5 r → e 2, 4 6 p → r → i 3-5

Mathias Payer (Purdue University) CS510 Software Engineering 2015 22 / 60

slide-23
SLIDE 23

Semantic entailment Natural deduction of proof system

Natural Deduction: Negation

Proof rules for negation: ¬ introduction φ . . . ⊥ ¬φ ¬i ¬ elimination: φ ¬φ ⊥ ¬q

Mathias Payer (Purdue University) CS510 Software Engineering 2015 23 / 60

slide-24
SLIDE 24

Semantic entailment Natural deduction of proof system

Negation: Exercise

Prove p → q, p → ¬q ⊢ ¬p: 1 p → q premise 2 p → ¬q premise 3 p assumption 4 q → e 1,3 5 ¬q → e 2,3 6 ⊥ ¬e 4, 5 7 ¬p ¬i 3-6

Mathias Payer (Purdue University) CS510 Software Engineering 2015 24 / 60

slide-25
SLIDE 25

Semantic entailment Natural deduction of proof system

Negation: Exercise (2)

Prove ¬p ∨ q ⊢ p → q: 1 ¬p ∨ q premise 2 ¬p assumption (∨e1) 3 p assumption (contradiction) 4 ⊥ ¬e 3, 2 5 q ⊥e 4 6 p → q → i 3-5 7 q assumption (∨e2) 8 p assumption 9 q copy 7 10 p → q → i 8, 9 11 p → q ∨e 1, 2-6, 7-10

Mathias Payer (Purdue University) CS510 Software Engineering 2015 25 / 60

slide-26
SLIDE 26

Semantic entailment Natural deduction of proof system

Natural Deduction: Falsum

Proof rules for falsum: ⊥ introduction: there are no proof rules for the introduction of ⊥ ⊥ elimination: ⊥ φ ⊥e

Mathias Payer (Purdue University) CS510 Software Engineering 2015 26 / 60

slide-27
SLIDE 27

Semantic entailment Natural deduction of proof system

Natural Deduction: Double Negation

Proof rules for double negation: ¬¬ introduction: φ ¬¬φ¬¬i ¬¬ elimination: ¬¬φ φ ¬¬e

Mathias Payer (Purdue University) CS510 Software Engineering 2015 27 / 60

slide-28
SLIDE 28

Semantic entailment Natural deduction of proof system

Natural Deduction: Derived Rules

Modus Tollens: φ → ψ ¬ψ ¬φ MT Reduction Ad Absurdum: ¬φ . . . ⊥ φ RAA Tertium Non Datur: φ ∨ ¬φTND TND can also be called Law of the Excluded Middle.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 28 / 60

slide-29
SLIDE 29

Semantic entailment Soundness and completeness

Natural Deduction is Sound and Complete

Natural deduction is sound: if φ1, · · · φn ⊢ ψ, then φ1, · · · φn | = ψ Natural deduction is complete: if φ1, · · · φn | = ψ, then φ1, · · · φn ⊢ ψ

Mathias Payer (Purdue University) CS510 Software Engineering 2015 29 / 60

slide-30
SLIDE 30

Validity and Satisfiability

Table of Contents

1

Syntax of propositional logic

2

Semantics of propositional logic

3

Semantic entailment Natural deduction of proof system Soundness and completeness

4

Validity and Satisfiability Conjunctive normal forms

5

SAT Solver

Mathias Payer (Purdue University) CS510 Software Engineering 2015 30 / 60

slide-31
SLIDE 31

Validity and Satisfiability

Validity and Satisfiability of Propositional Formulas

A formula φ is valid if for any valuations v, φ(v) = ⊤ A formula φ is satisfiable if there exists a valuation v such that φ(v) = ⊤

Mathias Payer (Purdue University) CS510 Software Engineering 2015 31 / 60

slide-32
SLIDE 32

Validity and Satisfiability

Validity and Satisfiability: Example

p ∧ q satisfiable p → (q → p) valid(and satisfiable) p ∧ ¬p unsatisfiable

Mathias Payer (Purdue University) CS510 Software Engineering 2015 32 / 60

slide-33
SLIDE 33

Validity and Satisfiability

Deciding Validity

What are the means to decide whether or not a given formula φ is valid? Use techniques for semantic entailment (e.g., natural deduction) Use a calculus for semantical equivalence to prove that φ ≡ ⊤. Transform φ into some normal form that is semantically equivalent and then apply dedicated (syntactic) techniques. (φ and ψ are semantically equivalent (not φ ≡ ψ) iff φ | = ψ and ψ | = φ.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 33 / 60

slide-34
SLIDE 34

Validity and Satisfiability

Deciding Validity (2)

Lemma 1.41 A decision procedure for validity can be used for semantic entailment. φ1, · · · φn | = ψ iff | = φ1 → (φ2 → · · · → (φn → ψ))

Mathias Payer (Purdue University) CS510 Software Engineering 2015 34 / 60

slide-35
SLIDE 35

Validity and Satisfiability

Deciding Validity (3)

If I’m wealthy, then I’m happy. I am happy.Therefore, I’m wealthy. If John drinks beer, he is at least 21 years old. John does not drink beer.Therefore, John is not yet 21 years old. If I study, then I will not fail basket weaving 101. If I do not play cards too often, then I will study. I failed basket weaving 101.Therefore, I played cards too often.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 35 / 60

slide-36
SLIDE 36

Validity and Satisfiability Conjunctive normal forms

Conjunctive Normal Form

A literal is either an atom p or the negation of an atom ¬p. A formula φ is in conjunctive normal form (CNF) if it is a conjunction

  • f a number of disjunctions and literals only.

L ::= P|¬P literal C ::= L|C ∨ C clause CNF ::= C|CNF ∧ CNF CNF

Mathias Payer (Purdue University) CS510 Software Engineering 2015 36 / 60

slide-37
SLIDE 37

Validity and Satisfiability Conjunctive normal forms

CNF Examples

p, ¬p CNF ¬¬p not CNF p ∧ ¬p CNF (p ∨ ¬r) ∧ (¬r ∨ s) ∧ q CNF (p ∧ ¬q) ∨ q not CNF

Mathias Payer (Purdue University) CS510 Software Engineering 2015 37 / 60

slide-38
SLIDE 38

Validity and Satisfiability Conjunctive normal forms

Validity in CNF

Remember a formula is valid iff any of its equivalent formulas is valid. Reduce the problem of determining whether any φ is valid to the problem of computing an equivalent ψ ≡ φ such that ψ is in CNF and then checking ψ. Deciding validity in CNF (C1 ∧ C2 ∧ · · · ∧ Cn) is incremental: each clause Ci must be valid individually. Each clause Ci consists of a disjunction of literals L1 ∨ L2 ∨ · · · ∨ Lm. A disjunction of literals is valid iff there are 1 ≤ i, j ≤ m such that Li is ¬Lj.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 38 / 60

slide-39
SLIDE 39

Validity and Satisfiability Conjunctive normal forms

Validity in CNF (2)

We now have a simple way to check the validity of | = φ as long as φ is in CNF: inspect all conjuncts ψk of φ and search for atoms in ψk so that ψk also contains their negation. If a match is found for all conjuncts we have | = φ. Otherwise (i.e., some conjunct contains no pair Li and ¬Lj), φ is not valid.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 39 / 60

slide-40
SLIDE 40

Validity and Satisfiability Conjunctive normal forms

Transformation into CNF

1

IF: Remove all occurrences of →: translate ψ → η to ¬ψ ∨ η (in: formula, out: formula without →).

2

NNF: Obtain a negation normal form (NNF) where only atoms are negated (in: formula without →, out: formula in NNF): N ::= P|¬P|(N ∨ N)|(N ∧ N) P ::= p|q|r| · · ·

3

CNF: Apply distribution laws (in: formula in NNF, out: formula in CNF): replace (φ1 ∧ φ2) ∨ ψ by (φ1 ∨ ψ) ∧ (φ2 ∨ ψ) replace φ ∨ (ψ1 ∧ ψ2) by (φ ∨ ψ1) ∧ (φ ∨ ψ2) Therefore, CNF(NNF(IF(φ))) is in CNF and semantically equivalent with φ.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 40 / 60

slide-41
SLIDE 41

Validity and Satisfiability Conjunctive normal forms

Transformation into CNF: IF algorithm

Remove implications from the formula by applying the following replacement until you reach a fix-point: ψ → η to ¬ψ ∨ η Inductive definition of IMPL FREE: IF(p) = p IF(¬φ) = ¬IF(φ) IF(φ1 ∧ φ2) = IF(φ1) ∧ IF(φ2) IF(φ1 ∨ φ2) = IF(φ1) ∨ IF(φ2) IF(φ1 → φ2) = ¬IF(φ1) ∨ IF(φ2) Properties of IF: it is (i) well-defined (terminates for any input), (ii) IF(ψ) ≡ ψ (output of both formulas are semantically equivalent),and (iii) IF(ψ) is an implication-free formula for any formula ψ.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 41 / 60

slide-42
SLIDE 42

Validity and Satisfiability Conjunctive normal forms

Transformation into CNF: NNF algorithm

Simplify formula into negation normal form by repeatedly applying pattern rewriting rules: ¬¬φ replace by φ ¬(φ ∧ ψ) replace by ¬φ ∨ ¬ψ ¬(φ ∨ ψ) replace by ¬φ ∧ ¬ψ Inductive definition of NFF: NNF(p) = p NNF(¬p) = ¬p NNF(¬¬φ) = NNF(φ) NNF(¬(φ ∧ ψ)) = NNF(¬φ) ∨ NNF(¬ψ) NNF(¬(φ ∨ ψ)) = NNF(¬φ) ∧ NNF(¬ψ) NNF(φ ∧ ψ) = NNF(φ) ∧ NNF(ψ) NNF(φ ∨ ψ) = NNF(φ) ∨ NNF(ψ)

Mathias Payer (Purdue University) CS510 Software Engineering 2015 42 / 60

slide-43
SLIDE 43

Validity and Satisfiability Conjunctive normal forms

Transformation into CNF: NNF algorithm (2)

Properties of NNF: it is (i) well-defined (terminates for any input), (ii) NNF(ψ) ≡ ψ (output of both formulas are semantically equivalent),and (iii) NNF(ψ) is a negation-free formula for any formula ψ.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 43 / 60

slide-44
SLIDE 44

Validity and Satisfiability Conjunctive normal forms

Transformation into CNF: CNF algorithm

Simplify formula into conjunctive normal form (CNF) by repeatedly applying pattern rewriting rules: (φ1 ∧ φ2) ∨ ψ replace by (φ1 ∨ ψ) ∧ (φ2 ∨ ψ) φ ∨ (ψ1 ∧ ψ2) replace by (φ ∨ ψ1) ∧ (φ ∨ ψ2)

Mathias Payer (Purdue University) CS510 Software Engineering 2015 44 / 60

slide-45
SLIDE 45

Validity and Satisfiability Conjunctive normal forms

Transformation into CNF: CNF algorithm (2)

Inductive definition of CNF: CNF(p) = p CNF(¬p) = ¬p CNF(φ1 ∧ φ2) = CNF(φ1) ∧ CNF(φ2) CNF(φ1 ∨ φ2) = D(CNF(φ1), CNF(φ2)) D(φ1, φ2) =      D(φ11, φ2) ∧ D(φ12, φ2) φ1 = φ11 ∧ φ12 D(φ1, φ21) ∧ D(φ1, φ22) φ2 = φ21 ∧ φ22 φ1 ∨ φ2

  • therwise

Properties of CNF and D: CNF and D are (i) well-defined (terminate for any input), (ii) D(φ, ψ) ≡ φ ∨ ψ and CNF(φ) ≡ φ (output of both formulas are semantically equivalent),and (iii) CNF(φ) is in CNF for any formula φ in NNF and D(φ, ψ) is in CNF for any formulas φ and ψ in CNF.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 45 / 60

slide-46
SLIDE 46

Validity and Satisfiability Conjunctive normal forms

CNF: Example

Find a CNF for p ∨ ¬q → r: p ∨ ¬q → r premise ¬(p ∨ ¬q) ∨ r apply IMPL FREE (¬p ∧ ¬¬q) ∨ r apply NNF (¬p ∧ q) ∨ r apply NNF (¬p ∨ r) ∧ (q ∨ r) apply CNF

Mathias Payer (Purdue University) CS510 Software Engineering 2015 46 / 60

slide-47
SLIDE 47

SAT Solver

Table of Contents

1

Syntax of propositional logic

2

Semantics of propositional logic

3

Semantic entailment Natural deduction of proof system Soundness and completeness

4

Validity and Satisfiability Conjunctive normal forms

5

SAT Solver

Mathias Payer (Purdue University) CS510 Software Engineering 2015 47 / 60

slide-48
SLIDE 48

SAT Solver

SAT Solver

Find satisfying valuations to a propositional formula. Develop a systematic approach to test all possible valuations to find a satisfiable valuation. SAT solving is NP-complete, so the worst-case complexity will always be exponential.But good heuristics exist.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 48 / 60

slide-49
SLIDE 49

SAT Solver

Forcing Laws: Negation

φ ¬φ T F F T ¬

  • T

⇐ ⇒ F ¬

  • F

⇐ ⇒ T

Mathias Payer (Purdue University) CS510 Software Engineering 2015 49 / 60

slide-50
SLIDE 50

SAT Solver

Forcing Laws: Conjunction

φ ψ φ ∧ ψ T T T T F F F T F F F F ∧ φ, ψ φ, ψ ∧ T = ⇒ T, T T, T = ⇒ T ?, F = ⇒ F F, ? = ⇒ F ∧, φ ψ ∧, ψ φ F, T = ⇒ F F, T = ⇒ F

Mathias Payer (Purdue University) CS510 Software Engineering 2015 50 / 60

slide-51
SLIDE 51

SAT Solver

Forcing Laws: Completeness

Is this enough?We now have ¬ and ∧. We can convert any propositional formula (without loss of generality) to a formula that

  • nly contains ¬ and ∧.

Simplify formula into ¬, ∧ T(p) = p T(¬φ) = ¬T(φ) T(φ ∧ ψ) = T(φ) ∧ T(ψ) T(φ ∨ ψ) = ¬(¬T(φ) ∧ ¬T(ψ)) T(φ → ψ) = ¬(T(φ) ∧ ¬T(ψ)) This translation results in a linear growth in the formula size.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 51 / 60

slide-52
SLIDE 52

SAT Solver

SAT Solving

1

Convert formula to ¬ and ∧

2

Translate the formula to a DAG, sharing common subterms.

3

Set the root to T and apply the forcing rules. The formula is satisfiable iff all nodes are consistently annotated.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 52 / 60

slide-53
SLIDE 53

SAT Solver

Example: Satisfiability

Formula: p ∧ ¬(q ∨ ¬p) ≡ p ∧ ¬¬(¬q ∧ ¬¬p):

∧ ¬ ¬ ∧ ¬ ¬ ¬ q p

1T 2T 2T 3F 4T 5T 5T 6F 6F Is the formula satisfiable? Yes: p = T, q = F is a witness.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 53 / 60

slide-54
SLIDE 54

SAT Solver

Example: Validity

Show the validity of (p ∨ (p ∧ q)) → p. This formula is valid if ¬((p ∨ (p ∧ q)) → p) is not satisfiable.Translated formula: ¬(¬p ∧ ¬(p ∧ q)) ∧ ¬p.

∧ ¬ ∧ ¬ ¬ ∧ q p

1T 2T 2T 3F 3F 4F 5T Contradiction!

Mathias Payer (Purdue University) CS510 Software Engineering 2015 54 / 60

slide-55
SLIDE 55

SAT Solver

Example: Satisfiability

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

¬ ∧ ¬ ∧ ¬ ¬ ∧ q p

1T 2F We have an unsatisfiable formula. Now what?

Mathias Payer (Purdue University) CS510 Software Engineering 2015 55 / 60

slide-56
SLIDE 56

SAT Solver

Limitation of the SAT solver algorithm

Fails for all formulas of the form ¬(φ1 ∧ φ2). Yet, some are valid and thus satisfiable: ⊤ ≡ p → p ≡ ¬(p ∧ ¬p) Some are not valid and thus not satisfiable: ⊥ ≡ ¬⊤ ≡ ¬(⊤∧⊤) ≡ ¬(p → p∧p → p) ≡ ¬(¬(p∧¬p)∧¬(p∧¬p))

Mathias Payer (Purdue University) CS510 Software Engineering 2015 56 / 60

slide-57
SLIDE 57

SAT Solver

Extended Algorithm

SAT Checking

1

Pick an unmarked node and add temporary T and F marks.

2

Use the forcing rules to propagate both marks.

3

If both marks lead to a contradiction, report a contradiction.

4

If both marks lead to some node having the same value, permanently assign the node that value.

5

Erase the remaining temporary marks and continue. Complexity: O(n3): (i) testing each unmarked node O(n), (ii) testing a given unmarked node O(n), (iii) repeating the process when a new node is marked O(n).

Mathias Payer (Purdue University) CS510 Software Engineering 2015 57 / 60

slide-58
SLIDE 58

SAT Solver

Extended Algorithm: Example

Formula: ¬(q ∧ r) ∧ ¬(¬(q ∧ r) ∧ ¬(¬q ∧ r)):

∧ ¬ ¬ ∧ q r ∧ ¬ ∧ q r ¬ ∧ ¬ q r

1T 2T 2T 3F 3F

4T 4F 5T 5F 5F 6T 6T 6T 6T 6T 6T 6T 7T 7T 7T 7T 8T 8T 8T

r is true in both cases. Fix r to T.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 58 / 60

slide-59
SLIDE 59

SAT Solver

Extended Algorithm: Example (2)

∧ ¬ ¬ ∧ q r ∧ ¬ ∧ q r ¬ ∧ ¬ q r 1T 2T 2T 3F 3F 4T 4T 4T 5F 5F 5F 6F 6T 7T 7T 8F

Satisfiable!

Mathias Payer (Purdue University) CS510 Software Engineering 2015 59 / 60

slide-60
SLIDE 60

SAT Solver

Questions?

?

Mathias Payer (Purdue University) CS510 Software Engineering 2015 60 / 60