Extending ACL2 with SMT solvers Yan Peng & Mark Greenstreet - - PowerPoint PPT Presentation

extending acl2 with smt solvers
SMART_READER_LITE
LIVE PREVIEW

Extending ACL2 with SMT solvers Yan Peng & Mark Greenstreet - - PowerPoint PPT Presentation

Motivation Integration architecture Customizing Smtlink Summary and Future work Extending ACL2 with SMT solvers Yan Peng & Mark Greenstreet University of British Columbia October 2nd, 2015 Smtlink handles tedious details of proofs so you


slide-1
SLIDE 1

Motivation Integration architecture Customizing Smtlink Summary and Future work

Extending ACL2 with SMT solvers

Yan Peng & Mark Greenstreet

University of British Columbia

October 2nd, 2015 Smtlink handles tedious details of proofs so you can focus on the interesting parts.

1 / 24

slide-2
SLIDE 2

Motivation Integration architecture Customizing Smtlink Summary and Future work

Contents

1

Motivation AMS verification Examples Motivation

2

Integration architecture Architecture Interesting issues Soundness

3

Customizing Smtlink Customization interface Customizing Smtlink Our digital PLL proof example

4

Summary and Future work

2 / 24

slide-3
SLIDE 3

Motivation Integration architecture Customizing Smtlink Summary and Future work AMS verification Examples Motivation

The digital Phase-Locked Loop example[CNA10]

Linear Phase Control

ref

Φ ΦDCO/N

Fref

ΦDCO Bang−Bang Frequency Control PFD

+ −

dn up

Coarse Control Frequency

discarded v

DCO

φ

BBPFD

0:23 0:14 15:23 0:7

Σ

Fref

Σ DAC

c

÷N −

  • Center

code

  • A PLL is a feedback control system that, given an input

reference clock fref , it outputs a clock at a frequency fDCO that’s N times of the input clock frequency and aligned with the reference in phase. Analog/Mixed-Signal design are composed of both analog and digital circuits.

3 / 24

slide-4
SLIDE 4

Motivation Integration architecture Customizing Smtlink Summary and Future work AMS verification Examples Motivation

Modelling the digital PLL

The digital PLL is naturally modelled using non-linear recurrences that update the state variables on each rising edge

  • f φref .

c(i + 1) = nextc(c(i), v(i), φ(i)) v(i + 1) = nextv(c(i), v(i), φ(i)) φ(i + 1) = nextφ(c(i), v(i), φ(i))1

1Three state variables: capacitance setting c (digital), supply voltage v

(linear), phase correction φ (time-difference of digital transitions).

4 / 24

slide-5
SLIDE 5

Motivation Integration architecture Customizing Smtlink Summary and Future work AMS verification Examples Motivation

Modelling the digital PLL

In more details, c(i + 1) = saturate(c(i) + gc sgn(φ(i)), cmin, cmax) v(i + 1) = saturate(v(i) + gv(ccenter − c(i)), vmin, vmax) φ(i + 1) = wrap(φ(i) + (fdco(c(i), v(i)) − fref ) − gφφ(i)) fdco(c, v) =

1+αv 1+βc f0

saturate(x, lo, hi) = min(max(x, lo), hi) wrap(φ) = wrap(φ + 1), if φ ≤ −1 = φ, if −1 < φ < 1 = wrap(φ − 1), if 1 ≤ φ Turns out to be a relatively large system of non-linear arithmetic formulas.

4 / 24

slide-6
SLIDE 6

Motivation Integration architecture Customizing Smtlink Summary and Future work AMS verification Examples Motivation

Convergence

5 5 10 0.015 0.01 0.005 0.005 0.01 c1 c2 (2n1)

c (quantized) (continuous)

Requires reasoning about sequences of states. We want to show that each crossing of φ = 0 is closer to the

  • rigin than the previous one.

5 / 24

slide-7
SLIDE 7

Motivation Integration architecture Customizing Smtlink Summary and Future work AMS verification Examples Motivation

Example: polynomial inequalities

Do you sometimes find it frustrating to prove a theorem like this?

X

  • 3
  • 2
  • 1

