Decision Procedures An Algorithmic Point of View Part I Decision Procedures for Propositional Logic Decision Procedures for Propositional Logic D. Kroening O. Strichman ETH/Technion Version 1.0, 2007 Outline SAT Example: Equivalence Checking if-then-else Chains Optimization of if-then-else chains original C code optimized C code 1 Modeling with Propositional Logic SAT Example: Equivalence Checking if-then-else Chains SAT Example: Circuit Equivalence Checking if(!a && !b) h(); if(a) f(); else if(!a) g(); else if(b) g(); else f(); else h(); 2 Formal Definition SAT ⇓ ⇑ 3 Conjunctive Normal Form if(!a) { if(a) f(); Definition ⇒ if(!b) h(); else { Tseitin Transformation else g(); if(!b) h(); DIMACS CNF } else f(); else g(); } How to check that these two versions are equivalent? D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 3 / 24 D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 4 / 24 SAT Example II ”Compilation” 1 Represent procedures as independent Boolean variables ≡ if ¬ a ∧ ¬ b then h else if ¬ a then g else h original original := optimized := ≡ ( ¬ a ∧ ¬ b ) ∧ h ∨ ¬ ( ¬ a ∧ ¬ b ) ∧ if ¬ a then g else f if ¬ a ∧ ¬ b then h if a then f ≡ ( ¬ a ∧ ¬ b ) ∧ h ∨ ¬ ( ¬ a ∧ ¬ b ) ∧ ( ¬ a ∧ g ∨ a ∧ f ) else if ¬ a then g else if b then g else f else h 2 Compile if-then-else chains into Boolean formulae optimized ≡ if a then f else if b then g else h ≡ a ∧ f ∨ ¬ a ∧ if b then g else h compile( if x then y else z ) ≡ ( x ∧ y ) ∨ ( ¬ x ∧ z ) ≡ a ∧ f ∨ ¬ a ∧ ( b ∧ g ∨ ¬ b ∧ h ) 3 Check equivalence of Boolean formulae compile( original ) ⇔ compile( optimized ) ( ¬ a ∧¬ b ) ∧ h ∨ ¬ ( ¬ a ∧¬ b ) ∧ ( ¬ a ∧ g ∨ a ∧ f ) ⇔ a ∧ f ∨ ¬ a ∧ ( b ∧ g ∨ ¬ b ∧ h ) D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 5 / 24 D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 6 / 24
How to Check (In)Equivalence? SAT Example: Circuit Equivalence Checking Reformulate it as a satisfiability (SAT) problem: Is there an assignment to a, b, f, g, h , a b which results in different evaluations of original a b and optimized ? c c or equivalently: b ∨ a ∧ c ( a ∨ b ) ∧ ( b ∨ c ) Is the boolean formula equivalent? compile( original ) �↔ compile( optimized ) satisfiable? b ∨ a ∧ c ⇔ ( a ∨ b ) ∧ ( b ∨ c ) Such an assignment provides an easy to understand counterexample D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 7 / 24 D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 8 / 24 SAT SAT SAT belongs to NP SAT (Satisfiability) the classical NP-complete problem: There is a non-deterministic Touring-machine deciding SAT in Given a propositional formula f over n propositional variables polynomial time: V = { x, y, . . . } . guess the assignment σ (linear in n ), calculate σ ( f ) (linear in | f | ) Note: on a real (deterministic) computer this still requires 2 n time SAT is complete for NP (see complexity / theory class) Is there are an assignment σ : V → { 0 , 1 } with σ ( f ) = 1 ? Implications for us: general SAT algorithms are probably exponential in time (unless NP = P) D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 9 / 24 D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 10 / 24 Conjunctive Normal Form CNF for Parity Function is Exponential b Definition (Conjunctive Normal Form) 0 1 0 1 A formula in Conjunctive Normal Form (CNF) is a conjunction of clauses no merging in the Karnaugh 1 0 1 0 map C 1 ∧ C 2 ∧ . . . ∧ C n a 0 1 0 1 all clauses contain all variables c each clause C is a disjunction of literals 1 0 1 0 CNF for parity with n variables has 2 n − 1 clauses C = L 1 ∨ . . . ∨ L m d a ⊕ b ⊕ c ⊕ d and each literal is either a plain variable x or a negated variable x . Better ideas? Example ( a ∨ b ∨ c ) ∧ ( a ∨ b ) ∧ ( a ∨ c ) D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 11 / 24 D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 12 / 24
Example of Tseitin Transformation: Circuit to CNF Algorithmic Description of Tseitin Transformation Tseitin Transformation y 1 For each non input circuit signal s generate a new variable x s o ∧ ( x ↔ a ∧ c ) ∧ 2 For each gate produce complete input / output constraints as clauses x ( y ↔ b ∨ x ) ∧ 3 Collect all constraints in a big conjunction o ( u ↔ a ∨ b ) ∧ u a ( v ↔ b ∨ c ) ∧ The transformation is satisfiability equivalent: b w ( w ↔ u ∧ v ) ∧ w the result is satisfiable iff and only the original formula is satisfiable ( o ↔ y ⊕ w ) c v Not equivalent in the classical sense to original formula: it has new variables o ∧ ( x → a ) ∧ ( x → c ) ∧ ( x ← a ∧ c ) ∧ . . . You an get a satisfying assignment for original formula by projecting the satisfying assignment onto the original variables o ∧ ( x ∨ a ) ∧ ( x ∨ c ) ∧ ( x ∨ a ∨ c ) ∧ . . . D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 13 / 24 D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 14 / 24 Tseitin Transformation: Input / Output Constraints Optimizations for the Tseitin Transformation Negation: x ↔ y ⇔ ( x → y ) ∧ ( y → x ) ⇔ ( x ∨ y ) ∧ ( y ∨ x ) Disjunction: x ↔ ( y ∨ z ) ⇔ ( y → x ) ∧ ( z → x ) ∧ ( x → ( y ∨ z )) Goal is smaller CNF (less variables, less clauses) ⇔ ( y ∨ x ) ∧ ( z ∨ x ) ∧ ( x ∨ y ∨ z ) Extract multi argument operands Conjunction: x ↔ ( y ∧ z ) ⇔ ( x → y ) ∧ ( x → z ) ∧ (( y ∧ z ) → x ) (removes variables for intermediate nodes) ⇔ ( x ∨ y ) ∧ ( x ∨ z ) ∧ (( y ∧ z ) ∨ x ) ⇔ ( x ∨ y ) ∧ ( x ∨ z ) ∧ ( y ∨ z ∨ x ) NNF: half of AND, OR node constraints may be removed due to Equivalence: x ↔ ( y ↔ z ) ⇔ ( x → ( y ↔ z )) ∧ (( y ↔ z ) → x ) monotonicity ⇔ ( x → (( y → z ) ∧ ( z → y )) ∧ (( y ↔ z ) → x ) use sharing ⇔ ( x → ( y → z )) ∧ ( x → ( z → y )) ∧ (( y ↔ z ) → x ) ⇔ ( x ∨ y ∨ z ) ∧ ( x ∨ z ∨ y ) ∧ (( y ↔ z ) → x ) ⇔ ( x ∨ y ∨ z ) ∧ ( x ∨ z ∨ y ) ∧ ((( y ∧ z ) ∨ ( y ∧ z )) → x ) ⇔ ( x ∨ y ∨ z ) ∧ ( x ∨ z ∨ y ) ∧ (( y ∧ z ) → x ) ∧ (( y ∧ z ) → x ) ⇔ ( x ∨ y ∨ z ) ∧ ( x ∨ z ∨ y ) ∧ ( y ∨ z ∨ x ) ∧ ( y ∨ z ∨ x ) D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 15 / 24 D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 16 / 24 DIMACS CNF DIMACS CNF Every clause is a list of numbers, separated by spaces DIMACS CNF format = standard format for CNF A clause ends with 0 Used by most SAT solvers Every number 1 , 2 , . . . corresponds to a variable Plain text file with following structure: → variable names (e.g., a , b , . . . ) have to be mapped to numbers p cnf < # variables > < # clauses > A negative number corresponds to negation < clause > 0 < clause > 0 → Let a have number 5. Then a is -5. . . . One or more lines per clause D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 17 / 24 D. Kroening, O. Strichman (ETH/Technion) Decision Procedures Version 1.0, 2007 18 / 24
Recommend
More recommend