GiNaCRA:A C++ Library for Real Algebraic Computations Work-In-Progress Presentation NFM 2011 Contribution

Ulrich Loup Erika Abrah´am´

AlgoSyn

February 2011 AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

Naming

GiNaC C++ library for symbolic computations

GiNaCRA – GiNaC Real Algebra package http://ginacra.sourceforge.net/

RealAlgebra E.g. ∃x, y ( x42y − 2y 4 < 1 ∨ y − x ≥ 0 ) ∧ x2 − y > 0

Ulrich Loup 2/ 17 AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

Outline

Introduction

Features and Functioning

Outlook

Ulrich Loup 3/ 17 The quadratic case (Virtual substitution solver) √ 2 −b± b2−4ac ax + bx − c = 0 ⇐⇒ x ∈ { 2a }, a, b, c ∈ Z. I Real solutions: rationals with square roots

Arbitrary degree polynomials (I-RiSC) Pk i i=0 ci x = 0, k ∈ N, ci ∈ Z, 0 ≤ i ≤ k, ck 6= 0. I Real solutions: real algebraic numbers

AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

Number representations in exact solving over the reals Linear real arithmetic (Yices/Z3, OpenSMT,...) a ax − b = 0 ⇐⇒ x = b , a, b ∈ Z.

I Real solutions: rational numbers

Introduction Ulrich Loup 4/ 17 Arbitrary degree polynomials (I-RiSC) Pk i i=0 ci x = 0, k ∈ N, ci ∈ Z, 0 ≤ i ≤ k, ck 6= 0. I Real solutions: real algebraic numbers

AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

Number representations in exact solving over the reals Linear real arithmetic (Yices/Z3, OpenSMT,...) a ax − b = 0 ⇐⇒ x = b , a, b ∈ Z.

I Real solutions: rational numbers

The quadratic case (Virtual substitution solver) √ 2 −b± b2−4ac ax + bx − c = 0 ⇐⇒ x ∈ { 2a }, a, b, c ∈ Z. I Real solutions: rationals with square roots

Introduction Ulrich Loup 4/ 17 AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

Number representations in exact solving over the reals Linear real arithmetic (Yices/Z3, OpenSMT,...) a ax − b = 0 ⇐⇒ x = b , a, b ∈ Z.

I Real solutions: rational numbers

The quadratic case (Virtual substitution solver) √ 2 −b± b2−4ac ax + bx − c = 0 ⇐⇒ x ∈ { 2a }, a, b, c ∈ Z. I Real solutions: rationals with square roots

Arbitrary degree polynomials (I-RiSC) Pk i i=0 ci x = 0, k ∈ N, ci ∈ Z, 0 ≤ i ≤ k, ck 6= 0. I Real solutions: real algebraic numbers

Introduction Ulrich Loup 4/ 17 AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

Where is exact solving for real algebra desired?

Verification of, e.g., I probabilistic programs ( Friedrich Gretz’s topic) or I hybrid systems. ;

Synthesis of, e.g., I parameters for hybrid systems.

Nonlinear optimization in, e.g., I designing a railway infrastructure ( Jacob Sp¨onemann’stopic). ... ;

Introduction Ulrich Loup 5/ 17 AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

State of the art

C++ libraries implementing real root computations Libreduce (based on Reduce), CoCoALib (based on CoCoA), Givaro, SYNAPS

Software implementing algebraic number arithmetic , KANT, PARI/GP

Software implementing polynomial arithmetic GiNaC, , MATLAB, Mathematica,...

Introduction Ulrich Loup 6/ 17 Features and Functioning AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

Representing a real algebraic number Interval representation

p, ( l, r )  |{z} | {z } ∈ Z[x] exactly one root of p in (l, r)

Example

2 √ x − 2 √ − 2 2 ( )( ) R -3 -2 -1 0 1 2 3

Features and Functioning Ulrich Loup 8/ 17 AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

Demonstration A life cycle of a real algebraic number

I Real root isolation

I Refinement of isolating intervals

I Arithmetic and relational operations

I Sign determination with polynomials

Features and Functioning Ulrich Loup 9/ 17 AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

Mathematical ingredients (1/2): Cauchy bound Let Pk i I p = i=0 ci x with k ∈ N, ci ∈ Z, 0 ≤ i ≤ k, ck 6= 0. then for all roots a ∈ R of p k X ci |a| ≤ ck i=0

Example 2 −2 1 The Cauchy bound of p = x − 2 is 1 + 1 = 3. Indeed, √ | 2| ≤ 3.

Features and Functioning Ulrich Loup 10/ 17 Example Given p = x2 − 2 in , then

2 and #s−3 = 2, =⇒ x − 2 has .

AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

Mathematical ingredients (2/2): Sturm’s Theorem Let I (l, r) be an interval with l, r ∈ Q, 0 0 I s = (p, p , −rem(p, p ),..., c) with rem(p1, p2) being the remainder when dividing p1 by p2 and c constant, 0 0 I sa = (p(a), p (a), −rem(p, p )(a),..., c) with a ∈ Q, and I #sa be the number of sign changes in sa (0 not counted),

