5.3 PARI C-library interface

Module: sage.libs.pari.all

Author Log:

Module-level Functions

allocatemem( )

Double the PARI stack.

This doubles the stack for the PARI C library.

Class: pari_gen

class pari_gen
Python extension class that models the PARI GEN type.

Functions: abs,$  $ acos,$  $ acosh,$  $ adjoint,$  $ agm,$  $ algdep,$  $ arg,$  $ asin,$  $ asinh,$  $ atan,$  $ atanh,$  $ bernfrac,$  $ bernreal,$  $ bernvec,$  $ besselh1,$  $ besselh2,$  $ besseli,$  $ besselj,$  $ besseljh,$  $ besselk,$  $ besseln,$  $ bezout,$  $ binary,$  $ binomial,$  $ bitand,$  $ bitneg,$  $ bitnegimply,$  $ bitor,$  $ bittest,$  $ bitxor,$  $ bnfcertify,$  $ bnfinit,$  $ bnfisintnorm,$  $ bnfisprincipal,$  $ bnfnarrow,$  $ bnfunit,$  $ ceil,$  $ centerlift,$  $ changevar,$  $ charpoly,$  $ chinese,$  $ Col,$  $ component,$  $ concat,$  $ conj,$  $ conjvec,$  $ contfrac,$  $ copy,$  $ cos,$  $ cosh,$  $ cotan,$  $ denominator,$  $ deriv,$  $ dilog,$  $ dirzetak,$  $ disc,$  $ divrem,$  $ eint1,$  $ elladd,$  $ ellak,$  $ ellan,$  $ ellap,$  $ ellbil,$  $ ellchangecurve,$  $ ellchangepoint,$  $ elleisnum,$  $ elleta,$  $ ellglobalred,$  $ ellheight,$  $ ellheightmatrix,$  $ ellinit,$  $ ellisoncurve,$  $ ellj,$  $ elllocalred,$  $ elllseries,$  $ ellminimalmodel,$  $ ellorder,$  $ ellordinate,$  $ ellpointtoz,$  $ ellpow,$  $ ellrootno,$  $ ellsigma,$  $ ellsub,$  $ elltaniyama,$  $ elltors,$  $ ellwp,$  $ ellzeta,$  $ ellztopoint,$  $ erfc,$  $ eta,$  $ eval,$  $ exp,$  $ factor,$  $ factormod,$  $ factorpadic,$  $ floor,$  $ frac,$  $ gamma,$  $ gammah,$  $ gcd,$  $ getattr,$  $ hilbert,$  $ hyperu,$  $ idealadd,$  $ idealdiv,$  $ idealfactor,$  $ idealhnf,$  $ idealmul,$  $ idealnorm,$  $ idealtwoelt,$  $ idealval,$  $ imag,$  $ incgam,$  $ incgamc,$  $ int_unsafe,$  $ intformal,$  $ intvec_unsafe,$  $ ispower,$  $ isprime,$  $ issquare,$  $ issquarefree,$  $ j,$  $ kronecker,$  $ lcm,$  $ length,$  $ lex,$  $ lift,$  $ lindep,$  $ list,$  $ List,$  $ list_str,$  $ listinsert,$  $ listput,$  $ lllgram,$  $ lllgramint,$  $ lngamma,$  $ log,$  $ Mat,$  $ matadjoint,$  $ matfrobenius,$  $ mathnf,$  $ matker,$  $ matkerint,$  $ matsnf,$  $ mattranspose,$  $ max,$  $ min,$  $ Mod,$  $ ncols,$  $ newtonpoly,$  $ nextprime,$  $ nfbasis,$  $ nfgenerator,$  $ nfinit,$  $ norm,$  $ nrows,$  $ numdiv,$  $ numerator,$  $ numtoperm,$  $ omega,$  $ order,$  $ padicappr,$  $ padicprec,$  $ parent,$  $ permtonum,$  $ phi,$  $ Pol,$  $ polcoeff,$  $ polcompositum,$  $ poldegree,$  $ poldisc,$  $ poldiscreduced,$  $ polgalois,$  $ polhensellift,$  $ polinterpolate,$  $ polisirreducible,$  $ pollead,$  $ polrecip,$  $ polresultant,$  $ Polrev,$  $ polroots,$  $ polrootsmod,$  $ polrootspadic,$  $ polrootspadicfast,$  $ polsturm,$  $ polsylvestermatrix,$  $ polsym,$  $ polylog,$  $ precision,$  $ primepi,$  $ printtex,$  $ psi,$  $ python,$  $ python_list,$  $ python_list_small,$  $ Qfb,$  $ qflllgram,$  $ qfminim,$  $ qfrep,$  $ random,$  $ real,$  $ reverse,$  $ rnfcharpoly,$  $ rnfdisc,$  $ rnfeltabstorel,$  $ rnfeltreltoabs,$  $ rnfequation,$  $ rnfidealabstorel,$  $ rnfidealadd,$  $ rnfidealhnf,$  $ rnfidealnormrel,$  $ rnfidealreltoabs,$  $ rnfidealtwoelt,$  $ rnfinit,$  $ rnfisfree,$  $ round,$  $ Ser,$  $ serconvol,$  $ serlaplace,$  $ serreverse,$  $ Set,$  $ shift,$  $ shiftmul,$  $ sign,$  $ simplify,$  $ sin,$  $ sinh,$  $ sizebyte,$  $ sizedigit,$  $ sqr,$  $ sqrt,$  $ sqrtn,$  $ Str,$  $ Strchr,$  $ Strexpand,$  $ Strtex,$  $ subst,$  $ substpol,$  $ sumdiv,$  $ sumdivk,$  $ tan,$  $ tanh,$  $ taylor,$  $ teichmuller,$  $ theta,$  $ thetanullk,$  $ thue,$  $ thueinit,$  $ trace,$  $ transpose,$  $ truncate,$  $ type,$  $ valuation,$  $ variable,$  $ Vec,$  $ vecextract,$  $ vecmax,$  $ vecmin,$  $ Vecrev,$  $ Vecsmall,$  $ weber,$  $ xgcd,$  $ zeta,$  $ znprimroot

abs( )

Returns the absolute value of x (its modulus, if x is complex). Rational functions are not allowed. Contrary to most transcendental functions, an exact argument is not converted to a real number before applying abs and an exact result is returned if possible.

sage: x = pari("-27.1")
sage: x.abs()
27.10000000000000000000000000               # 32-bit
27.100000000000000000000000000000000000     # 64-bit

If x is a polynomial, returns -x if the leading coefficient is real and negative else returns x. For a power series, the constant coefficient is considered instead.

sage: pari('x-1.2*x^2').abs()
1.200000000000000000000000000*x^2 - x              # 32-bit
1.2000000000000000000000000000000000000*x^2 - x    # 64-bit

acos( )

The principal branch of $ \cos^{-1}(x)$ , so that $ \Re(\acos (x))$ belongs to $ [0,Pi]$ . If $ x$ is real and $ \vert x\vert > 1$ , then $ \acos (x)$ is complex.

sage: pari('0.5').acos()
1.047197551196597746154214461               # 32-bit
1.0471975511965977461542144610931676281     # 64-bit
sage: pari('1.1').acos()
-0.4435682543851151891329110664*I             # 32-bit
-0.44356825438511518913291106635249808665*I   # 64-bit
sage: pari('1.1+I').acos()
0.8493430542452523259630143655 - 1.097709866825328614547942343*I           
# 32-bit
0.84934305424525232596301436546298780187 -
1.0977098668253286145479423425784723444*I     # 64-bit

acosh( )

The principal branch of $ \cosh^{-1}(x)$ , so that $ \Im(\acosh (x))$ belongs to $ [0,Pi]$ . If $ x$ is real and $ x <
1$ , then $ \acosh (x)$ is complex.

sage: pari(2).acosh()
1.316957896924816708625046347              # 32-bit
1.3169578969248167086250463473079684440    # 64-bit
sage: pari(0).acosh()
1.570796326794896619231321692*I            # 32-bit
1.5707963267948966192313216916397514421*I  # 64-bit
sage: pari('I').acosh()
0.8813735870195430252326093250 + 1.570796326794896619231321692*I    #
32-bit
0.88137358701954302523260932497979230902 +
1.5707963267948966192313216916397514421*I   # 64-bit

agm( )

The arithmetic-geometric mean of x and y. In the case of complex or negative numbers, the principal square root is always chosen. p-adic or power series arguments are also allowed. Note that a p-adic AGM exists only if x/y is congruent to 1 modulo p (modulo 16 for p=2). x and y cannot both be vectors or matrices.

sage: pari('2').agm(2)                  
2.000000000000000000000000000             # 32-bit
2.0000000000000000000000000000000000000   # 64-bit
sage: pari('0').agm(1)
0
sage: pari('1').agm(2)
1.456791031046906869186432383             # 32-bit
1.4567910310469068691864323832650819750   # 64-bit
sage: pari('1+I').agm(-3)
-0.9647317222908759112270275374 + 1.157002829526317260939086020*I          
# 32-bit
-0.96473172229087591122702753739366831917 +
1.1570028295263172609390860195427517825*I    # 64-bit

algdep( )

sage: n = pari.get_real_precision()
sage: pari.set_real_precision (200)
sage: w1 = pari('z1=2-sqrt(26); (z1+I)/(z1-I)')
sage: f = w1.algdep(12); f
545*x^11 - 297*x^10 - 281*x^9 + 48*x^8 - 168*x^7 + 690*x^6 - 168*x^5 +
48*x^4 - 281*x^3 - 297*x^2 + 545*x    # 32-bit
3270*x^12 - 1782*x^11 - 1686*x^10 + 1378*x^9 - 2147*x^8 + 4965*x^7 -
2315*x^6 - 609*x^5 + 1362*x^4 - 531*x^3 - 1469*x^2 + 1883*x + 545   #
64-bit
sage: f(w1)
7.75513996 E-200 + 5.70672991 E-200*I     # 32-bit
1.8709440771032287632 E-208 + 1.4223313715139293357 E-209*I  # 64-bit
sage: f.factor()
[x, 1; x + 1, 2; x^2 + 1, 1; x^2 + x + 1, 1; 545*x^4 - 1932*x^3 + 2790*x^2
- 1932*x + 545, 1]
sage: pari.set_real_precision(n)

arg( )

arg(x): argument of x,such that $ -\pi < \arg(x) \leq \pi$ .

       sage: pari('2+I').arg()               
       0.4636476090008061162142562315              # 32-bit
0.46364760900080611621425623146121440203    # 64-bit

asin( )

The principal branch of $ \sin^{-1}(x)$ , so that $ \Re(\asin (x))$ belongs to $ [-\pi/2,\pi/2]$ . If $ x$ is real and $ \vert x\vert > 1$ then $ \asin (x)$ is complex.

sage: pari(pari(0.5).sin()).asin()
0.5000000000000000000000000000               # 32-bit
0.50000000000000000000000000000000000000     # 64-bit
sage: pari(2).asin()
1.570796326794896619231321692 + 1.316957896924816708625046347*I            
# 32-bit
1.5707963267948966192313216916397514421 +
1.3169578969248167086250463473079684440*I  # 64-bit

asinh( )

The principal branch of $ \sinh^{-1}(x)$ , so that $ \Im(\asinh (x))$ belongs to $ [-\pi/2,\pi/2]$ .

