Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python bindings for Flint and Arb

License

NotificationsYou must be signed in to change notification settings

flintlib/python-flint

Repository files navigation

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

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

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

Author: Fredrik Johanssonfredrik.johansson@gmail.com

Installation

Currently python-flint supports CPython versions 3.11-3.14 and 3.14t(free-threaded) and provides binaries on PyPI for the following platforms:

  • Windows (x86-64)
  • MacOS (x86-64, arm64)
  • Linux (manylinux: x86-64, aarch64)

For these platforms python-flint can be installed simply withpip

pip install python-flint

Alternatively python-flint can be installed usingconda

conda install -c conda-forge python-flint

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 Flintsuch as 2.9 are not supported any more. Note that as of Flint 3 Arb no longerneeds 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) canbe 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 ofFLINT 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 installedusing:

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

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

pip install .

See the documentation for further notes on building and installingpython-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

  • Write more tests and add missing docstrings
  • Wrap missing flint types: matrices over finite fields, p-adic numbers, rational functions
  • Build on the preliminary interface to FLINT's generic (gr) types.
  • Make a nicer interface likeZZ(1) etc rather thanfmpz_poly([1, 2]).
  • 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 Pythonexceptions 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.)

Compatibility table

Generally each release of python-flint will be compatible with a range ofPython versions. Since python-flint 0.5.0 the minimum supported Flint versionis3.0 and each release of python-flint supports all versions of Flint>=3.0 available at the time of release.

Compatible versions:

python-flintRelease dateCPythonFLINTCython
0.9.0???3.11-3.143.0-3.33.1-3.2?
0.8.029th Aug 20253.11-3.143.0-3.33.1 only
0.7.016th Mar 20253.11-3.133.0-3.23.0.11-3.1.0a1
0.6.01st Feb 20243.9-3.123.0 only3.0 only

The requirement for Cython 3.1 is only for CPython's free-threaded build.Otherwise Cython 3.0 is fine. Cython 3.2 is required for a stable ABI build ofpython-flint.

As of python-flint 0.7.0, CPython 3.13PEP703 free-threaded (no-GIL) builds ofpython-flint are provided. In the the free-threaded build, mutating matrices orpolynomials from multiple threads can lead to memory corruption. There are someother known issues with the free-threaded build so it should be consideredexperimental.

CHANGELOG

Next release (0.9.0)...

Contributors (0.9.0):

  • Rémy Oudompheng (RO)
  • Agriya Khetarpal (AK)
  • Oscar Benjamin (OB)
  • Daniel Simmons-Marengo (DSM)

Changes (0.9.0):

  • gh-322,Addmul_low andpow_trunc methods tofmpz_poly,fmpq_poly andnmod_poly. (RO)
  • gh-318,Add emscripten build in CI. Polynomial factors and roots arenow sorted into a consistent order fornmod_poly andfq_default_poly. Some tests are fixed so that they pass on32-bit systems. (AK, OB)
  • gh-312,Adddiscriminant method tofmpz_poly,fmpq_poly andnmod_poly. (RO)
  • gh-336,Fixed a bug inarb.neg() which caused it to return its inputwithout negating it. (DSM)
  • gh-339,Addfmpq.__float__ method so thatfloat(fmpq) andcomplex(fmpq)work. (OB)

0.8.0

Contributors (0.8.0):

  • Oscar Benjamin (OB)
  • Robert Dougherty-Bliss (RDB)
  • Rémy Oudompheng (RO)
  • Agriya Khetarpal (AK)

Notes (0.8.0):

  • This mostly a maintenance release with some bug fixes,dependency updates and a few smaller features.
  • Since GitHub Actions is retiring its MacOS x86-64 runnerspython-flint 0.8.0 is likely the last release to provideprebuilt wheels for MacOS x86-64 (MacOS arm64 remainsfully supported). It is likely that future versions willstill work fine on MacOS x86-64 but would require buildingfrom source and will not be tested in python-flint's CI.MacOS arm64 wheels will still be provided and tested.

