Arb and mpmath (external)
The content on this page was written by AI under human supervision.
Arb and mpmath are public software written by Fredrik Johansson and collaborators. Arb, now part of the FLINT library, does real and complex arithmetic at any precision and returns every result with a proven error bound; mpmath is a Python library for arithmetic and special functions at any precision, 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.
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 against an independent numerical value is only convincing 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 and mpmath supply the arithmetic for both.
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. What comes back is an interval with a proof attached, provided 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. BootLoops reaches Arb from Python through python-flint (types arb and acb, with polynomial, matrix and series versions), from Julia through Arblib.jl and Nemo.jl, and from C in one place, the sweep kernel of POSQ, which links the FLINT library directly.
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). Results are numerical estimates with no bound attached; the usual check is to repeat at a higher precision and keep the digits that agree. mpmath is pure Python, slower than Arb and quicker to script.
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. Neither is a computer-algebra system; exact polynomial algebra belongs in FLINT's exact types (see the flintexport module of Wayfinder) or SymPy. One pitfall applies to both: 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). 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 (by default about three quarters of the working precision), 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 if the same integer vector comes back at a second, higher precision and a known relation placed among the same constants is recovered by the same run. That logic lives in Lockpick, on top of mpmath.pslq.
Both libraries in one downloadable script. direct_linear_extract.py, a download on the Threshold banana, K3 rung page, 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, takes about a minute and needs only python3, python-flint, mpmath and the fixture files beside it.
Routines
BootLoops adds no code of its own inside Arb, FLINT or mpmath; they are installed from upstream and called as libraries. BootLoops-side code written directly against them:
tools/wayfinder/acbfast.py— optional Arb backend for Wayfinder's series-transport step, selected withbackend="acb"inenable_fast_pathandtransport_fixed_eps, used for speed.mpc_to_acbandacb_to_mpcconvert exactly between mpmath and Arb numbers, andAcbFastTablebuilds the Taylor coefficients of the equation's entries in ball arithmetic. The state is trimmed to ball midpoints after each step, so accuracy is checked at two precisions as on the mpmath path and the output is not a certified ball.tools/posq/posq_kernel.c— the C sweep kernel of POSQ, the one piece of BootLoops code that links FLINT/Arb directly. It evaluates positive quadrature sums in ball arithmetic and exchanges exact balls with the Python driverkernel_io.py. No binary is distributed: on first use the driver compiles 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.tools/wayfinder/flintexport.py— exact multivariate rational-function arithmetic on FLINT polynomials (mk_ctx,make_env,walk,canonical_terms), imported aswayfinder.flintexport; described on the Wayfinder page.tools/lockpick/pslq_gate.py— the toolkit's integer-relation acceptance test, a wrapper aroundmpmath.pslq. It accepts a relation only if the same integer vector comes back at two working precisions under a cap on coefficient size, and only if a known relation placed in the same set of constants is recovered. See Lockpick and PSLQ and LLL.
BootLoops packages that compute in Arb ball arithmetic: Baller, Coalescer, Eichler, GPLEval, Landau Alphabet, POSQ, SubTropica, Abacus, Terrier and Wayfinder; Counterweight uses FLINT's exact rational and polynomial types instead of balls. Packages that compute in mpmath: Wayfinder, Terrier, Lockpick, Nestor, Gatekeeper, Formglue, Coalescer, and the stand-alone *-evaluate.py scripts offered for download on the Feynman-integral pages.
Used on this site
- Threshold banana, K3 rung — the certificate on the connection coefficient is an Arb ball-arithmetic transport of the exact differential operator (through
Arblib.jl); an independent mpmath transport agrees with it. - Threshold banana, CY₃ rung — the same pair of routes, Arb on one and mpmath on the other.
- The polylogarithmic warm-ups — Arb and GPLEval were the two independent polylogarithm evaluators behind every comparison with published results.
- Kite — the downloadable evaluator runs on plain Python with mpmath and python-flint, with no computer-algebra system.
Requirements and source
Arb is written in C and distributed as part of FLINT (LGPL-3.0-or-later), flintlib.org. Its Python bindings are python-flint (MIT; the wheels bundle FLINT, GMP and MPFR); its Julia bindings are Arblib.jl and Nemo.jl. mpmath is pure Python (BSD), mpmath.org. BootLoops' bootloops-dev repository (GitHub organization BootLoops-ai), released under the MIT license, does not bundle FLINT, Arb or mpmath; they keep their own licenses and are installed from upstream with the repository's core Python dependencies, pip install mpmath sympy numpy python-flint. The Julia packages fetch their FLINT bindings with Pkg.instantiate() from each Project.toml, and the POSQ kernel is compiled from source against the FLINT, MPFR and GMP headers. The repository includes no tests of the libraries themselves; the self-tests of the packages above exercise them (for example python3 tools/wayfinder/flintexport.py, which prints wayfinder.flintexport selftest: PASS). References: F. Johansson, Arb: efficient arbitrary-precision midpoint-radius interval arithmetic, IEEE Trans. Comput. 66 (2017) 1281, arXiv:1611.02831; F. Johansson et al., mpmath: a Python library for arbitrary-precision floating-point arithmetic, mpmath.org.