\chapter{Specific use of the {\bf \idx{GP}} calculator}

Originally, GP was designed as a debugging tool for the PARI system library,
and hence not much thought had been given to make it user--friendly. The
situation has now changed somewhat, and GP is very useful as a standalone
tool. The operations and functions available in PARI and GP will be described
in the next chapter. In the present one, we describe the specific use of the
GP programmable calculator.

To start the calculator, the general syntax is:

\centerline{\tt gp [-s stacksize] [-p primelimit] [-b buffersize]}

\noindent where as usual items within brackets are optional. Those correspond
to some internal parameters of GP, or {\it defaults}. See
\secref{se:defaults} below for a list and explanation of all defaults,
there are many more than just those three. These defaults can be changed by
adding parameters to the input line as above, or interactively during a GP
session or, on UNIX versions, in a \kbd{.gprc} init file \footnote{*}{ On the
Macintosh, even after clicking on the gp icon, once in the MPW Shell, you
still need to type explicitly the above command. If you are using the
standalone version SAGp, the limits are hardwired and cannot be changed.}.

\unix Some new features, such as the \kbd{.gprc} alluded to above, were
developed on UNIX platforms, and depend heavily on the operating system in
use. It is {\it possible} that some of these will be ported to other OS in
future versions (it should be an easy task for anybody acquainted with
those). As for now, most of them were not. So, whenever a specific feature of
the UNIX version is discussed in a paragraph, a UNIX sign sticks out in the
left margin, like here. Just skip these if you're stranded on a different
operating system: the core GP functions (i.e.~at least everything which is
even faintly mathematical in nature) will still be available to you.

\emacs If you have GNU Emacs, you can work in a special Emacs shell (see
\secref{se:emacs}), which is started by typing \kbd{M-x gp} (where as
usual \kbd{M} is the \kbd{Meta} key) if you accept the default stack, prime
and buffer sizes, or \kbd{C-u M-x gp} which will ask you for the name of the
gp executable, the stack size, the prime limit and the buffersize. Specific
features of this Emacs shell will be indicated by an EMACS sign. \smallskip

\unix If a file named \kbd{.gprc} (to be discussed in
\secref{se:gprc}) lies in your home directory, GP will then read it,
and execute the commands therein. This provides an easy way to customize GP
without having to delve into the code to hardwire it to your likings.

A copyright message then appears which includes the version number. Please
note this number, so as to be sure to have the most recent version if you
wish to have updates of PARI. The present manual is written for version
\vers, and has undergone major changes since the 1.39.xx versions.

After the copyright, the computer works for a few seconds (it is in fact
computing and storing a table of primes), writes the top-level help
information, some initial defaults, and then waits after printing its prompt
(initially: \kbd{?}).

Note that at any point the user can type \kbd{Ctrl-C} (that is press
simultaneously the \kbd{Control} and \kbd{C} keys): the current
computation will be interrupted and control given back to the user at the GP
prompt.

The top-level help information tells you that (as in many systems), to get
help you should type a \kbd{?}. When you do this, a menu appears,
describing the eleven main categories of available functions and what to do
to get more precise help. If you now type \kbd{?$n$} with $1\le n\le11$ you
will get the list of commands corresponding to category $n$ and
simultaneously to Section $3.n$ of this manual. 

If you type \kbd{?functionname}'' where \kbd{functionname} is the
name of a PARI function, you will get a short explanation about this
function.

\unix If you have \kbd{perl} installed on your system, GP was told about it
at compile time, and a valid external help script is present (see
\secref{se:exthelp}), you can double the \kbd{?} sign (i.e.~type {\tt
??functionname}) to get extended help. You then get the function description
exactly as it stands in Chapter 3. All operators (e.g \kbd{+}, \kbd{\&\&},
etc.) are accepted by this extended help, as well as a few other keywords
describing key GP concepts, e.g \kbd{readline} (the line editor), \kbd{nf}
(``number field'' used in most algebraic number theory computations), 
\kbd{ell} (elliptic curve), etc.

\unix If GP was compiled with the right options (see Appendix A), a line
editor will be available to correct the command line, get automatic
completions, and so on. See \secref{se:readline} for a short summary of
available commands.

 Whether extended on-line help and line editing are available or not is
indicated in GP header, between the version number and the copyright message.

If you type \kbd{?\bs} you will get a short description of the metacommands
(keyboard shortcuts).

Finally, typing \kbd{?.} will return the list of available member
function. That is functions attached to specific kind of objects, usually to
retrieve easily some information from complicated structures. We will soon
describe these commands in more detail.

As a general rule, under GP, commands starting with \b{} and some
other symbols like \kbd{?}, are not computing commands, but are
metacommands which correspond to information exchange with GP. The available
commands of this sort can be divided among default setting commands
(explained below) and simple commands (or keyboard shortcuts, to be dealt
with in \secref{se:meta}).

\section{Defaults \sidx{defaults} and \idx{output formats}.}
\label{se:defaults}
There are many internal variables in GP, defining how the system will behave
in specific situations, when no specific override has been detected. The
interface function used to manipulate these is called \key{default}, which
will be described in \secref{se:default}. In interactive use, this can often be
abbreviated by the historic GP metacommands (mostly, starting with
\b{}), which we shall describe in the next section.

Here we will only describe the available defaults and how they are used. Just
be aware that typing \key{default} by itself will list those, as well as
their current values (see \b{d}). Just after the default name, we give the
initial value (i.e.~when GP just started, if you did not tamper with it using
command-line switches or a~\kbd{.gprc}) between parentheses.

\subsecidx{buffersize} (default {\tt 30000}): GP input is buffered, which means
only so many bytes of data can be read at a time before a command is
executed. This used to be a very important variable, to allow for overly
large input files to be read into GP, for example large matrices, without it
complaining about ``unused characters''. Currently, \key{buffersize} is
automatically adjusted to the size of the data that is to be read. It will
never go down by itself though. Thus this option may come handy to decrease
it after some unusually large \key{read}, when you don't need to keep
gigantic buffers around anymore.

\subsecidxunix{colors} (default {\tt ""}): this default is only usable if GP
\label{se:colors}
is running within certain color-capable terminals. For instance
\kbd{color-xterm} under X Windows, or standard Linux text consoles and
xterms. It prompts GP to use a different set of colors for its output. The
colormap used correspond to the ressources {\tt Xterm*color$n$} where $n$
runs from $0$ to $15$ (see the file {\tt lib/color.defaults} for an example).
The value of this default is a string {\tt "$a_1$,\dots,$a_k$"} where $k\le7$
and the $a_i$ are either {\tt -1} (use the default color, usually black) or
integers between 0 and 15 corresponding to the aforementioned colormap.

  The corresponding output objects affected are respectively error messages,