Changes (0.8.0):

  • gh-302,gh-283,gh-284,Wheels now ship MPFR 4.2.2 and FLINT 3.3.1. Cython 3.1 is nowsupported for building (and required for the freethreadedbuild). Wheels are provided for CPython 3.14 and 3.14t(free-threaded) and PyPy 3.11. (OB)
  • gh-310,Addtruncate,left_shift andright_shift methods tofmpz_poly,fmpq_poly,nmod_poly,acb_poly,arb_polyto match other univariate polynomial types. (RO)
  • gh-287,gh-293,gh-305,gh-307,gh-309,Add type annotations forfmpz,fmpq,nmod,fmpz_mod,fq_default,fmpz_poly,fmpq_poly,nmod_poly,fmpz_mod_poly,fq_default_poly,fmpz_mpoly,fmpq_mpoly,nmod_mpoly,fmpz_mod_mpoly,fmpz_series andfmpq_series(about half of the codebase). (OB)
  • gh-300,Fixarb.repr which now returns a Python representation thatround trips. (OB)
  • gh-292,Thefmpq constructor now acceptsfmpq numerator and denominatoras input. (OB)
  • gh-289,Add.prec attribute to series typesfmpz_series,fmpq_series,arb_series andacb_series. (OB)
  • gh-285,Don't use deprecated meson build option. (AK)
  • gh-274,Add resultant methods tofmpz_poly,fmpq_poly andnmod_poly. Now all univariate and polynomial types have theresultant method except forfq_default_poly. (RDB)

0.7.0

Contributors (0.7.0):

  • Jake Moss (JM)
  • Giacomo Pope (GP)
  • Joris Roos (JR)
  • Edgar Costa (EC)
  • Frédéric Chapoton (FC)
  • Oscar Benjamin (OB)
  • Tom Hubrecht (TH)

