Arb and mpmath (external)

Arb and mpmath are public libraries for arithmetic at any precision, written by Fredrik Johansson and collaborators. Arb, now part of the FLINT library, returns every real or complex result with a proven error bound; mpmath is a Python library of arithmetic and special functions without error bounds. BootLoops uses both as released, for every computation that needs more digits than ordinary floating point, and adds no code inside either.

Where it comes from

Arb and mpmath were written by Fredrik Johansson and collaborators; the table names the authors of each library and of its bindings. Arb is written in C and distributed as part of FLINT; mpmath is pure Python. BootLoops calls Arb from Python, from Julia and, in one place, from C (the sweep kernel of POSQ, which links the FLINT library directly). It calls mpmath from Python.

LibraryWhat it isAuthors
Arb, in FLINTC library for real and complex arithmetic with proven error boundsF. Johansson (Arb); W. Hart, F. Johansson, A. Ahlbäck and the FLINT team (FLINT)
python-flintPython bindings to FLINT and ArbF. Johansson, O. Benjamin and contributors
Arblib.jlJulia bindings to ArbM. Kaluba, J. Dahne and contributors
Nemo.jlJulia bindings to FLINT and ArbC. Fieker, W. Hart, T. Hofmann and F. Johansson
mpmathPython library for arithmetic and special functions at any precisionF. Johansson and the mpmath contributors

Please cite the authors' papers when you use the libraries. BootLoops is not affiliated with or endorsed by their authors.

What it does

Double-precision arithmetic carries about sixteen significant digits and no record of how many are still correct after a long computation. Two recurring steps in BootLoops need more. Comparing a proposed closed form with a separately computed numerical value is convincing only at thirty to several hundred digits. An integer-relation searchgiven a list of high-precision numbers, find small integers that combine them to zero, turning a decimal into an exact expression in known constants needs its inputs to that many digits before it can succeed.

Arb implements ball arithmetic. A real number is stored as a midpoint $m$ and a radius $r$, meaning the true value lies in $[m-r,\,m+r]$; a complex number is a pair of such balls. Every operation rounds the midpoint at the working precision you choose and enlarges the radius enough that the output ball is guaranteed to contain the exact result. In python-flint the types are arb and acb, with polynomial, matrix and series versions.

mpmath provides arbitrary-precision floats (mpf, mpc) whose working precision is set by mp.dps. On top of them it has a large library: special functions (gamma, zeta, polylogarithms, elliptic and hypergeometric functions), numerical integration, root finding, linear algebra, and the PSLQ integer-relation algorithm (pslq, identify).

Use Arb when a number must carry a proven bound, for example the certificate on a closed form. Use mpmath for exploratory evaluation, special functions and PSLQ.

The libraries have these limits:

Examples

A ball at two precisions (from the python-flint documentation). With python-flint installed (see Requirements), divide by four and by three at the default 15 digits, then evaluate one third at 50 digits.

>>> from flint import arb, ctx
>>> print(1 / arb(4))  # exact
0.250000000000000
>>> print(1 / arb(3))  # approximate
[0.333333333333333 +/- 3.71e-16]
>>> ctx.dps = 50
>>> print(arb("1/3"))
[0.33333333333333333333333333333333333333333333333333 +/- 3.78e-51]
>>> ctx.default()

An exactly representable result prints as a plain number. One that is not prints as [midpoint +/- radius], and the true value $1/3$ is guaranteed to lie inside. Raising ctx.dps shrinks the radius; ctx.default() puts the global precision back.

Recognizing a number with PSLQ (from the mpmath documentation). Find integer relations between $\pi$ and 1 at two loose tolerances, then verify Machin's formula $\pi/4 = 4\,\mathrm{acot}\,5 - \mathrm{acot}\,239$ at 30 digits.

>>> from mpmath import *
>>> mp.dps = 15; mp.pretty = True
>>> pslq([-1, pi], tol=0.01)
[22, 7]
>>> pslq([-1, pi], tol=0.001)
[355, 113]
>>> mp.dps = 30
>>> pslq([pi/4, acot(5), acot(239)])
[1, -4, 1]

pslq(x) returns integers $c$ with $\sum_k c_k x_k$ zero to within the tolerance, or None if no relation with coefficients below maxcoeff exists. The first two answers, $-22 + 7\pi \approx 0$ and $-355 + 113\pi \approx 0$, are the approximations $22/7$ and $355/113$; the last is Machin's formula. In BootLoops a relation is accepted only after the test in Lockpick, described under Routines.

Both libraries in one downloadable script. direct_linear_extract.py is in the bundle offered on the Four-loop banana at the mass threshold page. It recovers the threshold connection coefficients of the K3 and CY₃ bananas by a direct linear solve in 1400-bit Arb arithmetic (flint.acb). mpmath only counts agreeing digits at the end. Its usage text gives:

python3 direct_linear_extract.py --selftest

The self-test runs the clean extraction for both families, then two deliberately corrupted runs that must stop with a specific error message (one operator coefficient shifted by one; one digit of a recorded string flipped). It exits 0 only if all of that happens, and takes about a minute. It needs python-flint, mpmath and the fixture files beside it; the result page also lists numpy for the scripts of the bundle.

Routines

Four BootLoops files are written directly against the libraries.

FileWhat it does
tools/wayfinder/acbfast.pyOptional Arb backend for the series-transport step of Wayfinder (one Taylor-series step of its integration), selected with backend="acb"
tools/posq/posq_kernel.cThe C sweep kernel of POSQ, the one piece of BootLoops code that links FLINT directly; built as under Requirements
tools/wayfinder/flintexport.pyExact arithmetic on rational functions of several variables, on FLINT polynomials; see Wayfinder
tools/lockpick/pslq_gate.pyThe integer-relation acceptance test of Lockpick, a wrapper around mpmath.pslq

In acbfast.py, backend="acb" is an argument of enable_fast_path and transport_fixed_eps. mpc_to_acb and acb_to_mpc convert exactly between mpmath and Arb numbers, and AcbFastTable builds, in ball arithmetic, the Taylor coefficients of the entries of the differential equation that Wayfinder integrates. The solution vector is trimmed to ball midpoints after each step, so accuracy is checked at two precisions as on the mpmath path. The output is not a certified ball.

pslq_gate.py accepts a relation only if the same integer vector comes back at two working precisions, under a cap on coefficient size. A known relation placed in the same set of constants must also be recovered. See also PSLQ and LLL.

These BootLoops packages compute in the libraries:

Used on this site

Requirements

Source and references

The BootLoops files that call the libraries are in the BootLoops repository. The repository does not bundle FLINT, Arb or mpmath; they are installed from upstream.

ReferenceWhat it supplies
F. Johansson, Arb: efficient arbitrary-precision midpoint-radius interval arithmetic, IEEE Trans. Comput. 66 (2017) 1281, arXiv:1611.02831Arb and its ball arithmetic
C. Fieker, W. Hart, T. Hofmann and F. Johansson, Nemo.jl, arXiv:1705.06134Julia bindings to FLINT and Arb
F. Johansson et al., mpmath: a Python library for arbitrary-precision floating-point arithmetic, mpmath.orgArbitrary-precision floats, special functions and PSLQ

← back to the tools index