sage: pari(2).asinh()
1.443635475178810342493276740                # 32-bit
1.4436354751788103424932767402731052694      # 64-bit
sage: pari('2+I').asinh()
1.528570919480998161272456185 + 0.4270785863924761254806468833*I      #
32-bit
1.5285709194809981612724561847936733933 +
0.42707858639247612548064688331895685930*I      # 64-bit

atan( )

The principal branch of $ \tan^{-1}(x)$ , so that $ \Re(\atan (x))$ belongs to $ ]-\pi/2, \pi/2[$ .

sage: pari(1).atan()
0.7853981633974483096156608458              # 32-bit
0.78539816339744830961566084581987572104    # 64-bit
sage: pari('1.5+I').atan()
1.107148717794090503017065460 + 0.2554128118829953416027570482*I           
# 32-bit
1.1071487177940905030170654601785370401 +
0.25541281188299534160275704815183096744*I     # 64-bit

atanh( )

The principal branch of $ \tanh^{-1}(x)$ , so that $ \Im(\atanh (x))$ belongs to $ ]-\pi/2,\pi/2]$ . If $ x$ is real and $ \vert x\vert > 1$ then $ \atanh (x)$ is complex.

sage: pari(0).atanh()
0.E-250   # 32-bit
0.E-693   # 64-bit
sage: pari(2).atanh()
0.5493061443340548456976226185 + 1.570796326794896619231321692*I          
# 32-bit
0.54930614433405484569762261846126285232 +
1.5707963267948966192313216916397514421*I     # 64-bit

bernfrac( )

The Bernoulli number $ B_x$ , where $ B_0 = 1$ , $ B_1 = -1/2$ , $ B_2 = 1/6,\ldots,$ expressed as a rational number. The argument $ x$ should be of type integer.

sage: pari(18).bernfrac()
43867/798
sage: [pari(n).bernfrac() for n in range(10)]
[1, -1/2, 1/6, 0, -1/30, 0, 1/42, 0, -1/30, 0]

bernreal( )

The Bernoulli number $ B_x$ , as for the function bernfrac, but $ B_x$ is returned as a real number (with the current precision).

sage: pari(18).bernreal()
54.97117794486215538847117794                  # 32-bit
54.971177944862155388471177944862155388        # 64-bit

bernvec( )

Creates a vector containing, as rational numbers, the Bernoulli numbers $ B_0, B_2,\ldots, B_{2x}$ . This routine is obsolete. Use bernfrac instead each time you need a Bernoulli number in exact form.

Note: this routine is implemented using repeated independent calls to bernfrac, which is faster than the standard recursion in exact arithmetic.

sage: pari(8).bernvec()
[1, 1/6, -1/30, 1/42, -1/30, 5/66, -691/2730, 7/6, -3617/510]
sage: [pari(2*n).bernfrac() for n in range(9)]
[1, 1/6, -1/30, 1/42, -1/30, 5/66, -691/2730, 7/6, -3617/510]

besselh1( )

The $ H^1$ -Bessel function of index $ \nu$ and argument $ x$ .

sage: pari(2).besselh1(3)
0.4860912605858910769078310941 - 0.1604003934849237296757682995*I          
# 32-bit
0.48609126058589107690783109411498403480 -
0.16040039348492372967576829953798091810*I    # 64-bit

besselh2( )

The $ H^2$ -Bessel function of index $ \nu$ and argument $ x$ .

sage: pari(2).besselh2(3)
0.4860912605858910769078310941 + 0.1604003934849237296757682995*I          
# 32-bit
0.48609126058589107690783109411498403480 +
0.16040039348492372967576829953798091810*I     # 64-bit

besseli( )

Bessel I function (Bessel function of the second kind), with index $ u$ and argument $ x$ . If $ x$ converts to a power series, the initial factor $ (x/2)^{
u}/Gamma(
u+1)$ is omitted (since it cannot be represented in PARI when $ u$ is not integral).

sage: pari(2).besseli(3)
2.245212440929951154625478386              # 32-bit
2.2452124409299511546254783856342650577    # 64-bit
sage: pari(2).besseli('3+I')
1.125394076139128134398383103 + 2.083138226706609118835787255*I      #
32-bit
1.1253940761391281343983831028963896470 +
2.0831382267066091188357872547036161842*I    # 64-bit

besselj( )

Bessel J function (Bessel function of the first kind), with index $ \nu$ and argument $ x$ . If $ x$ converts to a power series, the initial factor $ (x/2)^{\nu}/\Gamma(\nu+1)$ is omitted (since it cannot be represented in PARI when $ \nu$ is not integral).

sage: pari(2).besselj(3)
0.4860912605858910769078310941            # 32-bit
0.48609126058589107690783109411498403480  # 64-bit

besseljh( )

J-Bessel function of half integral index (Speherical Bessel function of the first kind). More precisely, besseljh(n,x) computes $ J_{n+1/2}(x)$ where n must an integer, and x is any complex value. In the current implementation (PARI, version 2.2.11), this function is not very accurate when $ x$ is small.

sage: pari(2).besseljh(3)
0.4127100322097159934374967959      # 32-bit
0.41271003220971599343749679594186271499    # 64-bit

besselk( )

nu.besselk(x, flag=0): K-Bessel function (modified Bessel function of the second kind) of index nu, which can be complex, and argument x.

INPUT:
    nu -- a complex number
    x -- real number (positive or negative)
    flag -- default: 0 or 1: use hyperu  (hyperu is much slower for
            small x, and doesn't work for negative x).

WARNING/TODO - with flag = 1 this function is incredibly slow (on 64-bit Linux) as it is implemented using it from the C library, but it shouldn't be (e.g., it's not slow via the GP interface.) Why?

sage: pari('2+I').besselk(3)
0.04559077184075505871203211094 + 0.02891929465820812820828883526*I     #
32-bit
0.045590771840755058712032110938791854704 +
0.028919294658208128208288835257608789842*I     # 64-bit

sage: pari('2+I').besselk(-3)
-4.348708749867516799575863067 - 5.387448826971091267230878827*I        #
32-bit
-4.3487087498675167995758630674661864255 -
5.3874488269710912672308788273655523057*I  # 64-bit

sage: pari('2+I').besselk(300, flag=1)
3.742246033197275082909500148 E-132 + 2.490710626415252262644383350 E-134*I
# 32-bit
3.7422460331972750829095001475885825717 E-132 +
2.4907106264152522626443833495225745762 E-134*I   # 64-bit

besseln( )

nu.besseln(x): Bessel N function (Spherical Bessel function of the second kind) of index nu and argument x.

sage: pari('2+I').besseln(3)
-0.2807755669582439141676487005 - 0.4867085332237257928816949747*I     #
32-bit
-0.28077556695824391416764870046044688871 -
0.48670853322372579288169497466916637395*I    # 64-bit

binary( )

binary(x): gives the vector formed by the binary digits of abs(x), where x is of type t_INT.

INPUT:
    x -- gen of type t_INT
OUTPUT:
    gen -- of type t_VEC

sage: pari(0).binary()
[0]
sage: pari(-5).binary()
[1, 0, 1]
sage: pari(5).binary()
[1, 0, 1]
sage: pari(2005).binary()
[1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1]

sage: pari('"2"').binary()
Traceback (most recent call last):
...
TypeError: x (=2) must be of type t_INT, but is of type t_STR.

bitand( )

bitand(x,y): Bitwise and of two integers x and y. Negative numbers behave as if modulo some large power of 2.

INPUT:
    x -- gen  (of type t_INT)
    y -- coercible to gen  (of type t_INT)
OUTPUT:
    gen -- of type type t_INT

sage: pari(8).bitand(4)
0
sage: pari(8).bitand(8)
8
sage: pari(6).binary()
[1, 1, 0]
sage: pari(7).binary()
[1, 1, 1]
sage: pari(6).bitand(7)
6
sage: pari(19).bitand(-1)
19
sage: pari(-1).bitand(-1)
-1

bitneg( )

bitneg(x,n=-1): Bitwise negation of the integer x truncated to n bits. n=-1 (the default) represents an infinite sequence of the bit 1. Negative numbers behave as if modulo some large power of 2.

With n=-1, this function returns -n-1. With n >= 0, it returns a number a such that $ a\cong -n-1 \pmod{2^n}$ .

INPUT:
    x -- gen (t_INT)
    n -- long, default = -1
OUTPUT:
    gen -- t_INT

sage: pari(10).bitneg()
-11
sage: pari(1).bitneg()
-2
sage: pari(-2).bitneg()
1
sage: pari(-1).bitneg()
0
sage: pari(569).bitneg()
-570
sage: pari(569).bitneg(10)
454
sage: 454 % 2^10
454
sage: -570 % 2^10
454

bitnegimply( )

bitnegimply(x,y): Bitwise negated imply of two integers x and y, in other words, x BITAND BITNEG(y). Negative numbers behave as if modulo big power of 2.

INPUT:
    x -- gen  (of type t_INT)
    y -- coercible to gen  (of type t_INT)
OUTPUT:
    gen -- of type type t_INT

sage: pari(14).bitnegimply(0)    
14
sage: pari(8).bitnegimply(8)
0
sage: pari(8+4).bitnegimply(8)
4

bitor( )

bitor(x,y): Bitwise or of two integers x and y. Negative numbers behave as if modulo big power of 2.

INPUT:
    x -- gen  (of type t_INT)
    y -- coercible to gen  (of type t_INT)
OUTPUT:
    gen -- of type type t_INT

sage: pari(14).bitor(0)
14
sage: pari(8).bitor(4)
12
sage: pari(12).bitor(1)
13
sage: pari(13).bitor(1)
13

bittest( )

bittest(x, long n): Returns bit number n (coefficient of $ 2^n$ in binary) of the integer x. Negative numbers behave as if modulo a big power of 2.

INPUT:
   x -- gen (pari integer)
OUTPUT:
   bool -- a Python bool

sage: x = pari(6)
sage: x.bittest(0)
False
sage: x.bittest(1)
True
sage: x.bittest(2)
True
sage: x.bittest(3)
False
sage: pari(-3).bittest(0)
True
sage: pari(-3).bittest(1)
False
sage: [pari(-3).bittest(n) for n in range(10)]
[True, False, True, True, True, True, True, True, True, True]

bitxor( )

bitxor(x,y): Bitwise exclusive or of two integers x and y. Negative numbers behave as if modulo big power of 2.

INPUT:
    x -- gen  (of type t_INT)
    y -- coercible to gen  (of type t_INT)
OUTPUT:
    gen -- of type type t_INT

sage: pari(6).bitxor(4)
2
sage: pari(0).bitxor(4)
4
sage: pari(6).bitxor(0)
6

bnfcertify( )

bnf being as output by bnfinit, checks whether the result is correct, i.e. whether the calculation of the contents of self are correct without assuming the Generalized Riemann Hypothesis. If it is correct, the answer is 1. If not, the program may output some error message, but more probably will loop indefinitely. In no occasion can the program give a wrong answer (barring bugs of course): if the program answers 1, the answer is certified.

Note: WARNING! By default, most of the bnf routines depend on the correctness of a heuristic assumption which is stronger than GRH. In order to obtain a provably-correct result you must specify $ c=c_2=12$ for the technical optional parameters to the function. There are known counterexamples for smaller $ c$ (which is the default).

ceil( )

Return the smallest integer >= x.

INPUT:
   x -- gen
OUTPUT:
   gen -- integer