1 2 3 y

  • 3
  • 2
  • 1

1 2 3 X 1 1.05 1.1 1.15 y

  • 0.1

0.1 0.2 0.3 0.4 0.5

1 (defthm poly-ineq-example-a 2

(implies (and (rationalp x) (rationalp y)

3

(<= (+ (* 4/5 x x) (* y y)) 1)

4

(<= (- (* x x) (* y y)) 1))

5

(<= y (- (* 3 (- x 17/8) (- x 17/8)) 3))))

6 / 24

slide-8
SLIDE 8

Motivation Integration architecture Customizing Smtlink Summary and Future work AMS verification Examples Motivation

Example: higher order polynomial inequalities

Maybe this? With a higher order term?

X

  • 3
  • 2
  • 1

1 2 3 y

  • 3
  • 2
  • 1

1 2 3 X 1 1.05 1.1 1.15 1.2 1.25 y

  • 0.1

0.1 0.2 0.3 0.4 0.5

1 (defthm poly-ineq-example-b 2

(implies (and (rationalp x) (rationalp y)

3

(<= (+ (* 2/3 x x) (* y y)) 1)

4

(<= (- (* x x) (* y y)) 1))

5

(<= y (+ 2 (- (* 4/9 x)) (- (* x x x x)) (* 1/4 x x x x x x)) )))

7 / 24

slide-9
SLIDE 9

Motivation Integration architecture Customizing Smtlink Summary and Future work AMS verification Examples Motivation

Example: exponential functions

Or even this one with exponential functions?

1 x z=0.5,n=3,m=2

  • 1

1 y

  • 1

0.5 0.4 0.3 0.2 0.1

  • 0.1
  • 0.2
  • 0.3

function

  • 1

x

  • 0.5

z=0.5,n=20,m=15 0.5 1 1

  • 1

#10-5 1 2 5 4 3 6

  • 1

7 y function

1 (defun ||x^2+y^2||^2 (x y) (+ (* x x) (* y y))) 2 (defthm poly-of-expt-example 3

(implies (and (rationalp x) (rationalp y) (rationalp z)

4

(integerp m) (integerp n)

5

(< 0 z) (< z 1) (< 0 m) (< m n))

6

(<= (* 2 (expt z n) x y)

7

(* (expt z m) (||x^2+y^2||^2 x y) ))))

8 / 24

slide-10
SLIDE 10

Motivation Integration architecture Customizing Smtlink Summary and Future work AMS verification Examples Motivation

Motivation

1 Motivation: provide better proof capabilities for AMS and

  • ther physical systems.

2 ACL2 provides extensive support for induction proofs and for

structuring large, complicated proofs.

3 Z3 has automatic procedures for solving arithmetic formulas.

No direct support for induction. Need to avoid “too much information” – important to give Z3 the relevant facts to keep the problems tractable.

9 / 24

slide-11
SLIDE 11

Motivation Integration architecture Customizing Smtlink Summary and Future work Architecture Interesting issues Soundness

Starting with a clause processor

Clause Processor

Original Clause G

SMT solver

^ ^ ^

… Clause returned by clause processor

C1 ^ C2 ^ ... ^ Cn ) G C1 C2 Cn Verified clause processor & trusted clause processor. We use a trusted clause processor for the integration. We utilize clauses C1, C2 ... Cn to get ACL2 to check many of the steps of our translation.

10 / 24

slide-12
SLIDE 12

Motivation Integration architecture Customizing Smtlink Summary and Future work Architecture Interesting issues Soundness

Two-step translation architecture

expanded clause

ACL2 (lisp)

to smt−py translate generate return clause simplify expand &

  • riginal

clause

ACL2 (lisp)

generate return clause Not(clause) satisfiable?

Z3

(python)

SMT clause step 2 translation

lisp (ACL2) python (z3)

(proven)

yes step 1 translation

  • riginal

expanded (implies expanded

  • riginal)

false ?

unsat

no

return

sat, unsat, unknown

  • r

acl2SMT

GSMT G G ′, A1, A2, ..., Am

