Pari/GP Reference Documentation |
Contents - Index - Meta commands |

addprimes bestappr bezout bezoutres bigomega binomial chinese content contfrac contfracpnqn core coredisc dirdiv direuler dirmul divisors eulerphi factor factorback factorcantor factorff factorial factorint factormod ffinit fibonacci gcd hilbert isfundamental ispower isprime ispseudoprime issquare issquarefree kronecker lcm moebius nextprime numbpart numdiv omega precprime prime primepi primes qfbclassno qfbcompraw qfbhclassno qfbnucomp qfbnupow qfbpowraw qfbprimeform qfbred qfbsolve quadclassunit quaddisc quadgen quadhilbert quadpoly quadray quadregulator quadunit removeprimes sigma sqrtint zncoppersmith znlog znorder znprimroot znstar | |

addprimes({x = []}) | |

adds the integers contained in the
vector x (or the single integer x) to a special table of
"user-defined primes", and returns that table. Whenever The entries in x are not checked for primality, and in fact they need only be positive integers. The algorithm makes sure that all elements in the table are pairwise coprime, so it may end up containing divisors of the input integers. It is a useful trick to add known composite numbers, which the function
To remove primes from the list use The library syntax is | |

bestappr(x,A,{B}) | |

if B is omitted, finds the best rational
approximation to x belongs to If B is present, x is assumed to be of type The library syntax is | |

bezout(x,y) | |

finds u and v minimal in a natural sense such that x*u+y*v = gcd(x,y). The arguments must be both integers or both polynomials, and the result is a row vector with three components u, v, and gcd(x,y).
The library syntax is | |

bezoutres(x,y) | |

as The library syntax is | |

bigomega(x) | |

number of prime divisors of |x| counted with multiplicity. x must be an integer. The library syntax is | |

binomial(x,y) | |

binomial coefficient binom{x}{y}. Here y must be an integer, but x can be any PARI object. The library syntax is | |

chinese(x,{y}) | |

if x and y are both intmods or both polmods, creates (with the same type) a z in the same residue class as x and in the same residue class as y, if it is possible. This function also allows vector and matrix arguments, in which case the operation is recursively applied to each component of the vector or matrix. For polynomial arguments, it is applied to each coefficient. If y is omitted, and x is a vector, Finally The library syntax is | |

content(x) | |

computes the gcd of all the coefficients of x,
when this gcd makes sense. This is the natural definition
if x is a polynomial (and by extension a power series) or a
vector/matrix. This is in general a weaker notion than the
If x is a scalar, this simply returns the absolute value of x if x is
rational ( The content of a rational function is the ratio of the contents of the
numerator and the denominator. In recursive structures, if a
matrix or vector
The library syntax is | |

contfrac(x,{b},{nmax}) | |

creates the row vector whose components are the partial quotients of the continued fraction expansion of x. That is a result [a_0,...,a_n] means that x ~ a_0+1/(a_1+...+1/a_n)...). The output is normalized so that a_n != 1 (unless we also have n = 0). The number of partial quotients n is limited to nmax. If x is a real number, the expansion stops at the last significant partial quotient if nmax is omitted. x can also be a rational function or a power series. If a vector b is supplied, the numerators will be equal to the coefficients of b (instead of all equal to 1 as above). The length of the result is then equal to the length of b, unless a partial remainder is encountered which is equal to zero, in which case the expansion stops. In the case of real numbers, the stopping criterion is thus different from the one mentioned above since, if b is too long, some partial quotients may not be significant. If b is an integer, the command is understood as The library syntax is
, or gcf(x)
, where nmax
is a C integer.gcf2(b,x) | |

contfracpnqn(x) | |

when x is a vector or a one-row matrix, x is considered as the list of partial quotients [a_0,a_1,...,a_n] of a rational number, and the result is the 2 by 2 matrix [p_n,p_{n-1};q_n,q_{n-1}] in the standard notation of continued fractions, so p_n/q_n = a_0+1/(a_1+...+1/a_n)...). If x is a matrix with two rows [b_0,b_1,...,b_n] and [a_0,a_1,...,a_n], this is then considered as a generalized continued fraction and we have similarly p_n/q_n = 1/b_0(a_0+b_1/(a_1+...+b_n/a_n)...). Note that in this case one usually has b_0 = 1. The library syntax is | |

core(n,{flag = 0}) | |

if n is a non-zero integer written as
n = df^2 with d squarefree, returns d. If The library syntax is
) and core0(n,0)
( = core2(n)
).core0(n,1) | |

coredisc(n,{flag}) | |

