+ All Categories
Home > Documents > Nikolaj Bjørner Senior Researcher Microsoft Research Redmond

Nikolaj Bjørner Senior Researcher Microsoft Research Redmond

Date post: 22-Feb-2016
Category:
Upload: kamal
View: 41 times
Download: 0 times
Share this document with a friend
Description:
Nikolaj Bjørner Senior Researcher Microsoft Research Redmond. Modern Satisfiability Modulo Theories Solvers in Program Analysis. Lectures. Wednesday 10:45–12:15 An Introduction to Z3 with Applications Thursday August 30 th 15:45–17:15 Introduction to SAT and SMT Friday 10:30–10:45 - PowerPoint PPT Presentation
Popular Tags:
127
Nikolaj Bjørner Senior Researcher Microsoft Research Redmond Modern Satisfiability Modulo Theories Solvers in Program Analysis
Transcript
Page 1: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Nikolaj BjørnerSenior ResearcherMicrosoft Research Redmond

Modern Satisfiability Modulo Theories Solvers in Program Analysis

Page 2: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Lectures

Wednesday 10:45–12:15An Introduction to Z3 with Applications

Thursday August 30th 15:45–17:15Introduction to SAT and SMT

Friday 10:30–10:45 Theories and Solving Algorithms

Friday 15:45–17:15 Advanced: Quantifiers, Arrays, Fixed-points

Page 3: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Takeaways:

• Engineering of an Incremental Decision Procedure for Arithmetic

• Engineering User Theories with Z3

• Combination methods for Decision Procedures– There are very many papers on the subject– Focus: Paper by de Moura and Bjørner, SMT 2007 on

Model-based theory combination.

Page 4: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Plan

– Decision procedures for Arithmetic [Dutertre & de Moura CAV 2006]

– Engineering Theories with Z3

– Combining Decision Procedures

Page 5: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Case Analysis

Many verification/analysis problems require: case-analysis

x 0, y = x + 1, (y > 2 y < 1)

Page 6: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Case Analysis

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)

Page 7: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Case Analysis

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)

Page 8: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

SAT

Theory

Solvers

SMT

SMT : Basic Architecture

Equality + UFArithmeticBit-vectors…

Case Analysis

Page 9: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

SAT + Theory solvers

Basic Ideax 0, y = x + 1, (y > 2 y < 1)

p1, p2, (p3 p4)

Abstract (aka “naming” atoms)

p1 (x 0), p2 (y = x + 1), p3 (y > 2), p4 (y < 1)

Page 10: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

SAT + Theory solvers

Basic Ideax 0, y = x + 1, (y > 2 y < 1)

p1, p2, (p3 p4)

Abstract (aka “naming” atoms)

p1 (x 0), p2 (y = x + 1), p3 (y > 2), p4 (y < 1)

SAT Solver

Page 11: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

SAT + Theory solvers

Basic Ideax 0, y = x + 1, (y > 2 y < 1)

p1, p2, (p3 p4)

Abstract (aka “naming” atoms)

p1 (x 0), p2 (y = x + 1), p3 (y > 2), p4 (y < 1)

SAT Solver

Assignmentp1, p2, p3, p4

Page 12: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

SAT + Theory solversBasic Idea

x 0, y = x + 1, (y > 2 y < 1)

p1, p2, (p3 p4)

Abstract (aka “naming” atoms)

p1 (x 0), p2 (y = x + 1), p3 (y > 2), p4 (y < 1)

SAT Solver

Assignmentp1, p2, p3, p4

x 0, y = x + 1, (y > 2), y < 1

Page 13: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

SAT + Theory solvers

Basic Ideax 0, y = x + 1, (y > 2 y < 1)

p1, p2, (p3 p4)

Abstract (aka “naming” atoms)

p1 (x 0), p2 (y = x + 1), p3 (y > 2), p4 (y < 1)

SAT Solver

Assignmentp1, p2, p3, p4

x 0, y = x + 1, (y > 2), y < 1

TheorySolver

Unsatisfiablex 0, y = x + 1, y <

1

Page 14: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

SAT + Theory solvers

Basic Ideax 0, y = x + 1, (y > 2 y < 1)

p1, p2, (p3 p4)

Abstract (aka “naming” atoms)

