Skip to main content

A Python interface to the number theory library PARI/GP

Project description

Documentation Status

A Python interface to the number theory library PARI/GP.

Installation

From a distribution package (GNU/Linux, conda-forge)

A package might be available in your package manager, see https://repology.org/project/python:cypari2/versions or https://doc.sagemath.org/html/en/reference/spkg/cypari for installation instructions.

From a pre-built wheel from PyPI

Requirements:

  • Python >= 3.9

  • pip

Install cypari2 via the Python Package Index (PyPI) via

$ pip install cypari2 [--user]

(the optional option –user allows to install cypari2 for a single user and avoids using pip with administrator rights).

From source with pip

Requirements:

Install cypari2 via the Python Package Index (PyPI) via

$ pip install --no-binary cypari2 cypari2 [--user]

(the optional option –user allows to install cypari2 for a single user and avoids using pip with administrator rights).

pip builds the package using build isolation. All Python build dependencies of the package, declared in pyproject.toml, are automatically installed in a temporary virtual environment.

If you want to try the development version, use

$ pip install git+https://github.com/sagemath/cypari2.git [--user]

Usage

The interface as been kept as close as possible from PARI/GP. The following computation in GP

? zeta(2)
%1 = 1.6449340668482264364724151666460251892

? p = x^3 + x^2 + x - 1;
? modulus = t^3 + t^2 + t - 1;
? fq = factorff(p, 3, modulus);
? centerlift(lift(fq))
%5 =
[            x - t 1]

[x + (t^2 + t - 1) 1]

[   x + (-t^2 - 1) 1]

translates into

>>> import cypari2
>>> pari = cypari2.Pari()

>>> pari(2).zeta()
1.64493406684823

>>> p = pari("x^3 + x^2 + x - 1")
>>> modulus = pari("t^3 + t^2 + t - 1")
>>> fq = p.factorff(3, modulus)
>>> fq.lift().centerlift()
[x - t, 1; x + (t^2 + t - 1), 1; x + (-t^2 - 1), 1]

The object pari above is the object for the interface and acts as a constructor. It can be called with basic Python objects like integer or floating point. When called with a string as in the last example the corresponding string is interpreted as if it was executed in a GP shell.

Beyond the interface object pari of type Pari, any object you get a handle on is of type Gen (that is a wrapper around the GEN type from libpari). All PARI/GP functions are then available in their original names as methods like zeta, factorff, lift or centerlift above.

Alternatively, the pari functions are accessible as methods of pari. The same computations be done via

>>> import cypari2
>>> pari = cypari2.Pari()

>>> pari.zeta(2)
1.64493406684823

>>> p = pari("x^3 + x^2 + x - 1")
>>> modulus = pari("t^3 + t^2 + t - 1")
>>> fq = pari.factorff(p, 3, modulus)
>>> pari.centerlift(pari.lift(fq))
[x - t, 1; x + (t^2 + t - 1), 1; x + (-t^2 - 1), 1]

The complete documentation of cypari2 is available at http://cypari2.readthedocs.io and the PARI/GP documentation at http://pari.math.u-bordeaux.fr/doc.html

Contributing

CyPari 2 is maintained by the SageMath community.

Open issues or submit pull requests at https://github.com/sagemath/cypari2 and join https://groups.google.com/group/sage-devel to discuss.

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

cypari2-2.1.5rc1.tar.gz (127.1 kB view hashes)

Uploaded Source

Built Distributions

cypari2-2.1.5rc1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (34.5 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

cypari2-2.1.5rc1-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (32.0 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686

cypari2-2.1.5rc1-cp312-cp312-macosx_11_0_arm64.whl (6.6 MB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

cypari2-2.1.5rc1-cp312-cp312-macosx_10_9_x86_64.whl (8.7 MB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

cypari2-2.1.5rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (34.9 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

cypari2-2.1.5rc1-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (32.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686

cypari2-2.1.5rc1-cp311-cp311-macosx_11_0_arm64.whl (6.6 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

cypari2-2.1.5rc1-cp311-cp311-macosx_10_9_x86_64.whl (8.7 MB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

cypari2-2.1.5rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (34.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

cypari2-2.1.5rc1-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (31.4 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686

cypari2-2.1.5rc1-cp310-cp310-macosx_11_0_arm64.whl (6.6 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

cypari2-2.1.5rc1-cp310-cp310-macosx_10_9_x86_64.whl (8.7 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

cypari2-2.1.5rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (34.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

cypari2-2.1.5rc1-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (31.4 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686

cypari2-2.1.5rc1-cp39-cp39-macosx_11_0_arm64.whl (6.6 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

cypari2-2.1.5rc1-cp39-cp39-macosx_10_9_x86_64.whl (8.7 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