history numbers, prompt, input line, output, help messages, timer (that's
seven of them). If $k < 7$, the remaining $a_i$ are assumed to be $-1$. For
instance
%
\bprog
default(colors,"9, 5, -1, -1, 4")
\eprog\noindent
typesets error messages in color $9$, history numbers in color $5$, output in
color $4$, and does not affect the rest.

  If you use an old \kbd{readline} library (version number less than 2.0),
you should do as in the example above and leave alone $a_3$ and $a_4$ (prompt
and input line). Since old versions of \kbd{readline} did not handle
correctly escape characters (or more accurately treated them in the only
sensible way since it did not care to check all your terminal capabilities:
it just ignored them), changing them would result in many annoying display
bugs. 

  The hacker's way to check if it be the case would be to look in the 
\kbd{readline.h} include file (wherever your readline include files are) for
the string {\tt RL\_PROMPT\_START\_IGNORE}. If it's there, you are safe. 

  A more sensible way is to make some experiments, and get a more
recent \kbd{readline} if yours doesn't work the way you'd like it to.

\subsecidx{compatible} (default {\tt 0}): The GP function names and syntax have
changed tremendously between versions 1.xx and 2.00. To help cope with this
we provide some kind of backward compatibility, depending on the value of
this default:

\quad \key{compatible} = 0: no backward compatibility. In this mode, a very
handy function, to be described in \secref{se:whatnow}, is \key{whatnow},
which tells you what has become of your favourite functions, which GP
suddenly can't seem to remember.

\quad \key{compatible} = 1: warn when using obsolete functions, but otherwise
accept them. The output use the new conventions though, and there may be
subtle incompatibilities between the behaviour of former and current
functions, even when sharing the same name (the current function is used in
that case of course !). We thought of this one as a transitory help for GP
old timers. Thus, to encourage switching to \key{compatible}=0, it is not
possible to disable the warning.

\quad \key{compatible} = 2: use only the old function naming scheme (as used up
to version 1.39.15), but {\it taking case into account}. Thus \kbd{I} ( =
$\sqrt{-1}$) is not the same as \kbd{i} (user variable, unbound by default),
and you won't get an error message using \kbd{i} as a loop index as used to
be the case.

\quad \key{compatible} = 3: try to mimic exactly the former behaviour. This is
not always possible when functions have changed in a fundamental way. But
these differences are usually for the better (they were meant to anyway), and
will probably not be discovered by the casual user.

One adverse side effect is that the user functions and aliases that have been
defined {\it before} changing \key{compatible}, will get erased if this
change modifies the function list, i.e.~if you move between groups $\{0,1\}$
and $\{2,3\}$ (variables are unaffected). We of course strongly encourage you
to try and get used to the setting \key{compatible}=0.

\subsecidx{debug} (default {\tt 0}): debugging level. If it is non-zero, some
messages may be printed (mostly in French), according to what is going on
(see \b{g}).

\subsecidx{debugmem} (default {\tt 0}): memory debugging level. If it is
non-zero, GP will regularly print information on memory usage. If it's
greater than 2, it will indicate any important garbage collecting and the
function they took place in (see \b{gm}).

\noindent {\bf Important Note:} As it noticeably slows down the performance
(and triggers bugs in a popular compiler), the first function (memory usage)
is disabled if you're not running a debugging version (see Appendix~A).

\subsecidx{echo} (default {\tt 0}): this is a toggle, which can either be 1
(on) or 0 (off). When \key{echo} mode is on, the command is reprinted before
being executed. This can be useful when reading a file by the \b{r} or {\tt
read} command. It is for example the first command of the test files used to
check the correctness of GP installation (see \b{e}).

\subsecidx{format} (default {\tt "g0.28"} and {\tt "g0.38"} on 32-bit and
64-bit machines respectively): of the form x$m.n$, where x is a letter in
$\{\kbd{f},\kbd{g},\kbd{h}\}$, and $n$, $m$ are integers. If x is \kbd{f},
real numbers will be printed in \idx{fixed floating point format} with no
explicit exponent (e.g. 0.000033); if the letter is \kbd{e}, they will be
printed in \idx{scientific format}, always with an explicit exponent (e.g.
3.3e-5). If the letter is \kbd{g}, real numbers will be printed in
\kbd{f} format, except when their absolute value is less than $2^{-32}$,
in which case they are printed in \kbd{e} format. \label{se:format}

   The number $n$ is the number of significant digits printed for real
numbers, except if $n\le0$ where all the significant digits will be printed
(initial default 28, or 38 for 64-bit machines), and the number $m$ is the
number of characters to be used for printing integers, but is ignored if
equal to 0 (which is the default). This is a feeble attempt at formatting.

\subsecidxunix{help} (default: the location of the \kbd{gphelp} script): the
name of the external help program which shall be used from within GP, when
extended help is needed, usually after a \kbd{??} request (see
\secref{se:exthelp}), or \kbd{M-H} under readline (see
\secref{se:readline}).

\subsecidx{histsize} (default {\tt 5000}): GP keeps an history of the last
\key{histsize} results computed so far, which you can recover using the 
\kbd{\%} notation (see \secref{se:history}). When this number is exceeded,
the oldest values are erased. Tampering with this default is the only way to
get rid of the ones you don't need anymore.

\subsecidx{log} (default {\tt 0}): this is a toggle, which can either be 1
(on) or 0 (off). When logging mode is on, GP opens a log file, whose exact
name is determined by the \key{logfile} default. Subsequently, all the
commands and results will be written in that file (see \b{l}). In case a file
with that precise name already existed, it will not be erased: your data will
be {\it appended} at the end of it.

\subsecidx{logfile} (default {\tt "pari.log"}): name of the log file to be
used when the \key{log} toggle is on.

\subsecidx{output} (default {\tt 1}): this can take any of the following three
values: 0  ( = raw), 1 ( = prettymatrix), or 2 ( = prettyprint). This means
that, in addition to the default \key{format} which we explained above, you
can print results in three ways. Either in ``raw''\sidx{raw format} format,
i.e.~a format which is equivalent to what you input, including explicit
multiplication signs, and everything typed on a line instead of two
dimensional boxes. This can have several advantages, for instance it allows
you to pick the result with a mouse or an editor, and to put it somewhere
else.
\label{se:output}

The second format is the ``prettymatrix''\sidx{prettymatrix format}. The only
difference with the raw format is that matrices are printed as boxes instead of
horizontally. This is prettier, but takes more space and cannot be used for
input. Column vectors are still printed horizontally.

The third format is the ``prettyprint''\sidx{prettyprint format} or
beautified format. In the present version \vers, this is not beautiful at
all. Independently of the default format, an object can be printed in any of
the three formats using the commands \b{a}, \b{m} and \b{b} respectively (see
below).

