Tutorial 1: Modern SMT Solvers and Verification

Similar documents
SAT Solvers: Theory and Practice

Solving SAT Modulo Theories

Satisfiability Modulo Theories

Lecture 2 Propositional Logic & SAT

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

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

Formal Verification Methods 1: Propositional Logic

Introduction to SAT (constraint) solving. Justyna Petke

COMP219: Artificial Intelligence. Lecture 20: Propositional Reasoning

Satisfiability Modulo Theories

SMT BASICS WS 2017/2018 ( ) LOGIC SATISFIABILITY MODULO THEORIES. Institute for Formal Models and Verification Johannes Kepler Universität Linz

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

Foundations of Artificial Intelligence

Foundations of Lazy SMT and DPLL(T)

CS156: The Calculus of Computation

Part 1: Propositional Logic

An Introduction to Satisfiability Modulo Theories

Topics in Model-Based Reasoning

The Eager Approach to SMT. Eager Approach to SMT

An Introduction to SAT Solving

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

Propositional and First Order Reasoning

LOGIC PROPOSITIONAL REASONING

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

Satisfiability Modulo Theories (SMT)

Interpolation. Seminar Slides. Betim Musa. 27 th June Albert-Ludwigs-Universität Freiburg

Satisfiability Modulo Theories

Lecture 9: The Splitting Method for SAT

Lecture 1: Logical Foundations

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

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

From SAT To SMT: Part 1. Vijay Ganesh MIT

Propositional Logic: Evaluating the Formulas

Satisfiability Modulo Theories (SMT)

CS156: The Calculus of Computation Zohar Manna Autumn 2008

Solving Quantified Verification Conditions using Satisfiability Modulo Theories

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

Internals of SMT Solvers. Leonardo de Moura Microsoft Research

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

Mathematical Logic Part Three

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

Pythagorean Triples and SAT Solving

Propositional Logic: Models and Proofs

Computation and Inference

Lecture Notes on SAT Solvers & DPLL

CS 512, Spring 2017, Handout 10 Propositional Logic: Conjunctive Normal Forms, Disjunctive Normal Forms, Horn Formulas, and other special forms

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

Planning as Satisfiability

UCLID: Deciding Combinations of Theories via Eager Translation to SAT. SAT-based Decision Procedures

Constraint Solving for Finite Model Finding in SMT Solvers

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

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

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

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

VLSI CAD: Lecture 4.1. Logic to Layout. Computational Boolean Algebra Representations: Satisfiability (SAT), Part 1

Quantified Boolean Formulas: Complexity and Expressiveness

Quantifiers. Leonardo de Moura Microsoft Research

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

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

PROPOSITIONAL LOGIC. VL Logik: WS 2018/19

USING FOURIER-MOTZKIN VARIABLE ELIMINATION FOR MCSAT EXPLANATIONS IN SMT-RAT

Leonardo de Moura Microsoft Research

Comp487/587 - Boolean Formulas

A brief introduction to Logic. (slides from

Constraint Logic Programming and Integrating Simplex with DPLL(T )

Reasoning with Quantified Boolean Formulas

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

Abstract DPLL and Abstract DPLL Modulo Theories

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

a > 3, (a = b a = b + 1), f(a) = 0, f(b) = 1

Theory Combination. Clark Barrett. New York University. CS357, Stanford University, Nov 2, p. 1/24

EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization

Notes. Corneliu Popeea. May 3, 2013

Classical Propositional Logic

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

Symbolic Analysis. Xiangyu Zhang

SMT Unsat Core Minimization

Finite model finding in satisfiability modulo theories

Logic and Inferences

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

Chapter 7 R&N ICS 271 Fall 2017 Kalev Kask

Propositional Calculus

Agenda. Artificial Intelligence. Reasoning in the Wumpus World. The Wumpus World

SAT/SMT/AR Introduction and Applications

CSE507. Satisfiability Modulo Theories. Computer-Aided Reasoning for Software. Emina Torlak

Course An Introduction to SAT and SMT. Cap. 2: Satisfiability Modulo Theories

Foundations of Artificial Intelligence

Introduction Algorithms Applications MINISAT. Niklas Sörensson Chalmers University of Technology and Göteborg University

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

Essential facts about NP-completeness:

Decision Procedures for Satisfiability and Validity in Propositional Logic


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

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

Propositional logic. Programming and Modal Logic

A Logic Primer. Stavros Tripakis University of California, Berkeley

Interpolant-based Transition Relation Approximation

Lecture 2/11: Satisfiability Modulo Theories, Part I

Propositional Logic: Methods of Proof (Part II)

Propositional Reasoning

Transcription:

University of Illinois at Urbana-Champaign Tutorial 1: Modern SMT Solvers and Verification Sayan Mitra Electrical & Computer Engineering Coordinated Science Laboratory University of Illinois at Urbana Champaign

Tutorial 1: Modern SMT Solvers and Verification Sayan Mitra slides adapted from a lecture by Clark Barrett

Plan SAT problem Logic and circuit representation Conversion to CNF DPLL Modeling and BMC using SAT (Z3) SMT Architecture Theories Examples Lecture Slides by Sayan Mitra mitras@illinois.edu

The satisfiability problem SAT Problem: Given a well-formed formula α in propositional logic, decide whether there exists a satisfying solution for α. Example: α x %, x ',, x ) x % x ' x - x % x - x ' Satisfying solution: (x % = 1; x ' = 1; x - = 0) Complexity: 2 ) First problem shown to be NP-complete [Cook 71] Though exponential, makes sense to build SAT-solvers and 30+ years of engineering has led to solvers that can solve practical problems Lecture Slides by Sayan Mitra mitras@illinois.edu

