Decision Procedures for Satisfiability and Validity in Propositional - - PowerPoint PPT Presentation

decision procedures for satisfiability and validity in
SMART_READER_LITE
LIVE PREVIEW

Decision Procedures for Satisfiability and Validity in Propositional - - PowerPoint PPT Presentation

Decision Procedures for Satisfiability and Validity in Propositional Logic Meghdad Ghari Institute for Research in Fundamental Sciences (IPM) School of Mathematics-Isfahan Branch Logic Group http://math.ipm.ac.ir/Isfahan/Logic-Group.htm Logic


slide-1
SLIDE 1

Decision Procedures for Satisfiability and Validity in Propositional Logic

Meghdad Ghari

Institute for Research in Fundamental Sciences (IPM) School of Mathematics-Isfahan Branch Logic Group http://math.ipm.ac.ir/Isfahan/Logic-Group.htm

Logic Short Course I, Computational Propositional Logic November 24, 2016

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 1 / 57

slide-2
SLIDE 2

Outline

1

Conjunctive Normal Form

2

Disjunctive Normal Form

3

Horn formulas

4

A linear SAT solver

5

Binary Decision Diagrams

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 2 / 57

slide-3
SLIDE 3

Logical reasoning

Is the following argument logically valid? A1 A2 . . . An B Artificial Language = ⇒ Various Semantics Various Proof systems

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 3 / 57

slide-4
SLIDE 4

Language

Formulas of propositional logic are defined by the following grammar: Formula ::= Atomic Formula | TRUE | FALSE | (¬ Formula) | (Formula ∧ Formula) | (Formula ∨ Formula) | (Formula → Formula). In Backus Naur form (BNF): φ ::= p | ⊤ | ⊥ | (¬φ) | (φ ∧ φ) | (φ ∨ φ) | (φ → φ), p ∈ Atom Atom denotes a non-empty (finite or infinite) set of atomic propositions (or propositional variables).

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 4 / 57

slide-5
SLIDE 5

Language

Formulas of propositional logic are defined by the following grammar: Formula ::= Atomic Formula | TRUE | FALSE | (¬ Formula) | (Formula ∧ Formula) | (Formula ∨ Formula) | (Formula → Formula). In Backus Naur form (BNF): φ ::= p | ⊤ | ⊥ | (¬φ) | (φ ∧ φ) | (φ ∨ φ) | (φ → φ), p ∈ Atom Atom denotes a non-empty (finite or infinite) set of atomic propositions (or propositional variables).

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 4 / 57

slide-6
SLIDE 6

Semantics

Valuations: v : Atom → {T, F} Valuations can be extended to the set of all formulas as follows: φ ¬φ T F F T ⊤ T ⊥ F φ ψ φ ∧ ψ T T T T F F F T F F F F φ ψ φ ∨ ψ T T T T F T F T T F F F φ ψ φ → ψ T T T T F F F T T F F T

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 5 / 57

slide-7
SLIDE 7

Principle of compositionality

The meaning of a complex expression is determined by the meanings

  • f its constituent expressions and the rules used to combine them.

v(⊤) = T v(⊥) = F v(¬φ) = 1 − v(φ) v(φ ∧ ψ) = min(v(φ), v(ψ)) v(φ ∨ ψ) = max(v(φ), v(ψ)) v(φ → ψ) = min(1, 1 − v(φ) + v(ψ))

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 6 / 57

slide-8
SLIDE 8

Semantic consequence

Definition

If for all valuations in which all φ1, φ2, . . . , φn evaluate to T, ψ evaluates to T as well, we say that φ1, φ2, . . . , φn | = ψ holds and call | = the semantic entailment relation.

Example

p ∨ q, ¬p | = q

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 7 / 57

slide-9
SLIDE 9

Syntactic consequence

Definition

If ψ is provable (in a proof system) from premises φ1, φ2, . . . , φn, we say that the sequent φ1, φ2, . . . , φn ⊢ ψ is valid.

Example

p ∨ q, ¬p ⊢ q

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 8 / 57

slide-10
SLIDE 10

Logical consequence