p1 (x 0), p2 (y = x + 1), p3 (y > 2), p4 (y < 1)

SAT Solver

Assignmentp1, p2, p3, p4

x 0, y = x + 1, (y > 2), y < 1

TheorySolver

Unsatisfiablex 0, y = x + 1, y <

1

New Lemmap1p2p4

Page 15: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

SAT + Theory solvers

TheorySolver

Unsatisfiablex 0, y = x + 1, y <

1

New Lemmap1p2p4

AKATheory conflict

Page 16: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

SAT + Theory solvers: Main loop

procedure SmtSolver(F)(Fp, M) := Abstract(F)loop

(R, A) := SAT_solver(Fp)if R = UNSAT then return

UNSATS := Concretize(A, M)(R, S’) := Theory_solver(S)if R = SAT then return SATL := New_Lemma(S’, M)Add L to Fp

Page 17: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

SAT + Theory solvers

Basic IdeaF: x 0, y = x + 1, (y > 2 y < 1)

Fp : p1, p2, (p3 p4)

Abstract (aka “naming” atoms)

M: p1 (x 0), p2 (y = x + 1),

p3 (y > 2), p4 (y < 1)

SAT Solver

A: Assignmentp1, p2, p3, p4

S: x 0, y = x + 1, (y > 2), y < 1

TheorySolver

S’: Unsatisfiablex 0, y = x + 1, y <

1

L: New Lemmap1p2p4

Page 18: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

SAT + Theory solversF: x 0, y = x + 1, (y > 2 y < 1)

Fp : p1, p2, (p3 p4)

Abstract (aka “naming” atoms)

M: p1 (x 0), p2 (y = x + 1),

p3 (y > 2), p4 (y < 1)SAT

Solver

A: Assignmentp1, p2, p3, p4

S: x 0, y = x + 1, (y > 2), y < 1

TheorySolver

S’: Unsatisfiablex 0, y = x + 1, y < 1

L: New Lemmap1p2p4

procedure SMT_Solver(F)(Fp, M) := Abstract(F)loop

(R, A) := SAT_solver(Fp)if R = UNSAT then return

UNSATS = Concretize(A, M)(R, S’) := Theory_solver(S)if R = SAT then return SATL := New_Lemma(S, M)Add L to Fp

“Lazy translation” to

DNF

Page 19: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

SAT + Theory solvers

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

Page 20: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

SAT + Theory solvers

IncrementalitySend the literals to the Theory solver as they are

assigned by the SAT solver

p1, p2, p4 | p1, p2, (p3 p4), (p5 p4)

p1 (x 0), p2 (y = x + 1), p3 (y > 2), p4 (y < 1), p5 (x < 2),

Partial assignment is already Theory inconsistent.

Page 21: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

SAT + Theory solvers

Efficient BacktrackingWe don’t want to restart from scratch after each

backtracking operation.

Page 22: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

SAT + Theory solvers

Efficient Lemma Generation (computing a small S’)Avoid lemmas containing redundant literals.

p1, p2, p3, p4 | p1, p2, (p3 p4), (p5 p4)

p1 (x 0), p2 (y = x + 1), p3 (y > 2), p4 (y < 1), p5 (x < 2),

p1p2 p3 p4 Imprecise Lemma

Page 23: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

SAT + Theory solvers

Theory PropagationIt is the SMT equivalent of unit propagation.

p1, p2 | p1, p2, (p3 p4), (p5 p4)

p1 (x 0), p2 (y = x + 1), p3 (y > 2), p4 (y < 1), p5 (x < 2),

p1, p2 imply p4 by theory propagation

p1, p2 , p4 | p1, p2, (p3 p4), (p5 p4)

Page 24: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

SAT + Theory solvers

Theory PropagationIt is the SMT equivalent of unit propagation.

p1, p2 | p1, p2, (p3 p4), (p5 p4)

p1 (x 0), p2 (y = x + 1), p3 (y > 2), p4 (y < 1), p5 (x < 2),

p1, p2 imply p4 by theory propagation

p1, p2 , p4 | p1, p2, (p3 p4), (p5 p4)

Tradeoff between precision performance.

Page 25: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Core

An Architecture: the core

SAT Solver

EqualityUninterpreted

Functions

Arithmetic Bit-Vectors Scalar Values

