SLIDE 1
Quantifiers Leonardo de Moura Microsoft Research Satisfiability - - PowerPoint PPT Presentation
Quantifiers Leonardo de Moura Microsoft Research Satisfiability - - PowerPoint PPT Presentation
Quantifiers Leonardo de Moura Microsoft Research Satisfiability > + 2, = 2 + 10, + 1000 Model SAT = 0, = 3, = 5 0 > + 2, 0 = 2 + 10, + () 1000
SLIDE 2
SLIDE 3
Quantifiers
∀𝑦 ∃𝑧 𝑦 > 0 ⟹ 𝑔 𝑦, 𝑧 = 0
SLIDE 4
Quantifiers
∀𝑦 ∃𝑧 𝑦 > 0 ⟹ 𝑔 𝑦, 𝑧 = 0 Universal
SLIDE 5
Quantifiers
∀𝑦 ∃𝑧 𝑦 > 0 ⟹ 𝑔 𝑦, 𝑧 = 0 Existential
SLIDE 6
Quantifiers
∀𝑦 ∃𝑧 𝑦 > 0 ⟹ 𝑔 𝑦, 𝑧 = 0
A Model 𝑔 is the constant function 0
SLIDE 7
Quantifiers
∀𝑦 ∃𝑧 𝑦 > 0 ⟹ 𝑔 𝑦, 𝑧 = 0
Another Model 𝑔 is the polynomial 𝑧2 − 𝑦
SLIDE 8
Verification Tools need Quantifiers
Modeling the Runtime
h,o,f: IsHeap(h) o ≠ null read(h, o, alloc) = t read(h,o, f) = null read(h, read(h,o,f),alloc) =
SLIDE 9
Verification Tools need Quantifiers
Frame Axioms o, f:
- ≠ null read(h0, o, alloc) = t
read(h1,o,f) = read(h0,o,f) (o,f) M
SLIDE 10
Verification Tools need Quantifiers
User provided assertions i,j: i j read(a,i) read(b,j)
SLIDE 11
Verification Tools need Quantifiers
Extra Theories
x: p(x,x) x,y,z: p(x,y), p(y,z) p(x,z) x,y: p(x,y), p(y,x) x = y
SLIDE 12
Verification Tools need Quantifiers
Main Challenge Solver must be fast is satisfiable instances
SLIDE 13
Verifying Compilers
Annotated Program Verification Condition F
pre/post conditions invariants and other annotations
SLIDE 14
Verification Condition: Structure
BIG and-or tree (ground) Axioms (non-ground) Control & Data Flow
SLIDE 15
VCC: Verifying C Compiler
SLIDE 16
BAD NEWS
First-order logic (FOL) is semi-decidable Quantifiers + EUF
SLIDE 17
BAD NEWS
FOL + Linear Integer Arithmetic is undecidable Quantifiers + EUF + LIA
SLIDE 18
Hypervisor
Hardware Hypervisor
Challenges:
VCs have several Megabytes Thousands universal quantifiers Developers are willing at most 5 min per VC
SLIDE 19
Verification Attempt Time vs. Satisfaction and Productivity
SLIDE 20
NNF: Negation Normal Form
SLIDE 21
NNF: Negation Normal Form
SLIDE 22
Skolemization
SLIDE 23
Skolemization
SLIDE 24
- Many Approaches
Heuristic quantifier instantiation SMT + Saturation provers
Complete quantifier instantiation Decidable fragments
Model based quantifier instantiation
Quantifier Elimination
SLIDE 25
Heuristic Quantifier Instantiation
E-matching (matching modulo equalities). Example:
x: f(g(x)) = x { f(g(x)) }
a = g(b), b = c, f(a) c
Pattern/Trigger
SLIDE 26
Heuristic Quantifier Instantiation
E-matching (matching modulo equalities). Example:
x: f(g(x)) = x { f(g(x)) }
a = g(b), b = c, f(a) c
x=b
f(g(b)) = b
SLIDE 27
E-matching problem
SLIDE 28
E-matching Challenge
Number of matches can be exponential It is not refutationally complete The real challenge is finding new matches: Incrementally during backtracking search Large database of patterns
SLIDE 29
EUF Solver: Review
SLIDE 30
EUF Solver: Review
SLIDE 31
EUF Solver: Review
SLIDE 32
EUF Solver: Review
SLIDE 33
EUF Solver: Review
SLIDE 34
EUF Solver: Review
SLIDE 35
EUF Solver: Review
SLIDE 36
EUF Solver: Review
SLIDE 37
EUF Solver: Review
SLIDE 38
EUF Solver: Review
SLIDE 39
E-matching
SLIDE 40
E-matching: Example
SLIDE 41
E-matching: Example
SLIDE 42
E-matching: Example
SLIDE 43
E-matching: Example
SLIDE 44
E-matching: Example
SLIDE 45
E-matching: Example
SLIDE 46
E-matching: Example
SLIDE 47
E-matching: Example
SLIDE 48
E-matching: Example
SLIDE 49
E-matching: Example
SLIDE 50
E-matching: Example
SLIDE 51
E-matching: Example
SLIDE 52
E-matching: Example
SLIDE 53
E-matching: Example
SLIDE 54
E-matching: Example
SLIDE 55
E-matching: Example
SLIDE 56
E-matching: Example
SLIDE 57
Efficient E-matching
Problem Indexing Technique Fast retrieval E-matching code trees Incremental E-Matching Inverted path index
SLIDE 58
E-matching: code trees
Trigger: f(x1, g(x1, a), h(x2), b) Instructions:
- 1. init(f, 2)
- 2. check(r4, b, 3)
- 3. bind(r2, g, r5, 4)
- 4. compare(r1, r5, 5)
- 5. check(r6, a, 6)
- 6. bind(r3, h, r7, 7)
- 7. yield(r1, r7)
Compiler Similar triggers share several instructions. Combine code sequences in a code tree
SLIDE 59
E-matching limitations
E-matching needs ground seeds. x: p(x), x: not p(x)
SLIDE 60
E-matching limitations
Bad user provided triggers: x: f(g(x))=x { f(g(x)) } g(a) = c, g(b) = c, a b
Trigger is too restrictive
SLIDE 61
E-matching limitations
Bad user provided triggers: x: f(g(x))=x { g(x) } g(a) = c, g(b) = c, a b
More “liberal” trigger
SLIDE 62
E-matching limitations
Bad user provided triggers: x: f(g(x))=x { g(x) } g(a) = c, g(b) = c, a b, f(g(a)) = a, f(g(b)) = b a=b
SLIDE 63
E-matching limitations
It is not refutationally complete
False positives
SLIDE 64
E-matching: why do we use it?
Integrates smoothly with current SMT Solvers design. Proof finding. Software verification problems are big & shallow.
SLIDE 65
Decidable Fragments & Complete Quantifier Instatiation
SLIDE 66
+ theories
There is no sound and refutationally complete procedure for linear arithmetic + unintepreted function symbols
SLIDE 67
Model Generation
How to represent the model of satisfiable formulas? Functor: Given a model M for T Generate a model M’ for F (modulo T) Example:
F: f(a) = 0 and a > b and f(b) > f(a) + 1
Symbol Interpretation a 1 b f ite(x=1, 0, 2) M’:
SLIDE 68
Model Generation
How to represent the model of satisfiable formulas? Functor: Given a model M for T Generate a model M’ for F (modulo T) Example:
F: f(a) = 0 and a > b and f(b) > f(a) + 1
Symbol Interpretation a 1 b f ite(x=1, 0, 2) M’:
Interpretation is given using T-symbols
SLIDE 69
Model Generation
How to represent the model of satisfiable formulas? Functor: Given a model M for T Generate a model M’ for F (modulo T) Example:
F: f(a) = 0 and a > b and f(b) > f(a) + 1
Symbol Interpretation a 1 b f ite(x=1, 0, 2) M’:
Non ground term (lambda expression)
SLIDE 70
Models as Functional Programs
SLIDE 71
Model Checking
Symbol Interpretation a 1 b f ite(x=1, 0, 2) M’:
Is x: f(x) ≥ 0 satisfied by M’? Yes, not (ite(k=1,0,2) ≥ 0) is unsatisfiable
SLIDE 72
Model Checking
Symbol Interpretation a 1 b f ite(x=1, 0, 2) M’:
Is x: f(x) ≥ 0 satisfied by M’? Yes, not (ite(k=1,0,2) ≥ 0) is unsatisfiable Negated quantifier Replaced f by its interpretation Replaced x by fresh constant k
SLIDE 73
Essentially uninterpreted fragment
Variables appear only as arguments of uninterpreted symbols.
f(g(x1) + a) < g(x1) h(f(x1), x2) = 0 f(x1+x2) f(x1) + f(x2)
SLIDE 74
Basic Idea
Given a set of formulas F, build an equisatisfiable set of quantifier-free formulas F* Suppose
1.
We have a clause C[f(x)] containing f(x).
2.
We have f(t). Instantiate x with t: C[f(t)]. “Domain” of f is the set of ground terms Af t Af if there is a ground term f(t)
SLIDE 75
Example
g(x1, x2) = 0 h(x2) = 0, g(f(x1),b) + 1 f(x1), h(c) = 1, f(a) = 0 F F*
SLIDE 76
Example
g(x1, x2) = 0 h(x2) = 0, g(f(x1),b) + 1 f(x1), h(c) = 1, f(a) = 0 F F* h(c) = 1, f(a) = 0 Copy quantifier-free formulas “Domains”: Af: { a } Ag: { } Ah: { c }
SLIDE 77
Example
g(x1, x2) = 0 h(x2) = 0, g(f(x1),b) + 1 f(x1), h(c) = 1, f(a) = 0 F F* h(c) = 1, f(a) = 0, “Domains”: Af : { a } Ag : { } Ah : { c }
SLIDE 78
Example
g(x1, x2) = 0 h(x2) = 0, g(f(x1),b) + 1 f(x1), h(c) = 1, f(a) = 0 F F* h(c) = 1, f(a) = 0, g(f(a),b) + 1 f(a) “Domains”: Af : { a } Ag : { [f(a), b] } Ah : { c }
SLIDE 79
Example
g(x1, x2) = 0 h(x2) = 0, g(f(x1),b) + 1 f(x1), h(c) = 1, f(a) = 0 F F* h(c) = 1, f(a) = 0, g(f(a),b) + 1 f(a), “Domains”: Af : { a } Ag : { [f(a), b] } Ah : { c }
SLIDE 80
Example
g(x1, x2) = 0 h(x2) = 0, g(f(x1),b) + 1 f(x1), h(c) = 1, f(a) = 0 F F* h(c) = 1, f(a) = 0, g(f(a),b) + 1 f(a), g(f(a), b) = 0 h(b) = 0 “Domains”: Af : { a } Ag : { [f(a), b] } Ah : { c, b }
SLIDE 81
Example
g(x1, x2) = 0 h(x2) = 0, g(f(x1),b) + 1 f(x1), h(c) = 1, f(a) = 0 F F* h(c) = 1, f(a) = 0, g(f(a),b) + 1 f(a), g(f(a), b) = 0 h(b) = 0 “Domains”: Af : { a } Ag : { [f(a), b]} Ah : { c, b }
SLIDE 82
Example
g(x1, x2) = 0 h(x2) = 0, g(f(x1),b) + 1 f(x1), h(c) = 1, f(a) = 0 F F* h(c) = 1, f(a) = 0, g(f(a),b) + 1 f(a), g(f(a), b) = 0 h(b) = 0, g(f(a), c) = 0 h(c) = 0 “Domains”: Af : { a } Ag : { [f(a), b], [f(a), c] } Ah : { c, b }
SLIDE 83
Example
g(x1, x2) = 0 h(x2) = 0, g(f(x1),b) + 1 f(x1), h(c) = 1, f(a) = 0 F F* h(c) = 1, f(a) = 0, g(f(a),b) + 1 f(a), g(f(a), b) = 0 h(b) = 0, g(f(a), c) = 0 h(c) = 0 a 2, b 2, c 3 f { 2 0, …} h { 2 0, 3 1, …} g { [0,2] -1, [0,3] 0, …} M
SLIDE 84
Basic Idea
Given a model M for F*, Build a model M for F Define a projection function f s.t. range of f is M(Af), and f (v) = v if v M(Af) Then, M(f)(v) = M(f)(f(v))
SLIDE 85
Basic Idea
M(Af) M(f(Af)) M(Af) M(f(Af))
M(f)
M(Af)
f M(f) M(f)
SLIDE 86
Basic Idea
Given a model M for F*, Build a model M for F In our example, we have: h(b) and h(c)
Ah = { b, c }, and M(Ah) = { 2, 3 }
h = { 2 2, 3 3, else 3 } M(h) { 2 0, 3 1, …} M(h) { 2 0, 3 1, else 1} M(h) = x. if(x=2, 0, 1)
SLIDE 87
Example
g(x1, x2) = 0 h(x2) = 0, g(f(x1),b) + 1 f(x1), h(c) = 1, f(a) = 0 F F* h(c) = 1, f(a) = 0, g(f(a),b) + 1 f(a), g(f(a), b) = 0 h(b) = 0, g(f(a), c) = 0 h(c) = 0 M a 2, b 2, c 3 f x. 2 h x. if(x=2, 0, 1) g x,y. if(x=0y=2,-1, 0) M a 2, b 2, c 3 f { 2 0, …} h { 2 0, 3 1, …} g { [0,2] -1, [0,3] 0, …}
SLIDE 88
Example : Model Checking
M a 2, b 2, c 3 f x. 2 h x. if(x=2, 0, 1) g x,y. if(x=0y=2,-1, 0) x1, x2: if(x1=0x2=2,-1,0) = 0 if(x2=2,0,1) = 0 is valid Does M satisfies? x1, x2 : g(x1, x2) = 0 h(x2) = 0 x1, x2: if(x1=0x2=2,-1,0) 0 if(x2=2,0,1) 0 is unsat if(s1=0s2=2,-1,0) 0 if(s2=2,0,1) 0 is unsat
SLIDE 89
Why does it work?
Suppose M does not satisfy C[f(x)]. Then for some value v, M{x v} falsifies C[f(x)]. M{x f(v)} also falsifies C[f(x)]. But, there is a term t Af s.t. M(t) = f(v) Moreover, we instantiated C[f(x)] with t. So, M must not satisfy C[f(t)]. Contradiction: M is a model for F*.
SLIDE 90
Refinement: Lazy construction
F* may be very big (or infinite). Lazy-construction
Build F* incrementally, F* is the limit of the sequence F0 F1 … Fk … If Fk is unsat then F is unsat. If Fk is sat, then build (candidate) M If M satisfies all quantifiers in F then return sat.
SLIDE 91
Refinement: Model-based instantiation
Suppose M does not satisfy a clause C[f(x)] in F.
Add an instance C[f(t)] which “blocks” this spurious model. Issue: how to find t? Use model checking, and the “inverse” mapping f
- 1 from values to terms (in Af).
f
- 1(v) = t if M(t) = f(v)
SLIDE 92
Example: Model-based instantiation
F x1: f(x1) < 0, f(a) = 1, f(b) = -1 F0 f(a) = 1, f(b) = -1 M a2, b3 f x. if(x = 2, 1, -1) Model Checking x1: f(x1) < 0 not if(s1= 2, 1, -1) < 0 s1 2
f
- 1(2) = a
F1 f(a) = 1, f(b) = -1 f(a) < 0 unsat
SLIDE 93
Infinite F*
Is refutationally complete? FOL Compactness
A set of sentences is unsatisfiable iff it contains an unsatisfiable finite subset.
A theory T is a set of sentences, then apply compactness to F*T
SLIDE 94
Infinite F*
𝑈𝑎 𝐺∗
∪
Infinite set of first-order sentences
Applying COMPACTNESS
Finite 𝑇
SLIDE 95
Infinite F* : Example
F x1: f(x1) < f(f(x1)), x1: f(x1) < a, 1 < f(0). F* f(0) < f(f(0)), f(f(0)) < f(f(f(0))), … f(0) < a, f(f(0)) < a, … 1 < f(0) Every finite subset
- f F* is satisfiable.
Unsatisfiable
SLIDE 96
Infinite F* : What is wrong?
Theory of linear arithmetic TZ is the set of all first-order sentences that are true in the standard structure Z. Tz has non-standard models. F and F* are satisfiable in a non-standard model. Alternative: a theory is a class of structures. Compactness does not hold. F and F* are still equisatisfiable.
SLIDE 97
Extensions
Shifting
- (0 x1) (x1 n) f(x1) = g(x1+2)
SLIDE 98
Extensions
Many-sorted logic Pseudo-Macros 0 g(x1) f(g(x1)) = x1, 0 g(x1) h(g(x1)) = 2x1, g(a) < 0
SLIDE 99
Extensions
Online tutorial at: http://rise4fun.com/z3/tutorial
SLIDE 100
Extensions
Online tutorial at: http://rise4fun.com/z3/tutorial
SLIDE 101
Related work
Bernays-Schönfinkel class. Stratified Many-Sorted Logic. Array Property Fragment. Local theory extensions.
SLIDE 102
SMT + Saturation
SLIDE 103
CDCL/DPLL : Review
M | F
Partial model Set of clauses
SLIDE 104
CDCL/DPLL : Review
Guessing
p, q | p q, q r p | p q, q r
SLIDE 105
CDCL/DPLL : Review
Deducing
p, s| p q, p s p | p q, p s
SLIDE 106
CDCL/DPLL : Review
Backtracking
p, s| p q, s q, p q p, s, q | p q, s q, p q
SLIDE 107
DPLL()
Tight integration: DPLL + Saturation solver.
BIG and-or tree (ground) Axioms (non-ground)
SLIDE 108
DPLL()
Inference rule: DPLL() is parametric.
Examples:
Resolution Superposition calculus …
SLIDE 109
DPLL()
M | F
Partial model Set of clauses
SLIDE 110
DPLL() : Deduce I
p(a) | p(a)q(a), x: p(x)r(x), x: p(x)s(x)
SLIDE 111
DPLL() : Deduce I
p(a) | p(a)q(a), p(x)r(x), p(x)s(x)
SLIDE 112
DPLL() : Deduce I
p(a) | p(a)q(a), p(x)r(x), p(x)s(x) p(a) | p(a)q(a), p(x)r(x), p(x)s(x), r(x)s(x) Resolution
SLIDE 113
DPLL() : Deduce II
Using ground atoms from M:
M | F
Main issue: backtracking. Hypothetical clauses: H C
(regular) Clause (hypothesis) Ground literals Track literals from M used to derive C
SLIDE 114
DPLL() : Deduce II
p(a) | p(a)q(a), p(x)r(x) p(a) | p(a)q(a), p(x)r(x), p(a)r(a) p(a), p(x)r(x) r(a)
SLIDE 115
DPLL() : Backtracking
p(a), r(a) | p(a)q(a), p(a)r(a), p(a)r(a), …
SLIDE 116
DPLL() : Backtracking
p(a), r(a) | p(a)q(a), p(a)r(a), p(a)r(a), … p(a) is removed from M
- p(a) | p(a)q(a), p(a)r(a), …
SLIDE 117
DPLL() : Improvement
Saturation solver ignores non-unit ground clauses.
p(a) | p(a)q(a), p(x)r(x)
SLIDE 118
DPLL() : Improvement
Saturation solver ignores non-unit ground clauses. It is still refutanionally complete if:
has the reduction property.
BIG and-or tree (ground) Axioms (non-ground)
SLIDE 119
DPLL() : Improvement
DPLL + Theories Saturation Solver
Saturation solver ignores non-unit ground clauses. It is still refutanionally complete if:
has the reduction property. Ground literals Ground clauses
SLIDE 120
DPLL() : Problem
Interpreted symtbols
- (f(a) > 2), f(x) > 5
It is refutationally complete if Interpreted symbols only occur in ground clauses Non ground clauses are variable inactive “Good” ordering is used
SLIDE 121
Summary
E-matching proof finding fast shallow proofs in big formulas not refutationally complete regularly solves VCs with more than 5 Mb
SLIDE 122
Summary
Complete instantiation + MBQI decides several useful fragments model & proof finding slow complements E-matching
SLIDE 123
Summary
SMT + Saturation refutationally complete for pure first-order proof finding slow
SLIDE 124
Not covered
Quantifier elimination Fourier-Motzkin (Linear Real Arithmetic) Cooper (Linear Integer Arithmetic) CAD (Nonlinear Real Arithmetic) Algebraic Datatypes (Hodges) Finite model finding Many Decidable Fragments
SLIDE 125