Quantifiers Leonardo de Moura Microsoft Research Satisfiability - - PowerPoint PPT Presentation

quantifiers
SMART_READER_LITE
LIVE PREVIEW

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-1
SLIDE 1

Quantifiers

Leonardo de Moura Microsoft Research

slide-2
SLIDE 2

Satisfiability

𝑏 > 𝑐 + 2, 𝑏 = 2𝑑 + 10, 𝑑 + 𝑐 ≤ 1000 𝑏 = 0, 𝑐 = −3, 𝑑 = −5

0 > −𝟒 + 2, 0 = 2 −𝟔 + 10, −𝟔 + (−𝟒) ≤ 1000

Model SAT

slide-3
SLIDE 3

Quantifiers

∀𝑦 ∃𝑧 𝑦 > 0 ⟹ 𝑔 𝑦, 𝑧 = 0

slide-4
SLIDE 4

Quantifiers

∀𝑦 ∃𝑧 𝑦 > 0 ⟹ 𝑔 𝑦, 𝑧 = 0 Universal

slide-5
SLIDE 5

Quantifiers

∀𝑦 ∃𝑧 𝑦 > 0 ⟹ 𝑔 𝑦, 𝑧 = 0 Existential

slide-6
SLIDE 6

Quantifiers

∀𝑦 ∃𝑧 𝑦 > 0 ⟹ 𝑔 𝑦, 𝑧 = 0

A Model 𝑔 is the constant function 0

slide-7
SLIDE 7

Quantifiers

∀𝑦 ∃𝑧 𝑦 > 0 ⟹ 𝑔 𝑦, 𝑧 = 0

Another Model 𝑔 is the polynomial 𝑧2 − 𝑦

slide-8
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
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
SLIDE 10

Verification Tools need Quantifiers

User provided assertions  i,j: i  j  read(a,i)  read(b,j)

slide-11
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
SLIDE 12

Verification Tools need Quantifiers

Main Challenge Solver must be fast is satisfiable instances

slide-13
SLIDE 13

Verifying Compilers

Annotated Program Verification Condition F

pre/post conditions invariants and other annotations

slide-14
SLIDE 14

Verification Condition: Structure

BIG and-or tree (ground)  Axioms (non-ground) Control & Data Flow

slide-15
SLIDE 15

VCC: Verifying C Compiler

slide-16
SLIDE 16

BAD NEWS

First-order logic (FOL) is semi-decidable Quantifiers + EUF

slide-17
SLIDE 17

BAD NEWS

FOL + Linear Integer Arithmetic is undecidable Quantifiers + EUF + LIA

slide-18
SLIDE 18

Hypervisor

Hardware Hypervisor

Challenges:

VCs have several Megabytes Thousands universal quantifiers Developers are willing at most 5 min per VC

slide-19
SLIDE 19

Verification Attempt Time vs. Satisfaction and Productivity

slide-20
SLIDE 20

NNF: Negation Normal Form

slide-21
SLIDE 21

NNF: Negation Normal Form

slide-22
SLIDE 22

Skolemization

slide-23
SLIDE 23

Skolemization

slide-24
SLIDE 24

 - Many Approaches

Heuristic quantifier instantiation SMT + Saturation provers

Complete quantifier instantiation Decidable fragments

Model based quantifier instantiation

Quantifier Elimination

slide-25
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
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
SLIDE 27

E-matching problem

slide-28
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
SLIDE 29

EUF Solver: Review

slide-30
SLIDE 30

EUF Solver: Review

slide-31
SLIDE 31

EUF Solver: Review

slide-32
SLIDE 32

EUF Solver: Review

slide-33
SLIDE 33

EUF Solver: Review

slide-34
SLIDE 34

EUF Solver: Review

slide-35
SLIDE 35

EUF Solver: Review

slide-36
SLIDE 36

EUF Solver: Review

slide-37
SLIDE 37

EUF Solver: Review

slide-38
SLIDE 38

EUF Solver: Review

slide-39
SLIDE 39

E-matching

slide-40
SLIDE 40

E-matching: Example

slide-41
SLIDE 41

E-matching: Example

slide-42
SLIDE 42

E-matching: Example