sage: pari(1.4).ceil()
2
sage: pari(-1.4).ceil()
-1
sage: pari('x').ceil()
x
sage: pari('x^2+5*x+2.2').ceil()
x^2 + 5*x + 2.200000000000000000000000000             # 32-bit
x^2 + 5*x + 2.2000000000000000000000000000000000000   # 64-bit
sage: pari('3/4').ceil()
1

centerlift( )

centerlift(x,v): Centered lift of x. This function returns exactly the same thing as lift, except if x is an integer mod.

INPUT:
    x -- gen
    v -- var (default: x)
OUTPUT:
    gen

sage: x = pari(-2).Mod(5)
sage: x.centerlift()
-2
sage: x.lift()
3
sage: f = pari('x-1').Mod('x^2 + 1')
sage: f.centerlift()
x - 1
sage: f.lift()
x - 1
sage: f = pari('x-y').Mod('x^2+1')
sage: f
Mod(x - y, x^2 + 1)
sage: f.centerlift('x')
x - y
sage: f.centerlift('y')
Mod(x - y, x^2 + 1)

changevar( )

changevar(gen x, y): change variables of x according to the vector y.

WARNING: This doesn't seem to work right at all in SAGE (!). Use with caution. *STRANGE*

INPUT:
    x -- gen
    y -- gen (or coercible to gen)
OUTPUT:
    gen

sage: pari('x^3+1').changevar(pari(['y']))
y^3 + 1

charpoly( )

charpoly(A,v=x,flag=0): det(v*Id-A) = characteristic polynomial of A using the comatrix. flag is optional and may be set to 1 (use Lagrange interpolation) or 2 (use Hessenberg form), 0 being the default.

Col( )

Col(x): Transforms the object x into a column vector.

The vector will have only one component, except in the following cases:

* When x is a vector or a quadratic form, the resulting vector is the initial object considered as a column vector.

* When x is a matrix, the resulting vector is the column of row vectors comprising the matrix.

* When x is a character string, the result is a column of individual characters.

* When x is a polynomial, the coefficients of the vector start with the leading coefficient of the polynomial.

* When x is a power series, only the significant coefficients are taken into account, but this time by increasing order of degree.

INPUT:
    x -- gen
OUTPUT:
    gen

sage: pari(1.5).Col()
[1.500000000000000000000000000]~               # 32-bit
[1.5000000000000000000000000000000000000]~     # 64-bit
sage: pari([1,2,3,4]).Col()
[1, 2, 3, 4]~
sage: pari('[1,2; 3,4]').Col()
[[1, 2], [3, 4]]~
sage: pari('"SAGE"').Col()
["S", "A", "G", "E"]~
sage: pari('3*x^3 + x').Col()
[3, 0, 1, 0]~
sage: pari('x + 3*x^3 + O(x^5)').Col()
[1, 0, 3, 0]~

component( )

component(x, long n): Return n'th component of the internal representation of x. This this function is 1-based instead of 0-based.

NOTE: For vectors or matrices, it is simpler to use x[n-1]. For list objects such as is output by nfinit, it is easier to use member functions.

INPUT:
    x -- gen
    n -- C long (coercible to)
OUTPUT:
    gen

sage: pari([0,1,2,3,4]).component(1)
0
sage: pari([0,1,2,3,4]).component(2)
1
sage: pari([0,1,2,3,4]).component(4)
3
sage: pari('x^3 + 2').component(1)
2
sage: pari('x^3 + 2').component(2)
0
sage: pari('x^3 + 2').component(4)
1

sage: pari('x').component(0)
Traceback (most recent call last):
...
PariError:  (8)

conj( )

conj(x): Return the algebraic conjugate of x.

INPUT:
    x -- gen
OUTPUT:
    gen

sage: pari('x+1').conj()
x + 1
sage: pari('x+I').conj()
x - I
sage: pari('1/(2*x+3*I)').conj()
1/(2*x - 3*I)
sage: pari([1,2,'2-I','Mod(x,x^2+1)', 'Mod(x,x^2-2)']).conj()
[1, 2, 2 + I, Mod(-x, x^2 + 1), Mod(-x, x^2 - 2)]
sage: pari('Mod(x,x^2-2)').conj()
Mod(-x, x^2 - 2)
sage: pari('Mod(x,x^3-3)').conj()
Traceback (most recent call last):
...
PariError: incorrect type (20)

conjvec( )

conjvec(x): Returns the vector of all conjugates of the algebraic number x. An algebraic number is a polynomial over Q modulo an irreducible polynomial.

INPUT:
    x -- gen
OUTPUT:
    gen

sage: pari('Mod(1+x,x^2-2)').conjvec()
[-0.4142135623730950488016887242, 2.414213562373095048801688724]~          
# 32-bit
[-0.41421356237309504880168872420969807857,
2.4142135623730950488016887242096980786]~     # 64-bit
sage: pari('Mod(x,x^3-3)').conjvec()
[1.442249570307408382321638311, -0.7211247851537041911608191554 +
1.249024766483406479413179544*I, -0.7211247851537041911608191554 -
1.249024766483406479413179544*I]~           # 32-bit
[1.4422495703074083823216383107801095884,
-0.72112478515370419116081915539005479419 +
1.2490247664834064794131795437632536350*I,
-0.72112478515370419116081915539005479419 -
1.2490247664834064794131795437632536350*I]~       # 64-bit

contfrac( )

contfrac(x,b,lmax): continued fraction expansion of x (x rational, real or rational function). b and lmax are both optional, where b is the vector of numerators of the continued fraction, and lmax is a bound for the number of terms in the continued fraction expansion.

cos( )

The cosine function.

       sage: x = pari('1.5')
       sage: x.cos()
       0.07073720166770291008818985142     # 32-bit
0.070737201667702910088189851434268709084    # 64-bit
       sage: pari('1+I').cos()
       0.8337300251311490488838853943 - 0.9888977057628650963821295409*I  
# 32-bit
       0.83373002513114904888388539433509447980 -
0.98889770576286509638212954089268618864*I   # 64-bit
       sage: pari('x+O(x^8)').cos()
       1 - 1/2*x^2 + 1/24*x^4 - 1/720*x^6 + 1/40320*x^8 + O(x^9)

cosh( )

The hyperbolic cosine function.

sage: x = pari('1.5')
sage: x.cosh()
2.352409615243247325767667965               # 32-bit
2.3524096152432473257676679654416441702     # 64-bit
sage: pari('1+I').cosh()
0.8337300251311490488838853943 + 0.9888977057628650963821295409*I          
# 32-bit
0.83373002513114904888388539433509447980 +
0.98889770576286509638212954089268618864*I   # 64-bit
sage: pari('x+O(x^8)').cosh()
1 + 1/2*x^2 + 1/24*x^4 + 1/720*x^6 + O(x^8)

cotan( )

The cotangent of x.

sage: pari(5).cotan()
-0.2958129155327455404277671681     # 32-bit
-0.29581291553274554042776716808248528607    # 64-bit

On a 32-bit computer computing the cotangent of $ \pi$ doesn't raise an error, but instead just returns a very large number. On a 64-bit computer it raises a RuntimeError.

       sage: pari('Pi').cotan()  
       1.980704062 E28                      # 32-bit
Traceback (most recent call last):   # 64-bit
       ...	                                 # 64-bit
       PariError: division by zero (46)     # 64-bit

denominator( )

denominator(x): Return the denominator of x. When x is a vector, this is the least common multiple of the denominators of the components of x.

what about poly?

INPUT:
    x -- gen
OUTPUT:
    gen

sage: pari('5/9').denominator()
9
sage: pari('(x+1)/(x-2)').denominator()
x - 2
sage: pari('2/3 + 5/8*x + 7/3*x^2 + 1/5*y').denominator()
1
sage: pari('2/3*x').denominator()
1
sage: pari('[2/3, 5/8, 7/3, 1/5]').denominator()
120

dilog( )

The principal branch of the dilogarithm of $ x$ , i.e. the analytic continuation of the power series $ \log_2(x) = \sum_{n>=1} x^n/n^2$ .

sage: pari(1).dilog()
1.644934066848226436472415167              # 32-bit
1.6449340668482264364724151666460251892    # 64-bit
sage: pari('1+I').dilog()
0.6168502750680849136771556875 + 1.460362116753119547679775739*I    #
32-bit
0.61685027506808491367715568749225944595 +
1.4603621167531195476797757394917875976*I   # 64-bit

disc( )

e.disc(): return the discriminant of the elliptic curve e.

sage: e = pari([0, -1, 1, -10, -20]).ellinit()
sage: e.disc()
-161051
sage: _.factor()
[-1, 1; 11, 5]

divrem( )

divrem(x, y, v): Euclidean division of x by y giving as a 2-dimensional column vector the quotient and the remainder, with respect to v (to main variable if v is omitted).

sage:

eint1( )

x.eint1(n): exponential integral E1(x):

$\displaystyle \int_{x}^{\infty} \frac{e^{-t}}{t} dt
$

If n is present, output the vector [eint1(x), eint1(2*x), ..., eint1(n*x)]. This is faster than repeatedly calling eint1(i*x).

REFERENCE: See page 262, Prop 5.6.12, of Cohen's book "A Course in Computational Algebraic Number Theory".

elladd( )

elladd(self, z0, z1)

Sum of the points z0 and z1 on this elliptic curve.

INPUT:
    self -- elliptic curve E
    z0 -- point on E
    z1 -- point on E
    
OUTPUT:
    point on E

First we create an elliptic curve:

sage: e = pari([0, 1, 1, -2, 0]).ellinit()
sage: str(e)[:65]   # first part of output
'[0, 1, 1, -2, 0, 4, -4, 1, -3, 112, -856, 389, 1404928/389, [0.90'

Next we add two points on the elliptic curve. Notice that the Python lists are automatically converted to PARI objects so you don't have to do that explicitly in your code.

sage: e.elladd([1,0,1], [-1,1,1])
[-3/4, -15/8]

ellak( )

e.ellak(n): Returns the coefficient $ a_n$ of the $ L$ -function of the elliptic curve e, i.e. the coefficient of a newform of weight 2 newform.

Note: The curve $ e$ must be a medium or long vector of the type given by ellinit. For this function to work for every n and not just those prime to the conductor, e must be a minimal Weierstrass equation. If this is not the case, use the function ellminimalmodel first before using ellak (or you will get INCORRECT RESULTS!)

INPUT:
    e -- a PARI elliptic curve.
    n -- integer ..

sage: e = pari([0, -1, 1, -10, -20]).ellinit()
sage: e.ellak(6)
2
sage: e.ellak(2005)        
2
sage: e.ellak(-1)
0
sage: e.ellak(0)
0

ellan( )

sage: e = pari([0, -1, 1, -10, -20]).ellinit()
sage: e.ellan(3)
[1, -2, -1]
sage: e.ellan(20)
[1, -2, -1, 2, 1, 2, -2, 0, -2, -2, 1, -2, 4, 4, -1, -4, -2, 4, 0, 2]
sage: e.ellan(-1)
[]

ellap( )

e.ellap(p): Returns the prime-indexed coefficient $ a_p$ of the $ L$ -function of the elliptic curve $ e$ , i.e. the coefficient of a newform of weight 2 newform.

Note: If p is not prime, this function will return an incorrect answer.

The curve e must be a medium or long vector of the type given by ellinit. For this function to work for every n and not just those prime to the conductor, e must be a minimal Weierstrass equation. If this is not the case, use the function ellminimalmodel first before using ellak (or you will get INCORRECT RESULTS!)

