NAME

libPARI - Functions and Operations available in PARI and GP

DESCRIPTION

The functions and operators available in PARI and in the GP/PARI calculator are numerous and everexpanding. Here is a description of the ones available in version 1.39.03.01. It should be noted that many of these functions accept quite different types as arguments, but others are more restricted. The list of acceptable types will be given for each function or class of functions. Except when stated otherwise, it is understood that a function or operation which should make natural sense is legal. In this chapter, we will describe the functions according to a rough classification. For the functions in alphabetical order, see the general index.

When not mentioned otherwise, the result of a function is assumed implicitly to be a GEN. Most other functions return an object of type long integer in C.

Standard monadic or dyadic operators.

+-

The expressions +x and -x refer to monadic operators (+x does nothing and -x negates x).

The library syntax is gneg(x) for -x.

+, -

The expression x+y is the sum and x-y is the difference of x and y. Among the prominent impossibilities are addition/subtraction between a scalar type and a vector or a matrix, between vector/matrices of incompatible sizes and between an integermod and a real number.

The library syntax is gadd(x,y) for x+y, gsub(x,y) for x-y.

*

The expression x*y is the product of x and y. Among the prominent impossibilities are multiplication between vector/matrices of incompatible sizes, between an integermod and a real number. Note that because of vector and matrix operations, * is not necessarily commutative. Note also that since multiplication between two column or two row vectors is not allowed, to obtain the scalar product of two vectors of the same length, you must multiply a line vector by a column vector, if necessary by transposing one of the vectors (using ~ or trans( ), see section 8).

The library syntax is gmul(x,y) for x*y.

/

The expression x/y is the quotient of x and y. In addition to the impossibilities for multiplication, note that if the divisor is a matrix, it must be an invertible square matrix, and in that case the result is x*y^{-1}. Furthermore note that the result is as exact as possible: in particular, division of two integers always gives a rational number (which may be an integer if the quotient is exact) and not the Euclidean quotient (see x\y for that), and similarly the quotient of two polynomials is a rational function in general. To obtain the approximate real value of the quotient of two integers, add 0. to the result; to obtain the approximate p-adic value of the quotient of two integers, add O(p^k) to the result; finally, to obtain the taylor series expansion of the quotient of two polynomials, add O(X^k) to the result or use the taylor function (see section 7).

The library syntax is gdiv(x,y) for x/y.

\

The expression x\y is the Euclidean quotient of x and y. The types must be either both integer or both polynomials. The result is the Euclidean quotient. In the case of integer division, the quotient is such that the corresponding remainder is non-negative.

The library syntax is gdivent(x,y) for x\y.

\/

The expression x\/y is the Euclidean quotient of x and y. The types must be either both integer or both polynomials. The result is the rounded Euclidean quotient. In the case of integer division, the quotient is such that the corresponding remainder is smallest in absolute value and in case of a tie the quotient closest to +\infty is chosen.

The library syntax is gdivround(x,y) for x\/y.

%

The expression x%y is the Euclidean remainder of x and y. The modulus y must be of type integer or polynomial. The result is the remainder, always non-negative in the case of integers. Allowed dividend types are scalar exact types when the modulus is an integer, and polynomials, polymods and rational functions when the modulus is a polynomial.

The library syntax is gmod(x,y) for x%y.

divres(x,y)

creates a column vector with two components, the first being the Euclidean quotient, the second the Euclidean remainder, of the division of x by y. This avoids the need to do two divisions if one needs both the quotient and the remainder. The arguments must be both integers or both polynomials, and in the case of integers the remainder is of the sign of the dividend.

The library syntax is gdiventres(x,y).

^

The expression x^y is powering. If the exponent is an integer, then exact operations are performed using binary powering techniques. In particular, in this case the first argument cannot be a vector or matrix unless it is a square matrix (and moreover invertible if the exponent is negative). If the exponent is not of type integer, this is treated as a transcendental function (see section 3), and in particular has the effect of componentwise powering on vector or matrices.

The library syntax is gpui(x,y,prec) for x^y where the precision parameter prec must be given only if y is not integral but x is an exact (real or complex) type.

In addition, there are two shift functions (i.e. multiplication and division by powers of 2) which are faster than the general multiplication or division routines:

shift(x,n)

shift x componentwise left by n bits if n>=0 and right by -n bits if n<0. A left shift by n corresponds to multiplication by 2^n. A right shift by -n corresponds to a Euclidean division of x by 2^{-n} with a remainder of the same sign as x, hence is not the same (in general) as x\2^n.

The library syntax is gshift(x,n) where n is a C-long integer.

shiftmul(x,n)

multiply x by 2^n. The difference with shift is that when n<0, the ordinary division takes place, hence for example if x is an integer the result may be a fraction, while for shift Euclidean division takes place when n<0 hence if x is an integer the result is still an integer.

The library syntax is gmul2n(x,n) where n is a C-long integer.

comparison and boolean operators.

The six standard comparison operators <=, <, >=, >, ==, != are available in GP, and in library mode under the names gle, glt, gge, ggt, geq, gne respectively. The library syntax is co(x,y), where co is the comparison operator. The result is 1 (as a GEN) if the comparison is true, 0 (as a GEN) if it is false.

The standard boolean functions | | (inclusive or) and && (and) are also available, and the library syntax is gor(x,y) and gand(x,y) respectively. Note that to avoid confusion with the factorial function, there is no ! (not) operator, but this can easily be circumvented.

In library mode, it is in fact usually preferable to use the two basic functions which are gcmp(x,y) which gives the sign (1, 0, or -1) of x-y, where x and y must be in R, and gegal(x,y) which can be applied to any two PARI objects x and y and gives 1 (i.e. true) if they are equal (but not necessarily identical), 0 (i.e. false) otherwise. Particular cases of gegal which should be used are gcmp0(x) (x=0 ?), gcmp1(x) (x=1 ?), and gcmp_1 (x) (x=-1 ?).

Note that gcmp0(x) tests whether x is equal to zero, even if x is not an exact object. To test whether x is an exact object which is equal to zero, one must use isexactzero.

Also note that the gcmpx and gegal functions return a C-integer, and not a GEN like gle etc.

GP accepts the following synonyms for some of the above functions: since there is no bitwise and or bitwise or, | and & are accepted as synonyms of | | and && respectively. Also, <> is accepted as a synonym for !=. On the other hand, = is definitely not a synonym for == since it is the assignment statement.

lex(x,y)

gives the result of a lexicographic comparison between x and y. This is to be interpreted in quite a wide sense. For example, the vector [1,3] will be considered smaller than the longer vector [1,3,-1] (but of course larger than [1,2,5]), i.e. lex([1,3],[1,3,-1]) will give -1 as a result.

The library syntax is lexcmp(x,y).

sign(x)

sign of x, which must be of type integer, real or fraction. The result (0, 1 or -1) is a C-long integer.

The library syntax is gsigne(x).

max(x,y) and min(x,y)

create the maximum and minimum of x and y when they can be compared.

The library syntax is gmax(x,y) and gmin(x,y).

Important remark.

In all the above library syntaxes, we have given only the basic names of the functions. For example gadd(x,y ) assumes that x and y are PARI objects (the GEN type) and creates the result x+y on the PARI stack. From most of these basic names, the names and effects of other functions can be obtained in the following way. We give the example for gadd, but the same is true for all the other functions above, and a few more that we have not given:

gaddgs(x,y): here x is a GEN, y is an ordinary C-long integer.

gaddsg(x,y): here x is an ordinary C-long integer, y is a GEN.

gaddz(x,y,z), gaddgsz(x,y,z), gaddsgz(x,y,z): here z is a preexisting GEN and the result of the corresponding operation is put in z. The size of the PARI stack does not change.

As simplification to programming, for many functions beginning with a g, such as gadd, one can replace the g by an l to obtain a long result instead of a GEN (i.e. pointer to long) result. For instance ladd(x,y) is identical with ((long)gadd(x,y)). These macros are written in the files listed in gencom.h. Note that ldiv is an ANSI C function name which is used to mean (long)gdiv in PARI.

Conversions and similar elementary functions or commands

Many of the conversion functions are rounding or truncating operations. In this case, if the argument is a rational function, the result is the Euclidean quotient of the numerator by the denominator, and if the argument is a vector or a matrix, the operation is done componentwise. This will not be restated for every function.

allocatemem(x)

this is a very special operation which allows the user to change the stack size after initialization. x must be a non-negative integer. If x>2, a new stack of size 16*\lceil x/16\rceil bytes will be allocated, all the PARI data on the old stack will be moved to the new one, and the old stack will be freed and discarded. If x=0, 1 or 2, the size of the new stack will be double that of the old one. Finally, in case x=0, after doubling the stack, a warning message will be printed.

Although it is a function, this must be the only instruction in a GP line. The technical reason is that this program terminates by a longjmp and not by a return.

The library syntax is allocatemoremem(x), where x is an unsigned long, and the return type is void. GP uses a variant which ends by a longjmp.

binary(x)

outputs the vector of the binary digits of |x|. Here x can be an integer, a real number (in which case the result has two components, one for the integer part, one for the fractional part) or a vector/matrix.

The library syntax is binaire(x).

bittest(x,n)

outputs the n^{th} bit of |x| starting from the right (i.e. the coefficient of 2^n in the binary expansion of x. The result is 0 or 1.

The library syntax is bittest(x,n), where n as well as the result are C-long integers.

bytesize(x)

outputs the total number of bytes occupied by the tree representing the PARI object x.

The library syntax is taille2(x) which returns a C-long integer. The function taille returns the number of words instead.

ceil(x)

ceiling of x. When x is in R, the result is the smallest integer greater than or equal to x.

The library syntax is gceil(x).

centerlift(x)

lifts an element x=a mod n of Z/nZ to a in Z, and similarly lifts a polymod to a polynomial. This is the same as lift except that in the particular case of elements of Z/nZ, the lift y is such that -n/2<y<= n/2. If x is of type fraction, complex, quadratic, polynomial, power series, rational function, vector or matrix, the lift is done for each coefficient. Forbidden types for x are reals and p-adics. Note that the main variable of the lift of a polymod will be variable number 0 (i.e. 'X') if the rules concerning the creation of polymods explained in Chapter 2 are observed.

The library syntax is centerlift(x).

changevar(x,y)

create a copy of the object x where its variables are modified according to the permutation specified by the vector y. For example, assume that the variables have been introduced in the order x, a, b, c. Then, if y is the vector [x,c,a,b], the variable a will be replaced by c, b by a, and c by b, x being unchanged. Note that the permutation must be completely specified, e.g. [c,a,b] would not work, since this would replace x by c, and leave a and b unchanged (as well as c which is the fourth variable of the initial list). In particular, the new variable names must be distinct.

The library syntax is changevar(x,y).

components of a PARI object

There are essentially three ways to extract the components from a PARI object.

The first and most general, is the function compo(x,n) which extracts the n^{th}-component of x. This is to be understood as follows: every PARI type has one or two initial code words. The components are counted, starting at 1, after these code words. In particular if x is a vector, this is indeed the n^{th}-component of x, if x is a matrix, the n^{th} column, if x is a polynomial, the n^{th} coefficient (i.e. of degree n-1), and for power series, the n^{th} significant coefficient. The use of the function compo implies the knowledge of the structure of the different PARI types, which can be recalled by typing \t under GP.

The library syntax is compo(x,n), where n is a C-long integer.

The two other methods are more natural but more restricted. First, the function coeff(x,n) gives the coefficient of degree n of the polynomial or power series x, with respect to the main variable of x (to see the order of the variables or to change it, use the function reorder, see section 11). In particular if n is less than the valuation of x or in the case of a polynomial, greater than the degree, the result is zero (contrary to compo which would send an error message). If x is a power series and n is greater than the largest significant degree, then an error message is issued.

For greater flexibility, vector or matrix types are also accepted for x, and the meaning is then identical with that of compo.

Finally note that a scalar type is considered by coeff as a polynomial of degree zero.

The library syntax is truecoeff(x,n).

The third method is specific to vectors or matrices under GP. If x is a (row or column) vector, then x[n] represents the n^{th} component of x, i.e. compo(x,n). It is more natural and shorter to write. If x is a matrix, x[m,n] represents the coefficient of row m and column n of the matrix, x[m,] represents the m^{th} row of x, and x[,n] represents the n^{th} column of x.

Finally note that in library mode, the macro coeff(x,m,n) exists with exactly the meaning of x[m,n] under GP when x is a matrix. This macro should not be confused with the two-variable macro coeff used primarily for polynomials and power series under GP.

In addition the library mode macro coeff does not create a copy of the coefficient (contrary to all the GP functions) and can be put on the left side of an assignment statement, and has value a long integer. The macro gcoeff can be used as a synonym for (GEN)coeff hence cannot be put on the left side of an assignment.

conj(x) or x_

conjugate of x. The meaning of this is clear, except that for real quadratic numbers, it means conjugation in the real quadratic field. This function has no effect on integers, reals, integermods, fractions or p-adics. The only forbidden type is polymod (see conjvec for this).

The library syntax is gconj(x).

conjvec(x)

conjugate vector representation of x. If x is a polymod mod(a,q), this gives a vector of length degree(q) containing the complex embeddings of the polymod if q has integral or rational coefficients, and the conjugates of the polymod if q has some integermod coefficients. The order is the same as that of the roots functions. If x is a integer or a rational number, the result is x. If x is a (row or column) vector, the result is a matrix whose columns are the conjugate vectors of the individual elements of x.

The library syntax is conjvec(x,prec), where prec is a C-long integer.

cvtoi(x)

If x is in R, truncates x to an integer. If the result is not significant because the exponent of x is too large compared to its precision, no error occurs, but the number of lost significant bits is put at the address specified in a second argument. This is transparent under GP, but this second argument must be given in library mode. If no digits are lost, this second argument contains the negative of the number of significant bits of the fractional part.

The library syntax is gcvtoi(x,& e), where e is a C-long integer.

denom(x)

lowest denominator of x. The meaning of this is clear when x is a rational number or function. When x is an integer or a polynomial, the result is equal to 1. When x is a vector or a matrix, the lowest common denominator of the components of x is computed. All other types are forbidden.

The library syntax is denom(x).

floor(x)

floor of x. When x is in R, the result is the largest integer smaller than or equal to x.

The library syntax is gfloor(x).

frac(x)

fractional part of x. Identical to x-floor(x). If x is real, the result is in [0,1[.

The library syntax is gfrac(x).

getheap()

returns a two-component row vector giving the number of objects on the heap and the amount of memory they occupy in long words. Useful mainly for debugging purposes.

The library syntax is getheap().

getrand()

returns the current value of the random number seed. Useful mainly for debugging purposes.

The library syntax is getrand(). The value returned is a GEN.

getstack()

returns the current value of top-avma, i.e. the number of bytes used up to now on the stack. Useful mainly for debugging purposes.

The library syntax is getstack(). The value returned is a GEN.

gettime()

returns the time (in milliseconds) elapsed since either the last call to gettime, or to the beginning of the containing GP instruction (if inside GP), whichever came last.

The library syntax is gettime(). The value returned is a GEN.

imag(x)

imaginary part of x. When x is a quadratic number, this is the coefficient of omega in the ``canonical'' integral basis (1, omega).

The library syntax is gimag(x).

length(x)

number of non-code words in x really used (i.e. the effective length minus 2 for integers and polynomials). In particular, the degree of a polynomial is equal to its length minus 1.

The library syntax is glength(x).

lift(x)

lifts an element x=a mod n of Z/nZ to a in Z, and similarly lifts a polymod to a polynomial. If x is of type fraction, complex, quadratic, polynomial, power series, rational function, vector or matrix, the lift is done for each coefficient. Forbidden types for x are reals and p-adics. Note that the main variable of the lift of a polymod will be variable number 0 (i.e. 'X') if the rules concerning the creation of polymods explained in Chapter 2 are observed.

The library syntax is lift(x).

mod(x,y)

creates the PARI object (x mod y), i.e. an integermod or a polymod. y must be an integer or a polynomial. If y is an integer, x must be an integer. If y is a polynomial, x must be a scalar or a polynomial. The result is put on the PARI stack.

This function is not the same as x% y, the result of which is an integer or a polynomial.

The library syntax is gmodulcp(x,y).

modp(x,y)

same effect as mod, except that the created result is put on the heap and not on the stack, and hence becomes a permanent copy which cannot be erased later by garbage collecting (see 4.2.4). In particular, care should be taken to avoid creating too many such objects, since the heap is very small (typically a few thousand objects at most).

The library syntax is gmodulo(x,y).

norm(x)

algebraic norm of x, i.e. the product of x with its conjugate (no square roots are taken), or conjugates for polymods. For vectors and matrices, the norm is taken componentwise and hence is not the L^2-norm (see norml2 below). Note that the norm of an element of R is its square, so as to be compatible with the complex norm.

The library syntax is gnorm(x).

norml2(x)

square of the L^2-norm of x. x must be a (row or column) vector.

The library syntax is gnorml2(x).

numer(x)

numerator of x. When x is a rational number or function, the meaning is clear. When x is an integer or a polynomial, the result is x itself. When x is a vector or a matrix, then numer(x) is defined to be denom(x)*x. All other types are forbidden.

The library syntax is numer(x).

padicprec(x,p)

absolute p-adic precision of the object x. This is the minimum precision of the components of x. The result is VERYBIGINT (2^{31}-1 for 32-bit machines or 2^{63}-1 for 64-bit machines) if x is an exact object.

The library syntax is padicprec(x,p) and the result is a C-long integer.

permutation(n,k)

generates the k-th permutation (as a row vector of length n) of the numbers 1 to n. The number k is taken modulo n! .

The library syntax is permute(n,k), where n is a C-long integer.

permutation2num(x)

given a permutation x on n elements, gives the number k such that x=permutation(n,k), i.e. inverse function of permutation.

The library syntax is permuteInv(x).

polvar(x)

gives the main variable of the object x, and p if x is a p-adic number. Gives an error if x has no variable associated to it. Note that this function is useful only in GP, since in library mode the function gvar is more useful.

The library syntax is gpolvar(x). However, in library mode, this function should not be used. Instead, test whether x is a p-adic (type 7), in which case p is in x[2], or call the function gvar(x) which returns the variable number of x if it exists, BIGINT otherwise.

poly(x,v)

transform the object x into a polynomial with main variable v. If x is a scalar, this gives a constant polynomial. If x is a power series, the effect is identical to trunc (see below), i.e. it chops off the O(X^k). If x is a vector, this function creates the polynomial whose coefficients are given in x, with x[1] being the leading coefficient (which can be zero).

Warning: this is not a substitution function. It is intended to be quick and dirty. So if you try poly(a,y) on the polynomial a=x+y, you will get y+y, which is not a valid PARI/GP object.

The library syntax is gtopoly(x,v), where v is a variable number.

polyrev(x,v)

transform the object x into a polynomial with main variable v. If x is a scalar, this gives a constant polynomial. If x is a power series, the effect is identical to trunc (see below), i.e. it chops off the O(X^k). If x is a vector, this function creates the polynomial whose coefficients are given in x, with x[1] being the constant term. Note that this is the reverse of poly if x is a vector, otherwise it is identical to poly.

The library syntax is gtopolyrev(x,v), where v is a variable number.

prec(x,n)

x being a PARI object and n a C-long integer, creates a new object equal to x but with a new precision n. This is to be understood as follows:

For exact types, no change. For x a vector or a matrix, the operation is done componentwise.

For real x, n is the number of desired significant decimal digits. If n is smaller than the precision of x, x is truncated, otherwise x is extended with zeros.

For x a p-adic or a power series, n is the desired number of significant p-adic or X-adic digits, where X is the main variable of x.

Note that the function prec never changes the type of the result. In particular it is not possible to use prec to obtain a polynomial from a power series. For that, see trunc (see below).

The library syntax is gprec(x,n), where n is a C-long integer.

quadgen(x)

creates the quadratic number omega=(a+ sqrt x)/2 where a=0 if x ~ 0 mod 4, a=1 if x ~ 1 mod 4, so that (1,omega) is an integral basis for the quadratic order of discriminant x. x must be an integer congruent to 0 or 1 modulo 4.

The library syntax is quadgen(x).

quadpoly(x)

creates the ``canonical'' quadratic polynomial corresponding to the discriminant x, i.e. the minimal polynomial of quadgen(x). x must be an integer congruent to 0 or 1 modulo 4.

The library syntax is quadpoly(x).

random()

gives a random integer between 0 and 2^{31}-1 (in the case of 64-bit machines this can be changed at compilation time to between 0 and 2^{63}-1). This is an internal PARI function and does not depend on the system's random number generator.

The library syntax is genrand() and the result is a C-long integer.

real(x)

real part of x. In the case where x is a quadratic number, this is the coefficient of 1 in the ``canonical'' integral basis (1, omega).

The library syntax is greal(x).

rndtoi(x)

same as cvtoi (see above) except that truncation is replaced by rounding (see round below).

If the result is not significant because the exponent of x is too large compared to its precision, no error occurs, but the number of lost significant bits is put at the address specified in a second argument. This is transparent under GP, but this second argument must be given in library mode. If no digits are lost, this second argument contains the negative of the number of significant bits of the fractional part.

The library syntax is grndtoi(x,& e), where e is a C-long integer.

round(x)

If x is in R, rounds x to the nearest integer. If the exponent of x is too large compared to its precision, the result is undefined and an error message occurs. Use rndtoi above to suppress this error handling.

Important remark: note that, contrary to the other truncation functions (except rndtoi which is essentially the same), this function operates on every coefficient at every level of a PARI object. For example trunc(\dfrac{2.4*X^2-1.7}{X})=2.4*X, whereas round(\dfrac{2.4*X^2-1.7}{X})=\dfrac{2*X^2-2}{X}. An important use of round is to get exact results after a long approximate computation, when theory tells you that the coefficients must be integers.

The library syntax is ground(x).

rounderror(x)

maximum error in decimal digits observed when rounding x. This functions allows the user to easily check the precision of the rounding of a result whose components are supposed to be integers.

The library syntax is rounderror(x) and the result is a C-long integer.

series(x,v)

transform the object x into a power series with main variable v. If x is a scalar, this gives a constant power series with precision given by the global variable precdl (transparent under GP). If x is a polynomial, the precision is the greatest of precdl 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 poly, see above).

The warning given for poly applies here: this is not a substitution function.

The library syntax is gtoser(x,v), where v is a variable number.

setprecision(n)

sets the current default precision equal to n decimal digits if n>0. In any case, it returns the value of the default precision before the change. Apart from the fact that it returns a value, this is identical to the \precision=n command, with the difference that it can be used inside any GP expression or program.

The library syntax is setprecr(n), where n is a C-long integer, as is the returned value.

setrand(n)

reseeds the random number generator to the value n. The initial seed (in UNIX systems at least) is n=1.

The library syntax is setrand(n), where n is a C-long integer. The value returned is n once again, but as a GEN.

setserieslength(n)

sets the current default series length equal to n if n>0. In any case, it returns the value of the default length before the change. Apart from the fact that it returns a value, this is identical to the \serieslength=n command, with the difference that it can be used inside any GP expression or program.

The library syntax is setserieslength(n), where n is a C-long integer, as is the returned value.

settype(x,t)

makes a copy of x and sets its type equal to type number t. This function must be used with extreme caution, otherwise disasters may occur, but one instance where it is extremely useful is settyp(x,14) when x is a rational function (type 13). In this case, the created object, as well as the objects created from it, will not be reduced automatically, making the operations much faster. In fact this function is the only way to create reducible rationals (type 5) or rational functions (type 14) in GP.

The library syntax is gsettype(x,t), where t is a long, but need not be used since the internal function settyp is available. Note that settyp does not create a copy of x, while gsettype does. Note also the different spellings of the internal function settyp and of the GP function settype.

simplify(x)

this function tries to simplify the object x as much as it can. The simplifications do not concern rational functions (which PARI automatically tries to simplify), but type changes. Specifically, a complex or quadratic number whose imaginary part is exactly equal to 0 (i.e. not a real zero) is converted to its real part, and a polynomial of degree zero is converted to its constant term. For all types, this of course occurs recursively. This function is useful in any case, but in particular before the use of arithmetic functions which expect integer arguments, and not for example a complex number of 0 imaginary part and integer real part (which is however printed as an integer).

The library syntax is simplify(x).

size(x)

gives an upper bound for the maximal number of decimal digits of the absolute value of the components of x, off by at most 1.

The library syntax is gsize(x), and the result is a C-long integer.

trunc(x)

truncation of x. When x is in R, this means that the part after the decimal point is chopped away. If the result is not significant because the exponent is too large compared to the precision, an error occurs. Use cvtoi (see above) to suppress this error handling.

Note a very special use of trunc: when applied to a power series, it transforms it into a polynomial or a rational function with denominator a power of X, by chopping away the O(X^k). Similarly, when applied to a p-adic number, it transforms it into an integer or a rational number by chopping away the O(p^k).

The library syntax is gtrunc(x).

type(x)

internal type number (from 1 to 19) of the PARI object x. This is useful only under GP. See also the function settype.

The library syntax is gtype(x), but need not be used since the internal function typ is available. Note that gtype gives a GEN while typ gives a C-long integer. Note also the different spellings of the internal function typ and of the GP function type.

valuation(x,p)

Computes the highest exponent of p dividing x. If p is of type integer, x must be an integer, an integermod whose modulus is divisible by p, a fraction, a q-adic number with q=p, or a polynomial or power series in which case the valuation is the minimum of the valuation of the coefficients.

If p is of type polynomial, x must be of type polynomial or rational function, and also a power series if x is a monomial. If x=0, an error is issued except in case of p-adic numbers and power series, in which case the result is the exponent of the zero. Finally, the valuation of a vector, complex or quadratic number is the minimum of the component valuations. Any other type combinations gives an error.

The library syntax is ggval(x), and the result is a C-long integer.

vec(x)

transform the object x into a row vector. The vector will be with one component only, except when x is a vector/matrix or a quadratic form (in which case the resulting vector is simply the initial object considered as a row vector), but more importantly when x is a polynomial or a power series. In the case of a polynomial, the coefficients of the vector starts with the leading coefficient of the polynomial, while for power series only the significant coefficients are taken into account, but this time by increasing order of degree.

The library syntax is gtovec(x).

vecmax(x)

if x is a vector or a matrix, returns the maximum of the elements of x, otherwise returns a copy of x. Returns -\infty in the form of -(2^{31}-1) (or -(2^{63}-1) for 64-bit machines) if x is empty.

The library syntax is vecmax(x).

vecmin(x)

if x is a vector or a matrix, returns the minimum of the elements of x, otherwise returns a copy of x. Returns +\infty in the form of 2^{31}-1 (or 2^{63}-1 for 64-bit machines) if x is empty.

The library syntax is vecmin(x).

Transcendental functions.

As a general rule, which of course in some cases may have exceptions, transcendental functions operate in the following way:

If the argument is either an integer, a real, a rational, a complex
or a quadratic number, it is, if necessary, first converted to a real
(or complex) number using the current X<precision>precision held in the variable
B<prec>. Note that only exact arguments are converted, while inexact
arguments such as reals are not.

Under GP this is transparent to the user, but when programming in library mode, care must be taken to supply the parameter prec as the last argument of the function if the first argument is an exact object (see 1.2.5.), otherwise disaster will occur.

Note that in library mode
the precision argument C<prec> is a word count including codewords,
i.e. represents the length in words of a real number, while under GP
the precision (which is changed by the command C<C<\>precision>)
is the number of significant decimal digits.

Also note that for the same value of prec you will obtain different results on 32-bit and 64-bit machines. For example if the value of prec is 5, the corresponding accuracy for 32-bit machines is (5-2)* log (2^{32})/ log (10) ~ 28 decimal digits, while for 64-bit machines it is (5-2)* log (2^{64})/ log (10) ~ 57 decimal digits. If you want your programs to run identically on 32-bit and 64-bit machines, you must take care to change the prec parameter that you give according to the bit size, which is determined using the compilation option -DLONG_IS_32BIT or -DLONG_IS_64BIT. For example, if you want the current value of prec to correspond to an accuracy of 38 decimal digits whatever the word size, you could write

{\obeylines\tt #ifdef LONG_IS_32BIT prec = 6; #else prec = 4; #endif }

Note that some accuracies attainable on 32-bit machines cannot be attained on 64-bit machines for parity reasons. For example the default GP accuracy is 28 decimal digits on 32-bit machines, corresponding to prec having the value 5, but this cannot be attained on 64-bit machines.

After possible conversion, the function is computed. Note that even if the argument is real, the result may be complex (e.g. acos(2.0) or acosh(0.0)). Note also that the principal branch is always chosen.

If the argument is an integermod or a C<p>-adic, at present only a
few functions like C<sqrt> (square root), C<sqr> (square), C<log>,
C<exp>, powering, C<teich> (Teichm\"uller character) and C<agm>
(arithmetic-geometric mean) are implemented.
Note that in the case of a C<2>-adic number,
C<C<sqr>(x)> is not identical to C<x*x>: for example if
C<x = 1+O(2^5)> then C<x*x = 1+O(2^5)> while C<C<sqr>(x) = 1+O(2^6)>.
(Remark: note that if we wanted to be strictly consistent with the
PARI philosophy, we should have C<x*y= (4  F<mod>  8)> when both C<x> and C<y> are
congruent to C<2> modulo C<4>, or C<C<sqr>(x)=(4 F<mod>  32)> when C<x> is
congruent to C<2> modulo C<4>. However, since an integermod is an exact object,
PARI assumes that the modulus must not change, and the result is hence
C<0  F<mod>  4> in both cases. On the other hand, C<p>-adics are not exact objects,
hence are treated differently.)

If the argument is a polynomial, power series or rational function,
it is, if necessary, first converted to a power series using the current
precision held in the variable B<X<precdl>precdl>. Under GP this again is
transparent to the user. When programming in library mode, however, the
global variable C<precdl> must be set before calling the function
if the argument has an exact type (i.e. not a power series). Here C<precdl> is
not an argument of the function, but a global variable.

Then the Taylor series expansion of the function around X=0 (where X is the main variable) is computed to a number of terms depending on the number of terms of the argument and the function being computed.

If the argument is a vector or a matrix, the result is componentwise
evaluation of the function. In particular, transcendental functions on
square matrices, which are not implemented in the present version 1.39.03.01{}
(see Appendix C however),
will have a slightly different name if they are implemented some day.

^

If y is not of type integer, x^y has the same effect as exp (y* ln (x)). It can be applied to p-adic numbers as well as to the more usual types.

The library syntax is gpui(x,y,prec).

abs(x)

absolute value of x (modulus if x is complex). Polynomials, power series and rational functions are not allowed. Contrary to most transcendental functions, an integer is not converted to a real number before applying abs.

The library syntax is gabs(x,prec), where the second argument prec is necessary only in the complex or imaginary quadratic case.

acos(x)

principal branch of cos^{-1}(x), i.e. such that Re(acos(x))\in [0,pi]. If x\in R and |x|>1, then acos(x) is complex.

The library syntax is gacos(x,prec).

acosh(x)

principal branch of cosh^{-1}(x), i.e. such that Im(acosh(x))\in [0,pi]. If x\in R and x<1, then acosh(x) is complex.

The library syntax is gach(x,prec).

agm(x,y)

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.

The library syntax is agm(x,y,prec).

arg(x)

argument of the complex number x, such that -pi<arg(x)<=pi.

The library syntax is garg(x,prec).

asin(x)

principal branch of sin^{-1}(x), i.e. such that Re(asin(x))\in [-pi/2,pi/2]. If x\in R and |x|>1 then asin(x) is complex.

The library syntax is gasin(x,prec).

asinh(x)

principal branch of sinh^{-1}(x), i.e. such that Im(asinh)(x)\in [-pi/2,pi/2].

The library syntax is gash(x,prec).

atan(x)

principal branch of tan^{-1}(x), i.e. such that Re(atan(x))\in ]-pi/2,pi/2[.

The library syntax is gatan(x,prec).

atanh(x)

principal branch of tanh^{-1}(x). i.e. such that Im(atanh(x))\in ]-pi/2,pi/2]. If x\in R and |x|>1 then atanh(x) is complex.

The library syntax is gath(x,prec).

bernreal(x)

Bernoulli number B_x, where B_0=1, B_1=-1/2, B_2=1/6,..., expressed as a real number with the current precision. The argument x should be of type integer.

The library syntax is bernreal(x,prec).

bernvec(x)

creates a vector containing, as rational numbers, the Bernoulli numbers B_0, B_2,..., B_{2x}. These Bernoulli numbers can then be used as follows. Assume that this vector has been put into a variable, say b. Then we define under GP:

bern(x)=if(x==1,-1/2,if((x<0)||(x%2),0,b[x/2+1]))

and then bern(k) gives the Bernoulli number of index k as a rational number, exactly as bernreal(k) gives it as a real number.

The library syntax is bernvec(x).

cos(x)

cosine of x.

The library syntax is gcos(x,prec).

cosh(x)

hyperbolic cosine of x.

The library syntax is gch(x,prec).

dilog(x)

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

The library syntax is dilog(x,prec).

eint1(x)

exponential integral \int_x^\infty \dfrac{e^{-t}}{t} dt.

The library syntax is eint1(x,prec).

erfc(x)

complementary error function (2/ sqrt pi)\int_x^\infty e^{-t^2} dt.

The library syntax is erfc(x,prec).

eta(x)

Dedekind's eta function, without the q^{1/24}. The meaning is this. If x is a complex number with positive imaginary part, the result is \prod_{n=1}^\infty(1-q^n), where q=e^{2ipi x}. If x is a power series (or can be converted to a power series) with positive valuation, the result is \prod_{n=1}^\infty(1-x^n).

The library syntax is eta(x,prec).

euler

Euler's constant 0.57721....

Note that euler is one of the few special reserved names which cannot be used for variables.

The library syntax is mpeuler(prec) where prec must be given. Note that this creates gamma on the PARI stack. If one does not want to create it on that stack but be able to use it later under the global name geuler (with no parentheses) use instead consteuler(prec ).

exp(x)

exponential of x. p-adic arguments with positive valuation are accepted.

The library syntax is gexp(x,prec).

gamh(x)

gamma function evaluated at the argument x+1/2. When x is an integer, this is much faster than using gamma(x+1/2).

The library syntax is ggamd(x,prec).

gamma(x)

gamma function of x. In the present version 1.39.03.01{} the p-adic gamma function is not implemented.

The library syntax is ggamma(x,prec).

hyperu(a,b,x)

U-confluent hypergeometric function with parameters a and b.

The library syntax is hyperu(a,b,x,prec).

incgam(x,y)

incomplete gamma function.

The arguments x and y must be positive. The result returned is \int_y^\infty e^{-t}t^{x-1} dt.

The library syntax is incgam(x,y,prec).

Note: in addition, there exist also the functions incgam1 and incgam2 which are used for internal purposes.

incgam3(x,y)

complementary incomplete gamma function.

The arguments x and y must be positive. The result returned is \int_0^y e^{-t}t^{x-1} dt, when y is not too large.

The library syntax is incgam3(x,y,prec).

incgam4(x,y,z)

incomplete gamma function with given gamma value. This function assumes (of course without checking) that z=Gamma(x). The arguments x and y must be positive. The result returned is \int_y^\infty e^{-t}t^{x-1} dt, as in the ordinary incgam function, but the computation will be much faster when y is small.

The library syntax is incgam4(x,y, z,prec).

jbesselh(n,x)

J-Bessel function of half integral index. More precisely, jbesselh(n,x) computes J_{n+1/2}(x) where n must be of type integer, and x is any element of C. In the present version 1.39.03.01, this function is not very accurate when x is small.

The library syntax is jbesselh(n,x,prec).

jell(x)

elliptic j-invariant. x must be a complex number with positive imaginary part, or convertible into a power series or a p-adic number with positive valuation.

The library syntax is jell(x,prec).

kbessel(nu,x)

K-Bessel function of index nu (which can be complex) and argument x. Only real and positive arguments x are allowed in the present version 1.39.03.01.

The library syntax is kbessel(nu, x,prec).

Note: in addition, another implementation of this function which is often faster than kbessel is the function kbessel2.

ln(x) or log(x)

principal branch of the natural logarithm of x, i.e. such that Im(ln(x))\in ]-pi,pi]. The result is complex (with imaginary part equal to pi) if x\in R and x<0.

