Satisfiability Modulo Theories

Similar documents
Satisfiability Modulo Theories

Tutorial 1: Modern SMT Solvers and Verification

Solving SAT Modulo Theories

Topics in Model-Based Reasoning

Satisfiability Modulo Theories (SMT)

SMT Solvers: Theory and Implementation

An Introduction to SAT Solving

Lecture 2 Propositional Logic & SAT

COMP219: Artificial Intelligence. Lecture 20: Propositional Reasoning

Rewriting for Satisfiability Modulo Theories

CS156: The Calculus of Computation

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

Chapter 7 R&N ICS 271 Fall 2017 Kalev Kask

Leonardo de Moura Microsoft Research

Formal Verification Methods 1: Propositional Logic

Leonardo de Moura Microsoft Research

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

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

Satisfiability Modulo Theories

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

SAT Solvers: Theory and Practice

Logical Agents. Chapter 7

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

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

Classical Propositional Logic

EE562 ARTIFICIAL INTELLIGENCE FOR ENGINEERS

Computation and Inference

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

Constraint Logic Programming and Integrating Simplex with DPLL(T )

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

Lecture 1: Logical Foundations

Intelligent Agents. Pınar Yolum Utrecht University

Propositional Logic: Methods of Proof (Part II)

LOGIC PROPOSITIONAL REASONING

Propositional Reasoning

Propositional and First Order Reasoning

First-Order Logic First-Order Theories. Roopsha Samanta. Partly based on slides by Aaron Bradley and Isil Dillig

Part 1: Propositional Logic

Propositional Logic: Methods of Proof. Chapter 7, Part II

Propositional Logic: Methods of Proof (Part II)

CS156: The Calculus of Computation Zohar Manna Autumn 2008

Internals of SMT Solvers. Leonardo de Moura Microsoft Research

Lecture 9: The Splitting Method for SAT

From SAT To SMT: Part 1. Vijay Ganesh MIT

Foundations of Lazy SMT and DPLL(T)

Propositional Logic: Evaluating the Formulas

Propositional and Predicate Logic. jean/gbooks/logic.html

Propositional Logic: Models and Proofs

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

An Introduction to Satisfiability Modulo Theories

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

Foundations of Artificial Intelligence

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

First-Order Theorem Proving and Vampire

Quantifiers. Leonardo de Moura Microsoft Research

Propositional logic. Programming and Modal Logic

Reasoning with Quantified Boolean Formulas

Proof Methods for Propositional Logic

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

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

Class Assignment Strategies

Propositional and Predicate Logic - V

Abstract DPLL and Abstract DPLL Modulo Theories

Deliberative Agents Knowledge Representation I. Deliberative Agents

Logical agents. Chapter 7. Chapter 7 1

First Order Logic (FOL)

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

Mathematical Logic Part Three

Satisfiability Modulo Theories (SMT)

Logical Agents. Santa Clara University

Logic and Inferences

Part 1: Propositional Logic

Combining Decision Procedures

Lecture Notes on SAT Solvers & DPLL

CS 771 Artificial Intelligence. Propositional Logic

Advanced Topics in LP and FP

Comp487/587 - Boolean Formulas

CS:4420 Artificial Intelligence

Model Based Theory Combination

Satisifiability and Probabilistic Satisifiability

Finite model finding in satisfiability modulo theories

3 Propositional Logic

CS 380: ARTIFICIAL INTELLIGENCE

Logical Agents. Outline

First Order Logic (FOL) 1 znj/dm2017

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

Solving SAT and SAT Modulo Theories: From an Abstract Davis Putnam Logemann Loveland Procedure to DPLL(T)

TDT4136 Logic and Reasoning Systems

Kecerdasan Buatan M. Ali Fauzi

First-Order Logic. 1 Syntax. Domain of Discourse. FO Vocabulary. Terms

COMP9414: Artificial Intelligence Propositional Logic: Automated Reasoning

Introduction to Artificial Intelligence. Logical Agents

