Calcium: Computing in Exact Real and Complex Fields Fredrik Johansson
Total Page:16
File Type:pdf, Size:1020Kb
Calcium: computing in exact real and complex fields Fredrik Johansson To cite this version: Fredrik Johansson. Calcium: computing in exact real and complex fields. ISSAC ’21, Jul 2021, Virtual Event, Russia. 10.1145/3452143.3465513. hal-02986375v2 HAL Id: hal-02986375 https://hal.inria.fr/hal-02986375v2 Submitted on 15 May 2021 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. Calcium: computing in exact real and complex fields Fredrik Johansson [email protected] Inria Bordeaux and Institut Math. Bordeaux 33400 Talence, France ABSTRACT This paper presents Calcium,1 a C library for exact computa- Calcium is a C library for real and complex numbers in a form tion in R and C. Numbers are represented as elements of fields suitable for exact algebraic and symbolic computation. Numbers Q¹a1;:::; anº where the extension numbers ak are defined symbol- ically. The system constructs fields and discovers algebraic relations are represented as elements of fields Q¹a1;:::; anº where the exten- automatically, handling algebraic and transcendental number fields sion numbers ak may be algebraic or transcendental. The system combines efficient field operations with automatic discovery and in a unified way. It is capable of deciding equality for a wide class certification of algebraic relations, resulting in a practical computa- of numbers which includes Q as a subset. We show a few basic tional model of R and C in which equality is rigorously decidable examples, here using a Python wrapper: for a large class of numbers. >>> (pi**2 - 9) / (pi + 3) 0.141593 {a-3 where a = 3.14159 [Pi]} >>> phi = (sqrt(5)+1)/2; (phi**100 - (1-phi)**100)/sqrt(5) CCS CONCEPTS 3.54225e+20 {354224848179261915075} • Computing methodologies ! Representation of exact num- >>> i**i - exp(pi / (sqrt(-2)**sqrt(2))**sqrt(2)) bers; Hybrid symbolic-numeric methods; Exact arithmetic 0 algorithms; Symbolic and algebraic manipulation. >>> log(sqrt(2)+sqrt(3)) / log(5+2*sqrt(6)) 0.500000 {1/2} >>> erf(4*atan(ca(1)/5) - atan(ca(1)/239)) + erfc(pi/4) KEYWORDS 1 Exact real arithmetic, Number fields, Transcendental numbers >>> -1e-12 < exp(pi*sqrt(163)) - 262537412640768744 < -1e-13 True ACM Reference Format: In the first example, the field is Q¹aº where a = π, and the Fredrik Johansson. 2021. Calcium: computing in exact real and complex element is a − 3. The numerical approximation (x ≈ 0:141593) fields. In Proceedings of the 2021 International Symposium on Symbolic and is computed to desired precision on demand, for example when Algebraic Computation (ISSAC ’21), July 18–23, 2021, Virtual Event, Russian printing or evaluating a numerical predicate. Examples 2–5 were ACM, New York, NY, USA,9 pages. https://doi.org/10.1145/ Federation. chosen so that the field of the result simplifies to Q. 3452143.3465513 The basic idea in this work is to combine a multivariate fraction field representation, automatic relation discovery, ideal reduction 1 INTRODUCTION (where the ideal may be incomplete), and rigorous numerical certi- fication using ball arithmetic. This approach is inspired by earlier A field K is said to be effective if its elements can be enumerated implementations of Q (including Sage [30] and Magma [3]) and f ; −; ·; /; g and the operations + = are computable. Examples include by theoretical work on transcendental fields (notably Richardson’s the rationals Q, finite fields Fq , and the algebraic numbers Q. algorithm [26]). The main improvement over previous software The fields of real and complex numbers R and C are notably non- is that we handle both algebraic and transcendental numbers in a effective, even when restricted to so-called computable numbers (a rigorous and structured way; compared to symbolic computation real number x is said to be computable if there is a program which, systems like Mathematica and Maple, our approach provides faster −n given n, outputs some xn 2 Q with jx − xn j < 2 ). The problem is field arithmetic and more reliable results. that equality is only semi-decidable: we can in general prove x , y, This paper is structured as follows. Section2 presents our high- but not x = y, as a consequence of the halting theorem. Neverthe- level strategy for exact computation, described at a general level less, as the example of Q shows, we can hope for an equality test at without reference to low-level implementation details. Section3 least for some numbers within a suitable algebraic framework. discusses the architecture of Calcium. Section4 relates our strategy to earlier work and presents some benchmark results. Permission to make digital or hard copies of all or part of this work for personal or 2 COMPUTING IN SUBFIELDS OF C classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation To simulate R and C, we may start with Q and lazily extend the on the first page. Copyrights for components of this work owned by others than the field with new numbers a as they arise in computations. A general author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or k republish, to post on servers or to redistribute to lists, requires prior specific permission way to compute in such extension fields of Q is in terms of quotient and/or a fee. Request permissions from [email protected]. rings and their fields of fractions (henceforth formal fields). ISSAC ’21, July 18–23, 2021, Virtual Event, Russian Federation © 2021 Copyright held by the owner/author(s). Publication rights licensed to ACM. 1Pronounced “kalkium” to distinguish it from the chemical element. Calcium is free and ACM ISBN 978-1-4503-8382-0/21/07...$15.00 open source (LGPL 2.1+) software. The source repository is https://github.com/fredrik- https://doi.org/10.1145/3452143.3465513 johansson/calcium and the documentation is available at http://fredrikj.net/calcium/. In the following, we assume that a1;:::; an is a finite list of • Evaluate the complex conjugation map z ! z. complex numbers. We let X1;:::; Xn denote independent formal • Evaluate numerical ordering relations (x < y, jxj < jyj, etc.). variables, we let µ : Q»X1;:::; Xn¼ ! C denote the evaluation • Exclude singularities (e.g. division by zero) and choose well- homomorphism induced by the map Xk 7! ak , and we define defined branches of multivalued functions. I := ker µ = ff 2 Q»X1;:::; Xn¼ : f ¹a1;:::; anº = 0g We therefore need a symbolic way to define extension numbers a ;:::; a so that they are explicitly (numerically) computable, and as the ideal of all algebraic relations among a ;:::; a over Q. 1 n 1 n we need to construct I from this symbolic data rather than vice Theorem 1. Assume that I is known (in the sense that an explicit versa. The following types of extensions are useful: list of generators I = hf1;:::; fmi is known). Then • Absolute algebraicp : a is a fixed algebraic constant a 2 Q, 2π i/3 5 K := Q¹a1;:::; anº Kformal := Frac¹Q»X1;:::; Xn]/Iº for example i, 2, e , or »a − a − 1 = 0; a ≈ 1:17¼. is an effective subfield of C. Such a constant can be defined canonically by its minimal polynomial over Q together with an isolating ball for a root. Proof. The isomorphism is obvious. Decidability of “=” in the • Relative algebraic: a is defined by an equation am/n = c with formal field follows from the fact that we can compute aGröb- c 2 C, or more generally P¹aº = 0 with P 2 C»X¼, together p r ner basis for I. Given formal fractions q and s with p;q;r;s 2 with an isolating complex ball for a root. Q»X1;:::; Xn¼, we can consequently decide whether ps ≡ qr mod I. • Transcendental (perhaps conjecturally): a is a symbolic con- z w Indeed, we can also decide whether q;s . 0 mod I and thereby en- stant (π, γ , etc.) or function (e , log¹zº, z , Γ¹zº, Jν ¹zº, etc.) sure that the fractions define numbers in the first place. □ evaluated at some point. • Black-box computable: a is defined by a program for numer- Some easy special cases are worth noting: ical evaluation in ball arithmetic. (We will not be able to • The trivial field K = Q (take n = 0). prove algebraic relations except self-relations like a − a = 0.) • = Q¹ ;:::; º Transcendental number fields K a1 an where the Calcium represents algebraic and transcendental extensions in numbers a1;:::; an are algebraically independent over Q. the usual way as symbolic expressions f ¹z1;:::; zp º. The argu- • Algebraic number fields K = Q¹aº Q»X]/hf ¹Xºi where ments z1;:::; zp are real or complex numbers which may belong a is an algebraic number with minimal polynomial f . to different fields, say z1 2 Q¹b1;:::;br º, z2 2 Q¹c1;:::;cs º, etc. The general case is a mixed field in which the extension numbers Each extension number defines a computable number through may be algebraic or transcendental and algebraically dependent or recursive numerical evaluation of the symbolic function and its independent in any combination. arguments in arbitrary-precision ball arithmetic. This is at least true in principle assuming that we can decide signs at discontinuities.