p-adic arguments are also accepted for x, with the convention that ln (p)=0. Hence in particular exp ( ln (x))/x will not in general be equal to 1 but to a p-1-th root of unity (or +-1 if p=2) times a power of p.

The library syntax is glog(x,prec).

lngamma(x)

principal branch of the logarithm of the gamma function of x. Can have much larger arguments than gamma itself. In the present version 1.39.03.01{} the p-adic lngamma function is not implemented.

The library syntax is glngamma(x,prec).

logagm(x)

principal branch of the natural logarithm of x, computed using an agm formula suggested by Mestre, when x is real, otherwise identical to log.

The library syntax is glogagm(x,prec).

pi

the constant pi (3.14159...).

The library syntax is mppi(prec) where prec must be given. Note that this creates pi on the PARI stack. If one does not want to create it on that stack but be able to use it later under the global name gpi (with no parentheses) use instead constpi(prec).

polylog(m,x)

m^th polylogarithm of x, i.e. analytic continuation of the power series log _m(x)=\sum_{n>=1}x^n/n^m. The program uses the power series when |x|^2<=1/2, and the power series expansion in log (x) otherwise. It is valid in a large domain (at least |x|<230), but should not be used too far away from the unit circle since it is then better to use the functional equation linking the value at x to the value at 1/x, which takes a trivial form for the polylogd and polylogp functions below. Power series, polynomial, rational and vector/matrix arguments are allowed.

The library syntax is gpolylog(m,x,prec).

polylogd(m,x)

modified m^th polylogarithm of x, called ~ D_m(x) in Zagier, defined for |x|<=1 by \Re_m(\sum_{k=0}^{m-1}\dfrac{(- log |x|)^k}{k!} log _{m-k}(x) +\dfrac{(- log |x|)^{m-1}}{m!} log |1-x|) and such that D_m(1/x)=(-1)^{m-1}D_m(x), where \Re_m denotes \Re or \Im depending whether m is odd or even.

The library syntax is polylogd(m,x,prec).

polylogdold(m,x)

modified m^th polylogarithm of x, called D_m(x) in Zagier, defined for |x|<=1 by \Re_m(\sum_{k=0}^{m-1}\dfrac{(- log |x|)^k}{k!} log _{m-k}(x) -\dfrac{1}{2}\dfrac{(- log |x|)^m}{m!}) and such that D_m(1/x)=(-1)^{m-1}D_m(x), where \Re_m denotes \Re or \Im depending whether m is odd or even.

The library syntax is polylogdold(m,x,prec).

polylogp(m,x)

another modified m^th polylogarithm of x, called P_m(x) in Zagier, defined for |x|<=1 by \Re_m(\sum_{k=0}^{m-1}\dfrac{2^kB_k}{k!}( log |x|)^k log _{m-k}(x) -\dfrac{2^{m-1}B_m}{m!}( log |x|)^m) and such that P_m(1/x)=(-1)^{m-1}P_m(x), where \Re_m denotes \Re or \Im depending whether m is odd or even.

The library syntax is polylogp(m,x,prec).

psi(x)

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

The library syntax is gpsi(x,prec).

sin(x)

sine of x.

The library syntax is gsin(x,prec).

sinh(x)

hyperbolic sine of x.

The library syntax is gsh(x,prec).

sqr(x)

square of x. Not identical to x*x in the case of 2-adics (see above), and acts componentwise on vectors and matrices. In particular, if x is a square matrix, sqr(x) is not the square of x (use instead x*x or x^2).

The library syntax is gsqr(x).

sqrt(x)

principal branch of the square root of x, i.e. such that Arg(sqrt(x))\in ]-pi/2,pi/2], or in other words such that Re(sqrt(x))>0 or Re(sqrt(x))=0 and Im(sqrt(x))>=0. If x\in R and x<0, then the result is complex with positive imaginary part.

Integermod a prime and p-adics are allowed as arguments. In that case, the square root (if it exists) which is returned is the one whose first p-adic digit (or its unique p-adic digit in the case of integermods) is in the interval [0,p/2].

The library syntax is gsqrt(x,prec).

tan(x)

tangent of x.

The library syntax is gtan(x,prec).

tanh(x)

hyperbolic tangent of x.

The library syntax is gth(x,prec).

teich(x)

Teichmuller character of the p-adic number x.

The library syntax is teich(x).

wf(x)

Weber's f function, i.e. such that j(x)=(f^{24}(x)-16)^3/f^{24}(x), where j is the elliptic j-invariant (see the function jell above).

The library syntax is wf(x,prec).

wf2(x)

Weber's f_2 function, i.e. such that j=(f_2^{24}+16)^3/f_2^{24}.

The library syntax is wf2(x,prec).

zeta(s)

Riemann's zeta function zeta(s)=\sum_{n>=1}n^{-s}, computed using the Euler-Maclaurin summation formula, except when s is of type integer, in which case it is computed using Bernoulli numbers for s<=0 or s>0 and even, and using modular forms for s>0 and odd.

The library syntax is gzeta(s,prec).

Arithmetic functions.

These functions are by definition functions whose natural domain of definition is either Z (or Z_{>0}), or sometimes polynomials over a base ring. Functions which concern polynomials exclusively will be explained in the next section. The way these functions are used is completely different from transcendental functions: in general only the types integer and polynomial are accepted as arguments.

In the present version 1.39.03.01{} a primitive but useful version of the ECM method has been implemented. Also, numbers found to be pseudo-primes after 10 successful trials of the Rabin-Miller test are declared primes.

addprimes(x)

add additional primes to the table computed by init, and return a row vector whose first entries contain all primes added by the user and whose last entries contain a 1. In total the returned row vector has 20 components. x must be a row or column vector with primes to be appended to that list. Whenever factor or smallfact is subsequently called, first the primes in the table computed by init will be checked, and then the additional primes in this table.

The entries in x are not checked for primality. They should be positive integers not divisible by any of the pre-computed primes.

The present PARI version 1.39.03.01{} allows up to 20 user-specified primes to be appended to the table. This limit may be changed by altering NUMPRTBELT in file init.c.

The library syntax is addprimestotable(x).

bestappr(x,k)

if x\inR, finds the best rational approximation to x with denominator at most equal to k using continued fractions. If x is a generic type, bestappr is used on each coefficient independently.

The library syntax is bestappr(x,k).

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 either vecbezout(x,y) to get the vector, or gbezout(x,y, & u, & v) which gives as result the address of the created gcd, and puts in u and v the addresses of the corresponding created objects.

bigomega(x)

number of prime divisors of x counted with multiplicity. x must be an integer, and the result is a C-long integer.

The library syntax is bigomega(x).

bin(x,y)

binomial coefficient \binom x y. Here y must be an integer, but x can be any PARI object.

The library syntax is binome(x,y), where y must be a C-long integer.

boundcf(x,lmax)

creates the row vector whose components are the partial quotients of the continued fraction expansion of x, the number of partial quotients being limited to lmax. If x is a real number, the expansion stops at the last significant partial quotient or after lmax terms, whichever is smallest. x can also be a rational function or a power series.

The library syntax is gboundcf(x,lmax), where lmax is a C integer.

boundfact(x,p)

For integer x, finds only the prime factors up to p or to the default bound of the prime table created upon initialization of GP, whichever is lowest (except when p<=1 where the effect is identical to smallfact). The remaining part is hence not necessarily prime.

The library syntax is boundfact(x,p).

buchcertify(bnf)

bnf being a big number field as output by buchinit or buchinitfu, checks whether the result is correct, i.e. whether it is possible to remove the assumption of 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: if the program answers 1, barring bugs of course the answer is certified.

The library syntax is certifybuchall(bnf), and the result is a C long.

buchfu(bnf)

bnf being a big number field as output by buchinit or buchinitfu, outputs a two component row vector giving in the first component the vector of fundamental units of the number field, and in the second component the number of bit of accuracy which remained in the computation (which is always correct, otherwise an error message is printed). This function is mainly for people who forgot to use buchinitfu instead of buchinit after a long buchinit computation.

The library syntax is buchfu(bnf).

buchimag(D,c,c2)

McCurley's sub-exponential algorithm for computing the class group of an imaginary quadratic field of discriminant D. Should be used instead of classno for |D|>10^{25} or when the structure is wanted. The numbers c and c2 are positive real numbers which control the execution time and the stack size. To get maximum speed, set c2=c. To get a rigorous result (under GRH) you must take c2=6. Reasonable values for c are between 0.1 and 2.

The result of this function is a vector with 4 components. The first is the class number, the second is a vector giving the structure of the class group as a product of cyclic groups, and the third is a vector giving as binary quadratic forms generators of those cyclic groups. The last component is a measure of the correctness of the result. If it is close to 1, the result is correct (under GRH). If it is close to a larger integer, this shows that the class number is off by a factor equal to this integer, and you must start again with a larger value for c or a different random seed. In this case, a warning message is printed.

Note: some installations may have this function disabled.

The library syntax is buchimag(D,c,c2).

buchreal(D,n,c,c2)

Buchmann's sub-exponential algorithm for computing the class group and the regulator of a real quadratic field of discriminant D. Should be used instead of classno and regula for D>10^{10} or when the structure is wanted. If the integer n is equal to 0 the function computes the ordinary (or wide) class group and regulator, while if n is non-zero it computes the narrow class group and regulator (this case is not yet implemented in version 1.39.03.01). The numbers c and c2 are positive real numbers which control the execution time and the stack size. To get maximum speed, set c2=c. To get a rigorous result (under GRH) you must take c2=6. Reasonable values for c are between 0.1 and 2.