Page 26: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Core

An Architecture: the core

SAT Solver

EqualityUninterpreted

Functions

Arithmetic Bit-Vectors Scalar Values

Case Analysis

Page 27: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Core

An Architecture: the core

SAT Solver

EqualityUninterpreted

Functions

Arithmetic Bit-Vectors Scalar Values

Blackboard:equalities, disequalities,predicates

Page 28: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Linear Arithmetic

• Many approaches– Graph-based for difference logic: a – b 3– Fourier-Motzkin elimination:

– Standard Simplex– General Form Simplex

Page 29: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Difference Logic: a – b 5

Very useful in practice!

Most arithmetical constraints in software verification/analysis are in this fragment.

x := x + 1

x1 = x0 + 1

x1 - x0 1, x0 - x1 -1

Page 30: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Job shop scheduling

Page 31: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Difference Logic

Chasing negative cycles!Algorithms based on Bellman-Ford (O(mn)).

Page 32: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

General Form

Page 33: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

From Definitions to a Tableau

s1 x + y, s2 x + 2y

Page 34: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

From Definitions to a Tableau

s1 x + y, s2 x + 2y

s1 = x + y, s2 = x + 2y

Page 35: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

From Definitions to a Tableau

s1 x + y, s2 x + 2y

s1 = x + y, s2 = x + 2y

s1 - x - y = 0

s2 - x - 2y = 0

Page 36: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

From Definitions to a Tableau

s1 x + y, s2 x + 2y

s1 = x + y, s2 = x + 2y

s1 - x - y = 0

s2 - x - 2y = 0

s1, s2 are basic (dependent) x,y are non-basic

Page 37: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Pivoting

A way to swap a basic with a non-basic variable!It is just equational reasoning.Key invariant: a basic variable occurs in only one equation.Example: swap s1 and y

s1 - x - y = 0 s2 - x - 2y = 0

Page 38: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Pivoting

A way to swap a basic with a non-basic variable!It is just equational reasoning.Key invariant: a basic variable occurs in only one equation.Example: swap s1 and y

s1 - x - y = 0 s2 - x - 2y = 0

-s1 + x + y = 0 s2 - x - 2y = 0

Page 39: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Pivoting

A way to swap a basic with a non-basic variable!It is just equational reasoning.Key invariant: a basic variable occurs in only one equation.Example: swap s1 and y

s1 - x - y = 0 s2 - x - 2y = 0

-s1 + x + y = 0 s2 - x - 2y = 0

-s1 + x + y = 0 s2 - 2s1 + x = 0

Page 40: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Pivoting

A way to swap a basic with a non-basic variable!It is just equational reasoning.Key invariant: a basic variable occurs in only one equation.Example: swap s1 and y

s1 - x - y = 0 s2 - x - 2y = 0

-s1 + x + y = 0 s2 - x - 2y = 0

-s1 + x + y = 0 s2 - 2s1 + x = 0

It is just substituting equals by equals.

Page 41: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Pivoting

A way to swap a basic with a non-basic variable!It is just equational reasoning.Key invariant: a basic variable occurs in only one equation.Example: swap s1 and y

s1 - x - y = 0 s2 - x - 2y = 0

-s1 + x + y = 0 s2 - x - 2y = 0

-s1 + x + y = 0 s2 - 2s1 + x = 0

It is just substituting equals by equals.

Definition:An assignment (model) is a mapping from variables to values

Key Property:If an assignment satisfies the equations before a pivoting step, then it will also satisfy them after!

Page 42: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Pivoting

A way to swap a basic with a non-basic variable!It is just equational reasoning.Key invariant: a basic variable occurs in only one equation.Example: swap s2 and y

s1 - x - y = 0 s2 - x - 2y = 0

-s1 + x + y = 0 s2 - x - 2y = 0

-s1 + x + y = 0 s2 - 2s1 + x = 0

It is just substituting equals by equals.

Definition:An assignment (model) is a mapping from variables to values

Key Property:If an assignment satisfies the equations before a pivoting step, then it will also satisfy them after!

Example:M(x) = 1M(y) = 1M(s1) = 2M(s2) = 3

Page 43: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Equations + Bounds + Assignment

Page 44: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

“Repairing Models”