A1 ∧ A2 ∧ ... ∧ Am ∧ (G ′ ⇒ G)

¬GSMT

First translation step: clause transformation Second translation step: transliteration

11 / 24

slide-13
SLIDE 13

Motivation Integration architecture Customizing Smtlink Summary and Future work Architecture Interesting issues Soundness

Extract type predicates

Clause Processor

Original Clause G

SMT solver

C1 = (T ∨ G) ∧ ((T ⇒ GT ) ⇒ G) C1 G T GT

Extract type predicates

ACL2 is not typed while Z3 is typed. It is common for the users to include type-recognizers in the hypotheses. We are currently translating rationalp in ACL2 into reals in Z3.

12 / 24

slide-14
SLIDE 14

Motivation Integration architecture Customizing Smtlink Summary and Future work Architecture Interesting issues Soundness

Extract type predicates

Clause Processor

Original Clause G

SMT solver

C1 = (T ∨ G) ∧ ((T ⇒ GT ) ⇒ G) C1 G T GT

Extract type predicates

G T GT

(implies (and (rationalp x) (rationalp y) (rationalp z) (integerp m) (integerp n) (< 0 z) (< z 1) (< 0 m) (< m n)) (<= (* 2 (expt z n) x y) (* (expt z m) (||x^2+y^2||^2 x y) ))) (and (rationalp x) (rationalp y) (rationalp z) (integerp m) (integerp n)) (implies (and (< 0 z) (< z 1) (< 0 m) (< m n)) (<= (* 2 (expt z n) x y) (* (expt z m) (||x^2+y^2||^2 x y) )))

12 / 24

slide-15
SLIDE 15

Motivation Integration architecture Customizing Smtlink Summary and Future work Architecture Interesting issues Soundness

Expand functions

Clause Processor

Original Clause G

SMT solver

^

C1 C2 G GF C2 = (Tfunc ∨ G) ∧ (GF ⇒ G)

Extract type predicates Expand functions

Functions are expanded into primitive functions. Recursive functions are expanded to a user specified level then replaced with a variable of appropriate type. Uninterpreted functions stay the same.

13 / 24

slide-16
SLIDE 16

Motivation Integration architecture Customizing Smtlink Summary and Future work Architecture Interesting issues Soundness

Expand functions

Clause Processor

Original Clause G

SMT solver

^

C1 C2 G GF C2 = (Tfunc ∨ G) ∧ (GF ⇒ G)

Extract type predicates Expand functions

Tfunc

(rationalp (||x^2+y^2||^2 x y))

((lambda (VAR1 VAR2) (+ (* VAR1 VAR1) (* VAR2 VAR2))) x y) (||x^2+y^2||^2 x y) function expansion function type clause

13 / 24

slide-17
SLIDE 17

Motivation Integration architecture Customizing Smtlink Summary and Future work Architecture Interesting issues Soundness

Revisit the expt proof

Let’s take a look at the expt theorem again:

1 (defun ||x^2+y^2||^2 (x y) (+ (* x x) (* y y))) 2 (defthm poly-of-expt-example 3

(implies (and (rationalp x) (rationalp y) (rationalp z)

4

(integerp m) (integerp n)

5

(< 0 z) (< z 1) (< 0 m) (< m n))

6

(<= (* 2 (expt z n) x y)

7

(* (expt z m) (||x^2+y^2||^2 x y) ))))

The reason that this is a theorem is because: 0 < z < 1 and 0 < m < n ⇒ 0 < zn < zm 2xy ≤ x2 + y2

14 / 24

slide-18
SLIDE 18

Motivation Integration architecture Customizing Smtlink Summary and Future work Architecture Interesting issues Soundness

Substitute subexpressions

Clause Processor

Original Clause G

SMT solver

^ ^

C3 = (Tsubs ∨ G) ∧ (GS ⇒ G) C1 C2 C3 G

Extract type predicates Expand functions Substitute subexpressions

GS The user can substitute subexpressions with variables.

15 / 24

slide-19
SLIDE 19

Motivation Integration architecture Customizing Smtlink Summary and Future work Architecture Interesting issues Soundness

Substitute subexpressions