Integrating Simplex with DPLL(T )

Logical agents. Chapter 7. Chapter 7 1

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

Foundations of Artificial Intelligence

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

Foundations of Artificial Intelligence

Propositional Logic: Methods of Proof (Part II)

Propositional Calculus

Transcription:

Satisfiability Modulo Theories Summer School on Formal Methods Menlo College, 2011 Bruno Dutertre and Leonardo de Moura bruno@csl.sri.com, leonardo@microsoft.com SRI International, Microsoft Research SAT/SMT p.1/50

What s Satisfiability Modulo Theory Satisfiability is the problem of determining whether a formula φ has a model If φ is propositional, a model is a truth assignemt to Boolean variables If φ is a first-order formula, a model assigns values to variables and interpretations to the function and predicate symbols SAT Solvers: check satisfiability of propositional formulas SMT Solvers: check satisfiability of formulas in a decidable first-order theory (e.g., linear arithmetic, uninterpreted functions, array theory, bitvectors) SAT/SMT p.2/50

Example b + 2 = c f(read(write(a,b, 3),c 2)) f(c b + 1) SAT/SMT p.3/50

Example b + 2 = c f(read(write(a,b, 3),c 2)) f(c b + 1) Arithmetic SAT/SMT p.3/50

Example b + 2 = c f(read(write(a,b, 3),c 2)) f(c b + 1) Array theory SAT/SMT p.3/50

Example b + 2 = c f(read(write(a,b, 3),c 2)) f(c b + 1) Uninterpreted function SAT/SMT p.3/50

Example b + 2 = c f(read(write(a,b, 3),c 2)) f(c b + 1) SAT/SMT p.3/50

Example b + 2 = c f(read(write(a,b, 3),c 2)) f(c b + 1) By arithmetic, this is equivalent to b + 2 = c f(read(write(a,b, 3),b)) f(3) SAT/SMT p.3/50

Example b + 2 = c f(read(write(a,b, 3),c 2)) f(c b + 1) By arithmetic, this is equivalent to b + 2 = c f(read(write(a,b, 3),b)) f(3) then, by the array theory axiom: read(write(v,i,x),i) = x b + 2 = c f(3) f(3) SAT/SMT p.3/50

Example b + 2 = c f(read(write(a,b, 3),c 2)) f(c b + 1) By arithmetic, this is equivalent to b + 2 = c f(read(write(a,b, 3),b)) f(3) then, by the array theory axiom: read(write(v,i,x),i) = x b + 2 = c f(3) f(3) then, the formula is unsatisfiable SAT/SMT p.3/50

Example 2 x 0 f(x) 0 y 0 f(y) 0 x y SAT/SMT p.4/50

Example 2 x 0 f(x) 0 y 0 f(y) 0 x y This formula is satisfiable SAT/SMT p.4/50

Example 2 x 0 f(x) 0 y 0 f(y) 0 x y This formula is satisfiable: Example model: x 1 y 2 f(1) 0 f(2) 1 f(...) 0 SAT/SMT p.4/50

SMT Solving Input a first-order formula φ Output the status of φ: satisfiable or unsatisfiable optionally, if φ is satisfiable, a model of φ also optionally, if φ is unsatisfiable, a proof of unsatisfiability Main issues Formula size (e.g., thousands of atoms or more) Formulas with complex Boolean structure Combinations of theories SAT/SMT p.5/50

Overview of SMT Solving SMT Solver = SAT Solver + Theory Solver The SAT solver enumerates possible truth assignments The theory solver is a decision procedure that checks whether the truth assignments are satisfiable in the theory (or combination of theories) Efficient integration uses several mechanisms Theory explanations to rule out unsatisfiable truth assignments Theory lemmas and theory propagation to prune the SAT solver search tree SAT/SMT p.6/50

