Counterexample-Guided Quantifjer Instantiation for Synthesis in SMT - - PowerPoint PPT Presentation

counterexample guided quantifjer instantiation for
SMART_READER_LITE
LIVE PREVIEW

Counterexample-Guided Quantifjer Instantiation for Synthesis in SMT - - PowerPoint PPT Presentation

Counterexample-Guided Quantifjer Instantiation for Synthesis in SMT Andrew Reynolds, Morgan Deters, Viktor Kuncak, Cesare Tinelli, and Clark Barrett Kumar Madhukar TCS Research, Pune Formal Methods Update Meet, IIT Mandi, 17-18 July, 2017


slide-1
SLIDE 1

Counterexample-Guided Quantifjer Instantiation for Synthesis in SMT

Andrew Reynolds, Morgan Deters, Viktor Kuncak, Cesare Tinelli, and Clark Barrett Kumar Madhukar

TCS Research, Pune Formal Methods Update Meet, IIT Mandi, 17-18 July, 2017

slide-2
SLIDE 2

Outline

▶ The Problem ▶ Restrictions ▶ Solutions

slide-3
SLIDE 3

The (Synthesis) Problem

▶ Synthesize a function that meets a given specifjcations. ▶ Example - Synthesize f such that:

▶ f (x1, x2) ≥ x1 ∧ ▶ f (x1, x2) ≥ x2 ∧ ▶ f (x1, x2) ≈ x1 ∨ f (x1, x2) ≈ x2

▶ Applicable in synthesis of functional programs, program sketching, synthesis of

reactive systems, etc.

slide-4
SLIDE 4

If P is a formula that encodes the specifjcation,

P[f, x1, x2] = f (x1, x2) ≥ x1 ∧ f (x1, x2) ≥ x2 ∧ (f (x1, x2) ≈ x1 ∨ f (x1, x2) ≈ x2)

then we must have

∀x1x2. P[f, x1, x2]

And the question that we are asking is

∃f. ∀x1x2. P[f, x1, x2]

slide-5
SLIDE 5

▶ Or, more generally,

∃f.

Exists a function s.t. ∀x1, x2, ...xn.P(f, x1, x2, ...xn)

  • for all ¯

x, P(f,¯ x) is true

▶ An SMT solver may treat f as an uninterpreted function, but the real challenge

here is the universal quantifjcation over ¯ x.

▶ The solver must construct (a fjnite representation of) an interpretation for f which

is true for all ¯ x .

slide-6
SLIDE 6

▶ In contrast, there are efgective techniques to show unsatisfjability of universally

quantifjed formulas.

▶ SMT solvers use instantiation-based methods - generate ground instances until a

refutation is found.

▶ Can we transform our problem into one of checking unsatisfjability?

If satisfjability (F) ⇒ validity (F), (F is sat) ⇔ (¬F is not valid) ⇔ (¬F is unsatisfjable)

slide-7
SLIDE 7

Restriction

  • 1. Satisfjability ⇒ Validity

▶ In other words, we will only consider theories that are satisfaction complete wrt the

formulas we are interested in.

▶ Most theories used in SMT (e.g. various theories of integers, reals, strings, algebraic

datatypes, bit-vectors, etc.) are satisfaction complete wrt the class of closed fjrst-order formulas.

slide-8
SLIDE 8

∃f . ∀¯ x . P(f,¯ x)

sat ↓ negate

¬ ∃f . ∀¯ x . P(f,¯ x) unsat

↓ push ¬

∀f . ∃¯ x . ¬ P(f,¯ x) unsat

▶ Another challenge: Negation introduces second-order universal quantifjcation

(over function f).

▶ What if we restrict ourselves to the class of synthesis problems

∃f . ∀¯ x . P[f,¯ x] , where every occurrence of f in P is of the form f(¯ x).

▶ In that case, we can transform the synthesis problem to: ∀¯

x . ∃y . Q[¯ x, y].

slide-9
SLIDE 9

Restrictions

  • 1. Satisfjability ⇒ Validity