Clause Processor

Original Clause G

SMT solver

^ ^

C3 = (Tsubs ∨ G) ∧ (GS ⇒ G) C1 C2 C3 G

Extract type predicates Expand functions Substitute subexpressions

GS

Tsubs

(expt z n) (expt z m) (and (rationalp (expt z m)) (rationalp (expt z n))) expt_z_m expt_z_n subexpression substitution subexpression types

15 / 24

slide-20
SLIDE 20

Motivation Integration architecture Customizing Smtlink Summary and Future work Architecture Interesting issues Soundness

User given hypotheses

Clause Processor

Original Clause G

SMT solver

^

C1

^

C3 G H

^

C4 C2 C4 = (H ∨ G) ∧ (GH ⇒ G)

Extract type predicates Expand functions Substitute subexpressions User given hypothesis

GH

The user can provide hypotheses about this theorem. The hypothesis feature conveys facts from the ACL2 world about these variables to the SMT solver.

16 / 24

slide-21
SLIDE 21

Motivation Integration architecture Customizing Smtlink Summary and Future work Architecture Interesting issues Soundness

User given hypotheses

Clause Processor

Original Clause G

SMT solver

^

C1

^

C3 G H

^

C4 C2 C4 = (H ∨ G) ∧ (GH ⇒ G)

Extract type predicates Expand functions Substitute subexpressions User given hypothesis

GH

;; given hypotheses in the theorem ((lambda (expt_z_n expt_z_m) (and (< expt_z_n expt_z_m) (< 0 expt_z_m) (< 0 expt_z_n))) (expt z n) (expt z m)) (and (< expt_z_n expt_z_m) (< 0 expt_z_m) (< 0 expt_z_n)) expt_z_m expt_z_n hypothesis clause added hypotheses

H

16 / 24

slide-22
SLIDE 22

Motivation Integration architecture Customizing Smtlink Summary and Future work Architecture Interesting issues Soundness

The expt proof

The transformed result clause G ′ becomes:

(lambda (expt_z_m expt_z_n) ;; bind substitution variables to their original expressions (implies (and (and (< 0 z) (< z 1) (< 0 m) (< m n)) (and (< expt_z_n expt_z_m) (< 0 expt_z_m) (< 0 expt_z_n))) (<= (* 2 expt_z_m x y) (* expt_z_n ((lambda (VAR1 VAR2) (+ (* VAR1 VAR1) (* VAR2 VAR2))) x y) ))) (expt z m) (expt z n)))

The returned clauses are respectively: T ∨ G, Tfunc ∨ G, Tsubs ∨ G and H ∨ G.

17 / 24

slide-23
SLIDE 23

Motivation Integration architecture Customizing Smtlink Summary and Future work Architecture Interesting issues Soundness

The expt proof

The clause processor hint:

1 :hints (("Goal" :clause-processor 2

(Smtlink clause

3

’((:expand ((:functions ((||x^2+y^2||^2 rationalp)))

4

(:expansion-levels 1)))

5

(:let ((expt_z_m (expt z m) rationalp)

6

(expt_z_n (expt z n) rationalp)))

7

(:hypothesize ((< expt_z_n expt_z_m)

8

(< 0 expt_z_m)

9

(< 0 expt_z_n)))))))

17 / 24

slide-24
SLIDE 24

Motivation Integration architecture Customizing Smtlink Summary and Future work Architecture Interesting issues Soundness

Trust a little, but not too much

Let G be the original clause, A be all auxiliary clauses generated during the first translation step and G ′ be the main clause after this step. Let GSMT be the transliteration result after the second translation step. Q1 and Q2 are the two sets of clauses returned to ACL2. Q1 = (G ′ ∧ A) ⇒ G Q2 = A ∨ G (1) Since we assume that the second translation step is sound, meaning GSMT ⇒ G ′, and the SMT solver proves GSMT, We conclude that G is a theorem.

18 / 24

slide-25
SLIDE 25

Motivation Integration architecture Customizing Smtlink Summary and Future work Customization interface Customizing Smtlink Our digital PLL proof example

Customization interface