Naïve SMT Solving x + y 0 (x = z z + y = 1) z > 3t 1) Replace atoms by boolean variables a x + y 0 b x = z c z + y = 1 d z > 3t 2) Ask for a model of a (b c) d using a SAT solver Boolean model: {a,b,c,d} Convert the model back to arithmetic x + y 0 x = z z + y = 1 z > 3t This is not consistent: Arithmetic = (x + y 0 x = z z + y = 1) SAT/SMT p.7/50

Naïve SMT Solving (continued) 3) Feed the explanation to the SAT solver: add the clause ( a b c) 4) Get a model of (a (b c) d) ( a b c) Boolean model: {a, b,c,d} Convert back to arithmetic: x + y 0 (x = z) z + y = 1 z > 3t Check consistency: satisfiable Conclusion: The original formula is satisfiable SAT/SMT p.8/50

Remainder of the Lectures We will cover the basics of SAT and SMT solving more precisely. We will not give a comprehensive survey, but a basic and rigorous introduction to some of the key ideas. This tutorial is not directed at experts but at potential users and developers of SMT solvers. SAT/SMT p.9/50

Plan Lecture 1: principles of SAT solving Logic background Modern DPLL SAT solvers Lecture 2: SMT solving DPLL + Theory Solvers Theory combination Equality Arithmetic Lecture 3: applications of SMT SAT/SMT p.10/50

Roadmap Logic Background Modern SAT Solvers DPPL with Theory Solvers Theory Combination Equality Arithmetic Applications SAT/SMT p.11/50

Logic Basics Logic studies the trinity between language, interpretation, and proof. Language circumscribes the syntax that is used to construct sensible assertions. Interpretation ascribes an intended sense to these assertions by fixing the meaning of certain symbols, e.g., the logical connectives, and delimiting the variation in the meanings of other symbols, e.g., variables, functions, and predicates. An assertion is valid if it holds in all interpretations. Checking validity through interpretations is typically not feasible, so proofs in the form axioms and inference rules are used to demonstrate the validity of assertions. SAT/SMT p.12/50

Language: Signatures A signature Σ is a finite set of: Function symbols: Σ F = {f,g,...}. Predicate symbols: Σ P = {p,q,...}. and an arity function: Σ N Function symbols with arity 0 are called constants. A countable set V of variables disjoint of Σ. SAT/SMT p.13/50

Language: Terms The set T(Σ, V) of terms is the smallest set such that: V T(Σ, V) f(t 1,...,t n ) T(Σ, V) whenever f Σ F, t 1,...,t n T(Σ, V) and arity(f) = n. The set of ground terms is defined as T(Σ, ). SAT/SMT p.14/50

Language: Atomic Formulas p(t 1,...,t n ) is an atomic formula whenever p Σ P, arity(p) = n, and t 1,...,t n T(Σ, V). true and false are atomic formulas. If t 1,...,t n are ground terms, then p(t 1,...,t n ) is called a ground (atomic) formula. We assume that the binary predicate = is present in Σ P. A literal is an atomic formula or its negation. SAT/SMT p.15/50

Language: Quantifier Free Formulas The set QFF(Σ, V) of quantifier-free formulas is the smallest set such that: Every atomic formulas is in QFF(Σ, V). If φ QFF(Σ, V), then φ QFF(Σ, V). If φ 1,φ 2 QFF(Σ, V), then φ 1 φ 2 QFF(Σ, V) φ 1 φ 2 QFF(Σ, V) φ 1 φ 2 QFF(Σ, V) φ 1 φ 2 QFF(Σ, V) SAT/SMT p.16/50

Language: Formulas The set of first-order formulas is the closure of QFF(Σ, V) under existential ( ) and universal ( ) quantification. Free (occurrences) of variables in a formula are those not bound by a quantifier. A sentence is a first-order formula with no free variables. SAT/SMT p.17/50

Models (Semantics) A model M is defined as: Domain M : set of elements. Interpretation M(f) : M n M for each f Σ F with arity(f) = n. Interpretation M(p) M n for each p Σ P with arity(p) = n. Assignment M(x) M for every variable x V. A formula φ is true in a model M if it evaluates to true under the given interpretations over the domain M. SAT/SMT p.18/50