If the assignment of a non-basic variable does not satisfy a bound, then fix it and propagate the change to all dependent variables.

a = c – db = c + dM(a) = 0M(b) = 0M(c) = 0M(d) = 01 c

a = c – db = c + dM(a) = 1M(b) = 1M(c) = 1M(d) = 01 c

Page 45: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

“Repairing Models”

If the assignment of a non-basic variable does not satisfy a bound, then fix it and propagate the change to all dependent variables. Of course, we may introduce new “problems”.

a = c – db = c + dM(a) = 0M(b) = 0M(c) = 0M(d) = 01 c a 0

a = c – db = c + dM(a) = 1M(b) = 1M(c) = 1M(d) = 01 ca 0

Page 46: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

“Repairing Models”

If the assignment of a basic variable does not satisfy a bound, then pivot it, fix it, and propagate the change to its new dependent variables.

a = c – db = c + dM(a) = 0M(b) = 0M(c) = 0M(d) = 01 a

c = a + db = a + 2dM(a) = 0M(b) = 0M(c) = 0M(d) = 01 a

c = a + db = a + 2dM(a) = 1M(b) = 1M(c) = 1M(d) = 01 a

Page 47: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

“Repairing Models”

Sometimes, a model cannot be repaired. It is pointless to pivot.

a = b – ca 0, 1 b, c 0M(a) = 1M(b) = 1M(c) = 0

The value of M(a) is too big. We can reduce it by:- reducing M(b)

not possible b is at lower bound- increasing M(c)

not possible c is at upper bound

Page 48: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

“Repairing Models”

s1 a + d, s2 c + d

a = s1 – s2 + c

a 0, 1 s1, s2 0, 0 c

M(a) = 1M(s1) = 1

M(s2) = 0

M(c) = 0

Extracting proof from failed repair attempts is easy.

Page 49: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

“Repairing Models”

s1 a + d, s2 c + d

a = s1 – s2 + c

a 0, 1 s1, s2 0, 0 c

M(a) = 1M(s1) = 1

M(s2) = 0

M(c) = 0

Extracting proof from failed repair attempts is easy.

{ a 0, 1 s1, s2 0, 0 c } is inconsistent

Page 50: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

“Repairing Models”

s1 a + d, s2 c + d

a = s1 – s2 + c

a 0, 1 s1, s2 0, 0 c

M(a) = 1M(s1) = 1

M(s2) = 0

M(c) = 0

Extracting proof from failed repair attempts is easy.

{ a 0, 1 s1, s2 0, 0 c } is inconsistent

{ a 0, 1 a + d, c + d 0, 0 c } is inconsistent

Page 51: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Plan

– Decision procedures for Arithmetic

– Engineering Theories with Z3 [B. APLAS/CPP 2011]

– Combining Decision Procedures

Page 52: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Why Engineering Theories?

EUF LRA LIA Arrays Bit-Vectors Alg. DTSAT

Support Rich Theories (and logics) with Efficient Decision Procedures

Strings Reg. Exprs. NRA NIA Float

s f* *

BAPAMultiSets

homomorphis

msOptimization Orders Object

s HOL

DLASPQueuesXDucersSequencesMSOLAuth

Page 53: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Theory Solver: Optimization, Partial Orders

Reduction: Object Types

Saturation: HOL

We review three methods:

Page 54: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Goal: Tools to make users happy & productive

Page 55: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Overview of methods

New Theory

NewTheory

NewTheory

Search

Compile

Model

PartialCompile

Constraints

Equalities

Theory Solver(1st class solver)

Reduction (eager reduction)

Saturation(lazy reduction)

Page 56: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

OptimizationGet More Satisfaction with SMT

Oliveras, Nieuenhuis, SAT 2006

New Theory

NewTheory

NewTheory

Search

CompileModel

PartialCompile

Constraints

Eqs

Theory Solver

Reduction

Saturation

IntroSMT?Z3? Theory

Solver

Eager Reduction

LazyReduction

Page 57: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Weighted MaxSMT

𝑁𝑎𝑚𝑒 𝐹𝑜𝑟𝑚𝑢𝑙𝑎 h𝑤𝑒𝑖𝑔 𝑡𝐹 0 𝑎∨𝑏∨𝑥≥2 ∞𝐹 1 ¬𝑎∨𝑥 ≥3 3𝐹 2 ¬𝑏∨𝑥≥3 4𝐹 3 𝑥<2 5