1 (local 2

(progn

3

(defun my-smtlink-expt-config ()

4

(declare (xargs :guard t))

5

(change-smtlink-config *default-smtlink-config*

6

:dir-interface ;; SMT file directory

7

"../z3_interface"

8

:SMT-module ;; SMT module name

9

"RewriteExpt"

10

:SMT-class ;; SMT class name

11

"to_smt_w_expt"

12

))

13

(defattach smt-cnf my-smtlink-expt-config)))

The default Smtlink and the customizable Smtlink uses different trust tags.

19 / 24

slide-26
SLIDE 26

Motivation Integration architecture Customizing Smtlink Summary and Future work Customization interface Customizing Smtlink Our digital PLL proof example

Customizing Smtlink

As an example, we created a customized Smtlink that adds a partial theory of expt to Z3. (expt x 0) → 1 (expt 0 n) → 0, if n > 0 (expt x (+ n1 n2)) → (* (expt x n1) (expt x n2)) (expt x (* c n)) → (* (expt x n) (expt x n) . . . ) (< (expt x m) (expt x n)), if 1 < x and m < n ... This simplified the use of Smtlink to produce a simpler proof. The new proof is about half the length of the original.

20 / 24

slide-27
SLIDE 27

Motivation Integration architecture Customizing Smtlink Summary and Future work Customization interface Customizing Smtlink Our digital PLL proof example

An example from the digital Phase-Locked Loop proof

Definitions: B-term(h) =(1 − Kt)−h(µ 1 + α(d0 + dv) 1 + β(g1h + (equc v0)) − 1) B-sum(n) =

n

  • h=1

(B-term(h) + B-term(−h))

21 / 24

slide-28
SLIDE 28

Motivation Integration architecture Customizing Smtlink Summary and Future work Customization interface Customizing Smtlink Our digital PLL proof example

An example from the digital Phase-Locked Loop proof

Proof of B-term-neg and B-sum-neg using Smtlink:

1 (defthm B-term-neg 2

(implies (a-bunch-of-hypothesis)

3

(< (+ (B-term h v0 dv g1 Kt)

4

(B-term (- h) v0 dv g1 Kt)) 0))

5

:hints (("Goal"

6

:clause-processor

7

(smtlink-custom-config clause

8

(smt-std-hint "B-term-neg") )))

9

:rule-classes :linear)

10 11 (defthm B-sum-neg 12

(implies (a-bunch-of-hypothesis)

13

(< (B-sum 1 n-minus-2 v0 dv g1 Kt) 0))

14

:hints (("Goal" :in-theory (e/d (B-sum) (B-term)))))

21 / 24

slide-29
SLIDE 29

Motivation Integration architecture Customizing Smtlink Summary and Future work

Future work

Support better counter-example report

Fetch counter-example result from the SMT solver and interpret it into ACL2 constants. The clause processor can execute the counter-example to make sure they are indeed counter-examples.

Add bounded model checking ability

We can use the SMT solver to build a bounded model checker that can be called through the customizable Smtlink interface.

Typing with less typing

Type information can be extracted from define. type-alist may contain lemmas/facts that Smtlink can send to the SMT solver to help with proofs.

Explore other interesting applications

22 / 24

slide-30
SLIDE 30

Motivation Integration architecture Customizing Smtlink Summary and Future work

Summary

Smtlink handles tedious details of proofs so you can focus on the interesting parts. We have demonstrated Smtlink for AMS design verification. Other cyberphysical problems should benefit as well. Smtlink is designed to be extensible to support, for example:

  • ther domains, and using more of the SMT solver’s

capabilities.

23 / 24

slide-31
SLIDE 31

Motivation Integration architecture Customizing Smtlink Summary and Future work

Summary

Smtlink handles tedious details of proofs so you can focus on the interesting parts. It provides an architecture and examples for further research

  • n combining the complementary strengths of ACL2 and SMT

solvers.

Thank you! Questions or thoughts?

23 / 24

slide-32
SLIDE 32

Motivation Integration architecture Customizing Smtlink Summary and Future work

Bibliography

  • J. Crossley, E. Naviasky, and E. Alon, An energy-efficient