Two approaches to logical consequence: Semantic: φ1, φ2, . . . , φn | = ψ. Syntactic: φ1, φ2, . . . , φn ⊢ ψ. A1 A2 . . . An B

Theorem (Soundness)

φ1, φ2, . . . , φn ⊢ ψ ⇒ φ1, φ2, . . . , φn | = ψ

Theorem (Completeness)

φ1, φ2, . . . , φn | = ψ ⇒ φ1, φ2, . . . , φn ⊢ ψ

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 9 / 57

slide-11
SLIDE 11

Logic in Computer Science

Two approaches: Semantic:

◮ M. Huth and M. Ryan,

Logic in Computer Science modelling and reasoning about systems, Cambridge University Press, 2004

Syntactic:

◮ M. Fitting,

First-Order Logic and Automated Theorem Proving, Springer, 1996.

◮ J. H. Gallier,

Logic for Computer Science Foundations of Automatic Theorem Proving, John Wiley, 1987.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 10 / 57

slide-12
SLIDE 12

Satisfiability, validity, equivalence

Definition (Satisfiable)

Given a formula φ in propositional logic, we say that φ is satisfiable (has a model) if it has a valuation in which it evaluates to true.

Definition (Valid)

Given a formula φ in propositional logic, we say that φ is valid if under every valuation it evaluates to true. In that case we write | = φ.

Definition (Equivalence)

Let φ and ψ be formulas of propositional logic. We say that φ and ψ are semantically equivalent iff φ | = ψ and φ | = ψ hold. In that case we write φ ≡ ψ.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 11 / 57

slide-13
SLIDE 13

Decision procedures

Definition

A decision problem is a question in some formal system with a yes-or-no answer, depending on the values of some input parameters.

Definition

A decision procedure is an algorithm that, given a decision problem, terminates with a correct yes/no answer.

Definition

A computer program that searches for a model for a propositional formula is called a SAT Solver.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 12 / 57

slide-14
SLIDE 14

Some applications of SAT solvers

Test for the functional equivalence of two circuits. Identifying defects of integrated circuits. Model checking of hardware and software systems. Planning in artificial intelligence. Joao Marques-Silva, Practical Applications of Boolean Satisfiability, In Workshop on Discrete Event Systems (WODES), IEEE Press, 2008.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 13 / 57

slide-15
SLIDE 15

Boolean functions

Definition

A boolean variable x is a variable ranging over the values 0 and 1. A boolean function f of n arguments is a function from {0, 1}n to {0, 1}.

Example

¯ 0 def = 1 and ¯ 1 def = 0; x · y def = 1 if x = y = 1; otherwise x · y def = 0; x + y def = 0 if x = y = 0; otherwise x + y def = 1. Various representations of boolean functions: Truth tables Propositional formulas. Binary decision diagrams.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 14 / 57

slide-16
SLIDE 16

Boolean functions

Definition

A boolean variable x is a variable ranging over the values 0 and 1. A boolean function f of n arguments is a function from {0, 1}n to {0, 1}.

Example

¯ 0 def = 1 and ¯ 1 def = 0; x · y def = 1 if x = y = 1; otherwise x · y def = 0; x + y def = 0 if x = y = 0; otherwise x + y def = 1. Various representations of boolean functions: Truth tables Propositional formulas. Binary decision diagrams.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 14 / 57

slide-17
SLIDE 17

Truth tables

Truth tables are very space-inefficient. Once you have computed a truth table, it is easy to see whether the boolean function represented is satisfiable or valid. Once you have computed a truth table, comparing whether two

  • rdered truth tables represent the same boolean function also

seems easy. Checking satisfiability of a function with n atoms requires of the

  • rder of 2n operations if the function is represented as a truth

table. We conclude that checking satisfiability, validity and equivalence is highly inefficient with the truth-table representation.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 15 / 57

slide-18
SLIDE 18

Propositional formulas

