1CyPari 2 2======== 3 4.. image:: https://travis-ci.org/sagemath/cypari2.svg?branch=master 5 :target: https://travis-ci.org/sagemath/cypari2 6.. image:: https://readthedocs.org/projects/cypari2/badge/?version=latest 7 :target: https://cypari2.readthedocs.io/en/latest/?badge=latest 8 :alt: Documentation Status 9 10A Python interface to the number theory library `PARI/GP <http://pari.math.u-bordeaux.fr/>`_. 11 12This library supports both Python 2 and Python 3. 13 14Installation 15------------ 16 17GNU/Linux 18^^^^^^^^^ 19 20A package `python-cypari2` or `python2-cypari2` or `python3-cypari2` might be 21available in your package manager. 22 23Using pip 24^^^^^^^^^ 25 26Requirements: 27 28- PARI/GP >= 2.9.4 (header files and library) 29- Python 2.7 or Python >= 3.4 30- pip 31- `cysignals <https://pypi.python.org/pypi/cysignals/>`_ >= 1.7 32- Cython >= 0.28 33 34Install cypari2 via the Python Package Index (PyPI) via 35 36:: 37 38 $ pip install cypari2 [--user] 39 40(the optional option *--user* allows to install cypari2 for a single user 41and avoids using pip with administrator rights). Depending on your operating 42system the pip command might also be called pip2 or pip3. 43 44If you want to try the development version use 45 46:: 47 48 $ pip install git+https://github.com/sagemath/cypari2.git [--user] 49 50If you have an error saying libpari-gmp*.so* is missing and have all requirements 51already installed, try to reinstall cysignals and cypari2 52 53:: 54 55 $ pip install cysignals --upgrade [--user] 56 $ pip install cypari2 --upgrade [--user] 57 58Other 59^^^^^ 60 61Any other way to install cypari2 is not supported. In particular, ``python 62setup.py install`` will produce an error. 63 64Usage 65----- 66 67The interface as been kept as close as possible from PARI/GP. The following 68computation in GP 69 70:: 71 72 ? zeta(2) 73 %1 = 1.6449340668482264364724151666460251892 74 75 ? p = x^3 + x^2 + x - 1; 76 ? modulus = t^3 + t^2 + t - 1; 77 ? fq = factorff(p, 3, modulus); 78 ? centerlift(lift(fq)) 79 %5 = 80 [ x - t 1] 81 82 [x + (t^2 + t - 1) 1] 83 84 [ x + (-t^2 - 1) 1] 85 86translates into 87 88:: 89 90 >>> import cypari2 91 >>> pari = cypari2.Pari() 92 93 >>> pari(2).zeta() 94 1.64493406684823 95 96 >>> p = pari("x^3 + x^2 + x - 1") 97 >>> modulus = pari("t^3 + t^2 + t - 1") 98 >>> fq = p.factorff(3, modulus) 99 >>> fq.lift().centerlift() 100 [x - t, 1; x + (t^2 + t - 1), 1; x + (-t^2 - 1), 1] 101 102The object **pari** above is the object for the interface and acts as a 103constructor. It can be called with basic Python objects like integer 104or floating point. When called with a string as in the last example 105the corresponding string is interpreted as if it was executed in a GP shell. 106 107Beyond the interface object **pari** of type **Pari**, any object you get a 108handle on is of type **Gen** (that is a wrapper around the **GEN** type from 109libpari). All PARI/GP functions are then available in their original names as 110*methods* like **zeta**, **factorff**, **lift** or **centerlift** above. 111 112Alternatively, the pari functions are accessible as methods of **pari**. The 113same computations be done via 114 115:: 116 117 >>> import cypari2 118 >>> pari = cypari2.Pari() 119 120 >>> pari.zeta(2) 121 1.64493406684823 122 123 >>> p = pari("x^3 + x^2 + x - 1") 124 >>> modulus = pari("t^3 + t^2 + t - 1") 125 >>> fq = pari.factorff(p, 3, modulus) 126 >>> pari.centerlift(pari.lift(fq)) 127 [x - t, 1; x + (t^2 + t - 1), 1; x + (-t^2 - 1), 1] 128 129The complete documentation of cypari2 is available at http://cypari2.readthedocs.io and 130the PARI/GP documentation at http://pari.math.u-bordeaux.fr/doc.html 131 132Contributing 133------------ 134 135Submit pull request or get in touch with the SageMath developers. 136