\subsecidx{parisize} (default, 1000000 bytes on the Mac, 4000000 otherwise):
GP, and in fact any program using the PARI library, needs a stack in which to
do its computations. \key{parisize} is the stack size, in bytes. It is
strongly recommended you increase this default (using the \kbd{-s}
command-line switch, or a \kbd{.gprc}) if you can afford it. In case of
urgency, you can use the \key{allocatemem} function to increase
\key{parisize}, once the session is started. GP will try to {\it double} the
stack size by itself in case memory runs low during a given computation, but
this very computation will then be lost, and you will have to type the
command again.

\subsecidx{path} (default {\tt ".:\til:\til/gp"} on UNIX systems, and 
{\tt "."} otherwise): This is a list of directories, separated by colons ':'.
When asked to read a file, whose name does not contain \kbd{/} (i.e.~no
explicit path was given), GP will look for it in those directories, in the
order they were written in \key{path}. Here, as usual, '.' means the current
directory, and '$.\,.$', the one which lies directly above.

\unix The \kbd{\til} symbol has the same meaning as in the C-shell, that is:
\kbd{\til} by itself stands for your home directory, and \kbd{\til{}user} is
expanded to \kbd{user}'s home directory. This so-called \kbd{\til}-notation
is valid whenever a given character string represents a file name.

\subsecidx{primelimit} (default {\tt 200000} on the Mac, and {\tt 500000}
otherwise): GP precomputes a list of all primes less than \key{primelimit} at
initialization time. These will be used in many arithmetical functions
hereafter. If you don't plan to use any, you can just set this to 1.

\subsecidx{prompt} (default {\tt "? "}): a string that will be printed as
prompt. Note that most usual escape sequences are available there: \b{e} for
Esc, \b{n} for Newline, \dots, \kbd{\bs\bs} for \kbd{\bs}.

\unix This string is sent through the library function \kbd{\idx{strftime}}
(try {\tt man strftime} at your shell prompt). This means that \kbd{\%}
constructs have a special meaning, usually related to the time and date. For
instance, \kbd{\%H} = hour (24-hour clock) and \kbd{\%M} = minute [00,59] (use
\kbd{\%\%} to get a real \kbd{\%}).

\unix If you use \kbd{readline}, escape sequences in your prompt will result
in display bugs. If you have a relatively recent \kbd{readline} (see the
comment at the end of \secref{se:colors}), you can brace them with special
characters (defined in the file \kbd{readline.h}, usually \kbd{C-A} and
\kbd{C-B}), and you will be safe. If those just result in extra spaces in your
prompt, then you'll have to get a more recent \kbd{readline}. See the file
\kbd{lib/gprc.default} for an example.

\emacs {\bf Caution}: Do not tamper with the \key{prompt} variable 
{\it unless} you know how to write a {\tt gp-mode-hook} to set correctly the
{\tt gp-prompt-pattern} regexp in your \kbd{.emacs} file. As a matter of
fact, Emacs needs to know about the prompt pattern to separate your
input from previous GP results, without ambiguity. It's not a trivial problem
to adapt automatically this regexp to an arbitrary prompt (which can be
self-modifying !). Thus, in this version \vers, Emacs relies on the prompt
being the default one.

\subsecidx{psfile} (default {\tt "pari.ps"}): name of the default file where
GP is to dump the postcript drawings (these will always be appended, so that
no previous data are lost).

\subsecidx{realprecision} (default {\tt 28} and {\tt 38} on 32-bit and 64-bit
machines respectively): the number of significant digits and, at the same
time, the number of printed digits of real numbers (see~\b{p}).

\subsecidx{seriesprecision} (default {\tt 16}): precision of power series
(see~\b{ps}).

\subsecidx{simplify} (default {\tt 1}): this is a toggle which can either be
1 (on) or 0 (off). When the PARI library makes a computation, the type of the
result is not always the simplest possible. The only type conversions which
the PARI library does automatically are rational numbers to integers (when
they are of type \typ{FRAC} and equal to integers), and similarly rational
functions to polynomials (when they are of type \typ{RFRAC} and equal to
polynomials). This feature is useful in many cases, and saves time, but can
be annoying at times. Hence you can disable this and, whenever you feel like
it, use the function \key{simplify} (see Chapter 3) which allows to simplify
objects to the simplest possible types recursively (see~\b{y}).
\sidx{automatic simplification}

\subsecidx{strictmatch} (default {\tt 1}): this is a toggle which can either
be 1 (on) or 0 (off). If on, unused characters after a sequence has been
processed will produce an error. Otherwise just print a warning. This can be
useful when you're not sure how many parentheses you have to close after
complicated nested loops.