INPUT:
    e -- a PARI elliptic curve.
    p -- prime integer ..

sage: e = pari([0, -1, 1, -10, -20]).ellinit()
sage: e.ellap(2)
-2
sage: e.ellap(2003)
4
sage: e.ellak(-1)
0

ellbil( )

sage: e = pari([0,1,1,-2,0]).ellinit()
sage: e.ellbil([1, 0, 1], [-1, 1, 1])
0.4181889844988605856298894582              # 32-bit
 0.41818898449886058562988945821587638238   # 64-bit

ellchangecurve( )

sage: e = pari([1,2,3,4,5]).ellinit()
sage: e.ellglobalred()
[10351, [1, -1, 0, -1], 1]
sage: f = e.ellchangecurve([1,-1,0,-1])
sage: f[:5]
[1, -1, 0, 4, 3]

ellchangepoint( )

self.ellchangepoint(y): change data on point or vector of points self on an elliptic curve according to y=[u,r,s,t]

sage: e = pari([0,1,1,-2,0]).ellinit()
sage: x = pari([1,0,1])
sage: e.ellisoncurve([1,4,4])
False
sage: e.ellisoncurve(x)
True
sage: f = e.ellchangecurve([1,2,3,-1])
sage: f[:5]   # show only first five entries
[6, -2, -1, 17, 8]
sage: x.ellchangepoint([1,2,3,-1])
[-1, 4]
sage: f.ellisoncurve([-1,4])
True

elleisnum( )

om.elleisnum(k, flag=0, prec): om=[om1,om2] being a 2-component vector giving a basis of a lattice L and k an even positive integer, computes the numerical value of the Eisenstein series of weight k. When flag is non-zero and k=4 or 6, this gives g2 or g3 with the correct normalization.

INPUT:
    om -- gen, 2-component vector giving a basis of a lattice L
    k  -- int (even positive)
    flag -- int (default 0)
    pref -- precision

OUTPUT:
    gen -- numerical value of E_k

sage: e = pari([0,1,1,-2,0]).ellinit()
sage: om = e.omega()
sage: om
[2.490212560855055075321357792, 1.971737701551648204422407698*I]           
# 32-bit
[2.4902125608550550753213577919423024602,
1.9717377015516482044224076981513423349*I]   # 64-bit
sage: om.elleisnum(2)
-5.288649339654257621791534695              # 32-bit
-5.2886493396542576217915346952045657616    # 64-bit
sage: om.elleisnum(4)
112.0000000000000000000000000               # 32-bit
112.00000000000000000000000000000000000     # 64-bit
sage: om.elleisnum(100)
2.153142485760776361127070349 E50              # 32-bit
2.1531424857607763611270703492586704424 E50    # 64-bit

ellheightmatrix( )

ellheightmatrix(e,x)

Returns the height matrix for vector of points x on elliptic curve e using theta functions.

ellminimalmodel( )

ellminimalmodel(e): return the standard minimal integral model of the rational elliptic curve e and the corresponding change of variables.

INPUT:
    e -- gen (that defines an elliptic curve)
OUTPUT:
    gen -- minimal model
    gen -- change of coordinates

sage: e = pari([1,2,3,4,5]).ellinit()
sage: F, ch = e.ellminimalmodel()
sage: F[:5]
[1, -1, 0, 4, 3]
sage: ch
[1, -1, 0, -1]
sage: e.ellchangecurve(ch)[:5]
[1, -1, 0, 4, 3]

ellwp( )

ellwp(E, z,flag=0): Return the complex value of the Weierstrass P-function at z on the lattice defined by e.

INPUT:
    E -- list OR elliptic curve
          list -- [om1, om2], which are Z-generators for a lattice
          elliptic curve -- created using ellinit
           
    z -- (optional) complex number  OR string (default = "z")
           complex number -- any number in the complex plane
           string (or PARI variable) -- name of a variable.
         
    n -- int (optional: default 20) if z is a variable, compute up to at
