Home

Awesome

Python-FLINT

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

Documentation: https://python-flint.readthedocs.io/en/latest/

Repository: https://github.com/flintlib/python-flint/

Author: Fredrik Johansson fredrik.johansson@gmail.com

Installation

Currently python-flint supports CPython versions 3.10-3.13. For Windows (x86-64) or OSX (x86-64 or arm64) or Linux (x86-64 manylinux_2_17) there are CPython 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

It is also possible to use python-flint with some PyPy versions. Binary wheels are not provided for this on PyPI but can be installed with conda.

Build from source

For other platforms or architectures installation needs to build from source. First install FLINT 3. Starting with python-flint 0.5.0 older versions of Flint such as 2.9 are not supported any more. Note that as of Flint 3 Arb no longer needs to be built separately as it is now merged into Flint.

As of e.g. Ubuntu 24.04 a new enough version of FLINT (at least version 3) can be installed from the Ubuntu repos like

sudo apt-get install libflint-dev

For older distros the version in the repos is too old and a newer version of FLINT needs to be built. See here for instructions on building FLINT:

A script that builds and installs FLINT on Ubuntu can be found here:

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

pip install --no-binary python-flint python-flint

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

pip install .

See the documentation for further notes on building and installing python-flint:

Examples

Import Python-FLINT:

>>> from flint import *

Number-theoretic functions:

>>> fmpz(1000).partitions_p()
24061467864032622473692149727991
>>> fmpq.bernoulli(64)
-106783830147866529886385444979142647942017/510

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()
10000
>>> 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()
1/46206893947914691316295628839036278726983680000000000

Numerical evaluation:

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

Numerical integration:

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

To do

Compatibility table

Generally each release of python-flint will be compatible with a range of Python versions as described in SPEC 0. Since python-flint 0.5.0 the minimum supported Flint version is 3.0 and each release of python-flint supports all versions of Flint >=3.0 available at the time of release.

Compatible versions (note that 0.7.0 is not yet released):

python-flintRelease dateCPythonFLINTCython
0.7.0Not yet3.10-3.133.0-3.2?3.0-3.1?
0.6.01st Feb 20243.9-3.123.0 only3.0 only

As of python-flint 0.7.0, CPython 3.13 free-threaded builds are tested in CI but wheels are not provided on PyPI. There are no known issues related to using python-flint in a PEP 703 free-threaded build but it is likely that mutating objects from multiple threads is not safe.

Binary wheels are not yet provided for Linux aarch64 (gh-105) or for Windows on ARM but may be added when CI runners for Linux/Windows are available.

CHANGELOG

Next release (0.7.0)...

Contributors (0.7.0):

Highlights (0.7.0):

Compatibility break (0.7.0):

Other changes (0.7.0):

0.6.0

0.5.0

Important compatibility changes:

New features:

Bug fixes:

0.4.4

0.4.3

0.4.2

0.4.1

0.4.0

License

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