\subsecidx{timer} (default {\tt 0}): this is a toggle which can either be 1
(on) or 0 (off). If on, time every instruction sequence (anything ended by a
newline in your input). The timer counts electrical cycles, so is precise
only to $\pm20$ms in Europe and $\pm16.7$ms in North America. The time
measured is the user \idx{CPU time}, {\it not} including the time for
printing (see \kbd{\#} and \kbd{\#\#}).

\subsec{Note on the output formats.}

A zero real number is printed in \kbd{e} format as $0.Exx$ where $xx$ is
the (usually negative) {\it decimal\/} exponent of the number (cf. 1.2.6.).
This allows the user to check the accuracy of the zero in question (this
could also be done using \b{x}, but it would be more technical).

When the integer part of a real number $x$ is not significant because the
exponent of $x$ is greater than the internal precision, the real number is
printed in \kbd{e} format (note that in versions before 1.38.93, this was
instead printed with a $*$ at the end).

Note also that a number of type integer or real is written without
enclosing parentheses, while most other types have them. Hence, if you see
printed the expression $( 3.14 )$, it is not of type real, but probably of
type complex with zero imaginary part (if you want to be sure, type
\b{x} or use the function \key{type}).

Finally note that in the present version \vers, the printing of $0$, $1$, and
$-1$ as coefficients in beautified format, although understandable, is buggy.
Hence the default is the \kbd{prettymatrix} format until this is improved.

\label{se:meta}
\section{Simple metacommands.}

Simple metacommands are meant as shortcuts and should not be used in GP
scripts (see \secref{se:programming}). Beware that these, as all of GP input,
are now {\it case sensitive}. For example, \b{Q} is no more identical to
\b{q}. In the following list, braces are used to denote optional arguments,
with their possible default value, e.g $\{n=0\}$ means that if $n$ is not
there, it is assumed to be $0$. The space (or spaces) between the metacommand
and its arguments and between the argument themselves is optional (this can
cause problems only with \b{w}, when you insist on having a filename whose
first character is a digit. In this case, just use the underlying \key{write}
function, see \secref{se:write}).

\subsec{{\tt ?}} $\{{\tt command}\}$: GP on-line help interface.
As already mentioned, if you type \kbd{?$n$} where $n$ is a number from 1
to 11, you will get the list of functions in Section $3.n$ of the manual
(the list of sections being obtained by simply typing \kbd{?}).
\label{se:exthelp}

These names being in general not informative enough, more can be obtained by
typing \kbd{?command}, which gives in short form the effect of the command.
Of course, to have complete information, read Chapter 3 of this manual (the
source code is still at your disposal as well, though a trifle less readable
!). Much better help can be obtained if you work under GNU Emacs (see
\secref{se:emacs}).

\unix If you have \kbd{perl} installed on your system, GP was told about
it at compile time, and the whole PARI distribution was correctly installed,
you can double the \kbd{?} sign (i.e.~type \kbd{??command}) to get extended
help (the line before the copyright message indicates whether this is the
case). You then get the function description exactly as it stands in Chapter
3. This is much more powerful than the short help, as this feature knows
about operators as well: you can type \kbd{??*} or \kbd{??\&\&}, whereas a
single \kbd{?} would just yield a not too helpful {\tt unknown identifier}
message. Also, you can ask for extended help on section number $n$ in chapter
3, just by typing \kbd{??$n$} (where \kbd{?$n$} would yield the list of
commands). Finally, a few key concepts in GP are documented in this way. For
instance \kbd{??readline} will give a short summary of line editor commands.

\unix In fact this functionality is provided by an external \kbd{perl} script
that you can use at will outside any GP session (and modify to your liking,
if you are perl-knowledgeable). It is called \kbd{\idx{gphelp}}, lies in
the \kbd{perl} subdirectory of your distribution (just make sure you run
\kbd{Configure} first, see Appendix~A) and is really two programs in one. The
one which is used from within GP is \kbd{gphelp} (runs \TeX\ on a selected
part of this manual, then opens a previewer), while {\tt gphelp -detex} is a
primitive text mode equivalent. The default \key{help} selects the one which
will be used from within GP. You are welcome to improve this help script, or
write new ones (and we really would like to know about it so that we may
include them in future distributions). By the way, outside of GP you can give
more than one keyword as argument to \kbd{gphelp}.

\subsec{{\tt /*...*/}}: comment. Everything between the stars is ignored by
GP. This can span any number of lines.

\subsec{{\tt \bs\bs}}: one-line comment. The rest of the line
is ignored by GP.

\subsec{\b{a}} $\{n\}$: print the object number $n$ ($\%n$)
in raw format. If the number $n$ is omitted, print the latest computed object
($\%$). \label{se:history}

\subsec{\b{b}} $\{n\}$: Same as \b{a}, in prettyprint (i.e.~beautified)
format.

\subsec{\b{c}}: print the list of all available hardcoded
functions \sidx{available commands} under GP, not including functions using a
special character (specifically \kbd{+}, \kbd{-}, \kbd{*}, \kbd{/}, \kbd{\bs},
\kbd{\pow}, \kbd{!}, \kbd{\til}, \kbd{\%}, \kbd{\&\&}, \kbd{||}).

These names being in general not informative enough, more can be obtained
using the \kbd{?} metacommand (see above). For user-defined functions, see
\b{u}.

\subsec{\b{d}}: prints the \idx{defaults} as described in the
previous section (shortcut for \key{default()}, see \secref{se:default}).

\subsec{\b{e}}: switch the \key{echo} mode on and off.

\subsec{\b{g}} $\{n=0\}$: set the debugging level \key{debug}
to the non-negative integer $n$.

\subsec{\b{gm}} $\{n=0\}$: set the memory debugging level \key{debugmem}
to the non-negative integer $n$.

\subsec{\b{h}} $\{m-n\}$: output some debugging info about the hashtable.
Probably useless for you. If first argument is a number $n$, output the
content of cell $n$. Ranges can be given in the form $m-n$ (from cell $m$ to
cell $n$, \$ = last cell). If it's a function name, output info on its {\tt
entree} structure. If it's a dash ('--'), output statistics about hashcell
usage.

\subsec{\b{k}}: reinitialize GP, {\it without} reading the \kbd{.gprc} init
file and without forgetting the variables values. This is otherwise otherwise
equivalent to exiting from GP and starting it again (except of course that
variable names cannot be used for function definitions).

\subsec{\b{l}}: switch \key{log} mode on and off.

\subsec{\b{m}}: as \b{a}, but use prettymatrix format.

\subsec{\b{p}} $\{n\}$: sets \key{realprecision} to $n$ decimal
digits. Print its current value, if $n$ is omitted.

\subsec{\b{ps}} $\{n\}$: sets \key{seriesprecision} to $n$ significant terms.
Print its current value, if $n$ is omitted.

\subsec{\b{q}}: \idx{quit}s GP and returns to the system.
Shortcut for the function \key{quit} (see \secref{se:quit}).

\subsec{\b{r}} $\{${\it filename}$\}$: \idx{read} into GP all the objects
written on the named file using for example the \b{w} command (see below).
Shortcut for the function \key{read} (see \secref{se:read}). If {\it
filename} is omitted, re-read last input file in this session (fail if no
file was successfully read).

\unix This command accepts compressed files in \idx{compress}ed (\kbd{.Z})
or \idx{gzip}ped (\kbd{.gz} or \kbd{.z}) format. They will be uncompressed on
the fly as GP will read them, the actual files not being touched in the
process.

\subsec{\b{s}}: print the state of the PARI \idx{stack} and \idx{heap}.
This is used primarily as a debugging device for PARI, and is not intended
for the casual user.

\subsec{\b{t}}: print the \idx{internal longword format} of all the PARI
types. The detailed bit or byte format of the initial codeword(s) is
explained in the technical reference manual, but its knowledge is not
necessary for a GP user.

\subsec{\b{v}}: print the \idx{version number} type of implementation (680x0,
Sparc, Alpha, other) of the program you are using. In library mode, you can
use instead the two character strings \kbd{PARIVERSION} and \kbd{PARIINFO}
corresponding to the two first lines printed by GP just before the Copyright
message.

\subsec{\b{w}} $\{n\}$ $\{${\it filename}$\}$: \idx{write} the object number
$n$ ( $\%n$ ) on the named file, in raw format. If the number $n$ is
omitted, write the latest computed object ( $\%$ ). If {\it filename} is
omitted, append to \key{logfile} (the GP function \key{write} is a trifle more
powerful, as you can have filenames whose first character is a digit).

\subsec{\b{x}}: print the complete tree with addresses and contents in
hexadecimal of the \idx{internal representation} of the latest computed
object in GP. As for \b{s}, this is used primarily as a debugging device for
PARI. However, used on a PARI integer, it can be used as a
decimal$\rightarrow$hexadecimal converter.

\subsec{\b{y}}: switch \key{simplify} on or off.
\subsec{\kbd{\#}}: switch \key{timer} on or off.
\subsec{\kbd{\#\#}}: print the duration of last computation. Useful in case
you forgot to set \key{timer} on.

\section{Input formats for the PARI types.}

Apart from commands, the general input in GP after the prompt is a sequence
of legal expressions. Before describing this in detail in the next section,
let us see here how to input the different types of PARI.

Note that blanks are ignored in any expression which is not a string (see
below).

\subsec{Integers} \sidx{integer}
(type \typ{INT}\idxtyp{INT}): type the integer (with an initial
\kbd{+} or \kbd{-}, if desired) with no decimal point.

\subsec{Real numbers} \sidx{real number}
(type \typ{REAL}\idxtyp{REAL}): type the number with a decimal
point. The internal precision of the real number will be the supremum of the
input precision and the default precision. For example, if the default
precision is 28 digits, typing \kbd{2.} will give a number with internal
precision 28, but typing a 45 significant digit real number will give a
number with internal precision at least 45 (although less may be printed).

You can also use scientific notation with the letter \kbd{E} or
\kbd{e} (like {\tt 6.02 E 23} or {\tt 1e-5}).

\subsec{Integermods}\sidx{integermod}
(type \typ{INTMOD}\idxtyp{INTMOD}): to enter $n \mod m$, type
\kbd{Mod(n,m)}, {\it not} \kbd{n\%m} (see Chapter~3).

\subsec{Rational numbers}\sidx{rational number}
(types \typ{FRAC}\idxtyp{FRAC} and 
\typ{FRACN}\idxtyp{FRACN}): under GP, all fractions are
automatically reduced to lowest terms, so it is in principle impossible to
enter a reducible fraction (of type \typ{FRACN}), although of course in
library mode this is easy. To enter $n/m$ just type it as written. As
explained in \secref{se:gdiv}, division will {\it not} be performed, only
reduction to lowest terms.\label{se:FRAC}

If you really want a reducible fraction under GP, you must use the \key{type}
function (see \secref{se:gptype}), by typing \kbd{type(x,FRACN)}. Be warned
however that this function must be used with extreme care.

\subsec{Complex numbers}\sidx{complex number}
(type \typ{COMPLEX}\idxtyp{COMPLEX}): to enter $x+iy$, type {\tt
x + I*y} ({\it not} {\tt x+i*y}). The letter \kbd{\idx{I}} stand for
$\sqrt{-1}$. Recall from Chapter 1 that $x$ and $y$ can be of type 
\typ{INT}, \typ{REAL}, \typ{INTMOD}, \typ{FRAC}/\typ{FRACN}, or
\typ{PADIC}.

\subsec{$p$-adic numbers}\sidx{p-adic number}\label{se:padic}
(type \typ{PADIC}\idxtyp{PADIC}): to enter a $p$-adic number,
simply write a rational or integer expression and add to it 
{\tt O($p$ \pow $k$)}, where $p$ and $k$ are integers. This last expression
indicates three things to GP: first that it is dealing with a $p$-adic (the
fact that $p$ is an integer), second the ``prime'' $p$ (note that no
verification is done that $p$ is indeed prime; you can work on 10-adics if
you want, but beware of disasters as soon as you do something non-trivial
like taking a square root), and finally the number of significant $p$-adic
digits $k$.

For example, to obtain the $7$-adic number
\smallskip

\centerline{\tt 2*7\pow(-1) + 3 + 4*7 + 2*7\pow 2 + O(7\pow3){\rm ,}}

\noindent you can type it exactly as shown, or equivalently as
{\tt 905/7 + O(7\pow3)}.

\subsec{Quadratic numbers}\sidx{quadratic number}
(type \typ{QUAD}\idxtyp{QUAD}): first, you must define the
default quadratic order or field in which you want to work. This is done
using the \key{\idx{quadgen}} function, in the following way. Write something
like

\centerline{\tt w = quadgen(d)}

\noindent where \kbd{d} is the {\it discriminant} of the quadratic order in
which you want to work (hence $d$ is congruent to $0$ or $1$ modulo $4$). The
name \kbd{w} is of course just a suggestion, but corresponds to traditional
usage. You can of course use any variable name that you like. However,
quadratic numbers are always printed with a \kbd{w}, regardless of the
discriminant. So beware, two numbers can be printed in the same way and not
be equal. However GP will refuse to add or multiply them for example.

Then, $(1,w)$ will be the ``canonical'' integral basis of the quadratic order
(i.e.~$w=\sqrt{d}/2$ if $d\equiv 0 \mod 4$, and $w=(1+\sqrt{d})/2$ if
$d\equiv 1 \mod 4$, where $d$ is the discriminant), and to enter $x+yw$ you
just type {\tt x + y*w}.

\subsec{Polmods}\sidx{polmod} (type \typ{POLMOD}\idxtyp{POLMOD}):
exactly as for integermods, to enter $x \mod y$ (where $x$ and $y$ are
polynomials), type \kbd{Mod(x,y)}, not \kbd{x\%y} (see \secref{se:Mod}). Note
that
when $y$ is an
irreducible polynomial in one variable, polmods whose modulus is $y$ are
simply algebraic numbers in the finite extension defined by the polynomial
$y$. This allows us to work easily in \idx{number field}s, finite extensions
of the $p$-adic field $\Bbb Q_p$, or \idx{finite field}s.

\label{se:rempolmod}
{\bf Important remark.} Since the variables occurring in a polmod are not
free variables, it is essential in order to avoid inconsistencies that 
polmods use the same variable in internal operations (i.e.~between polmods)
and variables of lower priority (that appeared later in the GP session) 
for external operations (typically between a polynomial and a polmod). For
example, PARI will not recognize that {\tt Mod(y, y\pow2 + 1)} is the same
as {\tt Mod(x, x\pow2 + 1)} and {\tt x + Mod(x, x\pow2 + 1)} will give
exactly this as a result and not {\tt Mod(2*x, x\pow2 + 1)}.

  On the other hand, {\tt Mod(x, x\pow2 + 1) + Mod(x, x\pow2 + 1)}
(giving {\tt Mod(2*x, x\pow2 + 1)}) and {\tt x + Mod(y, y\pow2 + 1)} 
(giving a result mathematically equivalent to $\kbd{x} + i$ with 
$i^2=-1$) are completely correct, while {\tt y + Mod(x, x\pow2 + 1)}
gives {\tt Mod(x + y, x\pow2 + 1)}, which may not be what you want (\kbd{y}
is here treated as a numerical parameter, not as a polynomial variable).

\subsec{Polynomials}\sidx{polynomial}\label{se:pol}
(type \typ{POL}\idxtyp{POL}): type the polynomial in a natural
way, not forgetting to put a ``$*$'' between a coefficient and a formal
variable (this $*$ does not appear on beautified output). Any variable name
can be used except for the reserved names \key{I} (used exclusively for the
square root of $-1$), \key{Pi} ($3.14\dots$), \key{Euler} (Euler's constant)
as well as all the function names: predefined functions, as described in
Chapter 3 (use \b{c} to get the list of all of these) and user-defined
functions which you ought to know about (use \b{u} if you are subject to
memory lapses). The total number of different variable names is limited to
$16384$ and $65536$ on 32-bit and 64-bit machines respectively, which should
be enough. If you ever need hundreds of variables, you should probably use
vectors instead.

\subsec{Power series}\sidx{power series}
(type \typ{SER}\idxtyp{SER}): type a rational function or
polynomial expression and add to it $O(expr\hat{\ }k)$, where $expr$ is an
expression having a non-zero valuation, like a polynomial, power series, or a
rational function (the most common cases being simply $expr=$variable name).
This indicates to GP that it is dealing with a power series, and the desired
precision is $k$ times the valuation of $expr$ with respect to its main
variable (to check the ordering of the variables, or to modify it, use the
function \key{reorder} see \secref{se:reorder}).

\subsec{Rational functions}\sidx{rational function} 
(types \typ{RFRAC}\idxtyp{RFRAC} and 
\typ{RFRACN}\idxtyp{RFRACN}): as for fractions, all rational
functions are automatically reduced to lowest terms under GP. All that was
said about fractions in \secref{se:FRAC} remains valid here.

\subsec{Binary quadratic forms of positive or negative discriminant}%
\sidx{binary quadratic forms}
(type \typ{QFR}\idxtyp{QFR} and \typ{QFI}\idxtyp{QFI}):
those are input using the function \key{Qfb} (see Chapter 3). For example
{\tt Qfb(1,2,3)} will create the binary form $x^2+2xy+3y^2$. It will be
imaginary (of internal type \typ{QFI}) since $2^2 - 4*3 = -8 < 0$.

  In the case of forms with positive discriminant (type \typ{QFR}), you
may add an optional fourth component (related to the regulator, more
precisely to Shanks and Lenstra's ``distance'') which must be a real number.
See also the function \key{qfbprimeform} which directly creates a prime form
of given discriminant (see Chapter 3).

\subsec{Row and column vectors}\sidx{row vector}\sidx{column vector} (types
\typ{VEC}\idxtyp{VEC} and \typ{COL}\idxtyp{COL}): to
enter a row vector, type the components separated by commas ``\kbd{,}'', and
enclosed between brackets ``{\tt [}$\,$'' and ``$\,${\tt ]}'', e.g. 
{\tt [1,2,3]}. To enter a column vector, type the vector horizontally, and
add a tilde ``\til'' to transpose. \kbd{[ ]} yields the empty (row) vector.
The function \key{Vec} can be used to transform any object into a vector (see
Chapter 3).

\subsec{Matrices} (type \typ{MAT}\idxtyp{MAT}):\sidx{matrix} to
enter a matrix, type the components line by line, the components being
separated by commas ``\kbd{,}'', the lines by semicolons ``\kbd{;}'', and
everything enclosed in brackets ``{\tt [}$\,$'' and ``$\,${\tt ]}'', e.g.
{\tt [x,y; z,t; u,v]}. \kbd{[ ; ]} yields the empty (0x0) matrix. The
function \key{Mat} can be used to transform any object into a matrix (see
Chapter 3).

Note that although the internal representation is essentially the same (only
the type number is different), a row vector of column vectors is {\it not} a
matrix; for example, multiplication will not work in the same way.

\subsec{Lists} (type \typ{LIST})\idxtyp{LIST}:\sidx{list}
Lists cannot be input directly, you have to use the functions
\key{listcreate} first, then \key{listput} each type you want to append a
new element (of course you can access the elements directly as with the
vector types described above). The function \key{List} can be used to
transform (row or column) vectors into lists (see chapter 3).

\subsec{Strings} (type \typ{STR})\idxtyp{STR}:\sidx{string}%
\sidx{character string} to enter a string, just enclose it between double
quotes \kbd{"}, like this: {\tt "this is a string"}. The function \key{Str}
can be used to transform any object into a string (see Chapter 3)

\section{Strings and Keywords}\sidx{string}\sidx{keyword}
\label{se:strings}
GP variables can now contain character strings (internal type \typ{STR}).
This section describes how they are actually used, as well as some convenient
tricks (automatic concatenation and expansion, keywords) valid in string
context.

As seen above, the general way to input a string is to enclose characters
between quotes~{\tt"}. This is the only input construct where whitespace
characters are actually significant: the string will contain the exact number
of spaces you typed in. Besides, you can ``escape'' characters by putting a
\kbd{\bs} just before them; this has the following effect:

{
\def\q{\quad}
\obeylines
\q \b{e}: the \kbd{<Escape>} character.
\q \b{n}: the \kbd{<Newline>} character.
\q \b{t}: the \kbd{<Tab>} character.
\q \b{any-other-char}: the {\tt any-other-char} character.
}
In particular, the only way to put a \kbd{"} in a string is to escape it.
Thus, for instance, {\tt "\bs"a\bs""} would produce the
string whose content is "a". This is definitely {\it not} the same thing as
typing \kbd{"a"} whose content is merely the letter a.

\noindent Here is a non trivial example, used to create generic matrices
under GP:

{ \tt
? genmat(u,v,s="x") = matrix(u,v,i,j, eval( concat(concat(s,i),j) ))

?  genmat(2,3) + genmat(2,3,"m")

\%1 = 

[x11 + m11 x12 + m12 x13 + m13]

[x21 + m21 x22 + m22 x23 + m23]

}

Some functions expect strings for some of their arguments: \key{print} would
be an obvious example (see Chapter 3, section 11 for a complete list). While
typing in such an argument, you will be said to be in {\it string context}.
The rest of this section is devoted to special syntactical tricks usable for
such arguments (and only here, you will get an error message if you try
these outside of string context):

$\bullet$ Writing two strings alongside one another will just concatenate
them, producing a longer string. Thus it is equivalent to type in 
{\tt "a " "b"} or {\tt "a b"}. A little tricky point in the first expression:
the first whitespace is enclosed between quotes, and so is part of a string;
while the second one (before the {\tt "b"}) is completely optional and GP
actually suppressed it, as it would with any number of whitespace characters
at this point (i.e.~outside of any string).

$\bullet$ If you insert an expression without quotes when GP expects a
string, it gets ``expanded'': it is evaluated as a standard GP expression,
and the final result (as would have been printed if you had typed it by
itself) is then converted to a string, as if you had typed it directly. Thus
{\tt "a"1+1"b"} is equivalent to {\tt "a2b"}: three strings get created, the
middle one being the expansion of {\tt 1+1}, and these are then concatenated
according to the rule described above. Another tricky point here: assume you
did not assess a value to {\tt aaa} in a GP expression before. Then typing
{\tt aaa} by itself in a string context will actually produce the correct
output (i.e.~the string whose content is aaa), but in a fortuitous way. This
{\tt aaa} gets expanded to the monomial of degree one in the variable {\tt
aaa}, which is of course printed as {\tt aaa}, and thus will expand to the
three letters you were expecting. But you will have defined a variable as a
side effect.

$\bullet$ Because of those cases where expansion is not really desirable, we
now distinguish between ``Keywords'' and ``Strings''. String is what has been
described so far. Keywords are special relatives of Strings which are
automatically assumed to be quoted, whether you actually type in the quotes
or not. Thus expansion is never performed on them. They get concatenated,
though. The analyzer supplies automatically the quotes you have ``forgotten''
and treat Keywords just as normal strings otherwise. For instance, if you
type {\tt "a"b+b} in a Keyword context, you will get the string whose content
is ab+b. Whereas in a String context, you would get a2{\tt *}b (and you would
have created a variable \kbd{b} in the process, but no variable \kbd{a}).

All GP functions have prototypes (described in Section 3 hereafter) giving
the precise kind of arguments they expect: either generic PARI objects (GEN),
or strings, or keywords. In the latter case, only a very small set of words
will actually be significant (the \key{default} function is the prominent
example).

Let's now try some not-so-stupid exercises to get the hang of it. Try to
guess the result of the following commands without actually typing them,
assuming that the \key{print} command prints its (string) arguments in order,
ending with a newline (giving 0 as an unprinted result):

\bprog
\q print()
\q print(1+3"a,3" ,4)
\q print(a=3, (1 + ((a-3)==print())) (a = (a == 5\bs/2)))
\q default("""pr"o"mpt"," \bs e["3\bs 2"mgp\bs e[m > ")
\eprog
For the last (admittedly horrible) one, assume that the first argument of the
\key{default} function is a Keyword (belonging to the set of default names,
as described in \secref{se:defaults}). Whereas its second argument is a
genuine String, which thus gets expanded.

\section{GP \idx{operators}}\label{se:operators}

  Loosely speaking, an operator is a function (usually associated to basic
arithmetic operations) whose name contain only non-alphanumeric characters.
In practice, they all are simple functions, which take arguments, and return a
value. These are internally ordered according to some priority value, which
means that, in a given expression, the operations with the highest priority
will be performed first. Those having the same priority will be performed in
the order they were written, i.e.~from left to right. Anything enclosed
between parenthesis is considered as a complete expression, and will be
resolved independently, regardless of surrounding context. For instance,
assuming that $op_1<op_2<op_3$ are standard binary operators (think of
\kbd{+}, \kbd{*}, \kbd{\pow} for instance),

$$ x~op_1~y~op_2~z~op_2~x~op_3~y $$
is equivalent to
$$ x~op_1~((y~op_2~z)~op_2~(x~op_3~y)).$$

  GP knows quite a lot of different operators, some of them unary (having
only one argument), some binary. Unary operators are defined for either
prefix (before its argument $op~x$), or postfix ($x~op$) position, never both
(some are syntactically correct in both positions, but with different
meanings). Binary operators all use the syntax $x~op~y$. Most of them are
well known, some are borrowed to the C syntax, and a few are specific to
GP. Beware that some GP operators may differ slightly from their C
counterparts. For instance the postfix \kbd{++} which returns the {\it new}
value, after the addition has taken place or the binary shifts \kbd{<<},
\kbd{>>} which have a different (higher) priority than their C counterparts.
When in doubt, just surround everything by parentheses (besides, your code
will probably be more legible).

\noindent Here is the complete list (listed by decreasing priority, binary
unless mentioned otherwise):

\sidx{priority}
\noindent $\bullet$ Priority 9

\kbd{++} and \kbd{--} (unary, postfix): \kbd{$x$++} affects the value $x+1$ to
$x$, then returns the new value of $x$. This corresponds to the C
statement \kbd{++$x$} (there is no prefix \kbd{++} operator in GP). 
\kbd{$x$--} does the same with $x-1$.

\noindent$\bullet$ Priority 8

\kbd{$op$=}, where $op$ is any simple binary operator (by definition: the
ones with no side effect, i.e.~the ones defined below) which is not a truth
operator (comparison or logical). {\tt x $op$= y} does the affectation 
{\tt x = $(\kbd{x}~op~\kbd{y})$}, then return the new value of \kbd{x}. 

\noindent$\bullet$ Priority 7

\kbd{=}: assignment operator. The result of \kbd{$x$ = $y$} is $y$. This in
{\it not} the equality test operator. Beware that the statement \kbd{x = 1}
is always true (ie non-zero) for instance, and sets \kbd{x} to 1.

\noindent$\bullet$ Priority 6

\kbd{!} (unary, prefix): logical {\it not}. \kbd{!$x$} return $1$ if $x$ is
equal to $0$ (specifically, if {\tt gcmp0(x)==1}). And $0$ otherwise.

\noindent$\bullet$ Priority 5

\kbd{\pow}: powering.

\kbd{'} (unary, postfix): derivative with respect to main variable.

\strut\kbd{\hbox{\til}} (unary, postfix): matrix transpose.

\kbd{!}: (unary, postfix): factorial. $\hbox{\kbd{$x$!}}=x(x-1)\cdots 1$.

\kbd{.}: \kbd{x.$b$} extracts member $b$ from structure \kbd{x}

\noindent$\bullet$ Priority 4

\kbd{+}, \kbd{-} (unary, prefix): \kbd{-} toggles sign of its argument,
\kbd{+} has no effect whatsoever.

\noindent$\bullet$ Priority 3

\kbd{*}: multiplication.

\kbd{/}: exact division (\kbd{3/2}=$3/2$, not $1.5$).

\kbd{\bs}, \kbd{\%}: euclidean quotient and remainder, i.e.~if $x =
qy + r$, with $0\leq r < y$ (if $x$ and $y$ are polynomials, assume instead
that $\deg r< \deg y$ and that the leading terms of $r$ and $x$ share the
same sign). Then $\kbd{x \b{} y} = q$, $\kbd{x\%y} = r$.

\kbd{\bs/}: rounded euclidean quotient for integers (rounded toward
$+\infty$ in case of tie).

\kbd{<<}, \kbd{>>}: left and right binary shift. {\tt x<<n}$\, = x * 2^n$
if $n>0$, and $x \b{/} 2^{-n}$ otherwise.
Whereas {\tt x>>n}$\, =\, $ {\tt x<<(-n)}.

\noindent$\bullet$ Priority 2

\kbd{+}, \kbd{-}: addition/substraction.

\noindent$\bullet$ Priority 1

\kbd{<}, \kbd{>}, \kbd{<=}, \kbd{>=}: the usual comparison operators,
returning 1 for \kbd{true} and 0 for \kbd{false}. For instance,
\kbd{x<=1} returns $1$ if $x\le 1$ and $0$ otherwise.

\kbd{<>}, \kbd{!=}: test for (exact) inequality.

\kbd{==}: test for (exact) equality.

\noindent$\bullet$ Priority 0

\kbd{\&}, \kbd{\&\&}: logical {\it and}. 

\kbd{|}, \kbd{||}: logical (inclusive) {\it or}. Any sequence of logical
{\it or} and {\it and} is evaluated from left to right, and aborted whenever
the final truth value is determined. Thus, for instance,
{\tt (x \&\& 1/x)} or {\tt (type(p) == "t\_INT" \&\& isprime(p))} will never
produce an error for the second argument need not (and will not) be processed
when the first is already \kbd{false}.

\noindent {\bf Remark:} For efficiency's sake, you should use the \kbd{++},
\kbd{--} and $op\kbd{=}$ operators as much as possible:

\bprog
? a=200000;
? i=0; while(i<a, i=i+1)
time = 4,919 ms.
? i=0; while(i<a, i+=1)
time = 4,478 ms.
? i=0; while(i<a, i++)
time = 3,639 ms.
\eprog

\noindent As well, the shift operators should be prefered to multiplication,
whenever possible:

\bprog
? a=1<<20000;
? i=1; while(i<a, i=i*2);
time = 5,255 ms.
? i=1; while(i<a, i<<=1);
time = 988 ms.
\eprog

\section{The general GP input line.}

A general GP session goes as follows: a sequence of characters is typed by
the user after the prompt. This can be either a function definition, or an
expression or a sequence of expressions (i.e.~a program). In this case, after
the last expression is computed the result is put in an internal array. The
successive elements of this array are called \kbd{\%1}, \kbd{\%2}, \dots As a
shortcut, the last computed expression can also be called \kbd{\%}, the one
before \kbd{\%`}, the one before \kbd{\%``} and so on.

  If you want to suppress the printing of the result, for example because it
is a long unimportant intermediate result, end the expression with a 
\kbd{;} sign. This same sign is used as an instruction separator when several
instructions are written on the same line (note that for the sake of BASIC
addicts the \kbd{:} sign can also be used, but we will try to keep
C-style conventions). Note that the final expression you have computed, even
if not printed, still has been assessed an internal name (\kbd{\%1},
\kbd{\%2}, \dots), so care must be used when using it subsequently since its
number does not appear explicitly. Of course, if it is simply used on the
next line, use \kbd{\%} as usual.

Any legal expression can be typed, and it is evaluated using the
conventions about operator priorities and left to right evaluation (see
previous section), using the available operator symbols, function names
(including user-defined functions), and special variables. Please note that,
from version $1.900$ on, there\sidx{case distinction} {\it is} a distinction
between lowercase and uppercase. Also, note that, outside of constant
strings, blanks are completely ignored in the input to GP.

The special variable names used by GP are \kbd{\idx{Euler}} (Euler's
constant=0.577\dots), \kbd{\idx{I}} (the square root of $-1$), \kbd{\idx{Pi}}
(3.14\dots), which are really functions without parameters, and \kbd{\idx{O}}
whose syntax is the following:

\centerline{\tt O(expr\pow k)}

When $expr$ is an integer or a rational number, this creates an
\kbd{expr}-adic number (zero in fact) of precision \kbd{k}. When \kbd{expr}
is a polynomial, a power series or a rational function whose main variable is
$X$, say, this creates a power series (also zero) of precision $v*\kbd{k}$
where $v$ is the $X$-adic valuation of \kbd{expr} (see \ref{se:padic} and 
\ref{se:pol}).

\sectionunix{The \kbd{.gprc} \sidx{gprc} file}
\label{se:gprc}
When GP is started, it first looks whether the environment variable
\idx{GPRC} is set. If you want this to be the case you can do something like:

{\tt GPRC=/my/dir/anyname; export GPRC}\quad in \kbd{sh} syntax (for
instance in your \kbd{.profile}).

{\tt setenv GPRC /my/dir/anyname}\quad in \kbd{csh} syntax (in your
\kbd{.login} or \kbd{.cshrc} file).

If not, it checks wether there exists a file called \kbd{.gprc} in your home
directory (whose name starts with a '.' and thus won't get listed with
regular 'ls' commands, you need to type 'ls -a' to see if it's already there
without your knowing about it).

In either case, GP will open the corresponding file and process the commands
in there, {\it before} doing anything else, e.g. creating the PARI stack. It
will just proceed to do its usual initialization and prompting otherwise.
If any explicit line command switch is given, this overrides the value
read from the \kbd{.gprc} file.

The syntax in this file (and valid in this file only, at this very precise
moment!) is simple-minded, but should be sufficient for most purposes; it can
contain exactly three types of lines:

$\bullet$ lines starting with {\tt \bs\bs} are comments and are completely
ignored.

$\bullet$ lines of the form {\tt default = value} (whitespace is optional as
usual), where \kbd{default} is one of the available defaults (see 
\secref{se:defaults}), which shall assume the given \kbd{value} on actual
startup. Don't forget the quotes around strings (e.g. for \key{prompt} or
\key{help}).

$\bullet$ lines of the form {\tt read "some\_GP\_file"} where
{\tt "some\_GP\_file"} is a regular GP script this time, which will
be read just before GP prompts you for commands, but after initializing the
defaults. This is the right place to put in \key{alias} commands, or
favorite macros.

A sample \kbd{.gprc} file called \kbd{gprc.default} is provided in the
standard distribution (in directory \kbd{lib}).

\section{Interfacing GP with other languages}
The PARI library was meant to be interfaced with C programs. This specific
use will be dealt with extensively in Chapter 4. GP itself provides a
convenient, if simple-minded, interpreter, which enables you to execute
rather intricate scripts (see \secref{se:programming}).

Scripts, when properly written, tend to be shorter and much clearer than C
programs, and are certainly easier to write, maintain or debug. You don't
need to deal with memory management, garbage collection, pointers,
declarations, and so on. Because of their intrinsic simplicity, they are more
robust as well. They are unfortunately much slower. Thus their use will
remain complementary: it is suggested that you test and debug your algorithms
using scripts, before actually coding them in C for the sake of speed.

We are aware of two public domain libraries \kbd{PariPerl}
\footnote{*}{
see {\tt http://nswt.tuwien.ac.at:8000/htdocs/internet/unix/perl/math-pari.html
}},
%
\sidx{PariPerl} and \kbd{PariPython}
%
\footnote{**}{
see {\tt http://www.math.jussieu.fr/\til{}fermigie/PariPython/readme.html}
}
%
\sidx{PariPython},
respectively written by Ilya Zakharevich ({\tt ilya@math.ohio-state.edu})
and St\'efane Fermigier ({\tt Stefane.Fermigier@ens.fr}), that provide an
interface to GP functions for use in \kbd{perl} or \kbd{python} programs.

 {\it We neither endorse nor support any of these}. You might want to give
them a try though, if you are familiar with either one of those languages.
\sidx{Perl}\sidx{Python}
\vfill\eject
