14.3.1.1 gen Objects

class gen
Python extension class that models the PARI GEN type.
Instances of class gen have the following methods (in addition to inherited methods and special methods):

abs,$  $ acos,$  $ acosh,$  $ agm,$  $ algdep,$  $ arg,$  $ asin,$  $ asinh,$  $ atan,$  $ atanh,$  $ bernfrac,$  $ bernreal,$  $ bernvec,$  $ besselh1,$  $ besselh2,$  $ besseli,$  $ besselj,$  $ besseljh,$  $ besselk,$  $ besselk2,$  $ besseln,$  $ bezout,$  $ binary,$  $ bitand,$  $ bitneg,$  $ bitnegimply,$  $ bitor,$  $ bittest,$  $ bitxor,$  $ bnfinit,$  $ bnfunit,$  $ ceil,$  $ centerlift,$  $ changevar,$  $ charpoly,$  $ chinese,$  $ Col,$  $ component,$  $ concat,$  $ conj,$  $ conjvec,$  $ contfrac,$  $ copy,$  $ cos,$  $ cosh,$  $ cotan,$  $ denominator,$  $ deriv,$  $ dilog,$  $ 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,$  $ hyperu,$  $ idealfactor,$  $ imag,$  $ incgam,$  $ incgamc,$  $ int_unsafe,$  $ intformal,$  $ intvec_unsafe,$  $ isprime,$  $ issquare,$  $ issquarefree,$  $ j,$  $ kronecker,$  $ lcm,$  $ length,$  $ lex,$  $ lift,$  $ lindep,$  $ list,$  $ List,$  $ list_str,$  $ listinsert,$  $ listput,$  $ lngamma,$  $ log,$  $ Mat,$  $ mathnf,$  $ matker,$  $ matkerint,$  $ matsnf,$  $ mattranspose,$  $ max,$  $ min,$  $ Mod,$  $ ncols,$  $ nextprime,$  $ nfbasis,$  $ nfgenerator,$  $ nfinit,$  $ norm,$  $ nrows,$  $ numdiv,$  $ numerator,$  $ numtoperm,$  $ omega,$  $ order,$  $ padicappr,$  $ padicprec,$  $ parent,$  $ permtonum,$  $ Pol,$  $ polcoeff,$  $ polcompositum,$  $ poldegree,$  $ poldisc,$  $ poldiscreduced,$  $ polgalois,$  $ polhensellift,$  $ polinterpolate,$  $ polisirreducible,$  $ pollead,$  $ polrecip,$  $ polresultant,$  $ Polrev,$  $ polroots,$  $ polrootsmod,$  $ polrootspadic,$  $ polrootspadicfast,$  $ polsturm,$  $ polsylvestermatrix,$  $ polsym,$  $ polylog,$  $ precision,$  $ printtex,$  $ psi,$  $ python,$  $ python_list,$  $ Qfb,$  $ random,$  $ real,$  $ reverse,$  $ rnfinit,$  $ round,$  $ Ser,$  $ serconvol,$  $ serlaplace,$  $ serreverse,$  $ Set,$  $ shift,$  $ shiftmul,$  $ sign,$  $ simplify,$  $ sin,$  $ sinh,$  $ sizebyte,$  $ sizedigit,$  $ sqr,$  $ sqrt,$  $ sqrtn,$  $ Str,$  $ Strchr,$  $ Strexpand,$  $ Strtex,$  $ subst,$  $ substpol,$  $ tan,$  $ tanh,$  $ taylor,$  $ teichmuller,$  $ theta,$  $ thetanullk,$  $ thue,$  $ thueinit,$  $ trace,$  $ transpose,$  $ truncate,$  $ type,$  $ valuation,$  $ variable,$  $ Vec,$  $ vecextract,$  $ vecmax,$  $ vecmin,$  $ Vecsmall,$  $ weber,$  $ xgcd,$  $ zeta,$  $ znprimroot