if n is a non-zero integer written as
n = df^2 with d fundamental discriminant (including 1), returns d. If
The library syntax is
) and
coredisc(n,0)
( = coredisc2(n)
).coredisc(n,1) | |

dirdiv(x,y) | |

x and y being vectors of perhaps different lengths but with y[1] != 0 considered as Dirichlet series, computes the quotient of x by y, again as a vector. The library syntax is | |

direuler(p = a,b,expr,{c}) | |

computes the
Dirichlet series associated to the Euler product of
expression The series is output as a vector of coefficients. If c is present, output
only the first c coefficients in the series. The following command computes
the
The library syntax is | |

dirmul(x,y) | |

x and y being vectors of perhaps different lengths considered as Dirichlet series, computes the product of x by y, again as a vector. The library syntax is | |

divisors(x) | |

creates a row vector whose components are the
divisors of x. The factorization of x (as output by By definition, these divisors are the products of the irreducible
factors of n, as produced by The library syntax is | |

eulerphi(x) | |

Euler's phi
(totient) function of |x|, in other words
|( The library syntax is | |

factor(x,{lim = -1}) | |

general factorization function. If x is of type integer, rational, polynomial or rational function, the result is a two-column matrix, the first column being the irreducibles dividing x (prime numbers or polynomials), and the second the exponents. If x is a vector or a matrix, the factoring is done componentwise (hence the result is a vector or matrix of two-column matrices). By definition, 0 is factored as 0^1. If x is of type integer or rational, the factors are
An argument The polynomials or rational functions to be factored must have scalar
coefficients. In particular PARI does Note that PARI tries to guess in a sensible way over which ring you want to factor. Note also that factorization of polynomials is done up to multiplication by a constant. In particular, the factors of rational polynomials will have integer coefficients, and the content of a polynomial or rational function is discarded and not included in the factorization. If needed, you can always ask for the content explicitly:
See also The library syntax is
),
factor0(x,-1)
( = smallfact(x)
).factor0(x,0) | |

factorback(f,{e},{nf}) | |

gives back the factored object
corresponding to a factorization. The integer 1 corresponds to the empty
factorization. If the last argument is of number field type (e.g.created by
If e is present, e and f must be vectors of the same length (e being integral), and the corresponding factorization is the product of the f[i]^{e[i]}. If not, and f is vector, it is understood as in the preceding case with e
a vector of 1 (the product of the f[i] is returned). Finally, f can be a
regular factorization, as produced with any
In the fourth example, 2 and 3 are interpreted as principal ideals in a
cubic field. In the fifth one, The library syntax is | |

factorcantor(x,p) | |

factors the polynomial x modulo the
prime p, using distinct degree plus
Cantor-Zassenhaus. The coefficients of x must be
operation-compatible with The library syntax is | |

factorff(x,p,a) | |

factors the polynomial x in the field
The library syntax is | |

factorial(x) | |

or x!: factorial of x. The expression x!
gives a result which is an integer, while The library syntax is
factorial(x). x must be a
long
integer and not a PARI integer. | |

factorint(n,{flag = 0}) | |

factors the integer n into a product of
pseudoprimes (see This gives direct access to the integer factoring engine called by most
arithmetical functions. You are invited to play with the flag settings and watch the internals at
work by using The library syntax is | |

factormod(x,p,{flag = 0}) | |

factors the polynomial x modulo
the prime integer p, using Berlekamp. The coefficients of x must be
operation-compatible with The library syntax is
) and
factormod(x,p,0)
( = simplefactmod(x,p)
).factormod(x,p,1) | |

fibonacci(x) | |

x^{{th}} Fibonacci number. The library syntax is | |

ffinit(p,n,{v = x}) | |

computes a monic polynomial of degree
n which is irreducible over The library syntax is | |

gcd(x,{y}) | |

creates the greatest common divisor of x
and y. x and y can be of quite general types, for instance both
rational numbers. If y is omitted and x is a vector, returns the
{gcd} of all components of x, i.e.this is equivalent to
When x and y are both given and one of them is a vector/matrix type,
the GCD is again taken recursively on each component, but in a different way.
If y is a vector, resp.matrix, then the result has the same type as y,
and components equal to The algorithm used is a naive Euclid except for the following inputs:
The library syntax is rational polynomials, one also has
.modulargcd(x,y) | |

hilbert(x,y,{p}) | |

Hilbert symbol of x and y modulo p. If x and y are of type integer or fraction, an explicit third parameter p must be supplied, p = 0 meaning the place at infinity. Otherwise, p needs not be given, and x and y can be of compatible types integer, fraction, real, intmod a prime (result is undefined if the modulus is not prime), or p-adic. The library syntax is | |

isfundamental(x) | |

true (1) if x is equal to 1 or to the discriminant of a quadratic field, false (0) otherwise. The library syntax is
long should be used if x is known to be of type
integer. | |

ispower(x,{k}, {&n}) | |

if k is given, returns true (1) if x is a k-th power, false (0) if not. In this case, x may be an integer or polynomial, a rational number or function, or an intmod a prime or p-adic. If k is omitted, only integers and fractions are allowed and the
function returns the maximal k If a third argument &n is given and a k-th root was computed in the process, then n is set to that root. The library syntax is | |

isprime(x,{flag = 0}) | |

true (1) if x is a (proven) prime
number, false (0) otherwise. This can be very slow when x is indeed
prime and has more than 1000 digits, say. Use If If If The library syntax is
long should be used if x is known to be of
type integer. | |

ispseudoprime(x,{flag}) | |

true (1) if x is a strong pseudo
prime (see below), false (0) otherwise. If this function returns false, x
is not prime; if, on the other hand it returns true, it is only highly likely
that x is a prime number. Use If There are no known composite numbers passing this test (in particular, all
composites If The library syntax is
long should be used if x is known to be of type
integer. | |

issquare(x,{&n}) | |

true (1) if x is a square, false (0)
if not. What "being a square" means depends on the type of x: all
If n is given and an exact square root had to be computed in
the checking process, puts that square root in n. This is the case when
x is a
This will The library syntax is | |

issquarefree(x) | |

true (1) if x is squarefree, false (0) if not. Here x can be an integer or a polynomial. The library syntax is
long should be used if x is known to be of type
integer. This issquarefree is just the square of the Moebius
function, and is computed as a multiplicative arithmetic function much like
the latter. | |

kronecker(x,y) | |

Kronecker symbol (x|y), where x and y must be of type integer. By
definition, this is the extension of Legendre symbol to
The library syntax is | |

lcm(x,{y}) | |

least common multiple of x and y, i.e.such that {lcm}(x,y)*gcd(x,y) = {abs}(x*y). If y is omitted and x is a vector, returns the {lcm} of all components of x. When x and y are both given and one of them is a vector/matrix type,
the LCM is again taken recursively on each component, but in a different way.
If y is a vector, resp.matrix, then the result has the same type as y,
and components equal to Note that
Indeed,
The library syntax is | |

moebius(x) | |

Moebius mu-function of |x|. x must be of type integer. The library syntax is | |

nextprime(x) | |

finds the smallest pseudoprime (see
The library syntax is | |

numdiv(x) | |

number of divisors of |x|. x must be of type integer. The library syntax is | |

numbpart(n) | |

gives the number of unrestricted partitions of
n, usually called p(n) in the litterature; in other words the number of
nonnegative integer solutions to a+2b+3c+.. .= n. n must be of type
integer and 1 The library syntax is | |

omega(x) | |

number of distinct prime divisors of |x|. x must be of type integer. The library syntax is | |

precprime(x) | |

finds the largest pseudoprime (see
The library syntax is | |

prime(x) | |

the x^{{th}} prime number, which must be among the precalculated primes. The library syntax is | |

primepi(x) | |

the prime counting function. Returns the number of
primes p, p The library syntax is | |

primes(x) | |

creates a row vector whose components are the first x prime numbers, which must be among the precalculated primes. The library syntax is | |

qfbclassno(D,{flag = 0}) | |

ordinary class number of the quadratic
order of discriminant D. In the present version If
Here are a few examples:
The library syntax is
),
qfbclassno(D)
( = classno2(D)
), and finally
we have the function qfbclassno(D,1)
which computes the class number of
an imaginary quadratic field by counting reduced forms, an O(|D|)
algorithm. See also hclassno(D)
qfbhclassno. | |

qfbcompraw(x,y) | |

composition of the binary quadratic forms x and y, without reduction of the result. This is useful e.g.to compute a generating element of an ideal. The library syntax is | |

qfbhclassno(x) | |

Hurwitz class number of x, where
x is non-negative and congruent to 0 or 3 modulo 4. For x > 5.
10^5, we assume the GRH, and use The library syntax is | |

qfbnucomp(x,y,l) | |

composition of the primitive positive
definite binary quadratic forms x and y (type The current implementation is straightforward and in general The library syntax is | |

qfbnupow(x,n) | |

n-th power of the primitive positive definite
binary quadratic form x using Shanks's NUCOMP and NUDUPL algorithms
(see The library syntax is | |

qfbpowraw(x,n) | |

n-th power of the binary quadratic form
x, computed without doing any reduction (i.e.using The library syntax is | |

qfbprimeform(x,p) | |

prime binary quadratic form of discriminant
x whose first coefficient is the prime number p. By abuse of notation,
p = ± 1 is a valid special case which returns the unit form. Returns an
error if x is not a quadratic residue mod p. In the case where x > 0,
p < 0 is allowed, and the "distance" component of the form is set equal
to zero according to the current precision. (Note that negative definite
The library syntax is | |

qfbred(x,{flag = 0},{D},{isqrtD},{sqrtD}) | |

reduces the binary quadratic form x (updating Shanks's distance function
if x is indefinite). The binary digits of 1: perform a single reduction step 2: don't update Shanks's distance D, The library syntax is Also available are
where x is definite),qfbred(x)and for indefinite forms:
),qfbred(x)
),qfbred(x,1)
),qfbred(x,2,,isqrtD)
).qfbred(x,3,,isqrtD) | |

qfbsolve(Q,p) | |

Solve the equation Q(x,y) = p over the integers, where Q is a binary quadratic form and p a prime number. Return [x,y] as a two-components vector, or zero if there is no solution. Note that this function returns only one solution and not all the solutions. Let D = \disc Q. The algorithm used runs in probabilistic polynomial time
in p (through the computation of a square root of D modulo p); it is
polynomial time in D if Q is imaginary, but exponential time if Q is
real (through the computation of a full cycle of reduced forms). In the
latter case, note that The library syntax is | |

quadclassunit(D,{flag = 0},{tech = []}) | |

Buchmann-McCurley's sub-exponential algorithm for computing the class group of a quadratic order of discriminant D. This function should be used instead of If Optional parameter The result is a vector v with 3 components if D < 0, and 4 otherwise. The correspond respectively to
The library syntax is
.buchreal(D,flag,c_1,c_2) | |

quaddisc(x) | |

discriminant of the quadratic field
The library syntax is | |

quadhilbert(D,{pq}) | |

relative equation defining the Hilbert class field of the quadratic field of discriminant D. If D < 0, uses complex multiplication (Schertz's variant). The technical component pq, if supplied, is a vector [p,q] where p, q are the prime numbers needed for the Schertz's method. More precisely, prime ideals above p and q should be non-principal and coprime to all reduced representatives of the class group. In addition, if one of these ideals has order 2 in the class group, they should have the same class. Finally, for efficiency, gcd(24,(p-1)(q-1)) should be as large as possible. The routine returns 0 if [p,q] is not suitable. If D > 0 Stark units are used and (in rare cases) a
vector of extensions may be returned whose compositum is the requested class
field. See The library syntax is | |

quadgen(D) | |

creates the quadratic number omega = (a+sqrt{D})/2 where a = 0 if x = 0 mod 4, a = 1 if D = 1 mod 4, so that (1,omega) is an integral basis for the quadratic order of discriminant D. D must be an integer congruent to 0 or 1 modulo 4, which is not a square. The library syntax is | |

quadpoly(D,{v = x}) | |

creates the "canonical" quadratic
polynomial (in the variable v) corresponding to the discriminant D,
i.e.the minimal polynomial of The library syntax is | |

quadray(D,f,{lambda}) | |

relative equation for the ray
class field of conductor f for the quadratic field of discriminant D
using analytic methods. A For D < 0, uses the sigma function. If supplied, For D > 0, uses Stark's conjecture, and a vector of relative equations may be
returned. See The library syntax is | |

quadregulator(x) | |

regulator of the quadratic field of
positive discriminant x. Returns an error if x is not a discriminant
(fundamental or not) or if x is a square. See also The library syntax is | |

quadunit(D) | |

fundamental unit of the
real quadratic field The library syntax is | |

removeprimes({x = []}) | |

removes the primes listed in x from
the prime number table. In particular The library syntax is | |

sigma(x,{k = 1}) | |

sum of the k^{{th}} powers of the positive divisors of |x|. x and k must be of type integer. The library syntax is
( =
gsumdivk(x,k)
), where k is a C long integer.sigma(x,k) | |

sqrtint(x) | |

integer square root of x, which must be a non-negative integer. The result is non-negative and rounded towards zero. The library syntax is | |

zncoppersmith(P, N, X, {B = N}) | |

finds all integers x_0 with
|x_0| The library syntax is | |

znlog(x,g) | |

g must be a primitive root mod a prime p, and
the result is the discrete log of x in the multiplicative group
( The library syntax is | |

znorder(x,{o}) | |

x must be an integer mod n, and the
result is the order of x in the multiplicative group ( The library syntax is | |

znprimroot(n) | |

returns a primitive root (generator) of
( The library syntax is | |

znstar(n) | |

gives the structure of the multiplicative group
( The library syntax is | |