least o(z^n).
    
    flag -- int: 0 (default): compute only P(z)
                 1 compute [P(z),P'(z)]
                 2 consider om or E as an elliptic curve and use P-function
to
                   compute the point on E (with the Weierstrass equation
for E)
                   P(z)
                   for that curve (identical to ellztopoint in this case).
            
OUTPUT:
    gen -- complex number or list of two complex numbers

We first define the elliptic curve X_0(11):

sage: E = pari([0,-1,1,-10,-20]).ellinit()

Compute P(1).

sage: E.ellwp(1)
13.96586952574849779469497770 + 1.465441833 E-249*I                       #
32-bit
13.965869525748497794694977695009324221 + 5.607702583566084181 E-693*I    #
64-bit

Compute P(1+I), where I = sqrt(-1).

sage: E.ellwp(pari("1+I"))
-1.115106825655550879209066492 + 2.334190523074698836184798794*I           
# 32-bit
-1.1151068256555508792090664916218413986 +
2.3341905230746988361847987936140321964*I   # 64-bit
sage: E.ellwp("1+I")
-1.115106825655550879209066492 + 2.334190523074698836184798794*I           
# 32-bit
-1.1151068256555508792090664916218413986 +
2.3341905230746988361847987936140321964*I   # 64-bit

The series expansion, to the default 20 precision:

sage: E.ellwp()
z^-2 + 31/15*z^2 + 2501/756*z^4 + 961/675*z^6 + 77531/41580*z^8 +
1202285717/928746000*z^10 + 2403461/2806650*z^12 +
30211462703/43418875500*z^14 + 3539374016033/7723451736000*z^16 +
413306031683977/1289540602350000*z^18 + O(z^20)

Compute the series for wp to lower precision:

sage: E.ellwp(n=4)
z^-2 + 31/15*z^2 + O(z^4)

Next we use the version where the input is generators for a lattice:

sage: pari(['1.2692', '0.63 + 1.45*I']).ellwp(1)
13.96561469366894364802003736 + 0.0006448292728105361474541633318*I        
# 32-bit
13.965614693668943648020037358850990554 +
0.00064482927281053614745416280316868200698*I    # 64-bit

With flag 1 compute the pair P(z) and P'(z):

sage: E.ellwp(1, flag=1)
[13.96586952574849779469497770 + 1.465441833 E-249*I,
50.56193008800727525558465690 + 4.46944479 E-249*I]    # 32-bit
[13.965869525748497794694977695009324221 + 5.607702583566084181 E-693*I,
50.561930088007275255584656898892400699 + 1.7102908181111172423 E-692*I]  
# 64-bit

With flag=2, the computed pair is (x,y) on the curve instead of [P(z),P'(z)]:

sage: E.ellwp(1, flag=2)
[14.29920285908183112802831103 + 1.465441833 E-249*I,
50.06193008800727525558465690 + 4.46944479 E-249*I]    # 32-bit
[14.299202859081831128028311028342657555 + 5.607702583566084181 E-693*I,
50.061930088007275255584656898892400699 + 1.7102908181111172423 E-692*I]  
# 64-bit

erfc( )

Return the complementary error function:

$\displaystyle (2/\sqrt{\pi}) \int_{x}^{\infty} e^{-t^2} dt.$

sage: pari(1).erfc()
0.1572992070502851306587793649                # 32-bit
0.15729920705028513065877936491739074070      # 64-bit

eta( )

x.eta(flag=0): if flag=0, $ \eta$ function without the $ q^{1/24}$ , otherwise $ \eta$ of the complex number $ x$ in the upper half plane intelligently computed using $ \SL (2,\mathbf{Z})$ transformations.

DETAILS: This functions computes the following. If the input $ x$ is a complex number with positive imaginary part, the result is $ \prod_{n=1}^{\infty} (q-1^n)$ , where $ q=e^{2 i \pi
x}$ . If $ x$ is a power series (or can be converted to a power series) with positive valuation, the result it $ \prod_{n=1}^{\infty} (1-x^n)$ .

sage: pari('I').eta()
0.9981290699259585132799623222             # 32-bit
0.99812906992595851327996232224527387813   # 64-bit

exp( )

x.exp(): exponential of x.

sage: pari(0).exp()
1.000000000000000000000000000               # 32-bit
1.0000000000000000000000000000000000000     # 64-bit
sage: pari(1).exp()
2.718281828459045235360287471               # 32-bit
2.7182818284590452353602874713526624978     # 64-bit
sage: pari('x+O(x^8)').exp()
1 + x + 1/2*x^2 + 1/6*x^3 + 1/24*x^4 + 1/120*x^5 + 1/720*x^6 + 1/5040*x^7 +
O(x^8)

factor( )

factor(x,lim): factorization of x. lim is optional and can be set whenever x is of (possibly recursive) rational type. If lim is set return partial factorization, using primes up to lim (up to primelimit if lim=0)

factormod( )

x.factormod(p,flag=0): factorization mod p of the polynomial x using Berlekamp. flag is optional, and can be 0: default or 1: simple factormod, same except that only the degrees of the irreducible factors are given.

factorpadic( )

self.factorpadic(p,r=20,flag=0): p-adic factorization of the polynomial x to precision r. flag is optional and may be set to 0 (use round 4) or 1 (use Buchmann-Lenstra)

floor( )

floor(x): Return the floor of x, which is the largest integer <= x. This function also works component-wise on polynomials, vectors, etc.

INPUT:
    x -- gen
OUTPUT:
    gen

sage: pari('5/9').floor()
0
sage: pari('11/9').floor()
1
sage: pari('1.17').floor()
1
sage: pari('x').floor()
x
sage: pari('x+1.5').floor()
x + 1.500000000000000000000000000             # 32-bit
x + 1.5000000000000000000000000000000000000   # 64-bit
sage: pari('[1.5,2.3,4.99]').floor()
[1, 2, 4]
sage: pari('[[1.1,2.2],[3.3,4.4]]').floor()
[[1, 2], [3, 4]]

sage: pari('"hello world"').floor()
Traceback (most recent call last):
...
PariError: incorrect type (20)

frac( )

frac(x): Return the fractional part of x, which is x - floor(x).

INPUT:
    x -- gen
OUTPUT:
    gen

sage: pari('1.7').frac()
0.7000000000000000000000000000            # 32-bit
0.70000000000000000000000000000000000000  # 64-bit
sage: pari('sqrt(2)').frac()
0.4142135623730950488016887242            # 32-bit
0.41421356237309504880168872420969807857  # 64-bit
sage: pari('sqrt(-2)').frac()
Traceback (most recent call last):
...
PariError: incorrect type (20)

gamma( )

s.gamma(precision): Gamma function at s.

INPUT:
    s -- gen (real or complex number
    precision -- optional precisiion

OUTPUT:
    gen -- value of the Gamma function at s.

sage: pari(2).gamma()
1.000000000000000000000000000              # 32-bit
1.0000000000000000000000000000000000000    # 64-bit
sage: pari(5).gamma()
24.00000000000000000000000000              # 32-bit
24.000000000000000000000000000000000000    # 64-bit
sage: pari('1+I').gamma()
0.4980156681183560427136911175 - 0.1549498283018106851249551305*I    #
32-bit
0.49801566811835604271369111746219809195 -
0.15494982830181068512495513048388660520*I    # 64-bit

gammah( )

x.gammah(): Gamma function evaluated at the argument x+1/2, for x an integer.

sage: pari(2).gammah()     
1.329340388179137020473625613               # 32-bit
1.3293403881791370204736256125058588871     # 64-bit
sage: pari(5).gammah()
52.34277778455352018114900849               # 32-bit
52.342777784553520181149008492418193679     # 64-bit
sage: pari('1+I').gammah()
0.5753151880634517207185443722 + 0.08821067754409390991246464371*I     #
32-bit
0.57531518806345172071854437217501119058 +
0.088210677544093909912464643706507454993*I     # 64-bit

gcd( )

gcd(x,y,flag=0): greatest common divisor of x and y. flag is optional, and can be 0: default, 1: use the modular gcd algorithm (x and y must be polynomials), 2 use the subresultant algorithm (x and y must be polynomials)

hyperu( )

a.hyperu(b,x): U-confluent hypergeometric function.

WARNING/TODO: This function is extremely slow as implemented when used from the C library. If you use the GP interpreter inteface it is vastly faster, so clearly this issue could be fixed with a better understanding of GP/PARI. Volunteers?

sage: pari(1).hyperu(2,3)
0.3333333333333333333333333333              # 32-bit
0.33333333333333333333333333333333333333    # 64-bit

imag( )

imag(x): Return the imaginary part of x. This function also works component-wise.

INPUT:
    x -- gen
OUTPUT:
    gen

sage: pari('1+2*I').imag()
2
sage: pari('sqrt(-2)').imag()
1.414213562373095048801688724              # 32-bit
1.4142135623730950488016887242096980786    # 64-bit
sage: pari('x+I').imag()
1
sage: pari('x+2*I').imag()
2
sage: pari('(1+I)*x^2+2*I').imag()
x^2 + 2
sage: pari('[1,2,3] + [4*I,5,6]').imag()
[4, 0, 0]

incgam( )

s.incgam(x, y, precision): incomplete gamma function. y is optional and is the precomputed value of gamma(s).

NOTE: This function works for any complex input (unlike in older version of PARI).

WARNING/TODO: This function is extremely slow as implemented when used from the C library. If you use the GP interpreter inteface it is vastly faster, so clearly this issue could be fixed with a better understanding of GP/PARI. Volunteers?

INPUT:
    s, x, y -- gens
    precision -- option precision

OUTPUT:
    gen -- value of the incomplete Gamma function at s.

sage: pari('1+I').incgam('3-I')
-0.04582978599199457259586742326 + 0.04336968187266766812050474478*I       
# 32-bit
-0.045829785991994572595867423261490338705 +
0.043369681872667668120504744775954724733*I    # 64-bit

incgamc( )

s.incgamc(x): complementary incomplete gamma function.

The arguments $ x$ and $ s$ are complex numbers such that $ s$ is not a pole of $ \Gamma$ and $ \vert x\vert/(\vert s\vert+1)$ is not much larger than $ 1$ (otherwise, the convergence is very slow). The function returns the value of the integral $ \int_{0}^{x}
e^{-t} t^{s-1} dt.$

sage: pari(1).incgamc(2)
0.8646647167633873081060005050               # 32-bit
0.86466471676338730810600050502751559659     # 64-bit

int_unsafe( )

Returns int form of self, but raises an exception if int does not fit into a long integer.

This is about 5 times faster than the usual int conversion.

intformal( )

x.intformal(y): formal integration of x with respect to the main variable of y, or to the main variable of x if y is omitted

intvec_unsafe( )

Returns Python int list form of entries of self, but raises an exception if int does not fit into a long integer. Here self must be a vector.

ispower( )

Determine whether or not self is a perfect k-th power. If k is not specified, find the largest k so that self is a k-th power.

NOTE: There is a BUG in the PARI C-library function (at least in PARI 2.2.12-beta) that is used to implement this function! This is in GP:

           ? p=nextprime(10^100); n=p^100; m=p^2; m^50==n; ispower(n,50)

INPUT:
    k -- int (optional)

OUTPUT:
    power -- int, what power it is
    g -- what it is a power of

sage: pari(9).ispower()
(2, 3)
sage: pari(17).ispower()
(1, 17)
sage: pari(17).ispower(2)
(False, None)
sage: pari(17).ispower(1)
(1, 17)
sage: pari(2).ispower()
(1, 2)

isprime( )

isprime(x, flag=0): Returns True if x is a PROVEN prime number, and False otherwise.

INPUT:
    flag -- int 
            0 (default): use a combination of algorithms.
            1: certify primality using the Pocklington-Lehmer Test.
            2: certify primality using the APRCL test.
OUTPUT:
    bool -- True or False

sage: pari(9).isprime()
False
sage: pari(17).isprime()
True
sage: n = pari(561)    # smallest Carmichael number
sage: n.isprime()      # not just a pseudo-primality test!
False
sage: n.isprime(1)
False
sage: n.isprime(2)
False

issquare( )

issquare(x,&n): true(1) if x is a square, false(0) if not. If find_root is given, also returns the exact square root if it was computed.

issquarefree( )

sage: pari(10).issquarefree()
True
sage: pari(20).issquarefree()
False

j( )

e.j(): return the j-invariant of the elliptic curve e.

sage: e = pari([0, -1, 1, -10, -20]).ellinit()
sage: e.j()
-122023936/161051
sage: _.factor()
[-1, 1; 2, 12; 11, -5; 31, 3]

lcm( )

Return the least common multiple of x and y.

sage: pari(10).lcm(15)
30

length( )

length(x): Return the number of non-code words in x. If x is a string, this is the number of characters of x.

?? terminator ?? carriage return ??

lex( )

lex(x,y): Compare x and y lexicographically (1 if x>y, 0 if x==y, -1 if x<y)

lift( )

lift(x,v): Returns the lift of an element of Z/nZ to Z or R[x]/(P) to R[x] for a type R if v is omitted. If v is given, lift only polymods with main variable v. If v does not occur in x, lift only intmods.

INPUT:
    x -- gen
    v -- (optional) variable
OUTPUT:
    gen

sage: x = pari("x")
sage: a = x.Mod('x^3 + 17*x + 3')
sage: a
Mod(x, x^3 + 17*x + 3)
sage: b = a^4; b
Mod(-17*x^2 - 3*x, x^3 + 17*x + 3)
sage: b.lift()
-17*x^2 - 3*x

??? more examples

List( )

List(x): transforms the PARI vector or list x into a list.

sage: v = pari([1,2,3])
sage: v
[1, 2, 3]
sage: v.type()
't_VEC'
sage: w = v.List()
sage: w
List([1, 2, 3])
sage: w.type()
't_LIST'

list_str( )

Return str that might correctly evaluate to a Python-list.

lngamma( )

x.lngamma(): logarithm of the gamma function of x.

This function returns the principal branch of the logarithm of the gamma function of $ x$ . The function $ \log(\Gamma(x))$ is analytic on the complex plane with non-positive integers removed. This function can have much larger inputs than $ \Gamma$ itself.

The $ p$ -adic analogue of this function is unfortunately not implemented.

sage: pari(100).lngamma()
359.1342053695753987760440105                # 32-bit
359.13420536957539877604401046028690961      # 64-bit

log( )

x.log(): natural logarithm of x.

This function returns the principal branch of the natural logarithm of $ x$ , i.e., the branch such that $ \Im(\log(x)) \in
]-\pi, \pi].$ The result is complex (with imaginary part equal to $ \pi$ ) if $ x\in \mathbf{R}$ and $ x<0$ . In general, the algorithm uses the formula

$\displaystyle \log(x) \simeq \frac{\pi}{2{\rm agm}(1,4/s)} - m\log(2),
$

if $ s=x 2^m$ is large enough. (The result is exact to $ B$ bits provided that $ s>2^{B/2}$ .) At low accuracies, this function computes $ \log$ using the series expansion near $ 1$ .

Note that $ p$ -adic arguments can also be given as input, with the convention that $ \log(p)=0$ . Hence, in particular, $ \exp(\log(x))/x$ is not in general equal to $ 1$ but instead to a $ (p-1)th$ root of unity (or $ \pm 1$ if $ p=2$ ) times a power of $ p$ .

sage: pari(5).log()
1.609437912434100374600759333                 # 32-bit
1.6094379124341003746007593332261876395       # 64-bit
sage: pari('I').log()
0.E-250 + 1.570796326794896619231321692*I             # 32-bit
0.E-693 + 1.5707963267948966192313216916397514421*I   # 64-bit

Mat( )

Mat(x): Returns the matrix defined by x.

* If x is already a matrix, a copy of x is created and returned.

* If x is not a vector or a matrix, this function returns a 1x1 matrix.

* If x is a row (resp. column) vector, this functions returns a 1-row (resp. 1-column) matrix, *unless* all elements are column (resp. row) vectors of the same length, in which case the vectors are concatenated sideways and the associated big matrix is returned.

INPUT:
    x -- gen
OUTPUT:
    gen -- a PARI matrix

sage: x = pari(5)
sage: x.type()
't_INT'
sage: y = x.Mat()
sage: y
Mat(5)
sage: y.type()
't_MAT'
sage: x = pari('[1,2;3,4]')
sage: x.type()
't_MAT'
sage: x = pari('[1,2,3,4]')
sage: x.type()
't_VEC'
sage: y = x.Mat()
sage: y
Mat([1, 2, 3, 4])
sage: y.type()
't_MAT'

sage: v = pari('[1,2;3,4]').Vec(); v
[[1, 3]~, [2, 4]~]
sage: v.Mat()
[1, 2; 3, 4]
sage: v = pari('[1,2;3,4]').Col(); v
[[1, 2], [3, 4]]~
sage: v.Mat()
[1, 2; 3, 4]

matadjoint( )

matadjoint(x): adjoint matrix of x.

matfrobenius( )

M.matfrobenius(flag=0): Return the Frobenius form of the square matrix M. If flag is 1, return only the elementary divisors (a list of polynomials). If flag is 2, return a two-components vector [F,B] where F is the Frobenius form and B is the basis change so that $ M=B^{-1} F B$ .

sage: a = pari('[1,2;3,4]')
sage: a.matfrobenius()
[0, 2; 1, 5]
sage: a.matfrobenius(flag=1)
[x^2 - 5*x - 2]
sage: a.matfrobenius(2)
[[0, 2; 1, 5], [1, -1/3; 0, 1/3]]
sage: v = a.matfrobenius(2)
sage: v[0]
[0, 2; 1, 5]
sage: v[1]^(-1)*v[0]*v[1]
[1, 2; 3, 4]

sage: T = ModularSymbols(43,sign=1).T(2).matrix()
sage: T
[ 3 -2  0  0]
[ 0 -2  0  1]
[ 0 -1 -2  2]
[ 0 -2  0  2]
sage: t = pari(T)
sage: t.matfrobenius()
[0, 0, 0, -12; 1, 0, 0, -2; 0, 1, 0, 8; 0, 0, 1, 1]
sage: T.charpoly()
x^4 - x^3 - 8*x^2 + 2*x + 12
sage: T.charpoly().factor()
(x - 3) * (x + 2) * (x^2 - 2)
sage: t.matfrobenius(1)
[x^4 - x^3 - 8*x^2 + 2*x + 12]

Author: 2006-04-02: Martin Albrecht

mathnf( )

A.mathnf(flag=0): (upper triangular) Hermite normal form of A, basis for the lattice formed by the columns of A. flag is optional whose value range from 0 to 4 (0 if omitted), meaning : 0: naive algorithm. 1: Use Batut's algorithm. Output 2-component vector [H,U] such that H is the HNF of A, and U is a unimodular matrix such that xU=H. 3: Use Batut's algorithm. Output [H,U,P] where P is a permutation matrix such that P A U = H. 4: as 1, using a heuristic variant of LLL reduction along the way.

matsnf( )

x.matsnf(flag=0): Smith normal form (i.e. elementary divisors) of the matrix x, expressed as a vector d. Binary digits of flag mean 1: returns [u,v,d] where d=u*x*v, otherwise only the diagonal d is returned, 2: allow polynomial entries, otherwise assume x is integral, 4: removes all information corresponding to entries equal to 1 in d.

max( )

max(x,y): Return the maximum of x and y.

min( )

min(x,y): Return the minumum of x and y.

Mod( )

Mod(x, y): Returns the object x modulo y, denoted Mod(x, y).

The input y must be a an integer or a polynomial:

* If y is an INTEGER, x must also be an integer, a rational number, or a p-adic number compatible with the modulus y.

* If y is a POLYNOMIAL, x must be a scalar (which is not a polmod), a polynomial, a rational function, or a power series.

WARNING: This function is not the same as x which is an integer or a polynomial.

INPUT:
    x -- gen
    y -- integer or polynomial

OUTPUT:
    gen -- intmod or polmod

sage: z = pari(3)
sage: x = z.Mod(pari(7))
sage: x
Mod(3, 7)
sage: x^2
Mod(2, 7)
sage: x^100
Mod(4, 7)
sage: x.type()
't_INTMOD'

sage: f = pari("x^2 + x + 1")
sage: g = pari("x")
sage: a = g.Mod(f)
sage: a
Mod(x, x^2 + x + 1)
sage: a*a
Mod(-x - 1, x^2 + x + 1)
sage: a.type()
't_POLMOD'

newtonpoly( )

self.newtonpoly(p): Newton polygon of polynomial x with respect to the prime p.

nextprime( )

nextprime(x): smallest pseudoprime >= x

numdiv( )

Return the number of divisors of the integer n.

sage: pari(10).numdiv()
4

numerator( )

numerator(x): Returns the numerator of x.

INPUT:
    x -- gen
OUTPUT:
    gen

numtoperm( )

numtoperm(k, n): Return the permutation number k (mod n!) of n letters, where n is an integer.

INPUT:
    k -- gen, integer
    n -- int
OUTPUT:
    gen -- vector (permutation of {1,...,n})

omega( )

e.omega(): return basis for the period lattice of the elliptic curve e.

sage: e = pari([0, -1, 1, -10, -20]).ellinit()
sage: e.omega()
[1.269209304279553421688794617, 0.6346046521397767108443973084 +
1.458816616938495229330889613*I]   # 32-bit
[1.2692093042795534216887946167545473052,
0.63460465213977671084439730837727365260 +
1.4588166169384952293308896129036752572*I]   # 64-bit

padicappr( )

x.padicappr(a): p-adic roots of the polynomial x congruent to a mod p

padicprec( )

padicprec(x,p): Return the absolute p-adic precision of the object x.

INPUT:
    x -- gen
OUTPUT:
    int

permtonum( )

permtonum(x): Return the ordinal (between 1 and n!) of permutation vector x. ??? Huh ??? say more. what is a perm vector. 0 to n-1 or 1-n.

INPUT:
    x -- gen (vector of integers)
OUTPUT:
    gen -- integer

phi( )

Return the Euler phi function of n.

sage: pari(10).phi()
4

Pol( )

Pol(x, v): convert x into a polynomial with main variable v and return the result.

* If x is a scalar, returns a constant polynomial.

* If x is a power series, the effect is identical to kbdtruncate, i.e. it chops off the $ O(X^k)$ .

* If x is a vector, this function creates the polynomial whose coefficients are given in x, with x[0] being the leading coefficient (which can be zero).

WARNING: This is *not* a substitution function. It will not transform an object containing variables of higher priority than v:

sage: pari('x+y').Pol('y')
Traceback (most recent call last):
...
PariError:  (8)

INPUT:
    x -- gen
    v -- (optional) which variable, defaults to 'x'
OUTPUT:
    gen -- a polynomial

sage: v = pari("[1,2,3,4]")
sage: f = v.Pol()
sage: f
x^3 + 2*x^2 + 3*x + 4
sage: f*f
x^6 + 4*x^5 + 10*x^4 + 20*x^3 + 25*x^2 + 24*x + 16

sage: v = pari("[1,2;3,4]")
sage: v.Pol()
[1, 3]~*x + [2, 4]~

polcoeff( )

sage: f = pari("x^2 + y^3 + x*y")
sage: f
x^2 + y*x + y^3
sage: f.polcoeff(1)
y
sage: f.polcoeff(3)
0
sage: f.polcoeff(3, "y")
1
sage: f.polcoeff(1, "y")
x

poldegree( )

f.poldegree(var=x): Return the degree of this polynomial.

poldisc( )

f.poldist(var=x): Return the discriminant of this polynomial.

polgalois( )

f.polgalois(): Galois group of the polynomial f

polhensellift( )

self.polhensellift(y, p, e): lift the factorization y of self modulo p to a factorization modulo $ p^e$ using Hensel lift. The factors in y must be pairwise relatively prime modulo p.

polinterpolate( )

self.polinterpolate(ya,x,&e): polynomial interpolation at x according to data vectors self, ya (i.e. return P such that P(self[i]) = ya[i] for all i). Also return an error estimate on the returned value.

polisirreducible( )

f.polisirreducible(): Returns True if f is an irreducible non-constant polynomial, or False if f is reducible or constant.

pollead( )

self.pollead(v): leading coefficient of polynomial or series self, or self itself if self is a scalar. Error otherwise. With respect to the main variable of self if v is omitted, with respect to the variable v otherwise

Polrev( )

Polrev(x, v): Convert x into a polynomial with main variable v and return the result. This is the reverse of Pol if x is a vector, otherwise it is identical to Pol. By "reverse" we mean that the coefficients are reversed.

INPUT:
    x -- gen
OUTPUT:
    gen -- a polynomial

sage: v = pari("[1,2,3,4]")
sage: f = v.Polrev()
sage: f
4*x^3 + 3*x^2 + 2*x + 1
sage: v.Pol()
x^3 + 2*x^2 + 3*x + 4
sage: v.Polrev('y')
4*y^3 + 3*y^2 + 2*y + 1

Note that Polrev does *not* reverse the coefficients of a polynomial!

sage: f
4*x^3 + 3*x^2 + 2*x + 1
sage: f.Polrev()
4*x^3 + 3*x^2 + 2*x + 1
sage: v = pari("[1,2;3,4]")
sage: v.Polrev()
[2, 4]~*x + [1, 3]~

polroots( )

polroots(x,flag=0): complex roots of the polynomial x. flag is optional, and can be 0: default, uses Schonhage's method modified by Gourdon, or 1: uses a modified Newton method.

polylog( )

x.polylog(m,flag=0): m-th polylogarithm of x. flag is optional, and can be 0: default, 1: D_m -modified m-th polylog of x, 2: D_m-modified m-th polylog of x, 3: P_m-modified m-th polylog of x.

TODO: Add more explanation, copied from the PARI manual.

sage: pari(10).polylog(3)
5.641811414751341250600725771 - 8.328202076980270580884185850*I            
# 32-bit
5.6418114147513412506007257705287671110 -
8.3282020769802705808841858505904310076*I      # 64-bit
sage: pari(10).polylog(3,0)
5.641811414751341250600725771 - 8.328202076980270580884185850*I            
# 32-bit
5.6418114147513412506007257705287671110 -
8.3282020769802705808841858505904310076*I      # 64-bit
sage: pari(10).polylog(3,1)
0.5237784535024110488342571116              # 32-bit
0.52377845350241104883425711161605950842    # 64-bit
sage: pari(10).polylog(3,2)
-0.4004590561634505605364328952             # 32-bit
-0.40045905616345056053643289522452400363   # 64-bit

precision( )

precision(x,n): Change the precision of x to be n, where n is a C-integer). If n is omitted, output the real precision of x.