Highlights (0.7.0):

  • gh-270,PyPI packages are now built with FLINT 3.2.0 (previously3.0.1 was used). All versions from FLINT 3.0.0 to FLINT 3.2.0are compatible with python-flint but some features requirenewer FLINT versions and the PyPI packages now use FLINT 3.2.0.
  • gh-97,gh-182:Addfq_default andfq_default_poly for finite fields andunivariate polynomials over finite fields. This exposes allof the different implementations of finite fields (fq_zech,fq_nmod etc) via thefq_default interface. (GP)
  • gh-132,gh-164,gh-190,gh-191:gh-192:gh-216:gh-225:gh-228:Addfmpz_mpoly,fmpq_mpoly,nmod_poly andfmpz_mod_polytypes for multivariate polynomials with integer, rational orintegers modn coefficients. (JM)
  • gh-142Addacb_theta module for the numerical evaluation ofthetafunctions (onlyavailable forFlint >= 3.1). (EC)
  • gh-218gh-254gh-255An experimental interface for FLINT's generic rings has beenadded. This provides access to many of FLINT's types thatare not yet wrapped by python-flint such as Gaussian integer,number fields, qqbar, calcium, as well as both univariate andmultivariate polynomials and series over these rings (nomatrices yet though). (OB and TH)
  • gh-129gh-208Use meson/meson-python instead of setuptools as the build systemfor parallel builds and better detection of build and dependencyrequirements. (OB)
  • gh-201gh-202The documentation has been updated and is now atreadthedocs.(OB)gh-235Nightly wheels for python-flint can now be installed from the[Anaconda Scientific Python Nightly Wheels index](https://anaconda.org/scientific-python-nightly-wheels/python-flint).gh-259Add PyPI wheels for Linux aarch64 (Linux on ARM CPU). (OB)

Compatibility break (0.7.0):

  • gh-189As of python-flint 0.7.0fmpq_poly.factor() now returnsprimitive rather than monic factors i.e.2*x + 1 rather thanx + 1/2. This ensures consistency between all poly typesincluding betweenfmpq_poly andfmpq_mpoly. (OB)

Other changes (0.7.0):

  • gh-269All univariate and multivariate polynomial types haveis_zero,is_one andis_constant methods. All polynomialtypes now consistently handle negative powers where possible.
  • gh-261Addfmpz_mat.fflu for fraction-free LU decomposition ofan integer matrix.
  • gh-251Add mpmath-style precision context managers for arbextraprec,extradps,workprec andworkdps. (TH)
  • gh-250Addfmpq.gcd() method.
  • gh-215gh-219The FLINT binding declarations are now fully generatedautomatically from the FLINT docs. (OB)
  • gh-203gh-204gh-205gh-206gh-207gh-211gh-212gh-271Various linting fixes and codebase improvements (FC and GP).
  • gh-189All scalar and poly types now havesqrt. All poly types nowhavefactor_squarefree andleading_coefficient methods.Exception types raised in a number of places were changed toDomainError for better consistency. (OB)
  • gh-196Supported Python versions are 3.10-3.13 (3.9 dropped). CITesting added for 3.13 free-threaded CPython.
  • gh-194Add version checking for build requirements. (OB)
  • gh-180Addequal_trunc,add_trunc,sub_trunc,mul_low,mul_mod andpow_trunc methods tofmpz_mod_poly. (GP)
  • gh-177Remove old Py2 code for compatibility with Cython 3.1. (OB)
  • gh-176Fix the error messages fromfmpq constructor. (OB)
  • gh-174Addpow_mod andcompose_mod methods tonmod_poly andfmpz_mod_poly. Also add some missing methods tonmod_polythat other poly types already have. (GP)
  • gh-172Addfmpz_is_square. (JR)
  • gh-168Make comparisons consistent between different types. Addis_one andis_zero for all poly types. (OB)
  • gh-161Addacb.lerch_phi to compute the Lerch transcendent. (OB)
  • gh-160Addbits toarb andacb, addlog_base toarb. (JR)
  • gh-148Remove debug symbols to make smaller Linux binaries. (OB)
  • gh-144Addrel_one_accuracy_bits toarb andacb. (EC)
  • gh-137Adderfinv anderfcinv forarb. (JR)
  • gh-119Add compatibility with Flint 3.1. (OB)

0.6.0

  • gh-112,gh-111,gh-110,gh-108:Add pyproject.toml and build dependencies. This means thatpython-flint can be built from source without--no-build-isolation.
  • gh-109:Use exact division for non-field domains. Nowfmpz(6)/fmpz(3)returns an exact resultfmpz(2) or raises an error if an exactresult is not possible. Similar changes forfmpz_poly/fmpz,fmpz_mat/fmpz, and for polynomial division withfmpz_poly,fmpq_poly,nmod_poly andfmpz_mod_poly.
  • gh-106:Addfmpz_mod_mat for matrices of integers modn wheren islarger than word sized.
  • gh-104:Bump Flint from 3.0.0 to 3.0.1

0.5.0

Important compatibility changes:

  • gh-80,gh-94,gh-98:Switch from Flint 2.9 to Flint 3.
  • gh-100:Supports Python 3.12 by using setuptools instead ofnumpy.distutils.

New features:

  • gh-87:Addsfmpz_mod_poly type for polynomials overfmpz_mod.
  • gh-85:Adds discrete logarithms tofmpz_mod.
  • gh-83:Introduces thefmpz_mod type for multi-precision integer mods.

Bug fixes:

  • gh-93:Fixes a bug withpow(int, int, fmpz) which previously gaveincorrect results.
  • gh-78,gh-79:minor fixes for thenmod type.

0.4.4

  • gh-75,gh-77:finish bulk of the work in refactoringpython-flint intosubmodules
  • gh-72:The roots method ofarb_poly is not supported. Use either thecomplex_roots method oracb_roots(p).roots() to get the oldbehaviour of returning the complex roots. Theroots method onfmpz_poly andfmpq_poly now return integer and rationalroots respectively. To access complex roots on these types, usethecomplex_roots method. Foracb_poly, bothroots andcomplex_roots behave the same
  • gh-71:Include files in sdist and fix issuegh-70
  • gh-67:Continue refactoring job to introduce submodules intopython-flint

0.4.3

  • gh-63:Theroots method ofarb_poly, andnmod_poly is no longersupported. Useacb_roots(p).roots() to get the old behaviourof returning the roots asacb. Note that theroots method offmpz_poly andfmpq_poly currently returns the complex rootsof the polynomial.
  • gh-61:Start refactoring job to introduce submodules intopython-flint

0.4.2

  • gh-57:Adds manylinux wheels

0.4.1

  • gh-47:Removes Linux wheels, updates instructions for building fromsource.

0.4.0

  • gh-45:Adds wheels for Windows, OSX and manylinux but the Linux wheelsare broken.

License

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

About

Python bindings for Flint and Arb

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors19

Languages


[8]ページ先頭

©2009-2025 Movatter.jp