Unsat

Page 58: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Weighted MaxSMT

𝑁𝑎𝑚𝑒 𝐹𝑜𝑟𝑚𝑢𝑙𝑎 h𝑤𝑒𝑖𝑔 𝑡𝐹 0 𝑎∨𝑏∨𝑥≥2 ∞𝐹 1 ¬𝑎∨𝑥 ≥3 3𝐹 2 ¬𝑏∨𝑥≥3 4𝐹 3 𝑥<2 5

Sat

Penalty:

Page 59: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Weighted MaxSMT

𝑁𝑎𝑚𝑒 𝐹𝑜𝑟𝑚𝑢𝑙𝑎 h𝑤𝑒𝑖𝑔 𝑡𝐹 0 𝑎∨𝑏∨𝑥≥2 ∞𝐹 1 ¬𝑎∨𝑥 ≥3 3𝐹 2 ¬𝑏∨𝑥≥3 4𝐹 3 𝑥<2 5

Sat

Penalty: 9 = 4 + 5

Page 60: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Weighted MaxSMT

𝑁𝑎𝑚𝑒 𝐹𝑜𝑟𝑚𝑢𝑙𝑎 h𝑤𝑒𝑖𝑔 𝑡𝐹 0 𝑎∨𝑏∨𝑥≥2 ∞𝐹 1 ¬𝑎∨𝑥 ≥3 3𝐹 2 ¬𝑏∨𝑥≥3 4𝐹 3 𝑥<2 5

Sat

Penalty: 5

Page 61: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Weighted MaxSMT

𝑁𝑎𝑚𝑒 𝐹𝑜𝑟𝑚𝑢𝑙𝑎 h𝑤𝑒𝑖𝑔 𝑡𝐹 0 𝑎∨𝑏∨𝑥≥2 ∞𝐹 1 ¬𝑎∨𝑥 ≥3 3𝐹 2 ¬𝑏∨𝑥≥3 4𝐹 3 𝑥<2 5

Sat

Penalty: 3

Page 62: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Weighted MaxSMT

𝐹𝑜𝑟𝑚𝑢𝑙𝑎 h𝑤𝑒𝑖𝑔 𝑡𝑎∨𝑏∨𝑥 ≥2 ∞

𝐹 1∨¬𝑎∨𝑥 ≥3 3𝐹 2∨¬𝑏∨𝑥≥3 4

𝐹3∨𝑥<2 5

Initially: All atoms are unassigned

Assert

Propagate:

Best so far:

Add Axiom - backtrack

Assert = 5 >

Add Axiom - backtrack

…. Assert

What does it take to encode this in Z3?

Page 63: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Principles of Modern SMT solvers in two slides

Page 64: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Core Engine in Z3: Modern DPLL/CDCL

Initialize

Decide

Propagate

Sat Conflict

Learn

Unsat

Backjump

Resolve

Forget is a learned clause

Restart [Nieuwenhuis, Oliveras, Tinelli J.ACM 06] customized

Model

Proof

ConflictResolution

Page 65: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

DPLL(T) solver interaction

T- Propagate

T- Conflict

h𝑤 𝑒𝑟𝑒𝑎>𝑏 ,𝑏>𝑐 ,𝑎≤𝑐⊆𝑀T- Conflict

T- Propagate

Page 66: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

How does Z3 enable T solvers?

Page 67: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

DPLL(T) Solver Interaction

Calls into DPLL engine

T-Propagate

T-Conflict

Callbacks from DPLL engine

Callbacks from DPLL engine with new assignment

T-Propagate

T-Conflict

Calls into DPLL engine

Page 68: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Partial Orders &Object Hierarcies

Acyclic graphs and SMT

New Theory

NewTheory

NewTheory

Search

CompileModel

PartialCompile

Constraints

Eqs

Theory Solver

Reduction

Saturation

IntroSMT?Z3? Theory

Solver

Eager Reduction

LazyReduction

Page 69: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Partial Orders as Acyclic Graphs

Elements are equalin strongly connectedcomponents = =

≼≼

≼≼

Page 70: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Partial Orders as Acyclic Graphs Checking negations

