encoding applications into sat
play

Encoding Applications into SAT Marijn J.H. Heule Warren A. Hunt Jr. - PowerPoint PPT Presentation

Encoding Applications into SAT Marijn J.H. Heule Warren A. Hunt Jr. The University of Texas at Austin Heule & Hunt (UT Austin) Encoding Applications into SAT 1 / 34 Introduction Dress Code as Satisability Problem Propositional logic:


  1. Encoding Applications into SAT Marijn J.H. Heule Warren A. Hunt Jr. The University of Texas at Austin Heule & Hunt (UT Austin) Encoding Applications into SAT 1 / 34

  2. Introduction Dress Code as Satisability Problem Propositional logic: Boolean variables : tie and shirt negation : ¬ (not) disjunction ∨ disjunction (or) conjunction ∧ conjunction (and) Three conditions / clauses: clearly one should not wear a tie without a shirt ¬ tie ∨ shirt not wearing a tie nor a shirt is impolite tie ∨ shirt wearing a tie and a shirt is overkill ¬ ( tie ∧ shirt ) ≡ ¬ tie ∨ ¬ shirt Is the formula ( ¬ tie ∨ shirt ) ∧ ( tie ∨ shirt ) ∧ ( ¬ tie ∨ ¬ shirt ) satisable? Heule & Hunt (UT Austin) Encoding Applications into SAT 2 / 34

  3. Introduction Overview Encoding common constraints Applications: Equivalence checking Hardware and software optimization Bounded model checking Hardware and software verification Arithmetic operations Factorization, term rewriting Graph coloring Sudoku, timetabling Heule & Hunt (UT Austin) Encoding Applications into SAT 3 / 34

  4. Common Constraints Common Constraints Heule & Hunt (UT Austin) Encoding Applications into SAT 4 / 34

  5. Common Constraints AtLeastOne Given a set of Boolean variables x 1 , . . ., x n , how to encode AtLeastOne ( x 1 , . . ., x n ) into SAT? Hint: This is easy... Heule & Hunt (UT Austin) Encoding Applications into SAT 5 / 34

  6. Common Constraints AtLeastOne Given a set of Boolean variables x 1 , . . ., x n , how to encode AtLeastOne ( x 1 , . . ., x n ) into SAT? Hint: This is easy... ( x 1 ∨ x 2 ∨ · · · ∨ x n ) Heule & Hunt (UT Austin) Encoding Applications into SAT 5 / 34

  7. Common Constraints AtMostOne (1) Given a set of Boolean variables x 1 , . . ., x n , how to encode AtMostOne ( x 1 , . . . , x n ) into SAT? Heule & Hunt (UT Austin) Encoding Applications into SAT 6 / 34

  8. Common Constraints AtMostOne (1) Given a set of Boolean variables x 1 , . . ., x n , how to encode AtMostOne ( x 1 , . . . , x n ) into SAT? The direct encoding requires n ( n − 1) / 2 binary clauses: � ( ¬ x i ∨ ¬ x j ) 1 ≤ i < j ≤ n Heule & Hunt (UT Austin) Encoding Applications into SAT 6 / 34

  9. Common Constraints AtMostOne (1) Given a set of Boolean variables x 1 , . . ., x n , how to encode AtMostOne ( x 1 , . . . , x n ) into SAT? The direct encoding requires n ( n − 1) / 2 binary clauses: � ( ¬ x i ∨ ¬ x j ) 1 ≤ i < j ≤ n Is it possible to use fewer clauses? Heule & Hunt (UT Austin) Encoding Applications into SAT 6 / 34

  10. Common Constraints AtMostOne (2) Given a set of Boolean variables x 1 , . . ., x n , how to encode AtMostOne ( x 1 , . . . , x n ) into SAT using a linear number of binary clauses? Heule & Hunt (UT Austin) Encoding Applications into SAT 7 / 34

  11. Common Constraints AtMostOne (2) Given a set of Boolean variables x 1 , . . ., x n , how to encode AtMostOne ( x 1 , . . . , x n ) into SAT using a linear number of binary clauses? By splitting the constraint using additional variables. Apply the direct encoding if n ≤ 4 otherwise replace AtMostOne ( x 1 , . . . , x n ) by AtMostOne ( x 1 , x 2 , x 3 , y ) ∧ AtMostOne ( ¬ y , x 4 , . . . , x n ) resulting in 3 n − 6 clauses and ( n − 3) / 2 new variables Heule & Hunt (UT Austin) Encoding Applications into SAT 7 / 34

  12. Common Constraints Exclusive OR Given a set of Boolean variables x 1 , . . ., x n , how to encode XOR ( x 1 , . . . , x n ) into SAT? Heule & Hunt (UT Austin) Encoding Applications into SAT 8 / 34

  13. Common Constraints Exclusive OR Given a set of Boolean variables x 1 , . . ., x n , how to encode XOR ( x 1 , . . . , x n ) into SAT? The direct encoding requires 2 n − 1 clauses of length n : � (( ¬ ) x 1 ∨ ( ¬ ) x 2 ∨ · · · ∨ ( ¬ ) x n ) even # ¬ Heule & Hunt (UT Austin) Encoding Applications into SAT 8 / 34

  14. Common Constraints Exclusive OR Given a set of Boolean variables x 1 , . . ., x n , how to encode XOR ( x 1 , . . . , x n ) into SAT? The direct encoding requires 2 n − 1 clauses of length n : � (( ¬ ) x 1 ∨ ( ¬ ) x 2 ∨ · · · ∨ ( ¬ ) x n ) even # ¬ Make it compact: XOR ( x 1 , x 2 , y ) ∧ XOR (¯ y , x 3 , . . . , x n ) Heule & Hunt (UT Austin) Encoding Applications into SAT 8 / 34

  15. Applications Applications Heule & Hunt (UT Austin) Encoding Applications into SAT 9 / 34

  16. Equivalence Checking Equivalence checking introduction Given two formulae, are they equivalent? Applications: Hardware and software optimization Software to FPGA conversion Heule & Hunt (UT Austin) Encoding Applications into SAT 10 / 34

  17. Equivalence Checking Equivalence checking example original C code if(!a && !b) h(); else if(!a) g(); else f(); Heule & Hunt (UT Austin) Encoding Applications into SAT 11 / 34

  18. Equivalence Checking Equivalence checking example original C code if(!a && !b) h(); else if(!a) g(); else f(); ⇓ if(!a) { if(!b) h(); else g(); } else f(); Heule & Hunt (UT Austin) Encoding Applications into SAT 11 / 34

  19. Equivalence Checking Equivalence checking example original C code if(!a && !b) h(); else if(!a) g(); else f(); ⇓ if(a) f(); if(!a) { else { if(!b) h(); ⇒ if(!b) h(); else g(); } else g(); } else f(); Heule & Hunt (UT Austin) Encoding Applications into SAT 11 / 34

  20. Equivalence Checking Equivalence checking example original C code optimized C code if(!a && !b) h(); if(a) f(); else if(!a) g(); else if(b) g(); else f(); else h(); ⇓ ⇑ if(a) f(); if(!a) { else { if(!b) h(); ⇒ if(!b) h(); else g(); } else g(); } else f(); Heule & Hunt (UT Austin) Encoding Applications into SAT 11 / 34

  21. Equivalence Checking Equivalence checking example original C code optimized C code if(!a && !b) h(); if(a) f(); else if(!a) g(); else if(b) g(); else f(); else h(); ⇓ ⇑ if(a) f(); if(!a) { else { if(!b) h(); ⇒ if(!b) h(); else g(); } else g(); } else f(); How to check that these two versions are equivalent? Heule & Hunt (UT Austin) Encoding Applications into SAT 11 / 34

  22. Equivalence Checking Equivalence checking encoding (1) 1. represent procedures as independent Boolean variables original C code := optimized C code := if ¬ a ∧ ¬ b then h if a then f else if ¬ a then g else if b then g else f else h Heule & Hunt (UT Austin) Encoding Applications into SAT 12 / 34

  23. Equivalence Checking Equivalence checking encoding (1) 1. represent procedures as independent Boolean variables original C code := optimized C code := if ¬ a ∧ ¬ b then h if a then f else if ¬ a then g else if b then g else f else h 2. compile if-then-else into Conjunctive Normal Form compile ( if x then y else z ) ≡ ( ¬ x ∨ y ) ∧ ( x ∨ z ) Heule & Hunt (UT Austin) Encoding Applications into SAT 12 / 34

  24. Equivalence Checking Equivalence checking encoding (1) 1. represent procedures as independent Boolean variables original C code := optimized C code := if ¬ a ∧ ¬ b then h if a then f else if ¬ a then g else if b then g else f else h 2. compile if-then-else into Conjunctive Normal Form compile ( if x then y else z ) ≡ ( ¬ x ∨ y ) ∧ ( x ∨ z ) 3. check equivalence of Boolean formulae compile ( original C code ) ⇔ compile ( optimized C code ) Heule & Hunt (UT Austin) Encoding Applications into SAT 12 / 34

  25. Equivalence Checking Equivalence checking encoding (2) compile ( original C code ): if ¬ a ∧ ¬ b then h else if ¬ a then g else f ≡ ( ¬ ( ¬ a ∧ ¬ b ) ∨ h ) ∨ (( ¬ a ∧ ¬ b ) ∨ ( if ¬ a then g else f )) ≡ ( a ∨ b ∨ h ) ∨ (( ¬ a ∧ ¬ b ) ∨ (( a ∨ g ) ∧ ( ¬ a ∨ f )) Heule & Hunt (UT Austin) Encoding Applications into SAT 13 / 34

  26. Equivalence Checking Equivalence checking encoding (2) compile ( original C code ): if ¬ a ∧ ¬ b then h else if ¬ a then g else f ≡ ( ¬ ( ¬ a ∧ ¬ b ) ∨ h ) ∨ (( ¬ a ∧ ¬ b ) ∨ ( if ¬ a then g else f )) ≡ ( a ∨ b ∨ h ) ∨ (( ¬ a ∧ ¬ b ) ∨ (( a ∨ g ) ∧ ( ¬ a ∨ f )) compile ( optimized C code ): if a then f else if b then g else h ≡ ( ¬ a ∨ f ) ∧ ( a ∨ ( if b then g else h )) ≡ ( ¬ a ∨ f ) ∧ ( a ∨ (( ¬ b ∨ g ) ∧ ( b ∨ h )) Heule & Hunt (UT Austin) Encoding Applications into SAT 13 / 34

  27. Equivalence Checking Equivalence checking encoding (2) compile ( original C code ): if ¬ a ∧ ¬ b then h else if ¬ a then g else f ≡ ( ¬ ( ¬ a ∧ ¬ b ) ∨ h ) ∨ (( ¬ a ∧ ¬ b ) ∨ ( if ¬ a then g else f )) ≡ ( a ∨ b ∨ h ) ∨ (( ¬ a ∧ ¬ b ) ∨ (( a ∨ g ) ∧ ( ¬ a ∨ f )) compile ( optimized C code ): if a then f else if b then g else h ≡ ( ¬ a ∨ f ) ∧ ( a ∨ ( if b then g else h )) ≡ ( ¬ a ∨ f ) ∧ ( a ∨ (( ¬ b ∨ g ) ∧ ( b ∨ h )) ( a ∨ b ∨ h ) ∨ (( ¬ a ∧¬ b ) ∨ (( a ∨ g ) ∧ ( ¬ a ∨ f )) ⇔ ( ¬ a ∨ f ) ∧ ( a ∨ (( ¬ b ∨ g ) ∧ ( b ∨ h )) Heule & Hunt (UT Austin) Encoding Applications into SAT 13 / 34

  28. Equivalence Checking Checking (in)equivalence Reformulate it as a satisfiability (SAT) problem: Is there an assignment to a, b, f , g, and h, which results in different evaluations of the compiled codes? Heule & Hunt (UT Austin) Encoding Applications into SAT 14 / 34

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend