Python bindings for FLINT
Failed to load latest commit information.


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 special functions

Author: Fredrik Johansson



First install both FLINT and Arb (currently, the git versions are required). See:

Install build dependencies:

sudo apt-get install cython python-dev

Build and install python-flint from source:

python build_ext
sudo python install

Run the test suite:

python test/

Import using:

>>> from flint import *

Additional paths

The FLINT and Arb header files and library files ( and must be available at compile time. If they are in a nonstandard location (for example, if they have been built but not installed), use a command such as the following to build:

python ./ build_ext \
    --include-dirs=/home/fredrik/src/flint2:/home/fredrik/src/arb \

Likewise, before starting the Python interpreter, tell the linker where to find the library files using something like:

export LD_LIBRARY_PATH=/home/fredrik/src/flint2:/home/fredrik/src/arb:$LD_LIBRARY_PATH

You may also have to install the CPimport file:

sudo cp /home/fredrik/src/flint2/qadic/CPimport.txt /usr/local/share/flint/CPimport.txt


Number-theoretic functions:

>>> fmpz(1000).number_of_partitions()
>>> fmpq.bernoulli_ui(64)

Polynomial arithmetic:

>>> a = fmpz_poly([1,2,3]); b = fmpz_poly([2,3,4]); a.gcd(a * b)
fmpz_poly([1, 2, 3])
>>> a = fmpz_poly(range(10001)); b = fmpz_poly(range(10000)); a.gcd(a * b).degree()

Matrix arithmetic:

>>> (fmpz_mat(2,2,[1,1,1,0]) ** 10)
fmpz_mat(2, 2, [89, 55, 55, 34])

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)


API documentation is available here:

To do

  • Work on packaging and the build system
  • Continuous integration
  • Write more tests and add missing docstrings
  • Wrap missing flint types: finite fields, p-adic numbers, multiprecision integer mods, rational functions
  • Rational functions
  • Vector or array types (maybe)
  • Many convenience methods
  • Lots of FLINT and Arb functions/methods that haven't been wrapped yet
  • 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)
  • Support for Python-level multithreading (there is some global state)
  • Support for subclassing (maybe, not a priority)
  • Improved printing and string input/output
  • IPython hooks (TeX pretty-printing etc.)
  • Python 3.x support (should mostly work, needs minor touches)
  • Windows support


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