≼≼

≼≼¬≼

≼≼

≼≼

OK

¬≼

Not OK

Page 71: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Partial Orders as Acyclic GraphsChecking Consistency of :

Is there is a path from to

Extracting Equalities from using strongly connected components:

≼≼

≼≼

¬≼

≼≼

≼≼

Page 72: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Inheritance as table-lookup

Sherman, Garvin, Dwyer. IJCAR 2010

𝑥≼ 𝑗𝑎𝑣𝑎 .𝑙𝑎𝑛𝑔 .𝐶𝑜𝑚𝑝𝑎𝑟𝑎𝑏𝑙𝑒𝑥≼ 𝑗𝑎𝑣𝑎 .𝑙𝑎𝑛𝑔 .𝐶𝑙𝑜𝑛𝑎𝑏𝑙𝑒𝑥= 𝑗𝑎𝑣𝑎 .𝑢𝑡𝑖𝑙 .𝐷𝑎𝑡𝑒

Efficient propagators usingType Slicing algorithmLeverages ordering of childrenJ. Gil and Y. Zibin.[TOPLAS 2007]

Available as F#/Z3 sample

Page 73: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Object GraphsTo Cycle and not to Cycle

from Pex

New Theory

NewTheory

NewTheory

Search

CompileModel

PartialCompile

Constraints

Eqs

Theory Solver

Reduction

Saturation

IntroSMT?Z3? Theory

Solver

Eager Reduction

LazyReduction

Page 74: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

A Theory of Objects

Read-only fields Objects are non-extensionalHeap can be updated

Page 75: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

A Theory of Objects

So far so good, but what about read-only fields?

Page 76: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Encoding: Heaps as Arrays

Only Axiom: Instantiate for every occurrence of left(h,o)

Domains: objects are Natural numbers, left child is a smaller number

Most axioms follow by function definitions.

Page 77: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Encoding: Heaps as Arrays+Data-Types

No Extra Axiom: Data-type theory enforces acyclicity over left

Domains: read-only fields use algebraic data-types

Most axioms follow by function definitions.

More efficient search

Page 78: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

HOL

Z3 at the service of ,,,,,,,,*,

SMT version of Satalax, Brown, CADE 2011

New Theory

NewTheory

NewTheory

Search

CompileModel

PartialCompile

Constraints

Eqs

Theory Solver

Reduction

Saturation

IntroSMT?Z3? Theory

Solver

Eager Reduction

LazyReduction

Page 79: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Armand, Grégoire, Keller, Théry, Werner

Types and Z3 do mingle

Sledge Hammer

Page 80: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

ButUsed for First-Order Theorems

Page 81: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Sure, oftenHOL (problem)

is just FO (solution)

in disguise

Henry Louis Mencken

“For every problem there is a solution which is simple, clean and wrong.”

“We are all faced with a series of great opportunities brilliantly disguised as unsolvable problems.”John W. Gardner

Page 82: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Digression: CALCAL – Combinatory Array Logic

Existential fragment is in NP by reduction to congruence closure using polynomial set of instances.

Page 83: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

∀ 𝒇 . (∀ 𝒙 ,𝒚 . 𝒇 (𝒙 )= 𝒇 (𝒚 )→𝒙=𝒚 )→∃𝒈 . ∀ 𝒙 . 𝒙=𝒈 ( 𝒇 (𝒙 ))

but can we do something more HOLish?

e.g.,

Page 84: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Idea: Saturate for Henkin ModelsTypes

Terms

Constants

Axioms

𝜎 ∷=𝑖|𝑜𝜏 ∷=𝜎|𝜏→𝜏

𝑀 ,𝑁 ∷=𝜆 𝑥 :𝜏 .𝑀|(𝑀 𝑁 )|𝑥

Page 85: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Lazy Saturation loopHOL formula

Assert

Check SAT InstantiateModelUnsat

𝐹←𝐹∧𝐹 𝐼𝑛𝑠𝑡

Page 86: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

HOL SMT

Propositional reasoning

Equalities

CongruenceClosure

Extensional arrays

⟦_ ⟧ :𝐻𝑂𝐿→𝑆𝑀𝑇

SMT

SAT

HOL formula

Assert

Check SAT

