\chapter{Functions and Operations available in PARI and GP}

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

\section{Standard monadic or dyadic operators.}

\subsec{$\pm$} $+x$ and $-x$ refer to monadic operators
($+x$ does nothing and $-x$ negates $x$).

The library syntax is $\teb{gneg}(x)$ for $-x$.

\subsec{$+$, $-$} $x+y$ and $x-y$ are the \ref{sum} and \ref{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 $\teb{gadd} ( x, y )$ for $x+y$, $\teb{gsub} ( x, y )$
for $x-y$.

\subsec{$*$} $x*y$ is the \ref{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 \ref{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 {\tt \~{}} or {\tt trans$(\,)$}, see 3.7.30).

The library syntax is $\teb{gmul} ( x, y )$ for $x*y$.

\subsec{$/$} $x/y$ is the \ref{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 {\sl
not\/} the euclidean quotient (see $x\backslash 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 \ref{taylor series} expansion of the quotient of two polynomials,
add $O(X\hat{\ }k)$ to the result or use the {\tt taylor} function (3.6.33).

The library syntax is $\teb{gdiv} ( x, y )$ for $x/y$.

\subsec{$\backslash$} $x\backslash y$ is the \ref{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 nonnegative.

The library syntax is $\teb{gdivent} ( x, y )$ for $x\backslash y$.

\subsec{$\%$} $x\%y$ is the \ref{euclidean remainder} of $x$ and $y$. The 
modulus $y$ must be of type integer or polynomial.
The result is the remainder, always nonnegative
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 $\teb{gmod} ( x, y )$ for $x\%y$.

\subsec{\ref{divres}}$( x, y )$ creates a 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 always nonnegative.

The library syntax is $\teb{gdiventres} ( x, y )$.

\subsec{$\hat{}$} $x\hat{\ }y$ is \ref{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 3.3.1.),
and in particular has the effect of componentwise powering on vector or
matrices.

The library syntax is $\teb{gpui} ( x, y )$ for $x\hat{\ }y$.

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

The standard boolean functions $|\,|$ (\ref{inclusive or}) and $\&\&$ (\ref{and}) \sref{or}are
also available, and the library syntax is $\teb{gor} ( x, y)$ and
$\teb{gand} (x, y)$ respectively. Note that to avoid confusion with the
factorial function, there is no $!$ (\ref{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 $\teb{gcmp} ( x, y )$ which gives
the sign (1, 0, or -1) of $x-y$, where $x$ and $y$ must be in $\Bbb R$,
and $\teb{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 $\teb{gcmp0} ( x )$ ($x=0$ ?), $\teb{gcmp1} ( x )$
($x=1$ ?), and \sref{gcmp\string\_1} {\bf gcmp\_1} $( x )$ ($x=-1$ ?).

Note that $\teb{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 $\teb{isexactzero}$.
\smallskip
GP accepts the following synonyms for some of the above functions:
since there is no bitwise {\tt and} or bitwise {\tt or}, $|$ and $\&$ are accepted as\sref{bitwise and} \sref{bitwise or}
synonyms of $|\,|$ and $\&\&$ respectively. Also, $<>$ is accepted as a
synonym for $!=$. On the other hand, $=$ is definitely {\sl not} a
synomym for $==$ since it is the assignment statement.

\subsec{sign}$( x )$: \ref{sign} of $x$, which must be of type
integer, real or fraction. The result (0, 1 or -1) is a C-integer.

The library syntax is $\teb{gsigne} ( x )$.

\subsec{\ref{max}}$( x, y )$ and {\bf \ref{min}}$( x, y )$ create the
maximum and minimum of $x$ and $y$ when they can be compared.

The library syntax is $\teb{gmax} ( x, y )$ and $\teb{gmin} ( x, y )$.

\subsectitle{Important remark.} In all the above library syntaxes, we have
given only the basic names of the functions. For example ${\tt gadd} ( x, y
)$
assumes that $x$ and $y$ are PARI objects (the GEN type) and {\sl 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:

$\teb{gaddgs} ( x, y )$: here $x$ is a GEN, $y$ is an ordinary 32-bit
integer.

$\teb{gaddsg} ( x, y )$: here $x$ is an ordinary 32-bit integer, $y$ is a
GEN.

$\teb{gaddz} ( x, y, z ),\ \teb{gaddgsz} ( x, y, z ),\ \teb{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 {\bf
g}, such
as gadd, one can replace the {\bf g} by an {\bf l} to obtain a {\bf long}
result instead
of a GEN (i.e. pointer to long) result. For instance $\teb{ladd} ( x, y )$ is
identical with $({\tt (long)gadd} ( x, y ) )$. These macros are written in
the files listed in {\tt \ref{gencom.h}}.

\section{Conversions and similar elementary functions}

Many of these 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.

\subsecref{binary}$(x)$: outputs the vector of the binary digits of $|x|$, where
$|x|<2^{32}$.

The library syntax is $\teb{binaire}(x)$.

\subsecref{bittest}$(x,n)$: outputs the $n^{\text{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 $\teb{bittest}(x,n)$ where $n$ as well as the result
are C-integers.

\subsec{\ref{ceil}}$( x )$: ceiling of $x$. When $x$ is in $\Bbb R$,
the result is the smallest integer greater than or equal to $x$.

The library syntax is $\teb{gceil} ( x )$.

\subsec{\ref{changevar}}$(x,y)$: change the variables in the object $x$
according to the permutation specified by the vector $y$.
For example, assume that the variables have been introduced in the
order {\tt x}, {\tt a}, {\tt b}, {\tt c}. Then,
if $y$ is the vector {\tt [x,c,a,b]}, the variable {\tt a} will be
replaced by {\tt c}, {\tt b} by {\tt a}, and {\tt a} by {\tt b}, {\tt x}
being unchanged. Note that the permutation must be completely
specified, e.g. {\tt [c,a,b]} would not work, since this would replace
{\tt x} by {\tt c}, and leave {\tt a} and {\tt b} unchanged.

The library syntax is $\teb{changevar}(x,y)$.

\subsec{\ref{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 $\teb{compo}(x,n)$ which extracts
the $n^{\text{th}}$-component of $x$. This is to be understood
as follows: every PARI type has one or two initial \ref{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^{\text{th}}$-component of $x$, if $x$ is a matrix, the $n^{\text{th}}$
column,
if $x$ is a polynomial, the $n^{\text{th}}$ coefficient (i.e. of degree
$n-1$),
and for power series, the $n^{\text{th}}$ significant coefficient. The use
of the function {\tt compo} implies the knowledge of the structure of the
different PARI types, which can be recalled by typing $\backslash$t under GP.

The library syntax is $\teb{compo} ( x, n )$, where $n$ is a 32-bit C-integer.

The two other methods are more natural but more restricted. First, the
function $\teb{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 
{\tt reorder}, see 3.9.4.6). 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 {\tt 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 {\tt compo}.

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

The library syntax is $\teb{truecoeff} (x,n)$.

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

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

\subsecref{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.

The library syntax is $\teb{gconj} ( x )$.

\subsecref{cvtoi}$( x )$: If $x$ is in $\Bbb 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 $\teb{gcvtoi} ( x, \& e )$ where $e$ is a 32-bit
C-integer.

\subsecref{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 $\teb{denom}(x)$.

\subsecref{floor}$( x )$: floor of $x$. When $x$ is in $\Bbb R$,
the result is the largest integer smaller than or equal to $x$.

The library syntax is $\teb{gfloor} ( x )$.

\subsecref{frac}$( x )$: fractional part of $x$. Identical to
$x-\text{floor} ( x )$. If $x$ is real, the result is in $[0,1[$.

The library syntax is $\teb{gfrac} ( x )$.

\subsecref{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 $\teb{gimag} ( x )$.

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

The library syntax is $\teb{glength}(x)$.

\subsecref{lift}$(x)$: lifts an element $x=a \bmod n$ of $\Bbb Z/n\Bbb Z$ to
$a$ in $\Bbb 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 $\teb{lift}(x)$.

\subsecref{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 $\teb{gmodulcp} ( x, y )$. 

\subsecref{modp}$(x,y)$: same effect as {\tt 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 $\teb{gmodulo}(x,y)$.

\subsecref{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 3.2.15). Note that the norm of an element of
$\Bbb R$ is its square, so as to be compatible with the complex norm.

The library syntax is $\teb{gnorm} ( x )$.

\subsecref{norml2}$( x )$: square of the $L^2$-norm of $x$. $x$ must
be a (row or column) vector.

The library syntax is $\teb{gnorml2} ( x )$.

\subsecref{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 {\tt numer(x)} is
defined to be {\tt denom(x)*x}. All other types are forbidden.

The library syntax is $\teb{numer}(x)$.

\subsecref{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 {\tt trunc} (see 3.2.25), 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 {\sl not} a substitution function. It is intended to be quick and
dirty. So if you try {\tt poly(a,y)} on the polynomial {\tt a=x+y}, you will get
{\tt y+y}, which is not a valid PARI/GP object.

The library syntax is $\teb{gtopoly}(x,v)$, where $v$ is a variable number.

\subsecref{prec}$( x, n )$: $x$ being a PARI object and $n$ a 32-bit
C-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 {\sl 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 {\tt prec} never changes the type of the result. In
particular
it is not possible to use {\tt prec} to obtain a polynomial from a power series.
For that, see {\tt trunc} (3.2.25 below).

The library syntax is $\teb{gprec} ( x, n )$, where $n$ is a C-integer.

\subsecref{quadgen}$(x)$: creates the quadratic number \sref{omega}
$\omega=(a+\sqrt{x})/2$ where $a=0$ if $x\equiv0\mod4$, 
$a=1$ if $x\equiv1\mod4$, 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 $\teb{quadgen}(x)$.

\subsecref{quadpoly}$( x )$: creates the ``canonical'' quadratic
polynomial corresponding to the discriminant $x$, i.e. the minimal polynomial
of {\tt quadgen(x)}. $x$ must be an integer congruent to 0 or 1 modulo 4.

The library syntax is $\teb{quaddisc} ( x )$.

\subsecref{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 $\teb{greal} ( x )$.

\subsecref{rndtoi}$( x )$: same as {\tt cvtoi} (see 3.2.5) except
that truncation is replaced by rounding (see 3.2.23).

The library syntax is $\teb{grndtoi} ( x, \& e )$.

\subsecref{round}$( x )$: If $x$ is in $\Bbb 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 {\tt rndtoi} (3.2.22) to suppress this error handling.

Important remark: note that, contrary to the other truncation functions
(except {\tt rndtoi} which is essentially the same), this function operates
on every coefficient at every level of a PARI object. For example
$$\text{trunc}\left(\dfrac{2.4*X^2-1.7}{1.2*X}\right)=2.0*X,$$ while
$$\text{round}\left(\dfrac{2.4*X^2-1.7}{1.2*X}\right)=\dfrac{2*X^2-2}{X}.$$
An important use of {\tt 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 $\teb{ground} ( x )$.

\subsecref{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 {\tt precdl} (transparent under GP).
If $x$ is a polynomial, the precision is the greatest of {\tt 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 {\tt poly}, see 3.2.17 above).

The warning given for {\tt poly} applies here: this is not a substitution
function.

The library syntax is $\teb{gtoser}(x,v)$, where $v$ is a variable number.

\subsecref{setprecision}$(n)$: sets the current default precision equal to $n$
decimal digits if $n>0$. In any case, it returns the value of the current
default precision. Apart from the fact that it returns a value, this is
identical to the $\backslash$precision=$n$ command, with the difference that
it can be used inside any GP expression or program.

The library syntax is $\teb{setprecr}(n)$, where $n$ is a C-integer, as
is the returned value.

\subsecref{setserieslength}$(n)$: sets the current default series length equal
to $n$ if $n>0$. In any case, it returns the value of the current
default length. Apart from the fact that it returns a value, this is
identical to the $\backslash$serieslength=$n$ command, with the difference that
it can be used inside any GP expression or program.

The library syntax is $\teb{setserieslength}(n)$, where $n$ is a C-integer, as
is the returned value.

\subsecref{trunc}$( x )$: truncation of $x$. When $x$ is in $\Bbb 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 {\tt cvtoi} (3.2.5) to suppress this error
handling.

Note a very special use of {\tt 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 $\teb{gtrunc} ( x )$.

\subsecref{type}$(x)$: internal type number (from 1 to 19) of the pari object
$x$. This is useful only under GP.

The library syntax is $\teb{gtype}(x)$, but need not be used since the
internal function {\tt typ} is available. Note that {\tt gtype} gives a
GEN while {\tt typ} gives a C-integer.

\subsecref{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 divible 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 $\teb{ggval}(x)$.

\subsecref{vec}$(x)$: transform the object $x$ into a 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 $\teb{gtovec}(x)$.

\section{Transcendental functions.}

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

\quad 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 \ref{precision} held in the variable
{\bf prec}. Under GP this is transparent to the user, but when programming
in library mode, care must be taken to supply the parameter {\tt prec} as 
the last argument of the function if the first argument is an exact object
(see 1.2.5.), otherwise disaster will occur.

Then, the function is computed. Note that even if the argument is real, the
result may be complex (e.g. $\text{acos} ( 2.0 )$ or $\text{acosh} ( 0.0
)$).
Note also that the principal branch is always chosen.

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

\quad 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 {\bf \ref{precdl}}. Under GP this again is
transparent to the user. When programming in library mode, however, the
global variable {\tt precdl} must be set before calling the function
if the argument has an exact type (i.e. not a power series). Here {\tt 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.

\quad 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.35
(see Appendix C however),
will have a slightly different name if they are implemented some day.

\subsec{$\hat{}$} $x\hat{\ }y$: if $y$ is not of type integer, this 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.\sref{powering}

The library syntax is $\teb{gpui} ( x, y, prec )$.

\subsecref{abs}$( x )$: absolute value of $x$. Polynomials, power series
and rational functions are not allowed.

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

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

The library syntax is $\teb{gacos} ( x, prec )$.

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

The library syntax is $\teb{gach} ( x, prec )$.

\subsecref{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 $\teb{agm}(x,y,prec)$.

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

The library syntax is $\teb{gasin} ( x, prec )$.

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

The library syntax is $\teb{gash} ( x, prec )$.

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

The library syntax is $\teb{gatan} ( x, prec )$.

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

The library syntax is $\teb{gath} ( x, prec )$.

\subsecref{bernreal}$(x)$: Bernoulli number $B_x$, where $B_0=1$, $B_1=-1/2$,
$B_2=1/6$,\dots, expressed as a real number with the current precision.

The library syntax is $\teb{bernreal}(x,prec)$.

\subsecref{bernvec}$(x)$: creates a vector containing, as rational numbers, the
Bernoulli numbers $B_0$, $B_2$,\dots, $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:

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

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

The library syntax is $\teb{bernvec}(x)$.

\subsecref{cos}$( x )$: cosine of $x$.

The library syntax is $\teb{gcos} ( x, prec )$.

\subsecref{cosh}$( x )$: hyperbolic cosine of $x$.

The library syntax is $\teb{gch} ( x, prec )$.

\subsecref{dilog}$(x)$: principal branch of the dilogarithm of $x$, i.e.
analytic continuation of the power series $\log_2(x)=\sum_{n\ge1}x^n/n^2$.

The library syntax is $\teb{dilog}(x,prec)$.

\subsecref{eint1}$(x)$: exponential integral 
$\int_x^\infty \dfrac{e^{-t}}{t}\,dt$.

The library syntax is $\teb{eint1}(x,prec)$.

\subsecref{erfc}$(x)$: complementary error function
$(2/\sqrt\pi)\int_x^\infty e^{-t^2}\,dt$.

The library syntax is $\teb{erfc}(x,prec)$.

\subsecref{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^{2i\pi 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 $\teb{eta}(x,prec)$.

\subsecref{euler}: Euler's constant $0.57721\cdots$.

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

The library syntax is $\teb{mpeuler} ( prec )$ where $prec$ {\sl 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 {\bf \ref{geuler}} (with no parentheses) use instead $\teb{consteuler} ( prec
)$.

\subsecref{exp}$( x )$: exponential of $x$.
$p$-adic arguments with positive valuation are accepted.

The library syntax is $\teb{gexp} ( x, prec )$.

\subsecref{gamh}$( x )$: gamma function evaluated at the argument
$x+1/2$. When $x$ is an integer, this is much faster than using
$\text{gamma} ( x + 1/2 )$.

The library syntax is $\teb{ggamd} ( x, prec )$.

\subsecref{gamma}$( x )$: gamma function of $x$.

The library syntax is $\teb{ggamma} ( x, prec )$.

\subsecref{hyperu}$(a,b,x)$: U-confluent hypergeometric function with
parameters $a$ and $b$.

The library syntax is $\teb{hyperu}(a,b,x,prec)$.

\subsecref{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 $\teb{incgam}( x, y, prec )$.

Note: in addition, there exist also the functions
{\tt \ref{incgam1}, \ref{incgam2} {\rm and} \ref{incgam3}},
which are used for internal purposes. The only really useful one of the three
in addition to the standard {\tt incgam}, is the function {\bf incgam3}
which computes
$\int_0^y e^{-t}t^{x-1}\,dt$. when $y$ is not too large.

\subsecref{jbesselh}$(n,x)$: $J$-bessel function of half integral index.
More precisely, {\tt jbesselh(n,x)} computes $J_{n+1/2}(x)$ where $n$
must be of type integer, and $x$ is any element of $\Bbb C$. In the
present version 1.35, this function is not very accurate when $x$ is
small. This will be improved soon.

The library syntax is $\teb{jbesselh}(n,x,prec)$.

\subsecref{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 $\teb{jell}(x,prec)$.

\subsecref{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.35.

The library syntax is $\teb{kbessel} ( nu, x, prec )$.

Note: in addition, another implementation of this function which is often
faster than kbessel is the function {\bf \ref{kbessel2}}.

\subsecref{ln}$( x )$ or {\bf log}$( x )$:\sref{log} pricipal branch of the
natural logarithm of $x$, i.e. such that $\text{Im(ln}(x))\in ]-\pi,\pi]$.
The result is complex (with imaginary part equal to $\pi$) if 
$x\in \Bbb 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 $\pm1$ if $p=2$)
times a power of $p$.

The library syntax is $\teb{glog} ( x, prec )$.

\subsecref{lngamma}$( x )$: principal branch of the logarithm of the gamma
function of $x$. Can have much larger arguments than {\tt gamma} itself.

The library syntax is $\teb{glngamma}(x,prec)$.

\subsecref{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 {\tt log}.

The library syntax is $\teb{glogagm}(x,prec)$.

\subsecref{pi}: the constant pi ($3.14159\cdots$).

The library syntax is $\teb{mppi} ( prec )$ where $prec$ {\sl 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 {\bf \ref{gpi}} (with no parentheses) use instead $\teb{constpi} ( prec )$.

\subsecref{polylog}$(m,x)$: $m^\text{th}$ polylogarithm of $x$, i.e. analytic
continuation of the power series $\log_m(x)=\sum_{n\ge1}x^n/n^m$.

The library syntax is $\teb{polylog}(m,x,prec)$.

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

The library syntax is $\teb{polylogd}(m,x,prec)$.

\subsecref{polylogp}$(m,x)$: another modified $m^\text{th}$ polylogarithm
of $x$, called $P_m(x)$ in Zagier, defined for $|x|\le1$ by
$$\Re_m\left(\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\right)$$
and such that $P_m(m,1/x)=(-1)^{m-1}P_m(m,x)$, where $\Re_m$ denotes $\Re$
or $\Im$ depending whether $m$ is odd or even.

The library syntax is $\teb{polylogp}(m,x,prec)$.

\subsecref{psi}$( x )$: the $\psi$-function of $x$, i.e. the
logarithmic derivative $\Gamma'(x)/\Gamma(x)$.

The library syntax is $\teb{gpsi} ( x, prec )$.

\subsecref{sin}$( x )$: sine of $x$.

The library syntax is $\teb{gsin} ( x, prec )$.

\subsecref{sinh}$( x )$: hyperbolic sine of $x$.

The library syntax is $\teb{gsh} ( x, prec )$.

\subsecref{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\hat{\ }2$).

The library syntax is $\teb{gsqr} ( x )$.

\subsecref{sqrt}$( x )$: principal branch of the square root of $x$,
i.e. such that $\text{Arg(sqrt}(x))\in ]-\pi/2,\pi/2]$, or in other words
such that $\text{Re(sqrt}(x))>0$ or $\text{Re(sqrt}(x))=0$ and
$\text{Im(sqrt}(x))>=0$.
Integermod a prime and $p$-adics are allowed as arguments.
If $x\in \Bbb R$ and $x<0$ the result is complex with positive imaginary part.

The library syntax is $\teb{gsqrt} ( x, prec )$.

\subsecref{tan}$( x )$: tangent of $x$.

The library syntax is $\teb{gtan} ( x, prec )$.

\subsecref{tanh}$( x )$: hyperbolic tangent of $x$.

The library syntax is $\teb{gth} ( x, prec )$.

\subsecref{teich}$(x)$: teichmuller character of the $p$-adic number
$x$.

The library syntax is $\teb{teich}(x)$.

\subsecref{wf}$(x)$: Weber's $f$ function, i.e. such that
$j=(f^{24}-16)^3/f^{24}$.

The library syntax is $\teb{wf}(x,prec)$.

\subsecref{wf2}$(x)$: Weber's $f_2$ function, i.e. such that
$j=(f_2^{24}+16)^3/f_2^{24}$.

The library syntax is $\teb{wf2}(x,prec)$.

\subsecref{zeta}$(s)$: Riemann's zeta function $\zeta(s)=\sum_{n\ge1}n^{-s}$,
computed using the Euler-Maclaurin summation formula.

The library syntax is $\teb{gzeta}(s,prec)$.

\section{Arithmetic functions.}

These functions are by definition functions whose natural domain
of definition is either $\Bbb Z$ (or $\Bbb N$), 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.35 a primitive but useful version of the \ref{ECM}
method has been implemented. Also, numbers found to be pseudo-primes after
10 successful trials of the \ref{Rabin-Miller} test are declared primes.

\subsecref{bezout}$( x, y )$: finds $u$ and $v$ minimal in a
natural sense such that $x*u+y*v=\text{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 $\text{gcd} (x,y)$.

The library syntax is either $\teb{vecbezout} ( x, y )$ to get the
vector, or $\teb{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.

\subsecref{bigomega}$( x )$: number of prime
divisors of $x$ counted with multiplicity. $x$ must be an integer,
and the result is a 32-bit C-integer.

The library syntax is $\teb{bigomega} ( x )$.

\subsecref{bin}$( x, y )$: \ref{binomial coefficient} $\binom x y$.
Here $y$ must be an integer, but $x$ can be any PARI object.

The library syntax is $\teb{binome} ( x, y )$.

\subsecref{boundcf}$(x,lmax)$: creates the row vector whose components are
the partial quotients of the \ref{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 $\teb{gboundcf}( x,lmax)$, where $lmax$ is a C integer.

\subsecref{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 {\tt smallfact}. The remaining part is hence not
necessarily prime. 

The library syntax is $\teb{boundfact}(x,p)$.

\subsecref{cf}$( x )$: creates the row vector whose components are
the partial quotients of the \ref{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 $\teb{gcf} ( x )$.

\subsecref{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 {\tt 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 $\teb{gcf2}(b,x)$.

\subsecref{chinese}$( x, y )$: $x$ and $y$ being both integermods or
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.

The library syntax is $\teb{chinois} ( x, y )$.

\subsecref{classno}$( x )$: class number of the quadratic field of
discriminant $x$. In the present version 1.35, 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})$.

The library syntax is $\teb{classno} ( x )$.

There also exists the function {\tt \ref{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 {\tt \ref{classno3}} which computes the class
number of an imaginary quadratic field by counting reduced forms, a
$O(|x|)$ algorithm. See also 3.4.14 below.

\subsecref{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 $\teb{content}(x)$.

\subsecref{divisors}$(x)$: creates a row vector whose components are the
positive divisors of the integer $x$ in increasing order.

The library syntax is $\teb{divisors}(x)$.

\subsecref{fact}$( x )$ or $x!$: factorial of $x$.

The library syntax is $\teb{mpfact} ( x )$. $x$ must be a
32-bit C-integer and not a PARI integer.

\subsecref{factfq}$(x,p,a)$: factorization in the field $\Bbb F_q$ defined by
the irreducible polynomial $a$ over $\Bbb F_p$ of the polynomial
$x$. The coefficients of $x$ must be operation-compatible with $\Bbb Z/p\Bbb
Z$. 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 {\tt lift()} of the
result will be legible.

The library syntax is $\teb{factmod9}(x,p,a)$.

\subsecref{factmod}$( x, p )$: factorization mod $p$ of the polynomial
$x$. The coefficients of $x$ must be operation-compatible with $\Bbb Z/p\Bbb
Z$. The result is a two column matrix, the first column being the irreducible
polynomials dividing $x$, and the second the exponents.

The library syntax is $\teb{factmod} ( x, p )$.

\subsecref{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 coefficients
either integers or integermods. Note that PARI does {\sl not}
know how to factor multivariate polynomials.

The library syntax is $\teb{factor} ( x )$. See also {\tt \ref{factpol}} 
and {\tt \ref{factpol2}} (see 3.6.10).

\subsecref{fibo}$( x )$: $x^{\text{th}}$ fibonacci number.

The library syntax is $\teb{fibo} ( x )$. $x$ must be a
32-bit C-integer and not a PARI integer.

\subsecref{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. Experiment will tell you what the result in these cases
will be.

The library syntax is $\teb{ggcd} ( x, y )$.

\subsecref{hclassno}$(x)$: \ref{Hurwitz class number} of $x$, where $x$ is
nonnegative and congruent to 0 or 3 modulo 4. See also 3.4.6 above.

The library syntax is $\teb{hclassno}(x)$.

\subsecref{hilb}$( x, y, p )$ or {\bf hilbp}$( x, y )$: \ref{Hilbert symbol} of
$x$ and $y$. If $x$ and $y$ are of type integer or fraction, the function
{\tt 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 $\teb{hil} (x, y, p )$ or
$\teb{hil} ( x, y )$.

\subsecref{isfund}$(x)$: true (1) if $x$ is equal to 1 or to the
discriminant of a quadratic field, false (0) otherwise.

The library syntax is $\teb{isfundamental}(x)$.

\subsecref{isprime}$(x)$: true (1) if $x$ is a strong pseudo-prime
for 10 randomly chosen bases, false (0) otherwise.

The library syntax is $\teb{isprime}(x)$.

\subsecref{ispsp}$(x)$: true (1) if $x$ is a strong 
pseudo-prime for a randomly chosen base, false (0) otherwise.

The library syntax is $\teb{ispsp}(x)$.

\subsecref{isqrt}$( x )$: integer square root of $x$, which must be
of PARI type integer. A negative $x$ is allowed, and the result in that case
is {\tt i*isqrt(-x)}.

The library syntax is $\teb{racine} ( x )$.

\subsecref{issqfree}$(x)$: true (1) if $x$ is squarefree, false if not.
Here $x$ can be an integer or a polynomial.

The library syntax is $\teb{issquarefree}(x)$.

\subsecref{issquare}$(x)$: true (1) if $x$ is square, false if not.

The library syntax is $\teb{carreparfait}(x)$.

\subsecref{kronecker}$( x, y )$ or {\bf kro}$( x, y )$: Kronecker
\sref{Legendre symbol}
(i.e. generalized Legendre) symbol $\left(\dfrac{x}{y}\right)$. $x$ and $y$
must be of type integer and the result ($0$ or $\pm 1$) is a 32-bit C-integer.

The library syntax is $\teb{kronecker} ( x, y )$.

\subsecref{lcm}$(x, y)$: least common multiple of $x$ and $y$, i.e.
such that $\text{lcm}(x,y)*\text{gcd}(x,y)=x*y$.

The library syntax is $\teb{glcm}(x,y)$.

\subsecref{mu}$( x )$: M\"obius $\mu$-function of $x$. $x$ must be of
type integer and the result ($0$ or $\pm 1$) is a 32-bit C-integer.

The library syntax is $\teb{mu} ( x )$.

\subsecref{nextprime}$( x )$: finds the smallest prime greater than or
equal to $x$. $x$ must be of type integer.

The library syntax is $\teb{bigprem} ( x )$.

\subsecref{numdiv}$( x )$: number of divisors of $x$. $x$ must be of type
integer, and the result is a 32-bit C-integer.

The library syntax is $\teb{numbdiv} ( x )$.

\subsecref{omega}$( x )$: number of distinct prime
divisors of $x$. $x$ must be of type integer, and the result is a 32-bit
C-integer.

The library syntax is $\teb{omega} ( x )$.

\subsecref{order}$(x)$: $x$ must be an integer mod $n$, and the result
is the order of $x$ in the multiplicative group $(\Bbb Z/n\Bbb Z)^*$. Error if
$x$ is not invertible.

The library syntax is $\teb{order}(x)$.

\subsecref{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 to the current precision.

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

\subsecref{phi}$( x )$: Euler's $\phi$-function of $x$. $x$ must be of
type integer.

The library syntax is $\teb{phi} ( x )$.

\subsecref{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,\dots,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+\dots+1/a_n)\dots)$. If $x$ is a matrix with two rows
$[b_0,b_1,\dots,b_n]$ and $[a_0,a_1,\dots,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+\dots+b_n/a_n)\dots)$. Note that in this
case one usually has $b_0=1$.

The library syntax is $\teb{pnqn}(x)$.

\subsecref{prime}$( x )$: the $x^{\text{th}}$ prime number. 

The library syntax is $\teb{prime} ( x )$. $x$ must be a 32-bit C-integer.

\subsecref{primes}$( x )$: creates a row vector whose components
are the first $x$ prime numbers. 

The library syntax is $\teb{primes} ( x )$. $x$ must be a 32-bit C-integer.

\subsecref{primroot}$(x)$: returns a primitive root of $x$, where $x$
is a prime power.

The library syntax is $\teb{gener}(x)$.

\subsecref{qfi}$(a,b,c)$: creates the binary quadratic form $ax^2+bxy+cy^2$
with $b^2-4ac<0$.

The library syntax is $\teb{qfi}(a,b,c)$.
\sref{Binary quadratic form}

\subsecref{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 $\teb{qfr}(a,b,c,d)$.

\subsecref{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.

The library syntax is $\teb{regula} ( x, prec )$.

\subsecref{sigma}$( x )$: sum of the positive divisors of $x$. $x$ must
be of type integer.

The library syntax is $\teb{sumdiv} ( x )$.

\subsecref{sigmak}$( k, x )$: sum of the $k^{\text{th}}$ powers of the
positive divisors of $x$. $x$ must be of type integer, but (in library mode)
$k$ must be a 32-bit C-integer.

The library syntax is $\teb{sumdivk} ( k, x )$.

\subsecref{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 {\tt factor} when
one needs only the small prime divisors and not the complete factorisation.

The library syntax is $\teb{smallfact}(x)$.

\subsecref{unit}$( x )$: \ref{fundamental unit} of the real quadratic field
$\Bbb 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 $\teb{fundunit} ( x )$.

\section{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 {\tt 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 {\tt initell} (see below),
which gives a 19 component vector (which we will call a long vector in this
section), or by the faster function {\tt 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 {\tt initell}, the curve can be given either as a five component
vector, or by one of the longer vectors computed by {\tt initell} or
{\tt smallinitell}.

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

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

\subsecref{addell}$(e,z1,z2)$: sum of the points $z1$ and $z2$ on the
elliptic curve corresponding to the vector $e$.

The library syntax is $\teb{addell}(e,z1,z2)$.

\subsecref{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 {\tt smallinitell} or {\tt initell}.

The library syntax is $\teb{anell}(e,n)$.

\subsecref{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 $\Bbb F_p$ is
$p+1-a_p$. $e$ must be a medium or long vector of the type given by 
{\tt smallinitell} or {\tt initell}.

The library syntax is $\teb{apell}(e,p)$.

\subsecref{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 {\tt apell} as soon as $p$ is greater than 100, say.
$e$ must be a medium or long vector of the type given by {\tt smallinitell}
or {\tt initell}.

The library syntax is $\teb{apell2}(e,p)$.

\subsecref{chell}$(e,v)$: change the data for the elliptic curve $e$
by changing the coordinates using the vector {\tt 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 {\tt smallinitell} or {\tt initell}.

The library syntax is $\teb{coordch}(e,v)$.

\subsecref{chptell}$(x,v)$: change the coordinates of the point or vector of
points $x$ using the vector {\tt 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 {\tt chell} above).

The library syntax is $\teb{pointch}(x,v)$.

\subsecref{globalred}$(e)$: calculate the arithmetic conductor and the global minimal
model of $e$. Here $e$ is an elliptic curve given by a medium or long vector of the
type given by {\tt smallinitell} or {\tt initell}, and is supposed to have all its
coefficients $a_i$ in $\Bbb Q$. The result is a 2 component vector $[N, v]$. $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 $\Bbb 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.

The library syntax is  $\teb{globalreduction}(e)$.

\subsecref{hell}$(e,z)$: global \ref{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 {\tt initell}. This computation is done using sigma and 
theta-functions and a trick due to J. Silverman.

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

\subsecref{hell2}$(e,z)$: same as {\tt hell}, except that the algorithm used
is Tate's $4^n$ algorithm, and is much slower. 

The library syntax is $\teb{ghell2}(e,z,prec)$.

\subsecref{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 $\Bbb R$ or not.
\smallskip
When $e$ is defined over $\Bbb 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_1}{\omega_2}$ having positive imaginary part.

$E[17]$ and $E[18]$ are the corresponding values $\eta_1$ and $\eta_2$
such that $\eta_1\omega_2-\eta_2\omega_1=i\pi$.

Finally, $E[19]$ is the volume of the complex lattice defining $e$.
\smallskip
When $e$ is defined over $\Bbb 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 $\Bbb 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.
\smallskip
For all other base fields or rings, the last six components are
arbitrarily set equal to zero.

The library syntax is $\teb{initell}(e,prec)$.

\subsecref{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 $\teb{oncurve}(e,z)$, and the result is a
C-integer.

\subsecref{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 {\tt smallinitell} or {\tt initell}, and is assumed to
have all its coefficients $a_i$ in $\Bbb Z$. The result is a 3 component vector
$[f, kod, v]$. 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.

The library syntax is $\teb{localreduction}(e, p)$.

\subsecref{matell}$(e,x)$: here $x$ is a vector of points, and this
function outputs the Gram matrix of $x$ with respect to the N\'eron-Tate
height, in other words, the {\tt (i,j)} component of the matrix is
equal to {\tt (hell(e,x[i]+x[j])-hell(e,x[i])-hell(e,x[j]))/2}, where
{\tt 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.

The library syntax is $\teb{matell}(e,x,prec)$.

\subsecref{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 $\teb{ordell}(e,x)$.

\subsecref{powell}$(e,n,z)$: computes $n$ times the point $z$ for the
group law on the elliptic curve $e$. Here $n$ is in $\Bbb Z$.

The library syntax is $\teb{powell}(e,n,z)$.

\subsecref{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 {\tt 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 $\teb{smallinitell}(e)$.

\subsecref{subell}$(e,z1,z2)$: difference of the points $z1$ and $z2$ on the
elliptic curve corresponding to the vector $e$.

The library syntax is $\teb{subell}(e,z1,z2)$.

\subsecref{zell}$(e,z)$: If $e$ is an elliptic curve with coefficients in
$\Bbb 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]$.
If $e$ has coefficients in $\Bbb Q_p$, then either Tate's $u$ is in $\Bbb 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
{\tt initell}.

The library syntax is $\teb{zell}(e,z,prec)$.

\section{Polynomial and power series functions.}

We group here all functions which are specific to polynomials or power
series, including functions related to number fields.
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.

\subsecref{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 $\Bbb Q_p$) or can be an element of a
finite extension of $\Bbb 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 $\Bbb Q_p$ as
$a$.

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

\subsecref{base}$(x)$: \ref{integral basis} of the number field defined by
the monic irreducible polynomial $x$, using the round 2 algorithm.

The library syntax is $\teb{base}(x,\&d)$, where $d$ will receive the
discriminant of the number field ({\sl not} of the polynomial $x$).
This program is the translation in C of a program written by David Ford.

\subsecref{convol}$( x, y )$: convolution (or \ref{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 $\text{convol} ( x, y )=\sum a_k*b_k*X^k$.

The library syntax is $\teb{convol} ( x, y )$.

\subsecref{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 $\teb{deriv} ( x,v )$, where $v$ is the number of the
variable $y$.

\subsecref{disc}$( x )$: discriminant of $x$. $x$ must be a polynomial.
The algorithm used is the \ref{subresultant algorithm}.

The library syntax is $\teb{discsr} ( x )$.

\subsecref{discf}$(x)$: \ref{field discriminant} of the number field defined
by the monic irreducible polynomial $x$.

The library syntax is $\teb{discf}(x)$. See also {\tt base}, 3.6.1 above.

\subsecref{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 {\tt subst}, 3.6.32 below).

The library syntax is $\teb{geval}(x)$.

\subsecref{factoredbase}$(x,p)$: \ref{integral basis} 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 $\teb{factoredbase}(x,p,\&d)$, where $d$ will receive the
discriminant of the number field.

\subsecref{factoreddiscf}$(x,p)$: \ref{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 $\teb{factoreddiscf}(x,p)$.

\subsecref{factoredpolred}$(x,p)$: same as {\tt polred} (see 3.6.18 below) except that
$p$ is the two column matrix of the factorization of the discriminant of the polynomial $x$.

The library syntax is $\teb{factoredpolred}(x,p,prec)$.

\subsecref{factorpadic}$(x,p,r)$: $p$-adic factorization of the polynomial $x$
to precision $r$, the result being a two column matrix as in {\tt factor}.
In the present version 1.35, only separable factors are given, hence the sum 
of the degrees of the factors may not add up to the degree of $x$. In any case,
$r$ must be stricly larger than some value which is at most equal to the
$p$-adic valuation of the discriminant of $x$ for the result to make any sense.

The library syntax is $\teb{factorpadic}(x,p,r)$, where $r$ is a C-integer.

\subsecref{factpol}$(x,l)$: $x$ must be a polynomial with coefficients
in $\Bbb 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$. The result is a two column matrix, the first one containing the irreducible 
factors, the second one the exponents.

The library syntax is $\teb{factpol}(x,l)$. The algorithm used is the standard
Hensel lifting of a mod $p$ factorization. Another implementation using instead
root finding over $\Bbb C$ (instead of implicitly using $\Bbb Q_p$) is
$\teb{factpol2}(x,l)$.

\subsecref{integ}$( x, y )$: \ref{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, but the case where $x$ is a
rational function is not implemented in the present version (1.35).

The library syntax is $\teb{integ} ( x )$.

\subsecref{laplace}$( x )$: $x$ must be a power series with only
nonnegative exponents. If $x=\sum (a_k/k!)*X^k$ then the result is
$\sum a_k*X^k$.

The library syntax is $\teb{laplace} ( x )$.

\subsecref{legendre}$( x )$: creates the $x^{\text{th}}$ \ref{Legendre polynomial}.

The library syntax is $\teb{legendre} ( x )$, where $x$ is a 32-bit C-integer.

\subsecref{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 $\teb{newtonpoly}(x,p)$.

\subsecref{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
$\Bbb 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 $\teb{ordred}(x)$.

\subsecref{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 \ref{interpolating polynomial}
passing through these points and evaluates it at the value $x$.

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

\subsecref{polred}$(x)$: finds polynomials with reasonably small
coefficients defining subfields of the number field defined by $x$. 
One of the polynomials always defines
$\Bbb 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 $\teb{polred}(x,prec)$.

\subsecref{polredreal}$(x)$: similar to {\tt polred} but only valid for
totally real polynomials $x$, i.e. polynomials having only real roots. In that
case it is often faster than polred.

The library syntax is $\teb{polredreal}(x,prec)$.

\subsecref{polsym}$(x,n)$: creates the vector of the \ref{symmetric powers}
of the roots of the polynomial $x$ up to power $n$.

The library syntax is $\teb{polsym}(x)$.

\subsecref{recip}$( x )$: reciprocal polynomial of $x$, i.e. the
coefficients are in reverse order. $x$ must be a polynomial.

The library syntax is $\teb{polrecip} ( x )$.

\subsecref{resultant}$( x, y )$: resultant of the two polynomials
$x$ and $y$. The algorithm used is the subresultant algorithm.

The library syntax is $\teb{subres} ( x, y )$.

\subsecref{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 $\teb{recip} ( x )$.

\subsecref{rootmod}$(x,p)$: roots modulo $p$ of the polynomial $x$. Slightly
slower than {\tt rootmod2} below for $p<100$, but much faster for larger
values. The particular nonprime value $p=4$ is accepted, mainly for $2$-adic
computations. Multiple roots are {\sl not} repeated.

The library syntax is $\teb{rootmod}(x,p)$.

\subsecref{rootmod2}$(x,p)$: 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 $\teb{rootmod2}(x,p)$.

\subsecref{rootpadic}$(x,p,r)$: vector of $p$-adic roots of the polynomial $x$
with $p$-adic precision equal to $r$. Multiple roots are {\sl not} repeated.

The library syntax is $\teb{rootpadic}(x,p,r)$, where $r$ is a C-integer.

\subsecref{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 {\tt 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.

The library syntax is $\teb{roots} ( x, prec )$.

\subsecref{smallbase}$(x)$: \ref{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 $\teb{smallbase}(x,\&y)$, where $y$ will receive the
discriminant of the number field ({\sl not} of the polynomial $x$).
This program is the translation in C of a program written by David Ford.

\subsecref{smalldiscf}$(x)$: \ref{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 $\teb{smalldiscf}(x)$. See also {\tt smallbase}, 3.6.27 above.

\subsecref{smallpolred}$(x)$: same as {\tt polred} (see 3.6.18 above) except that
only a suborder of the maximal order may be used.

The library syntax is $\teb{smallpolred}(x,prec)$.

\subsecref{sturm}$(x)$: number of real roots of the real polynomial $x$,
using Sturm's algorithm.

The library syntax is $\teb{sturm}(x)$. The result is a 32-bit C-integer.

\subsecref{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 $\teb{sturmpart}(x)$. The result is a 32-bit C-integer.

\subsecref{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 $\teb{gsubst} ( x, v, z )$, where $v$ is the number of
the variable $y$.

\subsecref{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 $\teb{tayl} ( x, y, n )$, where the 32-bit C-integer $n$
is the desired number of terms in the expansion.

\subsecref{tchebi}$( x )$: creates the $x^{\text{th}}$ Tchebicheff
polynomial.

The library syntax is $\teb{tchebi} ( x )$, where $x$ is a 32-bit C-integer.

\section{Vectors, matrices and linear algebra.}

\subsecref{adj}$( x )$: \ref{adjoint matrix} of $x$, i.e. the matrix $y$
of cofactors of $x$ such that $x*y=\text{det} ( x )*\text{Id}$. $x$ must be
a (non necessarily invertible) square matrix.

The library syntax is $\teb{adj} ( x )$.

\subsecref{algdep}$( x, k )$: 
\ref{algebraic dependence} $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 $\teb{algdep}(x,k,prec)$, where $k$ is a 32-bit
C-integer.

\subsecref{algdep2}$( x, k, bit )$: 
\ref{algebraic dependence} $x$ being real or complex, finds a
polynomial of degree at most $k$ having $x$ as approximate root.
$bit$ is a number which should be approximately equal to half the number
of precision bits. 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 $\teb{algdep2}(x,k,bit,prec)$, where $k$ and $bit$ are
32-bit C-integers.

\subsecref{char}$( x, y )$: \ref{characteristic polynomial} of $x$ with respect
to the variable $y$, i.e. determinant of $y*I-x$. $x$ must be a square matrix.

The library syntax is $\teb{caract} ( x, v )$, where $v$ is the variable 
number.

\subsecref{char2}$(x, y)$: characteristic polynomial of the square matrix
$x$ with respect to the variable $y$ using the hessenberg form. This is
faster than {\tt char} when the
coefficients are integermod a prime or real numbers, but can be slower in
other base rings.

The library syntax is $\teb{carhess}(x,v)$, where $v$ is the variable number.

\subsecref{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 2-row or two column
matrix), first transform the vector into a 1-row or 1-column matrix
using the function mat (3.7.22.).

The library syntax is $\teb{concat} ( x, y )$.

\subsecref{det}$( x )$: determinant of $x$. $x$ must be a
square matrix. Another program called {\bf \ref{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 $\teb{det} ( x )$ and $\teb{det2} ( x )$.

\subsecref{eigen}$(x)$: gives the eigenvectors of $x$ as columns of
a matrix.

The library syntax is $\teb{eigen}(x)$.

\subsecref{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
{\sl columns} of $x$. $y$ must be either a number of PARI type
integer, in which case 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. 

Or $y$ can be a vector, with integer entries, in which case these
entries correspond to the component number 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 $\teb{extract} ( x, y )$.

\subsecref{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, but is much faster,
than $x^{-1}*y$.

The library syntax is $\teb{gauss} ( x, y )$.

\subsecref{hermite}$(x)$: if $x$ is a (not necessarily square) matrix of
maximal rank, finds the {\sl upper triangular} Hermite Normal Form of $x$
(which is a square matrix).

The library syntax is $\teb{hnf}(x)$.

\subsecref{hess}$(x)$: Hessenberg form of the square matrix $x$.

The library syntax is $\teb{hess}(x)$.

\subsec{hilbert}$( x )$: $x$ being a 32-bit C-integer,
creates the \ref{Hilbert matrix} of order $x$, i.e. the matrix whose
coefficient ($i$,$j$) is $1\over {i+j-1}$.

The library syntax is $\teb{hilbert} ( x )$.

\subsecref{indsort}$(x)$: indirect sorting of the vector $x$, i.e. if $x$
is an $n$-dimensional vector, creates the permutation of $[1,2,\dots,n]$ which
applied to the components of $x$ sorts $x$ in increasing order.

The library syntax is $\teb{indexsort}(x)$.

\subsecref{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 $\teb{jacobi}(x)$.

\subsecref{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 {\tt keri} and {\tt kerr}.

The library syntax is $\teb{ker}(x)$.

\subsecref{keri}$(x)$: same as {\tt ker}, except that it assumes that the 
matrix has entries of type integer. In that case it is much faster.

The library syntax is $\teb{keri}(x)$.

\subsecref{kerr}$(x)$: gives a basis for the kernel of the matrix $x$ as
columns of a matrix, where $x$ has elements which can be nonexact 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 $\teb{kerreel}(x)$.

\subsecref{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 $\teb{image}(x)$.

\subsecref{lindep}$( x )$: 
\sref{linear dependence}$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 $\teb{lindep}(x,prec)$.

\subsecref{lindep2}$(x,bit)$: 
\sref{linear dependence}$x$ being a vector with real
or complex coefficients, finds a small integral linear combination
among these coefficients using the LLL algorithm. $bit$ is a parameter which
should be about one half the number of precision bits.

The library syntax is $\teb{lindep2}(x,bit,prec)$ where $bit$ is a C-integer.

\subsecref{lll}$( x )$: LLL algorithm applied to the {\bf columns}
of the (non necessarily square) matrix $x$. The result is a square 
transformation matrix $T$ such that $x\cdot 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.35) are numerically unstable.

The library syntax is $\teb{lll}(x,prec)$.

\subsecref{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.35.

The library syntax is $\teb{lllgram} ( x )$.

\subsecref{lllrat}$( x )$: same as LLL except that the computations
are all done in rational numbers. Hence no risk of numerical instability,
but extremely slow.

The library syntax is $\teb{lllrat} ( x )$.

\subsecref{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 {\tt concat}
(see 3.7.5.).

The library syntax is $\teb{gtomat} ( x )$.

\subsecref{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
{\tt extract} (3.7.8). The difference with {\tt extract} is that both lines
and columns are extracted.

The library syntax is $\teb{matextract} ( x, y, z )$.

\subsecref{minim}$(x)$: number of minimal vectors and minimum on $\Bbb Z$ 
of the positive definite integral quadratic form x, as a two component
vector. $x$ is represented by a square and symmetric matrix with integer
entries.

The library syntax is $\teb{minim}(x)$

\subsec{pascal}$( x )$: creates
as a matrix the lower triangular \ref{pascal triangle} of order $x+1$
(i.e. with binomial coefficients up to $x$).

The library syntax is $\teb{pascal} ( x )$, where $x$ is a 32-bit C-integer.

\subsecref{rank}$(x)$: rank of the matrix $x$.

The library syntax is $\teb{rank}(x)$, and the result is a 32-bit
C-integer.

\subsecref{signat}$(x)$: signature of the quadratic form
represented by the symmetric matrix $x$. The result is a two-component vector.

The library syntax is $\teb{signat}(x)$

\subsecref{smith}$(x)$: if $x$ is a nonsingular square matrix,
outputs the vector of elementary divisors of $x$ (i.e. the diagonal of the
Smith normal form of $x$)

The library syntax is $\teb{smith}(x)$.

\subsecref{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 {\tt indsort} (see 3.7.13 above) which gives
the indexes of the sorted vector in terms of the initial one. For example, 
{\tt extract(x,indsort(x))} is equivalent to {\tt sort(x)}.

The library syntax is $\teb{sort}(x)$.

\subsecref{sqred}$(x)$: \ref{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 $\teb{sqred}(x)$.

\subsecref{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 $\teb{suppl}(x)$.

\subsecref{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 $\teb{trace} ( x )$.

\subsecref{trans}$( x )$ or $x\tilde{\ }$: transpose of $x$.
This has an effect only on vectors and matrices.

The library syntax is $\teb{gtrans} ( x )$.

\section{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, summation of series or plotting 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 3.9.7.
Hence in this section we do not give the library syntax.

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

\subsecref{divsum}$( n,X,expr )$: sum of expression $expr$ over
the positive divisors of $n$.

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

\subsecref{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$.

\subsec{(numerical) integration}:\sref{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 \ref{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, one should set infinity equal to 10 for example, and 
cetrainly 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.

\subsecref{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$.

\subsecref{intinf}$(X=a, b, expr )$: numerical integration from $a$ to $b$,
tailored for being used when $a$ or $b$ are infinite. One {\sl 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\ge1$.

\subsecref{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]$.

\subsecref{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$.

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

\subsecref{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$.

\subsecref{plot}$(X=a, b, expr )$: crude plot of the function represented by
expression $expr$ from $a$ to $b$.

\subsecref{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 {\tt ploth}.

Note that this function is very much implementation dependent and has been
written for the moment for the Macintosh, for the SUN under Sunview/Suntools
and for the X-window system (release X11). An Atari/gem version is also
available upon request.

\subsecref{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 {\tt ploth2}.

Note that, as for {\tt ploth} above, this function has been written for the 
moment only for the Macintosh, for the SUN under Sunview/Suntools
and for the X-window system (release X11). An Atari/gem version is also
available upon request.

\subsecref{prod}$(x,X=a,b,expr)$: product of expression $expr$,
initialized at $x$, the formal parameter $X$ going from $a$ to $b$. As for {\tt 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 $$\text{prod} (1,j=1,100,(1-X\hat{\ }j) )$$
with  $$\text{prod} ( 1+O(X\hat{\ }101),j=1, 100, (1-X\hat{\ }j) ).$$

\subsecref{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$.\sref{Euler product}

\subsecref{prodinf}$(X=a,expr)$: \ref{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 $\Bbb C$.

\subsecref{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 $\Bbb C$.

\subsecref{solve}$(X=a,b,expr)$: real root of expression $expr$ between $a$ and
$b$, under the condition $expr(X=a)*expr(X=b)\le0$. The method used is Brent's method.

\subsecref{sum}$(x,X=a,b,expr)$: sum of expression $expr$,
initialized at $x$, the formal parameter going from $a$ to $b$. As for {\tt 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, operations will start being done exactly. If it is put
equal to the real $0.$, 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$, they will be done using power series of precision at most $k$. These
are the three most common initializations.

As an extreme example, compare $$\text{sum} ( 0,j=1, 1000, 1/j )$$
with  $$\text{sum} ( 0.,j=1, 1000, 1/j ).$$

\subsecref{sumalt}$(X=a, expr )$: numerical summation of the series $expr$,
which should be an \ref{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.

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

\subsecref{suminf}$(X=a,expr)$: \ref{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 $\Bbb C$.

\subsecref{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.

\subsecref{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 {\tt hvector}).

\subsecref{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$.

\section{Programming under GP and user-defined functions.}

\sref{programming}

\subsec{\ref{Variables} and symbolic expressions}.

In GP you can use up to 256 variable names. 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 '\_', '\$', or '.'. In addition to the function names which
you must not use (see the list with $\backslash$c) there are exactly three special 
variable names which you are not allowed to use: {\bf pi} and {\bf euler}, which
represent well
known constants, but also {\bf i} which is always equal to the square root of $-1$.
Since usually you are not going to use the variable name {\tt pi} for anything else but
the number $\pi$, and similarly for {\tt 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 {\tt 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 {\sl 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 {\sl 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 {\tt eval} (see 3.6.6 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
{\sl 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 {\tt changevar} (see 3.2.2). If you only want
to have them ordered when the result is printed, you can also use the function
{\tt reorder} (see 3.9.4.6).

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 {\sl not} to $x[m]$, which is a vector.

\subsec{\ref{Expression}s and \ref{expression sequence}s}.

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 nonempty 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 (';').

\subsecref{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.

\subsubsecref{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 $\Bbb R$.

\subsubsecref{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.

\subsubsecref{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 $\Bbb R$.

\subsubsecref{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 $\Bbb R$, and $s$ must
be nonzero.

\subsubsecref{if}$(a,seq1,seq2)$: if $a$ is nonzero, 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: {\tt if(a,seq,)} evaluates $seq$ if
$a$ is not equal to zero, does nothing otherwise; {\tt if(a,,seq)} evaluates $seq$ if $a$
is equal to zero, does nothing otherwise.

\subsubsecref{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 {\sl after} execution of
the $seq$, not before as in {\tt while}.

\subsubsecref{while}$(a,seq)$: while $a$ is nonzero evaluate the expression sequence
$seq$. The test is made {\sl before} evaluating the $seq$, hence in particular if $a$
is initially equal to zero the $seq$ will not be evaluated at all.
\smallskip
\subsec{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 specificlly for GP. They are as follows:

\subsubsecref{kill}$(x)$: kills the present value of the variable or user-defined
function $x$. After {\tt 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
'{\tt "}', which are always printed as they are.

\subsubsecref{pprint}$(list)$: output $list$ in prettyprint (beautified) format,
ending with a newline.

\subsubsecref{pprint1}$(list)$: output $list$ in prettyprint (beautified) format,
without ending with a newline.

\subsubsecref{print}$(list)$: output $list$ in raw format, ending with a newline.

\subsubsecref{print1}$(list)$: output $list$ in raw format, without ending with a 
newline.

\subsubsecref{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 nonempty, 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 {\tt [x,y,z]}, then after {\tt reorder([z,x])} the
order of importance of the variables will be {\tt [z,y,x]}.

\subsubsecref{texprint}$(list)$: outputs $list$ in \TeX{} format. This
output can then be used in a \TeX{} manuscript. 

Warning: in the present version 1.35, 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 3.10), 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 $\backslash$l). This will be improved.

\smallskip
\subsecref{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:

{\tt name(list of true formal variables, list of local variables)=seq}

where {\tt name} is the name that you want to give to your function (same syntactic
restrictions as for variable names). {\tt 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. {\tt 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 nondeclared
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 {\tt 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 {\tt ?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
{\tt kill} instruction.

In a given session you can give any identifier name to a function, {\sl 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 {\tt sumalt} function. Although
since version 1.34 the \ref{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:

\sref{zeta function}
{\tt 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\dots$ Of course, the call to the function is
done by {\tt zet(s)}, the variable {\tt j} must not be given.

\subsec{Special \ref{editing character}s}. 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 \ref{backslash character} '$\backslash$' 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
{\tt ?name}, you will see that your backslash has disappeared and that everything is on
the same line. You can type a $\backslash$ anywhere. It will be interpreted as above
only if it is immediately followed by a newline. For example, you can type

{\tt 3+$\backslash$}

{\tt 4}

instead of typing {\tt 3+4}.

The second one cannot be used everywhere, but is in general more useful. It is the use
\sref{brace characters}
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.

\subsec{The GP/PARI \ref{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, {\tt f(x, y)} rather than {\tt (f x y)}: all programming constructs,
such as {\tt 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 {\tt 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 {\bf \ref{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 {\tt 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 degre 1 in
this variable, as is natural for a mathematician.

Note that the iterative constructs which use a variable name ({\tt 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 {\tt zet}
example above, the variable {\tt 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.

{\bf Implementation note.} For the curious reader, here is how these stacks are
handled: a \ref{hashing function} is computed from the identifer, and used as an
index in {\tt \ref{hashtable}}, a table of pointers. Each of these pointers begins
a linked list of structures (type {\tt \ref{entree}}). The linked list is searched
linearly for the identifer (each list will have less than 7 components or
so). When the correct {\tt 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.

\section{Using GP under \ref{gnuemacs}.}

Thanks to the help of Annette Hoffman from the university of Saarbr\"ucken, 
and since version 1.34.05 from 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 {\tt .emacs} file the following line:

{\tt (load "\ref{pari}" nil t)}

where {\tt 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 {\tt 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 {\tt 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
{\tt /usr/local/bin/gp} for the executable, 4000000 for the stack, 500000 for the
prime limit and 30000 for the buffer size).
\smallskip
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 {\tt ?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 $\backslash$, $\%$) which use special symbols.

This help system can also be menu-driven, by using the command {\tt M-\char`\\ c}
which opens a help menu window which enables you to choose the category
of commands for which you want an explanation.
\smallskip
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 {\sl not} work if for some
reason you exited emacs before coming back (except for the C-z temporary
stopping command).


\vfill\eject

