Reasoning with Nonlinear Formulas in Isabelle/HOL Wenda Li - - PowerPoint PPT Presentation

reasoning with nonlinear formulas in isabelle hol
SMART_READER_LITE
LIVE PREVIEW

Reasoning with Nonlinear Formulas in Isabelle/HOL Wenda Li - - PowerPoint PPT Presentation

Reasoning with Nonlinear Formulas in Isabelle/HOL Wenda Li University of Cambridge wl302@cam.ac.uk January 7, 2020 Joint work with Grant Passmore and Larry Paulson 1 / 36 Alfred Tarski (1930s): the first-order theory of real closed fields is


slide-1
SLIDE 1

Reasoning with Nonlinear Formulas in Isabelle/HOL

Wenda Li

University of Cambridge wl302@cam.ac.uk

January 7, 2020

Joint work with Grant Passmore and Larry Paulson 1 / 36

slide-2
SLIDE 2

Alfred Tarski (1930s): the first-order theory of real closed fields is complete and decidable. That is, we have a decision procedure for closed sentences like the following: ∃x ∈ R. ∀y ∈ R. ∃z ∈ R. xz − y2 < 0 ∧ x > 0.

2 / 36

slide-3
SLIDE 3

The Sturm-Tarski theorem (also known as Tarski’s theorem)

Given P, Q ∈ R[X],P = 0, a, b ∈ R, a < b and are not roots of P, TaQ(Q, P, a, b) = Var(SRemS(P, P′Q); a, b), where

TaQ(Q, P, a, b) =

  • x∈(a,b),P(x)=0

sgn(Q(x)),

◮ P′ is the first derivative of P, ◮ Var computes the sign variations, ◮ SRemS computes the signed remainder sequence.

Also, TaQ(1, P, a, b) computes the number of real roots of P within the interval (a, b) (i.e., Sturm’s theorem).

3 / 36

slide-4
SLIDE 4

To decide ∃x ∈ R. P(x) = 0 ∧ Q1(x) > 0

Let c(Q1 ⊲ ⊳1 0, · · · , Qn ⊲ ⊳n 0) = card({x | P(x) = 0 ∧ Q1(x) ⊲ ⊳1 0 ∧ · · · ∧ Qn(x) ⊲ ⊳n 0}) , where ⊲ ⊳i∈ {<, >, =}, and TaQP(Qi) = TaQ(Qi, P, −∞, +∞). We have ∃x ∈ R. P(x) = 0 ∧ Q1(x) > 0 ⇐ ⇒ c(Q1 > 0) > 0, while c(Q1 > 0) can be found by solving the following linear equation:   1 1 1 1 −1 1 1     c(Q1 = 0) c(Q1 > 0) c(Q1 < 0)   =   TaQP(1) TaQP(Q1) TaQP(Q2

1)

  .

4 / 36

slide-5
SLIDE 5

The number of linear equations grows very quickly.

∃x ∈ R. P(x) = 0∧Q1(x) > 0∧Q2(x) < 0 ⇐ ⇒ c(Q1 > 0, Q2 < 0) > 0, requires us to solve a system with 9 equations:

    1 1 1 1 −1 1 1   ⊗   1 1 1 1 −1 1 1             c(Q1 = 0, Q2 = 0) c(Q1 = 0, Q2 > 0) · · · c(Q1 > 0, Q2 < 0) · · · c(Q1 < 0, Q2 < 0)         =         TaQP(1) TaQP(Q2) · · · TaQP(Q1Q2

2)

· · · TaQP(Q2

1Q2 2)

       

where ⊗ is tensor product.

5 / 36

slide-6
SLIDE 6

Tarski’s elimination procedure is mostly of theoretical interest

Univariate case: exponential in the number of polynomials General case: non-elementary in the number of variables Due to its elegance, Tarski’s elimination procedure has been implemented in Coq1, HOL Light2 and PVS3.

1Mahboubi and Cohen, “Formal proofs in real algebraic geometry: from

  • rdered fields to quantifier elimination”.

2Nieuwenhuis, CADE-20: 20th International Conference on Automated

Deduction, proceedings.

3Narkawicz, Mu˜

noz, and Dutle, “Formally-Verified Decision Procedures for Univariate Polynomial Computation Based on Sturm’s and Tarski’s Theorems.”

