2
<#38#>
=titlepage;''<#38#>
=1
by1=0
<#3048#><#3048#>
<#3049#>=0<#3051#><#3051#><#3049#>
Chapter : Overview of the <#3052#><#3060#><#3060#>PARI<#3052#> System
by1=0
<#3062#>=0<#3064#><#3064#><#3062#>
<#3063#><#3065#>. Introduction.<#3065#><#3063#>
The PARI system is a package which is capable of doing formal computations
on recursive types at high speed; it is primarily aimed at number
theorists, but can be used by people whose primary need is speed.
Although quite an amount of symbolic manipulation is possible in PARI, this
system does very badly compared to much more sophisticated systems like
Reduce, Macsyma, Maple, Mathematica or Scratchpad (now Axiom) on such
manipulations (e.g. multivariate
polynomials, formal integration, etc...). On the other hand, the two
main advantages of the system is its speed (which can be between 5 and
100 times better on many computations than the above mentioned systems),
and the possibility of using directly data types which are familiar
to mathematicians.
It is possible to use PARI in two different ways:
;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;1) as a library, which can be called from any upper-level language
application (for instance written in C, C+ +, Pascal or Fortran);
;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;2) as a sophisticated programmable calculator, named <#41#>GP<#41#>, which
contains most of the standard control instructions of a standard language
like C.
The use of GP is explained in chapters 2 and 3, and the programming in library
mode is explained in chapters 3 and 4. In the present chapter 1, we give
an overview of the system.
<#3068#>=0<#3070#><#3070#><#3068#>
<#3069#><#3071#>Implementation notes.<#3071#><#3069#>
Version 1.37of the PARI package contains essentially four versions. The
first one is a specific implementation for 68020/68030/68040 based computers
which contains a kernel (for
the elementary arithmetic operations on multiprecise integers and real numbers,
and binary/decimal conversion routines) entirely written in MC68020 assembly
language (around 7000 lines), the rest being at present entirely written in C
(although we are now looking into C++).
The system runs on SUN-3/xx, Sony News, NeXT cubes and on the Macintosh II.
It should be very easy to port on any other 680x0 based machine
like for instance the Apollo Domain workstations.
Note that the assembly language source code uses the SUN syntax,
which for some strange reason differs from the Motorola standard used by
most other 680x0 machines in the world. On the Mac II disquettes, we have
included a program which automatically converts
from the SUN syntax into the standard one, at least for the needed PARI
assembly file. On the Unix distribution, we have included other versions
of the assembly file, using different syntaxes.
The second version is a specific implementation for SPARC version 7 based
workstations, like the SPARCstation 1, 1+, 2 and the Solbourne 4000. This
version contains only a few hundred lines of assembly code, and is usually
slightly faster on the SPARCstation 1+ than on a SUN-3/60 or SUN-3/80.
A version for SPARC version 8 is included, but has not been tested at this time
due to the late delivery of such chips.
The third version is a specific implementation for the Hewlett-Packard HP-PA
architecture. Like the Sparc version, this contains a few hundred lines of
assembly code, and is quite fast.
Finally, a fourth version is written entirely in C, and should be portable with
not too much trouble to any 32-bit computer having no real memory constraints
It is again at least 2 times slower than the SPARC version. This version has
been tested for example on the DECstations 3100 and 5000.
In addition to Unix workstations and MacII, Pari has been ported to a
considerable number of smaller and larger machines, for example the VAX,
68000-based machines like the Atari, Mac Classic or Amiga 500, 68020 machines
such as the Amiga 2500 or 3000, and even to MS-DOS 386 or better machines,
using the <#43#>djgpp<#43#> port of the GNU C compiler and DOS-extender.
by1=0
<#3082#>=0<#3084#><#3084#><#3082#>
<#3083#><#3085#>. The PARI <#3092#><#3092#>types.<#3085#><#3083#>
The crucial word in PARI is <#3094#><#3094#>recursivity: most types
which are handled are recursive. For example, the basic type <#2703#><#3096#><#3096#>Complex<#2703#> exists. However, the components (i.e. the real and imaginary part)
of
such a ``complex number'' can be of any type. The only sensible ones are
integers
(we are then in #math28##tex2html_wrap_inline24630#[i]), rational numbers (#math29##tex2html_wrap_inline24632#[i]), real numbers
(#math30##tex2html_wrap_inline24634#[i] = #tex2html_wrap_inline24635#), or even elements of #math31##tex2html_wrap_inline24637#/n#tex2html_wrap_inline24638#
(#math32#(#tex2html_wrap_inline24640#/n#tex2html_wrap_inline24641#)[i] when this makes sense), or p-adic numbers when
#math33#p≡3 mod 4 (#math34##tex2html_wrap_inline24647#[i]).
This feature must of course not be used too rashly: for example you
are in principle allowed to create objects which are ``complex numbers of
complex numbers'', but don't expect PARI to make sensible use of such
objects: you will mainly get nonsense.
On the other hand, one thing which <#48#>is<#48#> allowed is to have components
of different, but compatible, types. For example, taking again complex
numbers, the real part could be of type integer, and the imaginary part
of type rational.
By compatible, we mean types which can be freely mixed in operations like
+ or *. For example if the real part is of type real, the imaginary
part cannot be of type integermod (integers modulo a given number n).
Let us now describe the types. As explained above, they are built
recursively from basic types which are as follows. We use the letter T
to designate any type; the type number corresponds to the internal
representation of the type.
xxx;SPMamp;typexxxxxx;SPMamp;xxxxxxxxxxxxxxxxxxx;SPMamp;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxx
;SPMamp;type 1:;SPMamp; #tex2html_wrap_inline24653#;SPMamp; <#3109#><#3109#>Integers (with arbitrary precision)
;SPMamp;type 2:;SPMamp; #tex2html_wrap_inline24655#;SPMamp; <#3112#><#3112#>Real numbers (with arbitrary precision)
;SPMamp;type 3:;SPMamp; #math35##tex2html_wrap_inline24657#/n#tex2html_wrap_inline24658#;SPMamp; <#3116#><#3116#>Integermods (integers modulo n)
;SPMamp;type 4:;SPMamp; #tex2html_wrap_inline24661#;SPMamp; <#3119#><#3119#>Rational numbers (in irreducible form)
;SPMamp;type 5:;SPMamp; #tex2html_wrap_inline24663#;SPMamp; Rational numbers (in non necessarily irreducible form)
;SPMamp;type 6:;SPMamp; T[i];SPMamp; <#3122#><#3122#>Complex numbers
;SPMamp;type 7:;SPMamp; #tex2html_wrap_inline24668#;SPMamp; p-adic<#3125#><#3125#> numbers
;SPMamp;type 8:;SPMamp; T[w];SPMamp; <#3127#><#3127#>Quadratic numbers (where #math36#[#tex2html_wrap_inline24672#[w] : #tex2html_wrap_inline24673#] = 2)
;SPMamp;type 9:;SPMamp; #math37#T[X]/P(X)T[X];SPMamp; <#3131#><#3131#>Polymods (polynomials modulo P)
;SPMamp;type 10:;SPMamp; T[X];SPMamp; <#3133#><#3133#>Polynomials
;SPMamp;type 11:;SPMamp; T((X));SPMamp; <#3135#><#3135#>Power series (finite Laurent series)
;SPMamp;type 13:;SPMamp; T(X);SPMamp; <#3137#><#3137#>Rational functions (in irreducible form)
;SPMamp;type 14:;SPMamp; T(X);SPMamp; Rational functions (in non necessarily irreducible
form)
;SPMamp;type 17:;SPMamp; Tn;SPMamp; Row (i.e. horizontal) <#3139#><#3139#>vectors
;SPMamp;type 18:;SPMamp; Tn;SPMamp; Column (i.e. vertical) <#3141#><#3141#>vectors
;SPMamp;type 19:;SPMamp; #math38##tex2html_wrap_inline24685#m, n(T);SPMamp; Matrices.<#3143#><#3143#>
In addition, there exist type 15 for binary quadratic forms of positive
discriminant, type 16 for binary quadratic forms of negative discriminant
<#3145#><#3145#>
which can be used in specific operations, but which may disappear in future
versions, hence their use is not documented in this manual.
Let us look closely at these types.
by 1=0
<#3147#>=0<#3149#><#3149#><#3147#>
<#3148#><#3150#>.. Integers and reals<#3150#><#3148#>:<#3154#><#3154#><#3156#><#3156#>
they are of arbitrary and varying length
(each number having coded
internally its own length or precision) with the following mild restrictions:
integers must be in absolute value less than #math39#21048480 (i.e. roughly
315623 digits).
The precision of real numbers is also at most 315623 significant decimal
digits, and the
binary exponent must be in absolute value less than #math40#223 = 8388608.
Note that PARI has been optimized so that it works as fast as possible on
numbers with
40 to 100 decimal digits. In particular, no fancy multiplication technique is
used.
Hence, although it is possible to use PARI to do computations with 300000
decimal digits, much better programs can be written for these loooong numbers.
Integers and real numbers are completely non recursive types and are sometimes
called the <#2704#><#3158#><#3158#>leaves<#2704#>.
by 1=0
<#3160#>=0<#3162#><#3162#><#3160#>
<#3161#><#3163#>.. Integermods, rational numbers (irreducible or not),
p-adic numbers, polymods, and
rational functions<#3163#><#3161#>:<#3167#><#3167#><#3169#><#3169#><#3171#><#3171#>
<#3173#><#3173#> they are recursive, but in a forced manner:
For integermods or polymods, there are two components: the modulus, which
must be of type integer (resp. polynomial), and the number (or polynomial).
For rational numbers or rational functions, there are also only two
components: the numerator
and the denominator, which must both be of type integer (resp. polynomial).
Finally, p-adic numbers have three components: the prime p, the
``modulus'' pk,
and an approximation to the p-adic number. Here #tex2html_wrap_inline24697# is considered as
#math41##tex2html_wrap_indisplay24699##tex2html_wrap_inline24700#/pk#tex2html_wrap_inline24701#, and #tex2html_wrap_inline24705# as its field of fractions.
Like real numbers, the codewords contain also the information on the
precision
of the number (which is in fact redundant with pk, but it is apparently more
efficient to keep this redundancy).
by 1=0
<#3181#>=0<#3183#><#3183#><#3181#>
<#3182#><#3184#>.. Complex numbers (a + bi) and quadratic numbers<#3184#><#3182#>: <#3188#><#3188#>
<#3190#><#3190#>quadratic numbers are numbers of the form a + bw,
where w is such that #math42#[#tex2html_wrap_inline24712#[w] : #tex2html_wrap_inline24713#] = 2, and more precisely #math43#w = #tex2html_wrap_inline24715#/2 when
#math44#d≡0 mod 4, and #math45#w = (1 + #tex2html_wrap_inline24718#)/2 when #math46#d≡1 mod 4, where d
is
the discriminant of a quadratic order.
Complex and quadratic numbers are partially recursive: the two components
a and b can be of type integer, real, rational, integermod or p-adic,
and can
be mixed, subject to the limitations mentioned above. For example,
a + bi with a and b p-adic is in #math47##tex2html_wrap_inline24731#[i], but this is equal to
#tex2html_wrap_inline24735#
when #math48#p≡1 mod 4, hence we must exclude these p when one explicitly
uses
a complex p-adic type.
by 1=0
<#3199#>=0<#3201#><#3201#><#3199#>
<#3200#><#3202#>.. Polynomials, power series, vectors and matrices<#3202#><#3200#>:
<#3206#><#3206#><#3208#><#3208#><#3210#><#3210#><#3212#><#3212#>
they are completely recursive:
their components can be of any type, and types can be mixed
(however beware when doing operations). Note in particular that a polynomial
in two variables is simply a polynomial with polynomial coefficients.
Note that in the present version 1.37of PARI, there is a bug in the handling
of power series of power series (i.e. power series in several variables).
However power series of polynomials (which are power series in several
variables of a special type) are OK. The reason for this bug is known,
but it is difficult to correct because the mathematical problem itself
contains some amount of imprecision.
by 1=0
<#3214#>=0<#3216#><#3216#><#3214#>
<#3215#><#3217#>.. Exact and imprecise objects<#3217#><#3215#>: <#3221#><#3221#>we have already
said that integers and reals are called the <#3223#><#3223#>leaves because they are
ultimately
at the end of every branch of a tree representing a PARI object. Another
important notion is that of an <#2705#><#3225#><#3225#>exact object<#2705#>: by definition,
numbers of basic type real, p-adic or power series are imprecise, and we
will
say that a PARI object having one of these imprecise types anywhere in its
tree
is not exact. All other PARI objects will be called exact. This is a very
important notion since no numerical analysis is involved when dealing with
exact objects.
by 1=0
<#3235#>=0<#3237#><#3237#><#3235#>
<#3236#><#3238#>.. What is <#3246#><#3246#>zero?<#3238#><#3236#>: this is a crucial question in all computer
systems. The answer we give in PARI is the following. For exact types,
all zeros are equivalent and are exact, so are usually represented as
an integer zero. The problem becomes
nontrivial for imprecise types. For p-adics the answer is as
follows: every p-adic number (including 0) has an exponent e and a
``mantissa'' u which is a p-adic unit, except when the number is zero (in
which case u is zero), the mantissa having a certain ``precision'' k (i.e.
is defined modulo pk). Then this p-adic zero is understood to be
equal to O(pe), i.e. there is an infinite number of zeros. The number k
is thus irrelevant.
For power series the situation is similar, with p replaced
by X, i.e. a power series zero will be O(Xe), the number k (here the
length of the power series) being also irrelevant.
For real numbers, the precision k is also irrelevant,
and a real zero will in fact be O(2e) where e is now usually a
negative binary exponent. This of course will be printed as usual for
a real number (#math49#0.0000 ... in <#90#>f<#90#> format or 0.Exx in <#91#>e<#91#> format)
and not with a O() symbol as with p-adics or power series.
by 1=0
<#3248#>=0<#3250#><#3250#><#3248#>
<#3249#><#3251#>.. Scalar types<#3251#><#3249#>:<#3255#><#3255#> basic types with type number less than or equal
to 9 will be called scalar types because they essentially occur as
coefficients of some more complicated object. Note that type 9, i.e. polymod,
is used to define algebraic extensions of a base ring, and as such is
a scalar type.
by1=0
<#3257#>=0<#3259#><#3259#><#3257#>
<#3258#><#3260#>. Operations and functions.<#3260#><#3258#>
by 1=0
<#3263#>=0<#3265#><#3265#><#3263#>
<#3264#><#3266#>.. The PARI philosophy<#3266#><#3264#>.
The basic philosophy which governs PARI is that operations and functions
should first give as exact a result as possible, and second, be permitted
if they make any kind of sense.
More specifically, if you do an operation (not a transcendental one)
between exact objects, you will get an exact object. For example,
dividing 1 by 3 does not give #math50#0.33333 ... as you could expect,
but simply the rational number (1/3). If you really want the result
in type real, evaluate 1./3 or add 0. to (1/3).
The result of operations between imprecise objects will be as precise
as possible. Consider for example one of the most difficult cases, that is
the addition of two real numbers x and y. The <#3270#><#3270#>accuracy of the result is
<#97#>a priori<#97#> unpredictable; it depends on the precisions of x and y, on
their sizes (i.e. their exponents), and also on the size of x + y. PARI
works out automatically the right precision for the result, even when it
is working in calculator mode GP where there is a <#3272#><#3272#>default precision.
See the technical reference manual for the precise formulas giving the
precision of the result.
The second part of the PARI philosophy is that PARI operations are in
general quite permissive. For instance taking the exponential of a vector
should not make sense. However, it is frequent that a computation comes
out with a result which is a vector with many components, and one wants
to get the exponential of each one. This could easily be done
either under GP or in library mode, but in fact PARI assumes
that this is exactly what you want to do when you take the exponential of a
vector, so no work is necessary. Most transcendental functions work in the
same way (see chapter 3 for details).
An ambiguity would arise with square matrices. PARI always considers
that you want to do componentwise function evaluation, hence to get
for example the exponential of a square matrix you would need to use
a function with a different name, <#99#>matexp<#99#> for instance. In the present
version 1.37, this is not yet implemented. See however the program in
Appendix C, which is a first attempt for this particular function.
The available operations and functions in PARI are described in detail
in chapter 3. Here is a brief summary:
by 1=0
<#3274#>=0<#3276#><#3276#><#3274#>
<#3275#><#3277#>.. Standard operations<#3277#><#3275#>.
The four standard operators +, -, *, / of course exist. It should
be once more emphasized that division is, as far as it can, an exact
operation (4 divided by 3 gives (4/3)). In addition to this, operations
on integers or polynomials, like #math51#\ (Euclidean division),
% (Euclidean remainder) exist. There is also the exponentiation
operator #tex2html_wrap_inline24782#, when the exponent is of type integer
(otherwise it is considered as a transcendental function).
Finally, the logical operators (<#102#>and<#102#> operator), | | (<#103#>or<#103#>
operator) exist, giving as results 1 (true) or 0 (false). Note that the
C-syntax and | is also accepted as a synonym. However, there is
no bitwise <#104#>and<#104#> or <#105#>or<#105#>.
by 1=0
<#3281#>=0<#3283#><#3283#><#3281#>
<#3282#><#3284#>.. Conversions and similar functions<#3284#><#3282#>.
Many conversion functions are available to convert between different
types. For example floor, ceiling, rounding, truncation, etc....
Other simple functions are included like real and imaginary part,
conjugation,
norm, absolute value, changing precision or creating an integermod or a
polymod.
by 1=0
<#3288#>=0<#3290#><#3290#><#3288#>
<#3289#><#3291#>.. Transcendental functions<#3291#><#3289#>.
They usually operate on any object in #tex2html_wrap_inline24788#, and some also on p-adics.
The list is everexpanding and of course contains all the elementary
functions, plus already a number of others. Recall that by extension,
PARI usually allows a transcendental function to operate componentwise
on vectors or matrices.
by 1=0
<#3296#>=0<#3298#><#3298#><#3296#>
<#3297#><#3299#>.. Arithmetic functions<#3299#><#3297#>.
Apart from a few like the factorial function or the Fibonacci
numbers, these are functions which explicitly use the prime factor
decomposition of integers. The standard functions are included.
In the present version 1.37, a primitive, but useful version of Lenstra's
Elliptic Curve Method (ECM) has been implemented.
More sophisticated functions are implemented, like finding integral bases
and discriminants of number fields, computing class numbers and regulators
(for quadratic fields only), and also many functions dealing with
elliptic curves over #tex2html_wrap_inline24791# or over local fields.
by 1=0
<#3304#>=0<#3306#><#3306#><#3304#>
<#3305#><#3307#>.. Other functions<#3307#><#3305#>.
Quite a number of other functions dealing with polynomials (e.g. finding
complex or p-adic roots, factoring,...), power series
(e.g. substitution, reversion),
linear algebra (e.g. determinant, characteristic polynomial, linear
systems), and different kinds of recursions are also included. In addition,
standard numerical analysis routines like Romberg integration (open or closed,
on a finite or infinite interval), real root finding when the root is bracketed,
polynomial interpolation, series acceleration, and plotting are included.
See the last sections of chapter 3 for details.
#./usersch1.tex#
by1=0
<#3319#><#3319#>
<#3320#>=0<#3322#><#3322#><#3320#>
Chapter : Specific use of the <#3323#><#3331#><#3331#>GP<#3323#> 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, and GP is very useful as a standalone
tool. Hence many new functionalities have been added.
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.
GP (and in fact any program using the PARI library) needs a stack in which
to do its computations, and a table of primes, which may be very small.
The default stack size is 1000000 bytes on the MacII, and 4000000 on
other machines. The prime number limit is by default
200000 on the MacII, and 500000 on other machines. These defaults can be
changed by adding parameters to the input line. To start the
calculator, the general syntax is:
gp [-s stacksize] [-p primelimit] [-b buffersize]
where as usual items within brackets are optional. The buffersize option is
to allow for overly large input files read into GP, for example large
matrices. The default is 30000, which is usually more than plenty.
(Note that on the Macintosh II, even after clicking on the gp icon,
once in the MPW Shell, you still need to type explicitly the above command.)
If you have GNUemacs, it is strongly advised to work in a special emacs
shell (see section 3.11), which is started by typing <#112#>M-x gp<#112#>
(where as usual <#113#>M<#113#> is the Meta key) if you accept the default
stack, prime and buffer sizes, or <#114#>C-u M-x gp<#114#> which will ask you for
the name of the gp executable, the stack size, the prime limit and the
buffersize.
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 1.37, but only details will change (like new and faster functions,
less bugs, better output, etc...) until the next major revision 2.00.
After the copyright, the computer works for a few seconds (it is in fact
computing and storing a table of primes), writes
some help information, the initial defaults, and then waits after its
prompt, initially ``?''.
by1=0
<#3333#>=0<#3335#><#3335#><#3333#>
<#3334#><#3336#>. Metacommands.<#3336#><#3334#>
Let us consider the first three printed lines. It says that to get help,
you should type #math52#\c, #math53#\d, #math54#\t, or ?command;
to exit you must type #math55#\q; and for timing you should type #.
As a general rule, under GP, commands starting with ``#math56#\'' and some
other
symbols like ``?'', are not computing commands, but are metacommands which
correspond to information exchange with GP. The available commands of this
sort can be divided among simple commands (explained here) and default
setting commands (explained in the next section).
Simple commands are case insensitive. For example, #math57#\Q is identical to
#math58#\q.
by 1=0
<#3339#>=0<#3341#><#3341#><#3339#>
<#3340#><#3342#>.. #math60#\\<#3342#><#3340#>: comment. The rest of the line
is ignored by GP.
by 1=0
<#3354#>=0<#3356#><#3356#><#3354#>
<#3355#><#3357#>.. #math62#\<#3359#>a<#3359#><#3357#><#3355#>n: print the object number n (%n)
in raw format. If the number n is omitted, print the latest computed object
( % ).
by 1=0
<#3371#>=0<#3373#><#3373#><#3371#>
<#3372#><#3374#>.. #math64#\<#3376#>b<#3376#><#3374#><#3372#>n: print the object number n (%n)
in prettyprint (i.e. beautified) format. If the number n is omitted,
print the latest computed object ( % ).
by 1=0
<#3388#>=0<#3390#><#3390#><#3388#>
<#3389#><#3391#>.. #math66#\<#3393#>c<#3393#><#3391#><#3389#>: prints the list of all available functions
<#3397#><#3397#>
under GP, not including functions using a special character (specifically
+ , - , * , /, #math67#\ , #tex2html_wrap_inline24824# , ! , #math68##tex2html_wrap_inline24827# ,
_ , % , , |). These names being in general not
informative enough, more information can be obtained by typing
``<#123#>?<#123#>command'', which gives in short form the effect of the command
and the name and syntax
of the corresponding library function. Of course, to have complete
information, read chapter 3 of this manual. Much better help can be obtained
if you work under GNUemacs (see section 3.11).
by 1=0
<#3407#>=0<#3409#><#3409#><#3407#>
<#3408#><#3410#>.. #math70#\<#3412#>d<#3412#><#3410#><#3408#>: prints the <#3416#><#3416#>defaults (see the next
section), including the stacksize, primelimit and buffersize. This
command is always executed (without user intervention), when GP is started.
by 1=0
<#3426#>=0<#3428#><#3428#><#3426#>
<#3427#><#3429#>.. #math72#\<#3431#>k<#3431#><#3429#><#3427#>: kill and reinitialize GP. Apart from the
initial message, this is equivalent to exiting from GP and starting it again,
apart from the fact that the variables which have been used are still known
to GP.
by 1=0
<#3443#>=0<#3445#><#3445#><#3443#>
<#3444#><#3446#>.. #math74#\<#3448#>l<#3448#><#3446#><#3444#>: switch the logfile on/off. Initially, the GP
session does not have a log file where all the commands and results are stored.
Typing #math75#\l will open a file named <#128#>pari.log<#128#> (and destroy any
previous file with that name), and until a subsequent #math76#\l, all the
commands and results will be written in that file.
by 1=0
<#3460#>=0<#3462#><#3462#><#3460#>
<#3461#><#3463#>.. #math78#\<#3465#>m<#3465#><#3463#><#3461#>: print the object number n (%n)
in prettymatrix format. If the number n is omitted, print the latest
computed object ( % ).
by 1=0
<#3477#>=0<#3479#><#3479#><#3477#>
<#3478#><#3480#>.. #math80#\<#3482#>p<#3482#><#3480#><#3478#>: changes the default format from raw
<#3486#><#3486#> to prettymatrix<#3488#><#3488#> to
prettyprint (i.e. beautified)<#3490#><#3490#> to raw format.
by 1=0
<#3500#>=0<#3502#><#3502#><#3500#>
<#3501#><#3503#>.. #math82#\<#3505#>q<#3505#><#3503#><#3501#>: <#3509#><#3509#>quits GP and returns to the system.
by 1=0
<#3519#>=0<#3521#><#3521#><#3519#>
<#3520#><#3522#>.. #math84#\<#3524#>r<#3524#><#3522#><#3520#>filename: <#3528#><#3528#>reads into GP all the objects written
on the named file using the #math85#\w command (see 2.1.13.).
by 1=0
<#3538#>=0<#3540#><#3540#><#3538#>
<#3539#><#3541#>.. #math87#\<#3543#>s<#3543#><#3541#><#3539#>: prints the state of the PARI <#3547#><#3547#>stack, and
in
particular the amount of memory used, expressed as a percentage. This enables
the user to see whether the stack is getting too full.
by 1=0
<#3557#>=0<#3559#><#3559#><#3557#>
<#3558#><#3560#>.. #math89#\<#3562#>s<#3562#>(n)<#3560#><#3558#>: prints the state of the PARI
stack,
and in addition the explicit <#3566#><#3566#>hexadecimal representations of the first n
longwords of the stack (going down) if n is positive, and the complete
stack
if n is negative. This is used primarily as a debugging device for PARI,
and is not intended for the casual user.
by 1=0
<#3576#>=0<#3578#><#3578#><#3576#>
<#3577#><#3579#>.. #math91#\<#3581#>t<#3581#><#3579#><#3577#>: prints the <#3585#><#3585#>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.
by 1=0
<#3595#>=0<#3597#><#3597#><#3595#>
<#3596#><#3598#>.. #math93#\<#3600#>v<#3600#><#3598#><#3596#>: prints the <#3604#><#3604#>version number type of
implementation (680x0, sparc, other) of the program you are using. Note
that the subversion may be omitted (e.g. 1.36 instead of 1.36.3).
by 1=0
<#3614#>=0<#3616#><#3616#><#3614#>
<#3615#><#3617#>.. #math95#\<#3619#>w<#3619#><#3617#><#3615#>n filename: <#3623#><#3623#>write the object number n
( %n ) on the named file, in raw format. If the number n is omitted,
write the latest computed object ( % ).
by 1=0
<#3633#>=0<#3635#><#3635#><#3633#>
<#3634#><#3636#>.. #math97#\<#3638#>x<#3638#><#3636#><#3634#>: print the complete tree with
addresses and contents in hexadecimal, of the <#3642#><#3642#>internal representation of
the latest computed object in GP. As for #math98#\s, this is used primarily
as a debugging device for PARI, and is not intended for the casual user.
However, used on a PARI integer, it can be used as a
decimal#math99#→hexadecimal converter.
by 1=0
<#3644#>=0<#3646#><#3646#><#3644#>
<#3645#><#3647#>.. #<#3647#><#3645#>: switches the <#3651#><#3651#>timer on or off. The timer counts electrical
cycles, so is precise only to ±20ms in Europe and ±16.7ms in North America.
The time measured is the user <#3653#><#3653#>CPU time, <#153#>not<#153#> including the time for
printing.
by1=0
<#3662#>=0<#3664#><#3664#><#3662#>
<#3663#><#3665#>. Defaults and <#3672#><#3672#>output formats.<#3665#><#3663#>
The other commands starting with ``#math100#\'' are for setting the
defaults.
Note that in the syntax given below, the ``='' sign must be written
explicitly, and n represents a non negative integer.
by 1=0
<#3682#>=0<#3684#><#3684#><#3682#>
<#3683#><#3685#>.. #math102#\<#3693#><#3693#>precision<#3685#><#3683#>= n:
Sets to n the number of significant digits, and at the same time the
number of printed digits of real numbers. The initial default is 28.
Note that one can also use the function <#156#>setprecision<#156#> (see chapter 3)
to achieve the same goal, and this <#157#>must<#157#> be done if it is inside a
GP expression or program.
by 1=0
<#3703#>=0<#3705#><#3705#><#3703#>
<#3704#><#3706#>.. #math104#\<#3714#><#3714#>serieslength<#3706#><#3704#>= n:
Sets to n the number of significant terms in power series. The initial
default is 16. Note that one can also use the function <#159#>setserieslength<#159#>
(see chapter 3) to achieve the same goal, and this <#160#>must<#160#> be done if it
is inside a GP expression or program.
by 1=0
<#3724#>=0<#3726#><#3726#><#3724#>
<#3725#><#3727#>.. #math106#\<#3735#><#3735#>format<#3727#><#3725#>=xn.m (where x is a letter): if the letter
is ``f'', real
numbers will be printed in <#3737#><#3737#>fixed floating point format with no explicit
exponent (e.g. 0.000033); if the letter is ``e'', they will be printed
in <#3739#><#3739#>scientific format, always with an explicit exponent (e.g. 3.3e-5).
If the letter is ``g'', real numbers will be printed in ``f'' format,
except when their absolute value is less than 2-32, in which case
they are printed in ``e'' format. The initial default is ``g''.
The number n is the number of significant digits printed for real numbers
except if n≤ 0 where all the significant digits will be printed
(initial default 28), and the number m is the number of characters to be
used for printing integers, but is ignored if is equal to zero (initial
default 0). This is a feeble attempt at formatting.
by 1=0
<#3749#>=0<#3751#><#3751#><#3749#>
<#3750#><#3752#>.. #math108#\<#3760#><#3760#>prompt<#3752#><#3750#>=string:
Sets the prompt equal to the given string. The initial default is ``?''.
by 1=0
<#3762#>=0<#3764#><#3764#><#3762#>
<#3763#><#3765#>.. Raw, prettymatrix and beautified format<#3765#><#3763#>: in addition to the default
formats which can be set as explained above, you can print results in three
ways. Either in ``raw''<#3769#><#3769#> 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.
The second format is the ``prettymatrix''<#3771#><#3771#>. 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. This is the default.
The third format is the ``prettyprint''<#3773#><#3773#> or beautified
format. In the present version 1.37, this is not beautiful at all. The command
#math109#\p is used to navigate between these formats as explained above,
and independently of the default format, an object can be printed in any of the
three formats using the commands #math110#\a, #math111#\m and
#math112#\b respectively.
by 1=0
<#3775#>=0<#3777#><#3777#><#3775#>
<#3776#><#3778#>.. Note on the output formats.<#3778#><#3776#>
A zero real number is printed in ``e'' format as 0.Exx where xx is the
(usually negative) <#171#>decimal<#171#> 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 #math113#\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, an approximation to
the integer part is printed, followed by a ``*'' instead of a
decimal point, indicating <#3782#><#3782#>corrupt digits on the left.
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
#math114#\x).
Finally note that in the present version 1.37, the printing of 0, 1, and
-1 as coefficients in beautified format, although understandable, is buggy.
Hence the default is the raw format until this is improved.
by1=0
<#3784#>=0<#3786#><#3786#><#3784#>
<#3785#><#3787#>. Input formats for the PARI types.<#3787#><#3785#>
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 an expression.
by 1=0
<#3798#>=0<#3800#><#3800#><#3798#>
<#3799#><#3801#>.. <#3809#><#3809#>Integers<#3801#><#3799#>(type 1): type the integer (with an initial
+ or - if desired) with no decimal point.
by 1=0
<#3819#>=0<#3821#><#3821#><#3819#>
<#3820#><#3822#>.. <#3830#><#3830#>Real numbers<#3822#><#3820#>(type 2): 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 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 ``E'' or ``e''
(like 6.02 E 23 or 1e-5).
by 1=0
<#3840#>=0<#3842#><#3842#><#3840#>
<#3841#><#3843#>.. <#3851#><#3851#>Integermods<#3843#><#3841#>(type 3): to enter #math115#n mod m, type
#math116#mod(n, m), not n%m (see 3.2.15.).
by 1=0
<#3863#>=0<#3865#><#3865#><#3863#>
<#3864#><#3866#>.. <#3874#><#3874#>Rational numbers<#3866#><#3864#>(types 4 and 5): under GP, all
fractions are automatically reduced to lowest terms, so it is not possible
to enter a non-irreducible fraction (type 5), although of course in
library mode this is easy. To enter n/m just type it as written.
As explained in section 3.1.4., division will <#179#>not<#179#> be performed, only
reduction to lowest terms.
by 1=0
<#3884#>=0<#3886#><#3886#><#3884#>
<#3885#><#3887#>.. <#3895#><#3895#>Complex numbers<#3887#><#3885#>(type 6): to enter x + iy, type
x + I*y or x + i*y. The letters I and #math117#i stand for #tex2html_wrap_inline24921#. Recall
from chapter 1 that x and y can be of type integer, real, integermod
fraction, or p-adic.
by 1=0
<#3899#>=0<#3901#><#3901#><#3899#>
<#3900#><#3902#>.. p-adic numbers<#3902#><#3900#><#3906#><#3906#> (type 7): to enter a p-adic number,
simply write a rational or integer expression and add to it #math118#O(p#tex2html_wrap_inline24929#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
#math119#
2*7#tex2html_wrap_indisplay24940#(- 1) + 3 + 4*7 + 2*7#tex2html_wrap_indisplay24941#2 + O(7#tex2html_wrap_indisplay24942#3),
you can type it
exactly as shown, or equivalently as #math120#
905/7 + O(7#tex2html_wrap_indisplay24944#3).
by 1=0
<#3916#>=0<#3918#><#3918#><#3916#>
<#3917#><#3919#>.. <#3927#><#3927#>Quadratic numbers<#3919#><#3917#>(type 8): first, you must define the default
quadratic order or field in which you want to work. This is done using the
<#2735#><#3929#><#3929#>quadgen<#2735#> function, in the following way. Write something like
w=quadgen(d)
where <#193#>d<#193#> is the <#194#>discriminant<#194#> of the quadratic order in which you
want to work (hence #math121#d≡0 or 1 mod 4). The name <#196#>w<#196#> 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 <#197#>w<#197#>,
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. #math122#w = #tex2html_wrap_inline24948#/2 if #math123#d≡0 mod 4, and #math124#w = (1 + #tex2html_wrap_inline24951#)/2 if
#math125#d≡1 mod 4, where d is the discriminant), and to enter x + yw you
just type x + y*w or x + y*W.
by 1=0
<#3942#>=0<#3944#><#3944#><#3942#>
<#3943#><#3945#>.. <#3953#><#3953#>Polymods<#3945#><#3943#>(type 9): exactly as for integermods,
to enter #math126#x mod y (where x and y are polynomials), type
#math127#mod(x, y), not x%y (see 3.2.12.). Note that when y is an
irreducible polynomial in one variable, polymods whose modulus is y are
simply algebraic numbers in the finite extension defined by the polynomial y.
This allows us to work easily in <#3957#><#3957#>number fields, finite extensions of
the p-adic field #tex2html_wrap_inline24969#, or <#3960#><#3960#>finite fields.
<#204#>Important remark.<#204#> Since the variables occurring in a polymod are not
free variables, it is essential in order to avoid inconsistencies, that
all polymods have the same structure, i.e. the main variable will be number 0,
the next number 1, etc.... In other words, since 0 is the variable number
of ``X'', do <#205#>not<#205#> use expressions like <#2737#>mod(Y,Yˆ2+1)<#2737#> since PARI
will not recognize that this is identical to <#2738#>mod(X,Xˆ2+1)<#2738#>. Another
consequence is that an operation like <#2739#>X+mod(X,Xˆ2+1)<#2739#> gives exactly
the same thing as a result (meaning X + i where i2 = - 1), and not
<#2740#>mod(2*X,Xˆ2+1)<#2740#>.
by 1=0
<#3970#>=0<#3972#><#3972#><#3970#>
<#3971#><#3973#>.. <#3981#><#3981#>Polynomials<#3973#><#3971#>(type 10): 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 <#211#>i<#211#> (used exclusively for the square root
of -1), <#212#>pi<#212#> (3.14...) and <#213#>euler<#213#> (Euler's constant).
The total number of different variable names is limited to 256, which
should be enough. If you ever need
hundreds of variables, you should probably use vectors instead.
by 1=0
<#3991#>=0<#3993#><#3993#><#3991#>
<#3992#><#3994#>.. <#4002#><#4002#>Power series<#3994#><#3992#>(type 11): type a rational function or
polynomial expression and add to it #math128#O(expr#tex2html_wrap_inline24978#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 order of the variables, or to modify it, use the function
<#216#>reorder<#216#> see 3.10.4.6).
by 1=0
<#4012#>=0<#4014#><#4014#><#4012#>
<#4013#><#4015#>.. <#4023#><#4023#>Rational functions<#4015#><#4013#>(types 13 and 14): under GP, all
fractions are automatically reduced to lowest terms, so it is not possible
to enter a non-irreducible rational function (type 14), although of course in
library mode this is easy. To enter x/y just type it as written.
As explained in section 3.1.4., division will <#218#>not<#218#> be performed, only
reduction to lowest terms.
by 1=0
<#4033#>=0<#4035#><#4035#><#4033#>
<#4034#><#4036#>.. <#4044#><#4044#>Binary quadratic forms of positive discriminant<#4036#><#4034#>(type 15):
enter a 4-component (row or column) vector, and transform it into a binary
quadratic form using the function <#220#>qfr<#220#> (see 3.4.45). The fourth component
(which is related to the regulator, more precisely to Shanks' ``distance'')
must be a real number. See also the function <#221#>pf<#221#> which directly creates
a prime form of given discriminant (see 3.4.37).
by 1=0
<#4054#>=0<#4056#><#4056#><#4054#>
<#4055#><#4057#>.. <#4065#><#4065#>Binary quadratic forms of negative discriminant<#4057#><#4055#>(type 16):
enter a 3-component (row or column) vector, and transform it into a binary
quadratic form using the function <#223#>qfi<#223#> (see 3.4.44). See also the
function <#224#>pf<#224#> which directly creates a prime form of given discriminant
(see 3.4.37).
by 1=0
<#4067#>=0<#4069#><#4069#><#4067#>
<#4068#><#4070#>.. Row and column vectors<#4070#><#4068#>
<#4074#><#4074#><#4076#><#4076#>
(types 17 and 18):
to enter a row vector, type the components separated by commas ``,'',
and enclosed between brackets ``['' and ``]'', e.g. [x, y, z].
To enter a column vector, type the vector horizontally, and add a tilde
``#math129##tex2html_wrap_inline24986#'' to transpose.
by 1=0
<#4078#>=0<#4080#><#4080#><#4078#>
<#4079#><#4081#>.. Matrices<#4081#><#4079#>(type 19):<#4085#><#4085#> to enter a matrix, type the
components line by line, the components being separated by commas ``,'',
the lines by semicolons ``;'', and everything enclosed in brackets
``['' and ``]'', e.g. #math130#[x, y;z, t;u, v].
Note that although the internal representation is essentially the same,
(only the type number being different), a row vector of column vectors is
<#231#>not<#231#> a matrix; for example, multiplication will not work in the same way.
To transform it into a matrix, use the function <#232#>mat<#232#> (see 3.7.38).
by1=0
<#4087#>=0<#4089#><#4089#><#4087#>
<#4088#><#4090#>. The general GP input line.<#4090#><#4088#>
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
%1, %2, ...under GP, and they can also be used in library mode with the names
<#234#>g[1], g[2], ...<#234#><#4093#><#4093#> In this case, the array is not automatically filled for you.
As a shortcut, the last computed expression can also be called %.
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 ``;'' sign.
This same sign is used as an instruction separator when several instructions
are written on the same line (note that the ``:'' sign can also be used, but
we will try to keep C-style conventions).
Note that the last expression you have computed, even if not printed,
still has the name (%1, %2, ...) 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 % as usual.
Any legal expressions can be typed, and it is evaluated using the usual
conventions about operator priorities and left to right evaluation
(including raising to a power), using the available operator
symbols, function names (including user-defined functions), and special
variables. Please note that in general there<#4095#><#4095#>
is no distinction between lowercase. and uppercase
Also, note that blanks are completely ignored in the input to GP.
The special variable names used by GP are <#2746#><#4097#><#4097#>euler<#2746#> (Euler's
constant=0.577...), <#2747#><#4099#><#4099#>i<#2747#> (the square root of -1),
<#2748#><#4101#><#4101#>pi<#2748#> (3.14...), which are really functions without parameters, and <#2749#><#4103#><#4103#>O<#2749#> whose syntax is the following:
<#241#>O<#241#>#math131#(expr#tex2html_wrap_inline24996#k)
When expr is an integer or a
rational number, creates a expr-adic number (zero in fact) of precision k.
When 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*k where v is the
X-adic valuation of expr (see 2.3.6 and 2.3.9.).
Note: as usual, lowercase <#243#>o<#243#> is allowed, but we do not
advise to use it since it has a different mathematical meaning.
by1=0
<#4105#><#4105#>
<#4106#>=0<#4108#><#4108#><#4106#>
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.37. 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.
by1=0
<#4111#>=0<#4113#><#4113#><#4111#>
<#4112#><#4114#>. Standard monadic or dyadic operators.<#4114#><#4112#>
by 1=0
<#4117#>=0<#4119#><#4119#><#4117#>
<#4118#><#4120#>.. ±<#4120#><#4118#>+ x and - x refer to monadic operators
(+ x does nothing and - x negates x).
The library syntax is #math132##tex2html_wrap_inline25014#(x) for - x.
by 1=0
<#4127#>=0<#4129#><#4129#><#4127#>
<#4128#><#4130#>.. +, -<#4130#><#4128#>x + y and x - y are the <#4134#><#4134#>sum and <#4136#><#4136#>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 #math133##tex2html_wrap_inline25025#(x, y) for x + y, #math134##tex2html_wrap_inline25028#(x, y)
for x - y.
by 1=0
<#4144#>=0<#4146#><#4146#><#4144#>
<#4145#><#4147#>.. *<#4147#><#4145#>x*y is the <#4151#><#4151#>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 <#4153#><#4153#>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 <#2750#>˜<#2750#> or <#257#>trans( )<#257#>, see 3.7.54).
The library syntax is #math135##tex2html_wrap_inline25038#(x, y) for x*y.
by 1=0
<#4158#>=0<#4160#><#4160#><#4158#>
<#4159#><#4161#>.. /<#4161#><#4159#>x/y is the <#4165#><#4165#>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 <#262#>not<#262#> the Euclidean quotient (see #math136#x\y for that), and similarly the
quotient of two polynomials is a rational function in general. To obtain the
approximate real value of the quotient of two integers, add 0. to the
result; to obtain the approximate p-adic value of the quotient of two
integers, add O(pk) to the result; finally,
to obtain the <#4167#><#4167#>taylor series expansion of the quotient of two polynomials,
add #math137#O(X#tex2html_wrap_inline25051#k) to the result or use the <#265#>taylor<#265#> function (3.6.47).
The library syntax is #math138##tex2html_wrap_inline25053#(x, y) for x/y.
by 1=0
<#4172#>=0<#4174#><#4174#><#4172#>
<#4173#><#4175#>.. #math140#\<#4175#><#4173#>#math141#x\y is the <#4179#><#4179#>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 #math142##tex2html_wrap_inline25061#(x, y) for #math143#x\y.
by 1=0
<#4184#>=0<#4186#><#4186#><#4184#>
<#4185#><#4187#>.. %<#4187#><#4185#>x%y is the <#4191#><#4191#>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 #math144##tex2html_wrap_inline25070#(x, y) for x%y.
by 1=0
<#4204#>=0<#4206#><#4206#><#4204#>
<#4205#><#4207#>.. <#4215#><#4215#>divres<#4207#><#4205#>(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 of the sign of the dividend.
The library syntax is #math145##tex2html_wrap_inline25076#(x, y).
by 1=0
<#4228#>=0<#4230#><#4230#><#4228#>
<#4229#><#4231#>.. #tex2html_wrap_inline25080#<#4231#><#4229#>#math146#x#tex2html_wrap_inline25082#y is <#4237#><#4237#>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 #math147##tex2html_wrap_inline25084#(x, y) for #math148#x#tex2html_wrap_inline25086#y.
In addition, there are two shift functions (i.e. multiplication and division
by powers of 2) which are faster than the general multiplication or division
routines:
<#4242#><#4242#>
by 1=0
<#4243#>=0<#4246#><#4246#><#4243#>
<#4244#><#4247#>.. shift<#4247#><#4244#>(x, n): shift x componentwise left by n bits if n≥ 0 and
right by - n bits if n ;SPMlt; 0. A left shift by n corresponds to multiplication
by 2n, and a right shift by - n corresponds to Euclidean division of x
by 2-n.
The library syntax is #math149##tex2html_wrap_inline25097#(x, n) where n is a C-integer.
<#4254#><#4254#>
by 1=0
<#4255#>=0<#4258#><#4258#><#4255#>
<#4256#><#4259#>.. shiftmul<#4259#><#4256#>(x, n): multiply x by 2n. The difference with
<#284#>shift<#284#> is that when n ;SPMlt; 0, the ordinary division takes place, hence for
example if x is an integer the result may be a fraction, while for
<#285#>shift<#285#> Euclidean division takes place when n ;SPMlt; 0 hence if x is an
integer the result is still an integer.
The library syntax is #math150##tex2html_wrap_inline25107#(x, n) where n is a C-integer.
by 1=0
<#4274#>=0<#4276#><#4276#><#4274#>
<#4275#><#4277#>.. comparison and <#4285#><#4285#>boolean operators<#4277#><#4275#>.
The six standard <#4287#><#4287#>comparison operators
;SPMlt; =, ;SPMlt;, ;SPMgt; =, ;SPMgt;, = =, ! = are available in GP, and in library mode
under the names <#2754#><#4289#><#4289#>gle, <#4291#><#4291#>glt, <#4293#><#4293#>gge, <#4295#><#4295#>ggt, <#4297#><#4297#>geq, <#4299#><#4299#>gne<#2754#> respectively. The
library syntax is #math151##tex2html_wrap_inline25116#(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 | | (<#4301#><#4301#>inclusive or) and (<#4303#><#4303#>and) <#4305#><#4305#>are
also available, and the library syntax is #math152##tex2html_wrap_inline25120#(x, y) and
#math153##tex2html_wrap_inline25122#(x, y) respectively. Note that to avoid confusion with the
factorial function, there is no ! (<#4313#><#4313#>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 #math154##tex2html_wrap_inline25125#(x, y) which gives
the sign (1, 0, or -1) of x - y, where x and y must be in #tex2html_wrap_inline25130#,
and #math155##tex2html_wrap_inline25132#(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 #math156##tex2html_wrap_inline25136#(x) (x = 0 ?), #math157##tex2html_wrap_inline25139#(x)
(x = 1 ?), and <#4328#><#4328#> <#307#>gcmp_1<#307#> (x) (x = - 1 ?).
Note that #math158##tex2html_wrap_inline25144#(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 #math159##tex2html_wrap_inline25149#.
GP accepts the following synonyms for some of the above functions:
since there is no bitwise <#310#>and<#310#> or bitwise <#311#>or<#311#>, | and are accepted as<#4336#><#4336#> <#4338#><#4338#>
synonyms of | | and respectively. Also, ;SPMlt; ;SPMgt; is accepted as a
synonym for ! =. On the other hand, = is definitely <#314#>not<#314#> a
synonym for = = since it is the assignment statement.
by 1=0
<#4340#>=0<#4342#><#4342#><#4340#>
<#4341#><#4343#>.. lex<#4343#><#4341#>(x, y): gives the result of a lexicographic comparison between x and y.
This is to be interpreted in quite a wide sense. For example, the vector [1, 3]
will be considered smaller than the longer vector [1, 3, - 1] (but of course larger
than [1, 2, 5]), i.e. <#316#>lex([1,3],[1,3,5])<#316#> will give -1 as a result.
The library syntax is #math160##tex2html_wrap_inline25165#(x, y).
by 1=0
<#4350#>=0<#4352#><#4352#><#4350#>
<#4351#><#4353#>.. sign<#4353#><#4351#>(x): <#4357#><#4357#>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 #math161##tex2html_wrap_inline25169#(x).
by 1=0
<#4370#>=0<#4372#><#4372#><#4370#>
<#4371#><#4373#>.. <#4381#><#4381#>max<#4373#><#4371#>(x, y) and <#2756#><#4383#><#4383#>min<#2756#>(x, y) create the
maximum and minimum of x and y when they can be compared.
The library syntax is #math162##tex2html_wrap_inline25175#(x, y) and #math163##tex2html_wrap_inline25177#(x, y).
<#4391#>=0<#4393#><#4393#><#4391#>
<#4392#><#4394#>Important remark.<#4394#><#4392#>In all the above library syntaxes, we have
given only the basic names of the functions. For example #math164##tex2html_wrap_inline25179#(x, y)
assumes that x and y are PARI objects (the GEN type) and <#327#>creates<#327#>
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:
#math165##tex2html_wrap_inline25184#(x, y): here x is a GEN, y is an ordinary 32-bit
integer.
#math166##tex2html_wrap_inline25188#(x, y): here x is an ordinary 32-bit integer, y is a
GEN.
#math167##tex2html_wrap_inline25192#(x, y, z), #tex2html_wrap_inline25193#(x, y, z), #tex2html_wrap_inline25194#(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 <#333#>g<#333#>, such
as gadd, one can replace the <#334#>g<#334#> by an <#335#>l<#335#> to obtain a <#336#>long<#336#>
result instead
of a GEN (i.e. pointer to long) result. For instance #math168##tex2html_wrap_inline25198#(x, y) is
identical with #math169#(#tex2html_wrap_inline25200#(x, y)). These macros are written in
the files listed in <#2757#><#4416#><#4416#>gencom.h<#2757#>.
by1=0
<#4418#>=0<#4420#><#4420#><#4418#>
<#4419#><#4421#>. Conversions and similar elementary functions<#4421#><#4419#>
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.
<#4424#><#4424#>
by 1=0
<#4425#>=0<#4428#><#4428#><#4425#>
<#4426#><#4429#>.. binary<#4429#><#4426#>(x): outputs the vector of the binary digits of | x|, where
#math170#| x| ;SPMlt; 232.
The library syntax is #math171##tex2html_wrap_inline25205#(x).
<#4436#><#4436#>
by 1=0
<#4437#>=0<#4440#><#4440#><#4437#>
<#4438#><#4441#>.. bittest<#4441#><#4438#>(x, n): outputs the #math172#nth bit of | x| starting
from the right (i.e. the coefficient of 2n in the binary expansion of x.
The result is 0 or 1.
The library syntax is #math173##tex2html_wrap_inline25212#(x, n) where n as well as the result
are C-integers.
by 1=0
<#4457#>=0<#4459#><#4459#><#4457#>
<#4458#><#4460#>.. <#4468#><#4468#>ceil<#4460#><#4458#>(x): ceiling of x. When x is in #tex2html_wrap_inline25218#,
the result is the smallest integer greater than or equal to x.
The library syntax is #math174##tex2html_wrap_inline25221#(x).
<#4474#><#4474#>
by 1=0
<#4475#>=0<#4478#><#4478#><#4475#>
<#4476#><#4479#>.. centerlift<#4479#><#4476#>(x): lifts an element #math175#x = a mod n of #math176##tex2html_wrap_inline25225#/n#tex2html_wrap_inline25226# to
a in #tex2html_wrap_inline25229#, and similarly lifts a polymod to a polynomial. This is the same
as <#350#>lift<#350#> except that in the particular case of elements of #math177##tex2html_wrap_inline25231#/n#tex2html_wrap_inline25232#, the
lift y is such that #math178#- n/2 ;SPMlt; y≤n. 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 #math179##tex2html_wrap_inline25239#(x).
by 1=0
<#4499#>=0<#4501#><#4501#><#4499#>
<#4500#><#4502#>.. <#4510#><#4510#>changevar<#4502#><#4500#>(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 <#353#>x<#353#>, <#354#>a<#354#>, <#355#>b<#355#>, <#356#>c<#356#>. Then,
if y is the vector <#357#>[x,c,a,b]<#357#>, the variable <#358#>a<#358#> will be
replaced by <#359#>c<#359#>, <#360#>b<#360#> by <#361#>a<#361#>, and <#362#>a<#362#> by <#363#>b<#363#>, <#364#>x<#364#>
being unchanged. Note that the permutation must be completely
specified, e.g. <#365#>[c,a,b]<#365#> would not work, since this would replace
<#366#>x<#366#> by <#367#>c<#367#>, and leave <#368#>a<#368#> and <#369#>b<#369#> unchanged.
The library syntax is #math180##tex2html_wrap_inline25245#(