InstantiateModelUnsat

𝐹←𝐹∧𝐹 𝐼𝑛𝑠𝑡

Page 87: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

long NF

Set of long NF terms with free variables from of type

Enumerate by depth:

Many more algorithms (matching, unification)/optimizations required for anything viable… … but main task of Boolean search, equalities, functions is delegated

HOL formula

Assert

Check SAT

InstantiateModelUnsat

𝐹←𝐹∧𝐹 𝐼𝑛𝑠𝑡

Page 88: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

ConclusionsWe surveyed three methods for adding new theories (logics) to Z3:

- As 1st class Theory Solver

- Eager reduction: embed theory in Z3

- Lazy reduction: add facts on demand

Choose one that fits your theory!

Page 90: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Plan

– Decision procedures for Arithmetic

– Engineering Theories with Z3

– Combining Decision Procedures [de Moura & B. SMT 2007]

Page 91: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Theories vs. Problem ClassesApplications often generate problems with particular characteristics (many ground clauses/bit-vectors + predicates/arithmetic + transendentals/..)

New Z3 feature by de Moura & Passmore:Compose strategies using tactical interface.

Page 92: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Combining Theories

In practice, we need a combination of theories.

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

A theory is a set (potentially infinite) of first-order sentences.

Main questions:Is the union of two theories T1 T2 consistent?Given a solvers for T1 and T2, how can we build a solver forT1 T2?

Page 93: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

A Combination History

1979 Nelson, Oppen - Framework

1996 Tinelli & Harindi. N.O. Fix

2000 Barrett et.al N.O + Rewriting

2002 Zarba & Manna. Nice Theories

2007 de Moura & B. Model-based Theory Combination

2006 Bruttomesso et.al. Delayed Theory Combination

1984 Shostak. Theory solvers

1996 Cyrluk et.al Shostak Fix #1

1998 B. Shostak with Constraints

2001 Rueß & Shankar Shostak Fix #2

2004 Ranise et.al. N.O + Superposition

Foundations Efficiency using rewriting

2001: Efficient DPLL made guessing cheap

Page 94: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Disjoint Theories

Two theories are disjoint if they do not share function/constant and predicate symbols.= is the only exception.

Example:The theories of arithmetic and arrays are disjoint.

Arithmetic symbols: {0, -1, 1, -2, 2, …, +, -, *, >, <, ≥, }Array symbols: { read, write }

Page 95: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Purification

It is a different name for our “naming” subterms procedure.

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

b + 2 = c, v6 ≠ v7

v1 3, v2 write(a, b, v1), v3 c-2, v4 read(v2, v3),v5 c-b+1, v6 f(v4), v7 f(v5)

Page 96: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Purification

It is a different name for our “naming” subterms procedure.

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

b + 2 = c, v6 ≠ v7

v1 3, v2 write(a, b, v1), v3 c-2, v4 read(v2, v3),v5 c-b+1, v6 f(v4), v7 f(v5)

b + 2 = c, v1 3, v3 c-2, v5 c-b+1,v2 write(a, b, v1), v4 read(v2, v3),v6 f(v4), v7 f(v5), v6 ≠ v7

Page 97: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Stably Infinite Theories

A theory is stably infinite if every satisfiable QFF is satisfiable in an infinite model.

EUF and arithmetic are stably infinite.

Bit-vectors are not.

Page 98: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Important Result

The union of two consistent, disjoint, stably infinite theories is consistent.

Page 99: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Convexity

A theory T is convex iff for all finite sets S of literals and

for all a1 = b1 … an = bn

S implies a1 = b1 … an = bn

iff S implies ai = bi for some 1 i n

Page 100: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Convexity: Results

Every convex theory with non trivial models is stably infinite.

All Horn equational theories are convex.formulas of the form s1 ≠ r1 … sn ≠ rn t = t’

Linear rational arithmetic is convex.

Page 101: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Convexity: Negative Results

Linear integer arithmetic is not convex 1 a 2, b = 1, c = 2 implies a = b a = c

Nonlinear arithmetica2 = 1, b = 1, c = -1 implies a = b a = c

Theory of bit-vectors

Theory of arraysc1 = read(write(a, i, c2), j), c3 = read(a, j)implies c1 = c2 c1 = c3