Propositional formulas often provide a compact and efficient presentation of boolean functions. Deciding whether two arbitrary propositional formulas f and g denote the same boolean function is suspected to be exponentially expensive. Deciding whether an arbitrary propositional formula is satisfiable is a famous problem in computer science: No efficient algorithms for SAT are known, and it is strongly suspected that there aren’t any. P ? = NP NP ? = co-NP

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 16 / 57

slide-19
SLIDE 19

Theorem

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

Theorem

Given formulas φ1, φ2, . . . , φn and ψ of propositional logic, φ1, φ2, . . . , φn | = ψ iff | = φ1 → (φ2 → . . . (φn → ψ))

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 17 / 57

slide-20
SLIDE 20

Theorem

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

Theorem

Given formulas φ1, φ2, . . . , φn and ψ of propositional logic, φ1, φ2, . . . , φn | = ψ iff | = φ1 → (φ2 → . . . (φn → ψ))

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 17 / 57

slide-21
SLIDE 21

Conjunctive Normal Form (CNF)

L ::= p | ¬p, p ∈ Atom Literal D ::= L | L ∨ D Clause C ::= D | D ∧ C Conjunctive normal form

Example

(¬q ∨ p ∨ r) ∧ (¬p ∨ r) ∧ q.

  • (¬q ∨ p ∨ r ∨ q) ∧ (¬p ∨ p).
  • (p ∧ r) ∧ (¬p → r).

× ¬(q ∨ p ∨ r) ∧ (¬q ∨ p). ×

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 18 / 57

slide-22
SLIDE 22

Conjunctive Normal Form (CNF)

L ::= p | ¬p, p ∈ Atom Literal D ::= L | L ∨ D Clause C ::= D | D ∧ C Conjunctive normal form

Example

(¬q ∨ p ∨ r) ∧ (¬p ∨ r) ∧ q.

  • (¬q ∨ p ∨ r ∨ q) ∧ (¬p ∨ p).
  • (p ∧ r) ∧ (¬p → r).

× ¬(q ∨ p ∨ r) ∧ (¬q ∨ p). ×

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 18 / 57

slide-23
SLIDE 23

Conjunctive Normal Form (CNF)

L ::= p | ¬p, p ∈ Atom Literal D ::= L | L ∨ D Clause C ::= D | D ∧ C Conjunctive normal form

Example

(¬q ∨ p ∨ r) ∧ (¬p ∨ r) ∧ q.

  • (¬q ∨ p ∨ r ∨ q) ∧ (¬p ∨ p).
  • (p ∧ r) ∧ (¬p → r).

× ¬(q ∨ p ∨ r) ∧ (¬q ∨ p). ×

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 18 / 57

slide-24
SLIDE 24

Conjunctive Normal Form (CNF)

L ::= p | ¬p, p ∈ Atom Literal D ::= L | L ∨ D Clause C ::= D | D ∧ C Conjunctive normal form

Example

(¬q ∨ p ∨ r) ∧ (¬p ∨ r) ∧ q.

  • (¬q ∨ p ∨ r ∨ q) ∧ (¬p ∨ p).
  • (p ∧ r) ∧ (¬p → r).

× ¬(q ∨ p ∨ r) ∧ (¬q ∨ p). ×

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 18 / 57

slide-25
SLIDE 25

Conjunctive Normal Form (CNF)

L ::= p | ¬p, p ∈ Atom Literal D ::= L | L ∨ D Clause C ::= D | D ∧ C Conjunctive normal form

Example

(¬q ∨ p ∨ r) ∧ (¬p ∨ r) ∧ q.

  • (¬q ∨ p ∨ r ∨ q) ∧ (¬p ∨ p).
  • (p ∧ r) ∧ (¬p → r).

× ¬(q ∨ p ∨ r) ∧ (¬q ∨ p). ×

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 18 / 57

slide-26
SLIDE 26

CNF and validity

Theorem

A disjunction of literals L1 ∨ L2 ∨ . . . ∨ Lm is valid iff there are 1 ≤ i, j ≤ m such that Li is ¬Lj.

Example

(¬q ∨ p ∨ r ∨ q) ∧ (¬p ∨ p) is valid, since both ¬q ∨ p ∨ r ∨ q and ¬p ∨ p are valid.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 19 / 57