▶ In other words, we will only consider theories that are satisfaction complete wrt the

formulas we are interested in

▶ Most theories used in SMT (e.g. various theories of integers, reals, strings, algebraic

datatypes, bit-vectors, etc.) are satisfaction complete wrt the class of closed fjrst-order formulas.

  • 2. P consists of single-invocation properties

f (x1, x2) ≥ x1 ∧ f (x1, x2) ≥ x2 ∧ (f (x1, x2) ≈ x1 ∨ f (x1, x2) ≈ x2) c(x1, x2) ≈ c(x2, x1)

slide-10
SLIDE 10

Recall

Synthesis conjecture:

∃f. ∀x1...xn. P[f, x1, ..., xn]

▶ avoid second-order quantifjcation, and ▶ solve an unsatisfjability (universal quantifjcation) problem instead of a satisfjability

  • ne.
slide-11
SLIDE 11

So far..

∃f . ∀¯ x . P(f,¯ x) sat

↓(single-invocation property)

∀¯ x . ∃g . P(g,¯ x) sat

↓(satisfaction-complete theory)

∀¯ x . ∃g . P(g,¯ x) valid

↓(negate)

¬∀¯ x . ∃g . P(g,¯ x) unsat

↓(push ¬)

∃¯ x . ∀g . ¬P(g,¯ x) unsat

slide-12
SLIDE 12

Our fjrst example

∃f. ∀x1x2.(f (x1, x2) ≥ x1 ∧ f (x1, x2) ≥ x2 ∧ (f (x1, x2) ≈ x1 ∨ f (x1, x2) ≈ x2)) sat

↓(single-invocation property)

∀x1x2. ∃g. (g ≥ x1 ∧ g ≥ x2 ∧(g ≈ x1 ∨ g ≈ x2)) sat

↓negate (satisfaction-complete theory)

∃x1x2. ∀g. (g < x1 ∨ g < x2 ∨(g ̸≈ x1 ∧ g ̸≈ x2)) unsat

↓Skolemize, for fresh a, b

∀g. (g < a ∨ g < b ∨(g ̸≈ a ∧ g ̸≈ b)) unsat

slide-13
SLIDE 13

Solving Max Example

g.(g<a  g<b (g≠a  g≠b))

Ground solver Quantifiers Module

slide-14
SLIDE 14

Solving Max Example

g.(g<a  g<b (g≠a  g≠b))

Quantifiers Module Ground solver

instances a/g, b/g (a<a  a<b (a≠a  a≠b)) (b<a  b<b (b≠a  b≠b))

slide-15
SLIDE 15

Solving Max Example

g.(g<a  g<b (g≠a  g≠b))

Quantifiers Module Ground solver

a<b  b<a  simplify

slide-16
SLIDE 16

Solving Max Example

g.(g<a  g<b (g≠a  g≠b))

Quantifiers Module unsat Ground solver

a<b  b<a   g.(g<a  g<b (g≠a  g≠b)) is unsatisfable, implies original synthesis conjecture has a solution

slide-17
SLIDE 17

How do we get solutions?

g.P(g,k)

Quantifiers Module Ground solver

f.x.P(f(x),x)

  • P(t1,k),…,P(tn,k)

instances

negate, translate to FO

unsat

  • P(t1,k),…,P(tn,k)|= false
slide-18
SLIDE 18

How do we get solutions?

g.P(g,k)

Quantifiers Module Ground solver

f.x.P(f(x),x)

  • P(t1,k),…,P(tn,k)

instances

negate, translate to FO

unsat

  • P(t1,k),…,P(tn,k)|= false