Page 102: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Combination of non-convex theories

EUF is convex (O(n log n))IDL is non-convex (O(nm))

EUF IDL is NP-CompleteReduce 3CNF to EUF IDLFor each boolean variable pi add 0 ai 1For each clause p1 p2 p3 add

f(a1, a2, a3) ≠ f(0, 1, 0)

Page 103: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Combination of non-convex theories

EUF is convex (O(n log n))IDL is non-convex (O(nm))

EUF IDL is NP-CompleteReduce 3CNF to EUF IDLFor each boolean variable pi add 0 ai 1For each clause p1 p2 p3 add

f(a1, a2, a3) ≠ f(0, 1, 0)

a1 ≠ 0 a2 ≠ 1 a3 ≠ 0

implies

Page 104: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Nelson-Oppen Combination

Page 105: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Nelson-Oppen Combination

Page 106: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

NO deterministic procedure(for convex theories)

Page 107: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

NO deterministic procedureCompleteness

Page 108: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

NO procedure: Example

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

Arithmeticb + 2 = c, v1 3, v3 c-2, v5 c-b+1

Arraysv2 write(a, b, v1), v4 read(v2, v3)

EUFv6 f(v4), v7 f(v5), v6 ≠ v7

Page 109: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

NO procedure: Example

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

Arithmeticb + 2 = c, v1 3, v3 c-2, v5 c-b+1

Arraysv2 write(a, b, v1), v4 read(v2, v3)

EUFv6 f(v4), v7 f(v5), v6 ≠ v7

Substituting c

Page 110: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

NO procedure: Example

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

Arithmeticb + 2 = c, v1 3, v3 b, v5 3

Arraysv2 write(a, b, v1), v4 read(v2, v3),

EUFv6 f(v4), v7 f(v5), v6 ≠ v7

Propagating v3 = b

Page 111: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

NO procedure: Example

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

Arithmeticb + 2 = c, v1 3, v3 b, v5 3

Arraysv2 write(a, b, v1), v4 read(v2, v3),v3 = b

EUFv6 f(v4), v7 f(v5), v6 ≠ v7,v3 = b

Deducing v4 = v1

Page 112: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

NO procedure: Example

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

Arithmeticb + 2 = c, v1 3, v3 b, v5 3

Arraysv2 write(a, b, v1), v4 read(v2, v3),v3 = b,v4 = v1

EUFv6 f(v4), v7 f(v5), v6 ≠ v7,v3 = b

Propagating v4 = v1

Page 113: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

NO procedure: Example

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

Arithmeticb + 2 = c, v1 3, v3 b, v5 3,v4 = v1

Arraysv2 write(a, b, v1), v4 read(v2, v3),v3 = b,v4 = v1

EUFv6 f(v4), v7 f(v5), v6 ≠ v7,v3 = b,v4 = v1

Propagating v5 = v1

Page 114: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

NO procedure: Example

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

Arithmeticb + 2 = c, v1 3, v3 b, v5 3,v4 = v1

Arraysv2 write(a, b, v1), v4 read(v2, v3),v3 = b,v4 = v1

EUFv6 f(v4), v7 f(v5), v6 ≠ v7,v3 = b,v4 = v1,v5 = v1

Congruence: v6 = v7

Page 115: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

NO procedure: Example

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

Arithmeticb + 2 = c, v1 3, v3 b, v5 3,v4 = v1

Arraysv2 write(a, b, v1), v4 read(v2, v3),v3 = b,v4 = v1

EUFv6 f(v4), v7 f(v5), v6 ≠ v7,v3 = b,v4 = v1,v5 = v1 , v6 = v7

Unsatisfiable

Page 116: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

NO deterministic procedure

Deterministic procedure may fail for non-convex theories.

0 a 1, 0 b 1, 0 c 1,f(a) ≠ f(b),f(a) ≠ f(c),f(b) ≠ f(c)

Page 117: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Combining Procedures in Practice

Page 118: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Combining Procedures in Practice

Page 119: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Example

Page 120: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Example

Page 121: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Example

Page 122: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Example

Page 123: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Example

Page 124: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Example

Page 125: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Example

Page 126: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Example

Page 127: Nikolaj  Bjørner Senior Researcher Microsoft Research  Redmond

Example


Recommended