Interpreting Terms M [x] = M(x) M [f(a 1,...,a n )] = M(f)(M [a 1 ],...,M [a n ]) SAT/SMT p.19/50

Interpreting Formulas The interpretation of a formula F in M, M [F ], is defined as M = a = b M = p(a 1,...,a n ) M = ψ M [a] = M [b] M [a 1 ],...,M [a n ] M(p) M = ψ M = ψ 1 ψ 2 M = ψ 1 or M = ψ 2 M = ψ 1 ψ 2 M = ψ 1 and M = ψ 2 M = ( x : ψ) M{x a} = ψ, for all a M M = ( x : ψ) M{x a} = ψ, for some a M SAT/SMT p.20/50

Interpretation Example Σ = {0, +,<}, and M such that M = {a,b,c} M(0) = a, M(+) = { a,a a, a,b b, a,c c, b,a b, b,b c, b,c a, c,a c, c,b a, c,c b } M(<) = { a,b, a,c, b,c } If M(x) = a,m(y) = b,m(z) = c, then M [+(+(x,y),z)] = M(+)(M(+)(M(x),M(y)),M(z)) = M(+)(M(+)(a,b),c) = M(+)(b,c) = a SAT/SMT p.21/50

Interpretation Example Σ = {0, +,<}, and M such that M = {a,b,c} M(0) = a, M(+) = { a,a a, a,b b, a,c c, b,a b, b,b c, b,c a, c,a c, c,b a, c,c b } M(<) = { a,b, a,c, b,c } M = ( x : ( y : +(x,y) = 0)) M = ( x : ( y : x < y)) M = ( x : ( y : +(x,y) = x)) SAT/SMT p.22/50

Validity A formula F is satisfiable if there is a model M such that M = F. Otherwise, the formula F is unsatisfiable. If a formula is satisfiable, so is its existential closure x : F, where x is vars(f), the set of free variables in F. If a formula F is unsatisfiable, then the negation of its existential closure x : F is valid. SAT/SMT p.23/50

Theories A (first-order) theory T (over a signature Σ) is a set of (deductively closed) sentences (over Σ and V). Let DC(Γ) be the deductive closure of a set of sentences Γ. For every theory T, DC(T ) = T. A theory T is consistent if false T. We can view a (first-order) theory T as the class of all models of T (due to completeness of first-order logic). SAT/SMT p.24/50

Satisfiability and Validity A formula φ( x) is satisfiable in a theory T if there is a model of DC(T x.φ( x)). That is, there is a model M for T in which φ( x) evaluates to true, denoted by, M = T φ( x) This is also called T -satisfiability. A formula φ( x) is valid in a theory T if x.φ( x) T. That is φ( x) evaluates to true in every model M of T. T -validity is denoted by = T φ( x). The quantifier free T -satisfiability problem restricts φ to be quantifier free. SAT/SMT p.25/50

Roadmap Logic Background Modern SAT Solvers DPLL with Theory Solvers Theory Combination Equality Arithmetic Applications SAT/SMT p.26/50

SAT Solvers Modern Boolean SAT solvers are based on the Davis-Putnam and Davis-Logemann-Loveland (DPLL) procedures Input formula is in Conjunctive Normal Form (CNF) Solvers combine search with backtracking and deduction based on resolution SAT/SMT p.27/50

Clausal Form (CNF) In clausal form, a formula is a set (conjunction) of clauses i C i, and each clause C i is a disjunction of literals. A literal is an atom or the negation of an atom. Example: (p 1 p 2 ) ( p 1 p 2 p 3 ) p 3 Theorem: for any formula φ, there s a CNF formula φ such that φ φ. But, φ may be exponentially larger than φ. For example, if φ is (p 1 q 1 ) (p 2 q 2 )... (p n q n ). Rather than constructing a CNF formula equivalent to φ, it s cheaper to construct a CNF formula φ that preserves satisfiability: φ is satisfiable iff φ is satisfiable SAT/SMT p.28/50