INPUT:
    x -- gen
    n -- (optional) int
OUTPUT:
    nothing
  or
    gen if n is omitted

primepi( )

Return the number of primes $ \leq x$ .

sage: pari(7).primepi()
4
sage: pari(100).primepi()
25
sage: pari(1000).primepi()
168
sage: pari(100000).primepi()
9592

psi( )

x.psi(): psi-function at x.

Return the $ \psi$ -function of $ x$ , i.e., the logarithmic derivative $ \Gamma'(x)/\Gamma(x)$ .

sage: pari(1).psi()
-0.5772156649015328606065120901              # 32-bit
-0.57721566490153286060651209008240243104    # 64-bit

python( )

Return Python eval of self.

python_list( )

Return a Python list of the PARI gens. This object must be of type t_VEC

INPUT: None
OUTPUT:
   list -- Python list whose elements are the
           elements of the input gen.

sage: v=pari([1,2,3,10,102,10])
sage: w = v.python_list()
sage: w
[1, 2, 3, 10, 102, 10]
sage: type(w[0])
<type 'gen.gen'>

python_list_small( )

Return a Python list of the PARI gens. This object must be of type t_VECSMALL, and the resulting list contains python 'int's

sage: v=pari([1,2,3,10,102,10]).Vecsmall()
sage: w = v.python_list_small()
sage: w
[1, 2, 3, 10, 102, 10]
sage: type(w[0])
<type 'int'>

Qfb( )

Qfb(a,b,c,D=0.): Returns the binary quadratic form

$\displaystyle ax^2 + bxy + cy^2.
$

The optional D is 0 by default and initializes Shanks's distance if $ b^2 - 4ac > 0$ .

NOTE: Negative definite forms are not implemented, so use their positive definitine counterparts instead. (I.e., if f is a negative definite quadratic form, then -f is positive definite.)

INPUT:
    a -- gen
    b -- gen
    c -- gen
    D -- gen (optional, defaults to 0)
OUTPUT:
    gen -- binary quadratic form

sage: pari(3).Qfb(7, 2)
Qfb(3, 7, 2, 0.E-250)               # 32-bit
Qfb(3, 7, 2, 0.E-693)               # 64-bit

qflllgram( )

qflllgram(x,flag=0): LLL reduction of the lattice whose gram matrix is x (gives the unimodular transformation matrix). flag is optional and can be 0: default,1: lllgramint algorithm for integer matrices, 4: lllgramkerim giving the kernel and the LLL reduced image, 5: lllgramkerimgen same when the matrix has polynomial coefficients, 8: lllgramgen, same as qflllgram when the coefficients are polynomials.

qfminim( )

qfminim(x,bound,maxnum,flag=0): number of vectors of square norm <= bound, maximum norm and list of vectors for the integral and definite quadratic form x; minimal non-zero vectors if bound=0. flag is optional, and can be 0: default; 1: returns the first minimal vector found (ignore maxnum); 2: as 0 but uses a more robust, slower implementation, valid for non integral quadratic forms.

qfrep( )

qfrep(x,B,flag=0): vector of (half) the number of vectors of norms from 1 to B for the integral and definite quadratic form x. Binary digits of flag mean 1: count vectors of even norm from 1 to 2B, 2: return a t_VECSMALL instead of a t_VEC.

random( )

random({N=$ 2^31$ }): Return a pseudo-random integer between 0 and $ N-1$ .

INPUT:
    N -- gen, integer
OUTPUT:
    gen -- integer

real( )

real(x): Return the real part of x.

INPUT:
    x -- gen
OUTPUT:
    gen

reverse( )

Return the polynomial obtained by reversing the coefficients of this polynomial.

