Automated Program Verification and Testing 15414/15614 Fall 2016 Lecture 3: Practical SAT Solving

Similar documents
Automated Program Verification and Testing 15414/15614 Fall 2016 Lecture 2: Propositional Logic

Solvers for the Problem of Boolean Satisfiability (SAT) Will Klieber Aug 31, 2011

Lecture 2 Propositional Logic & SAT

Lecture Notes on SAT Solvers & DPLL

Propositional Logic. Methods & Tools for Software Engineering (MTSE) Fall Prof. Arie Gurfinkel

From SAT To SMT: Part 1. Vijay Ganesh MIT

Heuristics for Efficient SAT Solving. As implemented in GRASP, Chaff and GSAT.

Satisifiability and Probabilistic Satisifiability

COMP219: Artificial Intelligence. Lecture 20: Propositional Reasoning

LOGIC PROPOSITIONAL REASONING

Chapter 7 R&N ICS 271 Fall 2017 Kalev Kask

Satisfiability Modulo Theories

Satisfiability Modulo Theories (SMT)

Propositional Logic: Evaluating the Formulas

Formal Verification Methods 1: Propositional Logic

Foundations of Artificial Intelligence

Solving SAT Modulo Theories

Satisfiability Modulo Theories

Lecture 9: The Splitting Method for SAT

Classical Propositional Logic

An Introduction to SAT Solving

Topics in Model-Based Reasoning

The Calculus of Computation: Decision Procedures with Applications to Verification. Part I: FOUNDATIONS. by Aaron Bradley Zohar Manna

Clause/Term Resolution and Learning in the Evaluation of Quantified Boolean Formulas

An instance of SAT is defined as (X, S)

Propositional Logic. Testing, Quality Assurance, and Maintenance Winter Prof. Arie Gurfinkel

SAT-Solving: From Davis- Putnam to Zchaff and Beyond Day 3: Recent Developments. Lintao Zhang

Tutorial 1: Modern SMT Solvers and Verification

3 Propositional Logic

Propositional Reasoning

The Wumpus Game. Stench Gold. Start. Cao Hoang Tru CSE Faculty - HCMUT

CS156: The Calculus of Computation

Chapter 7 Propositional Satisfiability Techniques

CS:4420 Artificial Intelligence

Lecture 9: Search 8. Victor R. Lesser. CMPSCI 683 Fall 2010

Introduction to Solving Combinatorial Problems with SAT

Propositional and First Order Reasoning

Foundations of Lazy SMT and DPLL(T)

Chapter 7 Propositional Satisfiability Techniques

NP Completeness. CS 374: Algorithms & Models of Computation, Spring Lecture 23. November 19, 2015

EE562 ARTIFICIAL INTELLIGENCE FOR ENGINEERS

Logic in AI Chapter 7. Mausam (Based on slides of Dan Weld, Stuart Russell, Dieter Fox, Henry Kautz )

Price: $25 (incl. T-Shirt, morning tea and lunch) Visit:

Computational Logic. Davide Martinenghi. Spring Free University of Bozen-Bolzano. Computational Logic Davide Martinenghi (1/30)

Introduction to Artificial Intelligence Propositional Logic & SAT Solving. UIUC CS 440 / ECE 448 Professor: Eyal Amir Spring Semester 2010

CSE507. Introduction. Computer-Aided Reasoning for Software. Emina Torlak courses.cs.washington.edu/courses/cse507/17wi/

Title: Logical Agents AIMA: Chapter 7 (Sections 7.4 and 7.5)

Propositional Logic: Models and Proofs

Satisfiability and SAT Solvers. CS 270 Math Foundations of CS Jeremy Johnson

On the Relative Efficiency of DPLL and OBDDs with Axiom and Join

Essential facts about NP-completeness:

Proof Methods for Propositional Logic

EECS 219C: Computer-Aided Verification Boolean Satisfiability Solving III & Binary Decision Diagrams. Sanjit A. Seshia EECS, UC Berkeley