Efficient Conversion to CNF Idea: replace a subformula ψ by a fresh variable p, then add clauses to express the constraint p ψ For example, we can replace (p 1 p 2 ) by a fresh p and add the clauses ( p p 1 ), ( p p 2 ), and (p p 1 p 2 ) SAT/SMT p.29/50

CNF-Conversion Procedure CNF(p, ) = p, CNF( φ, ) = l,, where l, = CNF(φ, ) CNF(φ 1 φ 2, ) = p,, where l 1, 1 = CNF(φ 1, ) l 2, 2 = CNF(φ 2, 1 ) p is fresh = 2 { p l 1, p l 2, l 1 l 2 p} CNF(φ 1 φ 2, ) = p,, where... = 2 { p l 1 l 2, l 1 p, l 2 p} Theorem: φ and l are equisatisfiable, where CNF(φ, ) = l,. SAT/SMT p.30/50

Conversion to CNF: Example p 1 {}}{ CNF( (q 1 (q 2 q 3 )), ) = }{{} p 2 p 2, { p 1 q 2 q 3, q 2 p 1, q 3 p 1, p 2 q 1, p 2 p 1, q 1 p 1 p 2 } SAT/SMT p.31/50

Conversion to CNF: Improvements Maximize sharing & canonicity in the input formula F. Cache φ l, when CNF(φ, ) = l,. Support for multiary and.... SAT/SMT p.32/50

Resolution Resolution rule: take two clauses (p A) and ( p B) add the new clause (A B), called the resolvent In this rule, clauses are considered as sets of literals: No duplicate literals in clauses. (A B) is a tautology (can be deleted) if it contains complementary literals l and l The empty clause is false. Property: if F is a set of clauses (CNF formula), and C is the resolvent of two clauses from F, then F and F C are equivalent. So, if we can derive the empty clause from F using resolution, we know that F is unsatisfiable. SAT/SMT p.33/50

Resolution: Example p q r, p q, p r, r SAT/SMT p.34/50

Resolution: Example p q r, p q, p r, r p q r, p q, p r, r, q r SAT/SMT p.34/50

Resolution: Example p q r, p q, p r, r p q r, p q, p r, r, q r p q r, p q, p r, r, q r, q r SAT/SMT p.34/50

Resolution: Example p q r, p q, p r, r p q r, p q, p r, r, q r p q r, p q, p r, r, q r, q r p q r, p q, p r, r, q r, q r, r SAT/SMT p.34/50

Resolution: Example p q r, p q, p r, r p q r, p q, p r, r, q r p q r, p q, p r, r, q r, q r p q r, p q, p r, r, q r, q r, r unsat SAT/SMT p.34/50

The (original) DPLL Search Procedure Exhaustive resolution is not practical (exponential amount of memory). DPLL tries to build incrementally a model M for a CNF formula F. M is grown by: deducing the truth value of a literal from M and F, or guessing the truth value of an unassigned literal Deducing is based on the unit-propagation rule: If F contains a clause C l and all literals of C are false in M then l must be true. If a wrong guess leads to an inconsistency, the procedure backtracks to the last guess and tries the opposite value. SAT/SMT p.35/50

Improvements to DPLL in Modern SAT solvers Breakthrough: Conflict-driven clause learning and backjumping: When an inconsistency is detected, use resolution to construct a new (learned) clause This clause is used to determine how far to backtrack Benefits: Backtracking can happen further than the last guess (pruning of the search tree) The learned clause may avoid repeating the same conflict Other improvements: restarts, variable activity heuristics, clause indexing for fast propagation, preprocessing, etc. SAT/SMT p.36/50

Abstract DPLL During search, DPLL states are pairs M F where M is a truth assignment F is a set of clauses (problem clauses + learned clauses) The truth assignment is a list of literals: either decision literals (guesses) or implied literals (by unit propagation). If literal l is implied by unit propagation from clause C l, then the clause is recorded as the explanation for l. This is written l C l in M. During conflict resolution, the state is written M F C where M and F are as before, and C is a clause. C is false in the assigment M (written M = C) C is either a clause of F or is derived by resolution from clauses of F. SAT/SMT p.37/50

Abstract DPLL M F = M l F if 8 < : l or l occurs in F, l is undefined in M (Decide) M F, C l = M l C l F, C l if 8 < : M = C, l is undefined in M (UnitPropagate) M F, C = M F, C C if M = C (Conflict) M F C l = M F D C if l D l M, (Resolve) M F C = M F, C C if C F (Learn) M l M F C l = M l C l F if 8 < : M = C, l is undefined in M (Backjump) M F = unsat (Unsat) SAT/SMT p.38/50

Abstract DPLL: Example 1 2, 3 4, 5 6, 6 5 2 SAT/SMT p.39/50

Abstract DPLL: Example 1 2, 3 4, 5 6, 6 5 2 (Decide) 1 1 2, 3 4, 5 6, 6 5 2 SAT/SMT p.39/50

Abstract DPLL: Example 1 2, 3 4, 5 6, 6 5 2 (Decide) 1 1 2, 3 4, 5 6, 6 5 2 (UnitProp) 1 2 1 2 1 2, 3 4, 5 6, 6 5 2 SAT/SMT p.39/50

Abstract DPLL: Example 1 2, 3 4, 5 6, 6 5 2 (Decide) 1 1 2, 3 4, 5 6, 6 5 2 (UnitProp) 1 2 1 2 1 2, 3 4, 5 6, 6 5 2 (Decide) 1 2 1 2 3 1 2, 3 4, 5 6, 6 5 2 SAT/SMT p.39/50

Abstract DPLL: Example 1 2, 3 4, 5 6, 6 5 2 (Decide) 1 1 2, 3 4, 5 6, 6 5 2 (UnitProp) 1 2 1 2 1 2, 3 4, 5 6, 6 5 2 (Decide) 1 2 1 2 3 1 2, 3 4, 5 6, 6 5 2 (UnitProp) 1 2 1 2 3 4 3 4 1 2, 3 4, 5 6, 6 5 2 SAT/SMT p.39/50

Abstract DPLL: Example 1 2, 3 4, 5 6, 6 5 2 (Decide) 1 1 2, 3 4, 5 6, 6 5 2 (UnitProp) 1 2 1 2 1 2, 3 4, 5 6, 6 5 2 (Decide) 1 2 1 2 3 1 2, 3 4, 5 6, 6 5 2 (UnitProp) 1 2 1 2 3 4 3 4 1 2, 3 4, 5 6, 6 5 2 (Decide) 1 2 1 2 3 4 3 4 5 1 2, 3 4, 5 6, 6 5 2 SAT/SMT p.39/50

Abstract DPLL: Example 1 2, 3 4, 5 6, 6 5 2 (Decide) 1 1 2, 3 4, 5 6, 6 5 2 (UnitProp) 1 2 1 2 1 2, 3 4, 5 6, 6 5 2 (Decide) 1 2 1 2 3 1 2, 3 4, 5 6, 6 5 2 (UnitProp) 1 2 1 2 3 4 3 4 1 2, 3 4, 5 6, 6 5 2 (Decide) 1 2 1 2 3 4 3 4 5 1 2, 3 4, 5 6, 6 5 2 (UnitProp) 1 2 1 2 3 4 3 4 5 6 5 6 1 2, 3 4, 5 6, 6 5 2 SAT/SMT p.39/50

Abstract DPLL: Example 1 2, 3 4, 5 6, 6 5 2 (Decide) 1 1 2, 3 4, 5 6, 6 5 2 (UnitProp) 1 2 1 2 1 2, 3 4, 5 6, 6 5 2 (Decide) 1 2 1 2 3 1 2, 3 4, 5 6, 6 5 2 (UnitProp) 1 2 1 2 3 4 3 4 1 2, 3 4, 5 6, 6 5 2 (Decide) 1 2 1 2 3 4 3 4 5 1 2, 3 4, 5 6, 6 5 2 (UnitProp) 1 2 1 2 3 4 3 4 5 6 5 6 1 2, 3 4, 5 6, 6 5 2 (Conflict) 1 2 1 2 3 4 3 4 5 6 5 6 1 2, 3 4, 5 6, 6 5 2 6 5 2 SAT/SMT p.39/50

Abstract DPLL: Example 1 2, 3 4, 5 6, 6 5 2 (Decide) 1 1 2, 3 4, 5 6, 6 5 2 (UnitProp) 1 2 1 2 1 2, 3 4, 5 6, 6 5 2 (Decide) 1 2 1 2 3 1 2, 3 4, 5 6, 6 5 2 (UnitProp) 1 2 1 2 3 4 3 4 1 2, 3 4, 5 6, 6 5 2 (Decide) 1 2 1 2 3 4 3 4 5 1 2, 3 4, 5 6, 6 5 2 (UnitProp) 1 2 1 2 3 4 3 4 5 6 5 6 1 2, 3 4, 5 6, 6 5 2 (Conflict) 1 2 1 2 3 4 3 4 5 6 5 6 1 2, 3 4, 5 6, 6 5 2 }{{} F 6 5 2 SAT/SMT p.39/50

Abstract DPLL: Example (cont.) 1 2 1 2 3 4 3 4 5 6 5 6 F 6 5 2 SAT/SMT p.40/50

Abstract DPLL: Example (cont.) 1 2 1 2 3 4 3 4 5 6 5 6 F 6 5 2 (Resolve) 1 2 1 2 3 4 3 4 5 6 5 6 F 5 2 SAT/SMT p.40/50

Abstract DPLL: Example (cont.) 1 2 1 2 3 4 3 4 5 6 5 6 F 6 5 2 (Resolve) 1 2 1 2 3 4 3 4 5 6 5 6 F 5 2 (Learn) 1 2 1 2 3 4 3 4 5 6 5 6 F, 5 2 5 2 SAT/SMT p.40/50

Abstract DPLL: Example (cont.) 1 2 1 2 3 4 3 4 5 6 5 6 F 6 5 2 (Resolve) 1 2 1 2 3 4 3 4 5 6 5 6 F 5 2 (Learn) 1 2 1 2 3 4 3 4 5 6 5 6 F, 5 2 5 2 (Resolve) 1 2 1 2 3 4 3 4 5 6 5 6 F, 5 2 5 1 SAT/SMT p.40/50

Abstract DPLL: Example (cont.) 1 2 1 2 3 4 3 4 5 6 5 6 F 6 5 2 (Resolve) 1 2 1 2 3 4 3 4 5 6 5 6 F 5 2 (Learn) 1 2 1 2 3 4 3 4 5 6 5 6 F, 5 2 5 2 (Resolve) 1 2 1 2 3 4 3 4 5 6 5 6 F, 5 2 5 1 (Backjump) 1 2 1 2 5 5 1 F, 5 2 SAT/SMT p.40/50

Abstract DPLL: Termination Each decision defines a new scope level. Metric: number of assigned literals per level 1 2 1 2 3 4 3 4 5 6 5 6 (2, 2, 2) 1 2 1 2 5 5 1 (3) Order: lexicographic ordering on the metric: (e..g., (3, 1) > (2, 2, 4, 1)) Decide, UnitPropagate, and Backjump increase the metric. It can not increase forever (finite number of variables). Conflict resolution rules (Conflict, Resolve, Learn) are also terminating. SAT/SMT p.41/50

Abstract DPLL: Strategy Abstract DPLL is very flexible. Basic Strategy: Only apply Decide if UnitPropagate and Conflict cannot be applied. Conflict Resolution: Learn only one clause per conflict (the clause used in Backjump). Use Backjump as soon as possible (FUIP). Use the rightmost (applicable) literal in M when applying Resolve. M F C l = M F D C if l D l M, (Resolve) SAT/SMT p.42/50

Abstract DPLL: Decision Strategy Decision heuristic: Associate a score with each boolean variable. Select the variable with highest score when Decide is used. Increase by δ the score of var(l) when Resolve is used: M F C l = M F D C if l D l M, (Resolve) Increase the score of every variable in the clause C l when Backjump is used: M l M F C l = M l C l F if 8 < : M = C, l is undefined in M After each conflict: slightly increase the value of δ. From time to time renormalize the scores and δ to avoid overflows. (Backjump) SAT/SMT p.43/50

Abstract DPLL: Phase Selection Assume p was selected by a decision strategy. Should we assign p or p in Decide? Always False Guess p (works well in practice). Always True Guess p. Score Associate a score with each literal instead of each variable. Pick the phase with highest score. Caching Caches the last phase of variables during conflict resolution. Improvement: except for variables in the last decision level. Greedy Select the phase that satisfies most clauses. SAT/SMT p.44/50

Abstract DPLL: Extra Rules Extra rules: M F, C = M F if C is a learned clause (Forget) M F = F (Restart) Forget in practice: Associate a score with each learned clause C. Increase by δ c the score of D l when Resolve is used. M F C l = M F D C if l D l M, (Resolve) From time to time use Forget to delete learned clauses with low score. SAT/SMT p.45/50

Abstract DPLL: Restart Strategies No restarts Linear Restart after every k conflicts, update k := k + δ. Geometric Restart after every k conflicts, update k := k δ. Inner-Out Geometric Two dimensional pattern that increases in both dimensions. Initially k := x, the inner loop multiplies k by δ at each restart. When k > y, k := x and y := y δ. Luby Restarts are performed according to the following series: 1, 1, 2, 1, 1, 2, 4, 1, 1, 2, 1, 1, 2, 4, 8,..., multiplied by a constant c (e.g., 100, 256, 512). luby(i) = 8 < : 2 k 1, if k. i = 2 k 1 luby(i 2 k 1 + 1), if k. 2 k 1 i < 2 k 1 SAT/SMT p.46/50

Indexing Indexing techniques are very important. How to implement UnitPropagate and Conflict? Scanning the set of clauses will not scale. Simple index: mapping from literals to clauses (occurrences). watch(l) = {C 1,...,C n }, where l C i If l is assigned, check each clause C watch(l) for UnitPropagate and Conflict. Most of the time C has more than one unassigned literal. Improvement: associate a counter u with each clause (number of unassigned literals). Problem: counters must be decremented when literals are assigned, and restored during Backjump. SAT/SMT p.47/50

Indexing: Two Watch Literal Insight: No need to include clause C in every set watch(l) where l C. It suffices to include C in at most 2 such sets. Invariant: If some literal l in C is not assigned to false, then C watch(l ) of some l that is not assigned to false. SAT/SMT p.48/50

Indexing: Two watch Literal Maintain 2-watch invariant: Whenever l is assigned. For each clause C watch(l) If the other watch literal l (C watch(l )) is assigned to true, then do nothing. Else if some other literal l is true or unassigned watch(l ) := watch(l ) {C} watch(l) := watch(l) \ {C} Else if all literals in C are assigned to false, then Backjump. Else (all but one literal in C is assigned to false) Propagate. SAT/SMT p.49/50

Preprocessing Preprocessing is very important for industrial benchmarks. Example simplification rules Apply subsumption to remove clauses: C subsumes D if C D, then D can be removed. Apply resolution to eliminate variables provided this does not create too many new clauses: occs(l) = {clauses that contain l} occs(p) occs( p) < k occs(p) = 1 or occs( p) = 1 SAT/SMT p.50/50