The result of this function is a vector with 5 components. The first is the class number, the second is a vector giving the structure of the class group as a product of cyclic groups, and the third is a vector giving as binary quadratic forms generators of those cyclic groups. The fourth component is the regulator, computed to an accuracy which is the maximum of an internal accuracy determined by the program and the current default (note that once the regulator is known to a small accuracy it is trivial to compute it to very high accuracy. I leave this as an exercise to the reader, or see the tutorial). The last component is a measure of the correctness of the result. If it is close to 1, the results are correct (under GRH). If it is close to a larger integer, this shows that the product of the class number by the regulator is off by a factor equal to this integer, and you must start again with a larger value for c or a different random seed. In this case, a warning message is printed.

Note: some installations may have this function disabled.

The library syntax is buchreal(D,n,c,c2).

cf(x)

creates the row vector whose components are the partial quotients of the continued fraction expansion of x. If x is a real number, the expansion stops at the last significant partial quotient. x can also be a rational function.

The library syntax is gcf(x).

cf2(b,x)

creates the row vector whose components are the partial quotients of the continued fraction expansion of x, the numerators being equal to the coefficients of the vector b. The length of the result is 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 in thus different from that of cf since if b is too long, some partial quotients may not be significant. x can also be a rational function or a power series.

The library syntax is gcf2(b,x).

chinese(x,y)

If x and y are both integermods or both polymods, 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. Finally chinese(x,x) = x regardless of the type of x; this allows vector inputs to contain other data types, if this data is identical in both vectors.

The library syntax is chinois(x,y).

classno(x)

class number of the quadratic field of discriminant x. In the present version 1.39.03.01, a simple algorithm is used for x>0, so x should not be too large (say x<10^7) for the time to be reasonable. On the other hand, for x<0 one can reasonably compute classno(x) for |x|<10^{25}, since the method used is Shanks' method which is in O(|x|^{1/4}). For larger values of |D|, see buchimag for D < 0 and buchreal for D>0.

The library syntax is classno(x).

There also exists the function classno2, which computes the class number using the functional equation. However, it is in O(|x|^{1/2}). Finally, in library mode only there exists the function classno3 which computes the class number of an imaginary quadratic field by counting reduced forms, a O(|x|) algorithm. See also hclassno below.

compimag(x,y)

composition of the binary quadratic forms x and y. This is of course a special case of gmul(x,y). See also nucomp and nudupl.

The library syntax is compimag(x,y).

comprealraw(x,y)

composition of the binary quadratic forms x and y with positive discriminant, without reduction of the result. This is useful e.g. to compute a generating element of an ideal.

The library syntax is comprealraw(x,y).

content(x)

computes the gcd of all the coefficients of x, when this gcd makes sense. If x is a scalar, this simply gives x. If x is a polynomial (and by extension a power series), it gives the usual content of x. If x is a rational function, it gives the ratio of the contents of the numerator and the denominator. Finally, if x is a vector or a matrix, it gives the gcd of all the entries.

The library syntax is content(x).

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 dirdiv(x,y).

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 dirmul(x,y).

divisors(x)

creates a row vector whose components are the positive divisors of the integer x in increasing order.

The library syntax is divisors(x).

fact(x) or x!

factorial of x. The expression x! gives a result which is an integer, while fact(x) gives a real number.

The library syntax is mpfact(x) for x! and mpfactr(x,prec) for fact(x). x must be a C-long integer and not a PARI integer.

factcantor(x,p)

factorization mod p of the polynomial x using distinct degree plus Cantor-Zassenhaus. The coefficients of x must be operation-compatible with Z/pZ. The result is a two-column matrix, the first column being the irreducible polynomials dividing x, and the second the exponents. If you want only the degrees of the irreducible polynomials (for example for computing an L-function), use the function simplefactmod. Note that the factmod algorithm is usually faster than factcantor.

The library syntax is factcantor(x,p).

factfq(x,p,a)

factorization in the field F_q defined by the irreducible polynomial a over F_p of the polynomial x. The coefficients of x must be operation-compatible with Z/pZ. The result is a two-column matrix, the first column being the irreducible polynomials dividing x, and the second the exponents. It is advised to use for the variable of a (which will be used as variable of a polymod), a name distinct from the other variables used, so that a lift() of the result will be legible.

The library syntax is factmod9(x,p,a).

factmod(x,p)

factorization mod p of the polynomial x using Berlekamp. The coefficients of x must be operation-compatible with Z/pZ. The result is a two-column matrix, the first column being the irreducible polynomials dividing x, and the second the exponents. If you want only the degrees of the irreducible polynomials (for example, for computing an L-function), use the function simplefactmod. A different algorithm for computing the mod p factorization is factcantor which is sometimes faster.

The library syntax is factmod(x,p).

factor(x)

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

The polynomials or rational functions to be factored must have scalar coefficients. In particular PARI does not yet know how to factor multivariate polynomials.

The library syntax is factor(x). See also factpol, factpol2 and factornf.

fibo(x)

x^{th} Fibonacci number.

The library syntax is fibo(x). x must be a C-long integer and not a PARI integer.

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. Vector/matrix types are also accepted, in which case the GCD is taken recursively on each component. Note that for these types, gcd is not commutative.

The library syntax is ggcd(x,y).

hclassno(x)

Hurwitz class number of x, where x is non-negative and congruent to 0 or 3 modulo 4. See also classno above.

The library syntax is hclassno(x).

hilb(x,y,p) or hilbp(x,y)

Hilbert symbol of x and y. If x and y are of type integer or fraction, the function hilb must be used with an explicit third parameter p, p=0 meaning the place at infinity. Otherwise, p need not be given, and x and y can be of compatible types integer, fraction, real, integermod or p-adic.

The library syntax is in both cases hil(x,y,p) or hil(x,y).

isfund(x)

true (1) if x is equal to 1 or to the discriminant of a quadratic field, false (0) otherwise. Vector/matrix arguments are also allowed in which case the function is applied to each component.

The library syntax is gisfundamental(x), but the simpler function isfundamental(x) which returns a C-long should be used if x is known to be of type integer.

isprime(x)

true (1) if x is a strong pseudo-prime for 10 randomly chosen bases, false (0) otherwise. Vector/matrix arguments are also allowed in which case the function is applied to each component.

The library syntax is gisprime(x), but the simpler function isprime(x) which returns a C-long should be used if x is known to be of type integer.

ispsp(x)

true (1) if x is a strong pseudo-prime for a randomly chosen base, false (0) otherwise. Vector/matrix arguments are also allowed in which case the function is applied to each component.

The library syntax is gispsp(x), but the simpler function ispsp(x) which returns a C-long should be used if x is known to be of type integer.

isqrt(x)

integer square root of x, which must be of PARI type integer. The result is non-negative and rounded towards zero. A negative x is allowed, and the result in that case is i*isqrt(-x).

The library syntax is racine(x).

issqfree(x)

true (1) if x is squarefree, false if not. Here x can be an integer or a polynomial. Vector/matrix arguments are also allowed in which case the function is applied to each component.

The library syntax is gissquarefree(x), but the simpler function issquarefree(x) which returns a C-long should be used if x is known to be of type integer.

issquare(x)

true (1) if x is square, false if not. x can be of any type. For vector/matrix arguments the function is applied to each component.

The library syntax is gcarreparfait(x). In the case where x is known to be of type integer, the function carrecomplet(x,&r) which returns a C-long should be used, since not only does it give the answer (true or false), but in the case where x is indeed a square, puts the integer square root in r.

kro(x,y)

Kronecker (i.e. generalized Legendre) symbol (\dfrac{x}{y}). x and y must be of type integer and the result (0 or +- 1) is a C-long integer.

The library syntax is kronecker(x,y).

lcm(x,y)

least common multiple of x and y, i.e. such that lcm(x,y)*gcd(x,y)=abs(x*y).

The library syntax is glcm(x,y).

mu(x)

M\"obius mu-function of x. x must be of type integer and the result (0 or +- 1) is a C-long integer.

The library syntax is mu(x).

nextprime(x)

finds the smallest prime greater than or equal to x. x must be of type integer.

The library syntax is bigprem(x).

nucomp(x,y,l)