6 / 36

slide-7
SLIDE 7

Can we have a more practical procedure? George E. Collins (1976): Yes, here is cylindrical algebraic decomposition (CAD).

7 / 36

slide-8
SLIDE 8

What is cylindrical algebraic decomposition (CAD)

x1 x2

( √ 2, 1) (− √ 2, 1) √ 3 − √ 3 (− √ 3, 3

2)

P1 P2

D1,1 = {(x1, x2) | x1 < − √ 3 ∧ x2 < x2

1/2}

D1,2 = {(x1, x2) | x1 < − √ 3 ∧ x2 = x2

1/2}

D1,3 = {(x1, x2) | x1 < − √ 3 ∧ x2 > x2

1/2}

D2,1 = {(x1, x2) | x1 = − √ 3 ∧ x2 < 0} D2,2 = {(x1, x2) | x1 = − √ 3 ∧ x2 = 0} . . . D9,2 = {(x1, x2) | x1 > √ 3 ∧ x2 = x2

1/2}

D9,3 = {(x1, x2) | x1 > √ 3 ∧ x2 > x2

1/2}

Here, P1(x1, x2) = x2

2 + x2 1 − 3 and P2(x1, x2) = x2 − x2 1/2.

8 / 36

slide-9
SLIDE 9

What is cylindrical algebraic decomposition (CAD)

x1 x2

( √ 2, 1) (− √ 2, 1) √ 3 − √ 3 (− √ 3, 3

2)

P1 P2

D1,1 = {(x1, x2) | x1 < − √ 3 ∧ x2 < x2

1/2}

D1,2 = {(x1, x2) | x1 < − √ 3 ∧ x2 = x2

1/2}

D1,3 = {(x1, x2) | x1 < − √ 3 ∧ x2 > x2

1/2}

D2,1 = {(x1, x2) | x1 = − √ 3 ∧ x2 < 0} D2,2 = {(x1, x2) | x1 = − √ 3 ∧ x2 = 0} . . . D9,2 = {(x1, x2) | x1 > √ 3 ∧ x2 = x2

1/2}

D9,3 = {(x1, x2) | x1 > √ 3 ∧ x2 > x2

1/2}

Here, P1(x1, x2) = x2

2 + x2 1 − 3 and P2(x1, x2) = x2 − x2 1/2.

9 / 36

slide-10
SLIDE 10

What is cylindrical algebraic decomposition (CAD)

x1 x2

( √ 2, 1) (− √ 2, 1) √ 3 − √ 3 (− √ 3, 3

2)

P1 P2

D1,1 = {(x1, x2) | x1 < − √ 3 ∧ x2 < x2

1/2}

D1,2 = {(x1, x2) | x1 < − √ 3 ∧ x2 = x2

1/2}

D1,3 = {(x1, x2) | x1 < − √ 3 ∧ x2 > x2

1/2}

D2,1 = {(x1, x2) | x1 = − √ 3 ∧ x2 < 0} D2,2 = {(x1, x2) | x1 = − √ 3 ∧ x2 = 0} . . . D9,2 = {(x1, x2) | x1 > √ 3 ∧ x2 = x2

1/2}

D9,3 = {(x1, x2) | x1 > √ 3 ∧ x2 > x2

1/2}

Here, P1(x1, x2) = x2

2 + x2 1 − 3 and P2(x1, x2) = x2 − x2 1/2.

10 / 36

slide-11
SLIDE 11

What is cylindrical algebraic decomposition (CAD)

x1 x2

( √ 2, 1) (− √ 2, 1) √ 3 − √ 3 (− √ 3, 3

2)

P1 P2

D1,1 = {(x1, x2) | x1 < − √ 3 ∧ x2 < x2

1/2}

D1,2 = {(x1, x2) | x1 < − √ 3 ∧ x2 = x2

1/2}

D1,3 = {(x1, x2) | x1 < − √ 3 ∧ x2 > x2

1/2}

D2,1 = {(x1, x2) | x1 = − √ 3 ∧ x2 < 0} D2,2 = {(x1, x2) | x1 = − √ 3 ∧ x2 = 0} . . . D9,2 = {(x1, x2) | x1 > √ 3 ∧ x2 = x2

1/2}

