Leonardo de Moura Microsoft Research. Is formula F satisfiable modulo theory T ? SMT solvers have specialized algorithms for T.

Slides:



Advertisements
Similar presentations
SMELS: Sat Modulo Equality with Lazy Superposition Christopher Lynch – Clarkson Duc-Khanh Tran - MPI.
Advertisements

Completeness and Expressiveness
Satisfiability Modulo Theories (An introduction)
SMT Solvers (an extension of SAT) Kenneth Roe. Slide thanks to C. Barrett & S. A. Seshia, ICCAD 2009 Tutorial 2 Boolean Satisfiability (SAT) ⋁ ⋀ ¬ ⋁ ⋀
Propositional and First Order Reasoning. Terminology Propositional variable: boolean variable (p) Literal: propositional variable or its negation p 
Proofs from SAT Solvers Yeting Ge ACSys NYU Nov
Interpolants from Z3 proofs Ken McMillan Microsoft Research TexPoint fonts used in EMF: A A A A A.
Leonardo de Moura and Nikolaj Bjørner Microsoft Research.
Deciding Equality with Uninterpreted Functions using Congruence Closure Constantinos Bartzis.
Number Theory and Cryptography
Nikolaj Bjørner Microsoft Research Lecture 4. DayTopicsLab 1Overview of SMT and applications. SAT solving, Z3 Encoding combinatorial problems with Z3.
SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:
Plan for today Proof-system search ( ` ) Interpretation search ( ² ) Quantifiers Equality Decision procedures Induction Cross-cutting aspectsMain search.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
Last time Proof-system search ( ` ) Interpretation search ( ² ) Quantifiers Equality Decision procedures Induction Cross-cutting aspectsMain search strategy.
Nikolaj Bjørner Microsoft Research Lecture 3. DayTopicsLab 1Overview of SMT and applications. SAT solving, Z3 Encoding combinatorial problems with Z3.
Interpolants [Craig 1957] G(y,z) F(x,y)
1 Satisfiability Modulo Theories Sinan Hanay. 2 Boolean Satisfiability (SAT) Is there an assignment to the p 1, p 2, …, p n variables such that  evaluates.
Automated Theorem Proving Lecture 4.   Formula := A |  |    A  Atom := b | t = 0 | t < 0 | t  0 t  Term := c | x | t + t | t – t | ct | Select(m,t)
Yeting Ge Leonardo de Moura New York University Microsoft Research.
Search in the semantic domain. Some definitions atomic formula: smallest formula possible (no sub- formulas) literal: atomic formula or negation of an.
Some administrative stuff Class mailing list: –send to with the command “subscribe”
Last time Proof-system search ( ` ) Interpretation search ( ² ) Quantifiers Equality Decision procedures Induction Cross-cutting aspectsMain search strategy.
1 A Combination Method for Generating Interpolants by G. Yorsh and M. Masuvathi Presentation by: Emilia Katz.
Monadic Predicate Logic is Decidable Boolos et al, Computability and Logic (textbook, 4 th Ed.)
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
Ofer Strichman, Technion 1 Decision Procedures in First Order Logic Part II – Equality Logic and Uninterpreted Functions.
Ofer Strichman, Technion Deciding Combined Theories.
Daniel Kroening and Ofer Strichman 1 Decision Procedures in First Order Logic Decision Procedures for Equality Logic.
1 First order theories. 2 Satisfiability The classic SAT problem: given a propositional formula , is  satisfiable ? Example:  Let x 1,x 2 be propositional.
Leonardo de Moura Microsoft Research. Many approaches Graph-based for difference logic: a – b  3 Fourier-Motzkin elimination: Standard Simplex General.
Relations Chapter 9.
Maps A map is an object that maps keys to values Each key can map to at most one value, and a map cannot contain duplicate keys KeyValue Map Examples Dictionaries:
Deciding a Combination of Theories - Decision Procedure - Changki pswlab Combination of Theories Daniel Kroening, Ofer Strichman Presented by Changki.
Nikolaj Bjørner, Leonardo de Moura Microsoft Research Bruno Dutertre SRI International.
CMU, Oct 4 DPLL-based Checkers for Satisfiability Modulo Theories Cesare Tinelli Department of Computer Science The University of Iowa Joint work with.
From SAT to SMT A Tutorial Nikolaj Bjørner Microsoft Research Dagstuhl April 23, 2015.
1 A Combination Method for Generating Interpolants Greta Yorsh Madan Musuvathi Tel Aviv University, Israel Microsoft Research, Redmond, US CAV’05.
SAT and SMT solvers Ayrat Khalimov (based on Georg Hofferek‘s slides) AKDV 2014.
Leonardo de Moura and Nikolaj Bjørner Microsoft Research.
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
Solvers for the Problem of Boolean Satisfiability (SAT) Will Klieber Aug 31, 2011 TexPoint fonts used in EMF. Read the TexPoint manual before you.
Introduction to Satisfiability Modulo Theories
Daniel Kroening and Ofer Strichman 1 Decision Procedures An Algorithmic Point of View BDDs.
Leonardo de Moura Microsoft Research. Quantifiers in Satisfiability Modulo Theories Logic is “The Calculus of Computer Science” (Z. Manna). High computational.
Leonardo de Moura and Nikolaj Bjørner Microsoft Research.
Symbolic and Concolic Execution of Programs Information Security, CS 526 Omar Chowdhury 10/7/2015Information Security, CS 5261.
Nikolaj Bjørner Microsoft Research DTU Winter course January 2 nd 2012 Organized by Flemming Nielson & Hanne Riis Nielson.
1 First order theories (Chapter 1, Sections 1.4 – 1.5) From the slides for the book “Decision procedures” by D.Kroening and O.Strichman.
Random Interpretation Sumit Gulwani UC-Berkeley. 1 Program Analysis Applications in all aspects of software development, e.g. Program correctness Compiler.
Leonardo de Moura Microsoft Research. Applications and Challenges in Satisfiability Modulo Theories Verification/Analysis tools need some form of Symbolic.
Daniel Kroening and Ofer Strichman Decision Procedures An Algorithmic Point of View Deciding Combined Theories.
Satisfiability and SAT Solvers CS 270 Math Foundations of CS Jeremy Johnson.
CS357 Lecture 13: Symbolic model checking without BDDs Alex Aiken David Dill 1.
Daniel Kroening and Ofer Strichman 1 Decision Procedures An Algorithmic Point of View Basic Concepts and Background.
Finding Conflicting Instances of Quantified Formulas in SMT Andrew Reynolds Cesare Tinelli Leonardo De Moura July 18, 2014.
Selected Decision Procedures and Techniques for SMT More on combination – theories sharing sets – convex theory Un-interpreted function symbols (quantifier-free.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
Deciding Combined Theories Presented by Adi Sosnovich Based on presentation from: Decision Procedures An Algorithmic Point of View Daniel Kroening and.
Knowledge Repn. & Reasoning Lecture #9: Propositional Logic UIUC CS 498: Section EA Professor: Eyal Amir Fall Semester 2005.
Dana Nau: Lecture slides for Automated Planning Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike License:
Week 8 - Wednesday.  What did we talk about last time?  Relations  Properties of relations  Reflexive  Symmetric  Transitive.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Certifying and Synthesizing Membership Equational Proofs Patrick Lincoln (SRI) joint work with Steven Eker (SRI), Jose Meseguer (Urbana) and Grigore Rosu.
Satisfiability Modulo Theories and DPLL(T) Andrew Reynolds March 18, 2015.
Decision Procedures in First Order Logic
Lazy Proofs for DPLL(T)-Based SMT Solvers
Solving Linear Arithmetic with SAT-based MC
Satisfiability Modulo Theories
Presentation transcript:

Leonardo de Moura Microsoft Research

Is formula F satisfiable modulo theory T ? SMT solvers have specialized algorithms for T

b + 2 = c and f(read(write(a,b,3), c-2)) ≠ f(c-b+1)

ArithmeticArithmetic

ArithmeticArithmetic Array Theory b + 2 = c and f(read(write(a,b,3), c-2)) ≠ f(c-b+1)

ArithmeticArithmetic Array Theory Uninterpreted Functions b + 2 = c and f(read(write(a,b,3), c-2)) ≠ f(c-b+1)

Substituting c by b+2

b + 2 = c and f(read(write(a,b,3), b+2-2)) ≠ f(b+2-b+1) Simplifying

b + 2 = c and f(read(write(a,b,3), b)) ≠ f(3)

Applying array theory axiom forall a,i,v: read(write(a,i,v), i) = v

b + 2 = c and f(3) ≠ f(3) Inconsistent

Repository of Benchmarks Benchmarks are divided in “logics”: QF_UF: unquantified formulas built over a signature of uninterpreted sort, function and predicate symbols. QF_UFLIA: unquantified linear integer arithmetic with uninterpreted sort, function, and predicate symbols. AUFLIA: closed linear formulas over the theory of integer arrays with free sort, function and predicate symbols.

For most SMT solvers: F is a set of ground formulas Many Applications Bounded Model Checking Test-Case Generation

An SMT Solver is a collection of Little Engines of Proof

An SMT Solver is a collection of Little Engines of Proof Examples: SAT Solver Equality solver Examples: SAT Solver Equality solver

a = b, b = c, d = e, b = s, d = t, a  e, a  s a a b b c c d d e e s s t t

a a b b c c d d e e s s t t

c c d d e e s s t t a,ba,b a,ba,b

c c d d e e s s t t a,b

a = b, b = c, d = e, b = s, d = t, a  e, a  s d d e e s s t t a,b,c

a = b, b = c, d = e, b = s, d = t, a  e, a  s d d e e s s t t a,b,c

d,ed,e d,ed,e a = b, b = c, d = e, b = s, d = t, a  e, a  s s s t t a,b,c

a = b, b = c, d = e, b = s, d = t, a  e, a  s s s t t a,b,c d,e

a,b,c,s a = b, b = c, d = e, b = s, d = t, a  e, a  s t t d,e

a = b, b = c, d = e, b = s, d = t, a  e, a  s t t d,e a,b,c,s

a = b, b = c, d = e, b = s, d = t, a  e, a  s a,b,c,s d,e,t

a = b, b = c, d = e, b = s, d = t, a  e, a  s a,b,c,s d,e,t

a = b, b = c, d = e, b = s, d = t, a  e, a  s a,b,c,s d,e,t Unsatisfiable

a = b, b = c, d = e, b = s, d = t, a  e a,b,c,s d,e,t Model construction

a = b, b = c, d = e, b = s, d = t, a  e a,b,c,s d,e,t Model construction |M| = {  1,  2 } (universe, aka domain) 11 22

a = b, b = c, d = e, b = s, d = t, a  e a,b,c,s d,e,t Model construction |M| = {  1,  2 } (universe, aka domain) M(a) =  1 (assignment) 11 22

a = b, b = c, d = e, b = s, d = t, a  e a,b,c,s d,e,t Model construction |M| = {  1,  2 } (universe, aka domain) M(a) =  1 (assignment) 11 22 Alternative notation: a M =  1 Alternative notation: a M =  1

a = b, b = c, d = e, b = s, d = t, a  e a,b,c,s d,e,t Model construction |M| = {  1,  2 } (universe, aka domain) M(a) = M(b) = M(c) = M(s) =  1 M(d) = M(e) = M(t) =  2 11 22

a = b, b = c, d = e, b = s, d = t, a  e a,b,c,s d,e,t Model construction |M| = {  1,  2 } (universe, aka domain) M(a) = M(b) = M(c) = M(s) =  1 M(d) = M(e) = M(t) =  2 11 22

Termination: easy Soundness Invariant: all constants in a “ball” are known to be equal. The “ball” merge operation is justified by: Transitivity and Symmetry rules. Completeness We can build a model if an inconsistency was not detected. Proof template (by contradiction): Build a candidate model. Assume a literal was not satisfied. Find contradiction.

Completeness We can build a model if an inconsistency was not detected. Instantiating the template for our procedure: Assume some literal c = d is not satisfied by our model. That is, M(c) ≠ M(d). This is impossible, c and d must be in the same “ball”. c,d,… ii M(c) = M(d) =  i

Completeness We can build a model if an inconsistency was not detected. Instantiating the template for our procedure: Assume some literal c ≠ d is not satisfied by our model. That is, M(c) = M(d). Key property: we only check the disequalities after we processed all equalities. This is impossible, c and d must be in the different “balls” c,… M(c) =  i M(d) =  j ii d,… jj

a = b, b = c, d = e, b = s, d = t, f(a, g(d))  f(b, g(e)) Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n )

a = b, b = c, d = e, b = s, d = t, f(a, g(d))  f(b, g(e)) First Step: “Naming” subterms Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n )

a = b, b = c, d = e, b = s, d = t, f(a, v 1 )  f(b, g(e)) v 1  g(d) First Step: “Naming” subterms Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n )

a = b, b = c, d = e, b = s, d = t, f(a, v 1 )  f(b, g(e)) v 1  g(d) First Step: “Naming” subterms Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n )

a = b, b = c, d = e, b = s, d = t, f(a, v 1 )  f(b, v 2 ) v 1  g(d), v 2  g(e) First Step: “Naming” subterms Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n )

a = b, b = c, d = e, b = s, d = t, f(a, v 1 )  f(b, v 2 ) v 1  g(d), v 2  g(e) First Step: “Naming” subterms Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n )

a = b, b = c, d = e, b = s, d = t, v 3  f(b, v 2 ) v 1  g(d), v 2  g(e), v 3  f(a, v 1 ) First Step: “Naming” subterms Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n )

a = b, b = c, d = e, b = s, d = t, v 3  f(b, v 2 ) v 1  g(d), v 2  g(e), v 3  f(a, v 1 ) First Step: “Naming” subterms Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n )

a = b, b = c, d = e, b = s, d = t, v 3  v 4 v 1  g(d), v 2  g(e), v 3  f(a, v 1 ), v 4  f(b, v 2 ) First Step: “Naming” subterms Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n )

a = b, b = c, d = e, b = s, d = t, v 3  v 4 v 1  g(d), v 2  g(e), v 3  f(a, v 1 ), v 4  f(b, v 2 ) Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n ) a,b,c,s d,e,t v1v1 v1v1 v2v2 v2v2 v3v3 v3v3 v4v4 v4v4

a = b, b = c, d = e, b = s, d = t, v 3  v 4 v 1  g(d), v 2  g(e), v 3  f(a, v 1 ), v 4  f(b, v 2 ) Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n ) d = e implies g(d) = g(e) a,b,c,s d,e,t v1v1 v1v1 v2v2 v2v2 v3v3 v3v3 v4v4 v4v4

a = b, b = c, d = e, b = s, d = t, v 3  v 4 v 1  g(d), v 2  g(e), v 3  f(a, v 1 ), v 4  f(b, v 2 ) Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n ) d = e implies v 1 = v 2 a,b,c,s d,e,t v1v1 v1v1 v2v2 v2v2 v3v3 v3v3 v4v4 v4v4

a = b, b = c, d = e, b = s, d = t, v 3  v 4 v 1  g(d), v 2  g(e), v 3  f(a, v 1 ), v 4  f(b, v 2 ) Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n ) d = e implies v 1 = v 2 a,b,c,s d,e,t v1,v2v1,v2 v1,v2v1,v2 v3v3 v3v3 v4v4 v4v4 We say: v 1 and v 2 are congruent. We say: v 1 and v 2 are congruent.

a = b, b = c, d = e, b = s, d = t, v 3  v 4 v 1  g(d), v 2  g(e), v 3  f(a, v 1 ), v 4  f(b, v 2 ) Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n ) a = b, v 1 = v 2 implies f(a, v 1 ) = f(b, v 2 ) a,b,c,s d,e,t v1,v2v1,v2 v1,v2v1,v2 v3v3 v3v3 v4v4 v4v4

a = b, b = c, d = e, b = s, d = t, v 3  v 4 v 1  g(d), v 2  g(e), v 3  f(a, v 1 ), v 4  f(b, v 2 ) Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n ) a = b, v 1 = v 2 implies v 3 = v 4 a,b,c,s d,e,t v1,v2v1,v2 v1,v2v1,v2 v3v3 v3v3 v4v4 v4v4

a = b, b = c, d = e, b = s, d = t, v 3  v 4 v 1  g(d), v 2  g(e), v 3  f(a, v 1 ), v 4  f(b, v 2 ) Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n ) a = b, v 1 = v 2 implies v 3 = v 4 a,b,c,s d,e,t v1,v2v1,v2 v1,v2v1,v2 v3,v4v3,v4 v3,v4v3,v4

a = b, b = c, d = e, b = s, d = t, v 3  v 4 v 1  g(d), v 2  g(e), v 3  f(a, v 1 ), v 4  f(b, v 2 ) Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n ) a,b,c,s d,e,t v 1,v 2 v3,v4v3,v4 v3,v4v3,v4 Unsatisfiable

a = b, b = c, d = e, b = s, d = t, a  v 4, v 2  v 3 v 1  g(d), v 2  g(e), v 3  f(a, v 1 ), v 4  f(b, v 2 ) Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n ) a,b,c,s d,e,t v 1,v 2 v 3, v 4 Changing the problem

a = b, b = c, d = e, b = s, d = t, a  v 4, v 2  v 3 v 1  g(d), v 2  g(e), v 3  f(a, v 1 ), v 4  f(b, v 2 ) Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n ) a,b,c,s d,e,t v 1,v 2 v 3, v 4

a = b, b = c, d = e, b = s, d = t, a  v 4, v 2  v 3 v 1  g(d), v 2  g(e), v 3  f(a, v 1 ), v 4  f(b, v 2 ) Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n ) a,b,c,s d,e,t v1,v2v1,v2 v1,v2v1,v2 v3,v4v3,v4 v3,v4v3,v4

a = b, b = c, d = e, b = s, d = t, a  v 4, v 2  v 3 v 1  g(d), v 2  g(e), v 3  f(a, v 1 ), v 4  f(b, v 2 ) Model construction: |M| = {  1,  2,  3,  4 } M(a) = M(b) = M(c) = M(s) =  1 M(d) = M(e) = M(t) =  2 M(v 1 ) = M(v 2 ) =  3 M(v 3 ) = M(v 4 ) =  4 a,b,c,s d,e,t v 1,v 2 v 3, v 4 11 22 33 44

a = b, b = c, d = e, b = s, d = t, a  v 4, v 2  v 3 v 1  g(d), v 2  g(e), v 3  f(a, v 1 ), v 4  f(b, v 2 ) Model construction: |M| = {  1,  2,  3,  4 } M(a) = M(b) = M(c) = M(s) =  1 M(d) = M(e) = M(t) =  2 M(v 1 ) = M(v 2 ) =  3 M(v 3 ) = M(v 4 ) =  4 a,b,c,s d,e,t v 1,v 2 v 3, v 4 11 22 33 44 Missing: Interpretation for f and g. Missing: Interpretation for f and g.

Building the interpretation for function symbols M(g) is a mapping from |M| to |M| Defined as: M(g)(  i ) =  j if there is v  g(a) s.t. M(a) =  i M(v) =  j =  k, otherwise (  k is an arbitrary element) Is M(g) well-defined?

Building the interpretation for function symbols M(g) is a mapping from |M| to |M| Defined as: M(g)(  i ) =  j if there is v  g(a) s.t. M(a) =  i M(v) =  j =  k, otherwise (  k is an arbitrary element) Is M(g) well-defined? Problem: we may have v  g(a) and w  g(b) s.t. M(a) = M(b) =  1 and M(v) =  2 ≠  3 = M(w) So, is M(g)(  1 ) =  2 or M(g)(  1 ) =  3 ?

Building the interpretation for function symbols M(g) is a mapping from |M| to |M| Defined as: M(g)(  i ) =  j if there is v  g(a) s.t. M(a) =  i M(v) =  j =  k, otherwise (  k is an arbitrary element) Is M(g) well-defined? Problem: we may have v  g(a) and w  g(b) s.t. M(a) = M(b) =  1 and M(v) =  2 ≠  3 = M(w) So, is M(g)(  1 ) =  2 or M(g)(  1 ) =  3 ? This is impossible because of the congruence rule! a and b are in the same “ball”, then so are v and w This is impossible because of the congruence rule! a and b are in the same “ball”, then so are v and w

a = b, b = c, d = e, b = s, d = t, a  v 4, v 2  v 3 v 1  g(d), v 2  g(e), v 3  f(a, v 1 ), v 4  f(b, v 2 ) Model construction: |M| = {  1,  2,  3,  4 } M(a) = M(b) = M(c) = M(s) =  1 M(d) = M(e) = M(t) =  2 M(v 1 ) = M(v 2 ) =  3 M(v 3 ) = M(v 4 ) =  4 a,b,c,s d,e,t v 1,v 2 v 3, v 4 11 22 33 44

a = b, b = c, d = e, b = s, d = t, a  v 4, v 2  v 3 v 1  g(d), v 2  g(e), v 3  f(a, v 1 ), v 4  f(b, v 2 ) Model construction: |M| = {  1,  2,  3,  4 } M(a) = M(b) = M(c) = M(s) =  1 M(d) = M(e) = M(t) =  2 M(v 1 ) = M(v 2 ) =  3 M(v 3 ) = M(v 4 ) =  4 M(g)(  i ) =  j if there is v  g(a) s.t. M(a) =  i M(v) =  j =  k, otherwise

a = b, b = c, d = e, b = s, d = t, a  v 4, v 2  v 3 v 1  g(d), v 2  g(e), v 3  f(a, v 1 ), v 4  f(b, v 2 ) Model construction: |M| = {  1,  2,  3,  4 } M(a) = M(b) = M(c) = M(s) =  1 M(d) = M(e) = M(t) =  2 M(v 1 ) = M(v 2 ) =  3 M(v 3 ) = M(v 4 ) =  4 M(g) = {  2 →  3 } M(g)(  i ) =  j if there is v  g(a) s.t. M(a) =  i M(v) =  j =  k, otherwise

a = b, b = c, d = e, b = s, d = t, a  v 4, v 2  v 3 v 1  g(d), v 2  g(e), v 3  f(a, v 1 ), v 4  f(b, v 2 ) Model construction: |M| = {  1,  2,  3,  4 } M(a) = M(b) = M(c) = M(s) =  1 M(d) = M(e) = M(t) =  2 M(v 1 ) = M(v 2 ) =  3 M(v 3 ) = M(v 4 ) =  4 M(g) = {  2 →  3 } M(g)(  i ) =  j if there is v  g(a) s.t. M(a) =  i M(v) =  j =  k, otherwise

a = b, b = c, d = e, b = s, d = t, a  v 4, v 2  v 3 v 1  g(d), v 2  g(e), v 3  f(a, v 1 ), v 4  f(b, v 2 ) Model construction: |M| = {  1,  2,  3,  4 } M(a) = M(b) = M(c) = M(s) =  1 M(d) = M(e) = M(t) =  2 M(v 1 ) = M(v 2 ) =  3 M(v 3 ) = M(v 4 ) =  4 M(g) = {  2 →  3, else →  1 } M(g)(  i ) =  j if there is v  g(a) s.t. M(a) =  i M(v) =  j =  k, otherwise

a = b, b = c, d = e, b = s, d = t, a  v 4, v 2  v 3 v 1  g(d), v 2  g(e), v 3  f(a, v 1 ), v 4  f(b, v 2 ) Model construction: |M| = {  1,  2,  3,  4 } M(a) = M(b) = M(c) = M(s) =  1 M(d) = M(e) = M(t) =  2 M(v 1 ) = M(v 2 ) =  3 M(v 3 ) = M(v 4 ) =  4 M(g) = {  2 →  3, else →  1 } M(f) = { (  1,  3 ) →  4, else →  1 } M(g)(  i ) =  j if there is v  g(a) s.t. M(a) =  i M(v) =  j =  k, otherwise

It is possible to implement our procedure in O(n log n)

d,e,t Sets (equivalence classes) t t d,e  = d,e,t Union a  s a,b,c,s Membership

Sets (equivalence classes) d,e,t t t d,e  = d,e,t Union a  s a,b,c,s Membership Key observation: The sets are disjoint! Key observation: The sets are disjoint!

Union-Find data-structure Every set (equivalence class) has a root element (representative). a,b,c,s,r a b c s r root We say: find(c) is b

Union-Find data-structure a,b,c a b c s r s,r  = a b c s r a,b,c,s,r

Tracking the equivalence classes size is important! a1a1 a2a2  a3a3 =a1a1 a2a2 a3a3 a1a1 a2a2 a3a3  a4a4 =a1a1 a2a2 a3a3 a4a4 … a1a1 a2a2 a3a3  anan = … a n-1 a1a1 a2a2 a3a3 … anan

Tracking the equivalence classes size is important! a1a1 a2a2  a3a3 =a1a1 a2a2 a3a3 a1a1 a2a2 a3a3  a4a4 =a1a1 a2a2 a3a3 a4a4 … a1a1 a2a2 a3a3  anan = … a n-1 a1a1 a2a2 a3a3 … anan

Tracking the equivalence classes size is important! a1a1 a2a2  a3a3 =a1a1 a2a2 a3a3 a1a1 a2a2 a3a3  a4a4 =a1a1 a2a2 a3a3 a4a4 … a1a1 a2a2 a3a3  anan = … a n-1 a1a1 a2a2 a3a3 … anan We can do n merges in O(n log n) Each constant has two fields: find and size.

Implementing the congruence rule. Occurrences of a constant: we say a occurs in v iff v  f(…,a,…) When we “merge” two equivalence classes we can traverse these occurrences to find new congruences. a b c s r  Occurrences(b) = { v 1  g(b), v 2  f(a) } Occurrences(s) = { v 3  f(r) }

Implementing the congruence rule. Occurrences of a constant: we say a occurs in v iff v  f(…,a,…) When we “merge” two equivalence classes we can traverse these occurrences to find new congruences. a b c s r  occurrences(b) = { v 1  g(b), v 2  f(a) } occurrences(s) = { v 3  f(r) } Inefficient version: for each v in occurrences(b) for each w in occurrences(s) if v and w are congruent add (v,w) to todo queue A queue of pairs that need to be merged.

a b c s r  occurrences(b) = { v 1  g(b), v 2  f(a) } occurrences(s) = { v 3  f(r) } We also need to merge occurrences(b) with occurrences(s). This can be done in constant time: Use circular lists to represent the occurrences. (More later) v1v1 v2v2 v3v3  = v1v1 v2v2 v3v3

Avoiding the nested loop: for each v in occurrences(b) for each w in occurrences(s) … Avoiding the nested loop: Use a hash table to store the elements v 1  f(a 1, …, a n ). Each constant has an identifier (e.g., natural number). Compute hash code using the identifier of the (equivalence class) roots of the arguments. hash(v 1 ) = hash-tuple(id(f), id(root(a 1 )), …, id(root(a n )))

Avoiding the nested loop: for each v in occurrences(b) for each w in occurrences(s) … Avoiding the nested loop: Use a hash table to store the elements v 1  f(a 1, …, a n ). Each constant has an identifier (e.g., natural number). Compute hash code using the identifier of the (equivalence class) roots of the arguments. hash(v 1 ) = hash-tuple(id(f), id(root(a 1 )), …, id(root(a n ))) hash-tuple can be the Jenkin’s hash function for strings. Just adding the ids produces a very bad hash-code! hash-tuple can be the Jenkin’s hash function for strings. Just adding the ids produces a very bad hash-code!

Efficient implementation of the congruence rule. Merging the equivalences classes with roots: a 1 and a 2 Assume a 2 is smaller than a 1 Before merging the equivalence classes: a 1 and a 2 for each v in occurrences(a 2 ) remove v from the hash table (its hashcode will change) After merging the equivalence classes: a 1 and a 2 for each v in occurrences(a 2 ) if there is w congruent to v in the hash-table add (v,w) to todo queue else add v to hash-table

Efficient implementation of the congruence rule. Merging the equivalences classes with roots: a 1 and a 2 Assume a 2 is smaller than a 1 Before merging the equivalence classes: a 1 and a 2 for each v in occurrences(a 2 ) remove v from the hash table (its hashcode will change) After merging the equivalence classes: a 1 and a 2 for each v in occurrences(a 2 ) if there is w congruent to v in the hash-table add (v,w) to todo queue else add v to hash-table add v to occurrences(a 1 ) Trick: Use dynamic arrays to represent the occurrences Trick: Use dynamic arrays to represent the occurrences

The efficient version is not optimal (in theory). Problem: we may have v = f(a 1, …, a n ) with “huge” n. Solution: currying Use only binary functions, and represent f(a 1, a 2,a 3,a 4 ) as f(a 1, h(a 2, h(a 3, a 4 ))) This is not necessary in practice, since the n above is small.

Each constant has now three fields: find, size, and occurrences. We also has use a hash-table for implementing the congruence rule. We will need many more improvements!

Many verification/analysis problems require: case-analysis x  0, y = x + 1, (y > 2  y < 1)

Many verification/analysis problems require: case-analysis x  0, y = x + 1, (y > 2  y < 1) Naïve Solution: Convert to DNF (x  0, y = x + 1, y > 2)  (x  0, y = x + 1, y < 1)

Many verification/analysis problems require: case-analysis x  0, y = x + 1, (y > 2  y < 1) Naïve Solution: Convert to DNF (x  0, y = x + 1, y > 2)  (x  0, y = x + 1, y < 1) Too Inefficient! (exponential blowup) Too Inefficient! (exponential blowup)

SAT Theory Solvers SMT Equality + UF Arithmetic Bit-vectors … Case Analysis

M | F Partial model Set of clauses

Guessing p,  q | p  q,  q  r p | p  q,  q  r

Deducing p, s| p  q,  p  s p | p  q,  p  s

Backtracking p, s| p  q, s  q,  p   q p,  s, q | p  q, s  q,  p   q

Efficient indexing (two-watch literal) Non-chronological backtracking (backjumping) Lemma learning

Basic Idea x  0, y = x + 1, (y > 2  y < 1) p 1, p 2, (p 3  p 4 ) Abstract (aka “naming” atoms) p 1  (x  0), p 2  (y = x + 1), p 3  (y > 2), p 4  (y < 1)

Basic Idea x  0, y = x + 1, (y > 2  y < 1) p 1, p 2, (p 3  p 4 ) Abstract (aka “naming” atoms) p 1  (x  0), p 2  (y = x + 1), p 3  (y > 2), p 4  (y < 1) SAT Solver SAT Solver

Basic Idea x  0, y = x + 1, (y > 2  y < 1) p 1, p 2, (p 3  p 4 ) Abstract (aka “naming” atoms) p 1  (x  0), p 2  (y = x + 1), p 3  (y > 2), p 4  (y < 1) SAT Solver SAT Solver Assignment p 1, p 2,  p 3, p 4

Basic Idea x  0, y = x + 1, (y > 2  y < 1) p 1, p 2, (p 3  p 4 ) Abstract (aka “naming” atoms) p 1  (x  0), p 2  (y = x + 1), p 3  (y > 2), p 4  (y < 1) SAT Solver SAT Solver Assignment p 1, p 2,  p 3, p 4 x  0, y = x + 1,  (y > 2), y < 1

Basic Idea x  0, y = x + 1, (y > 2  y < 1) p 1, p 2, (p 3  p 4 ) Abstract (aka “naming” atoms) p 1  (x  0), p 2  (y = x + 1), p 3  (y > 2), p 4  (y < 1) SAT Solver SAT Solver Assignment p 1, p 2,  p 3, p 4 x  0, y = x + 1,  (y > 2), y < 1 Theory Solver Theory Solver Unsatisfiable x  0, y = x + 1, y < 1

Basic Idea x  0, y = x + 1, (y > 2  y < 1) p 1, p 2, (p 3  p 4 ) Abstract (aka “naming” atoms) p 1  (x  0), p 2  (y = x + 1), p 3  (y > 2), p 4  (y < 1) SAT Solver SAT Solver Assignment p 1, p 2,  p 3, p 4 x  0, y = x + 1,  (y > 2), y < 1 Theory Solver Theory Solver Unsatisfiable x  0, y = x + 1, y < 1 New Lemma  p 1  p 2  p 4

Theory Solver Theory Solver Unsatisfiable x  0, y = x + 1, y < 1 New Lemma  p 1  p 2  p 4 AKA Theory conflict AKA Theory conflict

procedure SmtSolver(F) (F p, M) := Abstract(F) loop (R, A) := SAT_solver(F p ) if R = UNSAT then return UNSAT S := Concretize(A, M) (R, S’) := Theory_solver(S) if R = SAT then return SAT L := New_Lemma(S’, M) Add L to F p

Basic Idea F: x  0, y = x + 1, (y > 2  y < 1) F p : p 1, p 2, (p 3  p 4 ) Abstract (aka “naming” atoms) M: p 1  (x  0), p 2  (y = x + 1), p 3  (y > 2), p 4  (y < 1) SAT Solver SAT Solver A: Assignment p 1, p 2,  p 3, p 4 S: x  0, y = x + 1,  (y > 2), y < 1 Theory Solver Theory Solver S’: Unsatisfiable x  0, y = x + 1, y < 1 L: New Lemma  p 1  p 2  p 4

F: x  0, y = x + 1, (y > 2  y < 1) F p : p 1, p 2, (p 3  p 4 ) Abstract (aka “naming” atoms) M: p 1  (x  0), p 2  (y = x + 1), p 3  (y > 2), p 4  (y < 1) SAT Solver SAT Solver A: Assignment p 1, p 2,  p 3, p 4 S: x  0, y = x + 1,  (y > 2), y < 1 Theory Solver Theory Solver S’: Unsatisfiable x  0, y = x + 1, y < 1 L: New Lemma  p 1  p 2  p 4 procedure SMT_Solver(F) (F p, M) := Abstract(F) loop (R, A) := SAT_solver(F p ) if R = UNSAT then return UNSAT S = Concretize(A, M) (R, S’) := Theory_solver(S) if R = SAT then return SAT L := New_Lemma(S, M) Add L to F p “Lazy translation” to DNF “Lazy translation” to DNF

State-of-the-art SMT solvers implement many improvements.

Incrementality Send the literals to the Theory solver as they are assigned by the SAT solver p 1, p 2, p 4 | p 1, p 2, (p 3  p 4 ), (p 5   p 4 ) p 1  (x  0), p 2  (y = x + 1), p 3  (y > 2), p 4  (y < 1), p 5  (x < 2), Partial assignment is already Theory inconsistent. Partial assignment is already Theory inconsistent.

Efficient Backtracking We don’t want to restart from scratch after each backtracking operation.

Efficient Lemma Generation (computing a small S’) Avoid lemmas containing redundant literals. p 1, p 2, p 3, p 4 | p 1, p 2, (p 3  p 4 ), (p 5   p 4 ) p 1  (x  0), p 2  (y = x + 1), p 3  (y > 2), p 4  (y < 1), p 5  (x < 2),  p 1  p 2  p 3  p 4 Imprecise Lemma

Theory Propagation It is the SMT equivalent of unit propagation. p 1, p 2 | p 1, p 2, (p 3  p 4 ), (p 5   p 4 ) p 1  (x  0), p 2  (y = x + 1), p 3  (y > 2), p 4  (y < 1), p 5  (x < 2), p 1, p 2 imply  p 4 by theory propagation p 1, p 2,  p 4 | p 1, p 2, (p 3  p 4 ), (p 5   p 4 )

Theory Propagation It is the SMT equivalent of unit propagation. p 1, p 2 | p 1, p 2, (p 3  p 4 ), (p 5   p 4 ) p 1  (x  0), p 2  (y = x + 1), p 3  (y > 2), p 4  (y < 1), p 5  (x < 2), p 1, p 2 imply  p 4 by theory propagation p 1, p 2,  p 4 | p 1, p 2, (p 3  p 4 ), (p 5   p 4 ) Tradeoff between precision  performance.

Core SAT Solver Equality Uninterpreted Functions Equality Uninterpreted Functions Arithmetic Bit-Vectors Scalar Values

Core SAT Solver Equality Uninterpreted Functions Equality Uninterpreted Functions Arithmetic Bit-Vectors Scalar Values Case Analysis

Core SAT Solver Equality Uninterpreted Functions Equality Uninterpreted Functions Arithmetic Bit-Vectors Scalar Values Blackboard: equalities, disequalities, predicates Blackboard: equalities, disequalities, predicates