slide-27
SLIDE 27

CNF and validity

Theorem

A disjunction of literals L1 ∨ L2 ∨ . . . ∨ Lm is valid iff there are 1 ≤ i, j ≤ m such that Li is ¬Lj.

Example

(¬q ∨ p ∨ r ∨ q) ∧ (¬p ∨ p) is valid, since both ¬q ∨ p ∨ r ∨ q and ¬p ∨ p are valid.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 19 / 57

slide-28
SLIDE 28

Converting formulas to CNF I

Converting using truth tables p q ? T T T T F F F T T F F F φ = (¬p ∨ q) ∧ (¬p ∨ ¬q).

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 20 / 57

slide-29
SLIDE 29

Converting formulas to CNF II

Converting φ to CNF , using algorithm CNF(NNF(IMPL − FREE(φ))). Step 1. φ → ψ ≡ ¬φ ∨ ψ Step 2. De Morgan rules: ¬(φ ∧ ψ) ≡ ¬φ ∨ ¬ψ ¬(φ ∨ ψ) ≡ ¬φ ∧ ¬ψ Step 3. Distributivity rules: φ ∧ (ψ ∨ σ) ≡ (φ ∧ ψ) ∨ (φ ∧ σ) φ ∨ (ψ ∧ σ) ≡ (φ ∨ ψ) ∧ (φ ∨ σ)

Exercise

Compute CNF(NNF(IMPL − FREE((p ∨ q) → p))).

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 21 / 57

slide-30
SLIDE 30

Algorithm IMPL-FREE

function IMPL − FREE (φ): /* precondition: φ an arbitrary formula */ /* postcondition: IMPL − FREE (φ) computes an implication-free equivalent for φ */ begin function case φ is a literal: return φ φ is ¬φ1 : return ¬IMPL − FREE(φ1) φ is φ1 ∧ φ2 : return IMPL − FREE (φ1) ∧ IMPL − FREE (φ2) φ is φ1 ∨ φ2 : return IMPL − FREE (φ1) ∨ IMPL − FREE (φ2) φ is φ1 → φ2 : return ¬IMPL − FREE (φ1) ∨ IMPL − FREE (φ2) end case end function

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 22 / 57

slide-31
SLIDE 31

Algorithm NNF

function NNF (φ): /* precondition: φ is implication free */ /* postcondition: NNF (φ) computes a NNF for φ */ begin function case φ is a literal: return φ φ is ¬¬φ1 : return NNF (φ1) φ is φ1 ∧ φ2 : return NNF (φ1) ∧ NNF (φ2) φ is φ1 ∨ φ2 : return NNF (φ1) ∨ NNF (φ2) φ is ¬(φ1 ∧ φ2): return NNF (¬φ1) ∨ NNF (¬φ2) φ is ¬(φ1 ∨ φ2): return NNF (¬φ1) ∧ NNF (¬φ2) end case end function

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 23 / 57

slide-32
SLIDE 32

Algorithm DISTR

function DISTR (η1, η2): /* precondition: η1 and η2 are in CNF */ /* postcondition: DISTR (η1, η2) computes a CNF for η1 ∨ η2 */ begin function case η1 is η11 ∧ η12 : return DISTR (η11, η2) ∧ DISTR (η12, η2) η2 is η21 ∧ η22 : return DISTR (η1, η21) ∧ DISTR (η1, η22)

  • therwise (= no conjunctions): return η1 ∨ η2

end case end function

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 24 / 57

slide-33
SLIDE 33

Algorithm CNF

function CNF (φ): /* precondition: φ implication free and in NNF */ /* postcondition: CNF (φ) computes an equivalent CNF for φ */ begin function case φ is a literal: return φ φ is φ1 ∧ φ2 : return CNF (φ1) ∧ CNF (φ2) φ is φ1 ∨ φ2 : return DISTR (CNF (φ1), CNF (φ2)) end case end function

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 25 / 57

slide-34
SLIDE 34

Davis-Putnam Procedure