then the p has #sl − #sr distinct roots in (l, r).

Features and Functioning Ulrich Loup 11/ 17 AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

Mathematical ingredients (2/2): Sturm’s Theorem Let I (l, r) be an interval with l, r ∈ Q, 0 0 I s = (p, p , −rem(p, p ),..., c) with rem(p1, p2) being the remainder when dividing p1 by p2 and c constant, 0 0 I sa = (p(a), p (a), −rem(p, p )(a),..., c) with a ∈ Q, and I #sa be the number of sign changes in sa (0 not counted), then the p has #sl − #sr distinct roots in (l, r). Example Given p = x2 − 2 in (−3, 0), then

2 s = (x − 2, 2x, 2) s−3 = (7, −6, 2) s0 = (−2, 0, 2)

2 and #s−3 = 2, #s0 = 1 =⇒ x − 2 has one root in (−3, 0).

Features and Functioning Ulrich Loup 11/ 17 AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

Mathematical ingredients (2/2): Sturm’s Theorem Let I (l, r) be an interval with l, r ∈ Q, 0 0 I s = (p, p , −rem(p, p ),..., c) with rem(p1, p2) being the remainder when dividing p1 by p2 and c constant, 0 0 I sa = (p(a), p (a), −rem(p, p )(a),..., c) with a ∈ Q, and I #sa be the number of sign changes in sa (0 not counted), then the p has #sl − #sr distinct roots in (l, r). Example Given p = x2 − 2 in (−3, 3), then

2 s = (x − 2, 2x, 2) s−3 = (7, −6, 2) s3 = (7, 6, 2)

2 and #s−3 = 2, #s3 = 0 =⇒ x − 2 has two roots in (−3, 3).

Features and Functioning Ulrich Loup 11/ 17 AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

Isolating a real root

Divide and conquer 1. Calculate Cauchy bound C(p) and set l := −C(p), r := C(p). 2. If p(l) = 0, stop with output l. If p(r) = 0, stop with output r.

3. If #sl − #sr = 0, stop.

4. If #sl − #sr = 1, stop with output (l, r). 5. If #sl − #sr > 1, goto 1. with both r−l 5.1 r = l + 2 and r−l 5.2 l = l + 2 .

Features and Functioning Ulrich Loup 12/ 17 Operations on real algebraic numbers

I arithmetic operations: +, −, ∗, /

I relational operations: =

I sign determination w.r.t. other univariate polynomials

I common real roots of a set of univariate polynomials

AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

Main contributions in a nutshell

Class-oriented approach

I real algebraic numbers

I special types of univariate and multivariate polynomials

I open intervals including interval arithmetic

Features and Functioning Ulrich Loup 13/ 17 AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

Main contributions in a nutshell

Class-oriented approach

I real algebraic numbers

I special types of univariate and multivariate polynomials

I open intervals including interval arithmetic

Operations on real algebraic numbers

I arithmetic operations: +, −, ∗, /

I relational operations: =

I sign determination w.r.t. other univariate polynomials

I common real roots of a set of univariate polynomials

Features and Functioning Ulrich Loup 13/ 17 Standalone Reliable

I only non-standard library I CppUnit test suite with GiNaC many test cases

I independent of closed-source I uses C++ standard library software wherever possible

AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

Some more features

Open Source (GNU LGPLv3) Powerful interface

I accessible and extensible by I uncomplicated and efficient everyone communication with a C++ I usable in other application

non-proprietary projects I simple console application

Features and Functioning Ulrich Loup 14/ 17 AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

Some more features

Open Source (GNU LGPLv3) Powerful interface

I accessible and extensible by I uncomplicated and efficient everyone communication with a C++ I usable in other application

non-proprietary projects I simple console application

Standalone Reliable

I only non-standard library I CppUnit test suite with GiNaC many test cases

I independent of closed-source I uses C++ standard library software wherever possible

Features and Functioning Ulrich Loup 14/ 17 Outlook AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

Towards satisfiability modulo theories (SMT)

ϕ Boolean abstraction unsatisfiable satisfiable SAT-solver UNSAT

Constraint set Reason unsatisfiable Theory solver SAT satisfiable

Outlook Ulrich Loup 16/ 17 AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

Towards satisfiability modulo theories (SMT)

ϕ Boolean abstraction unsatisfiable satisfiable SAT-solver UNSAT

Constraint set Reason unsatisfiable Theory solver SAT satisfiable

Prototype: Virtual Substitution Solver Planed: I-RiSC–I ncremental Computation of the Realization of Sign Conditions

Outlook Ulrich Loup 16/ 17 AlgoSyn GiNaCRA:A C++ Library for Real Algebraic Computations

To conclude

GiNaCRA – GiNaC Real Algebra package http://ginacra.sourceforge.net/

Support: Ulrich Loup RWTH Aachen University Computer Science 2 Theory of Hybrid Systems http://www-i2.informatik.rwth-aachen.de/i2/hybrid/

Outlook Ulrich Loup 17/ 17