Further documentation:

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

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

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
sage: pari(1.1).acos()
-0.4435682543851151891329110664*I
sage: pari('1.1+I').acos()
0.8493430542452523259630143655 - 1.097709866825328614547942343*I

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
sage: pari(0).acosh()
1.570796326794896619231321692*I
sage: pari('I').acosh()
0.8813735870195430252326093250 + 1.570796326794896619231321692*I

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
sage: pari('0').agm(1)
0
sage: pari('1').agm(2)
1.456791031046906869186432383
sage: pari('1+I').agm(-3)
-0.9647317222908759112270275373 + 1.157002829526317260939086020*I

arg( )

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

sage: pari('2+I').arg()
0.4636476090008061162142562315

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
sage: pari(2).asin()
1.570796326794896619231321692 + 1.316957896924816708625046347*I

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
sage: pari('2+I').asinh()
1.528570919480998161272456185 + 0.4270785863924761254806468833*I

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
sage: pari('1.5+I').atan()
1.107148717794090503017065460 + 0.2554128118829953416027570482*I

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-28
sage: pari(2).atanh()
0.5493061443340548456976226185 + 1.570796326794896619231321692*I

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

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

besselh2( )

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

sage: pari(2).besselh2(3)
0.4860912605858910769078310941 + 0.1604003934849237296757682995*I

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
sage: pari(2).besseli('3+I')
1.125394076139128134398383103 + 2.083138226706609118835787255*I

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

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.4127100322097159934

besselk( )

K-Bessel function (modified Bessel function of the second kind) of index nu, which can be complex, and argument x. Only positive real positive arguments x are allowed in the current implementation (Pari version 2.2.11).

sage: pari('2+I').besselk(3)
0.04559077184075505871203211094 + 0.02891929465820812820828883526*I

besselk2( )

A different implementation of this besselk() which is faster when x » 1. Values of x are limited as for besselk().

sage: pari('2+I').besselk2(3)
0.04559077184075505871203211094 + 0.02891929465820812820828883526*I

besseln( )

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

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

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
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]~
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):
...
RuntimeError

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):
...
TypeError: x (=Mod(x, x^3 - 3)) has no conjugate.

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]~
sage: pari('Mod(x,x^3-3)').conjvec()
[1.442249570307408382321638311, -0.7211247851537041911608191554 +
1.249024766483406479413179544*I, -0.7211247851537041911608191554 -
1.249024766483406479413179544*I]~

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
sage: pari('1+I').cos()
0.8337300251311490488838853943 - 0.9888977057628650963821295409*I
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
sage: pari('1+I').cosh()
0.8337300251311490488838853943 + 0.9888977057628650963821295409*I
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

Note that cotangent of pi doesn't raise an error, but instead just returns a very large number:

sage: pari('Pi').cotan()  
1.980704062 E28

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
sage: pari('1+I').dilog()
0.6168502750680849136771556877 + 1.460362116753119547679775740*I

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.4181889844988605856298894585

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]
sage: om.elleisnum(2)
-5.288649339654257621791534696
sage: om.elleisnum(4)
112.0000000000000000000000000
sage: om.elleisnum(100)
2.153142485760776361127070332 E50

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.96586952574849779469497769 + 2.660659330 E-28*I

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

sage: E.ellwp(pari("1+I"))
-1.115106825655550879209066487 + 2.334190523074698836184798800*I
sage: E.ellwp("1+I")
-1.115106825655550879209066487 + 2.334190523074698836184798800*I

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.0006448292728105361474541635955*I

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

sage: E.ellwp(1, flag=1)
[13.96586952574849779469497769 + 2.660659330 E-28*I,
50.56193008800727525558465689 + 1.615587134 E-27*I]

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 + 2.660659330 E-28*I,
50.06193008800727525558465689 + 1.615587134 E-27*I]

erfc( )

Return the complementary error function:

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

sage: pari(1).erfc()
0.1572992070502851306587793649

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

exp( )

x.exp(): exponential of x.

sage: pari(0).exp()
1.000000000000000000000000000
sage: pari(1).exp()
2.718281828459045235360287471
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
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):
...
TypeError: x (=hello world) has no floor.

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
sage: pari('sqrt(2)').frac()
0.4142135623730950488016887242

sage: pari('sqrt(-2)').frac()
Traceback (most recent call last):
...
TypeError: Fractional part of 1.4142135623730950488016887242*I not defined.

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
sage: pari(5).gamma()
24.00000000000000000000000000
sage: pari('1+I').gamma()
0.4980156681183560427136911175 - 0.1549498283018106851249551305*I

