Module: sage.libs.pari.gen
PARI C-library interface
Author Log:
sage: pari('5! + 10/x') (120*x + 10)/x sage: pari('intnum(x=0,13,sin(x)+sin(x^2) + x)') 85.18856819515268446242866615 # 32-bit 85.188568195152684462428666150825866897 # 64-bit sage: f = pari('x^3-1') sage: v = f.factor(); v [x - 1, 1; x^2 + x + 1, 1] sage: v[0] # indexing is 0-based unlike in GP. [x - 1, x^2 + x + 1]~ sage: v[1] [1, 1]~
Arithmetic obeys the usual coercion rules.
sage: type(pari(1) + 1) <type 'sage.libs.pari.gen.gen'> sage: type(1 + pari(1)) <type 'sage.libs.pari.gen.gen'>
Module-level Functions
) |
Change the PARI scratch stack space to the given size.
The main application of this command is that you've done some individual PARI computation that used a lot of stack space. As a result the PARI stack may have doubled several times and is now quite large. That object you computed is copied off to the heap, but the PARI stack is never automatically shrunk back down. If you call this function you can shrink it back down.
If you set this too small then it will automatically be increased if it is exceeded, which could make some calculations initially slower (since they have to be redone until the stack is big enough).
Input:
sage: get_memory_usage() # random output '122M+' sage: a = pari('2^100000000') sage: get_memory_usage() # random output '157M+' sage: del a sage: get_memory_usage() # random output '145M+'
Hey, I want my memory back!
sage: sage.libs.pari.gen.init_pari_stack() sage: get_memory_usage() # random output '114M+'
Ahh, that's better.
) |
max(x,y): Return the maximum of x and y.
) |
min(x,y): Return the minimum of x and y.
) |
Input:
Class: gen
Functions: abs,
acos,
acosh,
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,
contfracpnqn,
copy,
cos,
cosh,
cotan,
denominator,
deriv,
dilog,
dirzetak,
disc,
divrem,
eint1,
elementval,
elladd,
ellak,
ellan,
ellap,
ellaplist,
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,
fibonacci,
floor,
frac,
gamma,
gammah,
gcd,
gen_length,
getattr,
hilbert,
hyperu,
idealadd,
idealappr,
idealdiv,
idealfactor,
idealhnf,
idealmul,
idealnorm,
idealred,
idealtwoelt,
idealval,
imag,
incgam,
incgamc,
int_unsafe,
intformal,
intvec_unsafe,
ispower,
isprime,
ispseudoprime,
issquare,
issquarefree,
j,
kronecker,
lcm,
length,
lex,
lift,
lindep,
list,
List,
list_str,
listinsert,
listput,
lllgram,
lllgramint,
lngamma,
log,
Mat,
matadjoint,
matdet,
matfrobenius,
mathnf,
mathnfmod,
mathnfmodid,
matker,
matkerint,
matsnf,
matsolve,
mattranspose,
max,
min,
Mod,
modreverse,
moebius,
ncols,
newtonpoly,
nextprime,
nfbasis,
nfbasis_d,
nfdisc,
nffactor,
nfgenerator,
nfinit,
nfisisom,
nfrootsof1,
nfsubfields,
norm,
nrows,
numbpart,
numdiv,
numerator,
numtoperm,
omega,
order,
padicappr,
padicprec,
parent,
permtonum,
phi,
Pol,
polcoeff,
polcompositum,
poldegree,
poldisc,
poldiscreduced,
polgalois,
polhensellift,
polinterpolate,
polisirreducible,
pollead,
polrecip,
polred,
polredabs,
polresultant,
Polrev,
polroots,
polrootsmod,
polrootspadic,
polrootspadicfast,
polsturm,
polsturm_full,
polsylvestermatrix,
polsym,
polylog,
precision,
primepi,
printtex,
psi,
python,
python_list,
python_list_small,
Qfb,
qfbhclassno,
qflll,
qflllgram,
qfminim,
qfrep,
random,
real,
reverse,
rnfcharpoly,
rnfdisc,
rnfeltabstorel,
rnfeltreltoabs,
rnfequation,
rnfidealabstorel,
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,
truncate,
type,
valuation,
variable,
Vec,
vecextract,
vecmax,
vecmin,
Vecrev,
Vecsmall,
weber,
xgcd,
zeta,
znprimroot
) |
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
) |
The principal branch of
, so that
belongs to
. If
is real and
,
then
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
) |
The principal branch of
, so that
belongs to
. If
is real and
, then
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
) |
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
) |
sage: n = 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 sage: f(w1) 7.75513996 E-200 + 5.70672991 E-200*I # 32-bit 3.780069700150794274 E-209 - 9.362977321012524836 E-211*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) 200
) |
arg(x): argument of x,such that
.
sage: pari('2+I').arg() 0.4636476090008061162142562315 # 32-bit 0.46364760900080611621425623146121440203 # 64-bit
) |
The principal branch of
, so that
belongs to
. If
is real
and
then
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
) |
The principal branch of
, so that
belongs to
.
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
) |
The principal branch of
, so that
belongs to
.
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
) |
The principal branch of
, so that
belongs to
. If
is real
and
then
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
) |
The Bernoulli number
, where
,
,
expressed as a rational number. The
argument
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]
) |
The Bernoulli number
, as for the function bernfrac, but
is returned as a real number (with the current
precision).
sage: pari(18).bernreal() 54.97117794486215538847117794 # 32-bit 54.971177944862155388471177944862155388 # 64-bit
) |
Creates a vector containing, as rational numbers, the
Bernoulli numbers
. 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]
) |
The
-Bessel function of index
and argument
.
sage: pari(2).besselh1(3) 0.4860912605858910769078310941 - 0.1604003934849237296757682995*I # 32-bit 0.48609126058589107690783109411498403480 - 0.16040039348492372967576829953798091810*I # 64-bit
) |
The
-Bessel function of index
and argument
.
sage: pari(2).besselh2(3) 0.4860912605858910769078310941 + 0.1604003934849237296757682995*I # 32-bit 0.48609126058589107690783109411498403480 + 0.16040039348492372967576829953798091810*I # 64-bit
) |
Bessel I function (Bessel function of the second kind), with
index
and argument
. If
converts to a power
series, the initial factor
is
omitted (since it cannot be represented in PARI when
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
) |
Bessel J function (Bessel function of the first kind), with
index
and argument
. If
converts to a power
series, the initial factor
is
omitted (since it cannot be represented in PARI when
is not
integral).
sage: pari(2).besselj(3) 0.4860912605858910769078310941 # 32-bit 0.48609126058589107690783109411498403480 # 64-bit
) |
J-Bessel function of half integral index (Speherical Bessel
function of the first kind). More precisely, besseljh(n,x)
computes
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
is small.
sage: pari(2).besseljh(3) 0.4127100322097159934374967959 # 32-bit 0.41271003220971599343749679594186271499 # 64-bit
) |
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:
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) # long time 3.742246033197275082909500148 E-132 + 2.490710626415252262644383350 E-134*I # 32-bit 3.7422460331972750829095001475885825717 E-132 + 2.4907106264152522626443833495225745762 E-134*I # 64-bit
) |
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(x): gives the vector formed by the binary digits of abs(x), where x is of type t_INT.
Input:
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.
) |
binomial(x, k): return the binomial coefficient "x choose k".
Input:
sage: pari(6).binomial(2) 15 sage: pari('x+1').binomial(3) 1/6*x^3 - 1/6*x sage: pari('2+x+O(x^2)').binomial(3) 1/3*x + O(x^2)
) |
bitand(x,y): Bitwise and of two integers x and y. Negative numbers behave as if modulo some large power of 2.
Input:
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(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
.
Input:
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(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:
sage: pari(14).bitnegimply(0) 14 sage: pari(8).bitnegimply(8) 0 sage: pari(8+4).bitnegimply(8) 4
) |
bitor(x,y): Bitwise or of two integers x and y. Negative numbers behave as if modulo big power of 2.
Input:
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(x, long n): Returns bit number n (coefficient of
in binary) of the integer x. Negative numbers behave as if modulo a
big power of 2.
Input:
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(x,y): Bitwise exclusive or of two integers x and y. Negative numbers behave as if modulo big power of 2.
Input:
sage: pari(6).bitxor(4) 2 sage: pari(0).bitxor(4) 4 sage: pari(6).bitxor(0) 6
) |
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
for the technical optional
parameters to the function. There are known counterexamples
for smaller
(which is the default).
) |
Return the smallest integer >= x.
Input:
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(x,v): Centered lift of x. This function returns exactly the same thing as lift, except if x is an integer mod.
Input:
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(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:
sage: pari('x^3+1').changevar(pari(['y'])) y^3 + 1
) |
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(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:
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(x, long n): Return n'th component of the internal representation of x. 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:
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(x): Return the algebraic conjugate of x.
Input:
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(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:
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(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.
) |
contfracpnqn(x): [p_n,p_n-1; q_n,q_n-1] corresponding to the continued fraction x.
) |
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)
) |
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)
) |
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
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(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:
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
) |
The principal branch of the dilogarithm of
, i.e. the analytic
continuation of the power series
.
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
) |
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(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).
) |
x.eint1(n): exponential integral E1(x):
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".
) |
e.elladd(z0, z1): return the sum of the points z0 and z1 on this elliptic curve.
Input:
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]) [-3/4, -15/8]
) |
e.ellak(n): Returns the coefficient
of the
-function of
the elliptic curve e, i.e. the
-th Fourier coefficient of the
weight 2 newform associated to e (according to Shimura-Taniyama).
Input:
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
) |
Return the first
Fourier coefficients of the modular form
attached to this elliptic curve. See ellak for more details.
Input:
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) [] sage: v = e.ellan(10, python_ints=True); v [1, -2, -1, 2, 1, 2, -2, 0, -2, -2] sage: type(v) <type 'list'> sage: type(v[0]) <type 'int'>
) |
e.ellap(p): Returns the prime-indexed coefficient
of the
-function of the elliptic curve
, i.e. the
-th Fourier
coefficient of the newform attached to e.
The computation uses the baby-step giant-step method and a trick
due to Mestre, and requires
time and
storage.
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 ellap (or you will get INCORRECT RESULTS!)
Input:
sage: e = pari([0, -1, 1, -10, -20]).ellinit() sage: e.ellap(2) -2 sage: e.ellap(2003) 4 sage: e.ellak(-1) 0
) |
e.ellaplist(n): Returns a PARI list of all the prime-indexed
coefficients
(up to n) of the
-function of the elliptic
curve
, i.e. the Fourier coefficients of the newform attached
to
.
Input:
Input:
sage: e = pari([0, -1, 1, -10, -20]).ellinit() sage: v = e.ellaplist(10); v [-2, -1, 1, -2] sage: type(v) <type 'sage.libs.pari.gen.gen'> sage: v.type() 't_VEC' sage: e.ellan(10) [1, -2, -1, 2, 1, 2, -2, 0, -2, -2] sage: v = e.ellaplist(10, python_ints=True); v [-2, -1, 1, -2] sage: type(v) <type 'list'> sage: type(v[0]) <type 'int'>
) |
e.ellbil(z0, z1): return the value of the canonical bilinear form on z0 and z1.
Input:
sage: e = pari([0,1,1,-2,0]).ellinit().ellminimalmodel()[0] sage: e.ellbil([1, 0], [-1, 1]) 0.4181889844988605856298894582 # 32-bit 0.41818898449886058562988945821587638238 # 64-bit
) |
e.ellchangecurve(ch): return the new model (equation) for the elliptic curve e given by the change of coordinates ch.
The change of coordinates is specified by a vector
ch=[u,r,s,t]; if
and
are the new coordinates, then
and
.
Input:
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]
) |
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]) sage: e.ellisoncurve([1,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
) |
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:
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
) |
e.elleta(): return the vector [eta1,eta2] of quasi-periods associated with the period lattice e.omega() of the elliptic curve e.
sage: e = pari([0,0,0,-82,0]).ellinit() sage: e.elleta() [3.605463601432652085915820564, 10.81639080429795625774746169*I] # 32-bit [3.6054636014326520859158205642077267748, 10.816390804297956257747461692623180324*I] # 64-bit
) |
e.ellglobalred(): return information related to the global minimal model of the elliptic curve e.
Input:
sage: e = pari([0, 5, 2, -1, 1]).ellinit() sage: e.ellglobalred() [20144, [1, -2, 0, -1], 1] sage: e = pari(EllipticCurve('17a').a_invariants()).ellinit() sage: e.ellglobalred() [17, [1, 0, 0, 0], 4]
) |
e.ellheight(a, flag=2): return the global N'eron-Tate height of the point a on the elliptic curve e.
Input:
sage: e = pari([0,1,1,-2,0]).ellinit().ellminimalmodel()[0] sage: e.ellheight([1,0]) 0.4767116593437395373794860589 # 32-bit 0.47671165934373953737948605888465305946 # 64-bit sage: e.ellheight([1,0], flag=0) 0.4767116593437395373794860589 # 32-bit 0.47671165934373953737948605888465305946 # 64-bit sage: e.ellheight([1,0], flag=1) 0.4767116593437395373794860589 # 32-bit 0.47671165934373953737948605888465305946 # 64-bit
) |
e.ellheightmatrix(x): return the height matrix for the vector x of points on the elliptic curve e.
In other words, it returns the Gram matrix of x with respect to the height bilinear form on e (see ellbil).
Input:
sage: e = pari([0,1,1,-2,0]).ellinit().ellminimalmodel()[0] sage: e.ellheightmatrix([[1,0], [-1,1]]) [0.4767116593437395373794860589, 0.4181889844988605856298894582; 0.4181889844988605856298894582, 0.6866670833055865857235521030] # 32-bit [0.47671165934373953737948605888465305946, 0.41818898449886058562988945821587638238; 0.41818898449886058562988945821587638238, 0.68666708330558658572355210295409678906] # 64-bit
) |
e.ellisoncurve(x): return True if the point x is on the elliptic curve e, False otherwise.
If the point or the curve have inexact coefficients, an attempt is made to take this into account.
sage: e = pari([0,1,1,-2,0]).ellinit() sage: e.ellisoncurve([1,0]) True sage: e.ellisoncurve([1,1]) False sage: e.ellisoncurve([1,0.00000000000000001]) False sage: e.ellisoncurve([1,0.000000000000000001]) True sage: e.ellisoncurve([0]) True
) |
e.elllocalred(p): computes the data of local reduction at the prime p on the elliptic curve e
For more details on local reduction and Kodaira types, see IV.8 and IV.9 in J. Silverman's book "Advanced topics in the arithmetic of elliptic curves".
Input:
Type
:
sage: e = pari([0,0,0,0,1]).ellinit() sage: e.elllocalred(7) [0, 1, [1, 0, 0, 0], 1]
Type
:
sage: e = pari(EllipticCurve('27a3').a_invariants()).ellinit() sage: e.elllocalred(3) [3, 2, [1, -1, 0, 1], 1]
Type
:
sage: e = pari(EllipticCurve('24a4').a_invariants()).ellinit() sage: e.elllocalred(2) [3, 3, [1, 1, 0, 1], 2]
Type
:
sage: e = pari(EllipticCurve('20a2').a_invariants()).ellinit() sage: e.elllocalred(2) [2, 4, [1, 1, 0, 1], 3]
Type
:
sage: e = pari(EllipticCurve('11a2').a_invariants()).ellinit() sage: e.elllocalred(11) [1, 5, [1, 0, 0, 0], 1]
Type
:
sage: e = pari(EllipticCurve('14a4').a_invariants()).ellinit() sage: e.elllocalred(2) [1, 6, [1, 0, 0, 0], 2]
Type
:
sage: e = pari(EllipticCurve('14a1').a_invariants()).ellinit() sage: e.elllocalred(2) [1, 10, [1, 0, 0, 0], 2]
Type
:
sage: e = pari(EllipticCurve('32a3').a_invariants()).ellinit() sage: e.elllocalred(2) [5, -1, [1, 1, 1, 0], 1]
Type
:
sage: e = pari(EllipticCurve('24a5').a_invariants()).ellinit() sage: e.elllocalred(2) [3, -2, [1, 2, 1, 4], 1]
Type
:
sage: e = pari(EllipticCurve('24a2').a_invariants()).ellinit() sage: e.elllocalred(2) [3, -3, [1, 2, 1, 4], 2]
Type
:
sage: e = pari(EllipticCurve('20a1').a_invariants()).ellinit() sage: e.elllocalred(2) [2, -4, [1, 0, 1, 2], 3]
Type
:
sage: e = pari(EllipticCurve('24a1').a_invariants()).ellinit() sage: e.elllocalred(2) [3, -5, [1, 0, 1, 2], 4]
Type
:
sage: e = pari(EllipticCurve('90c2').a_invariants()).ellinit() sage: e.elllocalred(3) [2, -10, [1, 96, 1, 316], 4]
) |
e.elllseries(s, A=1): return the value of the
-series of the
elliptic curve e at the complex number s.
This uses an
algorithm in the conductor N of e, so
it is impractical for large conductors (say greater than
).
Input:
sage: e = pari([0,1,1,-2,0]).ellinit() sage: e.elllseries(2.1) 0.4028380479566455155 sage: e.elllseries(1) # random, close to 0 -3.241361318972148540775276458 E-29 sage: e.elllseries(-2) 0
The following example differs for the last digit on 32 vs. 64 bit systems
sage: e.elllseries(2.1, A=1.1) 0.402838047956645515...
) |
ellminimalmodel(e): return the standard minimal integral model of the rational elliptic curve e and the corresponding change of variables. Input:
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]
) |
e.ellorder(x): return the order of the point x on the elliptic curve e (return 0 if x is not a torsion point)
Input:
sage: e = pari(EllipticCurve('65a1').a_invariants()).ellinit()
A point of order two:
sage: e.ellorder([0,0]) 2
And a point of infinite order:
sage: e.ellorder([1,0]) 0
) |
e.ellordinate(x): return the
-coordinates of the points on the
elliptic curve e having x as
-coordinate.
Input:
sage: e = pari([0,1,1,-2,0]).ellinit() sage: e.ellordinate(0) [0, -1] sage: e.ellordinate(I) [0.5822035897217411772333894787 - 1.386060824641769718531183421*I, -1.582203589721741177233389479 + 1.386060824641769718531183421*I] # 32-bit [0.58220358972174117723338947874993600727 - 1.3860608246417697185311834209833653345*I, -1.5822035897217411772333894787499360073 + 1.3860608246417697185311834209833653345*I] # 64-bit sage: e.ellordinate(1+3*5^1+O(5^3)) [4*5 + 5^2 + O(5^3), 4 + 3*5^2 + O(5^3)] sage: e.ellordinate('z+2*z^2+O(z^4)') [-2*z - 7*z^2 - 23*z^3 + O(z^4), -1 + 2*z + 7*z^2 + 23*z^3 + O(z^4)]
) |
e.ellpointtoz(P): return the complex number (in the fundamental parallelogram) corresponding to the point P on the elliptic curve e, under the complex uniformization of e given by the Weierstrass p-function.
The complex number z returned by this function lies in the parallelogram formed by the real and complex periods of e, as given by e.omega().
sage: e = pari([0,0,0,1,0]).ellinit() sage: e.ellpointtoz([0,0]) 1.854074677301371918433850347 # 32-bit 1.8540746773013719184338503471952600462 # 64-bit
The point at infinity is sent to the complex number 0:
sage: e.ellpointtoz([0]) 0
) |
e.ellpow(z, n): return n times the point z on the elliptic curve e.
Input:
We consider a CM curve:
sage: e = pari([0,0,0,1,0]).ellinit()
Multiplication by two:
sage: e.ellpow([0,0], 2) [0]
Complex multiplication (this is broken at the moment):
sage: e.ellpow([0,0], I+1) # optional
) |
e.ellrootno(p): return the (local or global) root number of the
-series of the elliptic curve e
If p is a prime number, the local root number at p is returned.
If p is 1, the global root number is returned. Note that the
global root number is the sign of the functional equation of the
-series, and therefore conjecturally equal to the parity of the
rank of e.
Input:
Here is a curve of rank 3:
sage: e = pari([0,0,0,-82,0]).ellinit() sage: e.ellrootno() -1 sage: e.ellrootno(2) 1 sage: e.ellrootno(1009) 1
) |
e.ellsigma(z, flag=0): return the value at the complex point z
of the Weierstrass
function associated to the elliptic
curve e.
) |
e.ellsub(z0, z1): return z0-z1 on this elliptic curve.
Input:
sage: e = pari([0, 1, 1, -2, 0]).ellinit() sage: e.ellsub([1,0], [-1,1]) [0, 0]
) |
e.elltors(flag = 0): return information about the torsion subgroup of the elliptic curve e
Input:
sage: e = pari([1,0,1,-19,26]).ellinit() sage: e.elltors() [12, [6, 2], [[-2, 8], [3, -2]]]
) |
ellwp(E, z,flag=0): Return the complex value of the Weierstrass P-function at z on the lattice defined by e.
Input:
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
) |
e.ellzeta(z): return the value at the complex point z of the
Weierstrass
function associated with the elliptic curve e.
NOTE: this function has infinitely many poles (one of which is at z=0); attempting to evaluate it too close to one of the poles will result in a PariError.
Input:
sage: e = pari([0,0,0,1,0]).ellinit() sage: e.ellzeta(1) 1.064798412958827927449913418 + 3.491753745 E-251*I # 32-bit 1.0647984129588279274499134181598985072 - 8.016988209895862073 E-694*I # 64-bit sage: e.ellzeta(I-1) -0.3501226585230491632779704180 - 0.3501226585230491632779704180*I # 32-bit -0.35012265852304916327797041802108326818 - 0.35012265852304916327797041802108326818*I # 64-bit
) |
e.ellztopoint(z): return the point on the elliptic curve e corresponding to the complex number z, under the usual complex uniformization of e by the Weierstrass p-function.
Input:
OUTPUT point on e
sage: e = pari([0,0,0,1,0]).ellinit() sage: e.ellztopoint(1+I) [0.E-251 - 1.021522867956699099826892460*I, -0.1490728137010962128964506933 - 0.1490728137010962128964506933*I] # 32-bit [0.E-694 - 1.0215228679566990998268924596833713669*I, -0.14907281370109621289645069325289375075 - 0.14907281370109621289645069325289375075*I] # 64-bit
Complex numbers belonging to the period lattice of e are of course sent to the point at infinity on e:
sage: e.ellztopoint(0) [0]
) |
Return the complementary error function:
sage: pari(1).erfc() 0.1572992070502851306587793649 # 32-bit 0.15729920705028513065877936491739074070 # 64-bit
) |
x.eta(flag=0): if flag=0,
function without the
;
otherwise
of the complex number
in the upper half plane
intelligently computed using
transformations.
DETAILS: This functions computes the following. If the input
is a complex number with positive imaginary part, the
result is
, where
. If
is a power series (or can be converted to a power
series) with positive valuation, the result is
.
sage: pari('I').eta() 0.9981290699259585132799623222 # 32-bit 0.99812906992595851327996232224527387813 # 64-bit
) |
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)
) |
Return the factorization of x.
Input:
proof - (default: True) optional. If False (not the default),
returned factors
may only be pseudoprimes.
NOTE: In the standard PARI/GP interpreter and C-library the factor command *always* has proof=False, so beware!
sage: pari('x^10-1').factor() [x - 1, 1; x + 1, 1; x^4 - x^3 + x^2 - x + 1, 1; x^4 + x^3 + x^2 + x + 1, 1] sage: pari(2^100-1).factor() [3, 1; 5, 3; 11, 1; 31, 1; 41, 1; 101, 1; 251, 1; 601, 1; 1801, 1; 4051, 1; 8101, 1; 268501, 1] sage: pari(2^100-1).factor(proof=False) [3, 1; 5, 3; 11, 1; 31, 1; 41, 1; 101, 1; 251, 1; 601, 1; 1801, 1; 4051, 1; 8101, 1; 268501, 1]
We illustrate setting a limit:
sage: pari(next_prime(10^50)*next_prime(10^60)*next_prime(10^4)).factor(10^5) [10007, 1; 1000000000000000000000000000000000000000000000001510000000007000 00000000000000000000000000000000000000000001057, 1]
PARI doesn't have an algorithm for factoring multivariate polynomials:
sage: pari('x^3 - y^3').factor() Traceback (most recent call last): ... PariError: sorry, (15)
) |
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.
) |
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)
) |
Return the Fibonacci number of index x.
sage: pari(18).fibonacci() 2584 sage: [pari(n).fibonacci() for n in range(10)] [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
) |
floor(x): Return the floor of x, which is the largest integer <= x. This function also works component-wise on polynomials, vectors, etc.
Input:
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(x): Return the fractional part of x, which is x - floor(x).
Input:
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)
) |
s.gamma(precision): Gamma function at s.
Input:
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
) |
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(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)
) |
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) # long time 0.3333333333333333333333333333 # 32-bit 0.33333333333333333333333333333333333333 # 64-bit
) |
imag(x): Return the imaginary part of x. This function also works component-wise.
Input:
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]
) |
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:
sage: pari('1+I').incgam('3-I') -0.04582978599199457259586742326 + 0.04336968187266766812050474478*I # 32-bit -0.045829785991994572595867423261490338708 + 0.043369681872667668120504744775954724732*I # 64-bit
) |
s.incgamc(x): complementary incomplete gamma function.
The arguments
and
are complex numbers such that
is
not a pole of
and
is not much larger
than
(otherwise, the convergence is very slow). The
function returns the value of the integral
sage: pari(1).incgamc(2) 0.8646647167633873081060005050 # 32-bit 0.86466471676338730810600050502751559659 # 64-bit
) |
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.
) |
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
) |
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.
) |
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:
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(x, flag=0): Returns True if x is a PROVEN prime number, and False otherwise.
Input:
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
) |
ispseudoprime(x, flag=0): Returns True if x is a pseudo-prime number, and False otherwise.
Input:
sage: pari(9).ispseudoprime() False sage: pari(17).ispseudoprime() True sage: n = pari(561) # smallest Carmichael number sage: n.ispseudoprime() # not just any old pseudo-primality test! False sage: n.ispseudoprime(2) False
) |
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.
) |
sage: pari(10).issquarefree() True sage: pari(20).issquarefree() False
) |
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]
) |
Return the least common multiple of x and y.
sage: pari(10).lcm(15) 30
) |
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(x,y): Compare x and y lexicographically (1 if x>y, 0 if x==y, -1 if x<y)
) |
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:
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(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'
) |
Return str that might correctly evaluate to a Python-list.
) |
x.lngamma(): logarithm of the gamma function of x.
This function returns the principal branch of the logarithm of
the gamma function of
. The function
is
analytic on the complex plane with non-positive integers
removed. This function can have much larger inputs than
itself.
The
-adic analogue of this function is unfortunately not
implemented.
sage: pari(100).lngamma() 359.1342053695753987760440105 # 32-bit 359.13420536957539877604401046028690961 # 64-bit
) |
x.log(): natural logarithm of x.
This function returns the principal branch of the natural
logarithm of
, i.e., the branch such that
The result is complex (with imaginary part equal
to
) if
and
. In general, the algorithm
uses the formula
if
Note that
-adic arguments can also be given as input,
with the convention that
. Hence, in
particular,
is not in general
equal to
but instead to a
-st root of
unity (or
if
) times a power of
.
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(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:
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(x): adjoint matrix of x.
sage: pari('[1,2,3; 4,5,6; 7,8,9]').matadjoint() [-3, 6, -3; 6, -12, 6; -3, 6, -3] sage: pari('[a,b,c; d,e,f; g,h,i]').matadjoint() [(i*e - h*f), (-i*b + h*c), (f*b - e*c); (-i*d + g*f), i*a - g*c, -f*a + d*c; (h*d - g*e), -h*a + g*b, e*a - d*b]
) |
Return the determinant of this matrix.
Input:
sage: pari('[1,2; 3,4]').matdet(0) -2 sage: pari('[1,2; 3,4]').matdet(1) -2
) |
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
.
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]
We let t be the matrix of
acting on modular symbols of level 43,
which was computed using
ModularSymbols(43,sign=1).T(2).matrix()
:
sage: t = pari('[3, -2, 0, 0; 0, -2, 0, 1; 0, -1, -2, 2; 0, -2, 0, 2]') sage: t.matfrobenius() [0, 0, 0, -12; 1, 0, 0, -2; 0, 1, 0, 8; 0, 0, 1, 1] sage: t.charpoly('x') x^4 - x^3 - 8*x^2 + 2*x + 12 sage: t.matfrobenius(1) [x^4 - x^3 - 8*x^2 + 2*x + 12]
Author: 2006-04-02: Martin Albrecht
) |
A.mathnf(flag=0): (upper triangular) Hermite normal form of A, basis for the lattice formed by the columns of A.
Input:
sage: pari('[1,2,3; 4,5,6; 7,8,9]').mathnf() [6, 1; 3, 1; 0, 1]
) |
Returns the Hermite normal form if d is a multiple of the determinant
Beware that PARI's concept of a hermite normal form is an upper triangular matrix with the same column space as the input matrix.
Input:
sage: M=matrix([[1,2,3],[4,5,6],[7,8,11]]) sage: d=M.det() sage: pari(M).mathnfmod(d) [6, 4, 3; 0, 1, 0; 0, 0, 1]
Note that d really needs to be a multiple of the discriminant, not just of the exponent of the cokernel:
sage: M=matrix([[1,0,0],[0,2,0],[0,0,6]]) sage: pari(M).mathnfmod(6) [1, 0, 0; 0, 1, 0; 0, 0, 6] sage: pari(M).mathnfmod(12) [1, 0, 0; 0, 2, 0; 0, 0, 6]
) |
Returns the Hermite Normal Form of M concatenated with d*Identity
Beware that PARI's concept of a Hermite normal form is a maximal rank upper triangular matrix with the same column space as the input matrix.
Input:
sage: M=matrix([[1,0,0],[0,2,0],[0,0,6]]) sage: pari(M).mathnfmodid(6) [1, 0, 0; 0, 2, 0; 0, 0, 6]
This routine is not completely equivalent to mathnfmod:
sage: pari(M).mathnfmod(6) [1, 0, 0; 0, 1, 0; 0, 0, 6]
) |
Return a basis of the kernel of this matrix.
Input:
sage: pari('[1,2,3;4,5,6;7,8,9]').matker() [1; -2; 1]
With algorithm 1, even if the matrix has integer entries the kernel need nto be saturated (which is weird):
sage: pari('[1,2,3;4,5,6;7,8,9]').matker(1) [3; -6; 3] sage: pari('matrix(3,3,i,j,i)').matker() [-1, -1; 1, 0; 0, 1] sage: pari('[1,2,3;4,5,6;7,8,9]*Mod(1,2)').matker() [Mod(1, 2); Mod(0, 2); 1]
) |
Return the integer kernel of a matrix.
This is the LLL-reduced Z-basis of the kernel of the matrix x with integral entries.
Input:
sage: pari('[2,1;2,1]').matker() [-1/2; 1] sage: pari('[2,1;2,1]').matkerint() [-1; 2]
This is worrisome (so be careful!):
sage: pari('[2,1;2,1]').matkerint(1) Mat(1)
) |
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.
sage: pari('[1,2,3; 4,5,6; 7,8,9]').matsnf() [0, 3, 1]
) |
matsolve(B): Solve the linear system Mx=B for an invertible matrix M
matsolve(B) uses gaussian elimination to solve Mx=B, where M is invertible and B is a column vector.
The corresponding pari library routine is gauss. The gp-interface name matsolve has been given preference here.
Input:
sage: pari('[1,1;1,-1]').matsolve(pari('[1;0]')) [1/2; 1/2]
) |
Transpose of the matrix self.
sage: pari('[1,2,3; 4,5,6; 7,8,9]').mattranspose() [1, 4, 7; 2, 5, 8; 3, 6, 9]
) |
max(x,y): Return the maximum of x and y.
) |
min(x,y): Return the minumum of x and y.
) |
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:
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'
) |
modreverse(x): reverse polymod of the polymod x, if it exists.
) |
moebius(x): Moebius function of x.
) |
Return the number of columns of self.
sage: pari('matrix(19,8)').ncols() 8
) |
x.newtonpoly(p): Newton polygon of polynomial x with respect to the prime p.
sage: x = pari('y^8+6*y^6-27*y^5+1/9*y^2-y+1') sage: x.newtonpoly(3) [1, 1, -1/3, -1/3, -1/3, -1/3, -1/3, -1/3]
) |
nextprime(x): smallest pseudoprime >= x
sage: pari(1).nextprime() 2 sage: pari(2^100).nextprime() 1267650600228229401496703205653
) |
nfbasis_d(x): Return a basis of the number field defined over QQ by x and its discriminant.
sage: F = NumberField(x^3-2,'alpha') sage: F._pari_()[0].nfbasis_d() ([1, x, x^2], -108)
sage: G = NumberField(x^5-11,'beta') sage: G._pari_()[0].nfbasis_d() ([1, x, x^2, x^3, x^4], 45753125)
sage: pari([-2,0,0,1]).Polrev().nfbasis_d() ([1, x, x^2], -108)
) |
nfdisc(x): Return the discriminant of the number field defined over QQ by x.
sage: F = NumberField(x^3-2,'alpha') sage: F._pari_()[0].nfdisc() -108
sage: G = NumberField(x^5-11,'beta') sage: G._pari_()[0].nfdisc() 45753125
sage: f = x^3-2 sage: f._pari_() x^3 - 2 sage: f._pari_().nfdisc() -108
) |
nfisisom(x, y): Determine if the number fields defined by x and y are isomorphic. According to the PARI documentation, this is much faster if at least one of x or y is a number field. If they are isomorphic, it returns an embedding for the generators. If not, returns 0.
sage: F = NumberField(x^3-2,'alpha') sage: G = NumberField(x^3-2,'beta') sage: F._pari_().nfisisom(G._pari_()) [x]
sage: GG = NumberField(x^3-4,'gamma') sage: F._pari_().nfisisom(GG._pari_()) [1/2*x^2]
sage: F._pari_().nfisisom(GG.pari_nf()) [1/2*x^2]
sage: F.pari_nf().nfisisom(GG._pari_()[0]) [x^2]
sage: H = NumberField(x^2-2,'alpha') sage: F._pari_().nfisisom(H._pari_()) 0
) |
nf.nfrootsof1()
number of roots of unity and primitive root of unity in the number field nf.
sage: nf = pari('x^2 + 1').nfinit() sage: nf.nfrootsof1() [4, [0, 1]~]
) |
Find all subfields of degree d of number field nf (all subfields if d is null or omitted). Result is a vector of subfields, each being given by [g,h], where g is an absolute equation and h expresses one of the roots of g in terms of the root x of the polynomial defining nf.
Input:
) |
Return the number of rows of self.
sage: pari('matrix(19,8)').nrows() 19
) |
numbpart(x): returns the number of partitions of x.
sage: pari(20).numbpart() 627 sage: pari(100).numbpart() 190569292
) |
Return the number of divisors of the integer n.
sage: pari(10).numdiv() 4
) |
numerator(x): Returns the numerator of x.
Input:
) |
numtoperm(k, n): Return the permutation number k (mod n!) of n letters, where n is an integer.
Input:
) |
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
) |
x.padicappr(a): p-adic roots of the polynomial x congruent to a mod p
) |
padicprec(x,p): Return the absolute p-adic precision of the object x.
Input:
) |
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:
) |
Return the Euler phi function of n.
sage: pari(10).phi() 4
) |
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 truncate, i.e. it chops off the
.
* 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:
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]~
) |
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
) |
f.poldegree(var=x): Return the degree of this polynomial.
) |
f.poldist(var=x): Return the discriminant of this polynomial.
) |
f.polgalois(): Galois group of the polynomial f
) |
self.polhensellift(y, p, e): lift the factorization y of
self modulo p to a factorization modulo
using Hensel
lift. The factors in y must be pairwise relatively prime
modulo p.
) |
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.
) |
f.polisirreducible(): Returns True if f is an irreducible non-constant polynomial, or False if f is reducible or constant.
) |
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(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:
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(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.
) |
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(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:
) |
Return the number of primes
.
sage: pari(7).primepi() 4 sage: pari(100).primepi() 25 sage: pari(1000).primepi() 168 sage: pari(100000).primepi() 9592
) |
x.psi(): psi-function at x.
Return the
-function of
, i.e., the logarithmic
derivative
.
sage: pari(1).psi() -0.5772156649015328606065120901 # 32-bit -0.57721566490153286060651209008240243104 # 64-bit
) |
Return Python eval of self.
) |
Return a Python list of the PARI gens. This object must be of type t_VEC
Input: none Output:
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 'sage.libs.pari.gen.gen'> sage: pari("[1,2,3]").python_list() [1, 2, 3]
) |
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(a,b,c,D=0.): Returns the binary quadratic form
The optional D is 0 by default and initializes Shanks's distance if
NOTE: Negative definite forms are not implemented, so use their positive definite counterparts instead. (I.e., if f is a negative definite quadratic form, then -f is positive definite.)
Input:
sage: pari(3).Qfb(7, 2) Qfb(3, 7, 2, 0.E-250) # 32-bit Qfb(3, 7, 2, 0.E-693) # 64-bit
) |
Computes the Hurwitz-Kronecker class number of n.
If n is large (more than
), the result is conditional upon
GRH.
sage: pari(-10007).qfbhclassno() 77 sage: pari(-3).qfbhclassno() 1/3
) |
qflll(x,flag=0): LLL reduction of the vectors forming the matrix x (gives the unimodular transformation matrix). The columns of x must be linearly independent, unless specified otherwise below. flag is optional, and can be 0: default, 1: assumes x is integral, columns may be dependent, 2: assumes x is integral, returns a partially reduced basis, 4: assumes x is integral, returns [K,I] where K is the integer kernel of x and I the LLL reduced image, 5: same as 4 but x may have polynomial coefficients, 8: same as 0 but x may have polynomial coefficients.
) |
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(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(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({N=
: Return a pseudo-random integer between 0 and
})
.
Input:
) |
real(x): Return the real part of x.
Input:
) |
Return the polynomial obtained by reversing the coefficients of this polynomial.
) |
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(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:
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(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:
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(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.
sage: f = pari('x+x^2+x^3+O(x^4)'); f x + x^2 + x^3 + O(x^4) sage: g = f.serreverse(); g x - x^2 + x^3 + O(x^4) sage: f.subst('x',g) x + O(x^4) sage: g.subst('x',f) x + O(x^4)
) |
Set(x): convert x into a set, i.e. a row vector of strings in increasing lexicographic order.
Input:
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(x,n): shift x left n bits if n>=0, right -n bits if n<0.
) |
shiftmul(x,n): Return the product of x by
.
) |
sign(x): Return the sign of x, where x is of type integer, real or fraction.
) |
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'
) |
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
) |
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(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:
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(x): Return a quick estimate for the maximal number of decimal digits before the decimal point of any component of x.
Input:
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
) |
x.sqr(): square of x. Faster than, and most of the time (but not always - see the examples) identical to x*x.
sage: pari(2).sqr() 4
For
-adic numbers, x.sqr() may not be identical to x*x
(squaring a
-adic number increases its precision):
sage: pari("1+O(2^5)").sqr() 1 + O(2^6) sage: pari("1+O(2^5)")*pari("1+O(2^5)") 1 + O(2^5)
However:
sage: x = pari("1+O(2^5)"); x*x 1 + O(2^6)
) |
x.sqrt(precision): The square root of x.
sage: pari(2).sqrt() 1.414213562373095048801688724 # 32-bit 1.4142135623730950488016887242096980786 # 64-bit
) |
x.sqrtn(n): return the principal branch of the n-th root
of x, i.e., the one such that
.
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
-adic numbers are
allowed as arguments.
Input:
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(self): Return the print representation of self as a PARI object is returned.
Input:
sage: pari([1,2,['abc',1]]).Str() [1, 2, [abc, 1]] sage: pari('[1,1, 1.54]').Str() [1, 1, 1.540000000000000000000000000] # 32-bit [1, 1, 1.5400000000000000000000000000000000000] # 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(x): converts x to a string, translating each integer into a character (in ASCII).
NOTE: Vecsmall is (essentially) the inverse to Strchr().
Input:
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(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(x): Translates the vector x of PARI gens to TeX format and returns the resulting concatenated strings as a PARI t_STR.
Input:
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
) |
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
) |
Return the sum of the divisors of
.
sage: pari(10).sumdiv() 18
) |
Return the sum of the k-th powers of the divisors of n.
sage: pari(10).sumdivk(2) 130
) |
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
) |
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(x): teichmuller character of p-adic number x.
This is the unique
-st root of unity congruent to
modulo
.
sage: pari('2+O(7^5)').teichmuller() 2 + 4*7 + 6*7^2 + 3*7^3 + O(7^5)
) |
q.theta(z): Jacobi sine theta-function.
sage: pari('0.5').theta(2) 1.632025902952598833772353216 # 32-bit 1.6320259029525988337723532162682089972 # 64-bit
) |
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
) |
Return the trace of this PARI object.
sage: pari('[1,2; 3,4]').trace() 5
) |
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
.
Similarly, when applied to a p-adic number, it transforms it
into an integer or a rational number by chopping away the
.
Input:
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(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 minimum of the valuations of the coefficients.
* If p is a polynomial, x must be a polynomial or a rational function. 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
on 32-bit machines or
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:
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(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:
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(x): Transforms the object x into a vector.
Input:
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]
) |
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(x): Return the maximum of the elements of the vector/matrix x.
) |
vecmin(x): Return the maximum of the elements of the vector/matrix x.
) |
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 Laurent series, raises an exception
Input:
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(x): transforms the object x into a t_VECSMALL.
Input:
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])
) |
x.weber(flag=0): One of Weber's f functions 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
,
1: function f1(x)=eta(x/2)/eta(x) such that
,
2: function f2(x)=sqrt(2)*eta(2*x)/eta(x) such that
.
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
) |
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(s): zeta function at s with s a complex or a p-adic number.
If
is a complex number, this is the Riemann zeta function
, computed either using the
Euler-Maclaurin summation formula (if
is not an integer),
or using Bernoulli numbers (if
is a negative integer or an
even nonnegative integer), or using modular forms (if
is
an odd nonnegative integer).
If
is a
-adic number, this is the Kubota-Leopoldt zeta
function, i.e. the unique continuous
-adic function on the
-adic integers that interpolates the values of
at negative integers
such that
if
is odd, and at odd
if
.
Input:
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 sage: pari('1+5*7+2*7^2+O(7^3)').zeta() 4*7^-2 + 5*7^-1 + O(7^0)
) |
Return a primitive root modulo self, whenever it exists.
This is a generator of the group
, whenever this
group is cyclic, i.e. if
or
or
, where
is an odd prime and
is a natural number.
Input:
sage: pari(4).znprimroot() Mod(3, 4) sage: pari(10007^3).znprimroot() Mod(5, 1002101470343) sage: pari(2*109^10).znprimroot() Mod(236736367459211723407, 473472734918423446802)
Special Functions: __abs__,
__call__,
__delitem__,
__eq__,
__float__,
__ge__,
__getitem__,
__getslice__,
__gt__,
__hex__,
__init__,
__int__,
__invert__,
__le__,
__len__,
__long__,
__lshift__,
__lt__,
__mod__,
__ne__,
__neg__,
__pow__,
__reduce__,
__repr__,
__rlshift__,
__rmod__,
__rpow__,
__rrshift__,
__rshift__,
__setitem__,
_add_unsafe,
_div_unsafe,
_eval_,
_mod,
_mul_unsafe,
_sage_,
_sub_unsafe,
_testclass
) |
) |
) |
Return Python float.
) |
Return the nth entry of self. The indexing is 0-based, like in Python. Note that this is *different* than the default behavior of the Pari/GP interpreter.
sage: p = pari('1 + 2*x + 3*x^2') sage: p[0] 1 sage: p[2] 3 sage: p[100] 0 sage: p[-1] 0 sage: q = pari('x^2 + 3*x^3 + O(x^6)') sage: q[3] 3 sage: q[5] 0 sage: q[6] Traceback (most recent call last): ... IndexError: index out of bounds sage: m = pari('[1,2;3,4]') sage: m[0] [1, 3]~ sage: m[1,0] 3 sage: l = pari('List([1,2,3])') sage: l[1] 2 sage: s = pari('"hello, world!"') sage: s[0] 'h' sage: s[4] 'o' sage: s[12] '!' sage: s[13] Traceback (most recent call last): ... IndexError: index out of bounds sage: v = pari('[1,2,3]') sage: v[0] 1 sage: c = pari('Col([1,2,3])') sage: c[1] 2 sage: sv = pari('Vecsmall([1,2,3])') sage: sv[2] 3 sage: type(sv[2]) <type 'int'> sage: tuple(pari(3/5)) (3, 5) sage: tuple(pari('1 + 5*I')) (1, 5) sage: tuple(pari('Qfb(1, 2, 3)')) (1, 2, 3) sage: pari(57)[0] Traceback (most recent call last): ... TypeError: unindexable object sage: m = pari("[[1,2;3,4],5]") ; m[0][1,0] 3
) |
Return the hexadecimal digits of self in lower case.
sage: print hex(pari(0)) 0 sage: print hex(pari(15)) f sage: print hex(pari(16)) 10 sage: print hex(pari(16938402384092843092843098243)) 36bb1e3929d1a8fe2802f083 sage: print hex(long(16938402384092843092843098243)) 0x36bb1e3929d1a8fe2802f083L sage: print hex(pari(-16938402384092843092843098243)) -36bb1e3929d1a8fe2802f083
) |
Return Python int. Very fast, and if the number is too large to fit into a C int, a Python long is returned instead.
sage: int(pari(0)) 0 sage: int(pari(10)) 10 sage: int(pari(-10)) -10 sage: int(pari(123456789012345678901234567890)) 123456789012345678901234567890L sage: int(pari(-123456789012345678901234567890)) -123456789012345678901234567890L sage: int(pari(2^31-1)) 2147483647 sage: int(pari(-2^31)) -2147483648
) |
) |
Return Python long.
) |
) |
) |
) |
sage: f = pari('x^3 - 3') sage: loads(dumps(f)) == f True
) |
) |
) |
VERY FAST addition of self and right on stack (and leave on stack) without any type checking.
Basically, this is often about 10 times faster than just typing "self + right". The drawback is that (1) if self + right would give an error in PARI, it will totally crash SAGE, and (2) the memory used by self + right is *never* returned - it gets allocated on the PARI stack and will never be freed.
sage: pari(2)._add_unsafe(pari(3)) 5
) |
VERY FAST division of self and right on stack (and leave on stack) without any type checking.
Basically, this is often about 10 times faster than just typing "self / right". The drawback is that (1) if self / right would give an error in PARI, it will totally crash SAGE, and (2) the memory used by self / right is *never* returned - it gets allocated on the PARI stack and will never be freed.
sage: pari(2)._div_unsafe(pari(3)) 2/3
) |
) |
) |
VERY FAST multiplication of self and right on stack (and leave on stack) without any type checking.
Basically, this is often about 10 times faster than just typing "self * right". The drawback is that (1) if self * right would give an error in PARI, it will totally crash SAGE, and (2) the memory used by self * right is *never* returned - it gets allocated on the PARI stack and will never be freed.
sage: pari(2)._mul_unsafe(pari(3)) 6
) |
Return SAGE version of self.
) |
VERY FAST subtraction of self and right on stack (and leave on stack) without any type checking.
Basically, this is often about 10 times faster than just typing "self - right". The drawback is that (1) if self - right would give an error in PARI, it will totally crash SAGE, and (2) the memory used by self - right is *never* returned - it gets allocated on the PARI stack and will never be freed.
sage: pari(2)._sub_unsafe(pari(3)) -1
) |
Class: PariError
Functions: errmessage
) |
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__
) |
) |
Class: PariInstance
Functions: allocatemem,
complex,
default,
double_to_gen,
euler,
factorial,
finitefield_init,
get_debug_level,
get_real_precision,
get_series_precision,
getrand,
init_primes,
listcreate,
matrix,
new_with_bits_prec,
new_with_prec,
nth_prime,
pari_rand31,
pari_version,
pi,
polcyclo,
pollegendre,
polsubcyclo,
poltchebi,
polzagier,
prime_list,
primes_up_to_n,
read,
set_debug_level,
set_real_precision,
set_series_precision,
setrand,
vector
) |
Double the PARI stack.
) |
Create a new complex number, initialized from re and im.
) |
Return Euler's constant to the current real precision.
sage: pari.euler() 0.5772156649015328606065120901 # 32-bit 0.57721566490153286060651209008240243104 # 64-bit sage: orig = pari.get_real_precision(); orig 28 # 32-bit 38 # 64-bit sage: _ = pari.set_real_precision(50) sage: pari.euler() 0.57721566490153286060651209008240243104215933593992
We restore precision to the default.
sage: pari.set_real_precision(orig) 50
Euler is returned to the original precision:
sage: pari.euler() 0.5772156649015328606065120901 # 32-bit 0.57721566490153286060651209008240243104 # 64-bit
) |
Return the factorial of the integer n as a PARI gen.
sage: pari.factorial(0) 1 sage: pari.factorial(1) 1 sage: pari.factorial(5) 120 sage: pari.factorial(25) 15511210043330985984000000
) |
finitefield_init(p, long n, var="x"): Return a polynomial f(x) so that the extension of F_p of degree n is k = F_p[x]/(f). Moreover, the element x (mod f) of k is a generator for the multiplicative group of k.
Input:
sage: pari.finitefield_init(97,1) Mod(1, 97)*x + Mod(92, 97)
These computations use pseudo-random numbers, so we set the seed for reproducible testing.
sage: set_random_seed(0)
sage: pari.finitefield_init(7,2) Mod(1, 7)*x^2 + Mod(5, 7)*x + Mod(3, 7)
sage: pari.finitefield_init(2,3) Mod(1, 2)*x^3 + Mod(1, 2)*x^2 + Mod(1, 2) # 32-bit Mod(1, 2)*x^3 + Mod(1, 2)*x + Mod(1, 2) # 64-bit
) |
Set the debug PARI C library variable.
) |
Returns Pari's current random number seed.
sage: pari.setrand(50) sage: pari.getrand() 50 sage: pari.pari_rand31() 621715893 sage: pari.getrand() 621715893
) |
Recompute the primes table including at least all primes up to M (but possibly more).
sage: pari.init_primes(200000)
) |
listcreate(n): return an empty pari list of maximal length n.
sage: pari.listcreate(20) List([])
) |
matrix(long m, long n, entries=None): Create and return the m x n PARI matrix with given list of entries.
) |
pari.new_with_bits_prec(self, s, precision) creates s as a PARI gen with (at most) precision bits of precision.
) |
pari.new_with_bits_prec(self, s, precision) creates s as a PARI gen
with at least precision
decimal digits of precision.
) |
Returns a random number from Pari's random number generator.
WARNING: You probably don't want to use this; it's a very poor random number generator. Sage exposes it only as a way to test unctiongetrand and unctionsetrand.
) |
Return the value of the constant pi = 3.1415 to the current real precision.
sage: pari.pi() 3.141592653589793238462643383 # 32-bit 3.1415926535897932384626433832795028842 # 64-bit sage: orig_prec = pari.set_real_precision(5) sage: pari.pi() 3.1416
sage: pari.get_real_precision() 5 sage: _ = pari.set_real_precision(40) sage: pari.pi() 3.141592653589793238462643383279502884197
We restore precision to the default.
sage: _ = pari.set_real_precision(orig_prec)
Note that pi is now computed to the original precision:
sage: pari.pi() 3.141592653589793238462643383 # 32-bit 3.1415926535897932384626433832795028842 # 64-bit
) |
polcyclo(n, v=x): cyclotomic polynomial of degree n, in variable v.
sage: pari.polcyclo(8) x^4 + 1 sage: pari.polcyclo(7, 'z') z^6 + z^5 + z^4 + z^3 + z^2 + z + 1 sage: pari.polcyclo(1) x - 1
) |
pollegendre(n, v=x): Legendre polynomial of degree n (n C-integer), in variable v.
sage: pari.pollegendre(7) 429/16*x^7 - 693/16*x^5 + 315/16*x^3 - 35/16*x sage: pari.pollegendre(7, 'z') 429/16*z^7 - 693/16*z^5 + 315/16*z^3 - 35/16*z sage: pari.pollegendre(0) 1
) |
polsubcyclo(n, d, v=x): return the pari list of polynomial(s)
defining the sub-abelian extensions of degree
of the cyclotomic
field
, where
divides
.
sage: pari.polsubcyclo(8, 4) [x^4 + 1] sage: pari.polsubcyclo(8, 2, 'z') [z^2 - 2, z^2 + 1, z^2 + 2] sage: pari.polsubcyclo(8, 1) [x - 1] sage: pari.polsubcyclo(8, 3) []
) |
poltchebi(n, v=x): Chebyshev polynomial of the first kind of degree n, in variable v.
sage: pari.poltchebi(7) 64*x^7 - 112*x^5 + 56*x^3 - 7*x sage: pari.poltchebi(7, 'z') 64*z^7 - 112*z^5 + 56*z^3 - 7*z sage: pari.poltchebi(0) 1
) |
prime_list(n): returns list of the first n primes
To extend the table of primes use pari.init_primes(M).
Input:
sage: pari.prime_list(0) [] sage: pari.prime_list(-1) [] sage: pari.prime_list(3) [2, 3, 5] sage: pari.prime_list(10) [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] sage: pari.prime_list(20) [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71] sage: len(pari.prime_list(1000)) 1000
) |
Return the primes <= n as a pari list.
sage: pari.primes_up_to_n(1) [] sage: pari.primes_up_to_n(20) [2, 3, 5, 7, 11, 13, 17, 19]
) |
Read a script from the named filename into the interpreter, where s is a string. The functions defined in the script are then available for use from SAGE/PARI.
If foo.gp is a script that contains
{foo(n) = n^2 }
read("foo.gp")
, then the command
pari("foo(12)")
will create the Python/PARI gen which
is the integer 144.
CONSTRAINTS: The PARI script must *not* contain the following function calls:
print, default, ??? (please report any others that cause trouble)
) |
Set the debug PARI C library variable.
) |
Sets the PARI default real precision, both for creation of new objects and for printing. This is the number of digits *IN DECIMAL* that real numbers are printed or computed to by default.
Returns the previous PARI real precision.
) |
Sets Pari's current random number seed.
This should not be called directly; instead, use Sage's global
random number seed handling in sage.misc.randstate
and call current_randstate().set_seed_pari()
.
sage: pari.setrand(12345) sage: pari.getrand() 12345
) |
vector(long n, entries=None): Create and return the length n PARI vector with given list of entries.
sage: pari.vector(5, [1, 2, 5, 4, 3]) [1, 2, 5, 4, 3] sage: pari.vector(2, [x, 1]) [x, 1] sage: pari.vector(2, [x, 1, 5]) Traceback (most recent call last): ... IndexError: length of entries (=3) must equal n (=2)
Special Functions: __call__,
__eq__,
__ge__,
__gt__,
__init__,
__le__,
__lt__,
__ne__,
__nth_prime,
__repr__,
_unsafe_deallocate_pari_stack
) |
Create the PARI object obtained by evaluating s using PARI.
sage: pari([2,3,5]) [2, 3, 5] sage: pari(Matrix(2,2,range(4))) [0, 1; 2, 3] sage: pari(x^2-3) x^2 - 3
) |
nth_prime(n): returns the n-th prime, where n is a C-int
) |
) |
See About this document... for information on suggesting changes.