SAT in Verification Reachability and invariance questions automata can be encoded as SAT questions Q. U is (not) reachable from Q 8 in n steps: F ;< X 8 F > X 8, X % F > X %, X ' F > X ', X - F > X )@%, X ) F A (X ) ) SAT iff U is reachable (UNSAT iff not reachable) Q. I is (not) an inductive invariant: F ;< X F D X F D X F > X, X E F D (X E )

Terminology variables: x %, x ' literals: positive or negative appearance of variables in a formula, e.g., x %, x ', clause: disjunction of literals, e.g. (x % x ' x - ) conjunctive normal form (CNF) formula: E.g., x % x ' x - ( x ' x % ) we will assume α to be in CNF Lecture Slides by Sayan Mitra mitras@illinois.edu

Propositional logic and circuits A B D D (A B) I D (A B) C (A B) C C (A B)

Propositional logic and circuits A B D D (A B) I D (A B) C (A B) C C (A B) Overcome inefficiency by renaming subexpressions Tautologically equivalent: Every satisfying solution of I is a satisfying solution of I E Equisatisfiable: I is satisfiable iff I E is satisfiable A B E I E D E C E ( A B E) I E and I are not tautologically equivalent, but are equisatisfiable (e.g., C = 0; A = B = 1; E = 0 satisfies I)

Converting to CNF A B D E G I C F H View formula as a circuit 1. Give new names to non-leaf nodes 2. For each non-leaf add conjunction of I/O clauses 3. Take conjunction of everything E A B A B E E A B A B E E A) E B G D E F C H F E I (H G)

SMT formats Alternative notations A B E E A E B D E A B E E A E B D E 1 2 5 5 1 5 2 4 5 [DIMACS]

SAT solving algorithms Davis Putnam Logemann Loveland (DPLL) 1962 Davis Putnam algorithm (DP) 1960 Basic idea: Given α perform a sequence of satisfiability preserving transformations; if this ends with empty clause then UNSAT and if this ends with no clauses then SAT

The DP rules 1. Unit propagation: If a clause has a single literal p then remove all instances of p from all clauses remove all clauses with p 2. Pure literal: If a variable appears only positively or negatively in all clauses then delete all clauses containing that literal 3. Resolution: Choose literal p (appears both positively and negatively) Let P be the set of clauses in which p is +ve Let N be the set of clauses in which p is ve Replace P, N with clauses obtained by resolving p in all pairs For a single pair p l % l ' l U ; ( p k % k ' k ) ) resolved clause is (l % l ' l U k % k ' k ) ) Quadratic blow-up in size of formula

Some experimental results From talk by Clark Barrett

Example 1 2Y, 1Y 2Y, 2 3, 3Y 2, 1 4 (Pureliteral 4) 4 1 2Y, 1Y 2Y, 2 3, 3Y 2, 1 4 (Decide 1) 4 1 \ 1 2Y, 1Y 2Y, 2 3, 3Y 2, 1 4 (Unitprop 2Y) 4 1 \ 2Y 1 2Y, 1Y 2Y, 2 3, 3Y 2, 1 4 (Unitprop 3) 4 1 \ 2Y 3 1 2Y, 1Y 2Y, 2 3, 3Y 2, 1 4 (Backtrack) 4 1Y 1 2Y, 1Y 2Y, 2 3, 3Y 2, 1 4 (Unitprop) 4 1Y 2Y 3Y 1 2Y, 1Y 2Y, 2 3, 3Y 2, 1 4 (Fail) fail Result: Unsatisfiable

Modeling for SAT Input: A = Q, Q 8, T Q Q, Invariant I or unsafe set U Output: I is (not) an invariant of A U is (not) reachable from Q 8 U is (not) reachable from Q 8 in n steps