D9,3 = {(x1, x2) | x1 > √ 3 ∧ x2 > x2

1/2}

such that

  • D = R2

∀X ∈ D. ∀Y ∈ D. X = Y → X ∩ Y = ∅ and both P1(x1, x2) = x2

2 + x2 1 − 3 and P2(x1, x2) = x2 − x2 1/2 have

constant sign over every X ∈ D (or {P1, P2} is adapted to D)

11 / 36

slide-12
SLIDE 12

x1 x2

(−2, 0) ∈ D1,1 (−2, 2) ∈ D1,2 (−2, 2.5) ∈ D1,3 (− √ 3, −1) ∈ D2,1 (− √ 3, 0) ∈ D2,2 . . . (2, 2) ∈ D9,2 (2, 2.5) ∈ D9,3

Let S = {(−2, 0), (−2, 2), (−2, 2.5), · · · , (2, 2), (2, 2.5)}. Sentences like the following can be decided: ∀x1x2. P1(x1, x2) = 0 ∧ P2(x1, x2) > 0 ⇐ ⇒ ∀(x1, x2) ∈ S. P1(x1, x2) = 0 ∧ P2(x1, x2) > 0

12 / 36

slide-13
SLIDE 13

Definition (Stack)

A stack D = {D1, D2, . . . , D2k+1} over a connected S ⊆ Rn is a decomposition of the cylinder S × R such that

◮ there is a sequence of continuous functions

f0, f1, . . . , fk+1 : S − → R, such that f0(x) < f1(x) < · · · < fk+1(x) for all x ∈ S, f0(x) = −∞, fk+1(x) = +∞,

◮ D2i+1 = {(x, x′) ∈ S × R | fi(x) < x′ < fi+1(x)}, for

i = 0, 1, . . . , k,

◮ D2i = {(x, x′) ∈ S × R | x′ = fi(x)}, for i = 1, 2, . . . , k.

13 / 36

slide-14
SLIDE 14

Example of a stack

x1 x2 (− √ 2, 1) ( √ 2, −1) Let