slide-43
SLIDE 43

E-matching: Example

slide-44
SLIDE 44

E-matching: Example

slide-45
SLIDE 45

E-matching: Example

slide-46
SLIDE 46

E-matching: Example

slide-47
SLIDE 47

E-matching: Example

slide-48
SLIDE 48

E-matching: Example

slide-49
SLIDE 49

E-matching: Example

slide-50
SLIDE 50

E-matching: Example

slide-51
SLIDE 51

E-matching: Example

slide-52
SLIDE 52

E-matching: Example

slide-53
SLIDE 53

E-matching: Example

slide-54
SLIDE 54

E-matching: Example

slide-55
SLIDE 55

E-matching: Example

slide-56
SLIDE 56

E-matching: Example

slide-57
SLIDE 57

Efficient E-matching

Problem Indexing Technique Fast retrieval E-matching code trees Incremental E-Matching Inverted path index

slide-58
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
SLIDE 59

E-matching limitations

E-matching needs ground seeds. x: p(x), x: not p(x)

slide-60
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
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
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
SLIDE 63

E-matching limitations

It is not refutationally complete

False positives

slide-64
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
SLIDE 65

Decidable Fragments & Complete Quantifier Instatiation

slide-66
SLIDE 66

 + theories

There is no sound and refutationally complete procedure for linear arithmetic + unintepreted function symbols

slide-67
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
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
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
SLIDE 70

Models as Functional Programs

slide-71
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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=0y=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
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=0y=2,-1, 0) x1, x2: if(x1=0x2=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=0x2=2,-1,0)  0  if(x2=2,0,1)  0 is unsat if(s1=0s2=2,-1,0)  0  if(s2=2,0,1)  0 is unsat

slide-89
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
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
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
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 a2, b3 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
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
SLIDE 94

Infinite F*

𝑈𝑎 𝐺∗

Infinite set of first-order sentences

Applying COMPACTNESS

Finite 𝑇

slide-95
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
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
SLIDE 97

Extensions

Shifting

  • (0  x1)  (x1  n)  f(x1) = g(x1+2)
slide-98
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
SLIDE 99

Extensions

Online tutorial at: http://rise4fun.com/z3/tutorial

slide-100
SLIDE 100

Extensions

Online tutorial at: http://rise4fun.com/z3/tutorial

slide-101
SLIDE 101

Related work

Bernays-Schönfinkel class. Stratified Many-Sorted Logic. Array Property Fragment. Local theory extensions.

slide-102
SLIDE 102

SMT + Saturation

slide-103
SLIDE 103

CDCL/DPLL : Review

M | F

Partial model Set of clauses

slide-104
SLIDE 104

CDCL/DPLL : Review

Guessing

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

slide-105
SLIDE 105

CDCL/DPLL : Review

Deducing

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

slide-106
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
SLIDE 107

DPLL()

Tight integration: DPLL + Saturation solver.

BIG and-or tree (ground) Axioms (non-ground)

slide-108
SLIDE 108

DPLL()

Inference rule: DPLL() is parametric.

Examples:

Resolution Superposition calculus …

slide-109
SLIDE 109

DPLL()

M | F

Partial model Set of clauses

slide-110
SLIDE 110

DPLL() : Deduce I

p(a) | p(a)q(a), x: p(x)r(x), x: p(x)s(x)

slide-111
SLIDE 111

DPLL() : Deduce I

p(a) | p(a)q(a), p(x)r(x), p(x)s(x)

slide-112
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
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
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
SLIDE 115

DPLL() : Backtracking

p(a), r(a) | p(a)q(a), p(a)r(a), p(a)r(a), …

slide-116
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
SLIDE 117

DPLL() : Improvement

Saturation solver ignores non-unit ground clauses.

p(a) | p(a)q(a), p(x)r(x)

slide-118
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
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
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
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
SLIDE 122

Summary

Complete instantiation + MBQI decides several useful fragments model & proof finding slow complements E-matching

slide-123
SLIDE 123

Summary

SMT + Saturation refutationally complete for pure first-order proof finding slow

slide-124
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
SLIDE 125

Challenge

New and efficient procedures capable of producing models for satisfiable instances.