Skip to main content

Bindings for FLINT and Arb

Project description


Python extension module wrapping FLINT (Fast Library for Number Theory) and Arb (arbitrary-precision ball arithmetic). Features:

  • Integers, rationals, integers mod n
  • Real and complex numbers with rigorous error tracking
  • Polynomials, power series and matrices over all the above types
  • Lots of mathematical functions



Author: Fredrik Johansson


For Windows (x86-64) or OSX (x86-64 or arm64) or Linux (x86-64 manylinux_2_17) there are binary wheels for python-flint on PyPI. For these platforms python-flint can be installed simply with pip

pip install python-flint

Alternatively python-flint can be installed using conda

conda install -c conda-forge python-flint

Build from source

For other platforms or architectures installation needs to build from source. First install both FLINT 2.9.0 and Arb 2.23. Note that for python-flint 0.4 only these exact versions of FLINT and Arb will work. While some Linux distributions may provide FLINT and Arb it is unlikely that they will provide the exact versions required (e.g. for Ubuntu only Ubuntu 23.04 provides these versions at the time of writing).

See here for instructions on building FLINT and Arb:

The latest release of Python-FLINT can then be built and installed using:

pip install 'cython>=3' numpy wheel
pip install --no-build-isolation python-flint

Python-FLINT can also be installed from a git checkout or a source archive as follows:

pip install 'cython>=3' numpy wheel
pip install --no-build-isolation .

A script that builds and installs FLINT, Arb and Python-FLINT that is tested on Ubuntu can be found in the git repo here:

See the documentation for further notes on building and installing Python-FLINT:


Import Python-FLINT:

>>> from flint import *

Number-theoretic functions:

>>> fmpz(1000).partitions_p()
>>> fmpq.bernoulli(64)

Polynomial arithmetic:

>>> a = fmpz_poly([1,2,3]); b = fmpz_poly([2,3,4]); a.gcd(a * b)
3*x^2 + 2*x + 1
>>> a = fmpz_poly(list(range(10001))); b = fmpz_poly(list(range(10000))); a.gcd(a * b).degree()
>>> x = fmpz_poly([0,1]); ((1-x**2)*(1+x**3)**3*(1+x+2*x)).factor()
(-1, [(3*x + 1, 1), (x + (-1), 1), (x^2 + (-1)*x + 1, 3), (x + 1, 4)])

Matrix arithmetic:

>>> fmpz_mat([[1,1],[1,0]]) ** 10
[89, 55]
[55, 34]
>>> fmpq_mat.hilbert(10,10).det()

Numerical evaluation:

>>> showgood(lambda: (arb.pi() * arb(163).sqrt()).exp() - 640320**3 - 744, dps=25)
>>> showgood(lambda: (arb.pi() * 10**100 + arb(1)/1000).sin(), dps=25)

Numerical integration:

>>> ctx.dps = 30
>>> acb.integral(lambda x, _: (-x**2).exp(), -100, 100) ** 2
[3.141592653589793238462643383 +/- 3.11e-28]

To do

  • Write more tests and add missing docstrings
  • Wrap missing flint types: finite fields, p-adic numbers, multiprecision integer mods, rational functions
  • Vector or array types (maybe)
  • Many convenience methods
  • Write generic implementations of functions missing for specific FLINT types
  • Proper handling of special values in various places (throwing Python exceptions instead of aborting, etc.)
  • Various automatic conversions
  • Conversions to and from external types (numpy, sage, sympy, mpmath, gmpy)
  • Improved printing and string input/output
  • IPython hooks (TeX pretty-printing etc.)



  • gh-63: The roots method of arb_poly, and nmod_poly is no longer supported. Use acb_roots(p).roots() to get the old behaviour of returning the roots as acb. Note that the roots method of fmpz_poly and fmpq_poly currently returns the complex roots of the polynomial.


Python-FLINT is licensed MIT. FLINT and Arb are LGPL v2.1+.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-flint-0.4.4.tar.gz (2.7 MB view hashes)

Uploaded Source

Built Distributions

python_flint-0.4.4-cp311-cp311-win_amd64.whl (12.5 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

python_flint-0.4.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (35.8 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

python_flint-0.4.4-cp311-cp311-macosx_11_0_arm64.whl (6.0 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

python_flint-0.4.4-cp311-cp311-macosx_10_9_x86_64.whl (7.1 MB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

python_flint-0.4.4-cp310-cp310-win_amd64.whl (12.5 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

python_flint-0.4.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (35.0 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

python_flint-0.4.4-cp310-cp310-macosx_11_0_arm64.whl (6.0 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

python_flint-0.4.4-cp310-cp310-macosx_10_9_x86_64.whl (7.1 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

python_flint-0.4.4-cp39-cp39-win_amd64.whl (12.5 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

python_flint-0.4.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (35.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

python_flint-0.4.4-cp39-cp39-macosx_11_0_arm64.whl (6.0 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

python_flint-0.4.4-cp39-cp39-macosx_10_9_x86_64.whl (7.1 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page