Modeling for SAT (2) A = Q, Q 8, T Q Q, Invariant I or unsafe set U Assume Q is finite Select k such that Q 2 b Define state variables X = x %, x ',, x b, type x g = 0,1 Then, Q = val(x) Q 8 F ;< (X) a formula encoding initial set U F A (X) a formula encoding unsafe set Define additional vars Y = y %, y ',, y b, type y g = 0,1 T F > (X, Y) a formula encoding transition relation

Bounded model checking Q 8 F ;< (X) a formula encoding initial set U F A (X) a formula encoding unsafe set T F > (X, Y) a formula encoding transition relation We need n + 1 copies of variables: X 8 = x 8%, x 8', x 8b, X % = x %%, x %', x %b,, X ) Q. U is (not) reachable from Q 8 in n steps: F ;< X 8 F > X 8, X % F > X %, X ' F > X ', X - F > X )@%, X ) F A (X ) ) SAT iff U is reachable (UNSAT iff not reachable)

Tutorial 1 FROM SAT TO SMT

Architecture of SMT Solvers Question: Input α(x) formula in some set of logical theories, x, x α? Theories CNF formula in theory of Arrays assertions Arithmetic, Arrays, UF, Bit vectors, solution/ CE Core boolean skeleton of problem DPLL Decision procedures ideally: incremental, backtrackable, conflict generating

Theories and terminology Signature : function symbol, predicate symbol, arity, set of variables Terms Σ, V : v f t 8,.., t b ground terms Atomic formula AF Σ, V : T,F, p t 8,.., t b literal: AF or its negation QFF Σ, V : φ, φ, φ % φ ', φ % φ ', φ % φ ', where φ, φ % AF FOF Σ, V : QFF under universal and existential quantifiers Free and bound variables Sentence: FOF with no free variables Theory Σ, V : set of all sentences Σ : = 0, +, Σ : = <, arity 0 : = 0, arity + : = 2, arity < : = 2, V: = {x, y, z} Terms: x, y, z, 0, + x, y, +(+ x, y, 0) AF: x < y, + x, y = +(y, x) QFF: + x, y = 0 x > y FOF: x, y: + x, y = 0 x > y

Decision procedures Models give meaning to symbols and formula A model M for Σ, V defines a domain, gives interpretation to all symbols and assignment to all the variables Given a theory T a theory solver (decision procedure) takes as input a set of literals Φ and determines whether Φ is T-satisfiable, i.e., does there exist a model M, such that M Φ?

Example theories Uninterpreted functions (UF) Σ = f, g,.., Σ = =, V = x g x % x ' x - x ' f x - = f(x ' ) Arithmetic Σ = <, >,,, = Difference logic Σ =, Σ = <, >,,, = x % x ' > k Linear arithmetic: 7x % 3x ' + 6x - 10 Nonlinear arithmetic: 7x % ' 3x ' x % + 6x - - 1 Arrays Bit vectors

A decision procedure for UF Φ x % = x ' x ' = x - x = x x x % F x % F x - Rules: 1. Put all variables and function instances in their own classes 2. if t g = t is the predicate then merge the containing classes; repeat 3. If t g and t are in the same class, then merge F t g and F(t ); repeat 4. If t g t is in Φ such that t g and t are in the same class then return UNSAT else return SAT {x % }{x ' } {x - } {x } x F(x % }{F x - } {x %, x ' } {x - } {x, x } F(x % }{F x - } {x %, x ', x - } {x, x } F(x % }{F x - } {x %, x ', x - } x, x F(x %, F x - } UNSAT

Back to SMT Two approaches Eager: Translate to equisatisfiable propositional formula Lazy: Abstract to propositional form, feed to DPLL, refine

SMT solver example Φ g a = c f g a f c g a = d c d 1 2Y 3 4Y Send {1, 2Y 3, 4Y} to SAT SAT solver returns model {1, 2Y, 4Y} UF-solver finds concretization of {1, 2Y, 4Y} UNSAT Send {1, 2Y 3, 4Y, (1 2Y 4Y)} to SAT Send {1, 2Y 3, 4Y, 1Y 2 4)} to SAT SAT solver returns model {1,3, 4Y} UF-solver finds concretization of {1,3, 4Y} UNSAT Send {1, 2Y 3, 4Y, 1Y 2 4, 1Y 3Y 4} to SAT SAT solver returns UNSAT; Original formula is UNSAT in UF

Summary This was just an introduction to SMT solvers Modern solvers Z3, CVC4, Chaff, have been used to solve practical verification problems Many, many tools use SAT solvers for verification, synthesis, symbolic simulation, etc. SMT competitions: http://www.satcompetition.org/