function DP-sat(clause set S) repeat for each unit clause L in S do /* unit propagation */ delete from S every clause containing L delete ¬L from every clause of S if S is empty return true else if S contains the empty clause return false until no changes occur in S /* splitting */ choose a literal L in S if DP-sat(S ∪ {L}) return true else if DP-sat(S ∪ {¬L}) return true else return false.

  • J. J. Lu, E. Rosenthal, Logic-Based Reasoning for Intelligent Systems, in

Computer Science Handbook, Allen B. Tucker (Editor), Chapter 61, Chapman and Hall/CRC, 2004.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 26 / 57

slide-35
SLIDE 35

Davis-Putnam Procedure

function DP-sat(clause set S) repeat for each unit clause L in S do /* unit propagation */ delete from S every clause containing L delete ¬L from every clause of S if S is empty return true else if S contains the empty clause return false until no changes occur in S /* splitting */ choose a literal L in S if DP-sat(S ∪ {L}) return true else if DP-sat(S ∪ {¬L}) return true else return false. Example: clause set S = {p ∨ ¬q, ¬p ∨ q, q ∨ ¬r, ¬q ∨ ¬r}

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 27 / 57

slide-36
SLIDE 36

Davis-Putnam Procedure

function DP-sat(clause set S) repeat for each unit clause L in S do /* unit propagation */ delete from S every clause containing L delete ¬L from every clause of S if S is empty return true else if S contains the empty clause return false until no changes occur in S /* splitting */ choose a literal L in S if DP-sat(S ∪ {L}) return true else if DP-sat(S ∪ {¬L}) return true else return false. Splitting: {p ∨ ¬q, ¬p ∨ q, q ∨ ¬r, ¬q ∨ ¬r, p}

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 28 / 57

slide-37
SLIDE 37

Davis-Putnam Procedure

function DP-sat(clause set S) repeat for each unit clause L in S do /* unit propagation */ delete from S every clause containing L delete ¬L from every clause of S if S is empty return true else if S contains the empty clause return false until no changes occur in S /* splitting */ choose a literal L in S if DP-sat(S ∪ {L}) return true else if DP-sat(S ∪ {¬L}) return true else return false. Propagation: {p∨¬q, ¬p∨q, q∨¬r, ¬q∨¬r, p}

p

⇒ {q, q∨¬r, ¬q∨¬r}

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 29 / 57

slide-38
SLIDE 38

Davis-Putnam Procedure

function DP-sat(clause set S) repeat for each unit clause L in S do /* unit propagation */ delete from S every clause containing L delete ¬L from every clause of S if S is empty return true else if S contains the empty clause return false until no changes occur in S /* splitting */ choose a literal L in S if DP-sat(S ∪ {L}) return true else if DP-sat(S ∪ {¬L}) return true else return false. Propagation:{q, q ∨ ¬r, ¬q ∨ ¬r}

q

⇒ {¬r}

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 30 / 57

slide-39
SLIDE 39

Davis-Putnam Procedure

function DP-sat(clause set S) repeat for each unit clause L in S do /* unit propagation */ delete from S every clause containing L delete ¬L from every clause of S if S is empty return true else if S contains the empty clause return false until no changes occur in S /* splitting */ choose a literal L in S if DP-sat(S ∪ {L}) return true else if DP-sat(S ∪ {¬L}) return true else return false. Propagation: {¬r}

¬r

⇒ {}

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 31 / 57

slide-40
SLIDE 40

Davis-Putnam Procedure

function DP-sat(clause set S) repeat for each unit clause L in S do /* unit propagation */ delete from S every clause containing L delete ¬L from every clause of S if S is empty return true else if S contains the empty clause return false until no changes occur in S /* splitting */ choose a literal L in S if DP-sat(S ∪ {L}) return true else if DP-sat(S ∪ {¬L}) return true else return false. Model: {p, q, ¬r} ⇒ v(p) = v(q) = T, v(r) = F.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 32 / 57

slide-41
SLIDE 41

Disjunctive Normal Form (DNF)

L ::= p | ¬p, p ∈ Atom Literal D ::= L | L ∧ D C ::= D | D ∨ C Disjunctive normal form

