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.
| Library | What it is | Authors |
|---|---|---|
| Arb, in FLINT | C library for real and complex arithmetic with proven error bounds | F. Johansson (Arb); W. Hart, F. Johansson, A. Ahlbäck and the FLINT team (FLINT) |
python-flint | Python bindings to FLINT and Arb | F. Johansson, O. Benjamin and contributors |
Arblib.jl | Julia bindings to Arb | M. Kaluba, J. Dahne and contributors |
Nemo.jl | Julia bindings to FLINT and Arb | C. Fieker, W. Hart, T. Hofmann and F. Johansson |
| mpmath | Python library for arithmetic and special functions at any precision | F. 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:
- An Arb result is an interval with a proof attached only if the inputs were exact or were themselves balls.
- A wide ball means "not enough precision", never "wrong answer". The remedy is to raise the precision and run again.
- mpmath results are numerical estimates with no bound attached. The usual check is to repeat at a higher precision and keep the digits that agree.
- Neither is a computer-algebra system. Exact polynomial algebra belongs in FLINT's exact types (see the
flintexportmodule of Wayfinder) or SymPy. - The working precision is a process-wide setting (
ctx.dps,mp.dps), so code that changes it should restore it.
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.
| File | What it does |
|---|---|
tools/wayfinder/acbfast.py | Optional Arb backend for the series-transport step of Wayfinder (one Taylor-series step of its integration), selected with backend="acb" |
tools/posq/posq_kernel.c | The C sweep kernel of POSQ, the one piece of BootLoops code that links FLINT directly; built as under Requirements |
tools/wayfinder/flintexport.py | Exact arithmetic on rational functions of several variables, on FLINT polynomials; see Wayfinder |
tools/lockpick/pslq_gate.py | The 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:
- Arb ball arithmetic: Baller, Coalescer, Eichler, GPLEval, Landau Alphabet, POSQ, SubTropica, Abacus, Terrier and Wayfinder.
- FLINT exact rational and polynomial types, instead of balls: Counterweight.
- mpmath: Wayfinder, Terrier, Lockpick, Nestor, Gatekeeper, Formglue, Coalescer, and the stand-alone
*-evaluate.pyscripts offered for download on the Feynman-integral pages.
Used on this site
- Three-loop banana at the mass threshold: Arb supplied the ball arithmetic for the high-precision value of the threshold coefficient $c_{3/2}$; the downloadable evaluator runs its own transport on mpmath.
- Four-loop banana at the mass threshold: Arb supplied the ball arithmetic for the transport and for the values in the Checks table.
- The polylogarithmic warm-ups: Arb and GPLEval, which computes in Arb, were the two polylogarithm evaluators behind every comparison with published results.
- Equal-mass kite: the downloadable evaluator needs only Python with mpmath.
Requirements
- Runs on: Python 3 with
mpmathandpython-flint, whose wheels bundle FLINT, GMP and MPFR. The Julia packages useArblib.jlandNemo.jl. - Install:
pip install mpmath sympy numpy python-flintinstalls the core Python dependencies of the BootLoops repository, both libraries among them. The Julia packages fetch their FLINT bindings withPkg.instantiate()from eachProject.toml. - Self-test: the repository includes no tests of the libraries themselves. The self-tests of the packages above exercise them; for example
python3 tools/wayfinder/flintexport.pyprintswayfinder.flintexport selftest: PASS. - Optional: the POSQ kernel is compiled from source against the FLINT, MPFR and GMP headers, and no binary is distributed. On first use the Python driver
kernel_io.pycompiles it (gcc -O2 -o posq_kernel posq_kernel.c -lflint -lmpfr -lgmp -lm, or setPOSQ_KERNELto your own build). Without a compiler and the FLINT headers its entry points stop with the errorPOSQ-KERNEL-UNAVAILABLE.
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.
| Reference | What it supplies |
|---|---|
| F. Johansson, Arb: efficient arbitrary-precision midpoint-radius interval arithmetic, IEEE Trans. Comput. 66 (2017) 1281, arXiv:1611.02831 | Arb and its ball arithmetic |
C. Fieker, W. Hart, T. Hofmann and F. Johansson, Nemo.jl, arXiv:1705.06134 | Julia bindings to FLINT and Arb |
| F. Johansson et al., mpmath: a Python library for arbitrary-precision floating-point arithmetic, mpmath.org | Arbitrary-precision floats, special functions and PSLQ |