A brief introduction to Logic. (slides from

1 Algebraic Methods. 1.1 Gröbner Bases Applied to SAT

Foundations of Artificial Intelligence

WHAT IS AN SMT SOLVER? Jaeheon Yi - April 17, 2008

Part 1: Propositional Logic

Logic in AI Chapter 7. Mausam (Based on slides of Dan Weld, Stuart Russell, Subbarao Kambhampati, Dieter Fox, Henry Kautz )

Logical agents. Chapter 7. Chapter 7 1

Logical Agents. Chapter 7

Propositional logic. Programming and Modal Logic

Chapter 2. Reductions and NP. 2.1 Reductions Continued The Satisfiability Problem (SAT) SAT 3SAT. CS 573: Algorithms, Fall 2013 August 29, 2013

Abstract Answer Set Solvers with Backjumping and Learning

Foundations of Artificial Intelligence

SAT Solvers: Theory and Practice

Artificial Intelligence

Planning as Satisfiability

Overview, cont. Overview, cont. Logistics. Optional Reference #1. Optional Reference #2. Workload and Grading

SAT, CSP, and proofs. Ofer Strichman Technion, Haifa. Tutorial HVC 13

Reasoning with Quantified Boolean Formulas

Intelligent Agents. Pınar Yolum Utrecht University

Automated Program Verification and Testing 15414/15614 Fall 2016 Lecture 8: Procedures for First-Order Theories, Part 2

Conjunctive Normal Form and SAT

Warm-Up Problem. Is the following true or false? 1/35

Knowledge base (KB) = set of sentences in a formal language Declarative approach to building an agent (or other system):

CS156: The Calculus of Computation Zohar Manna Autumn 2008

Advanced Artificial Intelligence, DT4048

ahmaxsat: Description and Evaluation of a Branch and Bound Max-SAT Solver

Logical agents. Chapter 7. Chapter 7 1

Verification using Satisfiability Checking, Predicate Abstraction, and Craig Interpolation. Himanshu Jain THESIS ORAL TALK

Pythagorean Triples and SAT Solving

CS 380: ARTIFICIAL INTELLIGENCE PREDICATE LOGICS. Santiago Ontañón

TDT4136 Logic and Reasoning Systems

NP and Computational Intractability

Algorithms for Satisfiability beyond Resolution.

CS 380: ARTIFICIAL INTELLIGENCE

Comp487/587 - Boolean Formulas

Inf2D 06: Logical Agents: Knowledge Bases and the Wumpus World

1 Propositional Logic

Logical Agents: Propositional Logic. Chapter 7

SAT, NP, NP-Completeness

Last update: March 4, Logical agents. CMSC 421: Chapter 7. CMSC 421: Chapter 7 1

Mathematical Logic Part Three

Logical Agents. Outline

Logic and Inferences

Chapter 4: Classical Propositional Semantics

Decision Procedures for Satisfiability and Validity in Propositional Logic

Propositional Logic: Methods of Proof (Part II)

Lecture 2: Symbolic Model Checking With SAT

Transcription:

Automated Program Verification and Testing 15414/15614 Fall 2016 Lecture 3: Practical SAT Solving Matt Fredrikson mfredrik@cs.cmu.edu October 17, 2016 Matt Fredrikson SAT Solving 1 / 36

Review: Propositional Semantics Goal: Give meaning to propositional formulas Assign Boolean truth values to (formula, interpretation) pairs Formula F + Interpretation I = TruthValue (true, false) Note: we often abbreviate true by 1 and false by 0 Interpretation An interpretation I for propositional formula F maps every propositional variable appearing in F to a truth value, i.e.: I = {P true, Q false, R false,...} Matt Fredrikson SAT Solving 2 / 36

Review: Interpretations Satisfying Interpretation I is a satisfyinginterpretation of a propositional formula F if F is true under I. We denote this with the notation: I = F Falsifying Interpretation I is a falsifyinginterpretation of a propositional formula F if F is false under I. We denote this with the notation: I = F Matt Fredrikson SAT Solving 3 / 36

Review: Conjunctive Normal Form (CNF) Take the form: To convert to CNF: 1. Convert to NNF 2. Distribute over i j P ij atom ::= P, Q,... literal ::= atom atom clause ::= literal literal clause Naive approach has exponential blowup formula ::= clause clause formula Tseitin s transformation: linear increase in formula size Matt Fredrikson SAT Solving 4 / 36

Satisfiability Problem SAT Problem Given a propositional formula F, decide whether there exists an interpretation I such that I = F. 3SAT was the first established NP-Complete problem (Cook, 1971) Most important logical problems can be reduced to SAT Validity Entailment Equivalence Matt Fredrikson SAT Solving 5 / 36

CNF Notation All of the algorithms we talk about assume that formulas are in CNF We ll refer to a formula as a set of clauses F = {C 1,..., C n } Likewise, clauses as sets of literals (P Q) (Q P ) {{P, Q}, { Q, P }} Some convenient notation: C i {P F }: C i with F substituted for P C i [P ]: P appears positive in C i, i.e., C i = {..., P,...} C i [ P ]: P appears negated in C i, i.e., C i = {..., P,...} C i C j : union of C i and C j, C i C j F i F j : union of F i and F j, F i F j Matt Fredrikson SAT Solving 6 / 36

Resolution Single inference rule: C 1 [P ] C 2 [ P ] C 1 {P } C 2 { P } Given two clauses that share variable P but disagree on its value: 1. If P is true, then some other literal in C 2 must be true 2. If P is false, then some other literal in C 1 must be true 3. Therefore, resolve on P in both clauses by removing it 4. C 1 {P } C 2 { P } is called the resolvent If C 1 {P } C 2 { P } = = : 1. Then C 1 C 2 is unsatisfiable 2. Any CNF containing {C 1, C 2 } is unsatisfiable Matt Fredrikson SAT Solving 7 / 36

Resolution Procedure function Resolution(F ) F = repeat F F F forall C i, C j F do C = Resolve(C i, C j ) if C = then return unsat end if F F {C } end for until F F return sat end function 1. For each round, compute all possible resolvents 2. F holds set of all resolvents 3. At each round, update F to contain past resolvents 4. Repeat resolution on updated F 5. Terminate when: Encounter resolvent Don t find anything new to add to F Matt Fredrikson SAT Solving 8 / 36

Resolution: Example (P Q) (P R) (Q R) R (P Q) ( P R) ( Q R) }{{}}{{}}{{}}{{} R C 1 C 2 C C 4 3 1 P Q 2 P R 3 Q R 4 R 5 Q R 1 & 2 7 P 2 & 4 8 Q 3 & 4 9 R 3 &5 10 Q 4 &5 11 P 1 &8 12 4 &9 Matt Fredrikson SAT Solving 9 / 36

Resolution: Properties Why is resolution particularly bad for large problems? Hint: What does this technique build along the way? Space complexity: exp(o(n)) Example: m pigeons won t go into n holes when m > n p i,j : pigeon i goes in hole j p i,1 p i,2 p i,n : every pigeon i gets a hole p i,j p i,j: no hole j gets two pigeons i i Resolution proof size: exp(ω(n)) Matt Fredrikson SAT Solving 10 / 36

Partial Interpretations Starting from an empty interpretation: Extend for each variable No direct modifications to literals in formula More flexibility in implementation strategy (more on this later) If I is a partial interpretation, literals l can be true, false, undef: true (satisfied): I = l false (conflicting): I = l undef: var(l) I Given a clause C and interpretation I: C is true under I iff I = C C is false under I iff I = C C is unit under I iff C = C l, I = C, l is undef Otherwise it is undef Matt Fredrikson SAT Solving 11 / 36

Example I = {P 1 1, P 2 0, P 4 1} P 1 P 3 P 4 satisfied P 1 P 2 conflicting P 1 P 4 P 3 unit P 1 P 3 P 5 undef Matt Fredrikson SAT Solving 12 / 36

Decision Procedure as a Transition System Transition system is a binary relation over states Transitions are induced by guarded transition rules Procedure State The possible states are: sat unsat [I] F Where [I] is an ordered interpretation, F is a CNF. Initial state: [ ] F Final states: sat, unsat Ex. intermediate states: [ ] F 1, C: empty interpretation, F = F 1 C [I 1, P, I 2 ] F : interp. assigns I 1 first, then P 0, then I 2 Matt Fredrikson SAT Solving 13 / 36

Basic Search Decision Rule [I] F [I, P ] F if { P occurs in F P unassigned in I Backtrack Rule [I 1, P, I 2 ] F [I 1, P ] F if { [I1, P, I 2 ] = F P last decision in interp. Sat Rule [I] F sat if [I] = F Unsat Rule [I] F unsat if { [I] = F No decisions in I Matt Fredrikson SAT Solving 14 / 36

Example F := C 1 = P 1 P 2 C 2 = P 3 P 4 C 3 = P 6 P 5 P 2 C 4 = P 5 P 6 C 5 = P 5 P 7 C 6 = P 1 P 5 P 7 I P 2 P2, P4 P2, P4, P5 P2, P4, P5, P6 P2, P4, P5, P 6 P2, P4, P 5 P2, P4, P 5, P7 P2, P4, P 5, P7 Rule Decide Decide Decide Decide Backtrack Backtrack Decide Sat Matt Fredrikson SAT Solving 15 / 36

Unit Propagation Recall unit clauses. For an interpretation I and clause C, I does not satisfy C All but one literals in C are assigned I implies an assignment for the unassigned literal Unit Propagation Rule [I] F, C ( )P [I, P (or P )] F, C ( )P if { [I] = C P undefined in I This is a restricted form of resolution Matt Fredrikson SAT Solving 16 / 36

Example Revisited F := C 1 = P 1 P 2 C 2 = P 3 P 4 C 3 = P 6 P 5 P 2 C 4 = P 5 P 6 C 5 = P 5 P 7 C 6 = P 1 P 5 P 7 I Rule I Rule P 1 P1, P 2 P1, P 2, P3 P1, P 2, P3, P 4 P1, P 2, P3, P 4, P5 P1, P 2, P3, P 4, P5, P 6 P1, P 2, P3, P 4, P 5 P1, P 2, P3, P 4, P 5, P 7 Decide Propagate Decide Propagate Decide Propagate Backtrack Propagate P1, P 2, P 3 P1, P 2, P 3, P5 P1, P 2, P 3, P5, P 6 P1, P 2, P 3, P 5 P1, P 2, P 3, P 5, P 7 P 1 P 1, P 2, P 3, P 4, P 5, P 7 Backtrack Decide Propagate Backtrack Propagate Backtrack Sat Matt Fredrikson SAT Solving 17 / 36

Example F := C 1 = P 1 P 2 C 2 = P 2 P 3 C 3 = P 3 P 4 C 4 = P 4 P 5 C 5 = P 5 P 1 C 6 = P 1 P 2 P 3 P 4 P 5 I P 1 Rule Decide P1, P 2 Propagate P1, P 2, P 3 Propagate P1, P 2, P 3, P 4 Propagate P1, P 2, P 3, P 4, P 5 Propagate P 1 Backtrack P 1, P2 Decide P 1, P2, P 3 Propagate (Several propagations) P 1, P2, P 3, P 4, P 5 Sat Matt Fredrikson SAT Solving 18 / 36

Non-Chronological Backtracking & Clause Learning The backtracking rule seems short-sighted It always jumps to the most recent decision It does not keep information about the conflict Backjump Rule [I 1, P, I 2 ] F [I 1, l] F, C if [I 1, P, I 2 ] = F Exists C s.t. : F (C l) I 1 = C var(l) undef. in I 1 var(l) appears in F C is called a conflictclause Will help us prevent similar conflicts in the future Matt Fredrikson SAT Solving 19 / 36

Example Revisited (again) F := C 1 = P 1 P 2 C 2 = P 3 P 4 C 3 = P 6 P 5 P 2 C 4 = P 5 P 6 C 5 = P 5 P 7 C 6 = P 1 P 5 P 7 I P 1 C 7 = P 1 P 5 Rule Decide P1, P 2 Propagate P1, P 2, P3 Decide P1, P 2, P3, P 4 Propagate P1, P 2, P3, P 4, P5 Decide P1, P 2, P3, P 4, P5, P 6 Propagate P1, P 2, P 5 Backjump, P 1 P 5 P1, P 2, P 5, P 7 Propagate P 1 Backjump, true P 1 Matt Fredrikson SAT Solving 20 / 36

Finding a Conflict Clause The Backjump rule requires a conflict clause To find one, we construct an implicationgraph G = (V, E) V has a node for each decision literal in I, labeled with the literal s value and its decision level. For each clause C = l 1 l n l where l 1,..., l n are assigned false, 1. Add a node for l with the decision level in which it entered I 2. Add edges (l i, l) for 1 i n to E Add a special conflictnode Λ. For any conflictvariable with nodes labeled P and P, add edges from these nodes to Λ in E. Label each edge with the clause that caused the implication. The implication graph contains sufficient information to generate a conflict clause Matt Fredrikson SAT Solving 21 / 36

Implication Graph F := C 1 = P 1 P 2 C 2 = P 3 P 4 C 3 = P 6 P 5 P 2 C 4 = P 5 P 6 C 5 = P 5 P 7 C 6 = P 1 P 5 P 7 I = [P 1, P 2, P 3, P 4, P 5, P 6 ] P 3 @2 P 4 @2 C 2 P 6 @3 C 4 Λ P 5 @3 C 4 C 3 P 6 @3 C 3 C C 3 1 P 1 @1 P 2 @1 Matt Fredrikson SAT Solving 22 / 36

Conflict Graph Implication graph where: Exactly one conflict variable All nodes have a path to Λ C 1 = P 1 P 2 C 2 = P 3 P 4 C 3 = P 6 P 5 P 2 C 4 = P 5 P 6 C 5 = P 5 P 7 C 6 = P 1 P 5 P 7 I = [P 1, P 2, P 3, P 4, P 5, P 6 ] P 6 @3 C 4 Λ P 5 @3 C 4 C 3 P 6 @3 C 3 C C 3 1 P 1 @1 P 2 @1 Matt Fredrikson SAT Solving 23 / 36

Generating Conflict Clauses Consider a conflict graph G 1. Pick a cut in G such that: All of the decision nodes are on one side (the reason side) At least one conflict literal is on the other (the conflict side) 2. Pick all nodes K on the reason side with an edge crossing the cut 3. The nodes in K form a cause of the conflict 4. The negations of the corresponding literal form the conflict clause Matt Fredrikson SAT Solving 24 / 36

Generating Conflict Clauses C 1 = P 1 P 2 C 2 = P 3 P 4 C 3 = P 6 P 5 P 2 C 4 = P 5 P 6 C 5 = P 5 P 7 C 6 = P 1 P 5 P 7 I = [P 1, P 2, P 3, P 4, P 5, P 6 ] P 6 @3 C 4 Λ P 5 @3 C 4 C 3 P 6 @3 C 3 C C 3 1 P 1 @1 P 2 @1 Conflict clause: P 1 P 5 Matt Fredrikson SAT Solving 25 / 36

Generating Conflict Clauses P 1 @1 C 1 = P 1 P 2 C 2 = P 2 P 3 C 3 = P 3 P 4 C 4 = P 4 P 5 C 5 = P 5 P 1 C 6 = P 1 P 2 P 3 P 4 P 5 I = [P 1, P 2, P 3, P 4, P 5 ] P 5 @1 C 5 P 2 @1 P 3 @1 C 1 C 2 C 3 Conflict clause: P 1 P 2 Any others? Does order matter? C 4 P 4 @1 P 5 @1 Λ C 4 C 5 Matt Fredrikson SAT Solving 26 / 36

Generating Conflict Clauses This corresponds to resolution: 1. Let C be the conflicted clause 2. Pick most recently implied literal in conflict graph G 3. Let C be the clause that implied it 4. Let C resolve(c, C ) 5. Repeat step 2 while applicable C 1 = P 1 P 2 C 2 = P 3 P 4 C 3 = P 6 P 5 P 2 C 4 = P 5 P 6 C 5 = P 5 P 7 C 6 = P 1 P 5 P 7 I = [P 1, P 2, P 3, P 4, P 5, P 6 ] 1. C = P 5 P 6 2. Pick P 6 3. C = P 6 P 5 P 2 4. C = P 5 P 2 5. Pick P 2 6. C = P 1 P 2 7. C = P 1 P 5 Matt Fredrikson SAT Solving 27 / 36

Generating Conflict Clauses The textbook doesn t cover this at all For more information, see: http://www.cs.cmu.edu/afs/cs/project/jair/pub/ volume22/beame04a-html/, Sections 3.4 and 3.5 DecisionProcedures by Kroening and Strichman. Download a copy from the library by visiting: http://vufind.library.cmu.edu/vufind/record/1607216 Matt Fredrikson SAT Solving 28 / 36

DPLL and CDCL Original DPLL used: Decide, Sat/Unsat, Propagate, Backtrack Modern DPLL replaces: Backtrack with Backjump These are called ConflictDriven ClauseLearning (CDCL) solvers In addition, most use: Forgetting : periodically forget learned clauses Restart: reset interpretation, but keep learned clauses while(1) { while(exists_unit(i, F)) I, F = propagate(i, F); I, F = decide(i, F); if(conflict(i, F)) { if(has_decision(i)) I, F = backjump(i, F); else return unsat; } else if(sat(i, F)) return sat; } Matt Fredrikson SAT Solving 29 / 36

Correctness of DPLL Soundness For every execution starting with [ ] F and ending with [I] sat (resp. [I] unsat), F is satisfiable (resp. unsatisfiable). Completeness If F is satisfiable (resp. unsatisfiable), then every execution starting with [ ] F ends with [I] sat (resp. [I] unsat). Note: Termination not obvious with Backjump. Define a metric that decreases: When adding a decision level (Decide) When adding literal to the current decision level (Propagate) When adding literal to previous decision level (Backjump) Matt Fredrikson SAT Solving 30 / 36

Practical Considerations Conflict-Driven Clause Learning (CDCL) made large-scale SAT practical GRASP solver, 1996 From hundreds and low-thousands to thousands and millions of variables Focus shifted towards better heuristics, implementation Several considerations proved effective: Make resolution more efficient: keep # memory accesses per iteration low Simple, low-overhead decision guidance Strategies for forgetting learned clauses Matt Fredrikson SAT Solving 31 / 36

Watch Pointers Idea: Watch two unassigned literals in each non-satisfied clause. Ignore the rest. Maintain two lists for each variable P The first, L P, contains watching clauses with P The second, L P, contains watching clauses with P Each time an assignment to is made to P : 1. For clauses in L P,P, find another literal in the clause to watch 2. If (1) is not possible, the clause is unit Advantages: 1. When P assigned, only examine clauses in the appropriate list 2. No overhead when backtracking Matt Fredrikson SAT Solving 32 / 36

Dynamic Largest Individual Sum (DLIS) Decision heuristic: choose variable that satisfies the most clauses How do we implement this? Maintain sat counters for every variable When clauses are satisfied, update counters Must touch every clause containing literal set to 1 Need to reverse process when backtracking More overhead than unit propagation... Probably not worth it Matt Fredrikson SAT Solving 33 / 36

Variable State Independent Decaying Sum (VSIDS) Rank variables by literal count in the initial database Only increment when clauses are learned Periodically divide all counts by 2 Main idea: bias towards literals from recent conflicts Conflict adds 1 to each literal in conflict clause More time passed more divisions by 2 Effectively solves conflicts before moving onto new clauses Use heap structure to find unassigned variable with the highest ranking Matt Fredrikson SAT Solving 34 / 36

Other Approaches There are other good SAT-solving approaches Randomized approaches (GSAT, WSAT) Hill-climbing, local search algorithms State: full interpretation, Cost: # non-satisfied clauses Move: flip one assignment Binary decision diagrams Efficiently represent formula as a DAG Manipulate formula by changing graph structure Stalmarck s algorithm Breadth-first search: try both branches at once Also branch on variable relationships Matt Fredrikson SAT Solving 35 / 36

Next Lecture Install Dafny on your machine See the Assignments section on course webpage for a guide Matt Fredrikson SAT Solving 36 / 36