Example

(¬q ∧ p ∧ r) ∨ (¬p ∧ r) ∨ q.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 33 / 57

slide-42
SLIDE 42

Disjunctive Normal Form (DNF)

L ::= p | ¬p, p ∈ Atom Literal D ::= L | L ∧ D C ::= D | D ∨ C Disjunctive normal form

Example

(¬q ∧ p ∧ r) ∨ (¬p ∧ r) ∨ q.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 33 / 57

slide-43
SLIDE 43

DNF and satisfiability

Theorem

A conjunction of literals L1 ∧ L2 ∧ . . . ∧ Lm is satisfiable iff there are no 1 ≤ i, j ≤ m such that Li is ¬Lj.

Example

(¬q ∧ p ∧ r) ∨ (¬r ∧ r) is satisfiable, since ¬q ∧ p ∧ r is satisfiable.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 34 / 57

slide-44
SLIDE 44

DNF and satisfiability

Theorem

A conjunction of literals L1 ∧ L2 ∧ . . . ∧ Lm is satisfiable iff there are no 1 ≤ i, j ≤ m such that Li is ¬Lj.

Example

(¬q ∧ p ∧ r) ∨ (¬r ∧ r) is satisfiable, since ¬q ∧ p ∧ r is satisfiable.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 34 / 57

slide-45
SLIDE 45

Horn formulas

P ::= ⊥ | ⊤ | p, p ∈ Atom A ::= P | P ∧ A C ::= A → P Horn clause H ::= C | C ∧ H Horn formula

Example

(p ∧ q ∧ s → ⊥) ∧ (q ∧ r → p) ∧ (⊤ → s).

  • (q ∧ ⊤ → ⊥) ∧ (p → q).
  • (p → p) ∧ (⊤ → s ∧ r).

× (¬q ∨ p). ×

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 35 / 57

slide-46
SLIDE 46

Horn formulas

P ::= ⊥ | ⊤ | p, p ∈ Atom A ::= P | P ∧ A C ::= A → P Horn clause H ::= C | C ∧ H Horn formula

Example

(p ∧ q ∧ s → ⊥) ∧ (q ∧ r → p) ∧ (⊤ → s).

  • (q ∧ ⊤ → ⊥) ∧ (p → q).
  • (p → p) ∧ (⊤ → s ∧ r).

× (¬q ∨ p). ×

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 35 / 57

slide-47
SLIDE 47

Horn formulas

P ::= ⊥ | ⊤ | p, p ∈ Atom A ::= P | P ∧ A C ::= A → P Horn clause H ::= C | C ∧ H Horn formula

Example

(p ∧ q ∧ s → ⊥) ∧ (q ∧ r → p) ∧ (⊤ → s).

  • (q ∧ ⊤ → ⊥) ∧ (p → q).
  • (p → p) ∧ (⊤ → s ∧ r).

× (¬q ∨ p). ×

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 35 / 57

slide-48
SLIDE 48

Horn formulas

P ::= ⊥ | ⊤ | p, p ∈ Atom A ::= P | P ∧ A C ::= A → P Horn clause H ::= C | C ∧ H Horn formula

Example

(p ∧ q ∧ s → ⊥) ∧ (q ∧ r → p) ∧ (⊤ → s).

  • (q ∧ ⊤ → ⊥) ∧ (p → q).
  • (p → p) ∧ (⊤ → s ∧ r).

× (¬q ∨ p). ×

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 35 / 57

slide-49
SLIDE 49

Horn formulas

P ::= ⊥ | ⊤ | p, p ∈ Atom A ::= P | P ∧ A C ::= A → P Horn clause H ::= C | C ∧ H Horn formula

Example

(p ∧ q ∧ s → ⊥) ∧ (q ∧ r → p) ∧ (⊤ → s).

  • (q ∧ ⊤ → ⊥) ∧ (p → q).
  • (p → p) ∧ (⊤ → s ∧ r).

× (¬q ∨ p). ×

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 35 / 57

slide-50
SLIDE 50

Algorithm HORN