S =] − √ 2, √ 2[, f1(x) = −

  • 3 − x2,

f2(x) = x2/2, f3(x) =

  • 3 − x2.

A stack decomposes S × R:

D1 = {(x1, x2) | x1 ∈ S ∧ x2 < f1(x1)} D2 = {(x1, x2) | x1 ∈ S ∧ x2 = f1(x1)} D3 = {(x1, x2) | x1 ∈ S ∧ f1(x1) < x2 < f2(x2)} . . . D7 = {(x1, x2) | x1 ∈ S ∧ x2 > f3(x)}

14 / 36

slide-15
SLIDE 15

Definition (Cylindrical)

A decomposition D of Rn is cylindrical if

◮ n = 1, D decomposes R: there exist a finite number of points

ai ∈ R for 1 ≤ i ≤ k, such that ai < ai+1 (1 ≤ i ≤ k − 1) and D = {(−∞, a1), {a1}, (a1, a2), {a2}, . . . , (ak−1, ak), {ak}, (ak, ∞)}.

◮ n > 1, there exists a cylindrical decomposition D′ of Rn−1

such that over each X ∈ D′ there is a stack t(X) and D =

  • X∈D′

t(X).

15 / 36

slide-16
SLIDE 16

Theorem (Delineability)

Let P ⊆ R[x1, . . . , xn−1][xn] be a set of polynomials and C be a connected subset of Rn−1. If

  • 1. for every P ∈ P, the total number of complex roots (counting

multiplicities) of P(β, x) is constant as β varies over C, where P(β, x) is a univariate polynomial in which the variables x1, . . . , xn−1 are instantiated by β ∈ Rn−1,

  • 2. for every P ∈ P, the number of distinct complex roots of

P(β, x) is constant as β varies over C,

  • 3. for every P, Q ∈ P, the total number of common complex

roots (counting multiplicities) of P(β, x) and Q(β, x) is constant as β varies over C, then the total number of distinct real roots of ( P)(β, x) is constant as β varies over C.

16 / 36

slide-17
SLIDE 17

Require: a finite set of polynomials P ⊆ R[x1, . . . , xn] Ensure: Return a set of sample points Sn ⊆ Rn from a CAD that is adapted to P

1: procedure CAD(P) 2:

Pn ← P

3:

for i = n to 2 do ⊲ Projection phase, where Pi ⊆ R[x1, . . . , xi]

4:

Pi−1 ← proj(Pi)

5:

end for

6:

S1 ← base(P1) ⊲ Base case, where base(Q) returns a set

  • f sample points adapted to Q ⊆ R[x]

7:

for i = 1 to n − 1 do ⊲ Lifting phase, where Si ⊆ Ri

8:

Si+1 ←

β∈Si({β} × base(Pi+1(β, x)))

9:

end for

10:

return Sn

11: end procedure

17 / 36

slide-18
SLIDE 18

Given P = {x2

2 + x2 1 − 3, x2 − x2 1/2},

proj(P) = {x4

1/4 + x2 1 − 3, 4x2 1 − 12, 2, 1}

S1 = base(proj(P)) = {−2, − √ 3, −3 2, − √ 2, 0, √ 2, 3 2, √ 3, 2}. We start to lift: P(−2, x2) = {x2

2 + 1, x2 − 2}

base(P(−2, x2)) = {0, 2, 2.5} {−2} × base(P(−2, x2)) = {(−2, 0), (−2, 2), (−2, 2.5)} . . . 2 × base(P(2, x2)) = {(2, 0), (2, 2), (2, 2.5)} combining which yields S2 =

  • β∈S1

({β} × base(P(β, x))) = {(−2, 0), (−2, 2), (−2, 2.5), (− √ 3, −1), · · · , (2, 2.5)},

18 / 36

slide-19
SLIDE 19

Real algebraic numbers

To encode an real algebraic number α, we can use a polynomial P ∈ Q[x] and two rational numbers a, b ∈ Q: α = (P, a, b), so that α is the only root of P within the interval (a, b). For example, √ 2 = (x2 − 2, 0, 2). They are closed under normal arithmetic: (x2 − 2, 0, 2) + (x2 − 3, 0, 2) = (x4 − 10x2 + 1, 1, 4) (x2 − 2, 0, 2) × (x2 − 3, 0, 2) = (x2 − 6, 1, 4)

19 / 36

slide-20
SLIDE 20

Exact algebraic arithmetic is too slow

Exact algebraic arithmetic has been implemented in Isabelle/HOL45 and Coq6. The implementation by Joosten, Thiemann and Yamada is arguably the most efficient one (with 70K LOC in Isabelle/HOL), and it takes 20s to compute 6

i=1

3

√ i. Even Mathematica7 fails to give an awnser to 7

i=1

3

√ i within 30m.

4Joosten, Thiemann, and Yamada, “A Verified Implementation of Algebraic

Numbers in Isabelle/HOL”.

5Li and Paulson, “A modular, efficient formalisation of real algebraic

numbers”.

6Cohen, “Construction of Real Algebraic Numbers in Coq.” 7RootReduce[Sum[Surd[i, 3], i, 1, 7]] on Mathematica 12 20 / 36

slide-21
SLIDE 21

Sign determination using only rational arithmetic

The Sturm-Tarski theorem provides a way to effectively compute the sign of a univariate polynomial at a real algebraic point: sgn(Q(α)) =

  • x∈(a,b),P(x)=0

sgn(Q(x)) = TaQ(Q, P, a, b) = Var(SRemS(P, P′Q); a, b). where P, Q ∈ Q[x] and α = (P, a, b). For example,

value "sgn at [:-1,1:] (Alg [:-2,0,1:] 1 2)"

which stands for the sign of (x − 1)[x → √ 2] and returns 1.

21 / 36

slide-22
SLIDE 22

To prove ∀x. x2 − 2 > 0 ∨ x < 2,

Let Q = {x2 − 2, x − 2}, with a root isolation procedure we can find all real roots of Q: {− √ 2, √ 2, 2}, and construct sample points: {−2, − √ 2, 0, √ 2, 3 2, 2, 3}. Do we want to isolate (find) roots within Isabelle? Nah, it is easier to check a root than finding it.

22 / 36

slide-23
SLIDE 23

To prove ∀x. x2 − 2 > 0 ∨ x < 2,

∀x.Q1(x) > 0 ∨ Q2(x) < 0 ⇐ = {Pick {− √ 2, √ 2, 2} from an unstructed computer algebra system} {− √ 2, √ 2, 2} are all the roots of Q1 and Q2 ∧ ∀x ∈ {−2, − √ 2, 0, √ 2, 3 2, 2, 3}.Q1(x) > 0 ∨ Q2(x) < 0 ⇐ ⇒

  • α∈{−

√ 2, √ 2,2}

  • Q∈{Q1,Q2}

sgn(Q(α)) = TaQ(1, Q1, −∞, ∞) +TaQ(1, Q2, −∞, ∞) ∧ ∀x ∈ {−2, − √ 2, 0, √ 2, 3 2, 2, 3}.Q1(x) > 0 ∨ Q2(x) < 0

23 / 36

slide-24
SLIDE 24

To prove ∀x. x2 − 2 > 0 ∨ x < 2,

Here, [− √ 2, √ 2, 2] ( encoded as [Arep [:-2,0,1:] -2 0, Arep

[:-2,0,1:] 1 1.5, Rat 2]) has been found automatically by

external solvers.

24 / 36

slide-25
SLIDE 25

To prove ∃x. x2 = 2 ∧ x3 > 2.5

Proving the existential case is even easier as we only need one witness:

25 / 36

slide-26
SLIDE 26

Promising results8 compared to Tarski’s elimination procedure

Time (s) Formula univ rcf (Isabelle) univ rcf cert (Isabelle) tarski (PVS) ex1 0.9 0.3 2.0 ex2 1.4 0.6 6.8 ex3 1.6 0.7 13.0 ex4 1.3 0.5 20.1 ex5 1.6 0.6 315.7 ex6 5.6 3.9 timeout ex7 38.4 34.9 timeout

Note: timeout indicates failure to terminate within 24 hours

8Li, Passmore, and Paulson, “Deciding Univariate Polynomial Problems

Using Untrusted Certificates in Isabelle/HOL”.

26 / 36

slide-27
SLIDE 27

Towards multivariate CAD: multivariate sign determination

Previous univariate sign determination procedure require arithmetic in Q(α) (e.g. α = √ 2). We convert arithmetic in Q(α) to polynomial arithmetic in Q[α] where α is a symbolic indeterminate with some constraint (e.g. α2 = 2). To eliminate arithmetic in Q(α) when calculating TaQ: degx(Q) = deg(Q[y → α]) degx(P) = deg(P[y → α]) P[y → α] pmod

arithmetic in Q(α)

Q[y → α] = (P pmod

arithmetic in Q

Q)[y → α] where pmod is pseudo-division of polynomials.

27 / 36

slide-28
SLIDE 28

Bivariate sign determination procedure using only rational arithmetic

We finish the bivariate sign determination procedure:

value "bsgn at [:[:0,-1:],[:1:]:] (Alg [:-2,0,1:] 1 2) (Alg [:-3,0,1:] 1 2)"

which stands for the sign of (x − y)[x → √ 2, y → √ 3] and returns

  • 1.

28 / 36

slide-29
SLIDE 29

Root isolation with real algebraic coefficient?

P ⊆ Q[x1, · · · , xn] P1, · · · , Pn such that Pk ⊆ Q[x1, · · · , xk] S1, · · · , Sn such that Sk ⊆ ˜ Qk Projection Base & Lifting Here, ˜ Q is the real closure of Q. In the base and lifting phase, we may need to root-isolate polynomials like √ 2x2 − 3x + 1.

29 / 36

slide-30
SLIDE 30

Again, we want to use certificates

There are efficient algorithms to isolate roots with algebraic coefficients91011, but none of them is easy to implement (and certify) in a proof assistant. With a multivariate sign determination procedure, we can efficiently check that S1, · · · , Sn are indeed sample points drawn from cells described by P1, · · · , Pn.

9Moura and Passmore, “Computation in Real Closed Infinitesimal and

Transcendental Extensions of the Rationals.”

10Strzebo´

nski, “Cylindrical Algebraic Decomposition using validated numerics”.

11Boulier et al., “Real root isolation of regular chains”. 30 / 36

slide-31
SLIDE 31

Towards certifying the projection

The proof relies on that polynomial roots continuously depend on the coefficients, which was further derived by Rouch´ e’s theorem12.

12Li and Paulson, “A formal proof of Cauchy’s residue theorem”. 31 / 36

slide-32
SLIDE 32

What’s left for multivariate CAD

In general, we decided to fully certify the projection phase and deal with base & lifting in a certificate-based way. The undergoing formalisation efforts are:

◮ multivariate sign determination ◮ multivariate subresultants (univariate ones are already

available13) Still, costly algebraic arithmetic has been avoided!

13Joosten, Thiemann, and Yamada, “Subresultants”. 32 / 36

slide-33
SLIDE 33

Remarks

Formalisation is time consuming – we may want to use certificates if possible. Many objects and sub-procedures in computer algebra are already in the Archive of Formal Proofs:

◮ executable multivariate polynomials ◮ procedures to count real or complex roots of a polynomial ◮ subresultants ◮ polynomial factorisation ◮ Gr¨

  • bner bases

◮ ODE ◮ · · ·

We can expect more verified computation in proof assistants.

33 / 36

slide-34
SLIDE 34

Boulier, Fran¸ cois et al. “Real root isolation of regular chains”. In: Computer Mathematics. Springer, 2014, pp. 33–48. Cohen, Cyril. “Construction of Real Algebraic Numbers in Coq.” In: Proceedings of the 3rd International Conference on Interactive Theorem Proving, ITP 2012. Ed. by Lennart Beringer and Amy Felty. Berlin, Heidelberg: Springer Berlin Heidelberg, 2012, pp. 67–82. Joosten, Sebastiaan, Ren Thiemann, and Akihisa Yamada. “Subresultants”. In: Archive of Formal Proofs (Apr. 2017). http://isa-afp.org/entries/Subresultants.html, Formal proof development. issn: 2150-914x. Joosten, Sebastiaan JC, Ren´ e Thiemann, and Akihisa Yamada. “A Verified Implementation of Algebraic Numbers in Isabelle/HOL”. In: Journal of automated reasoning (2018), pp. 1–27.

34 / 36

slide-35
SLIDE 35

Li, Wenda, Grant Olney Passmore, and Lawrence C Paulson. “Deciding Univariate Polynomial Problems Using Untrusted Certificates in Isabelle/HOL”. In: Journal of Automated Reasoning 44.3 (Aug. 2017), pp. 175–23. Li, Wenda and Lawrence C Paulson. “A formal proof of Cauchy’s residue theorem”. In: Proceedings of the 4th International Conference on Interactive Theorem Proving, ITP 2013. Ed. by Jasmin Christian Blanchette and Stephan Merz. Nancy, France: Springer, Aug. 2016, pp. 235–251. – .“A modular, efficient formalisation of real algebraic numbers”. In: Proceedings of the 5th ACM SIGPLAN Conference on Certified Programs and Proofs, CPP 2016. Ed. by Jeremy Avigad and Adam Chlipala. St. Petersburg, FL, USA: ACM, Jan. 2016, pp. 66–75. Mahboubi, Assia and Cyril Cohen. “Formal proofs in real algebraic geometry: from ordered fields to quantifier elimination”. In: Logical Methods in Computer Science 8.1 (2012).

35 / 36

slide-36
SLIDE 36

Moura, Leonardo de and Grant Olney Passmore. “Computation in Real Closed Infinitesimal and Transcendental Extensions of the Rationals.” In: Proceedings of the 24th International Conference on Automated Deduction, CADE ’13. Berlin, Heidelberg: Springer Berlin Heidelberg, 2013, pp. 178–192. Narkawicz, Anthony, C´ esar A Mu˜ noz, and Aaron Dutle. “Formally-Verified Decision Procedures for Univariate Polynomial Computation Based on Sturm’s and Tarski’s Theorems.” In: Journal of Automated Reasoning 54.4 (2015), pp. 285–326. Nieuwenhuis, Robert, ed. CADE-20: 20th International Conference

  • n Automated Deduction, proceedings. Tallinn, Estonia:

Springer-Verlag, 2005. Strzebo´ nski, Adam W. “Cylindrical Algebraic Decomposition using validated numerics”. In: Journal of Symbolic Computation 41.9 (Sept. 2006), pp. 1021–1038.

36 / 36