rnfinit( )

We construct a relative number field.

sage: f = pari('y^3+y+1')
sage: K = f.nfinit()
sage: x = pari('x'); y = pari('y')
sage: g = x^5 - x^2 + y
sage: L = K.rnfinit(g)

round( )

round(x,estimat=False): If x is a real number, returns x rounded to the nearest integer (rounding up). If the optional argument estimate is True, also returns the binary exponent e of the difference between the original and the rounded value (the "fractional part") (this is the integer ceiling of log_2(error)).

When x is a general PARI object, this function returns the result of rounding every coefficient at every level of PARI object. Note that this is different than what the truncate function does (see the example below).

One use of round is to get exact results after a long approximate computation, when theory tells you that the coefficients must be integers.

INPUT:
    x -- gen
    estimate -- (optional) bool, False by default
OUTPUT:
    * if estimate == False, return a single gen.
    * if estimate == True, return rounded verison of x and
      error estimate in bits, both as gens.

sage: pari('1.5').round()
2
sage: pari('1.5').round(True)
(2, -1)
sage: pari('1.5 + 2.1*I').round()
2 + 2*I
sage: pari('1.0001').round(True)
(1, -14)
sage: pari('(2.4*x^2 - 1.7)/x').round()
(2*x^2 - 2)/x
sage: pari('(2.4*x^2 - 1.7)/x').truncate()
2.400000000000000000000000000*x                # 32-bit
2.4000000000000000000000000000000000000*x      # 64-bit

Ser( )

Ser(x,v=x): Create a power series from x with main variable v and return the result.

* If x is a scalar, this gives a constant power series with precision given by the default series precision, as returned by get_series_precision().

* If x is a polynomial, the precision is the greatest of get_series_precision() and the degree of the polynomial.

* If x is a vector, the precision is similarly given, and the coefficients of the vector are understood to be the coefficients of the power series starting from the constant term (i.e. the reverse of the function Pol).

WARNING: This is *not* a substitution function. It will not transform an object containing variables of higher priority than v.

INPUT:
    x -- gen
    v -- PARI variable (default: x)
OUTPUT:
    gen -- PARI object of PARI type t_SER

sage: pari(2).Ser()
2 + O(x^16)
sage: x = pari([1,2,3,4,5])
sage: x.Ser()
1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 + O(x^5)
sage: f = x.Ser('v'); print f
1 + 2*v + 3*v^2 + 4*v^3 + 5*v^4 + O(v^5)
sage: pari(1)/f
1 - 2*v + v^2 + O(v^5)
sage: pari(1).Ser()
1 + O(x^16)

serreverse( )

serreverse(f): reversion of the power series f.

If f(t) is a series in t with valuation 1, find the series g(t) such that g(f(t)) = t.

Set( )

Set(x): convert x into a set, i.e. a row vector of strings in increasing lexicographic order.

INPUT:
    x -- gen
OUTPUT:
    gen -- a vector of strings in increasing lexicographic order.

sage: pari([1,5,2]).Set()
["1", "2", "5"]
sage: pari([]).Set()     # the empty set
[]
sage: pari([1,1,-1,-1,3,3]).Set()
["-1", "1", "3"]
sage: pari(1).Set()
["1"]
sage: pari('1/(x*y)').Set()
["1/(y*x)"]
sage: pari('["bc","ab","bc"]').Set()
["ab", "bc"]

shift( )

shift(x,n): shift x left n bits if n>=0, right -n bits if n<0.

shiftmul( )

shiftmul(x,n): Return the product of x by $ 2^n$ .

sign( )

sign(x): Return the sign of x, where x is of type integer, real or fraction.

simplify( )

simplify(x): Simplify the object x as much as possible, and return the result.

A complex or quadratic number whose imaginary part is an exact 0 (i.e., not an approximate one such as O(3) or 0.E-28) is converted to its real part, and a a polynomial of degree 0 is converted to its constant term. Simplification occurs recursively.

This function is useful before using arithmetic functions, which expect integer arguments:

sage: y = pari('y')
sage: x = pari('9') + y - y
sage: x
9
sage: x.type()
't_POL'
sage: x.factor()
matrix(0,2)
sage: pari('9').factor()
Mat([3, 2])
sage: x.simplify()
9
sage: x.simplify().factor()
Mat([3, 2])
sage: x = pari('1.5 + 0*I')
sage: x.type()
't_COMPLEX'
sage: x.simplify()
1.500000000000000000000000000                  # 32-bit
1.5000000000000000000000000000000000000        # 64-bit
sage: y = x.simplify()
sage: y.type()
't_REAL'

sin( )

x.sin(): The sine of x.

sage: pari(1).sin() 
0.8414709848078965066525023216             # 32-bit
0.84147098480789650665250232163029899962   # 64-bit
sage: pari('1+I').sin()
1.298457581415977294826042366 + 0.6349639147847361082550822030*I           
# 32-bit
1.2984575814159772948260423658078156203 +
0.63496391478473610825508220299150978151*I   # 64-bit

sinh( )

The hyperbolic sine function.

sage: pari(0).sinh()
0.E-250   # 32-bit
0.E-693   # 64-bit
sage: pari('1+I').sinh()
0.6349639147847361082550822030 + 1.298457581415977294826042366*I           
# 32-bit
0.63496391478473610825508220299150978151 +
1.2984575814159772948260423658078156203*I     # 64-bit

sizebyte( )

sizebyte(x): Return the total number of bytes occupied by the complete tree of the object x. Note that this number depends on whether the computer is 32-bit or 64-bit (see examples).

INPUT:
    x -- gen
OUTPUT:
    int (a Python int)

sage: pari('1').sizebyte()
12           # 32-bit
24           # 64-bit
sage: pari('10').sizebyte()
12           # 32-bit
24           # 64-bit
sage: pari('10000000000000').sizebyte()
16           # 32-bit
24           # 64-bit
sage: pari('10^100').sizebyte()
52           # 32-bit
64           # 64-bit
sage: pari('x').sizebyte()
36           # 32-bit
72           # 64-bit
sage: pari('x^20').sizebyte()
264          # 32-bit
528          # 64-bit
sage: pari('[x, 10^100]').sizebyte()
100          # 32-bit
160          # 64-bit

sizedigit( )

sizedigit(x): Return a quick estimate for the maximal number of decimal digits before the decimal point of any component of x.

INPUT:
    x -- gen
OUTPUT:
    int -- Python integer

sage: x = pari('10^100')
sage: x.Str().length()
101
sage: x.sizedigit()
101

Note that digits after the decimal point are ignored.

sage: x = pari('1.234')
sage: x
1.234000000000000000000000000              # 32-bit
1.2340000000000000000000000000000000000    # 64-bit
sage: x.sizedigit()
1

The estimate can be one too big:

sage: pari('7234.1').sizedigit()
4
sage: pari('9234.1').sizedigit()
5

sqr( )

x.sqr(): square of x. NOT identical to x*x.

TODO: copy extensive notes about this function from PARI manual. Put examples below.

sage: pari(2).sqr()
4

sqrt( )

x.sqrt(precision): The square root of x.

sage: pari(2).sqrt()
1.414213562373095048801688724               # 32-bit
1.4142135623730950488016887242096980786     # 64-bit

sqrtn( )

x.sqrtn(n): return the principal branch of the n-th root of x, i.e., the one such that $ \arg(\sqrt(x)) \in ]-\pi/n, \pi/n]$ . Also returns a second argument which is a suitable root of unity allowing one to recover all the other roots. If it was not possible to find such a number, then this second return value is 0. If the argument is present and no square root exists, return 0 instead of raising an error.

NOTE: intmods (modulo a prime) and $ p$ -adic numbers are allowed as arguments.

INPUT:
    x -- gen
    n -- integer
OUTPUT:
    gen -- principal n-th root of x
    gen -- z that gives the other roots

sage: s, z = pari(2).sqrtn(5)
sage: z
0.3090169943749474241022934172 + 0.9510565162951535721164393334*I          
# 32-bit
0.30901699437494742410229341718281905886 +
0.95105651629515357211643933337938214340*I     # 64-bit
sage: s
1.148698354997035006798626947               # 32-bit
1.1486983549970350067986269467779275894     # 64-bit
sage: s^5
2.000000000000000000000000000               # 32-bit
2.0000000000000000000000000000000000000     # 64-bit
sage: (s*z)^5
2.000000000000000000000000000 - 1.396701498 E-250*I                      #
32-bit
2.0000000000000000000000000000000000000 - 1.0689317613194482765 E-693*I  #
64-bit

Str( )

Str(self): Concatenate the entries of the vector self into a single string. If self is not a t_VEC its print representation is returned.

INPUT:
    self -- gen
OUTPUT:
    gen -- a PARI gen of type t_STR, i.e., a PARI string

sage: pari([1,2,['abc',1]]).Str()
12[abc, 1]
sage: pari('[1,1, 1.54]').Str()
111.540000000000000000000000000              # 32-bit
111.5400000000000000000000000000000000000    # 64-bit
sage: pari('[1, 1.54, 1]').Str()
11.5400000000000000000000000001              # 32-bit
11.54000000000000000000000000000000000001    # 64-bit
sage: pari(1).Str()       # 1 is automatically converted to string rep
1
sage: x = pari('x')       # PARI variable "x"
sage: x.Str()             # is converted to string rep.
x
sage: x.Str().type()
't_STR'

Strchr( )

Strchr(x): converts x to a string, translating each integer into a character (in ASCII).

NOTE: Vecsmall is (essentially) the inverse to Strchr().

INPUT:
    x -- PARI vector of integers
OUTPUT:
    gen -- a PARI string