composition of the primitive positive definite binary quadratic forms x and y using the NUCOMP and NUDUPL algorithms of Shanks (\`a la Atkin). l is any positive constant, but for optimal speed, one should take l=|D|^{1/4}, where D is the common discriminant of x and y.

The library syntax is nucomp(x,y,l). The auxiliary function nudupl(x,l) should be used instead for speed when x=y.

numdiv(x)

number of divisors of x. x must be of type integer, and the result is a C-long integer.

The library syntax is numbdiv(x).

nupow(x,n)

n-th power of the primitive positive definite binary quadratic form x using the NUCOMP and NUDUPL algorithms (see nucomp above).

The library syntax is nupow(x,n).

omega(x)

number of distinct prime divisors of x. x must be of type integer, and the result is a C-long integer.

The library syntax is omega(x).

order(x)

x must be an integer mod n, and the result is the order of x in the multiplicative group (Z/nZ)^*. Error if x is not invertible.

The library syntax is order(x).

pf(x,p)

prime binary quadratic form of discriminant x whose first coefficient is the prime number p. Error if x is not a quadratic residue mod p. In the case where x>0, the ``distance'' component of the form is set equal to zero according to the current precision.

The library syntax is primeform(x,p,prec), where the third variable prec is a C-long integer, but is necessary only when x>0.

phi(x)

Euler's phi-function of x. x must be of type integer.

The library syntax is phi(x).

pnqn(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 pnqn(x).

powrealraw(x,n)

n-th power of the binary quadratic form x of positive discriminant, computed without doing any reduction (i.e. using comprealraw above). Here n must be non-negative and n<2^{31}.

The library syntax is powrealraw(x,n) where n must be a C-long integer.

prime(x)

the x^{th} prime number.

The library syntax is prime(x). x must be a C-long integer.

primes(x)

creates a row vector whose components are the first x prime numbers.

The library syntax is primes(x). x must be a C-long integer.

primroot(x)

returns a primitive root of x, where x is a prime power.

The library syntax is gener(x).

qfi(a,b,c)

creates the binary quadratic form ax^2+bxy+cy^2 with b^2-4ac<0.

The library syntax is qfi(a,b,c).

qfr(a,b,c,d)

creates the binary quadratic form ax^2+bxy+cy^2 with b^2-4ac>0 and distance function d.

The library syntax is qfr(a,b,c,d).

quaddisc(x)

discriminant of the quadratic field Q( sqrt x), where x\inQ. Up to trivial 2-factors, this function can also be used to compute the squarefree part of x.

The library syntax is quaddisc(x).

redimag(x)

reduce the binary quadratic form x with negative discriminant.

The library syntax is redimag(x).

redreal(x)

reduce the binary quadratic form x with positive discriminant.

The library syntax is redreal(x).

redrealnod(x,sq)

reduce the binary quadratic form x with positive discriminant D without computing the distance function, where sq is the integer square root of D (no checking is done of this fact).

The library syntax is redrealnod(x,sq).

regula(x)

regulator of the quadratic field of positive discriminant x. Error if x is not a discriminant (fundamental or not) or if x is a square. See also buchreal if x is large.

The library syntax is regula(x,prec).

rhoreal(x)

perform one reduction step on the binary quadratic form x with positive discriminant.

The library syntax is rhoreal(x).

rhorealnod(x,sq)

perform one reduction step on the binary quadratic form x with positive discriminant D without computing the distance function, where sq is the integer square root of D (no checking is done of this fact).

The library syntax is rhorealnod(x,sq).

sigma(x)

sum of the positive divisors of x. x must be of type integer.

The library syntax is sumdiv(x).

sigmak(k,x)

sum of the k^{th} powers of the positive divisors of x. x must be of type integer, but (in library mode) k must be a C-long integer.

The library syntax is sumdivk(k,x).

simplefactmod(x,p)

factorization mod p of the polynomial x. The coefficients of x must be operation-compatible with Z/pZ. The result is a two-column matrix, the first column being the degrees of the irreducible polynomials dividing x, and the second the exponents. If you want the irreducible polynomials themselves, use the function factmod.

The library syntax is simplefactmod(x,p).

smallfact(x)

For integer x, finds only the prime factors up to the default table created when GP was started (usually 500000). The remaining part is hence not necessarily prime. This never takes more than a few seconds, and is particularly advantageous with respect to factor when one needs only the small prime divisors and not the complete factorization.

The library syntax is smallfact(x).

unit(x)

fundamental unit of the real quadratic field Q( sqrt x) where x is the positive discriminant of the field. If x is not a fundamental discriminant, this probably gives the fundamental unit of the corresponding order. x must be of type integer, and the result is a quadratic number.

The library syntax is fundunit(x).

znstar(n)

gives the structure of the multiplicative group (Z/nZ)^* as a 3-component row vector v, where v[1]=phi(n) is the order of that group, v[2] is a k-component row-vector d of integers d[i] such that d[i]>1 and d[i] | d[i-1] for i>=2 and (Z/nZ)^* ~ \prod_{i=1}^k(Z/d[i]Z), and v[3] is a k-component row vector giving generators of the image of the cyclic groups Z/d[i]Z.

The library syntax is znstar(n).

Functions related to elliptic curves.

We have implemented a number of functions which are useful for number theorists working on elliptic curves. We always use Tate's notations.

The functions assume that the curve is given by a general Weierstrass model

y^2+a_1xy+a_3y=x^3+a_2x^2+a_4x+a_6,

where a priori the a_i can be of any scalar type. This curve can be considered as a five component vector e=[a1,a2,a3,a4,a6], but for most functions it is useful to have at one's disposal more information. This is given either by the function initell (see below), which gives a 19 component vector (which we will call a long vector in this section), or by the faster function smallinitell which gives a 13 component vector (which we will call a medium vector), all these vectors starting in the same way. Consequently, in functions which do not use the extra information given by initell, the curve can be given either as a five component vector, or by one of the longer vectors computed by initell or smallinitell.

Other functions, in particular those relative to height computations (see hell below) require also that the curve be in minimal Weierstrass form. This is achieved by the function globalred below.

Points on elliptic curves are represented as two-component vectors [x,y], except for the point at infinity, i.e. the identity element of the group law, represented by the one-component vector [0].

addell(e,z1,z2)

sum of the points z1 and z2 on the elliptic curve corresponding to the vector e.

The library syntax is addell(e,z1,z2).

akell(e,n)

compute the coefficient a_n of the L-function of the elliptic curve e, i.e. in principle coefficients of a newform of weight 2 assuming Taniyama-Weil. e must be a medium or long vector of the type given by smallinitell or initell. 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 globalred first before using akell.

The library syntax is akell(e,n).

anell(e,n)

compute the vector of the first n a_k corresponding to the elliptic curve e, i.e. in principle coefficients of a newform of weight 2 assuming Taniyama-Weil. e must be a medium or long vector of the type given by smallinitell or initell. 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 globalred first before using anell.

The library syntax is anell(e,n), where n is a C integer.

apell(e,p)

compute the a_p corresponding to the elliptic curve e and the prime number p, using the baby-step giant-step method and a trick due to Mestre. No checking is done that p is indeed prime. The number of points of e over F_p is p+1-a_p. e must be a medium or long vector of the type given by smallinitell or initell.

The library syntax is apell(e,p).

apell2(e,p)

compute the a_p corresponding to the elliptic curve e and the prime number p as a sum of Legendre symbols. This is slower than apell as soon as p is greater than 100, say. e must be a medium or long vector of the type given by smallinitell or initell.

The library syntax is apell2(e,p).

bilhell(e,z1,z2)

If z1 and z2 are points on the elliptic curve e, this function computes the value of the canonical bilinear form on z1, z2, i.e. hell(e,z1+z2)-hell(e,z1)-hell(e,z2), where + denotes of course addition on e. In addition, z1 or z2 (but not both) can be vectors or matrices.

The library syntax is bilhell(e,z1,z2,prec).

chell(e,v)

change the data for the elliptic curve e by changing the coordinates using the vector v=[u,r,s,t], i.e. if x' and y' are the new coordinates, then x=u^2x'+r, y=u^3y'+su^2x'+t. The vector e must be a medium or long vector of the type given by smallinitell or initell.

The library syntax is coordch(e,v).

chptell(x,v)

change the coordinates of the point or vector of points x using the vector v=[u,r,s,t], i.e. if x' and y' are the new coordinates, then x=u^2x'+r, y=u^3y'+su^2x'+t (see also chell above).

The library syntax is pointch(x,v).

globalred(e)

calculate the arithmetic conductor, the global minimal model of e and the global Tamagawa number c. Here e is an elliptic curve given by a medium or long vector of the type given by smallinitell or initell, and is supposed to have all its coefficients a_i in Q. The result is a 3 component vector [N,v,c]. N is the arithmetic conductor of the curve, v is itself a vector [u,r,s,t] with rational components. It gives a coordinate change for e over Q such that the resulting model has integral coefficients, is everywhere minimal, a_1 is 0 or 1, a_2 is 0, 1 or -1 and a_3 is 0 or 1. Such a model is unique, and the vector v is unique if we specify that u is positive. To get the new model, simply type chell(e,v). Finally c is the product of the local Tamagawa numbers c_p, which is a quantity which enters in the Birch and Swinnerton-Dyer conjecture.

The library syntax is globalreduction(e).

hell(e,z)

global N\'eron-Tate height of the point z on the elliptic curve e. The vector e must be a long vector of the type given by initell. This computation is done using sigma and theta-functions and a trick due to J. Silverman.

The library syntax is ghell(e,z,prec). The archimedean contribution alone is given by the library function hell(e,z,prec).

hell2(e,z)

same as hell, except that the algorithm used is Tate's 4^n algorithm, and is much slower.

The library syntax is ghell2(e,z,prec).

initell(e)

compute some fixed data concerning the elliptic curve given by the five component vector e, which will be essential for most further computations on the curve. The result is a 19-component vector E (called a long vector in this section), containing the following information:

The first 13 components contain

a_1,a_2,a_3,a_4,a_6,b_2,b_4,b_6,b_8,c_4,c_6,Delta,j.

In particular, the discriminant is E[12], and the j-invariant is E[13].

For the other six components, their content depends on whether the curve is defined over R or not.

When e is defined over R, E[14] is a vector with three components containing the roots of the associated Weierstrass equation. If the roots are all real, then they are ordered by decreasing value. If only one is real, it is the first component of E[14].

E[15] is the real period of E (integral of dx/(2y+a_1x+a_3) over the connected component of the identity element of the real points of the curve), and E[16] is a complex period. In other words, omega_1=E[15] and omega_2=E[16] form a basis of the complex lattice defining e, with tau=\dfrac{omega_2}{omega_1} having positive imaginary part.

E[17] and E[18] are the corresponding values eta_1 and eta_2 such that eta_1omega_2-eta_2omega_1=ipi.

Finally, E[19] is the volume of the complex lattice defining e.

When e is defined over Q_p, the p-adic valuation of j must be negative. Then E[14] is the vector with a single component equal to the p-adic root of the associated Weierstrass equation corresponding to -1 under the Tate parametrization.

E[15] is equal to the square of the u-value, in the notation of Tate.

E[16] is the u-value itself, if it belongs to Q_p, otherwise zero.

E[17] is the value of Tate's q for the curve e.

E[18] is the value of Mestre's w (this is technical), and E[19] is arbitrarily set equal to zero.

For all other base fields or rings, the last six components are arbitrarily set equal to zero.

Note: temporarily, an older version of initell called initell2 is installed, but will disappear in the near future.

The library syntax is initell(e,prec).

isoncurve(e,z)

gives 1 (i.e. true) if the point z is on the elliptic curve e, 0 otherwise. Here e can be a five-component vector or a long vector.

The library syntax is oncurve(e,z), and the result is a C-long integer.

localred(e,p)

calculate the Kodaira type of the local fiber of the elliptic curve e at the prime p. e must be given by a medium or long vector of the type given by smallinitell or initell, and is assumed to have all its coefficients a_i in Z. The result is a 4-component vector [f,kod,v,c]. Here f is the exponent of p in the arithmetic conductor of e, kod is the Kodaira type which is coded as follows:

1 means good reduction (type I_0), 2, 3 and 4 mean types II, III and IV respectively, 4+nu with nu>0 means type I_nu; finally the opposite values -1, -2, etc. refer to the starred types I_0^*, II^*, etc. The third component v is itself a vector [u,r,s,t] giving the coordinate changes done during the local reduction. Normally, this has no use if u is 1, that is, if the given equation was already minimal. Finally, the last component c is the local Tamagawa number c_p.

The library syntax is localreduction(e,p).

lseriesell(e,s,N,A)

e being a medium or long vector given by smallinitell or initell, this computes the value of the L-series of e at s. It is assumed that e is a minimal model over Z, N is equal to plus or minus the conductor depending on the sign of the functional equation, that the curve is a Weil curve, and A is a cutoff point for the integral, which must be chosen close to 1 for best speed. The result being independent of A, this function can be used to compute the sign of the functional equation, and even N if one wants, although it is always much faster to apply the function globalred.

Note that in the present version 1.39.03.01, this function is accessible externally in GP, but in future versions it may only be accessible in library mode since it will be superseded.

Note also that if the conductor of the curve is large, say greater than 10^{12}, this function will take an unreasonable amount of time since it uses a O(N^{1/2}) algoorithm.

The library syntax is lseriesell(e,s,N,A,prec) where prec is a C-long integer.

mathell(e,x)

x being a vector of points, this function outputs the Gram matrix of x with respect to the N\'eron-Tate height, in other words, the (i,j) component of the matrix is equal to hell(e,x[i]+x[j])-hell(e,x[i])-hell(e,x[j]), where x[i]+x[j] denotes of course the sum of the points on the curve e. The rank of this matrix, at least in some approximate sense, gives the rank of the set of points, and if x is a basis of the Mordell-Weil group of e, its determinant is equal to the regulator of e.

The library syntax is mathell(e,x,prec).

ordell(e,x)

gives a 0, 1 or 2-component vector containing the y-coordinates of the points of the curve e having x as x-coordinate.

The library syntax is ordell(e,x).

orderell(e,z)

gives the order of the point z on the elliptic curve e if it is a torsion point, zero otherwise. In the present version 1.39.03.01{}, this is implemented only for elliptic curves defined over Q.

The library syntax is orderell(e,z), and the result is a GEN.

pointell(e,z)

e being a long vector, computes the coordinates [x,y] on the curve e corresponding to the complex number z. Hence this is the inverse function of zell. In other words, if the curve is put in Weierstrass form, [x,y] represent the Weierstrass \wp-function and its derivative. If z is in the lattice defining e over C, the result is the point at infinity [0].

The library syntax is pointell(e,z,prec).

powell(e,z,n)

computes n times the point z for the group law on the elliptic curve e. Here n is in Z.

The library syntax is powell(e,z,n).

smallinitell(e)

compute some fixed data concerning the elliptic curve given by the five component vector e, which may be useful for further computations on the curve. The result is a 13-component vector E (called a medium vector in this section), containing the first 13 components of the vector given by initell, in other words the vector

[a_1,a_2,a_3,a_4,a_6,b_2,b_4,b_6,b_8,c_4,c_6,Delta,j].

In particular, the discriminant is E[12], and the j-invariant is E[13].

The library syntax is smallinitell(e).

subell(e,z1,z2)

difference of the points z1 and z2 on the elliptic curve corresponding to the vector e.

The library syntax is subell(e,z1,z2).

taniyama(e)

computes the modular parametrization of the elliptic curve e (where e is given in the format output by initell or smallinitell), in the form of a two-component vector [u,v] of power series, given to the current default series precision. This vector is characterized by the following two properties. First the point (x,y)=(u,v) satisfies the equation of the elliptic curve. Second, the differential du/(2v+a_1u+a_3) is equal to f(z)dz, a differential form on H/Gamma_0(N) where N is the conductor of the curve. The variable used in the power series for u and v is x, which is implicitly understood to be equal to exp (2ipi z). It is assumed that the curve is a strong Weil curve, and the Manin constant is equal to 1. The equation of the curve e must be minimal (use globalred to get a minimal equation).

The library syntax is taniyama(e), and the precision of the result is determined by the global variable precdl.

torsell(e)

If e is an elliptic curve defined over Q, this outputs the torsion subgroup of e as a 3-component vector [t,v1,v2] with the following meaning. t is the order of the torsion group. v1 is a 0, 1 or 2-component vector giving the structure of the torsion group as a product of cyclic groups, with v1[2]=2 if it exists. Finally v2, which is a vector of the same length as v1, gives generators for these cyclic groups. e must be a vector as output by initell or smallinitell.

The library syntax is torsell(e).

zell(e,z)

If e is an elliptic curve with coefficients in R, this computes a complex number t (modulo the lattice defining e) corresponding to the point z, i.e. such that, in the standard Weierstrass model, \wp(t)=z[1],\wp'(t)=z[2]. In other words, this is the inverse function of pointell.

If e has coefficients in Q_p, then either Tate's u is in Q_p, in which case the output is a p-adic number t corresponding to the point z under the Tate parametrization, or only its square is, in which case the output is t+1/t. e must be a long vector of the type given by initell.

The library syntax is zell(e,z,prec).

Functions related to general number fields.

In this section can be found functions which are used almost exclusively for working in general number fields. Other less specific functions can be found in the next section on polynomials. Functions related to quadratic number fields can be found in section 3.4 above.

In this section, nf will always denote a number field, i.e. a 9-component vector in the format output by initalg or initalgred. An ideal (usually x or y) will mean the following:

x can be a Z-basis, in Hermite Normal Form (HNF) or not. In this case x is a square matrix.

x can be an idele, i.e. a 2-component vector, the first being an ideal given as a Z-basis, the second being a r_1+r_2-component row vector giving the complex logarithmic archimedean information.

x can be a Z_K-generating system for an ideal.

x can be a column vector expressing an element of the number field on the integral basis, in which case x is treated as being the principal idele (or ideal) generated by x.

x can be a prime ideal, i.e. a 5-component vector in the format output by primedec.

x can be a polymod, i.e. an algebraic integer, in which case x is treated as being the principal idele generated by x.

Finally, x can be an integer or a rational number, also treated as a principal idele.

Warnings.

1) An element in nf can be expressed either as a polymod or as a vector of components on the integral basis nf[7]. It is absolutely essential that all such vectors be column vectors.

2) When giving an ideal by a Z_K generating system to a function expecting an ideal, it must be ensured that the function understands that it is a Z_K-generating system and not a Z-generating system. When the number of generators is strictly less than the degree of the field, there is no ambiguity and the program assumes that one is giving a Z_K-generating set. When the number of generators is greater than or equal to the degree of the field, however, the program assumes on the contrary that you are giving a Z-generating set. If this is not the case, you must absolutely change it into a Z-generating set, the simplest manner being to use idealmul(nf,x,idmat(N)) where N is the degree of the field.

Remark. Starting with version 1.38.9, we include a number of programs for working in relative extensions of number fields. To our knowlege, this is the first existing implementation of such functions, and is being written up for publication. This has two consequences. First, the functions are provided for help in research, but their results must be considered with caution. Second, as an elementary courtesy to us, we ask you not to publish anything which uses these functions in an essential way, without sending us e-mail about it. Of course, when our paper(s) are published the above will become irrelevant.

Concerning relative extensions, some definitions are necessary. A relative matrix will be a matrix whose entries are elements of a (given) number field nf, always expressed as column vectors on the integral basis nf[7]. Hence it is a matrix of vectors.

An ideal list will be a row vector of (fractional) ideals of the number field nf.

A pseudo-matrix will be a pair (A,I) where A is a relative matrix and I an ideal list whose length is the same as the number of columns of A. This pair will be represented by a 2-component row vector.

The module generated by a pseudo-matrix (A,I) is the sum \sum_i\a_jA_j where the \a_j are the ideals of I and A_j is the j-th column of A.

A pseudo-matrix (A,I) is a pseudo-basis of the module it generates if A is a square matrix with non-zero determinant and all the ideals of I are non-zero. We say that it is in Hermite Normal Form (HNF) if it is upper triangular and all the elements of the diagonal are equal to 1.

The determinant of a pseudo-basis (A,I) is the ideal equal to the product of the determinant of A by all the ideals of I. The determinant of a pseudo-matrix is the determinant of any pseudo-basis of the module it generates.

Finally, when defining a relative extension, the base field should be defined by a variable having a lower priority (i.e. a higher number) than the variable defining the extension. For example, under GP you can use the variable name y (or t) to define the base field, and the variable name x to define the relative extension.

All the functions which are specific to relative extensions (name beginning with rnf) take as first argument either a number field as output by initalg or initalgred, or a big number field as output by buchinit or buchinitfu. Although not specified in the descriptions of the functions below, it is permissible, if the function expects a number field, to use a big number field instead. The program will make the effort of converting to what it needs. On the other hand, if the program requires a big number field, the program will not launch buchinit for you, which can be a costly operation, but give you a specific error message telling you that you should use buchinit.

algtobasis(nf,x)

this is the inverse function of basistoalg. Given an object x whose entries are expressed as algebraic numbers in the number field nf, transforms it so that the entries are expressed on the integral basis nf[7].

The library syntax is algtobasis(nf,x).

basis(x)

integral basis of the number field defined by the monic irreducible polynomial x, using the round 4 algorithm. For small degrees and coefficient size, basis2 is sometimes a little faster. For larger degrees, basis is much faster.

This program is the translation in C by Pascal Letard of a program written by David Ford in Maple. If only a local integral basis is desired, use factoredbasis.

The library syntax is base(x,&d), where d will receive the discriminant of the number field (not of the polynomial x).

basis2(x)

integral basis of the number field defined by the monic irreducible polynomial x, using the round 2 algorithm. This program is the translation in C of a program written by David Ford in Algeb.

The library syntax is base2(x,&d), where d will receive the discriminant of the number field (not of the polynomial x).

basistoalg(nf,x)

this is the inverse function of algtobasis. Given an object x whose entries are expressed on the integral basis nf[7], transforms it into an object whose entries are algebraic numbers (i.e. polymods).

The library syntax is basistoalg(nf,x).

The following functions starting with ``buch'' are implementations of the sub-exponential algorithms for finding class and unit groups under the GRH, due to Hafner-McCurley, Buchmann and Cohen-Diaz-Olivier.

Note that this is a completely experimental program which is constantly being improved.

The general library call to the functions concerning general number fields (i.e. excluding buchimag and buchreal) is

buchall(P,c,c2,nrel,borne,nrpid,minsfb,flun,prec)

where the parameters are to be understood as follows.

P is the defining polynomial for the number field, which must be in Z[X], irreducible and monic.

The numbers c and c2 are positive real numbers which control the execution time and the stack size. To get maximum speed, set c2=c. To get a rigorous result (under the GRH) you must take c2=12 (or c2=6 in the quadratic case, but then you should use the much faster functions buchimag and buchreal below). Reasonable values for c are between 0.1 and 2. (Default values c=c2=0.3).

nrel is the number of initial extra relations requested in computing the relation matrix. Reasonable values are between 5 and 20. (Default value is 5).

borne is a multiplicative coefficient of the Minkowski bound which controls the search for small norm relations. If this parameter is set equal to 0, the program does not search for small norm relations. Otherwise reasonable values are between 0.5 and 2.0. (Default value is 0).

nrpid is the maximal number of small norm relations associated to each ideal in the factor base. Irrelevant when borne=0. Otherwise, reasonable values are between 4 and 20. (Default value is 4).

minsfb is the minimal number of elements in the ``sub-factorbase''. If the program does not seem to succeed in finding a full rank matrix (which you can see in GP by typing \g 2), increase this number. Reasonable values are between 2 and 5. (Default value is 3).

flun corresponds to the requested function (see below) and is a C long: -3 for buchinitforcefu, -2 for buchinitfu, -1 for buchinit, 0 for buchgen, 2 for buchgenfu, 3 for buchgenforcefu.

Finally, as usual, prec is the default precision, as a C long. Note that the internal precision as well as the output precision may well be much higher than prec.

Remark.

Under GP, apart from the polynomial P, only part of the parameters can be given. However, they must be given in the requested order. For example, if you want to specify a given value of nrel, you must give some values for c and c2.

buchgen(P,...)

identical to buchgenfu (see below) except that the fundamental units and roots of unity are not computed. Hence the result has only 7 components. See the remark preceding the description of buchgen for the other parameters.

The library syntax is either buchgen(P,c,c2,prec) or buchall(P,c,c2,nrel,borne,nbpid,minsfb,0,prec) (see above).

buchgenforcefu(P,...)

identical to buchgenfu (see below), except that when the precision is insufficient for obtaining the fundamental units exactly, the internal precision is doubled and the computation redone, until the exact results are obtained. The user should be warned that this can take a very long time when the coefficients of the fundamental units on the integral basis are very large, for example in the case of large real quadratic fields. In that case, there are alternate methods for representing algeberaic numbers which are not implemented in Pari.

The library syntax is buchall(P,c,c2,nrel,borne,nbpid,minsfb,3,prec) (see above).

buchgenfu(P,...)

Buchmann's sub-exponential algorithm for computing the class group, the regulator and a system of fundamental units of the general algebraic number field K defined by the irreducible monic polynomial P with integer coefficients. See the remark preceding the description of buchgen for the other parameters.

The result of this function is a vector v with 10 components, which for ease of presentation is in fact output as a one column matrix. v[1] is equal to the polynomial P. Note that for optimum performance, P should have gone through polred or initalgred. v[2] is the 2-component vector [r1,r2] (where r1 and r2 are as usual the number of real and half the number of complex embeddings of the number field K). v[3] is the 2-component vector containing the field discriminant and the index, v[4] is an integral basis in Hermite normal form. v[5] is a 3-component vector containing the class number, the structure of the class group as a product of cyclic groups of order n_i, and the corresponding generators of the class group of respective orders n_i. v[6] is the regulator computed to an accuracy which is the maximum of an internally determined accuracy and of the default. v[7] is a measure of the correctness of the result. If it is close to 1, the results are correct (under GRH). If it is close to a larger integer, this shows that the product of the class number by the regulator is off by a factor equal to this integer, and you must start again with a larger value for c or a different random seed (i.e. use the function setrand(). (Since the computation involves a random process, starting again with exactly the same parameters may give the correct result.) In this case a warning message is printed. v[8] a vector with 2 components, the first being the number w of roots of unity in K and the second a primitive w-th root of unity expressed as a polynomial. v[9] is a system of fundamental units also expressed as polynomials. Finally, v[10] gives a measure of the correctness of the computations of the fundamental units (not of the regulator), expressed as a number of bits. If this number is greater than 20, say, everything is OK. If v[10]<=0, then we have lost all accuracy in computing the units (usually an error message will be printed and the units not given). In the intermediate cases, one must proceed with caution (for example by increasing the current precision).

Note: some installations may have this function disabled.

The library syntax is buchgenfu(P,c,c2,prec) or buchall(P,c,c2,nrel,borne,nbpid,minsfb,2,prec) (see above).

buchinit(P,...)

essentially identical to buchgen except that the output is much longer, and should not be printed out explicitly in general. The result of buchinit is used in programs such as isprincipal, isprincipalgen, isunit or buchnarrow. The result is an 8-component vector v, whose first 6 components are technical and in principle are not used by the casual user. However, for the sake of completeness, their description is as follows. We use the notations explained in the book by H. Cohen, A Course in Computational Algebraic Number Theory, Graduate Texts in Maths 138, Springer-Verlag, 1993, Section 6.5, and pages 354 and 355 in particular.

v[1] contains the matrix W (mit in the source code), i.e. the matrix in Hermite Normal Form giving on prime ideal generators (\bf p_i)_{1<= i<= r} relations for the class group. v[2] contains the matrix B (matalpha), i.e. the matrix containing the expressions of the prime ideal factorbase in terms of the p_i. It is an r\times c matrix. v[3] contains the complex logarithmic embeddings of the system of fundamental units which has been found (although not computed in the case of buchinit). It is an (r_1+r_2)\times(r_1+r_2-1) matrix. v[4] contains the matrix M''_C of Archimedean components of the relations of the matrix M'', except that the first r_1+r_2-1 columns are suppressed since they are already in v[3]. v[5] contains the prime factor base, i.e. the list of k prime ideals used in finding the relations. Finally, v[6] contains the permutation of the prime factor base which was necessary to reduce the relation matrix to the form explained on page 354 (i.e. with a big c\times c identity matrix on the lower right). Note that in the above mentioned book, the need to permute the rows of the relation matrices which occur was not stressed.

The less technical components are as follows. v[7] is equal to the number field data nf given by initalg, and v[8] is a 4-component vector containing the 5-th, 6-th, 7-th and 8-th components of the result of buchgenfu[,1], i.e. the class group, the regulator, the ``check'' number which should be close to 1 and the number of roots of unity and a generator.

The library syntax is buchinit(P,c,c2,t,prec) or buchall(P,c,c2,nrel,borne,nbpid,minsfb,-1,prec) (see above).

buchinitforcefu(P,...)

identical to buchinitfu (see below), except that when the precision is insufficient for obtaining the fundamental units exactly, the internal precision is doubled and the computation redone, until the exact results are obtained. The user should be warned that this can take a very long time when the coefficients of the fundamental units on the integral basis are very large.

The library syntax is buchall(P,c,c2,nrel,borne,nbpid,minsfb,-3,prec) (see above).

buchinitfu(P,...)

same as buchinit except that the 8-th component contains the last 6 components of buchgenfu[,1], i.e. also the fundamental units and the check on their computation.

The library syntax is buchinitfu(P,c,c2,prec) or buchall(P,c,c2,nrel,borne,nbpid,minsfb,-2,prec) (see above).

buchnarrow(bnf)

bnf being a big number field as output by buchinit or buchinitfu, computes the narrow class group of bnf. The output is a 3-component row vector analogous to the corresponding class group component bnf[8][1]: the first component is the narrow class number, the second component is a vector containing the SNF cyclic components of the narrow class group, and the third is a vector giving the generators of the corresponding cyclic groups. Note that this function is a special case of buchray.

The library syntax is buchnarrow(bnf).

buchray(bnf,I)

bnf being a big number field as output by buchinitfu (or buchinitforcefu, but the units are mandatory unless the ideal is trivial), and I being either an ideal in any form or a two-component row vector containing an ideal and an r_1-component row vector of flags indicating which real Archimedean embeddings to take in the module, computes the ray class group of the number field for the module I, as a 3-component vector as all other finite abelian groups (cardinality, vector of cylic components, corresponding generators).

The library syntax is buchray(bnf,I).

buchrayinit(bnf,I)

same as buchray except that the output is different. It is a 5-component vector w. w[1] is bnf. w[2] is the result of applying zidealstarinit to I. w[3], w[4] are technical components used only by the functions isprincipalray and isprincipalraygen. w[5] is the structure of the ray class group as would have been output by buchray.

The library syntax is buchrayinit(bnf,I).

compositum(x,y)

if x and y are irredicible, this gives a defining polynomial of a compositum of one of the number fields defined by x and one of the number fields defined by y. This really makes sense only when these compositums are all conjugate (for example when the degrees of x and y are coprime), otherwise we would need more information to define a number field than just a defining polynomial.

The library syntax is compositum(x,y).

dirzetak(nf,b)

gives as a vector the first b coefficients of the Dedekind zeta function of the number field nf considered as a Dirichlet series.

The library syntax is dirzetak(nf,b).

discf(x)

field discriminant of the number field defined by the monic irreducible polynomial x.

The library syntax is discf(x). See also basis above.

factoredbasis(x,f)

integral basis of the number field defined by the monic irreducible polynomial x, using the round 2 algorithm, where f is the two-column matrix of the factorization of the discriminant of the polynomial x. Note that f does not need to be a complete factorization of the discriminant. This is especially useful if only a local integral basis at a prime or primes is desired: only factors with exponents greater or equal to 2 will be considered.

The library syntax is factoredbase(x,f,&d), where d will receive the discriminant of the number field.

factoreddiscf(x,p)

field discriminant of the number field defined by the monic irreducible polynomial x, using the round 2 algorithm, where p is the two-column matrix of the factorization of the discriminant of the polynomial x.

The library syntax is factoreddiscf(x,p).

factoredpolred(x,p)

same as polred (see below) except that p is the two-column matrix of the factorization of the discriminant of the polynomial x.

The library syntax is factoredpolred(x,p,prec).

factoredpolred2(x,p)

same as polred2 (see below) except that p is the two-column matrix of the factorization of the discriminant of the polynomial x.

The library syntax is factoredpolred2(x,p,prec).

factornf(x,t)

factorization of the univariate polynomial x over the number field defined by the (univariate) polynomial t. x may have coefficients in Q or in the number field. The main variable of t must be of lower priority than that of x (in other words the variable number of t must be greater than that of x). However if the coefficients of the number field occur explicitly (as polymods) as coefficients of x, the variable of these polymods must be the same as the main variable of t. For example factornf(x^2+mod(y,y^2+1),y^2+1) and factornf(x^2+1,y^2+1) are legal but factornf(x^2+mod(z,z^2+1),y^2+1) is not.

The library syntax is polfnf(x,t).

galois(x)

Galois group of the non-constant polynomial x\inQ[X]. In the present version 1.39.03.01, x must be irreducible and the degree of x must be less than or equal to 7 (for degrees 8,9,10, and 11 we have specific PARI programs available upon request).

The output is a 3-component vector [n,s,k] with the following meaning: n is the cardinality of the group, s is its signature (s=1 if the group is a subgroup of the alternating group A_n, s=-1 otherwise), and k is the number of the group corresponding to a given pair (n,s) (k=1 except in 2 cases). Specifically, the groups are coded as follows, using standard notations (see GTM 138 quoted above):

In degree 1: S_1=[1,-1,1].

In degree 2: S_2=[2,-1,1].

In degree 3: A_3=C_3=[3,1,1], S_3=[6,-1,1].

In degree 4: C_4=[4,-1,1], V_4=[4,1,1], D_4=[8,-1,1], A_4=[12,1,1], S_4=[24,-1,1].

In degree 5: C_5=[5,1,1], D_5=[10,1,1], M_{20}=[20,-1,1], A_5=[60,1,1], S_5=[120,-1,1].

In degree 6: C_6=[6,-1,1], S_3=[6,-1,2], D_6=[12,-1,1], A_4=[12,1,1], G_{18}=[18,-1,1], S_4^-=[24,-1,1], A_4\times C_2=[24,-1,2], S_4^+=[24,1,1], G_{36}^-=[36,-1,1], G_{36}^+=[36,1,1], S_4\times C_2=[48,-1,1], A_5=PSL_2(5)=[60,1,1], G_{72}=[72,-1,1], S_5=PGL_2(5)=[120,-1,1], A_6=[360,1,1], S_6=[720,-1,1].

In degree 7: C_7=[7,1,1], D_7=[14,-1,1], M_{21}=[21,1,1], M_{42}=[42,-1,1], PSL_2(7)=PSL_3(2)=[168,1,1], A_7=[2520,1,1], S_7=[5040,-1,1].

The method used is that of resolvent polynomials. Beware that in the case of degree 7 one has to factor polynomials of degree 35 over Z, and this can take a long time. Furthermore there is a risk that the PARI stack overflows, so it is prudent in this case to start with a large stack.

The library syntax is galois(x,prec).

galoisapply(nf,aut,x)

nf being a number field as output by initalg or initalgred, and aut being a Galois automorphism of nf expressed either as a polynomial or a polymod (such automorphisms being found using for example one of the variants of galoisconj), computes the action of the automorphism aut on the object x in the number field. x can be an element (scalar, polymod, polynomial or column vector) of the number field, an ideal (either given by Z_K-generators or by a Z-basis), a prime ideal (given as a 5-element row vector) or an idele (given as a 2-element row vector). Because of possible confusion with elements and ideals, other vector or matrix arguments are forbidden.

The library syntax is galoisapply(nf,aut,x).

galoisconj(nf)

nf being a number field as output by initalg or initalgred, computes the conjugates of a root r of the non-constant polynomial x=nf[1] expressed as polynomials in r. This can be used even if the number field nf is not Galois since some conjugates may lie in the field. The method uses p-adic approximations to the roots and lllint. However, in rare cases some conjugates may be missed (in that case, if you know that the extension is Galois, use galoisconjforce below). As a note to old-timers of Pari, starting with version 1.39 this function works much better than the preceding version.

The library syntax is galoisconj(nf,prec).

galoisconj1(nf)

nf being a number field as output by initalg or initalgred, computes the conjugates of a root r of the non-constant polynomial x=nf[1] expressed as polynomials in r. This can be used even if the number field nf is not Galois since some conjugates may lie in the field. The method uses complex approximations to the roots and lllint (through lindep2).

The library syntax is galoisconj1(nf,prec). An older and usually less efficient version of this program is galoisconj2(x,prec), not accessible under GP, where x is now the polynomial itself.

galoisconjforce(nf)

nf being a number field as output by initalg or initalgred, computes the conjugates of a root r of the non-constant polynomial x=nf[1] expressed as polynomials in r. This function must be used ONLY when the number field nf is Galois, since otherwise it runs into an infinite loop. On the other hand, if the field is Galois, it is guaranteed to give all the conjugates after a finite time. The method uses p-adic approximations to the roots and lllint.

The library syntax is galoisconjforce(nf,prec).

idealadd(nf,x,y)

sum of the two ideals x and y in the number field nf. When x and y are given by Z-bases, this does not depend on nf and can be used to compute the sum of any two Z-modules. The result is given in HNF.

The library syntax is idealadd(nf,x,y).

idealaddone(nf,x,y)

x and y being two co-prime integral ideals (given in any form), this gives a two-component row vector [a,b] such that a\in x, b\in y and a+b=1.

The library syntax is idealaddone(nf,x,y).

idealaddmultone(nf,v)

v being a k-component vector of ideals (given in any form) which sum to Z_K, gives a k-component vector e such that e[i]\in x[i] for 1<= i<= k and \sum_{1<= i<= k}e[i]=1.

The library syntax is idealaddmultone(nf,v).

idealappr(nf,x)

If x is a fractional ideal (given in any form), gives an element alpha in nf such that for all prime ideals p such that the valuation of x at p is non-zero, we have v_p(alpha)=v_p(x), and. v_p(alpha)>=0 for all other p.

The library syntax is idealappr(nf,x).

idealapprfact(nf,x)

Given a prime ideal factorization as given by idealfactor, but possibly with zero or negative exponents gives an element alpha such that for all prime ideals p occuring in x, v_p(alpha) is equal to the exponent of p in x, and for all other prime ideals, v_p(alpha)>=0. This generalizes idealappr since it allows zero exponents. Note that the algorithm used is slightly different, so that idealapprfact(nf,idealfactor(nf,x)) is not always the same as idealappr(nf,x).

The library syntax is idealapprfact(nf,x).

idealcoprime(nf,x,y)

given two integral ideals x and y in the number field nf, finds a beta in the field, expressed on the integral basis nf[7], such that beta . y is an integral ideal coprime to x.

The library syntax is idealcoprime(nf,x).

idealdiv(nf,x,y)

quotient x . y^{-1} of the two ideals x and y in the number field nf. The result is given in HNF.

The library syntax is idealdiv(nf,x,y).

idealdivexact(nf, x, y)

Same as idealdiv, except that the quotient x . y^{-1} is assumed to be an integral ideal. This can be much faster than idealdiv when the norm of the quotient is small even though the norms of x and y are large.

The library syntax is idealdivexact(nf,x,y).

idealfactor(nf,x)

factors into prime ideal powers the ideal x in the number field nf. The output format is similar to the factor function, and the prime ideals are represented in the form output by the primedec function, i.e. as 5-element vectors.

The library syntax is idealfactor(nf,x).

idealhermite(nf,x)

gives the Hermite normal form matrix of the ideal x. The ideal can be given in any form whatsoever (typically by an algebraic number of it is principal, by a Z_K-system of generators, as a prime ideal as given by primedec, or by a Z-basis).

The library syntax is idealhermite(nf,x).

idealhermite2(nf,a,b)

gives the Hermite normal form matrix of the ideal x=aZ_K+bZ_K, where a and b are elements of K given either as vectors on the integral basis nf[7] or as algebraic numbers.

The library syntax is idealhermite(nf,x).

idealintersect(nf,x,y)

intersection of the two ideals x and y in the number field nf. When x and y are given by Z-bases, this does not depend on nf and can be used to compute the intersection of any two Z-modules. The result is given in HNF.

The library syntax is idealintersect(nf,x,y).

idealinv(nf,x)

inverse of the ideal x in the number field nf. The result is the Hermite normal form of the inverse of the ideal, together with the opposite of the Archimedean information if it is given.

The library syntax is idealinv(nf,x).

idealinv2(nf,x)

inverse of the ideal x in the number field nf. The result is the Hermite normal form of the inverse of the ideal, together with the opposite of the Archimedean information if it is given. The algorithm uses the different, and can be slower or faster than idealinv.

The library syntax is oldidealinv(nf,x).

ideallllred(nf,x,vdir)

LLL reduction of the ideal x in the number field nf, along the direction vdir. Here vdir must be either an r1+r2-component vector (r1 and r2 number of real and complex places of nf as usual), or the PARI zero, in which case vdir is assumed to be equal to the vector having only components equal to 1. The notion of reduction along a direction is technical and cannot be explained here. Note that this is not the same as the LLL reduction of the lattice x since ideal operations are involved. The result is the Hermite normal form of the LLL-reduced ideal, which is usually, but not always, a reduced ideal. x may also be a 2-component vector, the first being as above, and the second containing a matrix of Archimedean information. In that case, this matrix is suitably updated.

The library syntax is ideallllred(nf,x,vdir,prec).

idealmul(nf,x,y)

ideal multiplication of the ideals x and y in the number field nf. The result is a generating set for the ideal product with at most n elements, and is in Hermite normal form if x and y are, and this is given together with the sum of the Archimedean information in x and y if both are given.

The library syntax is idealmul(nf,x,y).

idealmulred(nf,x,y)

same as idealmul, except that the result is reduced using ideallllred.

The library syntax is idealmulred(nf,x,y,prec), where prec is a C-long integer representing the precision.

idealnorm(nf, x)

computes the norm of the ideal x in the number field nf.

The library syntax is idealnorm(nf, x).

idealpow(nf,x,k)

computes the k-th power of the ideal x in the number field nf. k can be positive, negative or zero. The result is NOT reduced, it is really the k-th ideal power, and is given in HNF. Use idealpowred if you want a reduced result.

The library syntax is idealpow(nf,x,k). A similar routine idealpows(nf,x,k) is available, where k is now a C-long integer.

idealpowred(nf,x,k)

computes a reduced k-th power of the ideal x in the number field nf. To get a non-reduced result, use idealpow. Note however that idealpowred is NOT the same as as idealpow followed by reduction (i.e. ideallllred), since the reduction is performed throughout the powering process.

The library syntax is idealpowred(nf,vp,k,prec), where prec is a C-long integer.

idealtwoelt(nf,x)

computes a two-element representation of the ideal x in the number field nf, using a straightforward (exponential time) search. x can be an ideal in any form, (including perhaps an Archimedean part, which is ignored) and the result is a row vector [a,alpha] with two components such that x=aZ_K+alphaZ_K and a\inZ. Note that a can be equal to zero if x is given as a polynomial, a polymod or by a single generator. If x is given by at least two generators, a is chosen to be the positive generator of x\capZ.

The library syntax is ideal_two_elt(nf,x).

idealtwoelt2(nf,x,a)

if x is an integral ideal (given in any form) and a a non-zero element of x, this computes a b\in x such that x=aZ_K+bZ_K, and outputs b on the integral basis nf[7]. The method uses idealapprfact and is asymptotically faster than idealtwoelt, but in practice it is usually slower.

The library syntax is ideal_two_elt2(nf,x,a).

idealval(nf,x,vp)

gives the valuation of the ideal x at the prime ideal vp in the number field nf, where vp must be a 5-component vector as given by primedec.

The library syntax is idealval(nf,x,vp) and the result is a C-long integer.

initalg(x)

x being a non-constant irreducible polynomial in Q[X], computes a 9-component vector v useful in working in the number field K defined by x. v[1] contains the polynomial x. v[2] contains [r1,r2], the number of real and complex places of K. v[3] contains the discriminant d(K) of the number field K. v[4] contains the index of v[1], i.e. [Z_K:Z[theta]], where theta is any root of v[1]. v[5] is a vector containing 7 matrices M, MC, T2, T, MD, TI, MDI useful for certain computations in the number field K. The matrix M is the (r1+r2)\times n matrix whose columns represent the numerical values of the conjugates of the elements of the integral basis. The matrix MC is essentially the conjugate of the transpose of M, except that the last r2 columns are also multiplied by 2. The matrix T2 is an n\times n matrix equal to the real part of the product MC . M (which is a real positive definite symmetric matrix), the so-called T2-matrix. The matrix T is the n\times n matrix whose coefficients are Tr(omega_iomega_j) where the omega_i are the elements of the integral basis. Note that T=\overline{MC} . M and in particular that T=T_2 if the field is totally real (in practice T_2 will have real approximate entries and T will have integer entries). Note also that det (T) is equal to the discriminant of the field K. The columns of MD express a Z-basis of the different of K on the integral basis v[7]. TI is equal to d(K)T^{-1}, which has integral coefficients. Finally, the columns of MDI express a Z-basis of d(K) times the codifferent ideal (which will be an integral ideal) on the integral basis v[7].

v[6] is the vector containing the r1+r2 roots of v[1] corresponding to the r1+r2 embeddings of the number field into C (the first r1 components are real, the next r2 have positive imaginary part). v[7] is an integral basis in Hermite normal form for Z_K expressed on the powers of theta. v[8] is the n\times n integral matrix expressing the power basis in terms of the integral basis, and finally v[9] is the n\times n^2 matrix giving the multiplication table of the integral basis.

The library syntax is initalg(x,prec).

initalgred(x)

same as initalg except that the polynomial x is changed into a polynomial defining K which is as simple as can easily be found using the polred algorithm, and all the subsequent computations are done using this new polynomial. In particular, the first component of the result is the modified polynomial. Note that x must be a monic polynomial.

The library syntax is initalgred(x,prec).

initalgred2(P)

this is a complement to initalgred. With the same conditions, it produces a two-element vector [nf,mod(a,pol)]. nf is the same as in initalgred, pol is the reduced polynomial nf[1] and mod(a,pol) is the polymod equal to mod(x,P).

The library syntax is initalgred2(x,prec).

initzeta(x)

compute a number of initilization data concerning the number field defined by the polynomial x so as to be able to compute the Dedekind zeta and lambda functions (zetak and lambdak). This function calls in particular the buchinit program, and is extremely dependent on the current precision. The result is a 9-component vector v whose components are very technical and cannot really be used by the user except through the programs zetak and lambdak. The only component which can be used if it has not been done already is v[1][4] which is the result of the buchinit call.

The library syntax is initzeta(x).

isideal(nf,x)

returns 1 if x is an ideal in the number field nf, 0 otherwise.

The library syntax is isideal(x).

isincl(x,y)

tests whether the number field K defined by the polynomial x is conjugate to a subfield of the field L defined by y (where x and y must be in Q[X]). If they are not, the output is the number 0. If they are, the output is a vector of polynomials, each polynomial a representing an isomorphism of K into L, i.e. being such that y | x\circ a.

The library syntax is nfincl(x,y).

isinclfast(x,y)

tests whether the number field K defined by the polynomial x is conjugate to a subfield of the field L defined by y (where x and y must be in Q[X]). If they are, this function may find an embedding much faster than isincl, but it may also miss some, so you must use isincl to be sure.

The library syntax is isinclfast(x,y).

isisom(x,y)

tests whether the two number fields defined by the polynomials x and y (which must be in Q[X]) are isomorphic. If they are not, the output is the number 0. If they are, the output is a vector of polynomials, each polynomial a representing an isomorphism, i.e. being such that y | x\circ a.

The library syntax is nfiso(x,y).

isisomfast(x,y)

tests whether the two number fields defined by the polynomials x and y (which must be in Q[X]) are isomorphic. If they are this function may find the isomorphism faster than isisom, and the output is the same, i.e. a vector of polynomials, each polynomial a representing an isomorphism, i.e. being such that y | x\circ a. However it may miss the isomorphism, so to be sure you must use isisom. To summarize, if you do not care about the complete list of isomorphisms: use first isisomfast. If the answer gives at least one isomorphism, stop. Otherwise (i.e. if the function returns 0) use isisom.

The library syntax is isisomfast(x,y).

isprincipal(bnf,x)

bnf being the number field data output by buchinit or buchinitfu, and x being either a Z-basis of an ideal in the number field (not necessarily in HNF) or a prime ideal in the format output by the function primedec, this function tests whether the ideal is principal or not. The result is more complete than a simple true/false answer: it gives a row vector v_1 which is the vector of components c_i of the class of the ideal x in the class group, expressed on the generators g_i given by buchinit (specifically buchinit[8][1][3]). The c_i are chosen so that 0<= c_i<n_i where n_i is the order of g_i (the vector of n_i being buchinit[8][1][2]). The more complete function isprincipalgen is available, but this function is slower and may print warning messages in the case where the precision is too low.

The library syntax is isprincipal(bnf,x).

isprincipalgen(bnf,x)

bnf being the number field data output by buchinit, and x being either a Z-basis of an ideal in the number field (not necessarily in HNF) or a prime ideal in the format output by the function primedec, this function tests whether the ideal is principal or not. The result is much more complete than a simple true/false answer: it is given as a 3 component vector [v_1,v_2,e] with the following meaning. v_1 is the vector of components c_i of the class of the ideal x in the class group, expressed on the generators g_i given by buchinit (specifically buchinit[8][1][3]). The c_i are chosen so that 0<= c_i<n_i where n_i is the order of g_i (the vector of n_i being buchinit[8][1][2]).

The second component v_2 gives on the integral basis the components of alpha such that x=alpha\prod_ig_i^{c_i}. In particular, x is principal if and only if v_1 is equal to the zero vector, and if this the case x=alphaZ_K where alpha is given by v_2. Note that if alpha is too large to be given, a warning message will be printed and v_2 will be set equal to the empty vector. Finally the third component e is analogous to the last component of buchgen: it gives a check on the accuracy of the result, in bits. e should be at least 10, and preferably much more. In any case, the result is checked for correctness.

The library syntax is isprincipalgen(bnf,x).

isprincipalray(bnfray,x)

bnfray being the number field data output by buchrayinit and x being an ideal in any form, outputs the components of x on the ray class group generators given in bnfray[5] in a manner similar to isprincipal.

The library syntax is isprincipalray(bnfray,x).

isprincipalraygen(bnfray,x)

bnfray being the number field data output by the function buchrayinit and x being an ideal in any form, outputs a 3-component vector v analogous to the one output by isprincipalgen, but for the ray class group. v[1] is the vector of components of x on the ray class group generators given in bnfray[5] in a manner similar to isprincipal. v[2] gives on the integral basis an element alpha such that x=alpha\prod_ig_i^{x_i}. Finally v[3] indicates the number of bits of accuracy left in the result. In any case the result is checked for correctness, but v[3] is included to see if it is necessary to increase the accuracy in other computations.

The library syntax is isprincipalraygen(bnfray,x).

isunit(bnf,x)

bnf being the number field data output by buchinit and x being an algebraic number (type integer, rational or polymod), this outputs the decomposition of x on the fundamental units an the roots of unity if x is a unit, the empty vector otherwise. More precisely, if u_1,...,u_r are the fundamental units found by buchgen and if zeta is the generator of the group of roots of unity found by buchgen, the output is a vector [x_1,...,x_r,x_{r+1}] such that x=u_1^{x_1}... u_r^{x_r} . zeta^{x_{r+1}}. The x_i are integers for i<= r and is an integer modulo the order of zeta for i=r+1.

The library syntax is isunit(bnf,x).

lambdak(nfz,x)

nfz being a number field initialized by initzeta (not by initalg), computes the value of the Dedekind lambda function of the number field at the complex number x (i.e. the product of the Dedekind zeta function by its gamma factors). The accuracy of the result depends in an essential way on the accuracy of both the initzeta program and the current accuracy, but even so the result may be off by up to 5 or 10 decimal digits.

The library syntax is glambdak(nfz,x,prec).

modreverse(a)

a being a polymod A(X) modulo T(X), finds the ``reverse polymod'' B(X) modulo Q(X), where Q is the minimal polynomial of a, which must be equal to the degree of T, and such that if theta is a root of T then theta=B(alpha) for a certain root alpha of Q.

This is very useful when one changes the generating element in algebraic extensions.

The library syntax is polymodrecip(x).

newtonpoly(x,p)

gives the vector of the slopes of the Newton polygon of the polynomial x with respect to the prime number p. The n components of the vector are in decreasing order, and n is equal to the degree of x.

The library syntax is newtonpoly(x,p).

nfdetint(nf,x)

given a pseudo-matrix x, computes a non-zero ideal contained in (i.e. multiple of) the determinant of x. This is particularly useful in conjunction with nfhermitemod

The library syntax is nfdetint(nf,x).

nfdiv(nf,x,y)

given two elements x and y as column vectors on the integral basis nf[7], computes their quotient x/y in the number field nf.

The library syntax is element_div(nf,x,y).

nfdiveuc(nf,x,y)

given two elements x and y as column vectors on the integral basis nf[7], computes an algebraic integer q in the number field nf such that the components of x-qy are reasonably small. In fact, this is functionally identical to round(nfdiv(nf,x,y)).

The library syntax is nfdiveuc(nf,x,y).

nfdivres(nf,x,y)

given two elements x and y as column vectors on the integral basis nf[7], gives a two-element row vector [q,r] such that x=qy+r, q is an algebraic integer in nf, and the components of r are reasonably small.

The library syntax is nfdivres(nf,x,y).

nfhermite(nf,x)

given a pseudo-matrix (A,I), finds a pseudo-basis in Hermite Normal Form of the module it generates.

The library syntax is nfhermite(nf,x).

nfhermitemod(nf,x,detx)

given a pseudo-matrix (A,I) and an ideal detx which is contained in (read integral multiple of) the determinant of (A,I) finds a pseudo-basis in Hermite Normal Form of the module generated by (A,I). This avoids coefficient explosion. detx can be computed using the function nfdetint.

The library syntax is nfhermitemod(nf,x,detx).

nfmod(nf,x,y)

given two elements x and y as column vectors on the integral basis nf[7], computes an element r of nf of the form r=x-qy with q and algebraic integer, and such that r is small. This is functionally identical to x-nfmul(nf,round(nfdiv(nf,x,y)),y).

The library syntax is nfmod(nf,x,y).

nfmul(nf,x,y)

given two elements x and y as column vectors on the integral basis nf[7], computes their product x*y in the number field nf.

The library syntax is element_mul(nf,x,y).

nfpow(nf,x,k)

given an element x as a column vector on the integral basis nf[7] and a positive or negative integer k, computes x^k in the number field nf.

The library syntax is element_pow(nf,x,k).

nfreduce(nf,x,ideal)

Given an ideal in Hermite Normal Form and an element x of the number field nf, finds an element r in nf such that x-r belongs to the ideal and r is small.

The library syntax is element_reduce(nf,x,ideal).

nfsmith(nf,x)

given a torsion module x as a 3-component row vector [A,I,J] where A is a square invertible n\times n matrix, I and J are two ideal lists, outputs an ideal list d_1,...,d_n which is the Smith normal form of x. In other words, x is isomorphic to Z_K/d_1\oplus...\oplusZ_K/d_n and d_i divides d_{i-1} for i>=2. The link between x and [A,I,J] is as follows: if e_i is the canonical basis of K^n, I=[b_1,...,b_n] and J=[a_1,...,a_n], then x is isomorphic to (b_1e_1\oplus...\oplus b_ne_n)/(a_1A_1\oplus...\oplus a_nA_n) , where the A_j are the columns of the matrix A.

Note that every finitely generated torsion module can be given in this way, and even with b_i=Z_K for all i.

The library syntax is nfsmith(nf,x).

nfval(nf,x,pr)

given an elements x as a column vectors on the integral basis nf[7], and a prime ideal pr in the format output by primedec, computes their the valuation at pr of the element x. The same result could be obtained using idealval(nf,x,pr) (since x would then be converted to a principal ideal), but it would be less efficient.

The library syntax is element_val(nf,x,pr), and the result is a C long.

ordred(x)

finds polynomials with reasonably small coefficients and of the same degree as that of x defining suborders of the order defined by x. One of the polynomials always defines Q (hence is equal to (x-1)^n, where n is the degree), and another always defines the same order as x if x is irreducible.

The library syntax is ordred(x).

polred(x)

finds polynomials with reasonably small coefficients defining subfields of the number field defined by x. One of the polynomials always defines Q (hence is equal to (x-1), where n is the degree), and another always defines the same number field as x if x is irreducible.

The library syntax is polred(x,prec).

polred2(x)

finds polynomials with reasonably small coefficients defining subfields of the number field defined by x. The result is a two-column matrix, the first column giving the elements, the second giving the polynomials.

One of the polynomials always defines Q (hence is equal to (x-1), where n is the degree), and another always defines the same number field as x if x is irreducible.

The library syntax is polred2(x,prec).

polredabs(x)

finds one of the polynomial defining the same number field as the one defined by x, and such that the sum of the squares of the modulus of the roots (i.e. the T_2-norm) is minimal.

The library syntax is polredabs(x,prec).

primedec(nf,p)

computes the prime ideal decomposition of the prime number p in the number field nf. p must be a (positive) prime number. Note that the fact that p is prime is not checked, so if a non-prime number p is given it may lead to unpredictable results.

The result is a vector of 5-component vectors, each representing one of the prime ideals above p in the number field nf. The representation vp=[p,a,e,f,b] of a prime ideal means the following. The prime ideal is equal to pZ_K+alphaZ_K where Z_K is the ring of integers of the field and alpha=\sum_i a_iomega_i where the omega_i form the integral basis nf[7], e is the ramification index, f is the residual index, and b is an n-component column vector representing a beta\inZ_K such that vp^{-1}=Z_K+beta/pZ_K which will be useful for computing valuations, but which the user can ignore.

The library syntax is primedec(nf,p).

principalideal(nf,x)

creates the principal ideal generated by the algebraic number x (which must be of type integer, rational or polymod) in the number field nf. The result is a one-column matrix.

The library syntax is principalideal(nf,x).

principalidele(nf,x)

creates the principal idele generated by the algebraic number x (which must be of type integer, rational or polymod) in the number field nf. The result is a two-component vector, the first being a one-column matrix representing the corresponding principal ideal, and the second being the vector with r_1+r_2 components giving the complex logarithmic embedding of x.

The library syntax is principalidele(nf,x).

rnfbasis(bnf,x)

given a big number field bnf as output by buchinit or buchinitfu, and either a polyomial x with coefficients in bnf defining a relative extension L of bnf, or a pseudo-basis x of such an extension, gives either a true bnf-basis of L if it exists, or an n+1-element generating set of L if not, where n is the rank of L over bnf.

The library syntax is rnfbasis(bnf,x).

rnfdiscf(nf,x)

given a number field nf as output by initalg or initalgred and a polyomial x with coefficients in nf defining a relative extension L of nf, computes the relative discriminant of L. This is a two-element row vector [D,d], where D is the relative ideal discriminant and d is the relative discriminant considered as an element of nf^*/{nf^*}^2.

Note: nf can be a bnf as output by buchinit.

The library syntax is rnfdiscf(bnf,x).

rnfhermitebasis(bnf,x)

given a big number field bnf as output by buchinit or buchinitfu, and either a polyomial x with coefficients in bnf defining a relative extension L of bnf, or a pseudo-basis x of such an extension, gives either a true bnf-basis of L in upper triangular Hermite Normal Form, if it exists, zero otherwise.

The library syntax is rnfhermitebasis(bnf,x).

rnfisfree(bnf,x)

given a big number field bnf as output by buchinit or buchinitfu, and either a polyomial x with coefficients in bnf defining a relative extension L of bnf, or a pseudo-basis x of such an extension, returns true (1) if L/bnf is free, false (0) if not.

The library syntax is rnfisfree(bnf,x), and the result is a C-long integer.

rnfpseudobasis(nf,x)

given a number field nf as output by initalg or initalgred and a polyomial x with coefficients in nf defining a relative extension L of nf, computes a pseudo-basis (A,I) and the relative discriminant of L. This is output as a four-element row vector [A,I,D,d], where D is the relative ideal discriminant and d is the relative discriminant considered as an element of nf^*/{nf^*}^2.

Note: nf can be a bnf as output by buchinit.

The library syntax is rnfpseudobasis(nf,x).

rnfsteinitz(nf,x)

given a number field nf as output by initalg or initalgred and either a polyomial x with coefficients in nf defining a relative extension L of nf, or a pseudo-basis x of such an extension as output for example by rnfpseudobasis, computes another pseudo-basis (A,I) (not in HNF in general) such that all the ideals of I except perhaps the last one are equal to the ring of integers of nf. The name of this functions comes from the fact that the ideal class of the last ideal of I (which is well defined) is called the steinitz class of the module Z_L.

Note: nf can be a bnf as output by buchinit.

The library syntax is rnfsteinitz(nf,x).

rootsof1(nf)

computes the number of roots of unity w and a primitive w-th root of unity (expressed on the integral basis) belonging to the number field nf. The result is a two-component vector [w,z] where z is a column vector expressing a primitive w-th root of unity on the integral basis nf[7].

The library syntax is rootsof1(nf).

signunit(bnf)

bnf being a the number field data output by buchinit and similar programs, this computes an r_1\times(r_1+r_2-1) matrix having +-1 components, giving the signs of the real embeddings of the fundamental units found by buchinit.

The library syntax is signunits(bnf).

smallbasis(x)

integral basis of the number field defined by the monic irreducible polynomial x, using the round 2 algorithm, where one does not take into account squares of primes which are not precomputed.

The library syntax is smallbase(x,&y), where y will receive the discriminant of the number field (not of the polynomial x). This program is the translation in C of a program written by David Ford.

smalldiscf(x)

field discriminant of the number field defined by the monic irreducible polynomial x, where one does not take into account squares of primes which are not precomputed.

The library syntax is smalldiscf(x). See also smallbasis above.

smallpolred(x)

same as polred above except that only a suborder of the maximal order may be used.

The library syntax is smallpolred(x,prec).

smallpolred2(x)

same as polred2 above except that only a suborder of the maximal order may be used.

The library syntax is smallpolred2(x,prec).

threetotwo(nf,a,b,c)

Given a number field nf and three algebraic integers a, b, c in nf given as column vectors on the integral basis nf[7], outputs a 3-component row vector [d,e,U] such that U is a unimodular (i.e. det (U)=+-1) 3\times 3 matrix with coefficients in the ring of integers of nf satisfying the matrix identity [a,b,c]U=[0,d,e]. The elements d, e and the entries of U are given as column vectors on nf[7].

The library syntax is threetotwo(nf,a,b,c).

tschirnhaus(x)

apply a random Tschirnhausen transformation to the non-constant separable polynomial x so as to obtain a new equation for the number field (or more generally the etale algebra) defined by x. This is for instance useful when computing resolvents, hence is used in the galois function above.

The library syntax is tschirnhaus(x).

twototwo(nf,a,b)

Given a number field nf and two algebraic integers a and b in nf given as column vectors on the integral basis nf[7], outputs a 3-component row vector [d,e,U] such that U is a unimodular (i.e. det (U)=+-1) 2\times 2 matrix with coefficients in the ring of integers of nf satisfying the matrix identity [a,b]U=[d,e], and d, e are as ``small'' as possible. The elements d, e and the entries of U are given as column vectors on nf[7].

The library syntax is twototwo(nf,a,b).

zetak(nfz,x)

nfz being a number field initialized by initzeta (not by initalg), computes the value of the Dedekind zeta function of the number field at the complex number x. The accuracy of the result depends in an essential way on the accuracy of both the initzeta program and the current accuracy, but even so the result may be off by up to 5 or 10 decimal digits.

The library syntax is gzetak(nfz,x,prec).

zideallog(nf,x,bid)

nf being a number field, bid being a ``big ideal'' as output by zidealstarinit and x being a non-necessarily integral element of nf which must have valuation equal to 0 at all prime ideals dividing I=bid[1], computes the ``discrete logarithm'' of x on the generators given in bid[2]. In other words, if g_i are these generators, of orders d_i respectively, the result is a column vector of integers (x_i) such that 0<= x_i<d_i and x ~ \prod_ig_i^{x_i}\pmod{ ^*I} . Note that when I is a module, this implies also sign conditions on the embeddings.

The library syntax is zideallog(nf,x,bid).

zidealstar(nf,I)

nf being a number field, and I either and ideal in any form, or a row vector whose first component is an ideal and whose second component is a row vector or r_1 0 or 1, computes the structure of (Z_K/I)^* as a 3-component vector v. v[1] is the order, v[2] is the vector of SNF cyclic components and v[3] the corresponding generators. When the row vector is explicitly included, the non-zero elements of this vector are considered as real embeddings of nf in the order given in roots, i.e. in nf[6], and then I is a module with components at infinity.

The library syntax is zidealstar(nf,I).

zidealstarinit(nf,I)

nf being a number field, and I either and ideal in any form, or a row vector whose first component is an ideal and whose second component is a row vector or r_1 0 or 1, computes necessary data for computing in the group (Z_K/I)^*. The result is a as a 5-component vector w. w[1] is the ideal or module I itself. w[2] is the structure of the group as output by zidealstar. the other components are difficult to describe and are used only in conjunction with the function zideallog.

The library syntax is zidealstarinit(nf,I).

Polynomials and power series.

We group here all functions which are specific to polynomials or power series. Many other functions which can be applied on these objects are described in the other sections. Also, some of the functions described here can be applied to other types.

apprpadic(x,a)

vector of p-adic roots of the polynomial x congruent to the p-adic number a modulo p (or modulo 4 if p=2), and with the same p-adic precision as a. The number a can be an ordinary p-adic number (type 7, i.e. an element of Q_p) or can be an element of a finite extension of Q_p, in which case it is of type 9 (polymod), where at least one of the coefficients of the polymod is a p-adic number. In this case, the result is the vector of roots belonging to the same extension of Q_p as a.

The library syntax is apprgen9(x,a), but if a is known to be simply a p-adic number (type 7), the syntax apprgen(x,a) can be used.

convol(x,y)

convolution (or Hadamard product) of the two power series x and y; in other words if x=\sum a_k*X^k and y=\sum b_k*X^k then convol(x,y)=\sum a_k*b_k*X^k.

The library syntax is convol(x,y).

cyclo(n)

n-th cyclotomic polynomial, where n must be positive.

The library syntax is cyclo(n), where n is a C-long integer.

deriv(x,y)

derivative of x with respect to the simple variable y. x can be any type except polymod. The derivative of a scalar type is zero, and the derivative of a vector or matrix is done componentwise.

The library syntax is deriv(x,v), where v is the number of the variable y.

disc(x)

discriminant of x. x must be a polynomial. The algorithm used is the subresultant algorithm.

The library syntax is discsr(x).

eval(x)

replace in x the formal variables by the values that have been assigned to them after the creation of x. This is mainly useful in GP, and not in library mode. Do not confuse this with substitution (see subst below).

The library syntax is geval(x).

factorpadic(x,p,r)

p-adic factorization of the polynomial x to precision r, the result being a two-column matrix as in factor. r must be in general be strictly larger than the p-adic valuation of the discriminant of x for the result to make any sense. The method used is Ford-Letard's implementation of the round 4 algorithm of Zassenhaus. Another version using an algorithm due to Buchmann and Lenstra is factorpadic2, but is less efficient.

The library syntax is factorpadic4(x,p,r), where r is a C-long integer.

factpol(x,l,hint)

x must be a polynomial with coefficients in Z. If l=0, find the complete factorization of x, and if l>0, search only for irreducible factors of degree less than or equal to l. hint is a positive integer which tells the program that the degrees of all the factors are multiples of hint. The result is a two-column matrix, the first one containing the irreducible factors, the second one the exponents.

The library syntax is factpol(x,l,hint). The algorithm used is the standard Hensel lifting of a mod p factorization. Another implementation using instead root finding over C (instead of implicitly using Q_p) is factpol2(x,l) (no hint included in that case).

integ(x,y)

formal integration of x with respect to the simple variable y. No logarithmic terms must occur in the result. x can be of any type. When x is a rational function, it is assumed that the base ring is an integral domain of characteristic zero.

The library syntax is integ(x).

isirreducible(x)

x being a polynomial (univarariate in the present version 1.39.03.01), returns 1 if x is non-constant and irreducible, 0 otherwise.

The library syntax is gisirreducible(x).

karamul(x,y,k)

Karatsuba multiplication of the polynomials x and y, recursively called k times. This is a very primitive and preliminary attempt at a sturdy Karatsuba program, and will hopefully be improved (in particular the recursion variable k will disappear).

The library syntax is karatsuba(x,y,k).

laplace(x)

x must be a power series with only non-negative exponents. If x=\sum (a_k/k!)*X^k then the result is \sum a_k*X^k.

The library syntax is laplace(x).

legendre(x)

creates the x^{th} Legendre polynomial.

The library syntax is legendre(x), where x is a C-long integer.

polint(xa,ya,x)

given the data vectors xa and ya of the same length n (xa containing the x-coordinates, and ya the corresponding y-coordinates), this function finds the interpolating polynomial passing through these points and evaluates it at the value x.

The library syntax is polint(xa,ya,x,&er), where er will contain an error estimate on the returned value.

polsym(x,n)

creates the vector of the symmetric powers of the roots of the polynomial x up to power n.

The library syntax is polsym(x).

recip(x)

reciprocal polynomial of x, i.e. the coefficients are in reverse order. x must be a polynomial.

The library syntax is polrecip(x).

resultant(x,y)

resultant of the two polynomials x and y with exact entries. The algorithm used is the subresultant algorithm.

The library syntax is subres(x,y).

resultant2(x,y)

resultant of the two polynomials x and y. The algorithm used is the determinant of Sylvester's matrix.

The library syntax is resultant2(x,y).

reverse(x)

reverse power series (i.e. x^{-1}, not 1/x) of x. x must be a power series whose valuation is exactly equal to one.

The library syntax is recip(x).

rootmod(x,p)

row vector of roots modulo p of the polynomial x. Slightly slower than rootmod2 below for p<100, but much faster for larger values. The particular non-prime value p=4 is accepted, mainly for 2-adic computations. Multiple roots are not repeated.

The library syntax is rootmod(x,p).

rootmod2(x,p)

row vector of roots modulo p of the polynomial x. To be used only when p is small. Multiple roots are repeated with their order of multiplicity.

The library syntax is rootmod2(x,p).

rootpadic(x,p,r)

row vector of p-adic roots of the polynomial x with p-adic precision equal to r. Multiple roots are not repeated.

The library syntax is rootpadic(x,p,r), where r is a C-long integer.

roots(x)

complex roots of the polynomial x, given as a column vector where each root is repeated according to its multiplicity. The precision is given as for transcendental functions: under GP it is kept in the variable prec and is transparent to the user, but it must be explicitly given as a second argument in library mode.

The algorithm used is a variant of the Newton-Raphson method and is not guaranteed to converge, but is rather fast. If you get the messages ``too many iterations in roots'' or ``INTERNAL ERROR: incorrect result in roots'', try modifying your polynomial to get the roots, or try to use the slower function rootslong.

The library syntax is roots(x,prec).

rootslong(x)

same as roots except that the program is a little more robust and slower.

The library syntax is rootslong(x,prec).

sturm(x)

number of real roots of the real polynomial x, using Sturm's algorithm.

The library syntax is sturm(x). The result is a C-long integer.

sturmpart(x,a,b)

number of real roots of the real polynomial x in the interval ]a,b], using Sturm's algorithm.

The library syntax is sturmpart(x). The result is a C-long integer.

subst(x,y,z)

replace the simple variable y by the argument z in expression x. Every non-scalar type is allowed for x. If x is a power series, z must be either a polynomial, a power series, or a rational function. y must be a simple variable name.

The library syntax is gsubst(x, v,z), where v is the number of the variable y.

sylvestermatrix(x,y)

forms the Sylvester matrix corresponding to the two polynomials x and y, where the coefficients of the polynomials are put in the columns of the matrix (which is the natural direction for solving equations afterwards). The use of this matrix can be essential when dealing with polynomials with inexact entries, since polynomial Euclidean division doesn't make much sense in that case.

The library syntax is sylvestermatrix(x,y).

taylor(x,y)

Taylor expansion around 0 of x with respect to the simple variable y. x can be of any reasonable type, for example a rational function. The number of terms of the expansion is transparent to the user under GP, but must be given as a second argument in library mode.

The library syntax is tayl(x,y,n), where the C-long integer n is the desired number of terms in the expansion.

tchebi(x)

creates the x^{th} Tchebicheff polynomial.

The library syntax is tchebi(x), where x is a C-long integer.

Vectors, matrices, linear algebra and sets.

adj(x)

adjoint matrix of x, i.e. the matrix y of cofactors of x such that x*y=det(x)*Id. x must be a (non-necessarily invertible) square matrix.

The library syntax is adj(x).

algdep(x, k)

x being real or complex, finds a polynomial of degree at most k having x as approximate root. The algorithm used is a variant of the LLL algorithm due to Hastad, Lagarias and Schnorr (STACS 1986). Note that the polynomial which is obtained is not necessarily the ``correct'' one. One can check the closeness either by a polynomial evaluation or substitution, or by finding the roots of the polynomial given by algdep.

The library syntax is algdep(x,k,prec), where k is a C-long integer.

algdep2(x, k, dec)

x being real or complex, finds a polynomial of degree at most k having x as approximate root. dec is a number which should be between half the number of decimal digits of precision and that number. The algorithm used is the LLL algorithm. Note that the polynomial which is obtained is not necessarily the ``correct'' one. One can check the closeness either by a polynomial evaluation or substitution, or by finding the roots of the polynomial given by algdep2.

The library syntax is algdep2(x,k,dec,prec), where k and dec are C-long integers.

char(x,y)

characteristic polynomial of x with respect to the variable y, i.e. determinant of y*I-x if x is a square matrix, determinant of the map multiplication by x if x is a polymod, error if x is of any other type. For matrices, the method used is essentially the same as for computing the adjoint matrix, i.e. computing the traces of the powers of x.

The library syntax is caradj0(x, v), where v is the variable number, or even caradj(x,v,0). Note that the function caradj(x,v,pty) returns the characteristic polynomial of x in the variable v, and if pty is not equal to 0, puts in pty the address of the adjoint matrix of x, so both can be obtained at once.

char1(x,y)

characteristic polynomial of x with respect to the variable y, i.e. determinant of y*I-x if x is a square matrix, determinant of the map multiplication by x if x is a polymod, error if x is of any other type. For matrices, the method used is that of Lagrange interpolation and is almost always slower than char. Identical to char for polymods.

The library syntax is caract(x, v), where v is the variable number.

char2(x,y)

characteristic polynomial of the square matrix x with respect to the variable y using the Hessenberg form. This is faster than char when the coefficients are integermod a prime or real numbers, but is usually slower in other base rings.

The library syntax is carhess(x,v), where v is the variable number.

concat(x,y)

concatenation of x and y. If x or y is not a vector or matrix, it is considered as a one-dimensional vector. All types are allowed for x and y, but the sizes must be compatible. Note that matrices are concatenated horizontally, i.e. the number of rows stays the same. Using transpositions, it is easy to concatenate them vertically.

To concatenate vectors sideways (i.e. to obtain a two-row or two-column matrix), first transform the vector into a one-row or one-column matrix using the function mat below.

The library syntax is concat(x,y).

det(x)

determinant of x. x must be a square matrix. Another program called det2(x) is better when the entries of the matrix are reals or integers for example, but can be much worse for more complicated entries like multivariate polynomials.

The library syntax is det(x) and det2(x).

detint(x)

x being an m\times n matrix with integer coefficients, this function computes a multiple of the determinant of the lattice generated by the columns of x if it is of rank m, and returns zero otherwise. This function can be useful in conjunction with the function hermitemod which needs to know such a multiple. Other ways to obtain this determinant (assuming the rank is maximal) is det(lllkerim(x)[2]*x) or simply det(hermite(x)). Try to see which is faster in your case.

The library syntax is detint(x).

eigen(x)

gives the eigenvectors of x as columns of a matrix.

The library syntax is eigen(x).

extract(x,y)

extraction of components of the vector or matrix x according to y. x must be a vector or a matrix. In the case of a matrix, the components are as usual the columns of x. The parameter y must be either a number of type integer or a vector. If y is an integer, it is considered as a mask: The binary bits of y are read from right to left, but correspond to taking the components from left to right. For example, if y=13=(1101)_2 then the components 1,3 and 4 are extracted.

If y is a vector, which must have integer entries, these entries correspond to the component numbers to be extracted, in the order specified.

In the case of a matrix, the difference between extract and matextract is that only columns are extracted.

The library syntax is extract(x,y).

gauss(x,y)

x being a square matrix and y a column vector, finds the solution u of x*u=y, using Gaussian elimination. This has the same effect as, but is much faster, than x^{-1}*y.

The library syntax is gauss(x,y).

hermite(x)

if x is a (not necessarily square) matrix of maximal rank, finds the upper triangular Hermite Normal Form of x If the rank of x is equal to its number of rows, the result is a square matrix. In general, the columns of the result form a basis of the lattice spanned by the columns of x.

The library syntax is hnf(x).

hermitemod(x,d)

if x is a (not necessarily square) matrix of maximal rank with integer entries, and d is a multiple of the (non-zero) determinant of the lattice spanned by the columns of x, finds the upper triangular Hermite Normal Form of x.

If the rank of x is equal to its number of rows, the result is a square matrix. In general, the columns of the result form a basis of the lattice spanned by the columns of x. This is much faster than hermite when d is known.

The library syntax is hnfmod(x,d).

hess(x)

Hessenberg form of the square matrix x.

The library syntax is hess(x).

hilbert(x)

x being a C-long integer, creates the Hilbert matrix of order x, i.e. the matrix whose coefficient (i,j) is 1\over {i+j-1}.

The library syntax is hilbert(x).

idmat(n)

creates the n\times n identity matrix.

The library syntax is idmat(n) where n is a C-long integer.

Related functions are gscalmat(x,n), which creates x times the identity matrix (x being a GEN and n a C-long integer), and gscalsmat(x,n) which is the same when x is a C-long integer.

image(x)

gives a basis for the image of the matrix x as columns of a matrix. A priori the matrix can have entries of any type.

The library syntax is image(x).

imagecompl(x)

gives the vector of the column indices which are not extracted by the function image. Hence the number of components of imagecompl(x) plus the number of columns of image(x) is equal to the number of columns of the matrix x.

The library syntax is imagecompl(x).

imager(x)

gives a basis for the image of the matrix x as columns of a matrix, where x has elements which can be non-exact real or complex numbers. In that case, the precision of the matrix entries determines what is meant by an element of the image. In particular, if the matrix is ill-conditioned, the results may not be what you expect.

The library syntax is imagereel(x).

indexrank(x)

x being a matrix of rank r, gives two vectors of length r giving a list of rows and columns respectively (starting from 1) such that the extracted matrix obtained from these 2 vectors using matextract is invertible.

The library syntax is indexrank(x).

indsort(x)

indirect sorting of the vector x, i.e. if x is an n-component vector, creates a permutation of [1,2,...,n] which applied to the components of x sorts x in increasing order.

The library syntax is indexsort(x).

intersect(x,y)

x and y being two matrices with the same number of rows each of whose columns are independent, finds a basis of the Q-vector space equal to the intersection of the spaces spanned by the columns of x and y respectively. See also the function idealintersect above, which does the same for free Z-modules.

The library syntax is intersect(x,y).

inverseimage(x,y)

gives a column vector belonging to the inverse image of the column vector y by the matrix x if one exists, the empty vector otherwise. To get the complete inverse image, it suffices to add to the result any element of the kernel of x obtained for example by ker.

The library syntax is inverseimage(x,y).

isset(x)

returns true (1) if x is a set, false (0) if not. In PARI, a set is simply a row vector whose entries are strictly increasing. To convert any vector (and other objects) into a set, use the function set below.

The library syntax is isset(x), and this returns a C-long integer.

jacobi(x)

x being a real symmetric matrix, this gives a vector having two components: the first one is the vector of eigenvalues of x, the second is the corresponding orthogonal matrix of eigenvectors of x. The method used is Jacobi's method for symmetric matrices.

The library syntax is jacobi(x).

ker(x)

gives a basis for the kernel of the matrix x as columns of a matrix. A priori the matrix can have entries of any type. See also keri and kerr.

The library syntax is ker(x).

keri(x)

same as ker, except that it assumes that the matrix has entries of type integer. In that case it is much faster.

The library syntax is keri(x).

kerint(x)

gives an LLL-reduced Z-basis for the lattice equal to the kernel of the matrix x as columns of the matrix x with integer entries (rational entries are not permitted) using a modified integer LLL algorithm.

The library syntax is kerint(x).

kerint1(x)

like kerint, but using matrixqz3, gives an LLL-reduced Z-basis for the lattice equal to the kernel of the matrix x as columns of the matrix x with integer or rational entries. If LLL reduction of the final result is not desired, use matrixqz3(ker(x)) instead.

The library syntax is kerint1(x).

kerint2(x)

like kerint, but using another modified LLL algorithm, gives an LLL-reduced Z-basis for the lattice equal to the kernel of the matrix x as columns of the matrix x with integer entries (rational entries are not permitted). In the present version 1.39.03.01, only independent rows are allowed.

The library syntax is kerint2(x).

kerr(x)

gives a basis for the kernel of the matrix x as columns of a matrix, where x has elements which can be non-exact real or complex numbers. In that case, the precision of the matrix entries determines what is meant by an element of the kernel. In particular, if the matrix is ill-conditioned, the results may not be what you expect.

The library syntax is kerreel(x).

lexsort(x)

sort the elements of the vector x by ascending lexicographic order (see lex above).

The library syntax is lexsort(x).

lindep(x)

x being a vector with real or complex coefficients, finds a small integral linear combination among these coefficients using a variant of the LLL algorithm due to Hastad, Lagarias and Schnorr (STACS 1986).

The library syntax is lindep(x,prec).

lindep2(x,dec)

x being a vector with real or complex coefficients, finds a small integral linear combination among these coefficients using the LLL algorithm. dec is a parameter which should be between one half the number of decimal digits of precision and that number.

The library syntax is lindep2(x,dec,prec) where dec is a C-long integer.

lll(x)

LLL algorithm applied to the columns of the (not necessarily square) matrix x. The columns of x must however be of maximal rank (otherwise if x has integral coefficients use lllint. The result is a square transformation matrix T such that x . T is an LLL-reduced basis of the lattice generated by the column vectors of x. The computations are done with real numbers (i.e. not with rational numbers) hence are fast but as presently programmed (version 1.39.03.01) are numerically unstable. An older version of this program is lll1.

The library syntax is lll(x,prec).

lllgram(x)

same as LLL except that the matrix x which is now square is the Gram matrix of the lattice vectors, and not the coordinates of the vectors themselves. The result is again the transformation matrix T which gives (as columns) the coefficients with respect to the initial basis vectors. Same remarks as for LLL about numerical instability in the present version 1.39.03.01. An older version of this program is lllgram1.

The library syntax is lllgram(x,prec).

lllgramint(x)

The matrix x being the Gram matrix of a basis of some lattice, is assumed to have integral entries. The result is the unimodular transformation matrix T which gives (as columns) the coefficients with respect to the initial basis vectors. The computation is done entirely with integers and is both accurate and quite fast.

The library syntax is lllgramint(x).

lllgramkerim(x)

LLL algorithm applied to the Gram matrix of some lattice, which is assumed to have integral entries. Here the columns can be linearly dependent. The result is a two-component vector of matrices whose concatenation form a unimodular transformation matrix T which gives as columns the coefficients with respect to the initial basis vectors. The first matrix will give the kernel, the second will give an LLL-reduced basis of the image.

The library syntax is lllgramkerim(x).

lllint(x)

LLL algorithm applied to the columns of the (not necessarily square) matrix x. It is assumed that the corresponding Gram matrix is integral. The result is a transformation matrix T such that x . T is an LLL-reduced basis of the lattice generated by the column vectors of x. The matrix T is square if the columns of x are linearly independent.

The computation is done entirely with integers and the algorithm is both accurate and quite fast.

The library syntax is lllint(x).

lllintpartial(x)

similar to lllint, except x should be an integer matrix whose columns are linearly independent. The output is a square transformation matrix T such that x . T is a partially reduced basis of the lattice generated by the column vectors of x. A basis is said to be partially reduced if | v_i +- v_j | >= |v_i| for any two distinct basis vectors v_i, v_j.

This can be faster than lllint when one row of x is huge and the rest of x is small. If T1 = lllintpartial(x) and T2 = lllint(gmul(x, T1), then output x . T1 . T2 is an LLL reduced basis for x.

The library syntax is lllintpartial(x).

lllkerim(x)

LLL algorithm applied to the columns of the (not necessarily square) matrix x which is assumed to have integral entries. Here the columns can be linearly dependent. The result is a two-component vector of matrices, the columns of the first matrix representing a basis of the integer kernel of x (not necessarily LLL-reduced) and the columns of the second matrix being an LLL-reduced Z-basis of the image of the matrix x.

The library syntax is lllkerim(x).

lllrat(x)

same as LLL except that the computations are all done in rational numbers. Hence no risk of numerical instability, but extremely slow. This function is essentially superseded by lllint so will soon disappear.

The library syntax is lllrat(x).

mat(x)

transform the object x into a matrix. If x is not a vector or a matrix, this creates a 1\times 1 matrix. If x is a row (resp. column) vector, this creates a 1-row (resp. 1-column) matrix. If x is already a matrix, a copy of x is created.

This function can be useful in connection with the function concat (see above).

The library syntax is gtomat(x).

matextract(x,y,z)

extraction of a matrix from the matrix x, the line mask or vector y and the column mask or vector z. x must be a matrix, and y and z either numbers of PARI type integer or vectors. The extraction is done using the same rules as for extract (see above). The difference with extract is that both lines and columns are extracted.

The library syntax is matextract(x,y,z).

matinvr(x)

computes the inverse matrix of x assumed to have real entries. This may be more efficient than using ginv (or x^{-1} under GP).

The library syntax is invmatreel(x). A related function is invmulmatreel(x,y) which directly computes x^{-1}*y for matrices x and y.

matsize(x)

x being a vector or matrix, returns a row vector with two components, the first being the number of rows (1 for a row vector), the second the number of columns (1 for a column vector).

The library syntax is matsize(x).

matrixqz(x,p)

x being an m\times n matrix with m>= n with rational or integer entries and of maximal rank, this function returns a matrix having only integral entries, having the same image as x (which is obtained from x by right multiplication with an n\times n invertible matrix) and such that the GCD of all its n\times n subdeterminants is equal to 1 when p is equal to 0, or not divisible by p otherwise. Here p must be a prime number (when it is non-zero). However, if the function is used when p has no small prime factors, it will either work or give the message ``impossible inverse modulo'' and a non-trivial divisor of p.

The library syntax is matrixqz(x,p).

matrixqz2(x)

x being an m\times n matrix with rational or integer entries, this function returns a matrix whose columns form a basis of the lattice equal to Z^n intersected with the lattice generated by the columns of x.

The library syntax is matrixqz2(x).

matrixqz3(x)

x being an m\times n matrix with rational or integer entries, this function returns a matrix whose columns form a basis of the lattice equal to Z^n intersected with the Q-vector space generated by the columns of x.

The library syntax is matrixqz3(x).

minim(x,b,m)

x being a square and symmetric matrix with integer entries representing a positive definite quadratic form, gives the number of vectors of square norm less than or equal to b (for the norm defined by x), and at most m of these vectors. The result is a three-component vector, the first component being the number of vectors, the second being the maximum norm found, and the last vector is a matrix whose columns are the vectors found (at most m).

In the special case where b=0, the function searches for the minimal non-zero vectors.

The library syntax is minim(x,b,m)

perf(x)

x being a square and symmetric matrix with integer entries representing a positive definite quadratic form, looks for the perfection of the form: gives the rank of the family of the s symmetric matrices v_iv_i^t, where s is half the number of minimal vectors and the v_i (1<= i<= s) are the minimal vectors.

The library syntax is perf(x)

pascal(x)

creates as a matrix the lower triangular pascal triangle of order x+1 (i.e. with binomial coefficients up to x).

The library syntax is pascal(x), where x is a C-long integer.

rank(x)

rank of the matrix x.

The library syntax is rank(x), and the result is a C-long integer.

set(x)

convert x into a set, i.e. into a row vector with strictly increasing entries. x can be of several types, but is most useful when x is already vector.

The library syntax is gtoset(x).

setintersect(x,y)

intersection of the two sets x and y.

The library syntax is intersect(x,y).

setminus(x,y)

difference of the two sets x and y, i.e. set of elements of x which do not belong to y.

The library syntax is setminus(x,y).

setsearch(x,y)

searches if y belongs to the set x. If it does, returns the index j such that x[j]==y, otherwise returns 0.

The library syntax is setsearch(x,y) which returns a C-long integer.

setunion(x,y)

union of the two sets x and y.

The library syntax is union(x,y).

signat(x)

signature of the quadratic form represented by the symmetric matrix x. The result is a two-component vector.

The library syntax is signat(x)

smith(x)

if x is a (singular or non-singular) square matrix with integer coefficients, outputs the vector of elementary divisors of x (i.e. the diagonal of the Smith normal form of x).

The library syntax is smith(x).

smithpol(x)

if x is a (singular or non-singular) square matrix with polynomial coefficients, outputs the vector of elementary divisors of x (i.e. the diagonal of the Smith normal form of x).

The library syntax is gsmith(x).

smith2(x)

if x is a (singular or non-singular) square matrix, outputs a 2-component vector [u,v] where u and v are two unimodular matrices such that uxv is the diagonal matrix whose diagonal is smith(x).

The library syntax is smith2(x).

sort(x)

sort the vector x in ascending order, using the heapsort method. x must be a vector, and its components integers, reals, or fractions. A related function is indsort (see above) which gives the indices of the sorted vector in terms of the initial one. For example, extract(x,indsort(x)) is equivalent to sort(x).

The library syntax is sort(x).

sqred(x)

decomposition into squares of the quadratic form represented by the symmetric matrix x. The result is a matrix whose diagonal entries are the coefficients of the squares, and the non-diagonal entries represent the bilinear forms.

The library syntax is sqred(x).

supplement(x)

assuming that the columns of the matrix x are linearly independent (if they are not, an error message is issued), find a square invertible matrix whose first columns are the columns of x, i.e. supplement the columns of x to a basis of the whole space.

The library syntax is suppl(x).

trace(x)

This applies to quite general x. If x is not a matrix, it is equal to the sum of x and its conjugate, except for polymods where it is the trace as an algebraic number.

For x a square matrix, it is the ordinary trace. If x is a non-square matrix (but not a vector), an error occurs.

The library syntax is trace(x).

trans(x) or x~{ }

transpose of x. This has an effect only on vectors and matrices.

The library syntax is gtrans(x).

vecsort(x,k)

sort the vector of vectors or matrix x in ascending order of the k-th component, using the heapsort method. The components being compared must be of type integer, real or fraction. k can also be a vector, in which case the sorting is done lexicographically according to the components listed in the vector k. For example, if k=[2,1,3], sorting will be done with respect to the second component, and when these are equal, with respect to the first, and when these are equal, with respect to the third.

The library syntax is vecsort(x,k).

Sums, products, integrals and similar functions.

Although the GP calculator is programmable, it is useful to have preprogrammed a number of loops, including sums, products, and a certain number of recursions. Also, a number of functions from numerical analysis like numerical integration and summation of series will be described here.

One of the parameters in these loops must be the control variable, hence a simple variable name. The last parameter must be any legal PARI expression, including of course expressions using loops. Since it is much easier to program directly the loops in library mode, these functions are mainly useful for GP programming. The use of these functions in library mode is a little tricky and its explanation will be omitted, although the reader can try and figure it out by himself by reading the source code. A brief explanatory sketch is given in section 11. Hence in this section we only give the library syntax, with no semantic explanation.

The letter X will always denote any simple variable name, and represents the formal parameter used in the function.

divsum(n,X,expr)

sum of expression expr over the positive divisors of n.

In the present version 1.39.03.01, n is restricted to being less than 2^{31}.

The library syntax is divsomme(entree *ep, GEN num, char *ch).

hvector(n,X,expr)

creates a row vector with n components whose components are the expression expr evaluated at the integral points between 1 and n.

The library syntax is vecteur(entree *ep, GEN nmax, char *ch).

(numerical) integration

A number of Romberg-like integration methods are implemented. The user should not require too much accuracy: 18 or 28 decimal digits is OK, but not much more. In addition, analytical cleanup of the integral must have been done: there must be no singularities in the interval or at the boundaries. In practice this can be accomplished with a simple change of variable. Furthermore, for improper integrals, where one or both of the limits of integration are plus or minus infinity, the function must decrease sufficiently rapidly at infinity. This can often be accomplished through integration by parts.

Note that infinity can be represented with essentially no loss of accuracy by 1e4000. However beware of real underflow when dealing with rapidly decreasing functions. For example, if one wants to compute the \int_0^\infty e^{-x^2} dx to 28 decimal digits, then one should set infinity equal to 10 for example, and certainly not to 1e4000.

The integrand may have values belonging to a vector space over the real numbers; in particular, it can be complex-valued or vector-valued.

intgen(X=a, b, expr)

general driver routine for doing numerical integration from a to b of the expression expr, with respect to the formal variable X.

The library syntax is rombint(entree *ep, GEN a, GEN b, char *ch, long int prec).

intinf(X=a, b, expr)

numerical integration from a to b, tailored for being used when a or b are infinite. One must have ab>0, and in fact if for example b=\infty, then it is preferable to have a as large as possible, at least a>=1.

The library syntax is qromi(entree *ep, GEN a, GEN b, char *ch, long int prec).

intnum(X=a,b,expr)

simple numerical integration from a to b. This is the fastest method, and should be used when a and b are not too large, the function is smooth, and can be evaluated exactly everywhere on the interval [a,b].

The library syntax is qromb(entree *ep, GEN a, GEN b, char *ch, long int prec).

intopen(X=a,b,expr)

numerical integration from a to b. This method should be used, again when a and b are not too large, but when the function is now allowed to be undefined (but continuous) at a or b, for example the function sin (x)/x at x=0.

The library syntax is qromo(entree *ep, GEN a, GEN b, char *ch, long int prec).

Two summation methods are also implemented, for alternating series, and for series with terms of the same sign (see sumalt and sumpos below).

matrix(m,n,X,Y,expr)

creation of the m\times n matrix whose coefficients are given by the expression expr. There are two formal parameters in expr, the first one (X) corresponding to the rows, the second (Y) to the columns, and X goes from 1 to m, Y goes from 1 to n.

The library syntax is matrice(entree *ep1, entree *ep2, GEN nlig, GEN ncol, char *ch).

prod(x,X=a,b,expr)

product of expression expr, initialized at x, the formal parameter X going from a to b. As for sum, the initialization parameter x must be given: its main purpose is to force the type of the operations being performed. For example if it is put equal to the integer 1, operations will start being done exactly. If it is put equal to the real 1., they will be done using real numbers having the default precision. If it is put equal to the power series 1+O(X^k) for a certain k, they will be done using power series of precision at most k. These are the three most common initializations.

As an extreme example, compare prod(1,j=1,100,(1-X^j)) with prod(1+O(X^101),j=1, 100, (1-X^j) ).

The library syntax is produit(entree *ep, GEN x, GEN a, GEN b, char *ch).

prodeuler(X=a,b,expr)

product of expression expr, initialized at 1., the formal parameter X ranging over the prime numbers between a and b.

The library syntax is prodeuler(entree *ep, GEN a, GEN b, char *ch, long int prec).

prodinf(X=a,expr)

infinite product of expression expr, the formal parameter X starting at a. The evaluation stops when the relative error of the expression minus 1 is less than the default precision. The expressions must always evaluate to an element of C.

The library syntax is prodinf(entree *ep, GEN a, char *ch, long int prec).

prodinf1(X=a,expr)

infinite product of expression 1+expr, the formal parameter X starting at a. The evaluation stops when the relative error of the expression is less than the default precision. The expressions must always evaluate to an element of C.

The library syntax is prodinf1(entree *ep, GEN a, char *ch, long int prec).

solve(X=a,b,expr)

real root of expression expr between a and b, under the condition expr(X=a)*expr(X=b)<=0. The method used is Brent's method.

The library syntax is zbrent(entree *ep, GEN a, GEN b, char *ch, long int prec).

sum(x,X=a,b,expr)

sum of expression expr, initialized at x, the formal parameter going from a to b. As for prod, the initialization parameter x must be given: its main purpose is to force the type of the operations being performed. For example, if it is put equal to the integer 0, then operations will start being done exactly. If it is put equal to the real 0., then they will be done using real numbers having the default precision. If it is put equal to the power series O(X^k) for a certain k, then they will be done using power series of precision at most k. These are the three most common initializations.

As an extreme example, compare sum(0,j=1, 1000, 1/j) with sum(0.,j=1, 1000, 1/j ).

The library syntax is somme(entree *ep, GEN x, GEN a, GEN b, char *ch).

sumalt(X=a, expr)

numerical summation of the series expr, which should be an alternating series, the formal variable X starting at a. The algorithm used is an algorithm of F. Villegas as modified by D. Zagier, and is much better than sumalt2() below which was used formerly. Beware that the stopping criterion is that the term gets small enough, hence terms which are equal to 0 will create problems and should be removed.

Divergent alternating series can sometimes be summed by this method, as well as series which are not exactly alternating (see for example section 11).

The library syntax is sumalt(entree *ep, GEN a, char *ch, long int prec).

sumalt2(X=a, expr)

numerical summation of the series expr, which should be an alternating series, the formal variable X starting at a. The algorithm used is Euler's method of finite differences combined with a trick due to van Wijngaarden. Beware that the stopping criterion is that the term gets small enough, hence terms which are equal to 0 will create problems and should be removed.

Divergent alternating series can sometimes be summed by this method, as well as series which are not exactly alternating (see for example section 11).

The library syntax is sumalt2(entree *ep, GEN a, char *ch, long int prec).

suminf(X=a,expr)

infinite sum of expression expr, the formal parameter X starting at a. The evaluation stops when the relative error of the expression is less than the default precision. The expressions must always evaluate to an element of C.

The library syntax is suminf(entree *ep, GEN a, char *ch, long int prec).

sumpos(X=a,expr)

numerical summation of the series expr, which must be a series of terms having the same sign, the formal variable X starting at a. The algorithm used is van Wijngaarden's trick for converting such a series into an alternating one, and is quite slow. Beware that the stopping criterion is that the term gets small enough, hence terms which are equal to 0 will create problems and should be removed.

The library syntax is sumpos(entree *ep, GEN a, char *ch, long int prec).

vector(n,X,expr)

creates a row vector with n components whose components are the expression expr evaluated at the integral points between 1 and n (identical with hvector).

The library syntax is vecteur(entree *ep, GEN nmax, char *ch).

vvector(n,X,expr)

creates a column vector with n components whose components are the expression expr evaluated at the integral points between 1 and n.

The library syntax is vvecteur(entree *ep, GEN nmax, char *ch).

Plotting functions.

Although plotting is not the main purpose of PARI, a number of plotting functions are provided. These functions are either high-level plotting functions (all the functions starting with plot) in which the user has little to do but explain what type of plot he wants, and whose syntax is similar to the one used in the preceding section. Or they can be low-level plotting functions, where every drawing primitive (point, line, box, etc...) must be specified by the user. These low-level functions (called rectplot functions) work as follows. You have at your disposal 16 virtual windows which are filled independently, and can then be physically ORed on a single window at user-defined positions. These rectwindows are numbered from 0 to 15, and must be initialized before being used by the function initrect, which specifies the height and width of the virtual window. At all times, a virtual cursor (initialized at [0,0]) is associated to the window, and its current value can be obtained using the function cursor.

A number of primitive graphic objects can then be drawn in these windows, and only the part of the object which is inside the window will be drawn, with the exception of polygons and strings which are drawn entirely (but the virtual cursor can move outside of the window). Finally, the actual physical drawing is done using the function draw. Note that the windows are preserved so that further drawings using the same windows at different positions or different windows can be done without extra work. If you want to erase a window (and free the corresponding memory), use the function killrect. It is not possible to partially erase a window. Erase it completely, initialize it again and then fill it with the graphic objects that you want to keep.

In addition to initializing the window, you may want to have a scaled window to avoid unnecessary conversions. For this, use the function scale below. As long as this function is not called, the scaling is simply the number of pixels, the origin being at the upper left and the y-coordinates going downwards.

Finally, note that in the same way that texprint allows you to have a TeX output corresponding to printed results, the functions starting with post allow you to have postscript output of the plots. This will not be absolutely identical with the screen output, but will be sufficiently close. Note that you can use postscript output even if you do not have the plotting routines enabled. The postscript output is written in a file called pari.ps. Each time a new postscript output is asked for the postscript output is appended to that file. Hence the user must remove this file first if he does not want unnecessary drawings from preceding sessions to appear. On the other hand, in this manner as many plots as desired can be kept in a single file.

box(w,x2,y2)

let (x1,y1) be the current position of the virtual cursor. Draw in the rectwindow w the outline of the rectangle which is such that the points (x1,y1) and (x2,y2) are opposite corners. Only the part of the rectangle which is in w is drawn. The virtual cursor does not move.

The library syntax is rectbox(w,x2,y2) where w is a C-long integer.

cursor(w)

give as a 2-component vector the current (scaled) position of the virtual cursor corresponding to the rectwindow w.

The library syntax is rectcursor(w) where w is a C-long integer.

draw(list)

physically draw the rectwindows given in list which must be a vector whose number of components is divisible by 3. If list=[w1,x1,y1,w2,x2,y2,...], the windows w1, w2, etc... are physically placed with their upper left corner at physical position (x1,y1), (x2,y2), ... respectively, and are then drawn together. Overlapping regions will thus be drawn twice, and the windows are considered transparent.

The library syntax is rectdraw(list).

Note that in the present version 1.39.03.01{} this function has been written for the X11-window system (hence also for GUI's based on X11 such as Openwindows and Motif), Gnuplot output, and for Sunview/Suntools.

initrect(w,x,y)

initialize the rectwindow w to width x and height y, and position the virtual cursor at (0,0).

The library syntax is initrect(w,x,y) where all 3 arguments are C-long integers.

killrect(w)

erase rectwindow w and free the corresponding memory. Note that if you want to use the rectwindow w again, you must use initrect first to specify the new size.

The library syntax is killrect(w) where w is a C-long integer.

line(w,x2,y2)

let (x1,y1) be the position of the virtual cursor. Draw in the rectwindow w the part of the segment (x1,y1)-(x2,y2) which is inside w, and move the virtual cursor to (x2,y2) (even if it is outside the window). If you want to draw a line from (x1,y1) to (x2,y2) where (x1,y1) is not necessarily the position of the virtual cursor, use move(w,x1,y1) before using the line function.

The library syntax is rectline(w,x2,y2) where w is a C-long integer.

lines(w,listx,listy)

draw on the rectwindow w the polygon such that the (x,y)-coordinates of the vertices are in the vectors of equal length listx and listy. The virtual cursor does not move. This is basically the same function as the function ploth2, but with no scaling factors. Note that to obtain a closed polygon, the first and last point must be the same. Finally, for simplicity, the whole polygon is drawn, not only the part of the polygon which is inside the rectwindow.

The library syntax is rectlines(w,listx,listy) where w is a C-long integer.

move(w,x,y)

move the virtual cursor of the rectwindow w to position (x,y).

The library syntax is rectmove(w,x,y) where w is a C-long integer.

plot(X=a, b, expr)

crude plot of the function represented by expression expr from a to b.

The library syntax is plot(entree *ep, GEN a, GEN b, char *ch).

ploth(X=a,b,expr)

high precision plot of the function y=f(x) represented by the expression expr, x going from a to b. Since this involves around 1000 function calls, it is advised to keep the current precision to a minimum (i.e. 9) before calling ploth.

Note that in the present version 1.39.03.01{} this function has been written for the Macintosh, the X11-window system (hence also for GUI's based on X11 such as Openwindows and Motif), Gnuplot output, and for Sunview/Suntools. An Atari/gem version is also available upon request.

The library syntax is ploth(entree *ep, GEN a, GEN b, char *ch, long int prec).

plothmult(X=a,b,[expr1,expr2,...])

high precision plots of the functions y=f_i(x) represented by the expressions expr_i, x going from a to b. Since this involves around 1000 function calls times the number of functions, it is advised to keep the current precision to a minimum (i.e. 9) before calling ploth.

Note that in the present version 1.39.03.01{} this function has been written only for the X11-window system (hence also for GUI's based on X11 such as Openwindows and Motif), and Gnuplot output.

The library syntax is plothmult(entree *ep, GEN a, GEN b, char *ch, long int prec).

ploth2(T=a,b,expr)

high precision plot of the curve represented in parametric form by x=f(t),y=g(t), represented by the expression expr, t going from a to b. The expression must be a two-component vector. Since this involves around 2000 function calls, it is advised to keep the current precision to a minimum (i.e. 9) before calling ploth2.

Note that in the present version 1.39.03.01{} this function has been written for the Macintosh, the X11-window system (hence also for GUI's based on X11 such as Openwindows and Motif), Gnuplot output, and for Sunview/Suntools. An Atari/gem version is also available upon request.

The library syntax is ploth2(entree *ep, GEN a, GEN b, char *ch, long int prec).

plothraw(listx,listy)

high precision plot of the points whose (x,y)-coordinates are in the vectors of equal length listx and listy. Automatic positioning and scaling is done, but with the same scaling factor on x and y.

The library syntax is plothraw(listx,listy).

Note that in the present version 1.39.03.01{} this function has been written for the X11-window system (hence also for GUI's based on X11 such as Openwindows and Motif), Gnuplot output, and for Sunview/Suntools.

plothrawlines(listx,listy)

high precision plot of a broken line. The (x,y)-coordinates of the nodes are in the vectors of equal length listx and listy. Automatic positioning and scaling is done, but with the same scaling factor on x and y.

The library syntax is plothrawlines(listx,listy).

Note that in the present version 1.39.03.01{} this function has been written for the X11-window system (hence also for GUI's based on X11 such as Openwindows and Motif), Gnuplot output, and for Sunview/Suntools.

point(w,x,y)

draw the point (x,y) on the rectwindow w (if it is inside w), and in any case move the virtual cursor to position (x,y).

The library syntax is rectpoint(w,x,y) where w is a C-long integer.

points(w,listx,listy)

draw on the rectwindow w the points whose (x,y)-coordinates are in the vectors of equal length listx and listy and which are inside w. The virtual cursor does not move. This is basically the same function as the function plothraw, but either with no scaling factor or with a scale chosen using the function scale.

The library syntax is rectpoints(w,listx,listy) where w is a C-long integer.

postdraw(list)

same as draw, except that the output is a postscript program appended to the file pari.ps.

The library syntax is postdraw(list).

postploth(X=a,b,expr)

same as ploth, except that the output is a postscript program appended to the file pari.ps.

The library syntax is postploth(entree *ep, GEN a, GEN b, char *ch).

postploth2(T=a,b,expr)

same as ploth2, except that the output is a postscript program appended to the file pari.ps.

The library syntax is postploth2(entree *ep, GEN a, GEN b, char *ch).

postplothraw(listx,listy)

same as plothraw, except that the output is a postscript program appended to the file pari.ps.

The library syntax is postplothraw(listx,listy).

rbox(w,dx,dy)

draw in the rectwindow w the outline of the rectangle which is such that the points (x1,y1) and (x1+dx,y1+dy) are opposite corners, where (x1,y1) is the current position of the cursor. Only the part of the rectangle which is in w is drawn. The virtual cursor does not move.

The library syntax is rectrbox(w,dx,dy) where w is a C-long integer.

rcopy(sourcew,destw,dx,dy)

Copy the contents of the rectwindow sourcew into the rectwindow destw with offsets (dx,dy).

The library syntax is rectcopy(sourcew,destw,dx,dy) where sourcew, destw are C-long integers.

rline(w,dx,dy)

draw in the rectwindow w the part of the segment (x1,y1)-(x1+dx,y1+dy) which is inside w, where (x1,y1) is the current position of the virtual cursor, and move the virtual cursor to (x1+dx,y1+dy) (even if it is outside the window).

The library syntax is rectrline(w,dx,dy) where w is a C-long integer.

rlines(w,xs,ys)

draw a broken line on the rectwindow w. xs is the vector of first coordinates of nodes, ys is the vector of second coordinates of nodes.

The library syntax is rectpoints(w,xs,ys) where w is a C-long integer.

rlinetype(w,t)

set visual representation of lines in the rectwindow w. Supported on some terminal types only. Type -2 is used by internal PARI functions to draw frames, -1 for axes, >=0 for the rest.

The library syntax is rectlinetype(w,t) where w, t are C-long integers.

rmove(w,dx,dy)

move the virtual cursor of the rectwindow w to position (x1+dx,y1+dy), where (x1,y1) is the initial position of the cursor (i.e. to position (dx,dy) relative to the initial cursor).

The library syntax is rectrmove(w,dx,dy) where w is a C-long integer.

rploth(w,X=a,b,expr,flag,npoints)

high precision plot of the function(s) y=f(x) represented by the expression expr, x going from a to b. Plot is put into rectangle w. Since this involves 1000s function calls, it is advised to keep the current precision to a minimum (i.e. 9) before calling rploth.

To plot single rectangular-coordinate graph expr should return a scalar. For parametric plot expr should return a vector of length 2n, n being the number of graphs. Otherwise expr should return a vector of length equal to the number of graphs created.

Binary digits of flag denote: 1 PARAMETRIC, 2 SINGLE, 8 NO_AXE_X, 16 NO_AXE_Y, 32 NO_FRAME, 64 POINTS. npoints specifies number of reference points on the graph. If numpoints is 0, maximal possible number of points is chosen.

Returns a vector for bounding box. As a side effect rectwindow is rescaled.

Note that in the present version 1.39.03.01{} this function has been written for the Macintosh, the X11-window system (hence also for GUI's based on X11 such as Openwindows and Motif), Gnuplot output, and for Sunview/Suntools. An Atari/gem version is also available upon request.

The library syntax is recplothmultin(long w, entree *ep, GEN a, GEN b, char *ch, long int prec, uLong flags, long testpoints).

rplothraw(w,frame,data,flag)

plot graph(s) for data in rectwindow w, frame is a vector with xmin, xmax, ymin, ymax as components, data is a vector of vectors. If the plot is parametric, the length of data should be even, and pairs of entries parametrize curves to plot. If not parametric, first entry gives x-coordinate, rest are y-coordinates for curves.

Binary digits of flag denote: 1 PARAMETRIC, 8 NO_AXE_X, 16 NO_AXE_Y, 32 NO_FRAME, 64 POINTS. npoints specifies number of reference points on the graph. If npoints is 0, maximal possible number of points is chosen.

Returns a vector for bounding box. As a side effect rectwindow is rescaled.

Note that in the present version 1.39.03.01{} this function has been written for the Macintosh, the X11-window system (hence also for GUI's based on X11 such as Openwindows and Motif), Gnuplot output, and for Sunview/Suntools. An Atari/gem version is also available upon request.

The library syntax is recplothraw(long drawrect, GEN frame, GEN data, long flags, long prec).

rpoint(w,dx,dy)

draw the point (x1+dx,y1+dy) on the rectwindow w (if it is inside w), where (x1,y1) is the current position of the cursor, and in any case move the virtual cursor to position (x1+dx,y1+dy).

The library syntax is rectrpoint(w,dx,dy) where w is a C-long integer.

rpoints(w,xs,ys)

draw the points on the rectwindow w. xs is the vector of first coordinates, ys is the vector of second coordinates. Points which do not fit into rectangle are not put.

The library syntax is rectpoints(w,xs,ys) where w is a C-long integer.

rpointtype(w,t)

set visual representation (picture/color) of points in the rectwindow w. Supported on some terminal types only. Type -1 is represented by a point, positive type give something else.

The library syntax is rectpointtype(w,t) where w, t are C-long integers.

scale(w,x1,x2,y1,y2)

scale the local coordinates of the rectwindow w so that x goes from x1 to x2 and y goes from y1 to y2 (x2<x1 and y2<y1 being allowed). Initially, after the initialization of the rectwindow w using the function initrect, the default scaling is the graphic pixel count, and in particular the y axis is oriented downwards since the origin is at the upper left. The function scale allows to change all these defaults and should be used whenever functions are graphed.

The library syntax is rectscale(w,x1,x2,y1,y2) where w is a C-long integer.

string(w,x)

draw on the rectwindow w at the current position of the cursor the string corresponding to x. x can either be a string enclosed in quotes ( " ), or x can be a number which can be converted into a real number. In that case it is printed in the format 9.3lf, i.e. 9 characters before the decimal point, and 3 after.

The library syntax is rectstring(w,x) where w is a C-long integer and x is a GEN which either represents a vector of ASCII values, or can be converted into a real number.

Programming under GP and user-defined functions.

Variables and symbolic expressions.

In GP you can use up to 256 variable names (up to 65536 on 64-bit machines). These names can be any standard identifier names, i.e. they must start with a letter and contain only alphanumeric characters. To avoid confusion with other symbols, you must not use non-alphanumeric symbols like '_', 'dollar', or '.'. In addition to the function names which you must not use (see the list with \c) there are exactly three special variable names which you are not allowed to use: pi and euler, which represent well known constants, but also i which is always equal to the square root of -1.

Since usually you are not going to use the variable name pi for anything else but the number pi, and similarly for euler, these two will not create any problems. On the other hand, you will have to get used to calling a loop control variable with a name different from i. We realize that this may initially be the cause for some confusion, but we do not have any replacement symbol for the square root of -1.

Now the main thing to understand is that PARI/GP is not a symbolic manipulation package, although it shares some of the functionalities. One of the main consequences of this fact is that all expressions are evaluated as soon as they are written, they never stay in a purely abstract form. As an important example, consider what happens when you use a variable name before assigning a value into it. This is perfectly acceptable to GP, who considers this variable in fact as a polynomial of degree 1, with coefficients 1 in degree 1, 0 in degree 0, whose variable is the variable name you used.

If later you assign a value to that variable, the objects which you have created before will still be considered as polynomials. If you want to obtain their value, use the function eval (see section 7 above).

Another consequence is that the variables are numbered in the order that they appear, and the main variable of an expression is always the lowest numbered variable. Hence if you are working with expressions involving several variables and want to have them ordered in a specific manner in the internal representation, the simplest is just to write down the variables one after the other under GP before starting any real computations. If you already have started working and want to change the names of the variables in an object, use the function changevar (see section 2). If you only want to have them ordered when the result is printed, you can also use the function reorder (see below).

Finally, note that if x is a vector, you can assign a result to x[m] (i.e. write something like x[k]=expr). If x is a matrix, you can assign a result to x[m,n], but not to x[m], which is a vector. If you want to assign an expression to the m-th column of a matrix x, use x[,m]=expr instead. Similarly, use x[m,]=expr to assign an expression to the m-th row of x.

% compactarrays(num)=Changes algorithm for assignments to elements of % arrays and matrices. If 0: assignment of a shorter value will leave a % hole speeding up processing. The hole survives until the next operation % with the whole array. % Returns old value.

Expressions and expression sequences.

An expression is formed by combining the GP operators, functions (including user-defined functions) and control statements. It may be preceded by an assignment statement '=' into a variable. It always has a value, which can be any PARI object.

Several expressions can be combined on a single line by separating them with semicolons (';') and also with colons (':') for those who are used to BASIC. Such an expression sequence will be called simply a seq. A seq also has a value, which is the value of the last non-empty expression in the sequence. Under GP, the value of the seq is always put on the stack (i.e. it will become the next object %n), and only that value. The values of the other expressions in the seq are discarded after the execution of the seq is complete, except of course if they were assigned into variables. In addition, the value of the seq (or of course of an expression if there is only one) is printed if the line does not end with a semicolon (';').

Control statements.

A number of control statements are available under GP. They are simpler and have a slightly different syntax than their C counterparts, but are quite powerful enough to write any kind of program. Some of them are specific to GP, since they are made for number theorists. They are as follows. As usual, X will denote any simple variable name, and seq will always denote a sequence of expressions, including the empty sequence.

for(X=a,b,seq)

the formal variable X going from a to b, the seq is evaluated. Nothing is done if a>b. a and b must be in R.

fordiv(n,X,seq)

the formal variable X ranging through the positive divisors of n, the sequence seq is evaluated. n must be of type integer.

forprime(X=a,b,seq)

the formal variable X ranging over the prime numbers between a to b (including a and b if they are prime), the seq is evaluated. Nothing is done if a>b. Note that a and b must be in R.

forstep(X=a,b,s,seq)

the formal variable X going from a to b, in increments of s, the seq is evaluated. Nothing is done if s>0 and a>b or if s<0 and a<b. a, b and s must be in R, and s must be non-zero.

forvec(X=v,seq)

v being an n-component vector (where n is arbitrary) of two-component vectors [a_i,b_i] for 1<= i<= n, the seq is evaluated with the formal variable x[1] going from a_1 to b_1,...,x[n] going from a_n to b_n. The formal variable with the highest index moves the fastest.

goto(a)

a being an integer between 0 and 99, go to the position in the seq referred to by label a. This can be either a forward skip or a backwards skip. In case of multiple labels, control is transferred in the following manner. If one such label is to the left of the goto instruction, control is transferred to the rightmost one among those which are to the left. Otherwise, control is transferred to the rightmost label with a given number. In any case, multiple labels in a given seq should be avoided.

Also, good programming practice implies that the goto instruction should be used only in special cases, such as getting out of a deeply nested set of control instructions in one step. In fact, in the present version 1.39.03.01, the goto instruction almost always leads to syntax errors hence should be avoided, except as a means to stop a program catastrophically without getting out of GP. This may be corrected in a future release.

Note that usually it is possible to use the goto instruction with an a which is not an absolute constant, but may vary in the seq ("computed goto").

if(a,seq1,seq2)

if a is non-zero, the expression sequence seq1 is evaluated, otherwise the expression seq2 is evaluated. Of course, seq1 or seq2 may be empty, but the syntax must stay the same: if(a,seq,) evaluates seq if a is not equal to zero, does nothing otherwise; if(a,,seq) evaluates seq if a is equal to zero, does nothing otherwise.

label(a)

a being an integer between 0 and 99, label this position as label number a for use by the goto instruction. Labels are specific to a given seq.

until(a,seq)

evaluate expression sequence seq until a is not equal to 0 (i.e. until a is true). If a is initially not equal to 0, seq is evaluated once (more generally, the condition on a is tested after execution of the seq, not before as in while).

while(a,seq)

while a is non-zero evaluate the expression sequence seq. The test is made before evaluating the seq, hence in particular if a is initially equal to zero the seq will not be evaluated at all.

Specific functions used in GP programming.

In addition to the general PARI functions, it is necessary to have some functions which will be of use specifically for GP. They are as follows:

addhelp(symbol,string)

Associate help string ``string'' to the symbol symbol.

If the help string starts as ``symbol(arg1,arg2,...)'', the arguments may be used for completion of function names in interactive mode.

kill(x)

kills the present value of the variable or user-defined function x. After kill of a variable, since the variable does not have a value, as has been explained above it is again considered as a monic polynomial of degree 1 with no constant term.

For the following four printing functions, list represents a list (separated by commas) either of PARI objects or of character strings between double quotes '"', which are always printed as they are.

pprint(list)

output list in prettyprint (beautified) format, ending with a newline.

pprint1(list)

output list in prettyprint (beautified) format, without ending with a newline.

print(list)

output list in raw format, ending with a newline.

print1(list)

output list in raw format, without ending with a newline.

read()

reads a string, interpreted as a GP expression, from the input file, usually standard input (i.e. the keyboard). If a sequence of expressions is given, the result is the result of the last expression of the sequence. When using this instruction, it is useful to prompt for the string by using the print1 function. Note that in the present version 2.12 of pari.el, when using GP under gnuemacs (see section 11) one must prompt for the string, with a string which ends with the same prompt as the current one (usually a '?').

reorder(x)

x must be a vector. If x is the empty vector, this gives the vector whose components are the existing variables in increasing order (i.e. in decreasing importance). If x is non-empty, it must be a permutation of variable names, and this permutation gives a new order of importance of the variables. For example, if the existing order is [x,y,z], then after reorder([z,x]) the order of importance of the variables will be [z,y,x].

texprint(list)

outputs list in TeX format. This output can then be used in a TeX manuscript.

Warning: in the present version 1.39.03.01, the printing is done on the standard output, hence to be able to get the output into a file, you must be either in an emacs session or shell (see section 11), in a windowing system (which enables you to grab the output with the mouse), under a UNIX script command, or with the logfile enabled (see the command \l). This will be improved.

User defined functions.

It is very easy to define a new function under GP, which can then be used like any other function. The syntax is as follows:

name(list of true formal variables, list of local variables)=seq

where name is the name that you want to give to your function (same syntactic restrictions as for variable names). list of true formal variables is the list of variables corresponding to those which you will actually use when calling your function, the variables being separated by commas, and the list being allowed to be empty. list of local variables is the list of the additional local variables which you will use in the definition of the function. If you omit some or all of these local variable declarations, the function will probably still work, but the non-declared variables will become global, hence known outside of the function, and this may have undesirable side-effects. On the other hand, in some cases it may also be what you want. Finally, as usual seq is any expression sequence.

Once the function is defined using the above syntax, you can use it like any other function. In addition, you can also recall its definition exactly as you do for predefined functions, that is by writing ?name. One small difference with predefined functions is that you can never redefine such a function, while you can redefine a user-defined function as many times as you want, without using the kill instruction.

In a given session you can give any identifier name to a function, except those of predefined functions (of course) but also those of any variables that have been used, even if they have been killed. On the other hand, if you want to use as a variable name the name of a user-defined function, it is enough (and necessary) to kill this function name first.

An amusing example of a user-defined function is the following. It is intended to illustrate both the use of user-defined functions and the power of the sumalt function. Although since version 1.34 the Riemann zeta-function is included in the standard functions, let us assume that this is not the case (or that we want another implementation). One way to define it, which is probably the simplest (but certainly not the most efficient), is as follows:

zet(s,j)=sumalt(j=1,(-1)^(j-1)*j^(-s))/(1-2^(1-s))

Then this gives reasonably good accuracy and speed as long as you are not too far from the domain of convergence. Try it for s integral between -5 and 5, say, or for s=0.5+i*t where t=14.134... Of course, the call to the function is done by zet(s), the variable j must not be given.

Special editing characters.

A GP program can of course have more than one line. Since GP executes your commands as soon as you have finished typing them, there must be a way to tell it to wait for the next line or lines of input before doing anything. There are two ways of doing this.

The first one is simply to use the backslash character '\' at the end of the line that you are typing, just before hitting <return>. This tells GP that what you will write on the next line is the physical continuation of what you have just written. In other words, it makes GP forget your newline character. For example if you use this while defining a function, and if you ask for the definition of the function using ?name, you will see that your backslash has disappeared and that everything is on the same line. You can type a \ anywhere. It will be interpreted as above only if it is immediately followed by a newline. For example, you can type

3+\

4

instead of typing 3+4.

The second one cannot be used everywhere, but is in general more useful. It is the use of braces `{' and `}'. When GP sees an opening brace (`{') at the beginning of a line, it understands that you are writing a program, and newlines will be ignored (but registered, contrary to when you use a backslash) until you type a closing brace `}'. However, there is an important (but easily obeyed) restriction: inside an open brace-close brace pair, all newlines must occur after a semicolon (';'), i.e. between two expressions forming a seq.

Of course you can combine the use of backslash and braces.

The GP/PARI programming language.

As we have seen, the GP calculator uses a primitive purely interpreted language. The structure of this language is in fact more reminiscent of LISP with a functional notation, f(x,y) rather than (f x y): all programming constructs, such as if, while, etc... are functions, and the main loop does not really execute, but rather evaluates (sequences of) expressions.

Of course, it is by no means a true LISP. Function names are distinct from variable names: once a name has been used as a variable name, this cannot be changed in the same session. Predefined function names cannot be used for anything else, and the number of actual parameters must match the declaration given in the online help. Identifiers that are used for user-defined functions can be freely redefined for other functions, or totally forgotten (using kill) and later reused for a variable, for example.

Each variable has a stack of values, implemented as a linked list. When a new scope is entered, during a function call, the value of the actual parameter is pushed on the stack. If the parameter is not supplied, a special 0 value called gnil is pushed on the stack (this value is not printed if it is returned as the result of a GP expression sequence). Upon exit, the stack decreases. You can kill a variable, decreasing the stack yourself. This should be used only at the top level of GP, to undo the effect of an assignment, not from a function. However, the stack has a bottom: the value of a variable is the monomial of degree 1 in this variable, as is natural for a mathematician.

Note that the iterative constructs which use a variable name (for, fordiv, forprime, prod, sum, vector, matrix, plot, etc.) also consider the given variable to be local to the construct. A value is pushed on entry and pulled on exit. So, it is not necessary for a function using such a construct to declare the variable as a dummy formal parameter. In particular, in our zet example above, the variable j need not be declared.

Otherwise, it is strongly recommended to declare in this way all other variables that are used inside a function: If a function accesses a variable which is not one of its formal parameters, the value used will be the one which happens to be on top of the stack at the time of the call. This could be a ``global'' value, or a local value belonging to any function higher in the call chain. So, be warned.

Implementation note. For the curious reader, here is how these stacks are handled: a hashing function is computed from the identifier, and used as an index in hashtable, a table of pointers. Each of these pointers begins a linked list of structures (type entree). The linked list is searched linearly for the identifier (each list will have less than 7 components or so). When the correct entree is found, it points to the top of the stack of values for that identifier if it is a variable, to the function itself if it is a predefined function, and to a copy of the text of the function if it is a user-defined function. When an error occurs, all of this maze (rather a tree, in fact) is searched and (hopefully) replaced in the situation preceding the last call of the main evaluator.

Using GP under gnuemacs.

Thanks to the initial help of Annette Hoffman from the University of Saarbr\"ucken, but now since version 1.34.05 thanks to David Carlisle from the University of Manchester, it is possible and in fact desirable to use GP as a subprocess of gnuemacs. This is of course possible only if gnuemacs has been installed on your machine.

To use this, you must include in your .emacs file the following line:

(load "pari" nil t)

where pari.el is the name of the file that will have to be loaded by gnuemacs (if you have changed the name, or if you have the file in a different directory, you must of course supply the correct name). This file is included in the PARI distribution.

Once this is done, under gnuemacs if you type M-x gp (where as usual M is the Meta key, i.e. Escape, or on SUN keyboards, the Left key), a special shell will be started, which in particular launches GP with the default stack size, prime limit and input buffer size. If you type instead C-u M-x gp, you will be asked for the name of the GP executable, the stack size, the prime limit and the input buffer size before the execution of GP begins. If for any of these you simply type return, the default value will be used (on UNIX machines it will be /usr/local/bin/gp for the executable, 4000000 for the stack, 500000 for the prime limit and 30000 for the buffer size).

You can then work as usual under GP, but with two notable advantages. First and foremost, you have at your disposal all the facilities of a text editor like emacs, in particular for correcting or copying blocks. Second, you can have an on-line help which is much more complete than what you obtain by typing ?name. This is done by typing M-? (where M is the Meta key). In the minibuffer, emacs asks what function you want to describe, and after your reply you obtain the description which is in the users manual, including the description of functions (such as \, %) which use special symbols.

This help system can also be menu-driven, by using the command M-\char`\ c which opens a help menu window which enables you to choose the category of commands for which you want an explanation.

Finally you can use command completion in the following way. After the prompt, type the first few letters of the command, then M-TAB where TAB is the TAB key (of course not the letters T,A,B). If there exists a unique command starting with the letters you have typed, the command name will be completed. If not, either the list of commands starting with the letters you typed will be displayed in a separate window (which you can then kill by typing as usual C-x 1 or by typing in more letters), or ``no match found'' will be displayed in the Emacs command line.

You also have at your disposal a few other commands. Read the file pari.txt for details.

Note that if for some reason the session crashes (due to a bug in your program or in the PARI system), you will usually stay under emacs, but the GP buffer will be killed. To recover it, simply type again M-x gp (or C-u M-x gp), and a new session of GP will be started after the old one, so you can recover what you have typed. Note that this will of course not work if for some reason you exited emacs before coming back (except for the C-z temporary stopping command).

Remark. Thanks to Ilya Zakhharevitch, there is a possibility of command name completion outside of an emacs buffer by using the TAB character. This can also give very primitive help on the necessary syntax.

4 POD Errors

The following errors were encountered while parsing the POD:

Around line 6629:

'=item' outside of any '=over'

Around line 6732:

You forgot a '=back' before '=head2'

Around line 6739:

'=item' outside of any '=over'

Around line 6829:

You forgot a '=back' before '=head2'