ring-oscillator digital pll, Custom Integrated Circuits Conference (CICC), 2010 IEEE, Sept 2010, pp. 1–4.

24 / 24

slide-33
SLIDE 33

Additional material Primitive functions Our digital PLL proof example - code

Primitive functions are: binary-+, unary--, binary-*, unary-/, equal, <, if, not, and lambda along with the constants t, nil, and arbitrary integer constants.

25 / 24

slide-34
SLIDE 34

Additional material Primitive functions Our digital PLL proof example - code

An example from the digital Phase-Locked Loop proof

Definition of B-term (I’ve removed guards and returns to save space):

1 (define B-term-expt (Kt nco) 2

(expt (gamma Kt) (- nco)))

3 4 (define B-term-rest (nco v0 dv g1) 5

(1- (* (mu) (/ (1+ (* *alpha* (+ v0 dv)))

6

(1+ (* *beta* (+ (* g1 nco) (equ-c v0))))))))

7 8 (define B-term (nco v0 dv g1 Kt) 9

(* (B-term-expt Kt nco) (B-term-rest nco v0 dv g1)))

26 / 24

slide-35
SLIDE 35

Additional material Primitive functions Our digital PLL proof example - code

An example from the digital Phase-Locked Loop proof

Definition of B-sum (I’ve removed guards and returns to save space):

1 (define B-sum (nco_lo nco_hi v0 dv g1 Kt) 2

:measure (if (and (integerp nco_hi) (integerp nco_lo)

3

(>= nco_hi nco_lo))

4

(1+ (- nco_hi nco_lo)) 0)

5

(if (and (integerp nco_hi) (integerp nco_lo) (>= nco_hi nco_lo))

6

(+ (B-term nco_hi v0 dv g1 Kt )

7

(B-term (- nco_hi) v0 dv g1 Kt)

8

(B-sum nco_lo (- nco_hi 1) v0 dv g1 Kt))

9

0))

26 / 24

slide-36
SLIDE 36

Additional material Primitive functions Our digital PLL proof example - code

An example from the digital Phase-Locked Loop proof

std-smt-hint:

1 (define smt-std-hint (clause-name) 2

:guard (stringp clause-name)

3

‘( (:expand ((:functions ( (B-term rationalp)

4

(B-term-expt rationalp)

5

(B-term-rest rationalp)

6

(dv0 rationalp)

7

...

8

(fdco rationalp)

9

(gamma rationalp)

10

(m rationalp)

11

(mu rationalp)))

12

(:expansion-level 1)))

13

(:uninterpreted-functions ((expt rationalp rationalp rationalp)))

14

(:python-file ,clause-name)))

26 / 24

slide-37
SLIDE 37

Additional material Primitive functions Our digital PLL proof example - code

An example from the digital Phase-Locked Loop proof

Proof of B-term-neg using Smtlink:

1 (defthm B-term-neg 2

(implies (and (integerp h) (<= 1 h) (< h (/ (* 2 g1)))

3

(hyp-macro g1 Kt v0 dv))

4

(< (+ (B-term h v0 dv g1 Kt) (B-term (- h) v0 dv g1 Kt)) 0))

5

:hints (

6

("Goal"

7

:in-theory (enable B-term B-term-expt B-term-rest mu equ-c gamma dv0)

8

:clause-processor

9

(smtlink-custom-config clause (smt-std-hint "B-term-neg") )))

10

:rule-classes :linear)

26 / 24

slide-38
SLIDE 38

Additional material Primitive functions Our digital PLL proof example - code

An example from the digital Phase-Locked Loop proof

Proof of B-sum-neg:

1 (defthm B-sum-neg 2

(implies (and (integerp n-minus-2)

3

(<= 1 n-minus-2)

4

(< n-minus-2 (/ (* 2 g1)))

5

(hyp-fn (list :v0 v0 :dv dv :g1 g1 :Kt Kt)))

6

(< (B-sum 1 n-minus-2 v0 dv g1 Kt) 0))

7

:hints (("Goal" :in-theory (e/d (B-sum) (B-term)))))

26 / 24