sage: pari([65,66,123]).Strchr()
AB{
sage: pari('"SAGE"').Vecsmall()   # pari('"SAGE"') --> PARI t_STR
Vecsmall([83, 65, 71, 69])
sage: _.Strchr()
SAGE
sage: pari([83, 65, 71, 69]).Strchr()
SAGE

Strexpand( )

Strexpand(x): Concatenate the entries of the vector x into a single string, performing tilde expansion.

NOTE: I have no clue what the point of this function is. - William

Strtex( )

Strtex(x): Translates the vector x of PARI gens to TeX format and returns the resulting concatenated strings as a PARI t_STR.

INPUT:
    x -- gen
OUTPUT:
    gen -- PARI t_STR (string)

sage: v=pari('x^2')
sage: v.Strtex()
x^2
sage: v=pari(['1/x^2','x'])
sage: v.Strtex()
\frac{1}{x^2}x
sage: v=pari(['1 + 1/x + 1/(y+1)','x-1'])
sage: v.Strtex()
\frac{ \left(y
 + 2\right)  x
 + \left(y
 + 1\right) }{ \left(y
 + 1\right)  x}x
 - 1

subst( )

sage: x = pari("x"); y = pari("y")
sage: f = pari('x^3 + 17*x + 3')
sage: f.subst(x, y)
y^3 + 17*y + 3
sage: f.subst(x, "z")
z^3 + 17*z + 3
sage: f.subst(x, "z")^2
z^6 + 34*z^4 + 6*z^3 + 289*z^2 + 102*z + 9
sage: f.subst(x, "x+1")
x^3 + 3*x^2 + 20*x + 21
sage: f.subst(x, "xyz")
xyz^3 + 17*xyz + 3
sage: f.subst(x, "xyz")^2
xyz^6 + 34*xyz^4 + 6*xyz^3 + 289*xyz^2 + 102*xyz + 9

sumdiv( )

Return the sum of the divisors of $ n$ .

sage: pari(10).sumdiv()
18

sumdivk( )

Return the sum of the k-th powers of the divisors of n.

sage: pari(10).sumdivk(2)
130

tan( )

x.tan() - tangent of x

sage: pari(2).tan()
-2.185039863261518991643306102                   # 32-bit
-2.1850398632615189916433061023136825434         # 64-bit
sage: pari('I').tan()
0.E-250 + 0.7615941559557648881194582826*I            # 32-bit
0.E-693 + 0.76159415595576488811945828260479359041*I  # 64-bit

tanh( )

x.tanh() - hyperbolic tangent of x

sage: pari(1).tanh()
0.7615941559557648881194582826             # 32-bit
0.76159415595576488811945828260479359041   # 64-bit
sage: pari('I').tanh()
0.E-250 + 1.557407724654902230506974807*I              # 32-bit
-5.344658806597241382 E-694 + 1.5574077246549022305069748074583601731*I  #
64-bit

teichmuller( )

teichmuller(x): teichmuller character of p-adic number x.

This is the unique $ (p-1)$ th root of unity congruent to $ x/p^{v_p(x)}$ modulo $ p$ .

sage: pari('2+O(7^5)').teichmuller()
2 + 4*7 + 6*7^2 + 3*7^3 + O(7^5)

theta( )

q.theta(z): Jacobi sine theta-function.

sage: pari(0.5).theta(2)
1.632025902952598833772353216               # 32-bit
1.6320259029525988337723532162682089972     # 64-bit

thetanullk( )

q.thetanullk(k): return the k-th derivative at z=0 of theta(q,z)

sage: pari(0.5).thetanullk(1)
0.5489785325603405618549383537             # 32-bit
0.54897853256034056185493835370857284861   # 64-bit

truncate( )

truncate(x,estimate=False): Return the truncation of x. If estimate is True, also return the number of error bits.

When x is in the real numbers, this means that the part after the decimal point is chopped away, e is the binary exponent of the difference between the original and truncated value (the "fractional part"). If x is a rational function, the result is the integer part (Euclidean quotient of numerator by denominator) and if requested the error estimate is 0.

When truncate is applied to a power series (in X), it transforms it into a polynomial or a rational function with denominator a power of X, by chopping away the $ O(X^k)$ . Similarly, when applied to a p-adic number, it transforms it into an integer or a rational number by chopping away the $ O(p^k)$ .

INPUT:
    x -- gen
    estimate -- (optional) bool, which is False by default
OUTPUT:
    * if estimate == False, return a single gen.
    * if estimate == True, return rounded verison of x and
      error estimate in bits, both as gens.
OUTPUT:

sage: pari('(x^2+1)/x').round()
(x^2 + 1)/x
sage: pari('(x^2+1)/x').truncate()
x
sage: pari('1.043').truncate()
1
sage: pari('1.043').truncate(True)
(1, -5)
sage: pari('1.6').truncate()
1
sage: pari('1.6').round()
2
sage: pari('1/3 + 2 + 3^2 + O(3^3)').truncate()
34/3
sage: pari('sin(x+O(x^10))').truncate()
1/362880*x^9 - 1/5040*x^7 + 1/120*x^5 - 1/6*x^3 + x
sage: pari('sin(x+O(x^10))').round()   # each coefficient has abs < 1
x + O(x^10)

valuation( )

valuation(x,p): Return the valuation of x with respect to p.

The valuation is the highest exponent of p dividing x.

* If p is an integer, x must be an integer, an intmod whose modulus is divisible by p, a rational number, a p-adic number, or a polynomial or power series in which case the valuation is the minimal of the valuations of the coefficients.

* If p is a polynomial, x must be a polynomial or a rational fucntion. If p is a monomial then x may also be a power series.

* If x is a vector, complex or quadratic number, then the valuation is the minimum of the component valuations.

* If x = 0, the result is $ 2^31-1$ on 32-bit machines or $ 2^63-1$ on 64-bit machines if x is an exact object. If x is a p-adic number or power series, the result is the exponent of the zero.

INPUT:
    x -- gen
    p -- coercible to gen
OUTPUT:
    gen -- integer

sage: pari(9).valuation(3)
2
sage: pari(9).valuation(9)
1
sage: x = pari(9).Mod(27); x.valuation(3)
2
sage: pari('5/3').valuation(3)
-1
sage: pari('9 + 3*x + 15*x^2').valuation(3)
1
sage: pari([9,3,15]).valuation(3)
1
sage: pari('9 + 3*x + 15*x^2 + O(x^5)').valuation(3)
1

sage: pari('x^2*(x+1)^3').valuation(pari('x+1'))
3
sage: pari('x + O(x^5)').valuation('x')
1
sage: pari('2*x^2 + O(x^5)').valuation('x')
2

sage: pari(0).valuation(3)   
2147483647            # 32-bit
9223372036854775807   # 64-bit

variable( )

variable(x): Return the main variable of the object x, or p if x is a p-adic number.

This function raises a TypeError exception on scalars, i.e., on objects with no variable associated to them.

INPUT:
    x -- gen 
OUTPUT:
    gen

sage: pari('x^2 + x -2').variable()
x
sage: pari('1+2^3 + O(2^5)').variable()
2
sage: pari('x+y0').variable()
x
sage: pari('y0+z0').variable()
y0

Vec( )

Vec(x): Transforms the object x into a vector.

INPUT:
    x -- gen
OUTPUT:
    gen -- of PARI type t_VEC

sage: pari(1).Vec()
[1]
sage: pari('x^3').Vec()
[1, 0, 0, 0]
sage: pari('x^3 + 3*x - 2').Vec()
[1, 0, 3, -2]
sage: pari([1,2,3]).Vec()
[1, 2, 3]
sage: pari('ab').Vec()
[1, 0]

vecextract( )

self.vecextract(y,z): extraction of the components of the matrix or vector x according to y and z. If z is omitted, y designates columns, otherwise y corresponds to rows and z to columns. y and z can be vectors (of indices), strings (indicating ranges as in"1..10") or masks (integers whose binary representation indicates the indices to extract, from left to right 1, 2, 4, 8, etc.)

Note: This function uses the PARI row and column indexing, so the first row or column is indexed by 1 instead of 0.

vecmax( )

vecmax(x): Return the maximum of the elements of the vector/matrix x,

vecmin( )

vecmin(x): Return the maximum of the elements of the vector/matrix x,

Vecrev( )

Vecrev(x): Transforms the object x into a vector. Identical to Vec(x) except when x is - a polynomial, this is the reverse of Vec. - a power series, this includes low-order zero coefficients. - a laurant series, raises an exception

INPUT:
    x -- gen
OUTPUT:
    gen -- of PARI type t_VEC

sage: pari(1).Vecrev()
[1]
sage: pari('x^3').Vecrev()
[0, 0, 0, 1]
sage: pari('x^3 + 3*x - 2').Vecrev()
[-2, 3, 0, 1]
sage: pari([1, 2, 3]).Vecrev()
[1, 2, 3]
sage: pari('Col([1, 2, 3])').Vecrev()
[1, 2, 3]
sage: pari('[1, 2; 3, 4]').Vecrev()
[[1, 3]~, [2, 4]~]
sage: pari('ab').Vecrev()
[0, 1]
sage: pari('x^2 + 3*x^3 + O(x^5)').Vecrev()
[0, 0, 1, 3, 0]
sage: pari('x^-2 + 3*x^3 + O(x^5)').Vecrev()
Traceback (most recent call last):
...
ValueError: Vecrev() is not defined for Laurent series

Vecsmall( )

Vecsmall(x): transforms the object x into a t_VECSMALL.

INPUT:
    x -- gen
OUTPUT:
    gen -- PARI t_VECSMALL

sage: pari([1,2,3]).Vecsmall()
Vecsmall([1, 2, 3])
sage: pari('"SAGE"').Vecsmall()
Vecsmall([83, 65, 71, 69])
sage: pari(1234).Vecsmall()
Vecsmall([1234])

weber( )

x.weber(flag=0): One of Weber's f function of x. flag is optional, and can be 0: default, function f(x)=exp(-i*Pi/24)*eta((x+1)/2)/eta(x) such that $ j=(f^{24}-16)^3/f^{24}$ , 1: function f1(x)=eta(x/2)/eta(x) such that $ j=(f1^24+16)^3/f2^{24}$ , 2: function f2(x)=sqrt(2)*eta(2*x)/eta(x) such that $ j=(f2^{24}+16)^3/f2^{24}$ .

TODO: Add further explanation from PARI manual.

sage: pari('I').weber()
1.189207115002721066717499971 - 6.98350749 E-251*I     # 32-bit
1.1892071150027210667174999705604759153 + 0.E-693*I    # 64-bit
sage: pari('I').weber(1)    
1.090507732665257659207010656             # 32-bit
1.0905077326652576592070106557607079790   # 64-bit
sage: pari('I').weber(2)
1.090507732665257659207010656             # 32-bit
1.0905077326652576592070106557607079790   # 64-bit

xgcd( )

Returns u,v,d such that d=gcd(x,y) and u*x+v*y=d.

sage: pari(10).xgcd(15)
(5, -1, 1)

zeta( )

zeta(s): Riemann zeta function at s with s a complex or a p-adic number.

TODO: Add extensive explanation from PARI user's manual.

INPUT:
    s -- gen (real or complex number)

OUTPUT:
    gen -- value of zeta at s.

sage: pari(2).zeta()
1.644934066848226436472415167             # 32-bit
1.6449340668482264364724151666460251892   # 64-bit
sage: pari('Pi^2/6')
1.644934066848226436472415167             # 32-bit
1.6449340668482264364724151666460251892   # 64-bit
sage: pari(3).zeta()
1.202056903159594285399738162             # 32-bit
1.2020569031595942853997381615114499908   # 64-bit

Special Functions: __abs__,$  $ __add__,$  $ __bool__,$  $ __call__,$  $ __cmp__,$  $ __delitem__,$  $ __div__,$  $ __eq__,$  $ __float__,$  $ __ge__,$  $ __getitem__,$  $ __getslice__,$  $ __gt__,$  $ __hex__,$  $ __int__,$  $ __invert__,$  $ __le__,$  $ __len__,$  $ __long__,$  $ __lshift__,$  $ __lt__,$  $ __mod__,$  $ __mul__,$  $ __ne__,$  $ __neg__,$  $ __pow__,$  $ __radd__,$  $ __rdiv__,$  $ __reduce__,$  $ __repr__,$  $ __rlshift__,$  $ __rmod__,$  $ __rmul__,$  $ __rpow__,$  $ __rrshift__,$  $ __rshift__,$  $ __rsub__,$  $ __setitem__,$  $ __sub__,$  $ _add,$  $ _div,$  $ _eval_,$  $ _mod,$  $ _mul,$  $ _sage_,$  $ _sub,$  $ _testclass

_sage_( )

Return SAGE version of self.

Class: PariError

class PariError

Functions: errmessage

errmessage( RuntimeError)
staticmethod(function) -> method

Convert a function to be a static method.

A static method does not receive an implicit first argument. To declare a static method, use this idiom:

class C: def f(arg1, arg2, ...): ... f = staticmethod(f)

It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). The instance is ignored except for its class.

Static methods in Python are similar to those found in Java or C++. For a more advanced concept, see the classmethod builtin.

Special Functions: __repr__,$  $ __str__

See About this document... for information on suggesting changes.