function HORN (φ): /* precondition: φ is a Horn formula */ /* postcondition: HORN (φ) decides the satisfiability for φ */ begin function mark all occurrences of ⊤ in φ; while there is a conjunct P1 ∧ P2 ∧ · · · ∧ Pki → P′ of φ such that all Pj are marked but P′ isn’t do mark P′ end while if ⊥ is marked then return ‘unsatisfiable’ else return ‘satisfiable’ end function φ = (p ∧ q ∧ s → ⊥) ∧ (q ∧ r → p) ∧ (⊤ → s)

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 36 / 57

slide-51
SLIDE 51

Algorithm HORN

function HORN (φ): /* precondition: φ is a Horn formula */ /* postcondition: HORN (φ) decides the satisfiability for φ */ begin function mark all occurrences of ⊤ in φ; while there is a conjunct P1 ∧ P2 ∧ · · · ∧ Pki → P′ of φ such that all Pj are marked but P′ isn’t do mark P′ end while if ⊥ is marked then return ‘unsatisfiable’ else return ‘satisfiable’ end function φ = (p ∧ q ∧ s → ⊥) ∧ (q ∧ r → p) ∧ (⊤ → s)

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 37 / 57

slide-52
SLIDE 52

Algorithm HORN

function HORN (φ): /* precondition: φ is a Horn formula */ /* postcondition: HORN (φ) decides the satisfiability for φ */ begin function mark all occurrences of ⊤ in φ; while there is a conjunct P1 ∧ P2 ∧ · · · ∧ Pki → P′ of φ such that all Pj are marked but P′ isn’t do mark P′ end while if ⊥ is marked then return ‘unsatisfiable’ else return ‘satisfiable’ end function φ = (p ∧ q ∧ s → ⊥) ∧ (q ∧ r → p) ∧ (⊤ → s)

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 38 / 57

slide-53
SLIDE 53

Algorithm HORN

function HORN (φ): /* precondition: φ is a Horn formula */ /* postcondition: HORN (φ) decides the satisfiability for φ */ begin function mark all occurrences of ⊤ in φ; while there is a conjunct P1 ∧ P2 ∧ · · · ∧ Pki → P′ of φ such that all Pj are marked but P′ isn’t do mark P′ end while if ⊥ is marked then return ‘unsatisfiable’ else return ‘satisfiable’ end function φ = (p ∧ q ∧ s → ⊥) ∧ (q ∧ r → p) ∧ (⊤ → s) is satisfiable. Assign T to all marked atoms and F to all unmarked atoms.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 39 / 57

slide-54
SLIDE 54

A linear SAT solver

φ ::= p | ¬φ | φ ∧ φ, p ∈ Atom The parse tree of formula p ∧ ¬¬(¬q ∧ ¬¬p):

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 40 / 57

slide-55
SLIDE 55

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 41 / 57

slide-56
SLIDE 56

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 42 / 57

slide-57
SLIDE 57

Binary Decision Diagrams (BDD)

Binary decision tree for f(x, y) = x + y (NOR): x y f(x, y) 1 1 1 1 1 Dashed line value 0. Solid line value 1. Binary decision tree = truth table

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 43 / 57

slide-58
SLIDE 58

Some examples

  • B0. The BDD of ⊤:
  • B1. The BDD of ⊥:
  • Bx. The BDD of a variable x:

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 44 / 57

slide-59
SLIDE 59
  • C1. Removal of duplicate terminals
  • C1. If a BDD contains more than one terminal 0-node, then we redirect

all edges which point to such a 0-node to just one of them. We proceed in the same way with terminal nodes labelled with 1.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 45 / 57

slide-60
SLIDE 60
  • C2. Removal of redundant tests
  • C2. If both outgoing edges of a node n point to the same node m, then

we eliminate that node n, sending all its incoming edges to m.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 46 / 57

slide-61
SLIDE 61
  • C3. Removal of duplicate non-terminals
  • C3. If two distinct nodes n and m in the BDD are the roots of

structurally identical subBDDs, then we eliminate one of them, say m, and redirect all its incoming edges to the other one.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 47 / 57