gammah( )

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

sage: pari(2).gammah()
1.329340388179137020473625613
sage: pari(5).gammah()
52.34277778455352018114900849
sage: pari('1+I').gammah()
0.5753151880634517207185443722 + 0.08821067754409390991246464371*I

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.

sage: pari(1).hyperu(2,3)
0.3333333333333333333333333333

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
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).

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.04582978599199457259586742327 + 0.04336968187266766812050474477*I

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.8646647167633873081060005048

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.

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.

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]

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

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
sage: pari('I').log()
0.E-29 + 1.570796326794896619231321692*I

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]

mathnf( )

mathnf(A,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( )

matsnf(x,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'

nextprime( )

nextprime(x): smallest pseudoprime >= x

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.458816616938495229330889612*I]

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

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):
...
RuntimeError: PARI error 8: error in Pol

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
sage: pari(10).polylog(3,0)
5.641811414751341250600725771 - 8.328202076980270580884185850*I
sage: pari(10).polylog(3,1)
0.5237784535024110488342571115
sage: pari(10).polylog(3,2)
-0.4004590561634505605364328953

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

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

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'>

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-28)

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

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
sage: y = x.simplify()
sage: y.type()
't_REAL'

sin( )

x.sin(): The sine of x.

sage: pari(1).sin()
0.8414709848078965066525023216
sage: pari('1+I').sin()
1.298457581415977294826042366 + 0.6349639147847361082550822030*I

sinh( )

The hyperbolic sine function.

sage: pari(0).sinh()
0.E-28
sage: pari('1+I').sinh()
0.6349639147847361082550822030 + 1.298457581415977294826042366*I

sizebyte( )

sizebyte(x): Return the total number of bytes occupied by the complete tree of the object x.

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

sage: pari('1').sizebyte()
12
sage: pari('10').sizebyte()
12
sage: pari('10000000000000').sizebyte()
16
sage: pari('10^100').sizebyte()
52
sage: pari('x').sizebyte()
36
sage: pari('x^20').sizebyte()
264
sage: pari('[x, 10^100]').sizebyte()
100

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

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

TODO: ??? lots of good examples in the PARI docs ???

sage: s, z = pari(2).sqrtn(5)
sage: z
0.3090169943749474241022934172 + 0.9510565162951535721164393334*I
sage: s
1.148698354997035006798626947
sage: s**5
2.000000000000000000000000000
sage: (s*z)**5
2.000000000000000000000000000 + 4.038967835 E-28*I

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
sage: pari([1,1.54,1]).Str()
11.5400000000000000000000000001
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(\frac{y
 + 2}{y
 + 1}\right)  x
 + 1}{x}x
 - 1

subst( )

sage: x = pari("x"); y = pari("y")
sage: f = 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

tan( )

x.tan() - tangent of x

sage: pari(2).tan()
-2.185039863261518991643306102
sage: pari('I').tan()
0.E-29 + 0.7615941559557648881194582826*I

tanh( )

x.tanh() - hyperbolic tangent of x

sage: pari(1).tanh()
0.7615941559557648881194582826
sage: pari('I').tanh()
-2.524354897 E-29 + 1.557407724654902230506974808*I

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

thetanullk( )

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

sage: pari(0.5).thetanullk(1)
0.5489785325603405618549383537

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)   # on 32-bit machine
2147483647

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,

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 + 0.E-28*I
sage: pari('I').weber(1)
1.090507732665257659207010656
sage: pari('I').weber(2)
1.090507732665257659207010656

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
sage: pari('Pi^2/6')
1.644934066848226436472415167
sage: pari(3).zeta()
1.202056903159594285399738162

Instances of class gen also have the following special methods:

__abs__,$  $ __add__,$  $ __bool__,$  $ __call__,$  $ __cmp__,$  $ __delitem__,$  $ __div__,$  $ __eq__,$  $ __float__,$  $ __ge__,$  $ __getitem__,$  $ __getslice__,$  $ __gt__,$  $ __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,$  $ _mod,$  $ _mul,$  $ _sub,$  $ _testclass

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