Claim the following is a solution for f:

  • lx. ite( P(t1,k), t1,

ite( P(t2,k), t2, … ite( P(tn-1,k), tn-1, tn)…)[x/k]

slide-19
SLIDE 19

Why is this a solution?

f.x.P(f(x),x)

  • P(t1,k),…,P(tn,k)|= false

Claim the following is a solution for f:

  • lx. ite( P(t1,k), t1,

ite( P(t2,k), t2, … ite( P(tn-1,k), tn-1, tn)…)[x/k] Given Found

slide-20
SLIDE 20

Why is this a solution?

f.x.P(f(x),x)

  • P(t1,k),…,P(tn,k)|= false

Claim the following is a solution for f:

  • lx. ite( P(t1,k), t1,

ite( P(t2,k), t2, … ite( P(tn-1,k), tn-1, tn)…)[x/k] Given Found

If P holds for t1, return t1

slide-21
SLIDE 21

Why is this a solution?

f.x.P(f(x),x)

  • P(t1,k),…,P(tn,k)|= false

Claim the following is a solution for f:

  • lx. ite( P(t1,k), t1,

ite( P(t2,k), t2, … ite( P(tn-1,k), tn-1, tn)…)[x/k] Given Found

If P holds for t2, return t2

slide-22
SLIDE 22

Why is this a solution?

f.x.P(f(x),x)

  • P(t1,k),…,P(tn,k)|= false

Claim the following is a solution for f:

  • lx. ite( P(t1,k), t1,

ite( P(t2,k), t2, … ite( P(tn-1,k), tn-1, tn)…)[x/k] Given Found

If P holds for tn-1, return tn-1

slide-23
SLIDE 23

Why is this a solution?

f.x.P(f(x),x)

  • P(t1,k),…,P(tn,k)|= false

Claim the following is a solution for f:

  • lx. ite( P(t1,k), t1,

ite( P(t2,k), t2, … ite( P(tn-1,k), tn-1, tn)…)[x/k] Given Found

Why does P(tn,k) hold?

slide-24
SLIDE 24

Solution for Max Example

f.xy.(f(x,y)≥x  f(x,y)≥y (f(x,y)=x  f(x,y)=y))

|= false

Claim the following is a solution for f:

  • lxy. ite( a≥a  a≥b (a=a  a=b), a,

b)…)[x/a][y/b] Given Found (a≥a  a≥b (a=a  a=b)),

  • (b≥a  b≥b (b=a  b=b))
slide-25
SLIDE 25

Solution for Max Example

f.xy.(f(x,y)≥x  f(x,y)≥y (f(x,y)=x  f(x,y)=y))

|= false

Claim the following is a solution for f:

  • lxy. ite( x≥x  x≥y (x=x  x=y), x,

y)…) Given Found (a≥a  a≥b (a=a  a=b)),

  • (b≥a  b≥b (b=a  b=b))
slide-26
SLIDE 26

Solution for Max Example

f.xy.(f(x,y)≥x  f(x,y)≥y (f(x,y)=x  f(x,y)=y))

|= false

Claim the following is a solution for f:

  • lxy. ite( x≥y , x, y )

Given Found (a≥a  a≥b (a=a  a=b)),

  • (b≥a  b≥b (b=a  b=b))
slide-27
SLIDE 27

Lifting the single-invocation property restriction

▶ Can we still refute negated synthesis conjectures? ▶ Yes, under syntactic restrictions.

slide-28
SLIDE 28

Example: Syntax-Guided Synthesis

▶ Syntactic restriction for the solution space, expressed by these algebraic datatypes:

S := t1 | t2 | zero | one | plus(S, S) | minus(S, S) | if (C, S, S) C := leq(S, S) | eq(S, S) | and(C, C) | not(C) And an interpretation of these datatypes in terms of the original theory.

  • 1. evS

Int Int Int : embedding S in Int.

  • 2. evC

Int Int Bool : embedding C in Bool.

slide-29
SLIDE 29

Example: Syntax-Guided Synthesis

▶ Syntactic restriction for the solution space, expressed by these algebraic datatypes:

S := t1 | t2 | zero | one | plus(S, S) | minus(S, S) | if (C, S, S) C := leq(S, S) | eq(S, S) | and(C, C) | not(C)

▶ And an interpretation of these datatypes in terms of the original theory.

  • 1. evS×Int×Int→Int : embedding S in Int.
  • 2. evC×Int×Int→Bool : embedding C in Bool.
slide-30
SLIDE 30

The evaluation operators

ev(t1, x, y) ≈ x ev(zero, x, y) ≈ 0 ev(not(c), x, y) ≈ ¬ev(c, x, y) ev(and(c1, c2), x, y) ≈ ev(c1, x, y) ∧ ev(c2, x, y) ev(plus(s1, s2), x, y) ≈ ev(s1, x, y) + ev(s2, x, y) ev(if (c, s1, s2), x, y) ≈ ite(ev(c, x, y), ev(s1, x, y), ev(s2, x, y))

slide-31
SLIDE 31

Another example P[c, x1, x2] = c(x1, x2) ≈ c(x2, x1)

▶ can be restated as follows, where g is a variable of type S:

Pev[g, x1, x2] = ev(g, x1, x2) ≈ ev(g, x2, x1)

▶ Now, instead of fjnding a witness for ∃c. ∀x1x2.P[c, x1, x2] we will determine the

unsatisfjability of ∃x1x2. ∀g.¬Pev[g, x1, x2].

slide-32
SLIDE 32

Positive Example : P[c, x1, x2] = c(x1, x2) ≈ c(x2, x1) Pev[g, x1, x2] = ev(g, x1, x2) ≈ ev(g, x2, x1)

Model Added Formula g t1 ev t1 a1 b1 ev t1 b1 a1 a1 1 b1 G ev g 1 0 ev g 0 1 g zero ev zero a2 b2 ev zero b2 a2 none

Solution: c x1 x2

slide-33
SLIDE 33

Positive Example : P[c, x1, x2] = c(x1, x2) ≈ c(x2, x1) Pev[g, x1, x2] = ev(g, x1, x2) ≈ ev(g, x2, x1)

Model Added Formula [g → t1] ev(t1, a1, b1) ̸≈ ev(t1, b1, a1) a1 1 b1 G ev g 1 0 ev g 0 1 g zero ev zero a2 b2 ev zero b2 a2 none

Solution: c x1 x2

slide-34
SLIDE 34

Positive Example : P[c, x1, x2] = c(x1, x2) ≈ c(x2, x1) Pev[g, x1, x2] = ev(g, x1, x2) ≈ ev(g, x2, x1)

Model Added Formula [g → t1] ev(t1, a1, b1) ̸≈ ev(t1, b1, a1) [a1 → 1, b1 → 0] G ⇒ ev(g, 1, 0) ≈ ev(g, 0, 1) g zero ev zero a2 b2 ev zero b2 a2 none

Solution: c x1 x2

slide-35
SLIDE 35

Positive Example : P[c, x1, x2] = c(x1, x2) ≈ c(x2, x1) Pev[g, x1, x2] = ev(g, x1, x2) ≈ ev(g, x2, x1)

Model Added Formula [g → t1] ev(t1, a1, b1) ̸≈ ev(t1, b1, a1) [a1 → 1, b1 → 0] G ⇒ ev(g, 1, 0) ≈ ev(g, 0, 1) [g → zero] ev(zero, a2, b2) ̸≈ ev(zero, b2, a2) none

Solution: c x1 x2

slide-36
SLIDE 36

Positive Example : P[c, x1, x2] = c(x1, x2) ≈ c(x2, x1) Pev[g, x1, x2] = ev(g, x1, x2) ≈ ev(g, x2, x1)

Model Added Formula [g → t1] ev(t1, a1, b1) ̸≈ ev(t1, b1, a1) [a1 → 1, b1 → 0] G ⇒ ev(g, 1, 0) ≈ ev(g, 0, 1) [g → zero] ev(zero, a2, b2) ̸≈ ev(zero, b2, a2) none

Solution: c x1 x2

slide-37
SLIDE 37

Positive Example : P[c, x1, x2] = c(x1, x2) ≈ c(x2, x1) Pev[g, x1, x2] = ev(g, x1, x2) ≈ ev(g, x2, x1)

Model Added Formula [g → t1] ev(t1, a1, b1) ̸≈ ev(t1, b1, a1) [a1 → 1, b1 → 0] G ⇒ ev(g, 1, 0) ≈ ev(g, 0, 1) [g → zero] ev(zero, a2, b2) ̸≈ ev(zero, b2, a2) none

Solution: c(x1, x2) = 0

slide-38
SLIDE 38

Negative Example: P[c, x1, x2] = c(x1, x2) ̸≈ c(x2, x1) Pev[g, x1, x2] = ev(g, x1, x2) ̸≈ ev(g, x2, x1)

Model Added Formula g t1 ev t1 a1 b1 ev t1 b1 a1 a1 0 b1 G ev g 0 0 ev g 0 0 none

No Solution

slide-39
SLIDE 39

Negative Example: P[c, x1, x2] = c(x1, x2) ̸≈ c(x2, x1) Pev[g, x1, x2] = ev(g, x1, x2) ̸≈ ev(g, x2, x1)

Model Added Formula g t1 ev t1 a1 b1 ev t1 b1 a1 a1 0 b1 G ev g 0 0 ev g 0 0 none

No Solution

slide-40
SLIDE 40

Negative Example: P[c, x1, x2] = c(x1, x2) ̸≈ c(x2, x1) Pev[g, x1, x2] = ev(g, x1, x2) ̸≈ ev(g, x2, x1)

Model Added Formula [g → t1] ev(t1, a1, b1) ≈ ev(t1, b1, a1) a1 0 b1 G ev g 0 0 ev g 0 0 none

No Solution

slide-41
SLIDE 41

Negative Example: P[c, x1, x2] = c(x1, x2) ̸≈ c(x2, x1) Pev[g, x1, x2] = ev(g, x1, x2) ̸≈ ev(g, x2, x1)

Model Added Formula [g → t1] ev(t1, a1, b1) ≈ ev(t1, b1, a1) [a1 → 0, b1 → 0] G ⇒ ev(g, 0, 0) ̸≈ ev(g, 0, 0) none

No Solution

slide-42
SLIDE 42

Negative Example: P[c, x1, x2] = c(x1, x2) ̸≈ c(x2, x1) Pev[g, x1, x2] = ev(g, x1, x2) ̸≈ ev(g, x2, x1)

Model Added Formula [g → t1] ev(t1, a1, b1) ≈ ev(t1, b1, a1) [a1 → 0, b1 → 0] G ⇒ ev(g, 0, 0) ̸≈ ev(g, 0, 0) none

No Solution

slide-43
SLIDE 43

Negative Example: P[c, x1, x2] = c(x1, x2) ̸≈ c(x2, x1) Pev[g, x1, x2] = ev(g, x1, x2) ̸≈ ev(g, x2, x1)

Model Added Formula [g → t1] ev(t1, a1, b1) ≈ ev(t1, b1, a1) [a1 → 0, b1 → 0] G ⇒ ev(g, 0, 0) ̸≈ ev(g, 0, 0) none

No Solution

slide-44
SLIDE 44

The procedure has following properties:

▶ Solution Soundness: Every term that it returns can be mapped to a solution of

the original synthesis conjecture ∃f .∀¯

  • x. P[f,¯

x].

▶ Refutation Soundness: If it does not fjnd a solution (up to a given length), the

  • riginal conjecture has no solution under the syntactic restrictions up to that

length.

▶ Solution Completeness: If the original synthesis conjecture has a solution under

these restrictions, the procedure will fjnd one.

slide-45
SLIDE 45

To conclude

▶ Refutation based approach for syntax-guided synthesis. ▶ Implemented in CVC4; winner in General and LIA tracks at SyGuS-Comp 2014. ▶ Single-invocation - appears to be restrictive but not quite so in practice; 176

benchmarks out of 243 at SyGuS-Comp 2014 were single-invocation.

slide-46
SLIDE 46

Thank you. Questions?