slide-62
SLIDE 62
  • C3. Removal of duplicate non-terminals
  • C3. If two distinct nodes n and m in the BDD are the roots of

structurally identical subBDDs, then we eliminate one of them, say m, and redirect all its incoming edges to the other one.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 48 / 57

slide-63
SLIDE 63

Ordered Binary Decision Diagrams (OBDD)

A BDD which does not have an ordering of variables:

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 49 / 57

slide-64
SLIDE 64

Definition

A BDD is said to be reduced if none of the optimisations C1–C3 can be applied (i.e. no more reductions are possible). An ordered BDD (OBDD) is a BDD which has an ordering for some list of variables.

Theorem

The reduced OBDD representing a given boolean function f is unique. OBDDs have a canonical form, namely their unique reduced OBDD.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 50 / 57

slide-65
SLIDE 65

Definition

A BDD is said to be reduced if none of the optimisations C1–C3 can be applied (i.e. no more reductions are possible). An ordered BDD (OBDD) is a BDD which has an ordering for some list of variables.

Theorem

The reduced OBDD representing a given boolean function f is unique. OBDDs have a canonical form, namely their unique reduced OBDD.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 50 / 57

slide-66
SLIDE 66

Definition

A BDD is said to be reduced if none of the optimisations C1–C3 can be applied (i.e. no more reductions are possible). An ordered BDD (OBDD) is a BDD which has an ordering for some list of variables.

Theorem

The reduced OBDD representing a given boolean function f is unique. OBDDs have a canonical form, namely their unique reduced OBDD.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 50 / 57

slide-67
SLIDE 67

The importance of canonical form

OBDDs allow compact representations of certain classes of boolean functions which only have exponential representations in other systems, such as truth tables and conjunctive normal forms.

  • Example. Consider the even parity function

feven(x1, x2, . . . , xn) which is defined to be 1 if there is an even number of variables xi with value 1; otherwise, it is defined to be 0.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 51 / 57

slide-68
SLIDE 68

Absence of redundant variables

If the value of the boolean function f(x1, x2, . . . , xn) does not depend

  • n the value of xi, then any reduced OBDD which represents f does

not contain any xi-node.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 52 / 57

slide-69
SLIDE 69

Test for semantic equivalence

f and g denote the same boolean functions iff the reduced OBDDs have identical structure.

  • Example. The reduced OBDD for

both boolean functions f(x, y) = x + y and g(x, y) = ¯ x · ¯ y.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 53 / 57

slide-70
SLIDE 70

Test for validity

The function f is valid iff its reduced OBDD is B1. A BDD represents a valid function if no 0-terminal node is reachable from the root along a consistent path in a BDD which represents it. (A consistent path is one which, for every variable, has only dashed lines or

  • nly solid lines leaving nodes labelled by that variable.)

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 54 / 57

slide-71
SLIDE 71

Test for satisfiability

The function f is satisfiable iff its reduced OBDD is not B0. A BDD represents a satisfiable function if a 1-terminal node is reachable from the root along a consistent path in a BDD which represents it.

  • Example. An OBDD for boolean

function f(x1, x2, . . . , x6) = (x1 + x2) · (x3 + x4) · (x5 + x6).

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 55 / 57

slide-72
SLIDE 72

Test for implication

We can test whether f(x1, x2, . . . , xn) implies g(x1, x2, . . . , xn) (i.e. whenever f computes 1, then so does g) by computing the reduced OBDD for f · ¯

  • g. This is B0 iff the implication holds.

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 56 / 57

slide-73
SLIDE 73

Comparing efficiency of five representations of boolean functions

Representation of test for boolean operations boolean functions compact SAT validity · + ¯

  • Prop. formulas
  • ften

hard hard easy easy easy Formulas in DNF sometimes easy hard hard easy hard Formulas in CNF sometimes hard easy easy hard hard Ordered truth tables never hard hard hard hard hard Reduced OBDDs

  • ften

easy easy medium medium easy

Meghdad Ghari (IPM) SAT Solvers Logic Short Course 2016 57 / 57