Computation in Real Closed Infinitesimal and Transcendental Extensions of the Rationals Leonardo de Moura Grant Passmore What? 2+ 3 3 Infinitesimal 1 3 2 3 4 − + = 9 9 9 3 3 1+π 100 > 10 π2 2−1 Transcendental π+π <π FindRoots (1 − 2 π₯ 2 − ππ₯ 3 + π 2 π₯ 5 ) Real Closed Fields Ordered Field Positive elements are squares ∀π₯ π₯ ≥ 0 ⇒ ∃π¦ π₯ = π¦ 2 All polynomials of odd degree have roots ∀π0 … π2π ∃π₯ π₯ 2π+1 + π2π π₯ 2π + … . +π1 π₯ + π0 = 0 ⊆ β βπππ Real Algebraic Numbers 0, 1, 1 3 , 2, − 3, ππππ‘ −1 − π₯ + π₯ 5 , 1,2 5 ,… Real Closed Fields ⊆ β βπππ = β Real Closure of the Rational Numbers Real Closed Fields … , 2, 3 π, ,… ⊆ β Field extension πΎ, πΎ = β(π) ⊆ ππππ‘ − π − π₯ + π₯ 5 , 1,2 βπππ = β 1, 1 3 , π, π + 1, π2 + 1 ,… 2 Real Closed Fields ⊆ β ⊆ πΎ1 , πΎ1 = β(π)(π) ⊆ πΎ, πΎ = β(π) βπππ = β 1, π, π + π, π2 + π ,… 2 Real Closed Fields β β πΎ2 , πΎ2 = β(π)(π)(π) ⊆ ⊆ Hyperreals ⊆ πΎ1 , πΎ1 = β(π)(π) ⊆ πΎ, πΎ = β(π) βπππ = β Infinitesimal Real Closed Fields β β πΎ2 , πΎ2 = β(π)(π)(π) ⊆ ⊆ Hyperreals ⊆ πΎ1 , πΎ1 = β(π)(π) ⊆ πΎ, πΎ = β(π) βπππ = β Infinitesimal Why? NLSat: Nonlinear Arithmetic Solver (∃RCF) IJCAR 2012 (joint work with Dejan Jovanovic) Also relevant for any CAD-based procedure, and model generating solvers NLSat bottlenecks: • Real algebraic number computations • Subresultant computations NLSat π₯2 − 2 = 0 π¦2 − π₯ + 1 < 0 Decide π₯ → − 2 NLSat π₯2 − 2 = 0 π¦2 − π₯ + 1 < 0 Decide π₯ → − 2 There is no π¦ s.t. π¦ 2 + 2 + 1 < 0 NLSat π₯2 − 2 = 0 π¦2 − π₯ + 1 < 0 Decide π₯ → − 2 There is no π¦ s.t. π¦ 2 + 2 + 1 < 0 Conflict resolution (and backtrack) π¦ 2 − π₯ + 1 < 0 implies π₯ > 1 NLSat π₯2 − 2 = 0 π¦2 − π₯ + 1 < 0 π₯>1 Decide π₯ → 2 Decide π¦ → −1/2 NLSat Example: 216 π₯ 15 + 4536 π₯ 14 + 31752 π₯ 13 − 520884 π₯ 12 − 42336 π₯ 11 − 259308 π₯ 10 + 3046158 π₯ 9 + 140742 π₯ 8 + 756756π₯ 7 − 5792221π₯ 6 − 193914π₯ 5 − 931392 π₯ 4 + 3266731π₯ 3 + 90972π₯ 2 + 402192 π₯ + 592704 π¦ 5 − π¦ + (π₯ 3 +1) Before: timeout (old package used Resultant theory) After: 0.05 secs NLSat + Transcendental constants Nonlinear Arithmetic Solver Transcendental Constants (e.g., MetiTarski) π₯2 − π = 0 π¦2 − π₯ + 1 < 0 Exact Nonlinear Optimization (on demand) Find smallest π¦ s.t. πΉ π¦, π₯ Output: unsat unbounded minimum(π) infimum(π) Exact Nonlinear Optimization (on demand) Find smallest π¦ s.t. πΉ π¦, π₯ Observation 1: Univariate πΉ[π¦] case is easy Inefficient solution: ∃π₯, πΉ[π¦, π₯] Exact Nonlinear Optimization (on demand) Find smallest π¦ s.t. πΉ π¦, π₯ Observation 2: Adapt NLSat for solving the satisfiability modulo assignment problem. Satisfiability Modulo Assignment (SMA) Given πΉ π¦, π₯ and π¦ → πΌ Output: sat π¦ → πΌ, π₯ → π½ satisfies πΉ π¦, π₯ unsat(π[π¦]) πΉ π¦, π₯ implies π[π¦] and π[πΌ] is false No-good sampling πΆβπππ πΉ π¦, π₯ , π¦ → πΌ1 = unsat π1 π¦ , πΊ1 = π1 [π¦], πΌ2 ∈ πΊ1 , πΆβπππ πΉ π¦, π₯ , π¦ → πΌ2 = unsat π2 π¦ , πΊ2 = πΊ1 ∧ π2 [π¦], πΌ3 ∈ πΊ2 , πΆβπππ πΉ π¦, π₯ , π¦ → πΌ3 = unsat π3 π¦ , πΊ3 = πΊ2 ∧ π3 [π¦], … πΌπ ∈ πΊπ−1 , πΆβπππ πΉ π¦, π₯ , π¦ → πΌπ πΊπ−1 ∧ ππ [π¦], … Finite decomposition property: The sequence is finite = unsat ππ π¦ , πΊπ = πΊπ approximates ∃π₯, πΉ[π¦, π₯] Exact Nonlinear Optimization (on demand) Univariate minimization −∞ Related Work Transcendental constants MetiTarski Interval Constraint Propagation (ICP) RealPaver, Rsolver, iSat, dReal Reasoning with Infinitesimals ACL2, Isabelle/HOL Nonstandard analysis Real Closure of a Single Infinitesimal Extension [Rioboo] Puiseux series Coste-Roy: encoding algebraic elements using Thom’s lemma Our approach Tower of extensions Hybrid representation Interval (arithmetic) + Thom’s lemma Clean denominators Non-minimal defining polynomials Tower of extensions β ⊆ β π1 ⊆ β π1 π2 ⊆ … β π1 π2 … ππ ⊆ … Transcendental, Infinitesimal, or Algebraic extension Tower of extensions β π‘1 … π‘π π1 … ππ πΌ1 … (πΌπ ) Transcendental Extensions Infinitesimal Extensions Algebraic Extensions Tower of extensions Basic Idea: Given (computable) ordered field πΎ Implement πΎ(π) Tower of extensions (Computable) ordered field πΎ Operations: +, −, ×, πππ£, π πππ π < π ⇔ π πππ π − π = −1 Binary Rational π 2π Approximation: ππππππ₯ π ∈ π΅∞ -interval π΅∞ = π΅ ∪ −∞, ∞ π ≠ 0 ⇒ 0 ∉ ππππππ₯(π) Refine approximation (Computable) Transcendental Extensions ππππππ₯(π) π ∈ π΅∞ -interval ∀π ∈ β+ , ∃π 1 ∈ β, π€πππ‘β(ππππππ₯(π) π ) < π Elements of the extension are encoded as rational functions π2 + π − 2 π+1 (Computable) Transcendental Extensions 1 2 1 π + π+1 1 1 2 2 π+ = 2 π+1 π+1 Standard normal form for rational functions GCD(numerator, denominator) = 1 Denominator is a monic polynomial (Computable) Transcendental Extensions Refine interval Interval arithmetic Refine coefficients and extension Zero iff numerator is the zero polynomial If π π₯ is not the zero polynomial, then π π can’t be zero, since π is transcendental. Remark π is transcendental with respect to β π is not transcendental with respect to β(π) Infinitesimal Extensions Every infinitesimal extension is transcendental Rational functions π πππ(π0 + π1 π + … + ππ π π ) sign of first non zero coefficient 1 ππππππ₯ π = (0, π ) 2 Non-refinable intervals 1 ππππππ₯ = (2π , ∞) π Algebraic Extensions πΎ πΌ πΌ is a root of a polynomial with coefficients in πΎ Encoding πΌ as polynomial + interval does not work πΎ may not be Archimedian Roots can be infinitely close to each other. Roots can be greater than any Real. Thom’s Lemma We can always distinguish the roots of a polynomial in a RCF using the signs of the derivatives Algebraic Extensions Roots: − 1/π, Three roots of 1/π, 3 1/π Algebraic Extensions The elements of πΎ πΌ are polynomials π(πΌ). Implement +, −, × using polynomial arithmetic. Compute sign (when possible) using interval arithmetic. Algebraic Extensions πΌ = (−2 + π₯ 2 , 1,2 , {}) Let π be π(πΌ) = 1 + πΌ 3 We can normalize a by computing the polynomial remainder. 1 + x 3 = π₯ −2 + π₯ 2 + (1 + 2π₯) 1 + πΌ 3 = πΌ −2 + πΌ 2 + 1 + 2πΌ = 1 + 2πΌ π = πππ 1 + π₯ 3 , −2 + π₯ 2 (πΌ) Polynomial Remainder Algebraic Extensions: non-minimal Polynomials Computing the inverse of π πΌ , where πΌ = π, π, π , π Find β πΌ s.t. π πΌ β πΌ = 1 Compute the extended GCD of π and π. π π₯ π π₯ +β π₯ π π₯ =1 π πΌ π πΌ +β πΌ π πΌ =1 0 Algebraic Extensions: non-minimal Polynomials We only use square-free polynomials π in πΌ = π, π, π , π They are not necessarily minimal in our implementation. π(π₯) = π(π₯)π (π₯) πΎ π₯ / π ≅ πΎ(πΌ) Only is π is minimal Solution: Dynamically refine π, when computing inverses. Algebraic Extensions Given π» = β1 , … , βπ , π ππππππ‘ π», π, π, π Feasible sign assignments of π» at roots of π in (π, π) Based on Sturm-Tarski Theorem Ben-Or et al algorithm. π πππ π πΌ where πΌ = (π, π, π , π) π = π ππππππ‘(ππππ¦ π , π, π, π ) Algebraic Extensions: Clean Representation Clean denominators of coefficients of π in πΌ = π, π, π , π Use pseudo-remainder when computing Sturm-sequences. Example 1 + π2 + 1 + π + π2 2 πΌ2 where πΌ is (π − 2 π₯ + π₯ 5 , −2, −1 , {}) πΌ Example 1 + π2 + 1 + π + π2 2 πΌ2 where πΌ is (π − 2 π₯ + π₯ 5 , −2, −1 , {}) πΌ π 1 1 Example 1 + π2 + 1 + π + π2 2 πΌ2 where πΌ is (π − 2 π₯ + π₯ 5 , −2, −1 , {}) πΌ 2 π 1 1 1 Example 1 + π2 + 1 + π + π2 2 πΌ2 where πΌ is (π − 2 π₯ + π₯ 5 , −2, −1 , {}) πΌ 2 π 1 1 1 π 1 Example 1 + π2 + 1 + π + π2 2 πΌ2 where πΌ is (π − 2 π₯ + π₯ 5 , −2, −1 , {}) πΌ 2 π 1 1 π 1 π 1 1 Examples − 2 −2 + π₯ 2 2 msqrt2, sqrt2 = MkRoots([-2, 0, 1]) print(msqrt2) >> root(x^2 + -2, (-oo, 0), {}) print(sqrt2) >> root(x^2 + -2, (0, +oo), {}) print(sqrt2.decimal(10)) >> 1.4142135623? Examples 1 − 10π₯ 2 + π₯ 4 r1,r2,r3,r4 = MkRoots([1, 0, -10, 0, 1]) msqrt2, sqrt2 = MkRoots([-2, 0, 1]) msqrt3, sqrt3 = MkRoots([-3, 0, 1]) print sqrt3 + sqrt2 == r4 >> True print sqrt3 + sqrt2 > r3 >> True print sqrt3 + msqrt2 == r3 >> True Examples π − 2 π₯ + π₯5 pi = Pi() rs = MkRoots([pi, - sqrt2, 0, 0, 0, 1]) print(len(rs)) >> 1 print(rs[0]) >> root(x^5 + -1 root(x^2 + -2, (0, +oo), {}) x + pi, (-oo, 0), {}) Examples eps = MkInfinitesimal() print(eps < 0.000000000000001) >> True Infinity value print(1/eps > 10000000000000000000000) >> True print(1/eps + 1 > 1/eps) >> True [r] = MkRoots([-eps, 0, 0, 1]) print(r > eps) >> True −π + π₯ 3 3 π>π Examples [x] = MkRoots([-1, -1, 0, 0, 0, 1]) [y] = MkRoots([-197, 3131, -31*x**2, 0, 0, 0, 0, x]) [z] = MkRoots([-735*x*y, 7*y**2, -1231*x**3, 0, 0, y]) print x.decimal(10), y.decimal(10), z.decimal(10) >> 1.1673039782?, 0.0629726948?, 31.4453571397? instantaneously solved Same Example in Mathematica x = Root[#^5 - # - 1 &, 1] y = Root[x #^7 - 31 x^2 #^2 + 3131 # - 197 &, 1] z = Root[y #^5 - 1231 x^3 #^2 + 7 y^2 # - 735 x y &, 1] 10min, π§ is encoded by a polynomial of degree 175. Conclusion Package for computing with transcendental, infinitesimal and algebraic extensions. Main application: exact nonlinear optimization. Code is available online. You can play with it online: http://rise4fun.com/z3rcf More info: https://z3.codeplex.com/wikipage?title=CADE24 PSPACE-complete procedures