#./usersch1.tex# = 25cm =

P> =users.toc users.idx =0

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; yn. 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#(x, y).

by 1=0 <#4523#>=0<#4525#><#4525#><#4523#>

<#4524#><#4526#>.. <#4534#><#4534#>components of a PARI object<#4526#><#4524#>:

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

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

The library syntax is #math188##tex2html_wrap_inline25261#(x, n), where n is a 32-bit C-integer.

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

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

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

The library syntax is #math190##tex2html_wrap_inline25274#(x, n).

The third method is specific to vectors or matrices under GP. If x is a (row or column) vector, then <#2767#><#4555#><#4555#>x[n]<#2767#> represents the #math191#nth component of x, i.e. <#389#>compo(x,n)<#389#>. It is more natural and shorter to write. If x is a matrix, <#2769#><#4558#><#4558#>x[m,n]<#2769#> represents the coefficient of row <#391#>m<#391#> and column <#392#>n<#392#> of the matrix, <#2770#><#4560#><#4560#>x[m,]<#2770#> represents the #math192#mth <#395#>row<#395#> of x, and <#2772#><#4563#><#4563#>x[,n]<#2772#> represents the #math193#nth <#398#>column<#398#> of x.

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

<#4568#><#4568#> by 1=0 <#4569#>=0<#4572#><#4572#><#4569#>

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

The library syntax is #math194##tex2html_wrap_inline25290#(x).

<#4580#><#4580#> by 1=0 <#4581#>=0<#4584#><#4584#><#4581#>

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

The library syntax is #math195##tex2html_wrap_inline25298#(x,e) where e is a 32-bit C-integer.

<#4593#><#4593#> by 1=0 <#4594#>=0<#4597#><#4597#><#4594#>

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

The library syntax is #math196##tex2html_wrap_inline25307#(x).

<#4605#><#4605#> by 1=0 <#4606#>=0<#4609#><#4609#><#4606#>

<#4607#><#4610#>.. floor<#4610#><#4607#>(x): floor of x. When x is in #tex2html_wrap_inline25312#, the result is the largest integer smaller than or equal to x.

The library syntax is #math197##tex2html_wrap_inline25315#(x).

<#4618#><#4618#> by 1=0 <#4619#>=0<#4622#><#4622#><#4619#>

<#4620#><#4623#>.. frac<#4623#><#4620#>(x): fractional part of x. Identical to #math198#x - floor(x). If x is real, the result is in [0, 1[.

The library syntax is #math199##tex2html_wrap_inline25322#(x).

<#4631#><#4631#> by 1=0 <#4632#>=0<#4635#><#4635#><#4632#>

<#4633#><#4636#>.. imag<#4636#><#4633#>(x): imaginary part of x. When x is a quadratic number, this is the coefficient of ω in the ``canonical'' integral basis #math200#(1, ω).

The library syntax is #math201##tex2html_wrap_inline25329#(x).

<#4643#><#4643#> by 1=0 <#4644#>=0<#4647#><#4647#><#4644#>

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

The library syntax is #math202##tex2html_wrap_inline25333#(x).

<#4655#><#4655#> by 1=0 <#4656#>=0<#4659#><#4659#><#4656#>

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

The library syntax is #math205##tex2html_wrap_inline25346#(x).

<#4670#><#4670#> by 1=0 <#4671#>=0<#4674#><#4674#><#4671#>

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

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

The library syntax is #math207##tex2html_wrap_inline25356#(x, y).

<#4683#><#4683#> by 1=0 <#4684#>=0<#4687#><#4687#><#4684#>

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

The library syntax is #math208##tex2html_wrap_inline25359#(x, y).

<#4695#><#4695#> by 1=0 <#4696#>=0<#4699#><#4699#><#4696#>

<#4697#><#4700#>.. norm<#4700#><#4697#>(x): algebraic norm of x, i.e. the product of x with its conjugate (no square roots are taken), or conjugates for polymods. For vectors and matrices, the norm is taken componentwise and hence is not the L2-norm (see 3.2.18). Note that the norm of an element of #tex2html_wrap_inline25365# is its square, so as to be compatible with the complex norm.

The library syntax is #math209##tex2html_wrap_inline25367#(x).

<#4708#><#4708#> by 1=0 <#4709#>=0<#4712#><#4712#><#4709#>

<#4710#><#4713#>.. norml2<#4713#><#4710#>(x): square of the L2-norm of x. x must be a (row or column) vector.

The library syntax is #math210##tex2html_wrap_inline25373#(x).

<#4720#><#4720#> by 1=0 <#4721#>=0<#4724#><#4724#><#4721#>

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

The library syntax is #math211##tex2html_wrap_inline25381#(x).

<#4732#><#4732#> by 1=0 <#4733#>=0<#4736#><#4736#><#4733#>

<#4734#><#4737#>.. permutation<#4737#><#4734#>(n, k): generates the k-th permutation (as a vector of length n) of the numbers 1 to n. The number k is taken modulo n! .

The library syntax is #math212##tex2html_wrap_inline25390#(n, k), where n is a C-integer.

<#4744#><#4744#> by 1=0 <#4745#>=0<#4748#><#4748#><#4745#>

<#4746#><#4749#>.. poly<#4749#><#4746#>(x, v): transform the object x into a polynomial with main variable v. If x is a scalar, this gives a constant polynomial. If x is a power series, the effect is identical to <#436#>trunc<#436#> (see 3.2.36), i.e. it chops off the O(Xk). If x is a vector, this function creates the polynomial whose coefficients are given in x, with x[1] being the leading coefficient (which can be zero).

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

The library syntax is #math213##tex2html_wrap_inline25402#(x, v), where v is a variable number.

<#4756#><#4756#> by 1=0 <#4757#>=0<#4760#><#4760#><#4757#>

<#4758#><#4761#>.. polyrev<#4761#><#4758#>(x, v): transform the object x into a polynomial with main variable v. If x is a scalar, this gives a constant polynomial. If x is a power series, the effect is identical to <#443#>trunc<#443#> (see 3.2.36), i.e. it chops off the O(Xk). If x is a vector, this function creates the polynomial whose coefficients are given in x, with x[1] being the constant term. Note that this is the reverse of <#444#>poly<#444#> if x is a vector, otherwise it is identical to <#445#>poly<#445#>.

The library syntax is #math214##tex2html_wrap_inline25415#(x, v), where v is a variable number.

<#4768#><#4768#> by 1=0 <#4769#>=0<#4772#><#4772#><#4769#>

<#4770#><#4773#>.. prec<#4773#><#4770#>(x, n): x being a PARI object and n a 32-bit C-integer, creates a new object equal to x but with a new precision n. This is to be understood as follows:

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

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

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

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

The library syntax is #math215##tex2html_wrap_inline25437#(x, n), where n is a C-integer.

<#4780#><#4780#> by 1=0 <#4781#>=0<#4784#><#4784#><#4781#>

<#4782#><#4785#>.. quadgen<#4785#><#4782#>(x): creates the quadratic number <#4789#><#4789#> #math216#ω = (a + #tex2html_wrap_inline25441#)/2 where a = 0 if #math217#x≡0 mod 4, a = 1 if #math218#x≡1 mod 4, so that #math219#(1, ω) is an integral basis for the quadratic order of discriminant x. x must be an integer congruent to 0 or 1 modulo 4.

The library syntax is #math220##tex2html_wrap_inline25450#(x).

<#4796#><#4796#> by 1=0 <#4797#>=0<#4800#><#4800#><#4797#>

<#4798#><#4801#>.. quadpoly<#4801#><#4798#>(x): creates the ``canonical'' quadratic polynomial corresponding to the discriminant x, i.e. the minimal polynomial of <#458#>quadgen(x)<#458#>. x must be an integer congruent to 0 or 1 modulo 4.

The library syntax is #math221##tex2html_wrap_inline25455#(x).

<#4808#><#4808#> by 1=0 <#4809#>=0<#4812#><#4812#><#4809#>

<#4810#><#4813#>.. random<#4813#><#4810#>(): gives a random integer between 0 and 231 - 1. This is simply the standard <#462#>rand()<#462#> function of C, hence in particular the low order bits are not very random.

The library syntax is #math222##tex2html_wrap_inline25459#().

<#4820#><#4820#> by 1=0 <#4821#>=0<#4824#><#4824#><#4821#>

<#4822#><#4825#>.. real<#4825#><#4822#>(x): real part of x. In the case where x is a quadratic number, this is the coefficient of 1 in the ``canonical'' integral basis #math223#(1, ω).

The library syntax is #math224##tex2html_wrap_inline25466#(x).

<#4832#><#4832#> by 1=0 <#4833#>=0<#4836#><#4836#><#4833#>

<#4834#><#4837#>.. rndtoi<#4837#><#4834#>(x): same as <#467#>cvtoi<#467#> (see 3.2.8) except that truncation is replaced by rounding (see 3.2.29).

The library syntax is #math225##tex2html_wrap_inline25469#(x,e).

<#4844#><#4844#> by 1=0 <#4845#>=0<#4848#><#4848#><#4845#>

<#4846#><#4849#>.. round<#4849#><#4846#>(x): If x is in #tex2html_wrap_inline25473#, rounds x to the nearest integer. If the exponent of x is too large compared to its precision, the result is undefined and an error message occurs. Use <#470#>rndtoi<#470#> (3.2.22) to suppress this error handling.

Important remark: note that, contrary to the other truncation functions (except <#471#>rndtoi<#471#> which is essentially the same), this function operates on every coefficient at every level of a PARI object. For example

#math226#

trunc#tex2html_wrap_indisplay25477##tex2html_wrap_indisplay25478##tex2html_wrap_indisplay25479# = 2.0*X,

while

#math227#

round#tex2html_wrap_indisplay25481##tex2html_wrap_indisplay25482##tex2html_wrap_indisplay25483# = #tex2html_wrap_indisplay25484#.

An important use of <#480#>round<#480#> is to get exact results after a long approximate computation, when theory tells you that the coefficients must be integers.

The library syntax is #math228##tex2html_wrap_inline25486#(x).

<#4868#><#4868#> by 1=0 <#4869#>=0<#4872#><#4872#><#4869#>

<#4870#><#4873#>.. rounderror<#4873#><#4870#>(x): maximum error in decimal digits observed when rounding x. This functions allows the user to easily check the precision of the rounding of a result whose components are supposed to be integers.

The library syntax is #math229##tex2html_wrap_inline25490#(x) and the result is a C-integer.

<#4880#><#4880#> by 1=0 <#4881#>=0<#4884#><#4884#><#4881#>

<#4882#><#4885#>.. series<#4885#><#4882#>(x, v): transform the object x into a power series with main variable v. If x is a scalar, this gives a constant power series with precision given by the global variable <#485#>precdl<#485#> (transparent under GP). If x is a polynomial, the precision is the greatest of <#486#>precdl<#486#> and the degree of the polynomial. If x is a vector, the precision is similarly given, and the coefficients of the vector are understood to be the coefficients of the power series starting from the constant term (i.e. the reverse of the function <#487#>poly<#487#>, see 3.2.21 above).

The warning given for <#488#>poly<#488#> applies here: this is not a substitution function.

The library syntax is #math230##tex2html_wrap_inline25498#(x, v), where v is a variable number.

<#4892#><#4892#> by 1=0 <#4893#>=0<#4896#><#4896#><#4893#>

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

The library syntax is #math232##tex2html_wrap_inline25506#(n), where n is a C-integer, as is the returned value.

<#4904#><#4904#> by 1=0 <#4905#>=0<#4908#><#4908#><#4905#>

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

The library syntax is #math234##tex2html_wrap_inline25514#(n), where n is a C-integer, as is the returned value.

<#4916#><#4916#> by 1=0 <#4917#>=0<#4920#><#4920#><#4917#>

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

The library syntax is #math235##tex2html_wrap_inline25519#(x).

<#4928#><#4928#> by 1=0 <#4929#>=0<#4932#><#4932#><#4929#>

<#4930#><#4933#>.. size<#4933#><#4930#>(x): gives the maximal number of decimal digits minus one of the components of x.

The library syntax is #math236##tex2html_wrap_inline25523#(x), and the result is a C-integer.

<#4940#><#4940#> by 1=0 <#4941#>=0<#4944#><#4944#><#4941#>

<#4942#><#4945#>.. trunc<#4945#><#4942#>(x): truncation of x. When x is in #tex2html_wrap_inline25528#, this means that the part after the decimal point is chopped away. If the result is not significant because the exponent is too large compared to the precision, an error occurs. Use <#499#>cvtoi<#499#> (3.2.8) to suppress this error handling.

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

The library syntax is #math237##tex2html_wrap_inline25534#(x).

<#4953#><#4953#> by 1=0 <#4954#>=0<#4957#><#4957#><#4954#>

<#4955#><#4958#>.. type<#4958#><#4955#>(x): internal type number (from 1 to 19) of the pari object x. This is useful only under GP.

The library syntax is #math238##tex2html_wrap_inline25538#(x), but need not be used since the internal function <#504#>typ<#504#> is available. Note that <#505#>gtype<#505#> gives a GEN while <#506#>typ<#506#> gives a C-integer.

<#4965#><#4965#> by 1=0 <#4966#>=0<#4969#><#4969#><#4966#>

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

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

The library syntax is #math239##tex2html_wrap_inline25553#(x).

<#4977#><#4977#> by 1=0 <#4978#>=0<#4981#><#4981#><#4978#>

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

The library syntax is #math240##tex2html_wrap_inline25559#(x).

by1=0 <#4989#>=0<#4991#><#4991#><#4989#>



<#4990#><#4992#>. Transcendental functions.<#4992#><#4990#>


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

;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;If the argument is either an integer, a real, a rational, a complex or a quadratic number, it is, if necessary, first converted to a real (or complex) number using the current <#4995#><#4995#>precision held in the variable <#513#>prec<#513#>. Under GP this is transparent to the user, but when programming in library mode, care must be taken to supply the parameter <#514#>prec<#514#> as the last argument of the function if the first argument is an exact object (see 1.2.5.), otherwise disaster will occur.

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

;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;If the argument is an integermod or a p-adic, at present only a few functions like <#517#>sqrt<#517#> (square root), <#518#>sqr<#518#> (square), <#519#>log<#519#>, <#520#>exp<#520#>, powering, <#521#>teich<#521#> (Teichmüller character) and <#522#>agm<#522#> (arithmetic-geometric mean) are implemented. Note that in the case of a 2-adic number, #math243##tex2html_wrap_inline25565#(x) is not identical to x*x: for example if #math244#x = 1 + O(25) then #math245#x*x = 1 + O(25) while #math246##tex2html_wrap_inline25570#(x) = 1 + O(26). (Remark: note that if we wanted to be strictly consistent with the PARI philosophy, we should have #math247#x*y = (4 mod 8) when both x and y are congruent to 2 modulo 4, or #math248##tex2html_wrap_inline25577#(x) = (4 mod 32) when x is congruent to 2 modulo 4. However, since an integermod is an exact object, PARI assumes that the modulus must not change, and the result is hence #math249#0 mod 4 in both cases. On the other hand, p-adics are not exact objects, hence are treated differently.)

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

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

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

by 1=0 <#5012#>=0<#5014#><#5014#><#5012#>

<#5013#><#5015#>.. #tex2html_wrap_inline25588#<#5015#><#5013#>#math250#x#tex2html_wrap_inline25590#y: if y is not of type integer, this has the same effect as #math251#exp(y*ln(x)). It can be applied to p-adic numbers as well as to the more usual types.<#5021#><#5021#>

The library syntax is #math252##tex2html_wrap_inline25595#(x, y, prec).

<#5026#><#5026#> by 1=0 <#5027#>=0<#5030#><#5030#><#5027#>

<#5028#><#5031#>.. abs<#5031#><#5028#>(x): absolute value of x (modulus if x is complex). Polynomials, power series and rational functions are not allowed.

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

<#5038#><#5038#> by 1=0 <#5039#>=0<#5042#><#5042#><#5039#>

<#5040#><#5043#>.. acos<#5043#><#5040#>(x): principal branch of #math254#cos-1(x), i.e. such that #math255#Re(acos(x))∈[0, π]. If #math256#x#tex2html_wrap_inline25608# and | x| ;SPMgt; 1 then #math257#acos(x) is complex.

The library syntax is #math258##tex2html_wrap_inline25612#(x, prec).

<#5054#><#5054#> by 1=0 <#5055#>=0<#5058#><#5058#><#5055#>

<#5056#><#5059#>.. acosh<#5059#><#5056#>(x): principal branch of #math259#cosh-1(x), i.e. such that #math260#Im(acosh(x))∈[0, π]. If #math261#x#tex2html_wrap_inline25619# and x ;SPMlt; 1 then #math262#acosh(x) is complex.

The library syntax is #math263##tex2html_wrap_inline25623#(x, prec).

<#5070#><#5070#> by 1=0 <#5071#>=0<#5074#><#5074#><#5071#>

<#5072#><#5075#>.. agm<#5075#><#5072#>(x, y): arithmetic-geometric mean of x and y. In the case of complex or negative numbers, the principal square root is always chosen. p-adic or power series arguments are also allowed. Note that a p-adic agm exists only if x/y is congruent to 1 modulo p (modulo 16 for p = 2). x and y cannot both be vectors or matrices.

The library syntax is #math264##tex2html_wrap_inline25635#(x, y, prec).

<#5082#><#5082#> by 1=0 <#5083#>=0<#5086#><#5086#><#5083#>

<#5084#><#5087#>.. arg<#5087#><#5084#>(x): argument of the complex number x, such that #math265#- π ;SPMlt; arg(x)≤π.

The library syntax is #math266##tex2html_wrap_inline25640#(x, prec).

<#5095#><#5095#> by 1=0 <#5096#>=0<#5099#><#5099#><#5096#>

<#5097#><#5100#>.. asin<#5100#><#5097#>(x): principal branch of #math267#sin-1(x), i.e. such that #math268#Re(asin(x))∈[- π/2, π/2]. If #math269#x#tex2html_wrap_inline25647# and | x| ;SPMgt; 1 then #math270#asin(x) is complex.

The library syntax is #math271##tex2html_wrap_inline25651#(x, prec).

<#5111#><#5111#> by 1=0 <#5112#>=0<#5115#><#5115#><#5112#>

<#5113#><#5116#>.. asinh<#5116#><#5113#>(x): principal branch of #math272#sinh-1(x), i.e. such that #math273#Im(asinh)(x)∈[- π/2, π/2].

The library syntax is #math274##tex2html_wrap_inline25658#(x, prec).

<#5125#><#5125#> by 1=0 <#5126#>=0<#5129#><#5129#><#5126#>

<#5127#><#5130#>.. atan<#5130#><#5127#>(x): principal branch of #math275#tan-1(x), i.e. such that #math276#Re(atan(x))∈] - π/2, π/2[.

The library syntax is #math277##tex2html_wrap_inline25665#(x, prec).

<#5139#><#5139#> by 1=0 <#5140#>=0<#5143#><#5143#><#5140#>

<#5141#><#5144#>.. atanh<#5144#><#5141#>(x): principal branch of #math278#tanh-1(x). i.e. such that #math279#Im(atanh(x))∈] - π/2, π/2]. If #math280#x#tex2html_wrap_inline25672# and | x| ;SPMgt; 1 then #math281#atanh(x) is complex.

The library syntax is #math282##tex2html_wrap_inline25676#(x, prec).

<#5155#><#5155#> by 1=0 <#5156#>=0<#5159#><#5159#><#5156#>

<#5157#><#5160#>.. bernreal<#5160#><#5157#>(x): Bernoulli number Bx, where B0 = 1, B1 = - 1/2, B2 = 1/6,..., expressed as a real number with the current precision.

The library syntax is #math283##tex2html_wrap_inline25683#(x, prec).

<#5167#><#5167#> by 1=0 <#5168#>=0<#5171#><#5171#><#5168#>

<#5169#><#5172#>.. bernvec<#5172#><#5169#>(x): creates a vector containing, as rational numbers, the Bernoulli numbers B0, B2,..., B2x. These Bernoulli numbers can then be used as follows. Assume that this vector has been put into a variable, say b. Then we define under GP:

<#578#>bern(x)=if(x==1,-1/2,if((x;SPMlt;0)||(x2),0,b[x/2+1]))<#578#>

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

The library syntax is #math284##tex2html_wrap_inline25690#(x).

<#5179#><#5179#> by 1=0 <#5180#>=0<#5183#><#5183#><#5180#>

<#5181#><#5184#>.. cos<#5184#><#5181#>(x): cosine of x.

The library syntax is #math285##tex2html_wrap_inline25694#(x, prec).

<#5191#><#5191#> by 1=0 <#5192#>=0<#5195#><#5195#><#5192#>

<#5193#><#5196#>.. cosh<#5196#><#5193#>(x): hyperbolic cosine of x.

The library syntax is #math286##tex2html_wrap_inline25698#(x, prec).

<#5203#><#5203#> by 1=0 <#5204#>=0<#5207#><#5207#><#5204#>

<#5205#><#5208#>.. dilog<#5208#><#5205#>(x): principal branch of the dilogarithm of x, i.e. analytic continuation of the power series #math287#log2(x) = #tex2html_wrap_inline25702#xn/n2.

The library syntax is #math288##tex2html_wrap_inline25704#(x, prec).

<#5215#><#5215#> by 1=0 <#5216#>=0<#5219#><#5219#><#5216#>

<#5217#><#5220#>.. eint1<#5220#><#5217#>(x): exponential integral #math289##tex2html_wrap_inline25707##tex2html_wrap_inline25708# dt.

The library syntax is #math290##tex2html_wrap_inline25710#(x, prec).

<#5231#><#5231#> by 1=0 <#5232#>=0<#5235#><#5235#><#5232#>

<#5233#><#5236#>.. erfc<#5236#><#5233#>(x): complementary error function #math291#(2/#tex2html_wrap_inline25713#)#tex2html_wrap_inline25714#e-t2 dt.

The library syntax is #math292##tex2html_wrap_inline25716#(x, prec).

<#5243#><#5243#> by 1=0 <#5244#>=0<#5247#><#5247#><#5244#>

<#5245#><#5248#>.. eta<#5248#><#5245#>(x): Dedekind's η function, without the q1/24. The meaning is this. If x is a complex number with positive imaginary part, the result is #math293##tex2html_wrap_inline25722#(1 - qn), where #math294#q = e2iπx. If x is a power series (or can be converted to a power series) with positive valuation, the result is #math295##tex2html_wrap_inline25726#(1 - xn).

The library syntax is #math296##tex2html_wrap_inline25728#(x, prec).

<#5255#><#5255#> by 1=0 <#5256#>=0<#5259#><#5259#><#5256#>

<#5257#><#5260#>.. euler<#5260#><#5257#>: Euler's constant #math297#0.57721 ... .

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

The library syntax is #math298##tex2html_wrap_inline25731#(prec) where prec <#605#>must<#605#> be given. Note that this creates γ on the PARI stack. If one does not want to create it on that stack but be able to use it later under the global name <#2777#><#5267#><#5267#>geuler<#2777#> (with no parentheses) use instead #math299##tex2html_wrap_inline25735#(prec).

<#5272#><#5272#> by 1=0 <#5273#>=0<#5276#><#5276#><#5273#>

<#5274#><#5277#>.. exp<#5277#><#5274#>(x): exponential of x. p-adic arguments with positive valuation are accepted.

The library syntax is #math300##tex2html_wrap_inline25740#(x, prec).

<#5284#><#5284#> by 1=0 <#5285#>=0<#5288#><#5288#><#5285#>

<#5286#><#5289#>.. gamh<#5289#><#5286#>(x): gamma function evaluated at the argument x + 1/2. When x is an integer, this is much faster than using #math301#gamma(x + 1/2).

The library syntax is #math302##tex2html_wrap_inline25746#(x, prec).

<#5297#><#5297#> by 1=0 <#5298#>=0<#5301#><#5301#><#5298#>

<#5299#><#5302#>.. gamma<#5302#><#5299#>(x): gamma function of x. In the present version 1.37 the p-adic gamma function is not yet implemented.

The library syntax is #math303##tex2html_wrap_inline25751#(x, prec).

<#5309#><#5309#> by 1=0 <#5310#>=0<#5313#><#5313#><#5310#>

<#5311#><#5314#>.. hyperu<#5314#><#5311#>(a, b, x): U-confluent hypergeometric function with parameters a and b.

The library syntax is #math304##tex2html_wrap_inline25756#(a, b, x, prec).

<#5321#><#5321#> by 1=0 <#5322#>=0<#5325#><#5325#><#5322#>

<#5323#><#5326#>.. incgam<#5326#><#5323#>(x, y): incomplete gamma function.

The arguments x and y must be positive. The result returned is #math305##tex2html_wrap_inline25761#e-ttx-1 dt.

The library syntax is #math306##tex2html_wrap_inline25763#(x, y, prec).

Note: in addition, there exist also the functions <#2778#><#5333#><#5333#>incgam1 and <#5335#><#5335#>incgam2<#2778#> which are used for internal purposes.

<#5337#><#5337#> by 1=0 <#5338#>=0<#5341#><#5341#><#5338#>

<#5339#><#5342#>.. incgam3<#5342#><#5339#>(x, y): complementary incomplete gamma function.

The arguments x and y must be positive. The result returned is #math307##tex2html_wrap_inline25768#e-ttx-1 dt. when y is not too large.

The library syntax is #math308##tex2html_wrap_inline25771#(x, y, prec).

<#5349#><#5349#> by 1=0 <#5350#>=0<#5353#><#5353#><#5350#>

<#5351#><#5354#>.. incgam4<#5354#><#5351#>#math309#(x, y, z): incomplete gamma function with given gamma value. This function assumes (of course without checking) that #math310#z = Γ(x). The arguments x and y must be positive. The result returned is #math311##tex2html_wrap_inline25777#e-ttx-1 dt, as in the ordinary <#630#>incgam<#630#> function, but the computation will be much faster when y is small.

The library syntax is #math312##tex2html_wrap_inline25780#(x, y, z, prec).

<#5361#><#5361#> by 1=0 <#5362#>=0<#5365#><#5365#><#5362#>

<#5363#><#5366#>.. jbesselh<#5366#><#5363#>(n, x): J-Bessel function of half integral index. More precisely, <#633#>jbesselh(n,x)<#633#> computes #math313#Jn+1/2(x) where n must be of type integer, and x is any element of #tex2html_wrap_inline25787#. In the present version 1.37, this function is not very accurate when x is small. This will be improved.

The library syntax is #math314##tex2html_wrap_inline25790#(n, x, prec).

<#5374#><#5374#> by 1=0 <#5375#>=0<#5378#><#5378#><#5375#>

<#5376#><#5379#>.. jell<#5379#><#5376#>(x): elliptic j-invariant. x must be a complex number with positive imaginary part, or convertible into a power series or a p-adic number with positive valuation.

The library syntax is #math315##tex2html_wrap_inline25796#(x, prec).

<#5386#><#5386#> by 1=0 <#5387#>=0<#5390#><#5390#><#5387#>

<#5388#><#5391#>.. kbessel<#5391#><#5388#>(nu, x): K-Bessel function of index nu (which can be complex) and argument x. Only real and positive arguments x are allowed in the present version 1.37.

The library syntax is #math316##tex2html_wrap_inline25802#(nu, x, prec).

Note: in addition, another implementation of this function which is often faster than kbessel is the function <#2779#><#5398#><#5398#>kbessel2<#2779#>.

<#5400#><#5400#> by 1=0 <#5401#>=0<#5404#><#5404#><#5401#>

<#5402#><#5405#>.. ln<#5405#><#5402#>(x) or <#642#>log<#642#>(x):<#5409#><#5409#> principal branch of the natural logarithm of x, i.e. such that #math317#Im(ln(x))∈] - π, π]. The result is complex (with imaginary part equal to π) if #math318#x#tex2html_wrap_inline25809# and x ;SPMlt; 0.

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

The library syntax is #math320##tex2html_wrap_inline25820#(x, prec).

<#5416#><#5416#> by 1=0 <#5417#>=0<#5420#><#5420#><#5417#>

<#5418#><#5421#>.. lngamma<#5421#><#5418#>(x): principal branch of the logarithm of the gamma function of x. Can have much larger arguments than <#647#>gamma<#647#> itself. In the present version 1.37the p-adic lngamma function is not yet implemented.

The library syntax is #math321##tex2html_wrap_inline25825#(x, prec).

<#5428#><#5428#> by 1=0 <#5429#>=0<#5432#><#5432#><#5429#>

<#5430#><#5433#>.. logagm<#5433#><#5430#>(x): principal branch of the natural logarithm of x, computed using an agm formula suggested by Mestre, when x is real, otherwise identical to <#650#>log<#650#>.

The library syntax is #math322##tex2html_wrap_inline25830#(x, prec).

<#5440#><#5440#> by 1=0 <#5441#>=0<#5444#><#5444#><#5441#>

<#5442#><#5445#>.. pi<#5445#><#5442#>: the constant pi (#math323#3.14159 ... ).

The library syntax is #math324##tex2html_wrap_inline25833#(prec) where prec <#654#>must<#654#> be given. Note that this creates π on the PARI stack. If one does not want to create it on that stack but be able to use it later under the global name <#2780#><#5452#><#5452#>gpi<#2780#> (with no parentheses) use instead #math325##tex2html_wrap_inline25837#(prec).

<#5457#><#5457#> by 1=0 <#5458#>=0<#5461#><#5461#><#5458#>

<#5459#><#5462#>.. polylog<#5462#><#5459#>(m, x): #math326#mth polylogarithm of x, i.e. analytic continuation of the power series #math327#logm(x) = #tex2html_wrap_inline25842#xn/nm. The program uses the power series when #math328#| x|2≤1/2, and the power series expansion in log(x) otherwise. It is valid in a large domain (at least | x| ;SPMlt; 230), but should not be used too far away from the unit circle since it is then better to use the functional equation linking the value at x to the value at 1/x, which takes a trivial form for the <#660#>polylogd<#660#> and <#661#>polylogp<#661#> functions below. Power series, polynomial, rational and vector/matrix arguments are allowed.

The library syntax is #math329##tex2html_wrap_inline25849#(m, x, prec).

<#5470#><#5470#> by 1=0 <#5471#>=0<#5474#><#5474#><#5471#>

<#5472#><#5475#>.. polylogd<#5475#><#5472#>(m, x): modified #math330#mth polylogarithm of x, called #math331##tex2html_wrap_inline25854#(x) in Zagier, defined for | x|≤1 by

#math332#

m#tex2html_wrap_indisplay25857##tex2html_wrap_indisplay25858##tex2html_wrap_indisplay25859#logm-k(x) + #tex2html_wrap_indisplay25860#log| 1 - x|#tex2html_wrap_indisplay25861#

and such that #math333#Dm(1/x) = (- 1)m-1Dm(x), where ℜm denotes ℜ or ℑ depending whether m is odd or even.

The library syntax is #math334##tex2html_wrap_inline25868#(m, x, prec).

<#5490#><#5490#> by 1=0 <#5491#>=0<#5494#><#5494#><#5491#>

<#5492#><#5495#>.. polylogdold<#5495#><#5492#>(m, x): modified #math335#mth polylogarithm of x, called Dm(x) in Zagier, defined for | x|≤1 by

#math336#

m#tex2html_wrap_indisplay25875##tex2html_wrap_indisplay25876##tex2html_wrap_indisplay25877#logm-k(x) - #tex2html_wrap_indisplay25878##tex2html_wrap_indisplay25879##tex2html_wrap_indisplay25880#

and such that #math337#Dm(1/x) = (- 1)m-1Dm(x), where ℜm denotes ℜ or ℑ depending whether m is odd or even.

The library syntax is #math338##tex2html_wrap_inline25887#(m, x, prec).

<#5512#><#5512#> by 1=0 <#5513#>=0<#5516#><#5516#><#5513#>

<#5514#><#5517#>.. polylogp<#5517#><#5514#>(m, x): another modified #math339#mth polylogarithm of x, called Pm(x) in Zagier, defined for | x|≤1 by

#math340#

m#tex2html_wrap_indisplay25894##tex2html_wrap_indisplay25895##tex2html_wrap_indisplay25896#(log| x|)klogm-k(x) - #tex2html_wrap_indisplay25897#(log| x|)m#tex2html_wrap_indisplay25898#

and such that #math341#Pm(1/x) = (- 1)m-1Pm(x), where ℜm denotes ℜ or ℑ depending whether m is odd or even.

The library syntax is #math342##tex2html_wrap_inline25905#(m, x, prec).

<#5532#><#5532#> by 1=0 <#5533#>=0<#5536#><#5536#><#5533#>

<#5534#><#5537#>.. psi<#5537#><#5534#>(x): the ψ-function of x, i.e. the logarithmic derivative #math343#Γ'(x)/Γ(x).

The library syntax is #math344##tex2html_wrap_inline25911#(x, prec).

<#5544#><#5544#> by 1=0 <#5545#>=0<#5548#><#5548#><#5545#>

<#5546#><#5549#>.. sin<#5549#><#5546#>(x): sine of x.

The library syntax is #math345##tex2html_wrap_inline25915#(x, prec).

<#5556#><#5556#> by 1=0 <#5557#>=0<#5560#><#5560#><#5557#>

<#5558#><#5561#>.. sinh<#5561#><#5558#>(x): hyperbolic sine of x.

The library syntax is #math346##tex2html_wrap_inline25919#(x, prec).

<#5568#><#5568#> by 1=0 <#5569#>=0<#5572#><#5572#><#5569#>

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

The library syntax is #math348##tex2html_wrap_inline25931#(x).

<#5580#><#5580#> by 1=0 <#5581#>=0<#5584#><#5584#><#5581#>

<#5582#><#5585#>.. sqrt<#5585#><#5582#>(x): principal branch of the square root of x, i.e. such that #math349#Arg(sqrt(x))∈] - π/2, π/2], or in other words such that #math350#Re(sqrt(x)) ;SPMgt; 0 or #math351#Re(sqrt(x)) = 0 and #math352#Im(sqrt(x)) ;SPMgt; = 0. Integermod a prime and p-adics are allowed as arguments. If #math353#x#tex2html_wrap_inline25940# and x ;SPMlt; 0 the result is complex with positive imaginary part.

The library syntax is #math354##tex2html_wrap_inline25943#(x, prec).

<#5597#><#5597#> by 1=0 <#5598#>=0<#5601#><#5601#><#5598#>

<#5599#><#5602#>.. tan<#5602#><#5599#>(x): tangent of x.

The library syntax is #math355##tex2html_wrap_inline25947#(x, prec).

<#5609#><#5609#> by 1=0 <#5610#>=0<#5613#><#5613#><#5610#>

<#5611#><#5614#>.. tanh<#5614#><#5611#>(x): hyperbolic tangent of x.

The library syntax is #math356##tex2html_wrap_inline25951#(x, prec).

<#5621#><#5621#> by 1=0 <#5622#>=0<#5625#><#5625#><#5622#>

<#5623#><#5626#>.. teich<#5626#><#5623#>(x): Teichmuller character of the p-adic number x.

The library syntax is #math357##tex2html_wrap_inline25956#(x).

<#5633#><#5633#> by 1=0 <#5634#>=0<#5637#><#5637#><#5634#>

<#5635#><#5638#>.. wf<#5638#><#5635#>(x): Weber's f function, i.e. such that #math358#j = (f24 -16)3/f24.

The library syntax is #math359##tex2html_wrap_inline25961#(x, prec).

<#5645#><#5645#> by 1=0 <#5646#>=0<#5649#><#5649#><#5646#>

<#5647#><#5650#>.. wf2<#5650#><#5647#>(x): Weber's f2 function, i.e. such that #math360#j = (f224 +16)3/f224.

The library syntax is #math361##tex2html_wrap_inline25966#(x, prec).

<#5657#><#5657#> by 1=0 <#5658#>=0<#5661#><#5661#><#5658#>

<#5659#><#5662#>.. zeta<#5662#><#5659#>(s): Riemann's zeta function #math362#ζ(s) = #tex2html_wrap_inline25969#n-s, computed using the Euler-Maclaurin summation formula, except when s is of type integer, in which case it is computed using Bernoulli numbers for s ;SPMlt; = 0 or s ;SPMgt; 0 and even, and using modular forms for s ;SPMgt; 0 and odd.

The library syntax is #math363##tex2html_wrap_inline25975#(s, prec).

by1=0 <#5669#>=0<#5671#><#5671#><#5669#>



<#5670#><#5672#>. Arithmetic functions.<#5672#><#5670#>


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

In the present version 1.37a primitive but useful version of the <#5677#><#5677#>ECM method has been implemented. Also, numbers found to be pseudo-primes after 10 successful trials of the <#5679#><#5679#>Rabin-Miller test are declared primes.

<#5681#><#5681#> by 1=0 <#5682#>=0<#5685#><#5685#><#5682#>

<#5683#><#5686#>.. bezout<#5686#><#5683#>(x, y): finds u and v minimal in a natural sense such that #math364#x*u + y*v = gcd(x, y). The arguments must be both integers or both polynomials, and the result is a row vector with three components u, v, and #math365#gcd(x, y).

The library syntax is either #math366##tex2html_wrap_inline25988#(x, y) to get the vector, or #math367##tex2html_wrap_inline25990#(x, y,u,v) which gives as result the address of the created gcd, and puts in u and v the addresses of the corresponding created objects.

<#5698#><#5698#> by 1=0 <#5699#>=0<#5702#><#5702#><#5699#>

<#5700#><#5703#>.. bigomega<#5703#><#5700#>(x): number of prime divisors of x counted with multiplicity. x must be an integer, and the result is a 32-bit C-integer.

The library syntax is #math368##tex2html_wrap_inline25997#(x).

<#5710#><#5710#> by 1=0 <#5711#>=0<#5714#><#5714#><#5711#>

<#5712#><#5715#>.. bin<#5715#><#5712#>(x, y): <#5719#><#5719#>binomial coefficient #math369##tex2html_wrap_inline26000#x#tex2html_wrap_inline26001#y. Here y must be an integer, but x can be any PARI object.

The library syntax is #math370##tex2html_wrap_inline26005#(x, y), where y must be a C-integer.

<#5727#><#5727#> by 1=0 <#5728#>=0<#5731#><#5731#><#5728#>

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

The library syntax is #math371##tex2html_wrap_inline26012#(x, lmax), where lmax is a C integer.

<#5741#><#5741#> by 1=0 <#5742#>=0<#5745#><#5745#><#5742#>

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

The library syntax is #math372##tex2html_wrap_inline26019#(x, p).

<#5753#><#5753#> by 1=0 <#5754#>=0<#5757#><#5757#><#5754#>

<#5755#><#5758#>.. buchimag<#5758#><#5755#>(D, c, t): McCurley's sub-exponential algorithm for computing the class group of an imaginary quadratic field of discriminant D. Should be used instead of <#751#>classno<#751#> for #math373#| D| ;SPMgt; 1025 or when the <#753#>structure<#753#> is wanted. The number c is a real number which must be (strictly) between 0 and 6, and controls the execution time and the stack size. Reasonable values for c are between 0.5 and 2. t is the number of ``extra relations'' that we want to use in McCurley's algorithm (see below). We must have t≥1, and usually t = 20 is sufficient.

The result of this function is a vector with 3 components. The first is the class number, and the second is a vector giving the structure of the class group as a product of cyclic groups. The last component is a measure of the correctness of the result. If it is close to 1, the result is correct (under GRH). If it is close to a larger integer, this shows that the class number is off by a factor equal to this integer, and you must start again with a larger value for t (the value of c plays no role here). Note: some installations may have this function disabled.

The library syntax is #math374##tex2html_wrap_inline26035#(D, c, t).

<#5765#><#5765#> by 1=0 <#5766#>=0<#5769#><#5769#><#5766#>

<#5767#><#5770#>.. buchreal<#5770#><#5767#>(D, n, c, t): Buchmann's sub-exponential algorithm for computing the class group and the regulator of a real quadratic field of discriminant D. Should be used instead of <#756#>classno<#756#> and <#757#>regula<#757#> for D ;SPMgt; 1010 or when the <#759#>structure<#759#> is wanted. If the integer n is equal to 0 the function computes the ordinary (or wide) class group and regulator, while if n is non-zero it computes the narrow class group and regulator. The number c is a real number which must be (strictly) between 0 and 6, and controls the execution time and the stack size. Reasonable values for c are between 0.5 and 2. t is the number of ``extra relations'' that we want to use in McCurley's algorithm (see below). We must have t≥2, and usually t = 20 is sufficient.

The result of this function is a vector with 5 components. The first is the class number, and the second is a vector giving the structure of the class group as a product of cyclic groups. The third component is the regulator, computed to an accuracy which is determined by the program and not by the user (note however that once the regulator is known to a small accuracy it is trivial to compute it to very high accuracy. I leave this as an exercise to the reader). The fourth component is a measure of the error made on computing the regulator but should not be taken too seriously. It is usually less than 10-20. If it is not very small (and t≥2), this probably indicates a bug in the program (please report). Finally the last component is a measure of the correctness of the result. If it is close to 1, the results are correct (under GRH). If it is close to a larger integer, this shows that the product of the class number by the regulator is off by a factor equal to this integer, and you must start again with a larger value for t (the value of c plays no role here). Note: some installations may have this function disabled.

The library syntax is #math375##tex2html_wrap_inline26055#(D, n, c, t).

<#5777#><#5777#> by 1=0 <#5778#>=0<#5781#><#5781#><#5778#>

<#5779#><#5782#>.. cf<#5782#><#5779#>(x): creates the row vector whose components are the partial quotients of the <#5786#><#5786#>continued fraction expansion of x. If x is a real number, the expansion stops at the last significant partial quotient. x can also be a rational function.

The library syntax is #math376##tex2html_wrap_inline26061#(x).

<#5791#><#5791#> by 1=0 <#5792#>=0<#5795#><#5795#><#5792#>

<#5793#><#5796#>.. cf2<#5796#><#5793#>(b, x): creates the row vector whose components are the partial quotients of the continued fraction expansion of x, the numerators being equal to the coefficients of the vector b. The length of the result is equal to the length of b unless a partial remainder is encountered which is equal to zero, in which case the expansion stops. In the case of real numbers, the stopping criterion in thus different from that of <#766#>cf<#766#> since if b is too long, some partial quotients may not be significant. x can also be a rational function or a power series.

The library syntax is #math377##tex2html_wrap_inline26069#(b, x).

<#5803#><#5803#> by 1=0 <#5804#>=0<#5807#><#5807#><#5804#>

<#5805#><#5808#>.. chinese<#5808#><#5805#>(x, y): x and y being both integermods or polymods, creates (with the same type) a z in the same residue class as x and in the same residue class as y, if it is possible.

The library syntax is #math378##tex2html_wrap_inline26077#(x, y).

<#5815#><#5815#> by 1=0 <#5816#>=0<#5819#><#5819#><#5816#>

<#5817#><#5820#>.. classno<#5820#><#5817#>(x): class number of the quadratic field of discriminant x. In the present version 1.37, a simple algorithm is used for x ;SPMgt; 0, so x should not be too large (say x ;SPMlt; 107) for the time to be reasonable. On the other hand, for x ;SPMlt; 0 one can reasonably compute classno(x) for #math379#| x| ;SPMlt; 1025, since the method used is Shanks' method which is in #math380#O(| x|1/4). For larger values of | D|, see <#773#>buchimag<#773#> for D ;SPMlt; 0 and <#774#>buchreal<#774#> for D ;SPMgt; 0.

The library syntax is #math381##tex2html_wrap_inline26091#(x).

There also exists the function <#2783#><#5827#><#5827#>classno2<#2783#>, which computes the class number using the functional equation. However, it is in #math382#O(| x|1/2). Finally, in library mode only there exists the function <#2784#><#5829#><#5829#>classno3<#2784#> which computes the class number of an imaginary quadratic field by counting reduced forms, a O(| x|) algorithm. See also 3.4.20 below.

<#5831#><#5831#> by 1=0 <#5832#>=0<#5835#><#5835#><#5832#>

<#5833#><#5836#>.. compose<#5836#><#5833#>(x, y) composition of the binary quadratic forms x and y. This is of course a special case of <#780#>gmul(x,y)<#780#>. See also <#781#>nucomp<#781#> and <#782#>nudupl<#782#>.

The library syntax is #math383##tex2html_wrap_inline26098#(x, y).

<#5843#><#5843#> by 1=0 <#5844#>=0<#5847#><#5847#><#5844#>

<#5845#><#5848#>.. comprealraw<#5848#><#5845#>(x, y) composition of the binary quadratic forms x and y with positive discriminant, without reduction of the result. This is useful e.g. to compute a generating element of an ideal.

The library syntax is #math384##tex2html_wrap_inline26103#(x, y).

<#5855#><#5855#> by 1=0 <#5856#>=0<#5859#><#5859#><#5856#>

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

The library syntax is #math385##tex2html_wrap_inline26113#(x).

<#5867#><#5867#> by 1=0 <#5868#>=0<#5871#><#5871#><#5868#>

<#5869#><#5872#>.. divisors<#5872#><#5869#>(x): creates a row vector whose components are the positive divisors of the integer x in increasing order.

The library syntax is #math386##tex2html_wrap_inline26117#(x).

<#5879#><#5879#> by 1=0 <#5880#>=0<#5883#><#5883#><#5880#>

<#5881#><#5884#>.. fact<#5884#><#5881#>(x) or x!: factorial of x. The expression x! gives a result which is an integer, while #math387#fact(x) gives a real number.

The library syntax is #math388##tex2html_wrap_inline26124#(x) for x! and #math389##tex2html_wrap_inline26127#(x, prec) for #math390#fact(x). x must be a 32-bit C-integer and not a PARI integer.

<#5896#><#5896#> by 1=0 <#5897#>=0<#5900#><#5900#><#5897#>

<#5898#><#5901#>.. factfq<#5901#><#5898#>(x, p, a): factorization in the field #tex2html_wrap_inline26134# defined by the irreducible polynomial a over #tex2html_wrap_inline26139# of the polynomial x. The coefficients of x must be operation-compatible with #math391##tex2html_wrap_inline26143#/p#tex2html_wrap_inline26144#. The result is a two column matrix, the first column being the irreducible polynomials dividing x, and the second the exponents. It is advised to use for the variable of a (which will be used as variable of a polymod), a name distinct from the other variables used, so that a <#796#>lift()<#796#> of the result will be legible.

The library syntax is #math392##tex2html_wrap_inline26148#(x, p, a).

<#5912#><#5912#> by 1=0 <#5913#>=0<#5916#><#5916#><#5913#>

<#5914#><#5917#>.. factmod<#5917#><#5914#>(x, p): factorization mod p of the polynomial x. The coefficients of x must be operation-compatible with #math393##tex2html_wrap_inline26154#/p#tex2html_wrap_inline26155#. The result is a two column matrix, the first column being the irreducible polynomials dividing x, and the second the exponents.

The library syntax is #math394##tex2html_wrap_inline26158#(x, p).

<#5926#><#5926#> by 1=0 <#5927#>=0<#5930#><#5930#><#5927#>

<#5928#><#5931#>.. factor<#5931#><#5928#>(x): general factorization function. If x is of type integer, rational, polynomial or rational function, the result is a two column matrix, the first column being the irreducibles dividing x (prime numbers or polynomials), and the second the exponents. If x is a vector or a matrix, the factoring is done componentwise (hence the result is a vector or matrix of two column matrices).

The polynomials or rational functions to be factored must have coefficients either integers or integermods. Note that PARI does <#801#>not<#801#> yet know how to factor multivariate polynomials.

The library syntax is #math395##tex2html_wrap_inline26164#(x). See also <#2785#><#5938#><#5938#>factpol<#2785#> <#2786#><#5940#><#5940#>factpol2<#2786#> and <#2787#><#5942#><#5942#>factornf<#2787#>.

<#5944#><#5944#> by 1=0 <#5945#>=0<#5948#><#5948#><#5945#>

<#5946#><#5949#>.. fibo<#5949#><#5946#>(x): #math396#xth Fibonacci number.

The library syntax is #math397##tex2html_wrap_inline26168#(x). x must be a 32-bit C-integer and not a PARI integer.

<#5957#><#5957#> by 1=0 <#5958#>=0<#5961#><#5961#><#5958#>

<#5959#><#5962#>.. gcd<#5962#><#5959#>(x, y): creates the greatest common divisor of x and y. x and y can be of quite general types; for instance both rational numbers. Vector/matrix types are also accepted. Note that for these types, <#810#>gcd<#810#> is not commutative.

The library syntax is #math398##tex2html_wrap_inline26176#(x, y).

<#5969#><#5969#> by 1=0 <#5970#>=0<#5973#><#5973#><#5970#>

<#5971#><#5974#>.. hclassno<#5974#><#5971#>(x): <#5978#><#5978#>Hurwitz class number of x, where x is nonnegative and congruent to 0 or 3 modulo 4. See also 3.4.9 above.

The library syntax is #math399##tex2html_wrap_inline26181#(x).

<#5983#><#5983#> by 1=0 <#5984#>=0<#5987#><#5987#><#5984#>

<#5985#><#5988#>.. hilb<#5988#><#5985#>#math400#(x, y, p) or <#816#>hilbp<#816#>(x, y): <#5992#><#5992#>Hilbert symbol of x and y. If x and y are of type integer or fraction, the function <#818#>hilb<#818#> must be used with an explicit third parameter p, p = 0 meaning the place at infinity. Otherwise, p need not be given, and x and y can be of compatible types integer, fraction, real, integermod or p-adic.

The library syntax is in both cases #math401##tex2html_wrap_inline26195#(x, y, p) or #math402##tex2html_wrap_inline26197#(x, y).

<#6000#><#6000#> by 1=0 <#6001#>=0<#6004#><#6004#><#6001#>

<#6002#><#6005#>.. isfund<#6005#><#6002#>(x): true (1) if x is equal to 1 or to the discriminant of a quadratic field, false (0) otherwise.

The library syntax is #math403##tex2html_wrap_inline26201#(x).

<#6012#><#6012#> by 1=0 <#6013#>=0<#6016#><#6016#><#6013#>

<#6014#><#6017#>.. isprime<#6017#><#6014#>(x): true (1) if x is a strong pseudo-prime for 10 randomly chosen bases, false (0) otherwise.

The library syntax is #math404##tex2html_wrap_inline26205#(x).

<#6024#><#6024#> by 1=0 <#6025#>=0<#6028#><#6028#><#6025#>

<#6026#><#6029#>.. ispsp<#6029#><#6026#>(x): true (1) if x is a strong pseudo-prime for a randomly chosen base, false (0) otherwise.

The library syntax is #math405##tex2html_wrap_inline26209#(x).

<#6036#><#6036#> by 1=0 <#6037#>=0<#6040#><#6040#><#6037#>

<#6038#><#6041#>.. isqrt<#6041#><#6038#>(x): integer square root of x, which must be of PARI type integer. A negative x is allowed, and the result in that case is <#828#>i*isqrt(-x)<#828#>.

The library syntax is #math406##tex2html_wrap_inline26214#(x).

<#6048#><#6048#> by 1=0 <#6049#>=0<#6052#><#6052#><#6049#>

<#6050#><#6053#>.. issqfree<#6053#><#6050#>(x): true (1) if x is squarefree, false if not. Here x can be an integer or a polynomial.

The library syntax is #math407##tex2html_wrap_inline26219#(x).

<#6060#><#6060#> by 1=0 <#6061#>=0<#6064#><#6064#><#6061#>

<#6062#><#6065#>.. issquare<#6065#><#6062#>(x): true (1) if x is square, false if not.

The library syntax is #math408##tex2html_wrap_inline26223#(x).

<#6072#><#6072#> by 1=0 <#6073#>=0<#6076#><#6076#><#6073#>

<#6074#><#6077#>.. kronecker<#6077#><#6074#>(x, y) or <#835#>kro<#835#>(x, y): Kronecker <#6081#><#6081#> (i.e. generalized Legendre) symbol #math409##tex2html_wrap_inline26227##tex2html_wrap_inline26228##tex2html_wrap_inline26229#. x and y must be of type integer and the result (0 or ±1) is a 32-bit C-integer.

The library syntax is #math410##tex2html_wrap_inline26235#(x, y).

<#6089#><#6089#> by 1=0 <#6090#>=0<#6093#><#6093#><#6090#>

<#6091#><#6094#>.. lcm<#6094#><#6091#>(x, y): least common multiple of x and y, i.e. such that #math411#lcm(x, y)*gcd(x, y) = x*y.

The library syntax is #math412##tex2html_wrap_inline26241#(x, y).

<#6103#><#6103#> by 1=0 <#6104#>=0<#6107#><#6107#><#6104#>

<#6105#><#6108#>.. mu<#6108#><#6105#>(x): Möbius μ-function of x. x must be of type integer and the result (0 or ±1) is a 32-bit C-integer.

The library syntax is #math413##tex2html_wrap_inline26249#(x).

<#6115#><#6115#> by 1=0 <#6116#>=0<#6119#><#6119#><#6116#>

<#6117#><#6120#>.. nextprime<#6120#><#6117#>(x): finds the smallest prime greater than or equal to x. x must be of type integer.

The library syntax is #math414##tex2html_wrap_inline26254#(x).

<#6127#><#6127#> by 1=0 <#6128#>=0<#6131#><#6131#><#6128#>

<#6129#><#6132#>.. nucomp<#6132#><#6129#>(x, y, l ) composition of the primitive positive definite binary quadratic forms x and y using the NUCOMP and NUDUPL algorithms of Shanks (a la Atkin). l is any positive constant, but for optimal speed, one should take #math415#l = | D|1/4 where D is the common discriminant of x and y.

The library syntax is #math416##tex2html_wrap_inline26264#(x, y, l ). The auxiliary function #math417##tex2html_wrap_inline26266#(x, l ) also exists when x = y.

<#6142#><#6142#> by 1=0 <#6143#>=0<#6146#><#6146#><#6143#>

<#6144#><#6147#>.. numdiv<#6147#><#6144#>(x): number of divisors of x. x must be of type integer, and the result is a 32-bit C-integer.

The library syntax is #math418##tex2html_wrap_inline26272#(x).

<#6154#><#6154#> by 1=0 <#6155#>=0<#6158#><#6158#><#6155#>

<#6156#><#6159#>.. nupow<#6159#><#6156#>(x, n): n-th power of the primitive positive definite binary quadratic form x using the NUCOMP and NUDUPL algorithms (see <#855#>nucomp<#855#> above).

The library syntax is #math419##tex2html_wrap_inline26277#(x, n).

<#6166#><#6166#> by 1=0 <#6167#>=0<#6170#><#6170#><#6167#>

<#6168#><#6171#>.. omega<#6171#><#6168#>(x): number of distinct prime divisors of x. x must be of type integer, and the result is a 32-bit C-integer.

The library syntax is #math420##tex2html_wrap_inline26282#(x).

<#6178#><#6178#> by 1=0 <#6179#>=0<#6182#><#6182#><#6179#>

<#6180#><#6183#>.. order<#6183#><#6180#>(x): x must be an integer mod n, and the result is the order of x in the multiplicative group #math421#(#tex2html_wrap_inline26288#/n#tex2html_wrap_inline26289#)*. Error if x is not invertible.

The library syntax is #math422##tex2html_wrap_inline26292#(x).

<#6192#><#6192#> by 1=0 <#6193#>=0<#6196#><#6196#><#6193#>

<#6194#><#6197#>.. pf<#6197#><#6194#>(x, p): prime binary quadratic form of discriminant x whose first coefficient is the prime number p. Error if x is not a quadratic residue mod p. In the case where x ;SPMgt; 0, the ``distance'' component of the form is set equal to zero to the current precision.

The library syntax is #math423##tex2html_wrap_inline26300#(x, p, prec), where the third variable prec is a C-integer, but is necessary only when x ;SPMgt; 0.

<#6204#><#6204#> by 1=0 <#6205#>=0<#6208#><#6208#><#6205#>

<#6206#><#6209#>.. phi<#6209#><#6206#>(x): Euler's φ-function of x. x must be of type integer.

The library syntax is #math424##tex2html_wrap_inline26308#(x).

<#6216#><#6216#> by 1=0 <#6217#>=0<#6220#><#6220#><#6217#>

<#6218#><#6221#>.. pnqn<#6221#><#6218#>(x): When x is a vector or a one row matrix, x is considered as the list of partial quotients #math425#[a0, a1,..., an] of a rational number, and the result is the 2 by 2 matrix #math426#[pn, pn-1;qn, qn-1] in the standard notation of continued fractions, so #math427#pn/qn = a0 +1/(a1 + ... +1/an)...). If x is a matrix with two rows #math428#[b0, b1,..., bn] and #math429#[a0, a1,..., an], this is then considered as a generalized continued fraction and we have similarly #math430#pn/qn = 1/b0(a0 + b1/(a1 + ... + bn/an)...). Note that in this case one usually has b0 = 1.

The library syntax is #math431##tex2html_wrap_inline26321#(x).

<#6228#><#6228#> by 1=0 <#6229#>=0<#6232#><#6232#><#6229#>

<#6230#><#6233#>.. powrealraw<#6233#><#6230#>(x, n) n-th power of the binary quadratic form x of positive discriminant, computed without doing any reduction (i.e. using <#870#>comprealraw<#870#> above). Here n must be non-negative and n ;SPMlt; 231.

The library syntax is #math432##tex2html_wrap_inline26328#(x, n) where n must be a C-integer.

<#6240#><#6240#> by 1=0 <#6241#>=0<#6244#><#6244#><#6241#>

<#6242#><#6245#>.. prime<#6245#><#6242#>(x): the #math433#xth prime number.

The library syntax is #math434##tex2html_wrap_inline26333#(x). x must be a 32-bit C-integer.

<#6253#><#6253#> by 1=0 <#6254#>=0<#6257#><#6257#><#6254#>

<#6255#><#6258#>.. primes<#6258#><#6255#>(x): creates a row vector whose components are the first x prime numbers.

The library syntax is #math435##tex2html_wrap_inline26338#(x). x must be a 32-bit C-integer.

<#6265#><#6265#> by 1=0 <#6266#>=0<#6269#><#6269#><#6266#>

<#6267#><#6270#>.. primroot<#6270#><#6267#>(x): returns a primitive root of x, where x is a prime power.

The library syntax is #math436##tex2html_wrap_inline26344#(x).

<#6277#><#6277#> by 1=0 <#6278#>=0<#6281#><#6281#><#6278#>

<#6279#><#6282#>.. qfi<#6282#><#6279#>(a, b, c): creates the binary quadratic form #math437#ax2 + bxy + cy2 with b2 -4ac ;SPMlt; 0.

The library syntax is #math438##tex2html_wrap_inline26349#(a, b, c). <#6289#><#6289#>

<#6291#><#6291#> by 1=0 <#6292#>=0<#6295#><#6295#><#6292#>

<#6293#><#6296#>.. qfr<#6296#><#6293#>(a, b, c, d ): creates the binary quadratic form #math439#ax2 + bxy + cy2 with b2 -4ac ;SPMgt; 0 and distance function d.

The library syntax is #math440##tex2html_wrap_inline26355#(a, b, c, d ).

<#6303#><#6303#> by 1=0 <#6304#>=0<#6307#><#6307#><#6304#>

<#6305#><#6308#>.. redcomp<#6308#><#6305#>(x): reduce the binary quadratic form x with negative discriminant.

The library syntax is #math441##tex2html_wrap_inline26359#(x).

<#6315#><#6315#> by 1=0 <#6316#>=0<#6319#><#6319#><#6316#>

<#6317#><#6320#>.. redreal<#6320#><#6317#>(x): reduce the binary quadratic form x with positive discriminant.

The library syntax is #math442##tex2html_wrap_inline26363#(x).

<#6327#><#6327#> by 1=0 <#6328#>=0<#6331#><#6331#><#6328#>

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

The library syntax is #math443##tex2html_wrap_inline26370#(x, sq).

<#6339#><#6339#> by 1=0 <#6340#>=0<#6343#><#6343#><#6340#>

<#6341#><#6344#>.. regula<#6344#><#6341#>(x): regulator of the quadratic field of positive discriminant x. Error if x is not a discriminant (fundamental or not) or if x is a square. See also <#892#>buchreal<#892#> if x is large.

The library syntax is #math444##tex2html_wrap_inline26377#(x, prec).

<#6351#><#6351#> by 1=0 <#6352#>=0<#6355#><#6355#><#6352#>

<#6353#><#6356#>.. rhoreal<#6356#><#6353#>(x): perform one reduction step on the binary quadratic form x with positive discriminant.

The library syntax is #math445##tex2html_wrap_inline26381#(x).

<#6363#><#6363#> by 1=0 <#6364#>=0<#6367#><#6367#><#6364#>

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

The library syntax is #math446##tex2html_wrap_inline26388#(x, sq).

<#6375#><#6375#> by 1=0 <#6376#>=0<#6379#><#6379#><#6376#>

<#6377#><#6380#>.. sigma<#6380#><#6377#>(x): sum of the positive divisors of x. x must be of type integer.

The library syntax is #math447##tex2html_wrap_inline26393#(x).

<#6387#><#6387#> by 1=0 <#6388#>=0<#6391#><#6391#><#6388#>

<#6389#><#6392#>.. sigmak<#6392#><#6389#>(k, x): sum of the #math448#kth powers of the positive divisors of x. x must be of type integer, but (in library mode) k must be a 32-bit C-integer.

The library syntax is #math449##tex2html_wrap_inline26400#(k, x).

<#6400#><#6400#> by 1=0 <#6401#>=0<#6404#><#6404#><#6401#>

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

The library syntax is #math450##tex2html_wrap_inline26405#(x).

<#6412#><#6412#> by 1=0 <#6413#>=0<#6416#><#6416#><#6413#>

<#6414#><#6417#>.. unit<#6417#><#6414#>(x): <#6421#><#6421#>fundamental unit of the real quadratic field #math451##tex2html_wrap_inline26408#(#tex2html_wrap_inline26409#) where x is the positive discriminant of the field. If x is not a fundamental discriminant, this probably gives the fundamental unit of the corresponding order. x must be of type integer, and the result is a quadratic number.

The library syntax is #math452##tex2html_wrap_inline26414#(x).

by1=0 <#6427#>=0<#6429#><#6429#><#6427#>



<#6428#><#6430#>. Functions related to elliptic curves.<#6430#><#6428#>


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

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

#math453#

y2 + a1xy + a3y = x3 + a2x2 + a4x + a6,

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

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

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

<#6433#><#6433#> by 1=0 <#6434#>=0<#6437#><#6437#><#6434#>

<#6435#><#6438#>.. addell<#6438#><#6435#>(e, z1, z2): sum of the points z1 and z2 on the elliptic curve corresponding to the vector e.

The library syntax is #math454##tex2html_wrap_inline26422#(e, z1, z2).

<#6445#><#6445#> by 1=0 <#6446#>=0<#6449#><#6449#><#6446#>

<#6447#><#6450#>.. akell<#6450#><#6447#>(e, n): compute the coefficient an of the L-function of the elliptic curve e, i.e. in principle coefficients of a newform of weight 2 assuming Taniyama-Weil. e must be a medium or long vector of the type given by <#923#>smallinitell<#923#> or <#924#>initell<#924#>. For this function to work for every n and not just those prime to the conductor, e must be a minimal Weierstrass equation. If this is not the case, use the function <#925#>globalred<#925#> first before using <#926#>akell<#926#>.

The library syntax is #math455##tex2html_wrap_inline26431#(e, n).

<#6457#><#6457#> by 1=0 <#6458#>=0<#6461#><#6461#><#6458#>

<#6459#><#6462#>.. anell<#6462#><#6459#>(e, n): compute the vector of the first n ak corresponding to the elliptic curve e, i.e. in principle coefficients of a newform of weight 2 assuming Taniyama-Weil. e must be a medium or long vector of the type given by <#929#>smallinitell<#929#> or <#930#>initell<#930#>. For this function to work for every n and not just those prime to the conductor, e must be a minimal Weierstrass equation. If this is not the case, use the function <#931#>globalred<#931#> first before using <#932#>anell<#932#>.

The library syntax is #math456##tex2html_wrap_inline26440#(e, n), where n is a C integer.

<#6469#><#6469#> by 1=0 <#6470#>=0<#6473#><#6473#><#6470#>

<#6471#><#6474#>.. apell<#6474#><#6471#>(e, p): compute the ap corresponding to the elliptic curve e and the prime number p, using the baby-step giant-step method and a trick due to Mestre. No checking is done that p is indeed prime. The number of points of e over #tex2html_wrap_inline26451# is p + 1 - ap. e must be a medium or long vector of the type given by <#935#>smallinitell<#935#> or <#936#>initell<#936#>.

The library syntax is #math457##tex2html_wrap_inline26455#(e, p).

<#6482#><#6482#> by 1=0 <#6483#>=0<#6486#><#6486#><#6483#>

<#6484#><#6487#>.. apell2<#6487#><#6484#>(e, p): compute the ap corresponding to the elliptic curve e and the prime number p as a sum of Legendre symbols. This is slower than <#939#>apell<#939#> as soon as p is greater than 100, say. e must be a medium or long vector of the type given by <#940#>smallinitell<#940#> or <#941#>initell<#941#>.

The library syntax is #math458##tex2html_wrap_inline26463#(e, p).

<#6494#><#6494#> by 1=0 <#6495#>=0<#6498#><#6498#><#6495#>

<#6496#><#6499#>.. chell<#6499#><#6496#>(e, v): change the data for the elliptic curve e by changing the coordinates using the vector <#944#>v=[u,r,s,t]<#944#>, i.e. if x' and y' are the new coordinates, then x = u2x' + r, #math459#y = u3y' + su2x' + t. The vector e must be a medium or long vector of the type given by <#945#>smallinitell<#945#> or <#946#>initell<#946#>.

The library syntax is #math460##tex2html_wrap_inline26472#(e, v).

<#6506#><#6506#> by 1=0 <#6507#>=0<#6510#><#6510#><#6507#>

<#6508#><#6511#>.. chptell<#6511#><#6508#>(x, v): change the coordinates of the point or vector of points x using the vector <#949#>v=[u,r,s,t]<#949#>, i.e. if x' and y' are the new coordinates, then x = u2x' + r, #math461#y = u3y' + su2x' + t (see also <#950#>chell<#950#> above).

The library syntax is #math462##tex2html_wrap_inline26480#(x, v).

<#6518#><#6518#> by 1=0 <#6519#>=0<#6522#><#6522#><#6519#>

<#6520#><#6523#>.. globalred<#6523#><#6520#>(e): calculate the arithmetic conductor and the global minimal model of e. Here e is an elliptic curve given by a medium or long vector of the type given by <#953#>smallinitell<#953#> or <#954#>initell<#954#>, and is supposed to have all its coefficients ai in #tex2html_wrap_inline26486#. The result is a 2 component vector [N, v]. N is the arithmetic conductor of the curve, v is itself a vector #math463#[u, r, s, t] with rational components. It gives a coordinate change for e over #tex2html_wrap_inline26493# such that the resulting model has integral coefficients, is everywhere minimal, a1 is 0 or 1, a2 is 0, 1 or -1 and a3 is 0 or 1. Such a model is unique, and the vector v is unique if we specify that u is positive.

The library syntax is #math464##tex2html_wrap_inline26501#(e).

<#6532#><#6532#> by 1=0 <#6533#>=0<#6536#><#6536#><#6533#>

<#6534#><#6537#>.. hell<#6537#><#6534#>(e, z): global <#6541#><#6541#>Néron-Tate height of the point z on the elliptic curve e. The vector e must be a long vector of the type given by <#958#>initell<#958#>. This computation is done using sigma and theta-functions and a trick due to J. Silverman.

The library syntax is #math465##tex2html_wrap_inline26507#(e, z, prec). The archimedean contribution alone is given by the library function #math466##tex2html_wrap_inline26509#(e, z, prec).

<#6549#><#6549#> by 1=0 <#6550#>=0<#6553#><#6553#><#6550#>

<#6551#><#6554#>.. hell2<#6554#><#6551#>(e, z): same as <#962#>hell<#962#>, except that the algorithm used is Tate's 4n algorithm, and is much slower.

The library syntax is #math467##tex2html_wrap_inline26513#(e, z, prec).

<#6561#><#6561#> by 1=0 <#6562#>=0<#6565#><#6565#><#6562#>

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

The first 13 components contain

#math468#

a1, a2, a3, a4, a6, b2, b4, b6, b8, c4, c6, Δ, j.

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

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

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

E[15] is the real period of E (integral of #math469#dx/(2y + a1x + a3) over the connected component of the identity element of the real points of the curve), and E[16] is a complex period. In other words, #math470#ω1 = E[15] and #math471#ω2 = E[16] form a basis of the complex lattice defining e, with #math472#τ = #tex2html_wrap_inline26535# having positive imaginary part.

E[17] and E[18] are the corresponding values η1 and η2 such that #math473#η1ω2 - η2ω1 = .

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

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

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

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

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

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

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

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

The library syntax is #math474##tex2html_wrap_inline26568#(e, prec).

<#6580#><#6580#> by 1=0 <#6581#>=0<#6584#><#6584#><#6581#>

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

The library syntax is #math475##tex2html_wrap_inline26574#(e, z), and the result is a C-integer.

<#6592#><#6592#> by 1=0 <#6593#>=0<#6596#><#6596#><#6593#>

<#6594#><#6597#>.. localred<#6597#><#6594#>(e, p): calculate the Kodaira type of the local fiber of the elliptic curve e at the prime p. e must be given by a medium or long vector of the type given by <#973#>smallinitell<#973#> or <#974#>initell<#974#>, and is assumed to have all its coefficients ai in #tex2html_wrap_inline26581#. The result is a 3 component vector #math476#[f, kod, v]. Here f is the exponent of p in the arithmetic conductor of e, kod is the Kodaira type which is coded as follows: 1 means good reduction (type I0), 2, 3 and 4 mean types II, III and IV respectively, 4 + ν with ν ;SPMgt; 0 means type Iν; finally the opposite values -1, -2, etc. refer to the starred types I0*, II*, etc. The third component v is itself a vector #math477#[u, r, s, t] giving the coordinate changes done during the local reduction. Normally, this has no use if u is 1, that is, if the given equation was already minimal.

The library syntax is #math478##tex2html_wrap_inline26596#(e, p).

<#6605#><#6605#> by 1=0 <#6606#>=0<#6609#><#6609#><#6606#>

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

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

The library syntax is #math479##tex2html_wrap_inline26609#(e, s, N, A, prec) where prec is a C-integer.

<#6618#><#6618#> by 1=0 <#6619#>=0<#6622#><#6622#><#6619#>

<#6620#><#6623#>.. matell<#6623#><#6620#>(e, x): here x is a vector of points, and this function outputs the Gram matrix of x with respect to the Néron-Tate height, in other words, the <#982#>(i,j)<#982#> component of the matrix is equal to <#983#>hell(e,x[i]+x[j])-hell(e,x[i])-hell(e,x[j])<#983#>, where <#984#>x[i]+x[j]<#984#> denotes of course the sum of the points on the curve e. The rank of this matrix, at least in some approximate sense, gives the rank of the set of points, and if x is a basis of the Mordell-Weil group of e, its determinant is equal to the regulator of e.

The library syntax is #math480##tex2html_wrap_inline26619#(e, x, prec).

<#6630#><#6630#> by 1=0 <#6631#>=0<#6634#><#6634#><#6631#>

<#6632#><#6635#>.. ordell<#6635#><#6632#>(e, x): gives a 0, 1 or 2-component vector containing the y-coordinates of the points of the curve e having x as x-coordinate.

The library syntax is #math481##tex2html_wrap_inline26626#(e, x).

<#6642#><#6642#> by 1=0 <#6643#>=0<#6646#><#6646#><#6643#>

<#6644#><#6647#>.. pointell<#6647#><#6644#>(e, z): e being a long vector, computes the coordinates [x, y] on the curve e corresponding to the complex number z. Hence this is the inverse function of <#989#>zell<#989#>. In other words, if the curve is put in Weierstraß form, [x, y] represent the Weierstraß ℘-function and its derivative. If z is in the lattice defining e over #tex2html_wrap_inline26637#, the result is the point at infinity [0].

The library syntax is #math482##tex2html_wrap_inline26640#(e, z, prec).

<#6655#><#6655#> by 1=0 <#6656#>=0<#6659#><#6659#><#6656#>

<#6657#><#6660#>.. powell<#6660#><#6657#>(e, n, z): computes n times the point z for the group law on the elliptic curve e. Here n is in #tex2html_wrap_inline26647#.

The library syntax is #math483##tex2html_wrap_inline26649#(e, n, z).

<#6668#><#6668#> by 1=0 <#6669#>=0<#6672#><#6672#><#6669#>

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

#math484#

[a1, a2, a3, a4, a6, b2, b4, b6, b8, c4, c6, Δ, j].

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

The library syntax is #math485##tex2html_wrap_inline26657#(e).

<#6680#><#6680#> by 1=0 <#6681#>=0<#6684#><#6684#><#6681#>

<#6682#><#6685#>.. subell<#6685#><#6682#>(e, z1, z2): difference of the points z1 and z2 on the elliptic curve corresponding to the vector e.

The library syntax is #math486##tex2html_wrap_inline26663#(e, z1, z2).

<#6692#><#6692#> by 1=0 <#6693#>=0<#6696#><#6696#><#6693#>

<#6694#><#6697#>.. zell<#6697#><#6694#>(e, z): If e is an elliptic curve with coefficients in #tex2html_wrap_inline26667#, this computes a complex number t (modulo the lattice defining e) corresponding to the point z, i.e. such that, in the standard Weierstrass model, #math487#℘(t) = z[1],℘'(t) = z[2]. In other words, this is the inverse function of <#999#>pointell<#999#>.

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

The library syntax is #math488##tex2html_wrap_inline26688#(e, z, prec).

by1=0 <#6707#>=0<#6709#><#6709#><#6707#>



<#6708#><#6710#>. Polynomials, power series and number fields.<#6710#><#6708#>


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

<#6713#><#6713#> by 1=0 <#6714#>=0<#6717#><#6717#><#6714#>

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

The library syntax is #math489##tex2html_wrap_inline26715#(x, a), but if a is known to be simply a p-adic number (type 7), the syntax #math490##tex2html_wrap_inline26719#(x, a) can be used.

<#6731#><#6731#> by 1=0 <#6732#>=0<#6735#><#6735#><#6732#>

<#6733#><#6736#>.. base<#6736#><#6733#>(x): <#6740#><#6740#>integral basis of the number field defined by the monic irreducible polynomial x, using the round 2 algorithm.

The library syntax is #math491##tex2html_wrap_inline26723#(x,d ), where d will receive the discriminant of the number field (<#1009#>not<#1009#> of the polynomial x). This program is the translation in C of a program written by David Ford.

<#6745#><#6745#> by 1=0 <#6746#>=0<#6749#><#6749#><#6746#>

<#6747#><#6750#>.. convol<#6750#><#6747#>(x, y): convolution (or <#6754#><#6754#>Hadamard product) of the two power series x and y; in other words if #math492#x = #tex2html_wrap_inline26730#ak*Xk and #math493#y = #tex2html_wrap_inline26732#bk*Xk then #math494#convol(x, y) = #tex2html_wrap_inline26734#ak*bk*Xk.

The library syntax is #math495##tex2html_wrap_inline26736#(x, y).

<#6760#><#6760#> by 1=0 <#6761#>=0<#6764#><#6764#><#6761#>

<#6762#><#6765#>.. cyclo<#6765#><#6762#>(n): n-th cyclotomic polynomial, where n must be positive.

The library syntax is #math496##tex2html_wrap_inline26739#(n), where n is a C-integer.

<#6772#><#6772#> by 1=0 <#6773#>=0<#6776#><#6776#><#6773#>

<#6774#><#6777#>.. deriv<#6777#><#6774#>(x, y): derivative of x with respect to the simple variable y. x can be any type except polymod. The derivative of a scalar type is zero, and the derivative of a vector or matrix is done componentwise.

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

<#6784#><#6784#> by 1=0 <#6785#>=0<#6788#><#6788#><#6785#>

<#6786#><#6789#>.. disc<#6789#><#6786#>(x): discriminant of x. x must be a polynomial. The algorithm used is the <#6793#><#6793#>subresultant algorithm.

The library syntax is #math498##tex2html_wrap_inline26753#(x).

<#6798#><#6798#> by 1=0 <#6799#>=0<#6802#><#6802#><#6799#>

<#6800#><#6803#>.. discf<#6803#><#6800#>(x): <#6807#><#6807#>field discriminant of the number field defined by the monic irreducible polynomial x.

The library syntax is #math499##tex2html_wrap_inline26757#(x). See also <#1024#>base<#1024#>, 3.6.2 above.

<#6812#><#6812#> by 1=0 <#6813#>=0<#6816#><#6816#><#6813#>

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

The library syntax is #math500##tex2html_wrap_inline26762#(x).

<#6824#><#6824#> by 1=0 <#6825#>=0<#6828#><#6828#><#6825#>

<#6826#><#6829#>.. factoredbase<#6829#><#6826#>(x, p): <#6833#><#6833#>integral basis of the number field defined by the monic irreducible polynomial x, using the round 2 algorithm, where p is the two column matrix of the factorization of the discriminant of the polynomial x.

The library syntax is #math501##tex2html_wrap_inline26768#(x, p,d ), where d will receive the discriminant of the number field.

<#6838#><#6838#> by 1=0 <#6839#>=0<#6842#><#6842#><#6839#>

<#6840#><#6843#>.. factoreddiscf<#6843#><#6840#>(x, p): <#6847#><#6847#>field discriminant of the number field defined by the monic irreducible polynomial x, using the round 2 algorithm, where p is the two column matrix of the factorization of the discriminant of the polynomial x.

The library syntax is #math502##tex2html_wrap_inline26775#(x, p).

<#6852#><#6852#> by 1=0 <#6853#>=0<#6856#><#6856#><#6853#>

<#6854#><#6857#>.. factoredpolred<#6857#><#6854#>(x, p): same as <#1035#>polred<#1035#> (see 3.6.28 below) except that p is the two column matrix of the factorization of the discriminant of the polynomial x.

The library syntax is #math503##tex2html_wrap_inline26780#(x, p, prec).

<#6864#><#6864#> by 1=0 <#6865#>=0<#6868#><#6868#><#6865#>

<#6866#><#6869#>.. factoredpolred2<#6869#><#6866#>(x, p): same as <#1038#>polred2<#1038#> (see 3.6.29 below) except that p is the two column matrix of the factorization of the discriminant of the polynomial x.

The library syntax is #math504##tex2html_wrap_inline26785#(x, p, prec).

<#6876#><#6876#> by 1=0 <#6877#>=0<#6880#><#6880#><#6877#>

<#6878#><#6881#>.. factornf<#6881#><#6878#>(x, t): factorization of the univariate polynomial x over the number field defined by the (univariate) polynomial t. x may have coefficients in #tex2html_wrap_inline26791# or in the number field. The main variable of t must be variable number 0 (printed ``X'').

The library syntax is #math505##tex2html_wrap_inline26794#(x, t).

<#6889#><#6889#> by 1=0 <#6890#>=0<#6893#><#6893#><#6890#>

<#6891#><#6894#>.. factorpadic<#6894#><#6891#>(x, p, r): p-adic factorization of the polynomial x to precision r, the result being a two column matrix as in <#1043#>factor<#1043#>. In the present version 1.37, only separable factors are given, hence the sum of the degrees of the factors may not add up to the degree of x. In any case, r must be strictly larger than some value which is at most equal to the p-adic valuation of the discriminant of x for the result to make any sense.

The library syntax is #math506##tex2html_wrap_inline26804#(x, p, r), where r is a C-integer.

<#6901#><#6901#> by 1=0 <#6902#>=0<#6905#><#6905#><#6902#>

<#6903#><#6906#>.. factpol<#6906#><#6903#>(x, l ): x must be a polynomial with coefficients in #tex2html_wrap_inline26809#. If l = 0, find the complete factorization of x, and if l ;SPMgt; 0, search only for irreducible factors of degree less than or equal to l. The result is a two column matrix, the first one containing the irreducible factors, the second one the exponents.

The library syntax is #math507##tex2html_wrap_inline26815#(x, l ). The algorithm used is the standard Hensel lifting of a mod p factorization. Another implementation using instead root finding over #tex2html_wrap_inline26818# (instead of implicitly using #tex2html_wrap_inline26822#) is #math508##tex2html_wrap_inline26824#(x, l ).

<#6919#><#6919#> by 1=0 <#6920#>=0<#6923#><#6923#><#6920#>

<#6921#><#6924#>.. galois<#6924#><#6921#>(x): Galois group of the nonconstant polynomial #math509#x#tex2html_wrap_inline26827#[X]. In the present version 1.37, x must be irreducible and the degree of x must be less than or equal to 7.

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

In degree 1: #math510#S1 = [1, - 1, 1].

In degree 2: #math511#S2 = [2, - 1, 1].

In degree 3: #math512#A3 = C3 = [3, 1, 1], #math513#S3 = [6, - 1, 1].

In degree 4: #math514#C4 = [4, - 1, 1], #math515#V4 = [4, 1, 1], #math516#D4 = [8, - 1, 1], #math517#A4 = [12, 1, 1], #math518#S4 = [24, - 1, 1].

In degree 5: #math519#C5 = [5, 1, 1], #math520#D5 = [10, 1, 1], #math521#M20 = [20, - 1, 1], #math522#A5 = [60, 1, 1], #math523#S5 = [120, - 1, 1].

In degree 6: #math524#C6 = [6, - 1, 1], #math525#S3 = [6, - 1, 2], #math526#D6 = [12, - 1, 1], #math527#A4 = [12, 1, 1], #math528#G18 = [18, - 1, 1], #math529#S4- = [24, - 1, 1], #math530#A4×C2 = [24, - 1, 2], #math531#S4+ = [24, 1, 1], #math532#G36- = [36, - 1, 1], #math533#G36+ = [36, 1, 1], #math534#S4×C2 = [48, - 1, 1], #math535#A5 = PSL2(5) = [60, 1, 1], #math536#G72 = [72, - 1, 1], #math537#S5 = PGL2(5) = [120, - 1, 1], #math538#A6 = [360, 1, 1], #math539#S6 = [720, - 1, 1].

In degree 7: #math540#C7 = [7, 1, 1], #math541#D7 = [14, - 1, 1], #math542#M21 = [21, 1, 1], #math543#M42 = [42, - 1, 1], #math544#PSL2(7) = PSL3(2) = [168, 1, 1], #math545#A7 = [2520, 1, 1], #math546#S7 = [5040, - 1, 1].

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

The library syntax is #math547##tex2html_wrap_inline26879#(x, prec).

<#6933#><#6933#> by 1=0 <#6934#>=0<#6937#><#6937#><#6934#>

<#6935#><#6938#>.. galoisconj<#6938#><#6935#>(x): conjugates of a root r of the nonconstant polynomial x expressed as polynomials in r. This can be used even if the corresponding number field is not Galois since some conjugates may lie in the field.

The library syntax is #math548##tex2html_wrap_inline26885#(x, prec). A slower version but which has a better chance of finding the conjugates when the index is large is #math549##tex2html_wrap_inline26887#(x, prec) (not accessible from GP).

<#6948#><#6948#> by 1=0 <#6949#>=0<#6952#><#6952#><#6949#>

<#6950#><#6953#>.. initalg<#6953#><#6950#>(x): x being a nonconstant irreducible polynomial in #math550##tex2html_wrap_inline26891#[X], computes a 7 component vector v useful in working in the number field K defined by x. v[1] contains a polynomial defining K which is as simple as can easily be found using the <#1061#>polred<#1061#> algorithm. v[2] contains [r1, r2], the number of real and complex places of K. v[3] contains the discriminant of the number field K. v[4] contains the index of v[1], i.e. #math551#[#tex2html_wrap_inline26907# : #tex2html_wrap_inline26908#[θ]], where θ is any root of v[1]. v[5] contains the L2 norm of the roots of v[1], i.e. the sum of the squares of their moduli. v[6] is the vector containing the roots of v[1]. Finally, v[7] is an integral basis for #tex2html_wrap_inline26920# expressed on the powers of θ, a root of v[1].

The library syntax is #math552##tex2html_wrap_inline26924#(x, prec).

<#6964#><#6964#> by 1=0 <#6965#>=0<#6968#><#6968#><#6965#>

<#6966#><#6969#>.. integ<#6969#><#6966#>(x, y): <#6973#><#6973#>formal integration of x with respect to the simple variable y. No logarithmic terms must occur in the result. x can be of any type, but the case where x is a rational function is not implemented in the present version 1.37.

The library syntax is #math553##tex2html_wrap_inline26931#(x).

<#6978#><#6978#> by 1=0 <#6979#>=0<#6982#><#6982#><#6979#>

<#6980#><#6983#>.. isincl<#6983#><#6980#>(x, y): tests whether the number field K defined by the polynomial x is conjugate to a subfield of the field L defined by y (where x and y must be in #math554##tex2html_wrap_inline26940#[X]). If they are not, the output is the number 0. If they are, the output is a vector of polynomials, each polynomial a representing an isomorphism of K into L, i.e. being such that #math555#y = xoa.

The library syntax is #math556##tex2html_wrap_inline26946#(x, y).

<#6991#><#6991#> by 1=0 <#6992#>=0<#6995#><#6995#><#6992#>

<#6993#><#6996#>.. isisom<#6996#><#6993#>(x, y): tests whether the two number fields defined by the polynomials x and y (which must be in #math557##tex2html_wrap_inline26951#[X]) are isomorphic. If they are not, the output is the number 0. If they are, the output is a vector of polynomials, each polynomial a representing an isomorphism, i.e. being such that #math558#y = xoa.

The library syntax is #math559##tex2html_wrap_inline26955#(x, y).

<#7004#><#7004#> by 1=0 <#7005#>=0<#7008#><#7008#><#7005#>

<#7006#><#7009#>.. laplace<#7009#><#7006#>(x): x must be a power series with only nonnegative exponents. If #math560#x = #tex2html_wrap_inline26959#(ak/k!)*Xk then the result is #math561##tex2html_wrap_inline26961#ak*Xk.

The library syntax is #math562##tex2html_wrap_inline26963#(x).

<#7016#><#7016#> by 1=0 <#7017#>=0<#7020#><#7020#><#7017#>

<#7018#><#7021#>.. legendre<#7021#><#7018#>(x): creates the #math563#xth <#7026#><#7026#>Legendre polynomial.

The library syntax is #math564##tex2html_wrap_inline26967#(x), where x is a 32-bit C-integer.

<#7031#><#7031#> by 1=0 <#7032#>=0<#7035#><#7035#><#7032#>

<#7033#><#7036#>.. modreverse<#7036#><#7033#>(a): a being a polymod A(X) modulo T(X), finds the ``reverse polymod'' B(X) modulo Q(X), where Q is the minimal polynomial of a, which must be equal to the degree of T, and such that if θ is a root of T then #math565#θ = B(α) for a certain root α of Q.

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

The library syntax is #math566##tex2html_wrap_inline26984#(x).

<#7043#><#7043#> by 1=0 <#7044#>=0<#7047#><#7047#><#7044#>

<#7045#><#7048#>.. newtonpoly<#7048#><#7045#>(x, p): gives the vector of the slopes of the Newton polygon of the polynomial x with respect to the prime number p. The n components of the vector are in decreasing order, and n is equal to the degree of x.

The library syntax is #math567##tex2html_wrap_inline26992#(x, p).

<#7055#><#7055#> by 1=0 <#7056#>=0<#7059#><#7059#><#7056#>

<#7057#><#7060#>.. ordred<#7060#><#7057#>(x): finds polynomials with reasonably small coefficients and of the same degree as that of x defining suborders of the order defined by x. One of the polynomials always defines #tex2html_wrap_inline26997# (hence is equal to (x - 1)n, where n is the degree), and another always defines the same order as x if x is irreducible.

The library syntax is #math568##tex2html_wrap_inline27003#(x).

<#7068#><#7068#> by 1=0 <#7069#>=0<#7072#><#7072#><#7069#>

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

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

<#7082#><#7082#> by 1=0 <#7083#>=0<#7086#><#7086#><#7083#>

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

The library syntax is #math570##tex2html_wrap_inline27025#(x, prec).

<#7095#><#7095#> by 1=0 <#7096#>=0<#7099#><#7099#><#7096#>

<#7097#><#7100#>.. polred2<#7100#><#7097#>(x): finds polynomials with reasonably small coefficients defining subfields of the number field defined by x. The result is a two column matrix, the first column giving the elements, the second giving the polynomials.

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

The library syntax is #math571##tex2html_wrap_inline27035#(x, prec).

<#7108#><#7108#> by 1=0 <#7109#>=0<#7112#><#7112#><#7109#>

<#7110#><#7113#>.. polsym<#7113#><#7110#>(x, n): creates the vector of the <#7117#><#7117#>symmetric powers of the roots of the polynomial x up to power n.

The library syntax is #math572##tex2html_wrap_inline27040#(x).

<#7122#><#7122#> by 1=0 <#7123#>=0<#7126#><#7126#><#7123#>

<#7124#><#7127#>.. recip<#7127#><#7124#>(x): reciprocal polynomial of x, i.e. the coefficients are in reverse order. x must be a polynomial.

The library syntax is #math573##tex2html_wrap_inline27045#(x).

<#7134#><#7134#> by 1=0 <#7135#>=0<#7138#><#7138#><#7135#>

<#7136#><#7139#>.. resultant<#7139#><#7136#>(x, y): resultant of the two polynomials x and y with exact entries. The algorithm used is the subresultant algorithm.

The library syntax is #math574##tex2html_wrap_inline27050#(x, y).

<#7146#><#7146#> by 1=0 <#7147#>=0<#7150#><#7150#><#7147#>

<#7148#><#7151#>.. resultant2<#7151#><#7148#>(x, y): resultant of the two polynomials x and y. The algorithm used is the determinant of Sylvester's matrix.

The library syntax is #math575##tex2html_wrap_inline27055#(x, y).

<#7158#><#7158#> by 1=0 <#7159#>=0<#7162#><#7162#><#7159#>

<#7160#><#7163#>.. reverse<#7163#><#7160#>(x): reverse power series (i.e. x-1, not 1/x ) of x. x must be a power series whose valuation is exactly equal to one.

The library syntax is #math576##tex2html_wrap_inline27062#(x).

<#7170#><#7170#> by 1=0 <#7171#>=0<#7174#><#7174#><#7171#>

<#7172#><#7175#>.. rootmod<#7175#><#7172#>(x, p): roots modulo p of the polynomial x. Slightly slower than <#1102#>rootmod2<#1102#> below for p ;SPMlt; 100, but much faster for larger values. The particular nonprime value p = 4 is accepted, mainly for 2-adic computations. Multiple roots are <#1103#>not<#1103#> repeated.

The library syntax is #math577##tex2html_wrap_inline27070#(x, p).

<#7182#><#7182#> by 1=0 <#7183#>=0<#7186#><#7186#><#7183#>

<#7184#><#7187#>.. rootmod2<#7187#><#7184#>(x, p): roots modulo p of the polynomial x. To be used only when p is small. Multiple roots are repeated with their order of multiplicity.

The library syntax is #math578##tex2html_wrap_inline27076#(x, p).

<#7194#><#7194#> by 1=0 <#7195#>=0<#7198#><#7198#><#7195#>

<#7196#><#7199#>.. rootpadic<#7199#><#7196#>(x, p, r): vector of p-adic roots of the polynomial x with p-adic precision equal to r. Multiple roots are <#1108#>not<#1108#> repeated.

The library syntax is #math579##tex2html_wrap_inline27083#(x, p, r), where r is a C-integer.

<#7206#><#7206#> by 1=0 <#7207#>=0<#7210#><#7210#><#7207#>

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

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

The library syntax is #math580##tex2html_wrap_inline27088#(x, prec).

<#7218#><#7218#> by 1=0 <#7219#>=0<#7222#><#7222#><#7219#>

<#7220#><#7223#>.. rootsof1<#7223#><#7220#>(x): computes the number of roots of unity belonging to the number field defined by the polynomial #math581#x#tex2html_wrap_inline27091#[X].

The library syntax is #math582##tex2html_wrap_inline27093#(x), and the result is a C-integer.

<#7231#><#7231#> by 1=0 <#7232#>=0<#7235#><#7235#><#7232#>

<#7233#><#7236#>.. smallbase<#7236#><#7233#>(x): <#7240#><#7240#>integral basis of the number field defined by the monic irreducible polynomial x, using the round 2 algorithm, where one does not take into account squares of primes which are not precomputed.

The library syntax is #math583##tex2html_wrap_inline27097#(x,y), where y will receive the discriminant of the number field (<#1118#>not<#1118#> of the polynomial x). This program is the translation in C of a program written by David Ford.

<#7245#><#7245#> by 1=0 <#7246#>=0<#7249#><#7249#><#7246#>

<#7247#><#7250#>.. smalldiscf<#7250#><#7247#>(x): <#7254#><#7254#>field discriminant of the number field defined by the monic irreducible polynomial x, where one does not take into account squares of primes which are not precomputed.

The library syntax is #math584##tex2html_wrap_inline27103#(x). See also <#1122#>smallbase<#1122#>, 3.6.27 above.

<#7259#><#7259#> by 1=0 <#7260#>=0<#7263#><#7263#><#7260#>

<#7261#><#7264#>.. smallpolred<#7264#><#7261#>(x): same as <#1124#>polred<#1124#> (see 3.6.18 above) except that only a suborder of the maximal order may be used.

The library syntax is #math585##tex2html_wrap_inline27106#(x, prec).

<#7271#><#7271#> by 1=0 <#7272#>=0<#7275#><#7275#><#7272#>

<#7273#><#7276#>.. smallpolred2<#7276#><#7273#>(x): same as <#1127#>polred2<#1127#> (see 3.6.19 above) except that only a suborder of the maximal order may be used.

The library syntax is #math586##tex2html_wrap_inline27109#(x, prec).

<#7283#><#7283#> by 1=0 <#7284#>=0<#7287#><#7287#><#7284#>

<#7285#><#7288#>.. sturm<#7288#><#7285#>(x): number of real roots of the real polynomial x, using Sturm's algorithm.

The library syntax is #math587##tex2html_wrap_inline27113#(x). The result is a 32-bit C-integer.

<#7295#><#7295#> by 1=0 <#7296#>=0<#7299#><#7299#><#7296#>

<#7297#><#7300#>.. sturmpart<#7300#><#7297#>(x, a, b): number of real roots of the real polynomial x in the interval (a, b], using Sturm's algorithm.

The library syntax is #math588##tex2html_wrap_inline27118#(x). The result is a 32-bit C-integer.

<#7307#><#7307#> by 1=0 <#7308#>=0<#7311#><#7311#><#7308#>

<#7309#><#7312#>.. subst<#7312#><#7309#>#math589#(x, y, z): replace the simple variable y by the argument z in expression x. Every non-scalar type is allowed for x. If x is a power series, z must be either a polynomial, a power series, or a rational function. y must be a simple variable name.

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

<#7319#><#7319#> by 1=0 <#7320#>=0<#7323#><#7323#><#7320#>

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

The library syntax is #math591##tex2html_wrap_inline27137#(x, y, n), where the 32-bit C-integer n is the desired number of terms in the expansion.

<#7331#><#7331#> by 1=0 <#7332#>=0<#7335#><#7335#><#7332#>

<#7333#><#7336#>.. tchebi<#7336#><#7333#>(x): creates the #math592#xth Tchebicheff polynomial.

The library syntax is #math593##tex2html_wrap_inline27142#(x), where x is a 32-bit C-integer.

<#7344#><#7344#> by 1=0 <#7345#>=0<#7348#><#7348#><#7345#>

<#7346#><#7349#>.. tchirnhausen<#7349#><#7346#>(x): apply a random Tchirnhausen transformation to the nonconstant separable polynomial x so as to obtain a new equation for the number field (or more generally the etale algebra) defined by x. This is for instance useful when computing resolvents, hence is used in the <#1141#>galois<#1141#> function above.

The library syntax is #math594##tex2html_wrap_inline27148#.

by1=0 <#7356#>=0<#7358#><#7358#><#7356#>



<#7357#><#7359#>. Vectors, matrices and linear algebra.<#7359#><#7357#>


<#7362#><#7362#> by 1=0 <#7363#>=0<#7366#><#7366#><#7363#>

<#7364#><#7367#>.. adj<#7367#><#7364#>(x): <#7371#><#7371#>adjoint matrix of x, i.e. the matrix y of cofactors of x such that #math595#x*y = det(x)*Id. x must be a (non necessarily invertible) square matrix.

The library syntax is #math596##tex2html_wrap_inline27156#(x).

<#7378#><#7378#> by 1=0 <#7379#>=0<#7382#><#7382#><#7379#>

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

The library syntax is #math597##tex2html_wrap_inline27162#(x, k, prec), where k is a 32-bit C-integer.

<#7392#><#7392#> by 1=0 <#7393#>=0<#7396#><#7396#><#7393#>

<#7394#><#7397#>.. algdep2<#7397#><#7394#>#math598#(x, k, bit): <#7401#><#7401#>algebraic dependence x being real or complex, finds a polynomial of degree at most k having x as approximate root. bit is a number which should be approximately equal to half the number of precision bits. The algorithm used is the LLL algorithm. Note that the polynomial which is obtained is not necessarily the ``correct'' one. One can check the closeness either by a polynomial evaluation or substitution, or by finding the roots of the polynomial given by algdep2.

The library syntax is #math599##tex2html_wrap_inline27170#(x, k, bit, prec), where k and bit are 32-bit C-integers.

<#7406#><#7406#> by 1=0 <#7407#>=0<#7410#><#7410#><#7407#>

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

The library syntax is #math600##tex2html_wrap_inline27183#(x, v), where v is the variable number, or even #math601##tex2html_wrap_inline27186#(x, v, 0). Note that the function <#1159#>caradj(x,v,pty)<#1159#> returns the characteristic polynomial of x in the variable v, and if <#1160#>pty<#1160#> is not equal to 0, puts in <#1161#>pty<#1161#> the address of the adjoint matrix of x, so both can be obtained at once.

<#7423#><#7423#> by 1=0 <#7424#>=0<#7427#><#7427#><#7424#>

<#7425#><#7428#>.. char1<#7428#><#7425#>(x, y): <#7432#><#7432#>characteristic polynomial of x with respect to the variable y, i.e. determinant of y*I - x if x is a square matrix, determinant of the map multiplication by x if x is a polymod, error if x is of any other type. For matrices, the method used is that of Lagrange interpolation and is almost always slower than <#1164#>char<#1164#>. Identical to <#1165#>char<#1165#> for polymods.

The library syntax is #math602##tex2html_wrap_inline27199#(x, v), where v is the variable number.

<#7437#><#7437#> by 1=0 <#7438#>=0<#7441#><#7441#><#7438#>

<#7439#><#7442#>.. char2<#7442#><#7439#>(x, y): characteristic polynomial of the square matrix x with respect to the variable y using the Hessenberg form. This is faster than <#1168#>char<#1168#> when the coefficients are integermod a prime or real numbers, but is usually slower in other base rings.

The library syntax is #math603##tex2html_wrap_inline27205#(x, v), where v is the variable number.

<#7449#><#7449#> by 1=0 <#7450#>=0<#7453#><#7453#><#7450#>

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

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

The library syntax is #math604##tex2html_wrap_inline27215#(x, y).

<#7461#><#7461#> by 1=0 <#7462#>=0<#7465#><#7465#><#7462#>

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

The library syntax is #math605##tex2html_wrap_inline27221#(x) and #math606##tex2html_wrap_inline27223#(x).

<#7478#><#7478#> by 1=0 <#7479#>=0<#7482#><#7482#><#7479#>

<#7480#><#7483#>.. eigen<#7483#><#7480#>(x): gives the eigenvectors of x as columns of a matrix.

The library syntax is #math607##tex2html_wrap_inline27227#(x).

<#7490#><#7490#> by 1=0 <#7491#>=0<#7494#><#7494#><#7491#>

<#7492#><#7495#>.. extract<#7495#><#7492#>(x, y): extraction of components of the vector or matrix x according to y. x must be a vector or a matrix. In the case of a matrix, the components are as usual the <#1179#>columns<#1179#> of x. y must be either a number of PARI type integer, in which case it is considered as a mask: The binary bits of y are read from right to left, but correspond to taking the components from left to right. For example, if #math608#y = 13 = (1101)2 then the components 1,3 and 4 are extracted.

Or y can be a vector, with integer entries, in which case these entries correspond to the component number to be extracted, in the order specified.

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

The library syntax is #math609##tex2html_wrap_inline27238#(x, y).

<#7502#><#7502#> by 1=0 <#7503#>=0<#7506#><#7506#><#7503#>

<#7504#><#7507#>.. gauss<#7507#><#7504#>(x, y): x being a square matrix and y a column vector, finds the solution u of x*u = y, using Gaussian elimination. This has the same effect, but is much faster, than x-1*y.

The library syntax is #math610##tex2html_wrap_inline27246#(x, y).

<#7514#><#7514#> by 1=0 <#7515#>=0<#7518#><#7518#><#7515#>

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

The library syntax is #math611##tex2html_wrap_inline27253#(x).

<#7526#><#7526#> by 1=0 <#7527#>=0<#7530#><#7530#><#7527#>

<#7528#><#7531#>.. hess<#7531#><#7528#>(x): Hessenberg form of the square matrix x.

The library syntax is #math612##tex2html_wrap_inline27257#(x).

by 1=0 <#7538#>=0<#7540#><#7540#><#7538#>

<#7539#><#7541#>.. hilbert<#7541#><#7539#>(x): x being a 32-bit C-integer, creates the <#7545#><#7545#>Hilbert matrix of order x, i.e. the matrix whose coefficient (i,j) is #math613#1#tex2html_wrap_inline27264#i+j-1.

The library syntax is #math614##tex2html_wrap_inline27266#(x).

<#7550#><#7550#> by 1=0 <#7551#>=0<#7554#><#7554#><#7551#>

<#7552#><#7555#>.. idmat<#7555#><#7552#>(n): creates the n×n identity matrix.

The library syntax is #math615##tex2html_wrap_inline27270#(n) where n is a C-integer. Related functions are #math616##tex2html_wrap_inline27273#(x, n) which creates x times the identity matrix (x being a GEN and n a C-integer) and #math617##tex2html_wrap_inline27278#(x, n) which is the same when x is a C-integer.

<#7568#><#7568#> by 1=0 <#7569#>=0<#7572#><#7572#><#7569#>

<#7570#><#7573#>.. image<#7573#><#7570#>(x): gives a basis for the image of the matrix x as columns of a matrix. A priori the matrix can have entries of any type.

The library syntax is #math618##tex2html_wrap_inline27283#(x).

<#7580#><#7580#> by 1=0 <#7581#>=0<#7584#><#7584#><#7581#>

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

The library syntax is #math619##tex2html_wrap_inline27289#(x).

<#7592#><#7592#> by 1=0 <#7593#>=0<#7596#><#7596#><#7593#>

<#7594#><#7597#>.. indsort<#7597#><#7594#>(x): indirect sorting of the vector x, i.e. if x is an n-dimensional vector, creates the permutation of #math620#[1, 2,..., n] which applied to the components of x sorts x in increasing order.

The library syntax is #math621##tex2html_wrap_inline27298#(x).

<#7604#><#7604#> by 1=0 <#7605#>=0<#7608#><#7608#><#7605#>

<#7606#><#7609#>.. intersect<#7609#><#7606#>(x, y): x and y being two matrices with the same number of rows whose columns are independent, finds a basis of the #tex2html_wrap_inline27303#-vector space equal to the intersection of the spaces spanned by the columns of x and y respectively.

The library syntax is #math622##tex2html_wrap_inline27307#(x, y).

<#7617#><#7617#> by 1=0 <#7618#>=0<#7621#><#7621#><#7618#>

<#7619#><#7622#>.. inverseimage<#7622#><#7619#>(x, y): gives one column vector belonging to the inverse image of the column vector y by the matrix x if one exists, the empty vector otherwise. To get the complete inverse image, it suffices to add to the result any element of the kernel of x obtained for example by <#1207#>ker<#1207#>.

The library syntax is #math623##tex2html_wrap_inline27313#(x, y).

<#7629#><#7629#> by 1=0 <#7630#>=0<#7633#><#7633#><#7630#>

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

The library syntax is #math624##tex2html_wrap_inline27319#(x).

<#7641#><#7641#> by 1=0 <#7642#>=0<#7645#><#7645#><#7642#>

<#7643#><#7646#>.. ker<#7646#><#7643#>(x): gives a basis for the kernel of the matrix x as columns of a matrix. A priori the matrix can have entries of any type. See also <#1212#>keri<#1212#> and <#1213#>kerr<#1213#>.

The library syntax is #math625##tex2html_wrap_inline27323#(x).

<#7653#><#7653#> by 1=0 <#7654#>=0<#7657#><#7657#><#7654#>

<#7655#><#7658#>.. keri<#7658#><#7655#>(x): same as <#1216#>ker<#1216#>, except that it assumes that the matrix has entries of type integer. In that case it is much faster.

The library syntax is #math626##tex2html_wrap_inline27326#(x).

<#7665#><#7665#> by 1=0 <#7666#>=0<#7669#><#7669#><#7666#>

<#7667#><#7670#>.. kerint<#7670#><#7667#>(x): gives an LLL-reduced #tex2html_wrap_inline27329#-basis for the lattice equal to the kernel of the matrix x as columns of the matrix x with integer entries (rational entries are not permitted) using a modified integer LLL algorithm.

The library syntax is #math627##tex2html_wrap_inline27333#(x).

<#7678#><#7678#> by 1=0 <#7679#>=0<#7682#><#7682#><#7679#>

<#7680#><#7683#>.. kerint1<#7683#><#7680#>(x): like <#1221#>kerint<#1221#>, but using <#1222#>matrixqz3<#1222#>, gives an LLL-reduced #tex2html_wrap_inline27336#-basis for the lattice equal to the kernel of the matrix x as columns of the matrix x with integer or rational entries. If LLL reduction of the final result is not desired, use <#1223#>matrixqz3(ker(x))<#1223#> instead.

The library syntax is #math628##tex2html_wrap_inline27340#(x).

<#7691#><#7691#> by 1=0 <#7692#>=0<#7695#><#7695#><#7692#>

<#7693#><#7696#>.. kerint2<#7696#><#7693#>(x): like <#1226#>kerint<#1226#>, but using another modified LLL algorithm, gives an LLL-reduced #tex2html_wrap_inline27343#-basis for the lattice equal to the kernel of the matrix x as columns of the matrix x with integer entries (rational entries are not permitted). In the present version 1.37, only independent rows are allowed.

The library syntax is #math629##tex2html_wrap_inline27347#(x).

<#7704#><#7704#> by 1=0 <#7705#>=0<#7708#><#7708#><#7705#>

<#7706#><#7709#>.. kerr<#7709#><#7706#>(x): gives a basis for the kernel of the matrix x as columns of a matrix, where x has elements which can be nonexact real or complex numbers. In that case, the precision of the matrix entries determines what is meant by an element of the kernel. In particular, if the matrix is ill conditioned, the results may not be what you expect.

The library syntax is #math630##tex2html_wrap_inline27352#(x).

<#7716#><#7716#> by 1=0 <#7717#>=0<#7720#><#7720#><#7717#>

<#7718#><#7721#>.. lexsort<#7721#><#7718#>(x) sort the elements of the vector x by ascending lexicographic order (see <#1231#>lex<#1231#> above).

The library syntax is #math631##tex2html_wrap_inline27356#(x).

<#7728#><#7728#> by 1=0 <#7729#>=0<#7732#><#7732#><#7729#>

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

The library syntax is #math632##tex2html_wrap_inline27360#(x, prec).

<#7742#><#7742#> by 1=0 <#7743#>=0<#7746#><#7746#><#7743#>

<#7744#><#7747#>.. lindep2<#7747#><#7744#>(x, bit): <#7751#><#7751#>x being a vector with real or complex coefficients, finds a small integral linear combination among these coefficients using the LLL algorithm. bit is a parameter which should be about one half the number of precision bits.

The library syntax is #math633##tex2html_wrap_inline27365#(x, bit, prec) where bit is a C-integer.

<#7756#><#7756#> by 1=0 <#7757#>=0<#7760#><#7760#><#7757#>

<#7758#><#7761#>.. lll<#7761#><#7758#>(x): LLL algorithm applied to the <#1240#>columns<#1240#> of the (non necessarily square) matrix x. The result is a square transformation matrix T such that xT is an LLL-reduced basis of the lattice generated by the column vectors of x. The computations are done with real numbers (i.e. not with rational numbers) hence are fast but as presently programmed (version 1.37) are numerically unstable. An older version of this program is <#1241#>lll1<#1241#>.

The library syntax is #math634##tex2html_wrap_inline27373#(x, prec).

<#7768#><#7768#> by 1=0 <#7769#>=0<#7772#><#7772#><#7769#>

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

The library syntax is #math635##tex2html_wrap_inline27378#(x, prec).

<#7780#><#7780#> by 1=0 <#7781#>=0<#7784#><#7784#><#7781#>

<#7782#><#7785#>.. lllgramint<#7785#><#7782#>(x): The matrix x being the gram matrix of a basis of some lattice, is assumed to have integral entries. The result is the unimodular transformation matrix T which gives (as columns) the coefficients with respect to the initial basis vectors. The computations are done entirely with integers and is both accurate and quite fast.

The library syntax is #math636##tex2html_wrap_inline27383#(x).

<#7792#><#7792#> by 1=0 <#7793#>=0<#7796#><#7796#><#7793#>

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

The library syntax is #math637##tex2html_wrap_inline27387#(x).

<#7804#><#7804#> by 1=0 <#7805#>=0<#7808#><#7808#><#7805#>

<#7806#><#7809#>.. lllint<#7809#><#7806#>(x): LLL algorithm applied to the <#1251#>columns<#1251#> of the (non necessarily square) matrix x. It is assumed that the corresponding gram matrix is integral. The result is a square transformation matrix T such that xT is an LLL-reduced basis of the lattice generated by the column vectors of x. The computations are done entirely with integers and is both accurate and quite fast.

The library syntax is #math638##tex2html_wrap_inline27394#(x).

<#7816#><#7816#> by 1=0 <#7817#>=0<#7820#><#7820#><#7817#>

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

The library syntax is #math639##tex2html_wrap_inline27402#(x).

<#7829#><#7829#> by 1=0 <#7830#>=0<#7833#><#7833#><#7830#>

<#7831#><#7834#>.. lllrat<#7834#><#7831#>(x): same as LLL except that the computations are all done in rational numbers. Hence no risk of numerical instability, but extremely slow. This function is essentially superseded by <#1256#>lllint<#1256#> so will soon disappear.

The library syntax is #math640##tex2html_wrap_inline27405#(x).

<#7841#><#7841#> by 1=0 <#7842#>=0<#7845#><#7845#><#7842#>

<#7843#><#7846#>.. mat<#7846#><#7843#>(x): transform the object x into a matrix. If x is not a vector or a matrix, this creates a 1×1 matrix. If x is a row (resp. column) vector, this creates a 1-row (resp. 1-column) matrix. If x is already a matrix, a copy of x is created.

This function can be useful in connection with the function <#1259#>concat<#1259#> (see 3.7.7.).

The library syntax is #math641##tex2html_wrap_inline27414#(x).

<#7853#><#7853#> by 1=0 <#7854#>=0<#7857#><#7857#><#7854#>

<#7855#><#7858#>.. matextract<#7858#><#7855#>#math642#(x, y, z): extraction of a matrix from the matrix x, the line mask or vector y and the column mask or vector z. x must be a matrix, and y and z either numbers of PARI type integer or vectors. The extraction is done using the same rules as for <#1262#>extract<#1262#> (3.7.10). The difference with <#1263#>extract<#1263#> is that both lines and columns are extracted.

The library syntax is #math643##tex2html_wrap_inline27423#(x, y, z).

<#7865#><#7865#> by 1=0 <#7866#>=0<#7869#><#7869#><#7866#>

<#7867#><#7870#>.. matinvr<#7870#><#7867#>(x): computes the inverse matrix of x assumed to have real entries. This may be more efficient than using <#1266#>ginv<#1266#> (or x-1 under GP).

The library syntax is #math644##tex2html_wrap_inline27428#(x). A related function is #math645##tex2html_wrap_inline27430#(x, y) which directly computes x-1*y for matrices x and y.

<#7880#><#7880#> by 1=0 <#7881#>=0<#7884#><#7884#><#7881#>

<#7882#><#7885#>.. matsize<#7885#><#7882#>(x): x being a vector or matrix, returns a row vector with two components, the first being the number of rows (1 for a row vector), the second the number of columns (1 for a column vector).

The library syntax is #math646##tex2html_wrap_inline27437#(x).

<#7892#><#7892#> by 1=0 <#7893#>=0<#7896#><#7896#><#7893#>

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

The library syntax is #math647##tex2html_wrap_inline27452#(x, p).

<#7904#><#7904#> by 1=0 <#7905#>=0<#7908#><#7908#><#7905#>

<#7906#><#7909#>.. matrixqz2<#7909#><#7906#>(x): x being an m×n matrix with rational or integer entries, this function returns a matrix whose columns form a basis of the lattice equal to #tex2html_wrap_inline27459# intersected with the lattice generated by the columns of x.

The library syntax is #math648##tex2html_wrap_inline27462#(x).

<#7917#><#7917#> by 1=0 <#7918#>=0<#7921#><#7921#><#7918#>

<#7919#><#7922#>.. matrixqz3<#7922#><#7919#>(x): x being an m×n matrix with rational or integer entries, this function returns a matrix whose columns form a basis of the lattice equal to #tex2html_wrap_inline27469# intersected with the #tex2html_wrap_inline27471#-vector space generated by the columns of x.

The library syntax is #math649##tex2html_wrap_inline27474#(x).

<#7931#><#7931#> by 1=0 <#7932#>=0<#7935#><#7935#><#7932#>

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

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

The library syntax is #math650##tex2html_wrap_inline27483#(x, b, m)

by 1=0 <#7943#>=0<#7945#><#7945#><#7943#>

<#7944#><#7946#>.. pascal<#7946#><#7944#>(x): creates as a matrix the lower triangular <#7950#><#7950#>pascal triangle of order x + 1 (i.e. with binomial coefficients up to x).

The library syntax is #math651##tex2html_wrap_inline27488#(x), where x is a 32-bit C-integer.

<#7955#><#7955#> by 1=0 <#7956#>=0<#7959#><#7959#><#7956#>

<#7957#><#7960#>.. rank<#7960#><#7957#>(x): rank of the matrix x.

The library syntax is #math652##tex2html_wrap_inline27493#(x), and the result is a 32-bit C-integer.

<#7967#><#7967#> by 1=0 <#7968#>=0<#7971#><#7971#><#7968#>

<#7969#><#7972#>.. signat<#7972#><#7969#>(x): signature of the quadratic form represented by the symmetric matrix x. The result is a two-component vector.

The library syntax is #math653##tex2html_wrap_inline27497#(x)

<#7979#><#7979#> by 1=0 <#7980#>=0<#7983#><#7983#><#7980#>

<#7981#><#7984#>.. smith<#7984#><#7981#>(x): if x is a nonsingular square matrix, outputs the vector of elementary divisors of x (i.e. the diagonal of the Smith normal form of x)

The library syntax is #math654##tex2html_wrap_inline27503#(x).

<#7991#><#7991#> by 1=0 <#7992#>=0<#7995#><#7995#><#7992#>

<#7993#><#7996#>.. sort<#7996#><#7993#>(x): sort the vector x in ascending order, using the heapsort method. x must be a vector, and its components integers, reals, or fractions. A related function is <#1291#>indsort<#1291#> (see 3.7.13 above) which gives the indexes of the sorted vector in terms of the initial one. For example, <#1292#>extract(x,indsort(x))<#1292#> is equivalent to <#1293#>sort(x)<#1293#>.

The library syntax is #math655##tex2html_wrap_inline27508#(x).

<#8003#><#8003#> by 1=0 <#8004#>=0<#8007#><#8007#><#8004#>

<#8005#><#8008#>.. sqred<#8008#><#8005#>(x): <#8012#><#8012#>decomposition into squares of the quadratic form represented by the symmetric matrix x. The result is a matrix whose diagonal entries are the coefficients of the squares, and the non diagonal entries represent the bilinear forms.

The library syntax is #math656##tex2html_wrap_inline27512#(x).

<#8017#><#8017#> by 1=0 <#8018#>=0<#8021#><#8021#><#8018#>

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

The library syntax is #math657##tex2html_wrap_inline27518#(x).

<#8029#><#8029#> by 1=0 <#8030#>=0<#8033#><#8033#><#8030#>

<#8031#><#8034#>.. trace<#8034#><#8031#>(x): This applies to quite general x. If x is not a matrix, it is equal to the sum of x and its conjugate, except for polymods where it is the trace as an algebraic number.

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

The library syntax is #math658##tex2html_wrap_inline27526#(x).

<#8041#><#8041#> by 1=0 <#8042#>=0<#8045#><#8045#><#8042#>

<#8043#><#8046#>.. trans<#8046#><#8043#>(x) or #math659#x#tex2html_wrap_inline27529#: transpose of x. This has an effect only on vectors and matrices.

The library syntax is #math660##tex2html_wrap_inline27532#(x).

<#8053#><#8053#> by 1=0 <#8054#>=0<#8057#><#8057#><#8054#>

<#8055#><#8058#>.. vecsort<#8058#><#8055#>(x, k): sort the vector of vectors or matrix x in ascending order of the k-th components, using the heapsort method. The components being compared must be of type integer, real or fraction.

The library syntax is #math661##tex2html_wrap_inline27536#(x, k).

by1=0 <#8065#>=0<#8067#><#8067#><#8065#>



<#8066#><#8068#>. Sums, products, integrals and similar functions.<#8068#><#8066#>


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

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

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

<#8071#><#8071#> by 1=0 <#8072#>=0<#8075#><#8075#><#8072#>

<#8073#><#8076#>.. divsum<#8076#><#8073#>#math662#(n, X, expr): sum of expression expr over the positive divisors of n.

In the present version 1.37, n is restricted to being less than 231.

<#8080#><#8080#> by 1=0 <#8081#>=0<#8084#><#8084#><#8081#>

<#8082#><#8085#>.. hvector<#8085#><#8082#>#math663#(n, X, expr): creates a row vector with n components whose components are the expression expr evaluated at the integral points between 1 and n.

by 1=0 <#8089#>=0<#8091#><#8091#><#8089#>

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

Note that <#8098#><#8098#>infinity can be represented with essentially no loss of accuracy by 1e4000. However beware of real underflow when dealing with rapidly decreasing functions. For example, if one wants to compute the #math664##tex2html_wrap_inline27548#e-x2 dx to 28 decimal digits, one should set infinity equal to 10 for example, and certainly not to 1e4000.

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

<#8100#><#8100#> by 1=0 <#8101#>=0<#8104#><#8104#><#8101#>

<#8102#><#8105#>.. intgen<#8105#><#8102#>#math665#(X = a, b, expr): general driver routine for doing numerical integration from a to b of the expression expr, with respect to the formal variable X.

<#8109#><#8109#> by 1=0 <#8110#>=0<#8113#><#8113#><#8110#>

<#8111#><#8114#>.. intinf<#8114#><#8111#>#math666#(X = a, b, expr): numerical integration from a to b, tailored for being used when a or b are infinite. One <#1317#>must<#1317#> have ab ;SPMgt; 0, and in fact if for example b = ∞, then it is preferable to have a as large as possible, at least a≥1.

<#8118#><#8118#> by 1=0 <#8119#>=0<#8122#><#8122#><#8119#>

<#8120#><#8123#>.. intnum<#8123#><#8120#>#math667#(X = a, b, expr): simple numerical integration from a to b. This is the fastest method, and should be used when a and b are not too large, the function is smooth, and can be evaluated exactly everywhere on the interval [a, b].

<#8127#><#8127#> by 1=0 <#8128#>=0<#8131#><#8131#><#8128#>

<#8129#><#8132#>.. intopen<#8132#><#8129#>#math668#(X = a, b, expr): numerical integration from a to b. This method should be used, again when a and b are not too large, but when the function is now allowed to be undefined (but continuous) at a or b, for example the function sin(x)/x at x = 0.

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

<#8136#><#8136#> by 1=0 <#8137#>=0<#8140#><#8140#><#8137#>

<#8138#><#8141#>.. matrix<#8141#><#8138#>#math669#(m, n, X, Y, expr): creation of the m×n matrix whose coefficients are given by the expression expr. There are two formal parameters in expr, the first one (X) corresponding to the rows, the second (Y) to the columns, and X goes from 1 to m, Y goes from 1 to n.

<#8145#><#8145#> by 1=0 <#8146#>=0<#8149#><#8149#><#8146#>

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

As an extreme example, compare

#math671#

prod(1, j = 1, 100,(1 - X#tex2html_wrap_indisplay27600#j))

with

#math672#

prod(1 + O(X#tex2html_wrap_indisplay27602#101), j = 1, 100,(1 - X#tex2html_wrap_indisplay27603#j)).

<#8156#><#8156#> by 1=0 <#8157#>=0<#8160#><#8160#><#8157#>

<#8158#><#8161#>.. prodeuler<#8161#><#8158#>#math673#(X = a, b, expr): product of expression expr, initialized at 1., the formal parameter X ranging over the prime numbers between a and b.<#8165#><#8165#>

<#8167#><#8167#> by 1=0 <#8168#>=0<#8171#><#8171#><#8168#>

<#8169#><#8172#>.. prodinf<#8172#><#8169#>#math674#(X = a, expr): <#8176#><#8176#>infinite product of expression expr, the formal parameter X starting at a. The evaluation stops when the relative error of the expression minus 1 is less than the default precision. The expressions must always evaluate to an element of #tex2html_wrap_inline27614#.

<#8179#><#8179#> by 1=0 <#8180#>=0<#8183#><#8183#><#8180#>

<#8181#><#8184#>.. prodinf1<#8184#><#8181#>#math675#(X = a, expr): infinite product of expression 1 + expr, the formal parameter X starting at a. The evaluation stops when the relative error of the expression is less than the default precision. The expressions must always evaluate to an element of #tex2html_wrap_inline27620#.

<#8189#><#8189#> by 1=0 <#8190#>=0<#8193#><#8193#><#8190#>

<#8191#><#8194#>.. solve<#8194#><#8191#>#math676#(X = a, b, expr): real root of expression expr between a and b, under the condition #math677#expr(X = a)*expr(X = b)≤ 0. The method used is Brent's method.

<#8198#><#8198#> by 1=0 <#8199#>=0<#8202#><#8202#><#8199#>

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

As an extreme example, compare

#math679#

sum(0, j = 1, 1000, 1/j)

with

#math680#

sum(0., j = 1, 1000, 1/j).

<#8209#><#8209#> by 1=0 <#8210#>=0<#8213#><#8213#><#8210#>

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

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

<#8220#><#8220#> by 1=0 <#8221#>=0<#8224#><#8224#><#8221#>

<#8222#><#8225#>.. suminf<#8225#><#8222#>#math682#(X = a, expr): <#8229#><#8229#>infinite sum of expression expr, the formal parameter X starting at a. The evaluation stops when the relative error of the expression is less than the default precision. The expressions must always evaluate to an element of #tex2html_wrap_inline27647#.

<#8232#><#8232#> by 1=0 <#8233#>=0<#8236#><#8236#><#8233#>

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

<#8241#><#8241#> by 1=0 <#8242#>=0<#8245#><#8245#><#8242#>

<#8243#><#8246#>.. vector<#8246#><#8243#>#math684#(n, X, expr): creates a row vector with n components whose components are the expression expr evaluated at the integral points between 1 and n (identical with <#1344#>hvector<#1344#>).

<#8250#><#8250#> by 1=0 <#8251#>=0<#8254#><#8254#><#8251#>

<#8252#><#8255#>.. vvector<#8255#><#8252#>#math685#(n, X, expr): creates a column vector with n components whose components are the expression expr evaluated at the integral points between 1 and n.

by1=0 <#8259#>=0<#8261#><#8261#><#8259#>



<#8260#><#8262#>. Plotting functions.<#8262#><#8260#>


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

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

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

<#8265#><#8265#> by 1=0 <#8266#>=0<#8269#><#8269#><#8266#>

<#8267#><#8270#>.. box<#8270#><#8267#>#math686#(w, x1, y1, x2, y2): draw in the rectwindow w the outline of the rectangle which is such that the points (x1, y1) and (x2, y2) are opposite corners. Only the part of the rectangle which is in w is drawn. The virtual cursor does <#1358#>not<#1358#> move.

The library syntax is #math687##tex2html_wrap_inline27667#(w, x1, y1, x2, y2) where all 5 arguments are C-integers.

<#8277#><#8277#> by 1=0 <#8278#>=0<#8281#><#8281#><#8278#>

<#8279#><#8282#>.. cursor<#8282#><#8279#>(w): give as a 2-component vector the current position of the virtual cursor corresponding to the rectwindow w.

The library syntax is #math688##tex2html_wrap_inline27671#(w) where w is a C-integer.

<#8289#><#8289#> by 1=0 <#8290#>=0<#8293#><#8293#><#8290#>

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

The library syntax is #math690##tex2html_wrap_inline27681#(list).

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

<#8301#><#8301#> by 1=0 <#8302#>=0<#8305#><#8305#><#8302#>

<#8303#><#8306#>.. initrect<#8306#><#8303#>(w, x, y): initialize the rectwindow w to width x and height y, and position the virtual cursor at (0, 0).

The library syntax is #math691##tex2html_wrap_inline27688#(w, x, y) where all 3 arguments are C-integers.

<#8313#><#8313#> by 1=0 <#8314#>=0<#8317#><#8317#><#8314#>

<#8315#><#8318#>.. killrect<#8318#><#8315#>(w): erase rectwindow w and free the corresponding memory.

The library syntax is #math692##tex2html_wrap_inline27692#(w) where w is a C-integer.

<#8325#><#8325#> by 1=0 <#8326#>=0<#8329#><#8329#><#8326#>

<#8327#><#8330#>.. line<#8330#><#8327#>#math693#(w, x1, y1, x2, y2): draw in the rectwindow w the part of the segment #math694#(x1, y1) - (x2, y2) which is inside w, and move the virtual cursor to (x2, y2) (even if it is outside the window).

The library syntax is #math695##tex2html_wrap_inline27700#(w, x1, y1, x2, y2) where all 5 arguments are C-integers.

<#8337#><#8337#> by 1=0 <#8338#>=0<#8341#><#8341#><#8338#>

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

The library syntax is #math697##tex2html_wrap_inline27706#(w, listx, listy) where w is a C-integer.

<#8349#><#8349#> by 1=0 <#8350#>=0<#8353#><#8353#><#8350#>

<#8351#><#8354#>.. move<#8354#><#8351#>(w, x, y): move the virtual cursor of the rectwindow w to position (x, y).

The library syntax is #math698##tex2html_wrap_inline27712#(w, x, y) where all 3 arguments are C-integers.

<#8361#><#8361#> by 1=0 <#8362#>=0<#8365#><#8365#><#8362#>

<#8363#><#8366#>.. plot<#8366#><#8363#>#math699#(X = a, b, expr): crude plot of the function represented by expression expr from a to b.

<#8370#><#8370#> by 1=0 <#8371#>=0<#8374#><#8374#><#8371#>

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

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

<#8379#><#8379#> by 1=0 <#8380#>=0<#8383#><#8383#><#8380#>

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

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

<#8388#><#8388#> by 1=0 <#8389#>=0<#8392#><#8392#><#8389#>

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

The library syntax is #math704##tex2html_wrap_inline27733#(listx, listy).

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

<#8400#><#8400#> by 1=0 <#8401#>=0<#8404#><#8404#><#8401#>

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

The library syntax is #math705##tex2html_wrap_inline27740#(w, x, y) where all 3 arguments are C-integers.

<#8412#><#8412#> by 1=0 <#8413#>=0<#8416#><#8416#><#8413#>

<#8414#><#8417#>.. points<#8417#><#8414#>#math706#(w, listx, listy): draw on the rectwindow w the points whose (x,y)-coordinates are in the vectors of equal length listx and listy and which are inside w. The virtual cursor does not move. This is basically the same function as the function <#1385#>plothraw<#1385#>, but with no scaling factor.

The library syntax is #math707##tex2html_wrap_inline27747#(w, listx, listy) where w is a C-integer.

<#8424#><#8424#> by 1=0 <#8425#>=0<#8428#><#8428#><#8425#>

<#8426#><#8429#>.. postdraw<#8429#><#8426#>(list): same as <#1388#>draw<#1388#>, except that the output is a postscript program appended to the file <#1389#>pari.ps<#1389#>.

The library syntax is #math708##tex2html_wrap_inline27751#(list).

<#8436#><#8436#> by 1=0 <#8437#>=0<#8440#><#8440#><#8437#>

<#8438#><#8441#>.. postploth<#8441#><#8438#>#math709#(X = a, b, expr): same as <#1392#>ploth<#1392#>, except that the output is a postscript program appended to the file <#1393#>pari.ps<#1393#>.

<#8445#><#8445#> by 1=0 <#8446#>=0<#8449#><#8449#><#8446#>

<#8447#><#8450#>.. postploth2<#8450#><#8447#>#math710#(T = a, b, expr): same as <#1395#>ploth2<#1395#>, except that the output is a postscript program appended to the file <#1396#>pari.ps<#1396#>.

<#8454#><#8454#> by 1=0 <#8455#>=0<#8458#><#8458#><#8455#>

<#8456#><#8459#>.. postplothraw<#8459#><#8456#>#math711#(listx, listy): same as <#1398#>plothraw<#1398#>, except that the output is a postscript program appended to the file <#1399#>pari.ps<#1399#>.

The library syntax is #math712##tex2html_wrap_inline27756#(listx, listy).

<#8466#><#8466#> by 1=0 <#8467#>=0<#8470#><#8470#><#8467#>

<#8468#><#8471#>.. rbox<#8471#><#8468#>(w, x2, y2): draw in the rectwindow w the outline of the rectangle which is such that the points (x1, y1) and (x2, y2) are opposite corners, where (x1, y1) is the current position of the cursor. Only the part of the rectangle which is in w is drawn. The virtual cursor does <#1402#>not<#1402#> move.

The library syntax is #math713##tex2html_wrap_inline27764#(w, x2, y2) where all 3 arguments are C-integers.

<#8478#><#8478#> by 1=0 <#8479#>=0<#8482#><#8482#><#8479#>

<#8480#><#8483#>.. rline<#8483#><#8480#>(w, x2, y2): draw in the rectwindow w the part of the segment #math714#(x1, y1) - (x2, y2) which is inside w, where (x1, y1) is the current position of the virtual cursor, and move the virtual cursor to (x2, y2) (even if it is outside the window).

The library syntax is #math715##tex2html_wrap_inline27772#(w, x2, y2) where all 3 arguments are C-integers.

<#8490#><#8490#> by 1=0 <#8491#>=0<#8494#><#8494#><#8491#>

<#8492#><#8495#>.. rmove<#8495#><#8492#>(w, x, y): move the virtual cursor of the rectwindow w to position #math716#(x1 + x, y1 + y), where (x1, y1) is the initial position of the cursor (i.e. to position (x, y) relative to the initial cursor).

The library syntax is #math717##tex2html_wrap_inline27779#(w, x, y) where all 3 arguments are C-integers.

<#8502#><#8502#> by 1=0 <#8503#>=0<#8506#><#8506#><#8503#>

<#8504#><#8507#>.. rpoint<#8507#><#8504#>(w, x, y): draw the point #math718#(x + x1, y + y1) on the rectwindow w (if it is inside w), where (x1, y1) is the current position of the cursor, and in any case move the virtual cursor to position #math719#(x + x1, y + y1).

The library syntax is #math720##tex2html_wrap_inline27787#(w, x, y) where all 3 arguments are C-integers.

<#8514#><#8514#> by 1=0 <#8515#>=0<#8518#><#8518#><#8515#>

<#8516#><#8519#>.. string<#8519#><#8516#>(w, x): draw on the rectwindow w at the current position of the cursor the string corresponding to x. x can either be a string enclosed in quotes ( ;SPMquot; ), or x can be a number which can be converted into a real number. In that case it is printed in the format 9.3lf, i.e.~9 characters before the decimal point, and 3 after.

The library syntax is #math721##tex2html_wrap_inline27794#(w, x) where w is a C-integer and x is a GEN which either represents a vector of ASCII values, or can be converted into a real number.

by1=0 <#8526#>=0<#8528#><#8528#><#8526#>



<#8527#><#8529#>. Programming under GP and user-defined functions.<#8529#><#8527#>


<#8532#><#8532#>

by 1=0 <#8542#>=0<#8544#><#8544#><#8542#>

<#8543#><#8545#>.. <#8553#><#8553#>Variables and symbolic expressions<#8545#><#8543#>.

In GP you can use up to 256 variable names. These names can be any standard identifier names, i.e. they must start with a letter and contain only alphanumeric characters. To avoid confusion with other symbols, you must not use non alphanumeric symbols like '_', '$', or '.'. In addition to the function names which you must not use (see the list with #math722#\c) there are exactly three special variable names which you are not allowed to use: <#1415#>pi<#1415#> and <#1416#>euler<#1416#>, which represent well known constants, but also <#1417#>i<#1417#> which is always equal to the square root of -1. Since usually you are not going to use the variable name <#1418#>pi<#1418#> for anything else but the number π, and similarly for <#1419#>euler<#1419#>, these two will not create any problems. On the other hand, you will have to get used to calling a loop control variable with a name different from <#1420#>i<#1420#>. We realize that this may initially be the cause for some confusion, but we do not have any replacement symbol for the square root of -1.

Now the main thing to understand is that PARI/GP is <#1421#>not<#1421#> a symbolic manipulation package, although it shares some of the functionalities. One of the main consequences of this fact is that all expressions are evaluated as soon as they are written, they never stay in a purely abstract form. As an important example, consider what happens when you use a variable name <#1422#>before<#1422#> assigning a value into it. This is perfectly acceptable to GP, who considers this variable in fact as a polynomial of degree 1, with coefficients 1 in degree 1, 0 in degree 0, whose variable is the variable name you used.

If later you assign a value to that variable, the objects which you have created before will still be considered as polynomials. If you want to obtain their value, use the function <#1423#>eval<#1423#> (see 3.6.8 above).

Another consequence is that the variables are numbered in the order that they appear, and the main variable of an expression is always the lowest numbered variable. Hence if you are working with expressions involving several variables and want to have them ordered in a specific manner <#1424#>in the internal representation<#1424#>, the simplest is just to write down the variables one after the other under GP before starting any real computations. If you already have started working and want to change the names of the variables in an object, use the function <#1425#>changevar<#1425#> (see 3.2.5). If you only want to have them ordered when the result is printed, you can also use the function <#1426#>reorder<#1426#> (see 3.10.4.7).

Finally, note that if x is a vector, you can assign a result to x[m] (i.e. write something like x[k] = expr). If x is a matrix, you can assign a result to x[m, n], but <#1427#>not<#1427#> to x[m], which is a vector. If you want to assign an expression to the m-th column of a matrix x, use #math723#x[, m] = expr instead. Similarly, use #math724#x[m,] = expr to assign an expression to the m-th row of x.

by 1=0 <#8564#>=0<#8566#><#8566#><#8564#>

<#8565#><#8567#>.. <#8579#><#8579#>Expressions and <#8581#><#8581#>expression sequences<#8567#><#8565#>.

An expression is formed by combining the GP operators, functions (including user-defined functions) and control statements. It may be preceded by an assignment statement '=' into a variable. It always has a value, which can be any PARI object.

Several expressions can be combined on a single line by separating them with semicolons (';') and also with colons (':') for those who are used to BASIC. Such an expression sequence will be called simply a seq. A seq also has a value, which is the value of the last nonempty expression in the sequence. Under GP, the value of the seq is always put on the stack (i.e. it will become the next object %n), and only that value. The values of the other expressions in the seq are discarded after the execution of the seq is complete, except of course if they were assigned into variables. In addition, the value of the seq (or of course of an expression if there is only one) is printed if the line does not end with a semicolon (';').

<#8583#><#8583#> by 1=0 <#8584#>=0<#8587#><#8587#><#8584#>

<#8585#><#8588#>.. Control statements<#8588#><#8585#>.

A number of control statements are available under GP. They are simpler and have a slightly different syntax than their C counterparts, but are quite powerful enough to write any kind of program. Some of them are specific to GP, since they are made for number theorists. They are as follows. As usual, X will denote any simple variable name, and seq will always denote a sequence of expressions, including the empty sequence.

<#8592#><#8592#> by1 <#8593#>=0<#8596#><#8596#><#8593#>

<#8594#><#8597#>.. . for<#8597#><#8594#>#math725#(X = a, b, seq): the formal variable X going from a to b, the seq is evaluated. Nothing is done if a ;SPMgt; b. a and b must be in #tex2html_wrap_inline27832#.

<#8602#><#8602#> by1 <#8603#>=0<#8606#><#8606#><#8603#>

<#8604#><#8607#>.. . fordiv<#8607#><#8604#>(n, X, seq): the formal variable X ranging through the positive divisors of n, the sequence seq is evaluated. n must be of type integer.

<#8611#><#8611#> by1 <#8612#>=0<#8615#><#8615#><#8612#>

<#8613#><#8616#>.. . forprime<#8616#><#8613#>#math726#(X = a, b, seq): the formal variable X ranging over the prime numbers between a to b (including a and b if they are prime), the seq is evaluated. Nothing is done if a ;SPMgt; b. Note that a and b must be in #tex2html_wrap_inline27849#.

<#8621#><#8621#> by1 <#8622#>=0<#8625#><#8625#><#8622#>

<#8623#><#8626#>.. . forstep<#8626#><#8623#>#math727#(X = a, b, s, seq): the formal variable X going from a to b, in increments of s, the seq is evaluated. Nothing is done if s ;SPMgt; 0 and a ;SPMgt; b or if s ;SPMlt; 0 and a ;SPMlt; b. a, b and s must be in #tex2html_wrap_inline27864#, and s must be nonzero.

<#8631#><#8631#> by1 <#8632#>=0<#8635#><#8635#><#8632#>

<#8633#><#8636#>.. . goto<#8636#><#8633#>(a): a being an integer between 0 and 99, go to the position in the seq referred to by label a. This can be either a forward skip or a backwards skip. In case of multiple labels, control is transferred in the following manner. If one such label is to the left of the goto instruction, control is transferred to the rightmost one among those which are to the left. Otherwise, control is transferred to the rightmost label with a given number. In any case, multiple labels in a given seq should be avoided.

Also, good programming practice implies that the <#1436#>goto<#1436#> instruction should be used only in special cases, such as getting out of a deeply nested set of control instructions in one step. In fact, in the present version 1.37, the <#1437#>goto<#1437#> instruction almost always leads to syntax errors hence should be avoided, except as a means to stop a program catastrophically without getting out of GP. This may be corrected in a future release.

Note that usually, it is possible to use the <#1438#>goto<#1438#> instruction with an a which is not an absolute constant, but may vary in the seq (;SPMquot;computed goto;SPMquot;).

<#8640#><#8640#> by1 <#8641#>=0<#8644#><#8644#><#8641#>

<#8642#><#8645#>.. . if<#8645#><#8642#>#math728#(a, seq1, seq2): if a is nonzero, the expression sequence seq1 is evaluated, otherwise the expression seq2 is evaluated. Of course, seq1 or seq2 may be empty, but the syntax must stay the same: <#1440#>if(a,seq,)<#1440#> evaluates seq if a is not equal to zero, does nothing otherwise; <#1441#>if(a,,seq)<#1441#> evaluates seq if a is equal to zero, does nothing otherwise.

<#8649#><#8649#> by1 <#8650#>=0<#8653#><#8653#><#8650#>

<#8651#><#8654#>.. . label<#8654#><#8651#>(a): a being an integer between 0 and 99, label this position as label number a for use by the <#1443#>goto<#1443#> instruction. Labels are specific to a given seq.

<#8658#><#8658#> by1 <#8659#>=0<#8662#><#8662#><#8659#>

<#8660#><#8663#>.. . until<#8663#><#8660#>(a, seq): evaluate expression sequence seq until a is not equal to 0 (i.e. until a is true). If a is initially not equal to 0, seq is evaluated once (more generally, the condition on a is tested <#1445#>after<#1445#> execution of the seq, not before as in <#1446#>while<#1446#>).

<#8667#><#8667#> by1 <#8668#>=0<#8671#><#8671#><#8668#>

<#8669#><#8672#>.. . while<#8672#><#8669#>(a, seq): while a is nonzero evaluate the expression sequence seq. The test is made <#1448#>before<#1448#> evaluating the seq, hence in particular if a is initially equal to zero the seq will not be evaluated at all.

by 1=0 <#8676#>=0<#8678#><#8678#><#8676#>

<#8677#><#8679#>.. Specific functions used in GP programming<#8679#><#8677#>.

In addition to the general PARI functions, it is necessary to have some functions which will be of use specifically for GP. They are as follows:

<#8683#><#8683#> by1 <#8684#>=0<#8687#><#8687#><#8684#>

<#8685#><#8688#>.. . kill<#8688#><#8685#>(x): kills the present value of the variable or user-defined function x. After <#1451#>kill<#1451#> of a variable, since the variable does not have a value, as has been explained above it is again considered as a monic polynomial of degree 1 with no constant term.

For the following four printing functions, list represents a list (separated by commas) either of PARI objects or of character strings between double quotes '<#1452#>;SPMquot;<#1452#>', which are always printed as they are.

<#8692#><#8692#> by1 <#8693#>=0<#8696#><#8696#><#8693#>

<#8694#><#8697#>.. . pprint<#8697#><#8694#>(list): output list in prettyprint (beautified) format, ending with a newline.

<#8701#><#8701#> by1 <#8702#>=0<#8705#><#8705#><#8702#>

<#8703#><#8706#>.. . pprint1<#8706#><#8703#>(list): output list in prettyprint (beautified) format, without ending with a newline.

<#8710#><#8710#> by1 <#8711#>=0<#8714#><#8714#><#8711#>

<#8712#><#8715#>.. . print<#8715#><#8712#>(list): output list in raw format, ending with a newline.

<#8719#><#8719#> by1 <#8720#>=0<#8723#><#8723#><#8720#>

<#8721#><#8724#>.. . print1<#8724#><#8721#>(list): output list in raw format, without ending with a newline.

<#8728#><#8728#> by1 <#8729#>=0<#8732#><#8732#><#8729#>

<#8730#><#8733#>.. . read<#8733#><#8730#>(): reads a string, interpreted as a GP expression, from the input file, usually standard input (i.e. the keyboard). If a sequence of expressions is given, the result is the result of the last expression of the sequence. When using this instruction, it is useful to prompt for the string by using the <#1458#>print1<#1458#> function. Note that in the present version 2.8 of <#1459#>pari.el<#1459#>, when using GP under gnuemacs (see section 3.10) one <#1460#>must<#1460#> prompt for the string, with a string which ends with the same prompt as the current one (usually a '?').

<#8737#><#8737#> by1 <#8738#>=0<#8741#><#8741#><#8738#>

<#8739#><#8742#>.. . reorder<#8742#><#8739#>(x): x must be a vector. If x is the empty vector, this gives the vector whose components are the existing variables in increasing order (i.e. in decreasing importance). If x is nonempty, it must be a permutation of variable names, and this permutation gives a new order of importance of the variables. For example, if the existing order is <#1462#>[x,y,z]<#1462#>, then after <#1463#>reorder([z,x])<#1463#> the order of importance of the variables will be <#1464#>[z,y,x]<#1464#>.

<#8746#><#8746#> by1 <#8747#>=0<#8750#><#8750#><#8747#>

<#8748#><#8751#>.. . texprint<#8751#><#8748#>(list): outputs list in TEX<#1466#><#1466#> format. This output can then be used in a TEX<#1467#><#1467#> manuscript.

Warning: in the present version 1.37, the printing is done on the standard output, hence to be able to get the output into a file, you must be either in an emacs session or shell (see 3.10), in a windowing system (which enables you to grab the output with the mouse), under a UNIX script command, or with the logfile enabled (see the command #math729#\l). This will be improved.

<#8755#><#8755#> by 1=0 <#8756#>=0<#8759#><#8759#><#8756#>

<#8757#><#8760#>.. User defined functions<#8760#><#8757#>.

It is very easy to define a new function under GP, which can then be used like any other function. The syntax is as follows:

<#1469#>name(list of true formal variables, list of local variables)=seq<#1469#>

where <#1470#>name<#1470#> is the name that you want to give to your function (same syntactic restrictions as for variable names). <#1471#>list of true formal variables<#1471#> is the list of variables corresponding to those which you will actually use when calling your function, the variables being separated by commas, and the list being allowed to be empty. <#1472#>list of local variables<#1472#> is the list of the additional local variables which you will use in the definition of the function. If you omit some or all of these local variable declarations, the function will probably still work, but the nondeclared variables will become global, hence known outside of the function, and this may have undesirable side-effects. On the other hand, in some cases it may also be what you want. Finally, as usual <#1473#>seq<#1473#> is any expression sequence.

Once the function is defined using the above syntax, you can use it like any other function. In addition, you can also recall its definition exactly as you do for predefined functions, that is by writing <#1474#>?name<#1474#>. One small difference with predefined functions is that you can never redefine such a function, while you can redefine a user-defined function as many times as you want, without using the <#1475#>kill<#1475#> instruction.

In a given session you can give any identifier name to a function, <#1476#>except<#1476#> those of predefined functions (of course) but also those of any variables that have been used, even if they have been killed. On the other hand, if you want to use as a variable name the name of a user-defined function, it is enough (and necessary) to kill this function name first.

An amusing example of a user-defined function is the following. It is intended to illustrate both the use of user-defined functions and the power of the <#1477#>sumalt<#1477#> function. Although since version 1.34 the <#8764#><#8764#>Riemann zeta-function is included in the standard functions, let us assume that this is not the case (or that we want another implementation). One way to define it, which is probably the simplest (but certainly not the most efficient), is as follows:

<#8766#><#8766#> <#2796#>zet(s,j)=sumalt(j=1,(-1)ˆ(j-1)*jˆ(-s))/(1-2ˆ(1-s))<#2796#>

Then this gives reasonably good accuracy and speed as long as you are not too far from the domain of convergence. Try it for s integral between -5 and 5, say, or for s = 0.5 + i*t where #math730#t = 14.134... Of course, the call to the function is done by <#1483#>zet(s)<#1483#>, the variable <#1484#>j<#1484#> must not be given.

by 1=0 <#8776#>=0<#8778#><#8778#><#8776#>

<#8777#><#8779#>.. Special <#8787#><#8787#>editing characters<#8779#><#8777#>. A GP program can of course have more than one line. Since GP executes your commands as soon as you have finished typing them, there must be a way to tell it to wait for the next line or lines of input before doing anything. There are two ways of doing this.

The first one is simply to use the <#8789#><#8789#>backslash character '#math731#\' at the end of the line that you are typing, just before hitting ;SPMlt;return;SPMgt;. This tells GP that what you will write on the next line is the physical continuation of what you have just written. In other words, it makes GP forget your newline character. For example if you use this while defining a function, and if you ask for the definition of the function using <#1487#>?name<#1487#>, you will see that your backslash has disappeared and that everything is on the same line. You can type a #math732#\ anywhere. It will be interpreted as above only if it is immediately followed by a newline. For example, you can type

<#1488#>3+#math733#\<#1488#>

<#1489#>4<#1489#>

instead of typing <#1490#>3+4<#1490#>.

The second one cannot be used everywhere, but is in general more useful. It is the use <#8791#><#8791#> of braces '{' and '}'. When GP sees an opening brace ('{`) at the beginning of a line, it understands that you are writing a program, and newlines will be ignored (but registered, contrary to when you use a backslash) until you type a closing brace '}'. However, there is an important (but easily obeyed) restriction: inside an open brace-close brace pair, all newlines must occur after a semicolon (';'), i.e. between two expressions forming a seq.

Of course you can combine the use of backslash and braces.

by 1=0 <#8801#>=0<#8803#><#8803#><#8801#>

<#8802#><#8804#>.. The GP/PARI <#8812#><#8812#>programming language<#8804#><#8802#>.

As we have seen, the GP calculator uses a primitive purely interpreted language. The structure of this language is in fact more reminiscent of LISP with a functional notation, <#1493#>f(x, y)<#1493#> rather than <#1494#>(f x y)<#1494#>: all programming constructs, such as <#1495#>if, while,<#1495#> etc.) are functions, and the main loop does not really execute, but rather evaluates (sequences of) expressions.

Of course, it is by no means a true LISP. Function names are distinct from variable names: once a name has been used as a variable name, this cannot be changed in the same session. Predefined function names cannot be used for anything else, and the number of actual parameters must match the declaration given in the online help. Identifiers that are used for user-defined functions can be freely redefined for other functions, or totally forgotten (using <#1496#>kill<#1496#>) and later reused for a variable, for example.

Each variable has a stack of values, implemented as a linked list. When a new scope is entered, during a function call, the value of the actual parameter is pushed on the stack. If the parameter is not supplied, a special 0 value called <#2799#><#8814#><#8814#>gnil<#2799#> is pushed on the stack (this value is not printed if it is returned as the result of a GP expression sequence). Upon exit, the stack decreases. You can <#1498#>kill<#1498#> a variable, decreasing the stack yourself. This should be used only at the top level of GP, to undo the effect of an assignment, not from a function. However, the stack has a bottom: the value of a variable is the monomial of degree 1 in this variable, as is natural for a mathematician.

Note that the iterative constructs which use a variable name (<#1499#>for, fordiv, forprime, prod, sum, vector, matrix, plot,<#1499#> etc.) also consider the given variable to be local to the construct. A value is pushed on entry and pulled on exit. So, it is not necessary for a function using such a construct to declare the variable as a dummy formal parameter. In particular, in our <#1500#>zet<#1500#> example above, the variable <#1501#>j<#1501#> need not be declared.

Otherwise, it is strongly recommended to declare in this way all other variables that are used inside a function: If a function accesses a variable which is not one of its formal parameters, the value used will be the one which happens to be on top of the stack at the time of the call. This could be a ``global'' value, or a local value belonging to any function higher in the call chain. So, be warned.

<#1502#>Implementation note.<#1502#> For the curious reader, here is how these stacks are handled: a <#8816#><#8816#>hashing function is computed from the identifier, and used as an index in <#2800#><#8818#><#8818#>hashtable<#2800#>, a table of pointers. Each of these pointers begins a linked list of structures (type <#2801#><#8820#><#8820#>entree<#2801#>). The linked list is searched linearly for the identifier (each list will have less than 7 components or so). When the correct <#1506#>entree<#1506#> is found, it points to the top of the stack of values for that identifier if it is a variable, to the function itself if it is a predefined function, and to a copy of the text of the function if it is a user-defined function. When an error occurs, all of this maze (rather a tree, in fact) is searched and (hopefully) replaced in the situation preceding the last call of the main evaluator.

by1=0 <#8829#>=0<#8831#><#8831#><#8829#>



<#8830#><#8832#>. Using GP under <#8839#><#8839#>gnuemacs.<#8832#><#8830#>


Thanks to the help of Annette Hoffman from the university of Saarbrücken, and since version 1.34.05 from David Carlisle from the university of Manchester, it is possible and in fact desirable to use GP as a subprocess of gnuemacs. This is of course possible only if gnuemacs has been installed on your machine.

To use this, you must include in your <#1508#>.emacs<#1508#> file the following line:

<#2803#>(load ;SPMquot;<#8841#><#8841#>pari;SPMquot; nil t)<#2803#>

where <#1510#>pari.el<#1510#> is the name of the file that will have to be loaded by gnuemacs (if you have changed the name, or if you have the file in a different directory, you must of course supply the correct name). This file is included in the PARI distribution.

Once this is done, under gnuemacs if you type <#1511#>M-x gp<#1511#> (where as usual M is the Meta key, i.e. Escape, or on SUN keyboards, the Left key), a special shell will be started, which in particular launches GP with the default stack size, prime limit and input buffer size. If you type instead <#1512#>C-u M-x gp<#1512#>, you will be asked for the name of the GP executable, the stack size, the prime limit and the input buffer size before the execution of GP begins. If for any of these you simply type return, the default value will be used (on Unix machines it will be <#1513#>/usr/local/bin/gp<#1513#> for the executable, 4000000 for the stack, 500000 for the prime limit and 30000 for the buffer size).

You can then work as usual under GP, but with two notable advantages. First and foremost, you have at your disposal all the facilities of a text editor like emacs, in particular for correcting or copying blocks. Second, you can have an on-line help which is much more complete than what you obtain by typing <#1514#>?name<#1514#>. This is done by typing M-? (where M is the Meta key). In the minibuffer, emacs asks what function you want to describe, and after your reply you obtain the description which is in the users manual, including the description of functions (such as #math734#\, %) which use special symbols.

This help system can also be menu-driven, by using the command <#1515#>M-\c<#1515#> which opens a help menu window which enables you to choose the category of commands for which you want an explanation.

You also have at your disposal a few other commands. Read the file pari.txt for details.

Note that if for some reason the session crashes (due to a bug in your program or in the PARI system), you will usually stay under emacs, but the GP buffer will be killed. To recover it, simply type again M-x gp (or C-u M-x gp), and a new session of GP will be started after the old one, so you can recover what you have typed. Note that this will of course <#1516#>not<#1516#> work if for some reason you exited emacs before coming back (except for the C-z temporary stopping command).

by1=0 <#8843#><#8843#> <#8844#>=0<#8846#><#8846#><#8844#>

Chapter : Programming PARI in Library Mode

by1=0 <#8849#>=0<#8851#><#8851#><#8849#>



<#8850#><#8852#>. Introduction: initializations, universal objects, input and output.<#8852#><#8850#>


To be able to use PARI in <#8855#><#8855#>library mode, you must write a C program and link it to the PARI library and the PARI include files. See the installation guide (given in Appendix A) on how to create and install the PARI library and include files. A sample Makefile is also given in Appendix B.

Probably the best way to understand how programming is done is to work through a complete example. We will write such a program in section 4.3. Before doing this, a few explanations are in order.

by 1=0 <#8857#>=0<#8859#><#8859#><#8857#>

<#8858#><#8860#>.. Initializations and universal objects.<#8860#><#8858#>

First, one must explain to the outside world what kind of objects and programs we are going to use. This is done simply with the statement

<#1521#>#include ;SPMlt;genpari.h;SPMgt;<#1521#>

Note that this is usually a link, created when you make the library, to a file called either <#1522#>genpari68k.h<#1522#> (for 680x0-based machines with x at least 2) or <#1523#>genpariother.h<#1523#> (for all other machines).

This file <#2804#><#8864#><#8864#>genpari.h<#2804#>, first exports all the necessary constants, variables and functions, defines some important macros, and also defines the fundamental type for all PARI objects: the type <#2805#><#8866#><#8866#>GEN<#2805#>, which is simply a pointer to <#1526#>long<#1526#>.

<#1527#>Technical note<#1527#>: we would have liked to define a type GEN to be a pointer on itself. This unfortunately is not possible in C, except by using structures, but then the names become unwieldy. On the other hand, by a simple trick, it can be done in Pascal for example. The result of this is that when we will use a component of a PARI object, it will be a <#1528#>long<#1528#>, hence will need to be typecasted to a GEN again if we want to avoid warnings from the compiler. This will sometimes be quite tedious, but of course is trivially done.

To take an example, a polynomial P of degree 2 will be represented by a chunk of memory pointed to by the GEN P. P[0] and P[1] contain code information, in particular the type of the object, the degree of P, etc.... P[2], P[3], P[4] contain pointers to the coefficients of degree 0, 1, and 2 of P respectively (note the ascending order). This is where typecasting will be necessary: in principle P[i] (for i = 2, 3, 4) is a long, but we will want to use it as a GEN. The coefficients P[i] themselves are in chunks of memory whose complexity depends on the types of the coefficients, and so on.

Now we must state the most important law about programming in PARI, which must be respected if one wants to avoid disasters:

<#2806#>Apart from universal objects <#1529#>(see below)<#1529#> the chunks of memory used by a given PARI object must be in consecutive memory locations<#2806#>.

Don't panic: let's see the reason and the meaning of this, and how it can be achieved.

When doing large computations, unwanted intermediate results clutter up memory very fast so some kind of garbage collecting is needed. Most large systems do garbage collecting when the cluttering gets heavy, and this slows down the performance. In PARI we have taken a different approach: you must do your own cleaning up as soon as the intermediate results are not needed. Special purpose routines have been written to do this, but the primary requirement is exactly as stated above: a PARI object must be (essentially) connected. As a consequence of this explanation, one also sees that there is an evident exception to the above law: if your computation is small enough so that you don't need to do any garbage collecting, then just go ahead, PARI won't mind disconnected objects in most cases. However, since PARI routines do their own garbage collecting, watch carefully what you are doing.

The notion of <#8868#><#8868#>universal object alluded to above is quite simple: during the execution of your program, a number of objects will have been defined (by the system or by yourself) with the idea that they stay permanently with the same values. Examples are the integer 1, the fraction #math735##tex2html_wrap_inline27947#, the polynomial X, or a prime p which is used as a base modulus for integermods or p-adics. These universal objects are of course allowed to be disconnected from the other PARI objects.

After declaring the use of the file genpari.h, the first executable statement of a main program should be to initialize the PARI system, and in particular the PARI stack which will contain all the computations. This is simply done with a call to the two variable function <#2807#><#8873#><#8873#>init<#2807#>, like <#1532#>init(4000000,100000)<#1532#>. The first argument (here 4 million) is the number of bytes given to PARI to work with (it should not reasonably drop under 500000), and the second is the upper limit on a precomputed prime number table. If you don't want prime numbers, just put 2, but put an argument anyway because <#1533#>init()<#1533#> expects one.

We have now at our disposal:

• the following universal objects: the integer 0 (<#2808#><#8875#><#8875#>gzero<#2808#> as a GEN, <#2809#><#8877#><#8877#>zero<#2809#> as a long), the integer 1 (<#2810#><#8879#><#8879#>gun<#2810#> as a GEN, <#2811#><#8881#><#8881#>un<#2811#> as a long), the integer 2 (<#2812#><#8883#><#8883#>gdeux<#2812#> as a GEN, <#2813#><#8885#><#8885#>deux<#2813#> as a long), the fraction #math736##tex2html_wrap_inline27953# (<#2814#><#8890#><#8890#>ghalf<#2814#> as a GEN, <#2815#><#8892#><#8892#>lhalf<#2815#> as a long), the complex number i, <#2816#><#8894#><#8894#>gi<#2816#> as a GEN. In addition, space is reserved for the polynomials 1 (<#2817#><#8896#><#8896#>polun[]<#2817#> as a GEN, <#2818#><#8898#><#8898#>lpolun<#2818#> as a long), and the polynomials xv, (<#2819#><#8900#><#8900#>polx[]<#2819#> as GENs, <#2820#><#8902#><#8902#>lpolx<#2820#> as longs), where xv is the name of variable number v, where #math737#0≤v≤255. However, they are not created upon initialization, and it is the programmer's responsibility to fill them before use. Since this is not very easy, we advise the user to use the function <#2821#><#8904#><#8904#>lisseq<#2821#> which has essentially the same effect as <#2822#><#8906#><#8906#>lisexpr<#2822#> except that it can execute a sequence of expressions and not only a single expression. For example, to prepare for use the variables a,b,c,x, write

lisseq(;SPMquot;x;a;b;c;SPMquot;)

Note that <#1550#>polun<#1550#> and <#1551#>polx<#1551#> are arrays, the index being the polynomial variable number.

• a large PARI <#8908#><#8908#>stack containing nothing but (in the present version) the 167 long words (668 bytes) of the predefined universal objects.

• a <#8910#><#8910#>heap which is dealt with in a different way from the stack, and will contain other permanent universal objects.

• a table of primes.

• access to all the built-in functions of the PARI library.

We have already described many of these functions in the preceding chapters. However some of them are specific to library mode and thus will be explained in this chapter.

by 1=0 <#8912#>=0<#8914#><#8914#><#8912#>

<#8913#><#8915#>.. Input and output.<#8915#><#8913#>

Two important aspects have not yet been explained since they are specific to library mode: input and output of PARI objects.

For <#8919#><#8919#>input, PARI provides you with two powerful high level functions which enables you to input your objects as if you were under GP. In fact, the second one <#1556#>is <#1556#> essentially the GP syntactical parser, hence you can use it not only for input but for any computation that you can do under GP. These functions are called <#2823#><#8921#><#8921#>lisexpr<#2823#> and <#2824#><#8923#><#8923#>lisseq<#2824#>. The first one has the following syntax:

<#1559#>GEN lisexpr(char* s);<#1559#>

Its effect is to analyze the input string s and to compute the result as in GP. However it is limited to one expression. If you want to read and evaluate a sequence of expressions, use

<#1560#>GEN lisseq(char* s);<#1560#>

Warning: there is a slight difference between these functions and the GP syntactical parser: the expressions and sequences which you use must not contain any spaces.

Once in a while, it may be useful to have the evaluation of the string involving a call to a function you have defined in C. The function <#2825#><#8925#><#8925#>install<#2825#> allows you to give a name to a function taking 0, 1, 2 or 3 GEN arguments and returning a single GEN. The syntax is

<#1562#>void install(GEN (*f)(), char *name, int valence)<#1562#>

where <#1563#>f<#1563#> is the (address of) the function, <#1564#>name<#1564#> its new name, and <#1565#>valence<#1565#> the number of its arguments, an integer between 0 and 3.

For <#8927#><#8927#>output, there exist four different functions. First, you can use the function <#2826#><#8929#><#8929#>sor<#2826#> with the following syntax:

<#1568#>void sor(GEN x,char format,long dec,long field);<#1568#>

Here format is either <#1569#>'e'<#1569#>, <#1570#>'f'<#1570#> or <#1571#>'g'<#1571#> corresponding to the three output formats of GP, <#1572#>dec<#1572#> is the number of printed significant digits for real numbers, and should be put equal to -1 if all of them are wanted, and <#1573#>field<#1573#> corresponds to the field width of GP used for printing integers.

A default use of this function is to use the macro <#2827#><#8931#><#8931#>outbeaut(GEN x)<#2827#> which is equivalent to <#1575#>sor(x,'g',-1,0)<#1575#>.

The second format corresponds to the ``raw'' format of GP (see section 2.2.5) and is obtained by using the function <#2828#><#8933#><#8933#>brute<#2828#> with the following syntax:

<#1577#>void brute(GEN x,char format,long dec);<#1577#>

A default use of this function is to use the macro <#2829#><#8935#><#8935#>output(GEN x)<#2829#> which is equivalent to <#1579#>brute(x,'g',-1)<#1579#>.

The third format corresponds to the <#1580#>texprint<#1580#> function of GP, and gives a TEX<#1581#><#1581#> output of the result. It is obtained by using the function <#1582#>texe<#1582#> with the following syntax:

<#2830#>void <#8937#><#8937#>texe(GEN x,char format,long dec);<#2830#>

Finally, you can use the <#8939#><#8939#>hexadecimal tree output corresponding to the GP command #math738#\x using the function <#2831#><#8941#><#8941#>voir<#2831#> with the following syntax:

<#1586#>void voir(GEN x,-1);<#1586#>

Again the last parameter must be given and put equal to -1. In principle this last type of output is used only for debugging purposes.

by1=0 <#8943#>=0<#8945#><#8945#><#8943#>



<#8944#><#8946#>. Creation, destruction, and implementation of the PARI objects.<#8946#><#8944#>


By far the most important functions which are specific to the library mode are the functions which allow the programmer to create and delete PARI objects, and the assignment statements.

by 1=0 <#8949#>=0<#8951#><#8951#><#8949#>

<#8950#><#8952#>.. Creation of PARI objects.<#8952#><#8950#><#8956#><#8956#> The basic function which creates a PARI object is the function <#2832#><#8958#><#8958#>cgetg<#2832#> whose syntax is:

<#1591#>cgetg(long length,long type);<#1591#>

Here length is a long specifying the number of longwords to be allocated to the object, and type is a long which is the type number of the object (see chapter 1 or below for the list of these type numbers). Note that the length is the first argument, and type the second. The precise effect of this function is as follows: it first creates on the stack a chunk of memory of size ``length'' longwords, and puts the address of the chunk as the returned value. If not enough memory is available, a message to the effect that the PARI stack overflows will be printed. Otherwise, it sets the type of the chunk to ``type'', sets the length, and sets the reference count to 1. In effect, it fills correctly and completely the first codeword (z[0] or *z) of the PARI object. Many PARI objects having also a second codeword (types 1,2,7,10,11), <#1592#>it is the programmer's responsibility to fill this second codeword<#1592#>, either explicitly (see below), or implicitly using an assignment statement.

Note that the argument ``length'' is forced for a number of types: 3 for types 3,4,5,6,9,13,14 and 16, 4 for type 8 (Quad), and 5 for type 7 (p-adic). However for efficiency's sake no checking is made in the function <#1593#>cgetg<#1593#> so disastrous results can occur if you give an incorrect length.

Notes: 1) the creation of leaves, i.e. integers or reals, being so common, <#2833#><#8960#><#8960#>cgeti<#2833#> and <#2834#><#8962#><#8962#>cgetr<#2834#> should be used instead of <#1596#>cgetg( ,1)<#1596#> and <#1597#>cgetg( ,2)<#1597#>.

2) the macros <#2835#><#8964#><#8964#>lgetg<#2835#>, <#2836#><#8966#><#8966#>lgeti<#2836#> and <#2837#><#8968#><#8968#>lgetr<#2837#> are predefined as <#1601#>(long)cgetg<#1601#>, <#1602#>(long)cgeti<#1602#> and <#1603#>(long)cgetr<#1603#> respectively.

Examples:

<#1604#>z = cgeti(6);<#1604#> (or <#1605#>cgetg(6, 1);<#1605#>) creates an integer type which can hold numbers of absolute value less than 2128 (2 codewords + 4 mantissa longwords).

<#1607#>z = cgetg(3, 6); z[1] = lgetr(5); z[2] = lgetr(5);<#1607#> creates a complex type whose real and imaginary part can hold real numbers of precision 96 bits.

<#1608#>z = cgetg(4, 19); for(i=1; i;SPMlt;4; i++) z[i] = lgetg(5, 18);<#1608#> creates a matrix type for 4×3 matrices. One must also create space for the matrix elements themselves using a double loop.

These last two examples illustrates the fact that since PARI types are recursive, all the branches of the tree must be created. The function <#1609#>cgetg<#1609#> creates only the ``root'', and other calls to <#1610#>cgetg<#1610#> must be made to get the whole tree. For matrices, a common mistake is to think that <#1611#>z = cgetg(4, 19)<#1611#> (for example) will create the root of the matrix: one needs also to create the column vectors of the matrix. This is because a matrix is really nothing else than a line vector of column vectors (hence a priori not a basic type), but it has been given a special type number so that operations with matrices become possible.

by 1=0 <#8970#>=0<#8972#><#8972#><#8970#>

<#8971#><#8973#>.. Implementation of the PARI types<#8973#><#8971#>.

Although it is a little tedious, we must go through each type and explain their implementation. Let z be a PARI object. Common to all the types is the first codeword (z[0]), which we don't have to worry about since this is taken care of by <#1613#>cgetg<#1613#>. However we need its precise description: the first byte is the <#8977#><#8977#>type number, the second byte is the <#8979#><#8979#>reference count (used only for garbage collecting purposes), and the last two bytes (the low order word if you prefer) is the <#8981#><#8981#>length of the root in longwords. For instance in the example <#1617#>z = cgeti(6)<#1617#> above, z[0] will be set to <#1618#>0x01010006<#1618#>.

These bytes can be handled through the following functions:

<#2838#>long <#8983#><#8983#>typ(GEN z);<#2838#> returns the type number of z.

<#2839#>void <#8985#><#8985#>settyp(GEN z, long n);<#2839#> sets equal to <#1621#>n<#1621#> the type number of z (you should not have to use this function if you use cgetg).

<#2840#>long <#8987#><#8987#>pere(GEN z);<#2840#> returns the reference count of z.

<#2841#>void <#8989#><#8989#>setpere(GEN z, long n);<#2841#> sets equal to <#1624#>n<#1624#> the reference count of z.

<#2842#>void <#8991#><#8991#>incpere(GEN z);<#2842#> increments the reference count of z (with saturation at 255).

<#2843#>long <#8993#><#8993#>lg(GEN z);<#2843#> returns the length (in longwords) of the root of z.

<#2844#>long <#8995#><#8995#>setlg(GEN z, long l);<#2844#> sets equal to <#1628#>l<#1628#> the length of z (you should not have to use this function if you use <#1629#>cgetg<#1629#>; however, see an example of the use of this function in the matexp function given in section 4.3).

Let us now look precisely at the types:

<#1630#>Type 1 (integers)<#1630#>: <#8997#><#8997#> this type has a second codeword z[1] which contains the following information. The first byte is the sign of z, i.e. 1 if z ;SPMgt; 0, 0 if z = 0, -1 if z ;SPMlt; 0. The second byte is unused. The low order word is the <#1632#>effective length<#1632#> of z, i.e. the total number of significant longwords. This means the following: apart from the integer 0 (whose second codeword is equal to 2), every integer is ``normalized'', meaning that the first mantissa longword (i.e. z[2]) is non zero. However, the integer may have been created with a longer length. Hence the ``length'' which is in z[0] can be larger than the ``effective length'' which is in z[1]. In fact, it would be a disaster to try to access z[i] for i larger than or equal to the effective length.

This information can be handled using the following functions:

<#2845#>long <#8999#><#8999#>signe(GEN z);<#2845#> returns the sign of z.

<#2846#>void <#9001#><#9001#>setsigne(GEN z, long s);<#2846#> sets equal to <#1635#>s<#1635#> the sign of z.

<#2847#>long <#9003#><#9003#>lgef(GEN z);<#2847#> returns the <#9005#><#9005#>effective length of z.

<#2848#>void <#9007#><#9007#>setlgef(GEN z, long l);<#2848#> sets equal to <#1639#>l<#1639#> the effective length of z.

The integer 0 can be characterized either by its sign equal to 0, or by its effective length equal to 2. Apart from z = 0, z[2] exists and is non zero, and the absolute value of z is (z[2],z[3],...,z[lgef(z)-1]) in base 232, where as usual in this notation z[2] is the high order longword.

<#1641#>Type 2 (real numbers)<#1641#>: <#9009#><#9009#> this type has a second codeword z[1] whose first byte is also the sign (obtained or set using the same functions as for the integers), but whose 3 low order bytes contains a biased binary exponent (i.e. the exponent plus 223). This exponent can be handled using the following functions:

<#2849#>long <#9011#><#9011#>expo(GEN z);<#2849#> returns the true (unbiased) exponent of z. This is defined even when z is equal to zero, see section 1.2.6.

Note also the function <#2850#>long <#9013#><#9013#>gexpo(GEN z)<#2850#> which tries to return an exponent for z even if z is not a real number.

<#2851#>void <#9015#><#9015#>setexpo(GEN z, long e);<#2851#> sets equal to <#1647#>e<#1647#> the exponent of z, of course after adding the bias.

The real zero is characterized by having its sign equal to 0. However, usually the first mantissa word z[2] is defined and equal to 0. This fact must <#1648#>never<#1648#> be used to characterize 0. If z is not equal to 0, the first mantissa word z[2] is normalized, i.e. its first bit is 1. The mantissa is (z[2],z[3],...,z[lg(z]-1]) in base 232 where z[2] is the most significant longword, and the mantissa is understood to be between 1 and 2. Thus the real number -3.5 is represented (if the length is 4) as <#1650#>0x02010004, 0xff800001, 0xe0000000, 0<#1650#>.

<#1651#>Type 3 (integermods)<#1651#>: <#9017#><#9017#> z[1] points to the modulus, and z[2] on the number representing the class z. Both must be of type integer. In principle z[1] ;SPMgt; 0 and 0 ;SPMlt; = z[2] ;SPMlt; z[1], but this rule does not have to be strictly obeyed by the user. Any integermod obtained after a PARI operation will in principle satisfy these conditions.

<#1653#>Types 4 and 5 (rational numbers)<#1653#>: <#9019#><#9019#> z[1] points to the numerator, and z[2] on the denominator. Both must be of type integer. In principle z[2] ;SPMgt; 0, but this rule does not have to be strictly obeyed either.

<#1655#>Type 6 (complex numbers)<#1655#>: <#9021#><#9021#>z[1] points on the real part, and z[2] on the imaginary part. A priori z[1] and z[2] can be of any type, but only certain types are useful and make sense.

<#1657#>Type 7 (p-adic numbers)<#1657#>: <#9023#><#9023#> this type has a second codeword z[1] which contains the following information: the first <#1659#>word<#1659#> contains the exponent of p modulo which the p-adic unit corresponding to z is defined (if z is not 0), i.e. one less than the number of significant p-adic digits. the second word contains the biased exponent of z (the bias being here equal to 215). This information can be handled using the following functions:

<#2852#>long <#9025#><#9025#>precp(GEN z);<#2852#> returns the p-adic precision of z, i.e. one less than the number of significant p-adic digits.

<#2853#>void <#9027#><#9027#>setprecp(GEN z, long l);<#2853#> sets equal to <#1663#>l<#1663#> the p-adic precision of z.

<#2854#>long <#9029#><#9029#>valp(GEN z);<#2854#> returns the p-adic valuation of z (i.e. the unbiased exponent). This is defined even if z is equal to 0, see section 1.2.6.

<#2855#>void <#9031#><#9031#>setvalp(GEN z, long e);<#2855#> sets equal to <#1666#>e<#1666#> the p-adic valuation of z.

In addition to this codeword, z[2] points to the prime p, z[3] points to #math739#pprecp(z), and z[4] points to an integer representing the p-adic unit associated to z modulo z[3] (or points to zero if z is zero). To summarize, we have the equality:

#math740#

z = pvalp(z)*(z[4] + O(z[3])) = pvalp(z)*(z[4] + O(pprecp(z)))

<#1671#>Type 8 (quadratic numbers)<#1671#>: <#9037#><#9037#> z[1] points on the polynomial defining the quadratic field, z[2] on the ``real part'' and z[3] on the ``imaginary part'', where this is to be taken as the coefficients of z on the ``canonical'' basis (1,w) (see section 1.2.3). Complex numbers are particular cases of quadratics but deserve a separate type.

<#1673#>Type 9 (polymods)<#1673#>: <#9039#><#9039#> exactly as for integermods, z[1] points on the modulus, and z[2] on a polynomial representing the class of z. Both must be of type polynomial. However, one must obey the rules explained in chapter 2 concerning the hierarchical structure of the variables of a polymod.

<#1675#>Type 10 (polynomials)<#1675#>: <#9041#><#9041#> this type has a second codeword which is analogous to the one for integers. The first byte is the ``sign'', i.e. 0 if the polynomial is equal to 0, and 1 if not (see however the important remark below). The second byte is the variable number (e.g. 0 for X, 1 for Y, etc...). This number can be handled with the following functions:

<#2860#>long <#9043#><#9043#>varn(GEN z);<#2860#> returns the variable number of the object z.

Note also the function <#2861#>long <#9045#><#9045#>gvar(GEN z)<#2861#> which tries to return a variable number for z, even if z is not a polynomial or power series. The variable number of a scalar type is set by definition equal to 32767.

<#2862#>void <#9047#><#9047#>setvarn(GEN z,long v);<#2862#> sets equal to <#1680#>v<#1680#> the variable number of z.

The least significant word of the second codeword is the effective length of the polynomial. Note that the degree of the polynomial is equal to the effective length minus three. The functions used to handle this codeword are the same as for integers. The components z[2], z[3],...z[lgef(z)-1] point to the coefficients of the polynomial <#1681#>in ascending order<#1681#>, with z[2] being the constant term and so on.

<#1682#>Important remark<#1682#>. A zero polynomial can be characterized by the fact that its sign is 0. However, its effective length may be equal to 2, or greater than 2. If it is greater than 2, this means that all the coefficients of the polynomial are equal to zero (as they should for a zero polynomial), but not all of these zeros are exact zeros, and more precisely the leading term z[lgef(z)-1] is not an exact zero.

<#1683#>Type 11 (power series)<#1683#>: <#9049#><#9049#> This type also has a second codeword. Its first byte is the ``sign'', i.e. 0 if the power series is 0, and 1 if not. The second byte is the variable number, as for polynomials. The last two bytes code for a biased exponent with a bias of 215. This information can be handled with the following functions:

<#2863#><#9051#><#9051#>signe, <#9053#><#9053#>setsigne, <#9055#><#9055#>varn, <#9057#><#9057#>setvarn<#2863#> as for polynomials, and <#2864#><#9059#><#9059#>valp, <#9061#><#9061#>setvalp<#2864#> for the exponent. Beware not to use <#1692#>expo<#1692#> and <#1693#>setexpo<#1693#> for power series.

If the power series is non zero, z[2], z[3],...z[lg(z)-1] point to the coefficients of z in ascending order, z[2] being the first non-zero coefficient. Note that the exponent of a power series can be negative, i.e. we can deal with Laurent series with a finite number of negative terms.

<#1694#>Types 13 and 14 (rational functions)<#1694#>: <#9063#><#9063#> z[1] points on the numerator, and z[2] on the denominator. Both must be of type polynomial.

<#1696#>Type 16 (binary quadratic forms)<#1696#>: <#9065#><#9065#> z[1], z[2], z[3] point on the three coefficients of the form. All three should be of type integer.

<#1698#>Types 17 and 18 (vectors)<#1698#>: <#9067#><#9067#><#9069#><#9069#> z[1], z[2],...z[lg(z)-1] point on the components of the vector.

<#1701#>Type 19 (matrices)<#1701#>: <#9071#><#9071#> z[1], z[2],...z[lg(z)-1] point on the column vectors of z, i.e. they must be of type 18 and of the same length.

by 1=0 <#9073#>=0<#9075#><#9075#><#9073#>

<#9074#><#9076#>.. Assignment and copying of PARI objects<#9076#><#9074#>.

The general <#9080#><#9080#>assignment function is the function <#2865#><#9082#><#9082#>gaffect<#2865#> with the following syntax:

<#1706#>void gaffect(GEN x, GEN y);<#1706#>

Its effect is to assign the PARI object x into the (preexisting) object y. Many conditions must be met for the assignment to be possible. For instance it is allowed to assign an integer into a real number, but the converse is forbidden. For that, you must use the truncation or rounding function of your choice (see section 3.2). It can also happen that y is not large enough or does not have the proper tree structure to receive the object x. As an extreme example, assume y is the zero integer with length equal to 2. Then all assignments of a non zero integer into y will result in an error message since y is not large enough to fit a non zero integer. In general common sense will tell you what is possible, keeping in mind the PARI philosophy which says that if it makes sense it is legal (the assignment of an imprecise object into a precise one does <#1707#>not<#1707#> make sense. However, a change in precision of imprecise objects is allowed).

It is also necessary to assign ordinary 32-bit long numbers of C into a PARI object. This is done using the function <#2866#><#9084#><#9084#>gaffsg<#2866#> with the following syntax:

<#1709#>void gaffsg(long s, GEN y);<#1709#>

It is also very useful to copy a PARI object, not just by moving around a pointer, but by physically creating a copy of the whole tree structure. The function which does this is called <#2867#><#9086#><#9086#>gcopy<#2867#>, with the predefined macro <#2868#><#9088#><#9088#>lcopy<#2868#> as a synonym for <#1712#>(long)gcopy<#1712#>. Its syntax is:

<#1713#>GEN gcopy(GEN x);<#1713#>

and the effect is to create a new copy of x on the PARI stack.

However, it may also be useful to create a <#1714#>permanent<#1714#> copy of a PARI object. This will not be created on the stack but on the heap. The function which does this is called <#2869#><#9090#><#9090#>gclone<#2869#>, with the predefined macro <#2870#><#9092#><#9092#>lclone<#2870#> as a synonym for <#1717#>(long)gclone<#1717#>. Its syntax is:

<#1718#>GEN gclone(GEN x);<#1718#>

A final class of functions should be mentioned in this subsection: functions which convert from C objects to PARI objects (with creation of the objects on the stack). They are as follows:

<#2871#>GEN <#9094#><#9094#>stoi(long s);

GEN <#9096#><#9096#>dbltor(double s);<#2871#>

Their meaning is clear from their names. The converse functions

<#2872#>long <#9098#><#9098#>gtolong(GEN z);

double <#9100#><#9100#>gtodouble(GEN z);<#2872#>

also exist, but are seldom used.

by 1=0 <#9102#>=0<#9104#><#9104#><#9102#>

<#9103#><#9105#>.. Destruction of PARI objects and garbage collection<#9105#><#9103#>.

If you want to destroy (i.e. give back the memory occupied by) the latest PARI object on the stack (e.g. the latest one obtained by a cgetg or a function), this is very simple: just use the function <#2873#><#9109#><#9109#>cgiv<#2873#> with the syntax:<#9111#><#9111#>

<#1726#>void cgiv(z);<#1726#>

where z is the object (which can be a tree), which you want to give back. Unfortunately life is not so simple, and in general you are doing a computation and want to give back accumulated garbage. A simple example is the following.

Let x and y be two preexisting PARI objects and suppose that we want to compute x*x+y*y. This can trivially be done using the following program (we skip the necessary declarations):

<#1727#>p1=gmul(x,x);p2=gmul(y,y);z=gadd(p1,p2);<#1727#>

The GEN z will indeed point on the PARI object equal to x*x+y*y. However, consider the stack. It contains as unnecessary garbage p1 and p2. More precisely it contains (in that order) z, p1, p2. We need a way to get rid of this garbage (in this case it causes no harm except that it occupies memory space, but in other cases it could disconnect PARI objects and this is forbidden). It would not have been possible to get rid of p1, p2 before since they are used in the final operation. It is not possible to use the function <#1728#>cgiv<#1728#> since p1 and p2 are not at the bottom of the stack. Hence PARI provides us with a much more powerful tool whose correct handling is not always easy: the function <#2874#><#9113#><#9113#>gerepile<#2874#> (with the macro <#2875#><#9115#><#9115#>lpile<#2875#> as a synonym to <#1731#>(long)gerepile<#1731#>). This function has the following syntax:

<#1732#>GEN gerepile(long ltop, long lbot, GEN z);<#1732#>

The understanding of the behavior of this function is certainly the most difficult part of this chapter, hence we will try to go slowly in the explanation.

First, the PARI stack has a current stack pointer which is a global variable (hence must not be declared in a program) called <#2876#><#9117#><#9117#>avma<#2876#> (which stands for <#1734#>av<#1734#>ailable <#1735#>m<#1735#>emory <#1736#>a<#1736#>ddress, which as its name indicates points always just after the first free address on the stack (remember that the stack grows from high to low addresses). For certain reasons this variable is of type long and not of type GEN as would be natural.

Now let us see the effects of the function <#1737#>gerepile<#1737#>. For this function to work one must have lbot ;SPMlt; ltop. As a first approximation, we describe the effects of this function as follows. Give back the memory locations between lbot and ltop, and move the object z upwards so that no space is lost. Specifically, we rewrite our previous example as follows:

<#2877#><#1738#><#1738#> ltop=avma; /* keep in mind the current address of the top of the stack */ p1=gmul(x,x); p2=gmul(y,y); lbot=avma; /* keep the address of the bottom of the garbage pile */ z=gadd(p1,p2); z=gerepile(ltop,lbot,z); /* do the garbage collecting */<#2877#>

The last two instructions could also have been written more simply:

<#1739#>z=gerepile(ltop,lbot,gadd(p1,p2));<#1739#>

As you can see, in simple conditions the use of <#1740#>gerepile<#1740#> is not really difficult. However it is absolutely necessary to understand what has happened. When entering an instruction such as <#1741#>gerepile(ltop,lbot,z)<#1741#>, we must have avma ;SPMlt; = lbot ;SPMlt; ltop. As we will see, the variable z is in fact used very little. The function then considers all the PARI objects between avma and lbot (i.e. the ones that we want to keep) and looks at every component of such an object which is not a codeword. This component is a pointer on an object whose address is either between avma and lbot, in which case it will be suitably updated, larger than or equal to ltop, in which case it will not change, or between lbot and ltop in which case <#1742#>gerepile<#1742#> will scream an error message at you. If all goes well, the pointers are suitably updated, the chunk of memory from avma to lbot-1 is physically copied to addresses avma+ltop-lbot to ltop-1, avma is updated (to the value avma+ltop-lbot), and finally the displacement ltop-lbot is added to z and given as a result of the function. In addition, if z is not 0 (in the sense of being address 0), the PARI object pointed to by ltop is checked to see whether certain of its pointers need also to be updated. This is a horrible hack which should not be used.

<#1743#>Important remark<#1743#>: as we will see presently it is often necessary to do several <#1744#>gerepile<#1744#> in a computation. However, the least the better. The only condition for <#1745#>gerepile<#1745#> to work is that the garbage be connected. If the computation can be arranged so that there is a minimal number of connected pieces of garbage then it should be done.

For example suppose we want to write a function of two GEN variables x and y which creates the vector [x*x+y,y*y+x]. Without garbage collecting, one would write:

<#2878#><#1746#><#1746#> p1=gmul(x,x);p2=gadd(p1,y);p3=gmul(y,y);p4=gadd(p3,x); z=cgetg(3,17);z[1]=(long)p2;z[2]=(long)p4;<#2878#>

This leaves a dirty stack with (in that order) z,p4,p3,p2,p1 and p1 and p3 being garbage. But if we compute p3 <#1747#>before <#1747#> p2 then the garbage becomes connected and we get the following program with garbage collecting:

<#2879#><#1748#><#1748#> ltop=avma;p1=gmul(x,x);p3=gmul(y,y);lbot=avma; z=cgetg(3,17);z[1]=ladd(p1,y);z[2]=ladd(p3,x); z=gerepile(ltop,lbot,z);<#2879#>

We take our next example directly from the implementation of <#1749#>gmul<#1749#> in the file <#1750#>gen2.c<#1750#>, case 6 times case 6. In other words we want to write a program to compute the product of two complex numbers x and y, using a method which takes only 3 multiplications instead of 4. Let z=x*y, and set x=xr+i*xi and similarly for y and z. The well known trick is to compute p1=xr*yr, p2=xi*yi, p3=(xr+xi)*(yr+yi), and then we have zr=p1-p2, zi=p3-p1-p2. The program is essentially as follows:

<#2880#><#1751#><#1751#> ltop=avma;p1=gmul(x[1],y[1]);p2=gmul(x[2],y[2]); p3=gmul(gadd(x[1],x[2]),gadd(y[1],y[2]));p4=gadd(p1,p2);lbot=avma; z=cgetg(3,6);z[1]=lsub(p1,p2);z[2]=lsub(p3,p4); z=gerepile(ltop,lbot,z);<#2880#>

Let us now look at a less trivial example where more than one <#1752#>gerepile<#1752#> is needed in practice (in theory one can always use only one, see below, but generally at the expense of efficiency). Suppose for instance that we want to write a function which multiplies a line vector by a matrix (such a function is of course already part of <#1753#>gmul<#1753#>, but let's ignore this for a moment). Then the most natural way is to do a <#1754#>cgetg<#1754#> of the result immediately, and then for each coefficient of the result vector to do a <#1755#>gerepile<#1755#> to get rid of the garbage which has accumulated for that particular coefficient. We leave the details to the reader, who can look at the answer in the file gen2.c, in the function gmul, case 17 times case 19. As was said above, it would theoretically be possible to have a single connected piece of garbage, but it would be a much less natural and unnecessarily complicated program.

Finally, let us take an example which is probably the least trivial way of using <#1756#>gerepile<#1756#>, but is unfortunately sometimes necessary. Although it is not an infrequent occurrence, we will not give a specific example but a general one. Suppose that we want to do a computation (usually inside a larger function) giving more than one PARI object as a result, say two for instance. Then even if we set up the work properly, before cleaning up we will have a stack which has the desired results z1, z2 (say), and then connected garbage from lbot to ltop. If we write

<#1757#>z1=gerepile(ltop,lbot,z1);<#1757#>

then the stack will be cleaned, the pointers OK, but we will have lost the address of z2. Hence the best way in this case is to write the following, assuming that <#1758#>dec<#1758#> has been declared as a long and not as a GEN:

<#1759#>dec=lpile(ltop,lbot,0)/4;z1+=dec;z2+=dec;<#1759#>

This works because <#1760#>gerepile<#1760#> thinks that 0 is a valid address, hence puts in <#1761#>dec<#1761#> the displacement in bytes. Since z1 and z2 are pointers, we need to divide <#1762#>dec<#1762#> by 4 to get a longword displacement.

If you followed us this far, congratulations, and rejoice, the rest is much easier.

by 1=0 <#9119#>=0<#9121#><#9121#><#9119#>

<#9120#><#9122#>.. Some tricks and hints<#9122#><#9120#>. Even for the authors, the use of <#1764#>gerepile<#1764#> was not evident at first. Hence we give some indications on how to avoid most problems connected with <#1765#>gerepile<#1765#>, at the expense of speed.

First, although it looks complicated, <#1766#>gerepile<#1766#> has turned out to be a very flexible and fast garbage collector, which can compare very favorably with much more sophisticated methods used in other systems. A few tests that we have made indicate that the price paid for using <#1767#>gerepile<#1767#> is never more than 10 percent, and usually around 5 or 6 percent of the total time, which is quite acceptable.

Second, in many cases, in particular when the tree structure and the size of the PARI objects which will appear in a computation are under control, one can avoid <#1768#>gerepile<#1768#> altogether by creating sufficiently large objects at the beginning (using <#1769#>cgetg<#1769#>), and then using assignment statements and operations ending with z (such as <#1770#>gaddz<#1770#>). Coming back to our first example, note that if we know that x and y are of type real and of length less than or equal to 5, we can program without using <#1771#>gerepile<#1771#> at all:

<#1772#>z=cgetr(5);ltop=avma;p1=gmul(x,x);p2=gmul(y,y);gaddz(p1,p2,z);avma=ltop;<#1772#>

Here the cleaning up is done using the simple assignment avma=ltop which takes essentially no time at all.

Third, the philosophy of <#1773#>gerepile<#1773#> is the following: keep the value of the stack pointer avma at the beginning, and just <#1774#>before<#1774#> the last operation. Afterwards, it would be too late since the garbage address would be lost.

Finally, if everything seems hopeless, at the expense of speed you can do the following: after keeping in ltop the value of avma, perform your computation as you wish, in any order, leaving a messy stack. Let z be your result (let's assume you have only one. If you have more than one, you can always create a vector which is a single PARI object whose components are your results; after all, we are already cheating, we can cheat some more). Then write the following:

<#1775#>lbot=avma;z=gerepile(ltop,lbot,gcopy(z));<#1775#>

The trick is to force a copy of z at the bottom of the stack, hence all the rest including the initial z becomes connected garbage. Note that this may not work in some cases where you have created new universal objects between lbot and ltop, for instance moduli for mod p or p-adic computations. In that case you must also copy these objects on top of the stack and modify the components of your results which point to these objects. This in fact involves rewriting a simplified version of a part of <#1776#>gerepile<#1776#>, hence is not recommended. If you are in this situation and still want to use this trick, we strongly advise you to create all your new universal objects before starting your computation, hence before the instruction <#1777#>ltop=avma;<#1777#>. Then you should have no problems.

Another solution is to use clones, i.e. the function <#1778#>gclone<#1778#> (see 4.2.3), which creates a permanent object on the heap, and not on the stack.

by1=0 <#9126#>=0<#9128#><#9128#><#9126#>



<#9127#><#9129#>. A complete program.<#9129#><#9127#>


Now that the preliminaries are out of the way, the best way to learn how to use the library mode is to work through a detailed nontrivial example of a main program. We will write a program which computes the exponential of a square matrix x. The complete listing is given in Appendix C, but each part of the program will be written and commented here. We will use an algorithm which is not optimal but is not far from the one used for the PARI function <#1780#>gexp<#1780#> (in fact in the function <#1781#>mpexp1<#1781#>). This consists in calculating the sum of the series:

#math741#

ex/(2n) = #tex2html_wrap_indisplay28041##tex2html_wrap_indisplay28042#

for a suitable positive integer n, and then computing ex by repeated squarings. First, we will need to compute the L2-norm of the matrix x, i.e. the quantity:

#math742#

z = | x|2 = #tex2html_wrap_indisplay28048#.

We will then choose the integer n such that the L2-norm of x/(2n) is less than or equal to 1, i.e.

#math743#

n = #tex2html_wrap_indisplay28053##tex2html_wrap_indisplay28054##tex2html_wrap_indisplay28055#

if z ;SPMgt; = 1. Then the convergence of the series will be at least as good as the one for e1, and will be easy to estimate. In fact a larger value of n would be preferable, but this is slightly machine dependent and more complicated, and will be left to the reader.

We will now start writing our program. So as to be able to use it in other contexts, we will structure it in the following way: a main program which will do the input and output, and a function which we shall call <#1790#>matexp<#1790#> which does the real work. The main program is easy to write. It can be something like this:

<#2882#><#1791#><#1791#> #include ;SPMlt;genpari.h;SPMgt; GEN matexp(); <#1792#><#1792#> main() { ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;GEN x,y; ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;long prec,d; ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;char s[512]; <#1793#><#1793#> ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;init(1000000,2); /* take a million bytes of memory for the stack */ ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;printf(;SPMquot;precision of the computation in decimal digits? ;SPMquot;); ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;scanf(;SPMquot;d;SPMquot;,d);if(d;SPMlt;0) prec=3;else prec=d*K1+3; ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;printf(;SPMquot;input your matrix in GP format:#math744#\n;SPMquot;); ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;s[0]=0;while(!s[0]) gets(s);x=lisexpr(s); ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;y=matexp(x,prec); ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;sor(y,'g',d,0); }<#2882#>

The variable <#1794#>prec<#1794#> represents the length in longwords of the real numbers used. K1 is the constant (defined in <#1795#>gencom.h<#1795#>) equal to #math745#ln(10)/(32*ln(2)), which allows us to convert from a number of decimal digits to a number of longwords. The function <#1796#>lisexpr<#1796#> was mentioned earlier and avoids any trouble in the input. In fact, as was also mentioned, <#1797#>lisexpr<#1797#> can take any legal GP expression hence can do not only input but also computations. Note that we have used the construction <#1798#>s[0]=0;while(!s[0]) gets(s);<#1798#> to get our string, instead of <#1799#>scanf<#1799#> which would make trouble in this case.

Finally, <#1800#>sor<#1800#> is the general output routine. We have chosen to give d significant digits since this is what was asked. Note that there is a trick hidden here: if d was given to be negative, then the computation will be done in precision 3 (i.e. about 9.7 decimal digits) and in the function <#1801#>sor<#1801#>, giving a negative third argument outputs all the significant digits, hence nothing is wrong.

Now let us attack the main course, the function matexp:

<#2883#><#1802#><#1802#> GEN matexp(x,prec) ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;GEN x; ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;long prec; <#1803#><#1803#> { ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;GEN y,r,s,p1,p2; ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;long tx=typ(x),lx=lg(x),i,k,n,lbot,ltop; <#1804#><#1804#> /* check that x is a square matrix */ <#1805#><#1805#> ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;if(tx!=19) {printf(;SPMquot;This expression is not a matrix#math746#\n;SPMquot;);return(gzero);} ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;if(lx!=lg(x[1])) {printf(;SPMquot;This matrix is not square#math747#\n;SPMquot;);return(gzero);} <#1806#><#1806#> /* compute the L2 norm of x */ <#1807#><#1807#> ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;ltop=avma;s=gzero; ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;for(i=1;i;SPMlt;lx;i++) s=gadd(s,gnorml2(x[i])); ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;if(typ(s)==2) setlg(s,3); ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;s=gsqrt(s,3); /* we do not need much precision on s */ <#1808#><#1808#> /* if s;SPMlt;1, we are happy */ <#1809#><#1809#> ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;if(expo(s);SPMlt;0) {n=0;p1=x;} ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;else {n=expo(s)+1;p1=gmul2n(x,-n);s=gmul2n(s,-n);}<#2883#>

Before continuing, a few remarks are in order. First, after printing an error message we need to return a GEN value otherwise a fussy compiler will complain. Hence we return gzero, which in any case is an impossible result for an exponential.

Second, to compute the square of the L2-norm of x we just add the squares of the L2-norms of the column vectors which we obtain using the library function <#1810#>gnorml2<#1810#>. Had this function not existed, it would of course have been just as easy, but we would have had to make a double loop. Then, we take the square root of s, in precision 3. For that we use the function <#1811#>setlg<#1811#> which tells s to be in such a precision, only if s is of type real. Note that the matrix x is allowed to have complex entries, but the function <#1812#>gnorml2<#1812#> guarantees that s is a nonnegative number of type real. If we had not known this fact, we would simply have added the instruction <#1813#>s = greal(s);<#1813#> just after the <#1814#>for<#1814#> loop.

Third, before starting this computation which will produce garbage on the stack, we have carefully kept the value of the stack pointer avma in ltop. Note that we are going to assume throughout that the garbage does not overflow the memory that we allocated on the stack. If it did, we would have two solutions. Either allocate more memory in the main program (for instance change 1000000 into 2000000), or do some <#1815#>gerepile<#1815#> along the way.

Fourth, note that we initialized the sum <#1816#>s<#1816#> to gzero, which is an exact zero. This is logical, but has some disadvantages: if all the entries of the matrix are integers (or rational numbers), the computation will be rather long, about twice as long as with real numbers of the same length. It would be better to initialize <#1817#>s<#1817#> to a real zero, using for instance the instructions:

<#1818#>s=cgetr(prec+1);gaffsg(0,s);<#1818#>.

However, this would not make much sense. In fact you should avoid making an assignment of an exact zero (essentially the integer zero) into a real number: which real zero is it going to give as a result? In fact a choice has been made, and it will give you the zero with exponent equal to -32 times the number of longwords in the mantissa, but this is not really satisfactory. Perhaps PARI should give an error message in that case, or at least a warning.

Fifth, we will want to look at the approximate size of real numbers, and the fastest way to do this is to look at their binary exponents. Hence we need to have <#1819#>s<#1819#> as a real number, and not as an integer or a rational number. This is done automatically when we take the square root.

Finally, note the use of the function <#2884#><#9138#><#9138#>gmul2n<#2884#>. This function has the following syntax:

<#1821#>GEN gmul2n(GEN x,long n);<#1821#>

The effect is simply to multiply <#1822#>x<#1822#> by #math748#2n, where <#1824#>n<#1824#> can be positive or negative. This is much faster than gmul or gmulgs. Note that since n=expo(s)+1, the last gmul2n call could be replaced by <#1825#>setexpo(s,-1);<#1825#>.

There is another function <#2885#><#9141#><#9141#>gshift<#2885#> with exactly the same syntax. When <#1827#>n<#1827#> is nonnegative, the effects of these two functions is the same. However when <#1828#>n<#1828#> is negative, gshift acts like a right shift of <#1829#>-n<#1829#>, hence does not give the same effect on integers. The function gshift is the PARI analogue of the C operators <#1830#>;SPMlt;;SPMlt;<#1830#> and <#1831#>;SPMgt;;SPMgt;<#1831#>.

We now come to the heart of the function. We have now a GEN p1 which points to a certain matrix of which we want to take the exponential. We will want to transform this matrix into a matrix with real (or complex of real) entries before starting the computation. To do this, we simply multiply by the real number 1 in precision prec+1 (to be safe). Then, to compute the series we will keep three variables: a variable p2 which at stage k will contain #math749##tex2html_wrap_inline28082#/k!, a variable y which will contain #math750##tex2html_wrap_inline28084##tex2html_wrap_inline28087#/i!, and the variable r which will contain #math751##tex2html_wrap_inline28091#/k!. Note that we do not use Horner's rule. This is simply because we are lazy and do not want to compute in advance the number of terms that we need. We leave this modification (and many other improvements!) to the reader. The program continues as follows:

<#2964#><#1836#><#1836#> /* initializations before the loop */ <#1837#><#1837#> ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;r=cgetr(prec+1);gaffsg(1,r);p1=gmul(r,p1); ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;y=gscalmat(r,lx-1); /* this creates the scalar matrix r#math752#*#tex2html_wrap_inline28093# */ ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;p2=p1;r=s;k=1; ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;y=gadd(y,p2); <#1839#><#1839#> /* now the main loop */ <#1840#><#1840#> ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;while(expo(r) ;SPMgt;= -32*(prec-1)) ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;{k++;p2=gdivgs(gmul(p2,p1),k);r=gdivgs(gmul(s,r),k);y=gadd(y,p2);} <#1841#><#1841#> /* now square back n times if necessary */ <#1842#><#1842#> ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;if(!n){lbot=avma;y=gerepile(ltop,lbot,gcopy(y));} ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;else ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;{ ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;for(i=0;i;SPMlt;n;i++){lbot=avma;y=gmul(y,y);} ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;y=gerepile(ltop,lbot,y); ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;} ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;return(y); }<#2964#>

A few remarks once again. First note the use of the function <#2887#><#9144#><#9144#>gscalmat<#2887#> with the following syntax:

<#1844#>GEN gscalmat(GEN x, long l);<#1844#>

The effect of this function is to create the #math753##tex2html_wrap_inline28104#×#tex2html_wrap_inline28105# scalar matrix whose diagonal entries is the GEN x. Hence the length of the matrix including the codeword will in fact be <#1847#>l+1<#1847#>. There is a corresponding function <#2888#><#9146#><#9146#>gscalsmat<#2888#> which takes a long as a first argument.

If we refer to what has been said above, the main loop is clear.

When we do the final squarings, according to the fundamental theorem on the use of <#1849#>gerepile<#1849#> we keep the value of avma in lbot just <#1850#>before<#1850#> the squaring, so that if it is the last one, lbot will indeed be the bottom address of the garbage pile, and <#1851#>gerepile<#1851#> will work. Note that it takes a completely negligible time to do this in each loop compared to a matrix squaring. However, when n is initially equal to 0, no squarings have to be done, and we have our final result ready but we lost the address of the bottom of the garbage pile. Hence we use the trick of copying y again on top of the stack. This is inefficient, but does the work. If we wanted to avoid this, the best thing to do would be to put the instruction <#1852#>lbot=avma<#1852#> just before both occurrences of the instruction <#1853#>y=gadd(p2,y);<#1853#>.

Remarks on the program: as such, the program should work most of the time if x is a square matrix with real or complex entries. Indeed, since essentially the first thing that we do is to multiply by the real number 1, the program should work for integer, real, rational, complex or quadratic entries. This is in accordance with the behavior of transcendental functions.

Furthermore, since this program is intended to be only an illustrative example, it has been written a little sloppily. In particular many error checks have been omitted, and the efficiency is far from optimal. An evident improvement is to avoid the unnecessary gcopy by inserting a couple of extra <#1854#>lbot=avma;<#1854#> instructions. Another improvement is to multiply the matrix x by the real number 1 right at the beginning, speeding up the computation of the L2-norm in many cases. These improvements are included in the version given in Appendix C. Still another improvement would come from a better choice of n. If the reader takes a look at the implementation of the function <#2889#><#9148#><#9148#>mpexp1<#2889#> in the file trans1.c he can make himself the necessary changes. Finally, there exist other algorithms of a different nature to compute the exponential of a matrix.


<#1856#>Remark<#1856#>: While writing this program, we have seen a few new functions (the complete list of available functions is given by alphabetical order in the index). However, if you care to look at the file <#1857#>gencom.h<#1857#>, you will notice that many more functions are defined. But in every case these missing functions are particular cases of general functions. For example, we have the function <#1858#>gneg<#1858#>, which takes the negative of a PARI object. However, there also exist functions like <#1859#>negi<#1859#> (for type integer), <#1860#>negr<#1860#> (for type real), and <#1861#>mpneg<#1861#> (for type integer or real).

These functions can of course be called by the user but we feel that the few microseconds lost in calling more general functions (in this case <#1862#>gneg<#1862#>) is compensated by the fact that one needs to remember a much smaller number of functions, and also because there is a hidden danger here: the type of the objects that you use, if they are themselves results of a previous computation, is not completely predetermined. For instance the multiplication of a type real by a type integer <#1863#>usually<#1863#> gives a result of type real, except when the integer is 0, in which case according to the PARI philosophy the result is the exact integer 0. Hence if afterwards you call a function which specifically needs a real type argument, you are in trouble.

If you really want to use these functions, their names are self-explanatory once you know that <#1864#>i<#1864#> stands for a PARI integer, <#1865#>r<#1865#> for a PARI real, <#1866#>mp<#1866#> for i or r, <#1867#>s<#1867#> for an ordinary 32-bit signed long, <#1868#>z<#1868#> (as a suffix) meaning as usual that the result is not created on the PARI stack but assigned to a preexisting GEN given as an extra argument.

For completeness, in Chapter 5 we have given a description of all these low-level functions.

Please note that in the present version 1.37the names of the functions are not always consistent. This will be changed. Hence anyone programming in PARI must be aware that the names of almost all functions that he uses will change eventually. If the need arises (i.e. if there really are people out there who delve into the innards of PARI), updated versions with no name changes will be released.

by1=0 <#9150#>=0<#9152#><#9152#><#9150#>



<#9151#><#9153#>. Adding functions to PARI.<#9153#><#9151#>


As already mentioned, modified versions of the PARI package should NOT be spread without our prior approval. If you do modify PARI, however, it is certainly for a good reason, hence we would like to know about it, so that everyone can benefit from it. There is then a good chance that the modifications that you have made will be incorporated into the next release.

(Recall the e-mail: <#1870#>pari@alioth.greco-prog.fr<#1870#>).

Roughly 3 types of modifications can be made. The first type is to modify the code, include files and the Makefile so that compilation is possible on a new system.

The second type is to modify existing code, either to correct bugs, to add new functionalities, or to improve efficiency.

Finally the third type is to add new functions to Pari. We explain here how to do this, so that in particular the new function can be called from GP.

First choose the appropriate file where you are going to code your function. For example alglin1.c or alglin2.c if it is a function dealing with vectors or matrices (linear algebra), trans1.c, trans2.c, trans3.c if it is a transcendental function, arith1.c or arith2.c if it is an arithmetic function, bibli1.c or bibli2.c for miscellaneous functions, etc... Note that the files gp.c, mp.c and versionXXX.c as well as the assembly files have a special role and should not be modified.

Then code your function, using as a guide other functions in the Pari sources. One important thing to remember is to always clean the stack before exiting your function (usually using the function <#1871#>gerepile<#1871#>) otherwise the successive calls to the function will clutter the stack with unnecessary garbage and stack overflow will occur sooner.

If error messages are to be generated in your function, use the general error handling routine <#1872#>err<#1872#>. Initially, use the syntax

<#1873#>err(talker,"error message");<#1873#>

where <#1874#>error message<#1874#> is the message that you want printed. This function does not return, but ends with a <#1875#>longjmp<#1875#> statement.

Once the program is debugged, you can replace the above line by

<#1876#>err(errornumber);<#1876#>

where errornumber must be defined in the file <#1877#>erreurs.h<#1877#>, and the corresponding error message must be placed at the corresponding spot in the file <#1878#>errmessages.c<#1878#>. A look at these two files will tell you exactly what to do. Note however that to have the correct numbering of errors once again, hence the correct error messages, you must recompile the complete Pari distribution (for example after <#1879#>touch *.[chs]<#1879#>). This is not necessary if you use the <#1880#>talker<#1880#> syntax.

Finally, find the correct place in the file <#1881#>gencom.h<#1881#> to declare your function so that it is known to all other files and functions.

Your function is now ready to be used in library mode after compilation and creation of the library. It is however still inaccessible from GP.

To make your function accessible to GP, you must do the following. First, find a name for your function under GP, which does not have to be identical to the one used in library mode, but must use only lower case alphabetic characters and digits, the first character as usual being alphabetic. Then in the file <#1882#>anal.c<#1882#> place in exact alphabetical order of the name that you want to use under GP the following line (note that digits;SPMlt;letters):

<#1883#>{"gpname",V,(void*)libname,0},<#1883#>

where <#1884#>libname<#1884#> is the name of your function in library mode, <#1885#>gpname<#1885#> the name that you have chosen to call it under GP, and V is a number between 0 and 99, chosen so as to correspond to the type of the function and its arguments. The first digit identifies the number of arguments, not counting the variable <#1886#>prec<#1886#>.

The most common values for V are the following, expressed as C-function prototypes. You can find the others by looking at the function <#1887#>identifier<#1887#> in the file <#1888#>anal.c<#1888#>. Note that the parameter <#1889#>prec<#1889#> (which denotes the real precision) is included in most of the given prototypes, but can be omitted if the function does not use it. Note also that we implicitly identify <#1890#>int<#1890#> with <#1891#>long<#1891#>.

<#1892#> V=0: GEN name(long prec); V=1: GEN name(GEN x, long prec); V=2: GEN name(GEN x, GEN y, long prec); V=3: GEN name(GEN x, GEN y, GEN z, long prec); V=10: long name(GEN x); V=11: GEN name(long x,long prec); V=15: long name(long x); V=20: long name(GEN x, GEN y); V=23: GEN name(GEN x, long y, long prec); V=24: GEN name(long x, GEN y, long prec); V=29: long name(GEN x, long y); V=30: long name(GEN x, GEN y, GEN z); V=32: GEN name(GEN x, GEN y, long z); V=33: GEN name(GEN x, long y, long z); V=35: GEN name(long x, GEN y, GEN z); <#1892#>

If your function does not correspond to any of the above prototypes, or to the few others which you can find in the function <#1893#>identifier<#1893#>, you can make up your own. The best at this point is to read the code for the existing values of V, and to modify it according to your needs. One important point must be stressed if you add a value of V to the function <#1894#>identifier<#1894#>: you must also correspondingly add it to the function <#1895#>skipidentifier<#1895#>. Read the code for that function to see how to proceed.

Once this has been done, in the file <#1896#>helpmessages.c<#1896#> write in exact alphabetical order a short message describing the effect of your function:

<#1897#>"name(x,y,...)=short descriptive message",<#1897#>

The message must be a single line (which may have more than 80 characters). If the printed message would be more than one line, insert <#1898#>\n<#1898#> as appropriate (see the other messages for comparative purposes).

Finally create (or append to) a file called, say, <#1899#>Mychanges<#1899#>, which lists the modifications that you have made. Never touch the file <#1900#>Changes<#1900#> itself otherwise you would corrupt the Pari distribution. After compiling and debugging, you now have a new function available under GP (and we would very much like to hear about it!).

by1=0 <#9156#><#9156#> <#9157#>=0<#9159#><#9159#><#9157#>

Chapter : Technical reference guide for low-level functions

In this chapter, we give a description of almost all low-level functions of the PARI system. These essentially include functions for handling all the PARI types. Higher level functions, such as arithmetic or transcendental functions, are described fully in Chapter 3 of this manual.

by1=0 <#9162#>=0<#9164#><#9164#><#9162#>



<#9163#><#9165#>. Level 0 kernel (operations on unsigned longs)<#9165#><#9163#>


The type ``<#1903#>ulong<#1903#>'' is defined in the file <#1904#>gencom.h<#1904#> as <#1905#>unsigned long<#1905#>. The global <#1906#>ulong<#1906#> variables <#1907#>overflow<#1907#> (which will contain only 0 or 1) and <#1908#>hiremainder<#1908#> are defined in the file <#1909#>versionXXX.c<#1909#>.

For the non-68k versions, we need level 0 operations simulating basic operations of the 68020 processor. For compatibility reasons, and also for very rare cases, they are also included in the 68k version, although they are not really needed. Note that in the given prototypes ulongs are sometimes implicitly typecasted as ints or longs.

<#1910#>int addll(int x, int y)<#1910#>: add the ulongs x and y, output the lower 32 bits and put the overflow bit in <#1911#>overflow<#1911#>.

<#1912#>int addllx(int x, int y)<#1912#>: add <#1913#>overflow<#1913#> to the sum of the ulongs x and y, output the lower 32 bits and put the overflow bit in <#1914#>overflow<#1914#>.

<#1915#>int subll(int x, int y)<#1915#>: subtract the ulongs x and y, output the lower 32 bits and put the overflow bit in <#1916#>overflow<#1916#>.

<#1917#>int subllx(int x, int y)<#1917#>: subtract <#1918#>overflow<#1918#> from the difference of the ulongs x and y, output the lower 32 bits and put the overflow bit in <#1919#>overflow<#1919#>.

<#1920#>int shiftl(ulong x, ulong y)<#1920#>: left shift the ulong x by y bits, output the lower 32 bits and put the higher 32 bits in <#1921#>hiremainder<#1921#>. We must have #math754#y≤32.

<#1923#>int shiftlr(ulong x, ulong y)<#1923#>: right shift the ulong #math755#x ;SPMlt; ;SPMlt; 32 by y bits, output the higher 32 bits and put the lower 32 bits in <#1925#>hiremainder<#1925#>. We must have #math756#y≤32.

<#1927#>int bfffo(ulong x)<#1927#>: output the number of bits that the ulong x should be shifted left so that its leftmost bit is equal to 1 (32 if x is equal to 0).

<#1928#>int mulll(ulong x, ulong y)<#1928#>: multiply the ulong x by the ulong y, output the lower 32 bits and put the higher 32 bits in <#1929#>hiremainder<#1929#>.

<#1930#>int addmul(ulong x, ulong y)<#1930#>: add <#1931#>hiremainder<#1931#> to the product of the ulong x by the ulong y, output the lower 32 bits and put the higher 32 bits in <#1932#>hiremainder<#1932#>.

<#1933#>int divll(ulong x, ulong y)<#1933#>: output the Euclidean quotient of the ulong x by the ulong y and put the remainder in <#1934#>hiremainder<#1934#>.

<#1935#>long mulmodll(ulong x, ulong y, ulong z)<#1935#>: output x*y modulo z.

by1=0 <#9171#>=0<#9173#><#9173#><#9171#>



<#9172#><#9174#>. Level 1 kernel (operations on longs, integers and reals)<#9174#><#9172#>


In this section as elsewhere, ``long'' denotes a 32-bit signed C-integer, ``integer'' denotes a PARI multiprecise integer (type 1), ``real'' denotes a PARI multiprecise real (type 2). Refer to the users manual for general background.

by 1=0 <#9177#>=0<#9179#><#9179#><#9177#>

<#9178#><#9180#>.. Basic unit and subunit handling functions<#9180#><#9178#>

<#1938#>long typ(GEN x)<#1938#>: gives the type number of x.

<#1939#>long lg(GEN x)<#1939#>: gives the length in 32-bit words of x.

<#1940#>long lgef(GEN x)<#1940#>: gives the effective length in 32-bit words of x. This makes sense only if x is an integer (type 1) or a polynomial (type 10).

<#1941#>long mant(GEN x,long n)<#1941#>: gives the n-th 32-bit mantissa word of the integer or real x (the most significant word is n=1).

<#1942#>long signe(GEN x)<#1942#>: gives the sign (-1, 0 or 1) of x. Should be used for integers, reals, polynomials and power series (for these last two only 0 or 1 are possible). For all other types, use <#1943#>gsigne(GEN x)<#1943#>.

<#1944#>long expo(GEN x)<#1944#>: gives the unbiased 24-bit binary exponent of the real number x. If x is not a real number, one can define such a quantity, but in that case use the function <#1945#>gexpo(GEN x)<#1945#>.

<#1946#>long expi(GEN x)<#1946#>: binary exponent of the real number equal to the integer x. This is the special case of the function <#1947#>gexpo(GEN x)<#1947#> corresponding to the case where x is of type integer.

<#1948#>long pere(GEN x)<#1948#>: gives the number of objects pointing at x, saturating at 255. Now unused.

<#1949#>long valp(GEN x)<#1949#>: gives the unbiased 16-bit p-adic valuation (for a p-adic) or X-adic valuation (for a power series) of x.

<#1950#>long precp(GEN x)<#1950#>: gives the precision of the p-adic x.

<#1951#>long varn(GEN x)<#1951#>: gives the variable number of x (between 0 and 255). Should be used only for polynomials and power series. For all other types, use <#1952#>gvar(GEN x)<#1952#>.

<#1953#>void settyp(GEN x, long s)<#1953#>: set equal to s the type number of x. This should be used with extreme care since usually the type is set otherwise.

<#1954#>void setlg(GEN x, long s)<#1954#>: set equal to s the length of x. Again this should be used with extreme care since usually the length is set otherwise.

<#1955#>void setlgef(GEN x, long s)<#1955#>: set equal to s the effective length of x, where x is an integer or a polynomial. The number s must be less than or equal to the length of x.

<#1956#>void setmant(GEN x, long n, long s)<#1956#>: set equal to s the n-th mantissa word of the integer or real number x.

<#1957#>void setsigne(GEN x, long s)<#1957#>: set equal to s the sign of x. If x is an integer or real, s must be equal to -1, 0 or 1, and if x is a polynomial or a power series, s must be equal to 0 or 1.

<#1958#>void setexpo(GEN x, long s)<#1958#>: set equal to s the binary exponent of the real number x. s must be a 24-bit signed number.

<#1959#>void setpere(GEN x, long s)<#1959#>: set equal to s the number of objects pointing to x, where #math757#0≤s≤255. Now unused.

<#1960#>void incpere(GEN x)<#1960#>: increase by 1 the number of objects pointing to x, saturating at 255. Now unused.

<#1961#>void setvalp(GEN x, long s)<#1961#>: set equal to s the p-adic valuation of x (if x is a p-adic) or the X-adic valuation of x (if x is a power series).

<#1962#>void setprecp(GEN x, long s)<#1962#>: set equal to s the p-adic precision of the p-adic number x.

<#1963#>void setvarn(GEN x, long s)<#1963#>: set equal to s (#math758#0≤s≤255) the variable number of the polynomial or power series x.

by 1=0 <#9184#>=0<#9186#><#9186#><#9184#>

<#9185#><#9187#>.. Memory allocation on the PARI stack<#9187#><#9185#>

<#1965#>GEN cgetg(long n, long t)<#1965#>: allocate memory on the PARI stack for an object of length n and type t, and initialize its first codeword (containing <#1966#>typ<#1966#> (1 byte), <#1967#>pere<#1967#> (1 byte), <#1968#>lg<#1968#> (2 bytes).

<#1969#>GEN cgeti(long n)<#1969#>: allocate memory on the PARI stack for an integer of length n, and initialize its first codeword. Identical to <#1970#>cgetg(n,1)<#1970#>.

<#1971#>GEN cgetr(long n)<#1971#>: allocate memory on the PARI stack for a real of length n, and initialize its first codeword. Identical to <#1972#>cgetg(n,2)<#1972#>.

<#1973#>void cgiv(GEN x)<#1973#>: free object x if it is the last created on the PARI stack (otherwise disaster occurs).

<#1974#>GEN gerepile(long p, long q, GEN x)<#1974#>: general garbage collector for the PARI stack. See chapter 4 of the manual for a detailed explanation.

by 1=0 <#9191#>=0<#9193#><#9193#><#9191#>

<#9192#><#9194#>.. Assignments, conversions and integer parts<#9194#><#9192#>

<#1976#>void mpaff(GEN x, GEN z)<#1976#>: assign x into z (x and z integers or reals).

<#1977#>void affsz(long s, GEN z)<#1977#>: assign the long s into the integer or real z.

<#1978#>void affsi(long s, GEN z)<#1978#>: assign the long s into the integer z.

<#1979#>void affsr(long s, GEN z)<#1979#>: assign the long s into the real z.

<#1980#>void affii(GEN x, GEN z)<#1980#>: assign the integer x into the integer z.

<#1981#>void affir(GEN x, GEN z)<#1981#>: assign the integer x into the real z.

<#1982#>void affrs(GEN x, long s)<#1982#>: assign the real x into the long s. This is a forbidden assignment in PARI, so an error message is issued.

<#1983#>void affri(GEN x, GEN z)<#1983#>: assign the real x into the integer z. This is a forbidden assignment in PARI, so an error message is issued.

<#1984#>void affrr(GEN x, GEN z)<#1984#>: assign the real x into the real z.

<#1985#>GEN stoi(long s)<#1985#>: create the PARI integer corresponding to the long s.

<#1986#>long itos(GEN x)<#1986#>: convert to long the PARI integer x (if possible, otherwise an error message is issued).

<#1987#>GEN mptrunc(GEN x)<#1987#>: truncation of the integer or real x (not the same as the integer part if x is noninteger and negative).

<#1988#>void mptruncz(GEN x, GEN z)<#1988#>: assign the truncation of the integer or real x into z.

<#1989#>GEN mpent(GEN x)<#1989#>: true integer part of the integer or real x (i.e. the <#1990#>floor<#1990#> function).

<#1991#>void mpentz(GEN x, GEN z)<#1991#>: assign the true integer part of the integer or real x into z.

by 1=0 <#9198#>=0<#9200#><#9200#><#9198#>

<#9199#><#9201#>.. Valuation and shift<#9201#><#9199#>

<#1993#>long vals(long s)<#1993#>: 2-adic valuation of the long s. Returns -1 if s is equal to 0, with no error.

<#1994#>long vali(GEN x)<#1994#>: 2-adic valuation of the integer x. Returns -1 if s is equal to 0, with no error.

<#1995#>GEN mpshift(GEN x, long n)<#1995#>: shift by n the real or integer x. If n is positive, this is a left shift, i.e. multiplication by #math759#2n. If n is negative, it is a right shift, hence the truncation of the division of x by #math760#2-n.

<#1998#>void mpshiftz(GEN x, long n, GEN z)<#1998#>: assign into z the real or integer x shifted by n.

<#1999#>GEN shifts(long s, long n)<#1999#>: convert the long s into a PARI integer and shift by n.

<#2000#>GEN shifti(GEN x, long n)<#2000#>: shift by n the integer x.

<#2001#>GEN shiftr(GEN x, long n)<#2001#>: shift by n the real x.

by 1=0 <#9207#>=0<#9209#><#9209#><#9207#>

<#9208#><#9210#>.. Unary operations<#9210#><#9208#>

Let ``op'' be some unary operation of type GEN. The names and prototypes of the low-level functions corresponding to op will be as follows.

<#2003#>GEN mpop(GEN x)<#2003#>: create the result of op applied to the integer or real x.

<#2004#>GEN ops(long s)<#2004#>: create the result of op applied to the long s.

<#2005#>GEN opi(GEN x)<#2005#>: create the result of op applied to the integer x.

<#2006#>GEN opr(GEN x)<#2006#>: create the result of op applied to the real x.

<#2007#>void mpopz(GEN x, GEN z)<#2007#>: assign into the integer or real z the result of applying op to the integer or real x.

Remark: it has not been considered useful to include in PARI the functions <#2008#>void opsz(long s, GEN z)<#2008#>, <#2009#>void opiz(GEN x, GEN z)<#2009#> and <#2010#>void oprz(GEN x, GEN z)<#2010#>.

This can be applied to the following operators.

op=neg: negation (-x). The result is the same type as x.

op=abs: absolute value (| x|). The result is the same type as x.

In addition, there exist the following special unary functions with assignment.

<#2012#>void mpinvz(GEN x, GEN z)<#2012#>: assign the inverse of the integer or real x into the real z. The inverse is computed as a quotient of real numbers, not as a Euclidean division.

<#2013#>void mpinvsr(long s, GEN z)<#2013#>: assign the inverse of the long s into the real z.

<#2014#>void mpinvir(GEN x, GEN z)<#2014#>: assign the inverse of the integer x into the real z.

<#2015#>void mpinvrr(GEN x, GEN z)<#2015#>: assign the inverse of the real x into the real z.

by 1=0 <#9215#>=0<#9217#><#9217#><#9215#>

<#9216#><#9218#>.. Comparison operators<#9218#><#9216#>

<#2017#>long mpcmp(GEN x, GEN y)<#2017#>: compare the integer or real x with the integer or real y. The result is the sign of x-y.

<#2018#>long cmpss(long s, long t)<#2018#>: sign of s-t.

<#2019#>long cmpsi(long s, GEN x)<#2019#>: compare the long s with the integer x.

<#2020#>long cmpsr(long s, GEN x)<#2020#>: compare the long s with the real x.

<#2021#>long cmpis(GEN x, long s)<#2021#>: compare the integer x with the long s.

<#2022#>long cmpii(GEN x, GEN y)<#2022#>: compare the integer x with the integer y.

<#2023#>long cmpir(GEN x, GEN y)<#2023#>: compare the integer x with the real y.

<#2024#>long cmprs(GEN x, long s)<#2024#>: compare the real x with the long s.

<#2025#>long cmpri(GEN x, GEN y)<#2025#>: compare the real x with the integer y.

<#2026#>long cmprr(GEN x, GEN y)<#2026#>: compare the real x with the real y.

by 1=0 <#9222#>=0<#9224#><#9224#><#9222#>

<#9223#><#9225#>.. Binary operations<#9225#><#9223#>

Let ``op'' be some operation of type GEN. The names and prototypes of the low-level functions corresponding to op will be as follows.

<#2028#>GEN mpop(GEN x, GEN y)<#2028#>: create the result of op applied to the integer or reals x and y.

<#2029#>GEN opss(long s, long t)<#2029#>: create the result of op applied to the longs s and t.

<#2030#>GEN opsi(long s, GEN x)<#2030#>: create the result of op applied to the long s and the integer x.

<#2031#>GEN opsr(long s, GEN x)<#2031#>: create the result of op applied to the long s and the real x.

<#2032#>GEN opis(GEN x, long s)<#2032#>: create the result of op applied to the integer x and the long s.

<#2033#>GEN opii(GEN x, GEN y)<#2033#>: create the result of op applied to the integers x and y.

<#2034#>GEN opir(GEN x, GEN y)<#2034#>: create the result of op applied to the integer x and the real y.

<#2035#>GEN oprs(GEN x, long s)<#2035#>: create the result of op applied to the real x and the long s.

<#2036#>GEN opri(GEN x, GEN y)<#2036#>: create the result of op applied to the real x and the integer y.

<#2037#>GEN oprr(GEN x, GEN y)<#2037#>: create the result of op applied to the reals x and y.

<#2038#>GEN mpopz(GEN x, GEN y, GEN z)<#2038#>: assign into the integer or real z the result of op applied to the integer or reals x and y.

<#2039#>GEN opssz(long s, long t, GEN z)<#2039#>: assign into the integer or real z the result of op applied to the longs s and t.

<#2040#>GEN opsiz(long s, GEN x, GEN z)<#2040#>: assign into the integer or real z the result of op applied to the long s and the integer x.

<#2041#>GEN opsrz(long s, GEN x, GEN z)<#2041#>: assign into the integer or real z the result of op applied to the long s and the real x.

<#2042#>GEN opisz(GEN x, long s, GEN z)<#2042#>: assign into the integer or real z the result of op applied to the integer x and the long s.

<#2043#>GEN opiiz(GEN x, GEN y, GEN z)<#2043#>: assign into the integer or real z the result of op applied to the integers x and y.

<#2044#>GEN opirz(GEN x, GEN y, GEN z)<#2044#>: assign into the integer or real z the result of op applied to the integer x and the real y.

<#2045#>GEN oprsz(GEN x, long s, GEN z)<#2045#>: assign into the integer or real z the result of op applied to the real x and the long s.

<#2046#>GEN opriz(GEN x, GEN y, GEN z)<#2046#>: assign into the integer or real z the result of op applied to the real x and the integer y.

<#2047#>GEN oprrz(GEN x, GEN y, GEN z)<#2047#>: assign into the integer or real z the result of op applied to the reals x and y.

This can be applied to the following operators.

op=add: addition (x+y). The result is real except if both x and y are integers.

op=sub: subtraction (x-y). The result is real except if both x and y are integers.

op=mul: multiplication (x*y). The result is real except if both x and y are integers OR if x or y is the integer or long zero.

op=div: division (x/y). In the case where x and y are both integers or longs, the result is the Euclidean quotient, the remainder being of the sign of the dividend x. If one of x or y is real, the result is real except if x is the integer or long zero. Division by zero error if y is equal to zero.

op=res: remainder (x%y). This operation exists only when x and y are longs or integers. The result is the Euclidean remainder corresponding to div, i.e. its sign is that of the dividend x. The result is always an integer.

op=mod: remainder (x%y). This operation exists only when x and y are longs or integers. The result is the true Euclidean remainder, i.e. nonnegative and less than the absolute value of y.

by 1=0 <#9229#>=0<#9231#><#9231#><#9229#>

<#9230#><#9232#>.. Division with remainder<#9232#><#9230#>

<#2049#>GEN dvmdss(long s, long t, GEN* r<#2049#>: create the Euclidean quotient and remainder of the longs s and t. If r is not 0 or -1. put the address of the remainder in r, and output the quotient. If r is equal to 0, only the quotient is output. If r is equal to -1, the remainder is output instead of the quotient. The remainder is always of the sign of the dividend s.

<#2050#>GEN dvmdsi(long s, GEN x, GEN* r)<#2050#>: create the Euclidean quotient and remainder of the long s by the integer x.

<#2051#>GEN dvmdis(GEN x, long s, GEN* r)<#2051#>: create the Euclidean quotient and remainder of the integer x by the long s.

<#2052#>GEN dvmdii(GEN x, GEN y, GEN* r)<#2052#>: create the Euclidean quotient and remainder of the integer x by the integer y.

<#2053#>void mpdvmdz(GEN x, GEN y, GEN z, GEN* r)<#2053#>: assign into the integer or real z the Euclidean quotient of the integers x by y, putting the address of the remainder in r (except if r is equal to 0 or -1 as above).

<#2054#>void dvmdssz(long s, long t, GEN z, GEN* r)<#2054#>: assign into the integer or real z the Euclidean quotient of the longs s by t, putting the address of the remainder in r (except if r is equal to 0 or -1 as above).

<#2055#>void dvmdsiz(long s, GEN x, GEN z, GEN* r<#2055#>: assign into the integer or real z the Euclidean quotient of the long s by the integer x, putting the address of the remainder in r (except if r is equal to 0 or -1 as above).

<#2056#>void dvmdisz(GEN x, long s, GEN z, GEN* r)<#2056#>: assign into the integer or real z the Euclidean quotient of the integer x by the long s, putting the address of the remainder in r (except if r is equal to 0 or -1 as above).

<#2057#>void dvmdiiz(GEN x, GEN y, GEN z, GEN* r)<#2057#>: assign into the integer or real z the Euclidean quotient of the integers x by y, putting the address of the remainder in r (except if r is equal to 0 or -1 as above).

by 1=0 <#9236#>=0<#9238#><#9238#><#9236#>

<#9237#><#9239#>.. Miscellaneous functions<#9239#><#9237#>

<#2059#>long mpdivis(GEN x, GEN y, GEN z)<#2059#>: if the integer y divides the integer x, assign the quotient in the integer z and return 1 (true), otherwise return 0 (false).

<#2060#>long divise(GEN x, GEN y)<#2060#>: if the integer y divides the integer x, return 1 (true), otherwise return 0 (false).

<#2061#>GEN convi(GEN x)<#2061#>: converts the absolute value of the integer x in base 109. The result is an integer z such that z[1] is set artificially to -1, z[2], ..., z[m] contain the base 109 digits of | x|, and the output is the address of z[m+1].

<#2063#>GEN confrac(GEN x)<#2063#>: converts the fractional part of the real x in base 109. The result is an array z on the PARI stack such that z[0] contains the number of significant decimal digits, and z[1],...the base 109 expansion of the fractional part of x.

Warning: since z is not a standard PARI object, the stack must be cleaned by a simple avma=oldavma statement, and not by the <#2064#>gerepile<#2064#> garbage collector after execution of this function.

<#2065#>void addsii(long s, GEN x, GEN z)<#2065#>: assign into the integer z the sum of the long s and the integer x (essentially identical to <#2066#>addsiz<#2066#> except that z is specifically an integer).

<#2067#>void mulsii(long s, GEN x, GEN z)<#2067#>: assign into the integer z the product of the long s and the integer x (essentially identical to <#2068#>mulsiz<#2068#> except that z is specifically an integer).

<#2069#>long divisii(GEN x, long s, GEN z)<#2069#>: assign into the integer z the Euclidean quotient of the integer x by the long s, and return the remainder as a long.

by1=0 <#9244#>=0<#9246#><#9246#><#9244#>



<#9245#><#9247#>. Level 2 kernel (operations on general PARI objects)<#9247#><#9245#>


In this section, functions followed by an assignment statement will be mentioned as in the following example:

<#2071#>GEN gadd[z](GEN x, GEN y[, GEN z])<#2071#>: the explanation is given for the function <#2072#>gadd<#2072#>, and the brackets are there to say that the <#2073#>void<#2073#> function <#2074#>void gaddz(GEN x, GEN y, GEN z)<#2074#> also exists, where the result is assigned into z.

All these [z] functions are obtained using macros (see the file <#2075#>gencom.h<#2075#>) hence if an extension of the list is desired, it is trivial to add the suitable macro in the file <#2076#>gencom.h<#2076#>.

The functions available to handle subunits are the following.

<#2077#>GEN compo(GEN x, long n)<#2077#>: create a copy of the n-th true component (i.e. not counting the codewords) of the object x.

<#2078#>GEN truecoeff(GEN x, long n)<#2078#>: create a copy of the coefficient of degree n of x if x is a scalar, polynomial or power series, otherwise of the n-th component of x.

<#2079#>long coeff(GEN x, long i, long j)<#2079#>: x being a matrix (type 19), this gives the address of the coefficient of row i and column j of the matrix x. This is NOT a function, simply a macro, and can be used on the left or right hand side of an assignment statement.

by 1=0 <#9250#>=0<#9252#><#9252#><#9250#>

<#9251#><#9253#>.. Copying and conversion<#9253#><#9251#> <#2081#>GEN cgetp(GEN x)<#2081#>: create p-adic space sufficient to put x into, and set the prime p and the p-adic precision to that of x, but do not copy x.

<#2082#>GEN gcopy(GEN x)<#2082#>: create a new copy of the object x on the PARI stack.

<#2083#>GEN forcecopy(GEN x)<#2083#>: same as copy except that even permanent pointers are copied onto the stack.

<#2084#>long taille(GEN x)<#2084#>: total number of 32-bit words occupied by the tree representing x.

<#2085#>GEN gclone(GEN x)<#2085#>: create a new copy of the object x on the heap.

<#2086#>GEN greffe(GEN x, long l)<#2086#>: x being a polynomial (type 10), create a power series (type 11) of length l starting with x, but without actually copying the coefficients, just the pointers. For internal use.

<#2087#>double rtodbl(GEN x)<#2087#>: x being a real (type 2), convert x into a C double if possible.

<#2088#>GEN dbltor(double x)<#2088#>: convert the C double x into a PARI real.

<#2089#>double gtodouble(GEN x)<#2089#>: x being in the real numbers (but not necessarily of type real), convert x into a C double if possible.

<#2090#>long gtolong(GEN x)<#2090#>: x being in the integers (but not necessarily of type integer), convert x into a C long if possible.

<#2091#>GEN gtopoly(GEN x, long v)<#2091#>: convert or truncate the object x into a polynomial with main variable number v.

<#2092#>GEN gtopolyrev(GEN x, long v)<#2092#>: convert or truncate the object x into a polynomial with main variable number v, but vectors are converted in reverse order.

<#2093#>GEN gtoser(GEN x, long v)<#2093#>: convert the object x into a power series with main variable number v.

<#2094#>GEN gtovec(GEN x)<#2094#>: convert the object x into a (row) vector.

<#2095#>GEN co8(GEN x, long l)<#2095#>: x being a quadratic number (type 8), convert x into a real number or complex number depending on the sign of the discriminant of x, to precision l 32-bit words.

<#2096#>GEN gcvtop(GEN x, GEN p, long l)<#2096#>: convert x into a p-adic number of precision l.

<#2097#>GEN gmodulcp(GEN x, GEN y)<#2097#>: create the object mod(x,y) on the PARI stack, where x and y are either both integers, and the result is an integermod (type 3) or x is a scalar or a polynomial and y a polynomial, and the result is a polymod (type 9).

<#2098#>GEN gmodulo(GEN x, GEN y)<#2098#>: same as <#2099#>gmodulcp<#2099#> except that the modulus y is copied on the heap and not in the PARI stack.

<#2100#>long gexpo(GEN x)<#2100#>: return the binary exponent of x or the maximal binary exponent of the coefficients of x; return #math761#- (215 - 1) if x has no components. Error if x is exactly zero.

<#2102#>long gsize(GEN x)<#2102#>: return 0 if x is exactly 0, otherwise return <#2103#>gexpo(x)<#2103#> multiplied by #math762#log(2)/log(10). This gives a crude estimate for the maximal number of decimal digits of the components of x.

<#2104#>long gsigne(GEN x)<#2104#>: return the sign of x (-1, 0 or 1) when x is an integer, real or (irreducible or reducible) fraction. Error for all other types.

<#2105#>long gvar(GEN x)<#2105#>: return the main variable of x. If no component of x is a polynomial or power series, return 215 - 1.

<#2107#>int precision(GEN x)<#2107#>: If x is of type real, return the precision of x (the length of x in 32-bit words if x is not zero, and a reasonable quantity obtained from the exponent of x if x is equal to zero). If x is of type complex, return the minimum of the precisions of the real and imaginary part. Otherwise, return 0 (coding in fact for ∞).

by 1=0 <#9257#>=0<#9259#><#9259#><#9257#>

<#9258#><#9260#>.. Comparison operators and valuations<#9260#><#9258#>

<#2109#>int gcmp0(GEN x)<#2109#>: 1 (true) if x is equal to 0, 0 (false) otherwise.

<#2110#>int isexactzero(GEN x)<#2110#>: 1 (true) if x is exactly equal to 0, 0 (false) otherwise.

<#2111#>int gcmp1(GEN x)<#2111#>: 1 (true) if x is equal to 1, 0 (false) otherwise.

<#2112#>int gcmp_1(GEN x)<#2112#>: 1 (true) if x is equal to -1, 0 (false) otherwise.

<#2113#>long gcmp(GEN x, GEN y)<#2113#>: comparison of x with y (sign of x-y).

<#2114#>long gcmpsg(long s, GEN x)<#2114#>: comparison of the long s with x.

<#2115#>long gcmpgs(GEN x, long s)<#2115#>: comparison of x with the long s.

<#2116#>long lexcmp(GEN x, GEN y)<#2116#>: comparison of x with y for the lexicographic ordering.

<#2117#>long gegal(GEN x, GEN y)<#2117#>: 1 (true) if x is equal to y, 0 otherwise.

<#2118#>long gegalsg(long s, GEN x)<#2118#>: 1 (true) if the long s is equal to x, 0 otherwise.

<#2119#>long gegalgs(GEN x, long s)<#2119#>: 1 (true) if x is equal to the long s, 0 otherwise (it should not be very different from <#2120#>gegalsg<#2120#>!).

<#2121#>long iscomplex(GEN x)<#2121#>: 1 (true) if x is in the complex numbers but not in the reals, 0 if x is in the reals, error if x is not in the complex numbers.

<#2122#>long ismonome(GEN x)<#2122#>: 1 (true) if x is a nonzero monomial in its main variable, 0 otherwise.

<#2123#>long ggval(GEN x, GEN p)<#2123#>: greatest exponent of p dividing x, when this makes sense.

<#2124#>long gval(GEN x, long v)<#2124#>: highest power of the variable number v dividing the polynomial x.

<#2125#>int pvaluation(GEN x, GEN p, GEN*r)<#2125#>: x and p being integers, returns the highest power of p dividing x, creates the coprime to p part of x and returns its address in r.

by 1=0 <#9264#>=0<#9266#><#9266#><#9264#>

<#9265#><#9267#>.. Assignment statements<#9267#><#9265#>

<#2127#>void gaffsg(long s, GEN x)<#2127#>: assign the long s into the object x.

<#2128#>void gaffect(GEN x, GEN y)<#2128#>: assign the object x into the object y.

by 1=0 <#9271#>=0<#9273#><#9273#><#9271#>

<#9272#><#9274#>.. Unary operators<#9274#><#9272#>

<#2130#>GEN gneg[z](GEN x[, GEN z])<#2130#>: create -x.

<#2131#>GEN gabs[z](GEN x[, GEN z])<#2131#>: create | x|.

<#2133#>GEN gsqr(GEN x)<#2133#>: create the square of x,

<#2134#>GEN ginv(GEN x)<#2134#>: create the inverse of x.

<#2135#>GEN gfloor(GEN x)<#2135#>: create the floor of x, i.e. the (true) integral part.

<#2136#>GEN gfrac(GEN x)<#2136#>: create the fractional part of x, i.e. x minus the floor of x.

<#2137#>GEN gceil(GEN x)<#2137#>: create the ceiling of x.

<#2138#>GEN ground(GEN x)<#2138#>: round the components of x to the nearest integer.

<#2139#>GEN grndtoi(GEN x, long*e)<#2139#>: same as round, but in addition put in *e minus the number of significant binary bits left after rounding. If *e is positive, all significant bits are lost. This gives an error message in <#2140#>ground<#2140#> but not in <#2141#>grndtoi<#2141#>.

<#2142#>GEN gtrunc(GEN x)<#2142#>: truncate x. This is the (false) integer part if x is an integer, converts a series into a polynomial or rational function, takes the polynomial part of a rational function.

<#2143#>GEN gcvtoi(GEN x, long*e)<#2143#>: same as <#2144#>grndtoi<#2144#> except that rounding is replaced by truncation.

<#2145#>GEN gred[z](GEN x[, GEN z])<#2145#>: reduce x to lowest terms if x is a fraction or rational function (types 4, 5, 13 and 14), otherwise create a copy of x.

<#2146#>void gredsp(GEN* x)<#2146#>: reduce *x to lowest terms and put the result in *x again. The type of the result may be changed to integer or polynomial. A call to this function is the nomral way of finishing a computation whose result gives a fraction or rational function which is not necessarily in lowest terms.

<#2147#>GEN content(GEN x)<#2147#>: create the GCD of all the components of x.

<#2148#>GEN primpart(GEN x)<#2148#>: x divided by its content.

<#2149#>void normalize(GEN* px)<#2149#>: x=*px being an unnormalized power series (i.e. type 11 with all coefficients correctly set except that x[2] is not necessarily different from zero), normalize x correctly in place. For internal use.

<#2150#>void normalizepol(GEN* px)<#2150#>: x=*px being an unnormalized polynomial (i.e. type 10 with all coefficients correctly set except that x[2] is not necessarily different from zero), normalize x correctly in place. For internal use.

by 1=0 <#9279#>=0<#9281#><#9281#><#9279#>

<#9280#><#9282#>.. Binary operators<#9282#><#9280#>

<#2152#>GEN gmax[z](GEN x, GEN y[, GEN z])<#2152#>: create the maximum of the objects x and y if they can be compared.

<#2153#>GEN gmaxsg[z](long s, GEN x[, GEN z])<#2153#>: create the maximum of the long s and the object x.

<#2154#>GEN gmaxgs[z](GEN x, long s[, GEN z])<#2154#>: create the maximum of the object x and the long s.

<#2155#>GEN gmin[z](GEN x, GEN y[, GEN z])<#2155#>: create the minimum of the objects x and y if they can be compared.

<#2156#>GEN gminsg[z](long s, GEN x[, GEN z])<#2156#>: create the minimum of the long s and the object x.

<#2157#>GEN gmings[z](GEN x, long s[, GEN z])<#2157#>: create the minimum of the object x and the long s.

<#2158#>GEN gadd[z](GEN x, GEN y[, GEN z])<#2158#>: create the sum of the objects x and y.

<#2159#>GEN gaddsg[z](long s, GEN x[, GEN z])<#2159#>: create the sum of the long s and the object x.

<#2160#>GEN gaddgs[z](GEN x, long s[, GEN z])<#2160#>: create the sum of the object x and the long s.

<#2161#>GEN gaddpex(GEN x, GEN y)<#2161#>: create the sum of the integer or fraction x and the p-adic y. For internal use.

<#2162#>GEN gsub[z](GEN x, GEN y[, GEN z])<#2162#>: create the difference of the objects x and y.

<#2163#>GEN gsubgs[z](GEN x, long s[, GEN z])<#2163#>: create the difference of the object x and the long s.

<#2164#>GEN gsubsg[z](long s, GEN x[, GEN z])<#2164#>: create the difference of the long s and the object x.

<#2165#>GEN gmul[z](GEN x, GEN y[, GEN z])<#2165#>: create the product of the objects x and y.

<#2166#>GEN gmulsg[z](long s, GEN x[, GEN z])<#2166#>: create the product of the long s with the object x.

<#2167#>GEN gmulgs[z](GEN x, long s[, GEN z])<#2167#>: create the product of the object x with the long s.

<#2168#>GEN gshift[z](GEN x, long n[, GEN z])<#2168#>: left shift of the components of x by n (if n is nonnegative) or right shift by -n (if n is negative). Applies only to integers, reals and vectors/matrices of such. For other types, it is simply multiplication by #math763#2n.

<#2170#>GEN gmul2n[z](GEN x, long n[, GEN z])<#2170#>: create x multiplied by #math764#2n. The difference with <#2172#>gshift<#2172#> occurs when n is negative and x is of type integer: <#2173#>gshift<#2173#> truncates, while <#2174#>gmul2n<#2174#> creates a fraction if necessary.

<#2175#>GEN gdiv[z](GEN x, GEN y[, GEN z])<#2175#>: create the quotient of the objects x and y.

<#2176#>GEN gdivgs[z](GEN x, long s[, GEN z])<#2176#>: create the quotient of the object x with the long s.

<#2177#>GEN gdivsg[z](long s, GEN x[, GEN z])<#2177#>: create the quotient of the long s with the object x.

<#2178#>GEN gdivent[z](GEN x, GEN y[, GEN z])<#2178#>: create the true Euclidean quotient of x by the integer or polynomial y.

<#2179#>GEN gdiventsg[z](long s, GEN x[, GEN z])<#2179#>: create the true Euclidean quotient of the long s by the integer x.

<#2180#>GEN gdiventgs[z](GEN x, long s[, GEN z])<#2180#>: create the true Euclidean quotient of the integer x by the long s.

<#2181#>GEN gdiventres(GEN x, GEN y)<#2181#>: create a 2-component vertical vector whose components are the true Euclidean quotient and remainder of x by y.

<#2182#>GEN gdivmod(GEN x, GEN y, GEN*r)<#2182#>: If r is not equal to 0 or -1, create the (false) Euclidean quotient of x by y, and put the address of the remainder in r. If r is equal to 0, do not create the remainder, and if r is equal to -1, create and output only the remainder.

<#2183#>GEN poldivres(GEN x, GEN y, GEN*r)<#2183#>: same as <#2184#>gdivmod<#2184#> but specifically for x and y polynomials.

<#2185#>GEN gdeuc[z](GEN x, GEN y[, GEN z])<#2185#>: create the Euclidean quotient of the polynomial x by the polynomial y.

<#2186#>GEN gmod[z](GEN x, GEN y[, GEN z])<#2186#>: create the true remainder of x modulo the integer or polynomial y.

<#2187#>GEN gmodsg[z](long s, GEN x[, GEN z])<#2187#>: create the true remainder of the long s modulo the integer x.

<#2188#>GEN gmodgs[z](GEN x, long s[, GEN z])<#2188#>: create the true remainder of the integer x modulo the long s.

<#2189#>GEN gres(GEN x, GEN y)<#2189#>: create the Euclidean remainder of the polynomial x divided by the polynomial y.

<#2190#>GEN ginvmod(GEN x, GEN y)<#2190#>: create the inverse of x modulo y when it exists.

<#2191#>GEN gpui(GEN x, GEN y, long l)<#2191#>: create #math765#xy. The precision l is taken into account only if y is not an integer and x is an exact object. If y is an integer, binary powering is done. Otherwise, the result is #math766#exp(y*log(x)) computed to precision l.

<#2196#>GEN ggcd(GEN x, GEN y)<#2196#>: create the GCD of x and y.

<#2197#>GEN glcm(GEN x, GEN y)<#2197#>: create the LCM of x and y.

<#2198#>GEN subres(GEN x, GEN y)<#2198#>: resultant of the polynomials x and y computed using the subresultant algorithm.

<#2199#>GEN gpuigs(GEN x, long n, long l)<#2199#>: create #math767#xn using binary powering. The precision l is used <#2202#>only<#2202#> when x is of type 15 (real quadratic forms), hence can almost always be ommited.

<#2203#>GEN gsubst(GEN x, long v, GEN y)<#2203#>: substitute in x the object y for the variable number v.

<#2204#>int gdivise(GEN x, GEN y)<#2204#>: return 1 (true) if y divides x, 0 otherwise.

<#2205#>GEN gbezout(GEN x, GEN y, GEN* u, GEN* v)<#2205#>: create the GCD of x and y, and put in u and v the adresses of objects such that *ux+*vy= gcd(x,y).

by1=0 <#9294#><#9294#> <#9295#>=0<#9297#><#9297#><#9295#>

Chapter : A GP tutorial

This chapter is intended to be a guided tour and a tutorial to the GP calculator. Many examples will be given, but each time a new function is used, the reader should look at the appropriate section in the manual for detailed explanations. Hence although this chapter can be read independently of the rest (for example to get rapidly acquainted with the possibilities of GP without having to read the whole reference manual), the reader will profit most from it by reading it in conjunction with the reference manual.

by1=0 <#9300#>=0<#9302#><#9302#><#9300#>



<#9301#><#9303#>. Greetings!<#9303#><#9301#>


So you are sitting in front of your workstation (or terminal, or PC,...), and you type <#2208#>gp<#2208#> to get the program started (remember to always hit the <#2209#>enter<#2209#> key and not the <#2210#>return<#2210#> key on a Macintosh computer).

It says hello in its particular manner, and then waits for you after its <#2211#>prompt<#2211#>, initially <#2212#>?<#2212#>.

Type 2 + 2. What happens? Maybe not what you expect. First of all, of course, you should tell GP that your input is finished, and this is done by hitting the <#2213#>return<#2213#> (or <#2214#>newline<#2214#>) key, or the <#2215#>enter<#2215#> key on the Mac. If you do exactly this, you will get the expected answer. However some of you may be used to other systems like Macsyma or Maple. In this case, you will have subconsciously ended the line with a semicolon <#2216#>;<#2216#> before hitting <#2217#>return<#2217#>, since this is how it is done on those systems. In that case, you will simply see GP answering you with a smug expression, i.e. a new prompt and no answer! This is because a semicolon at the end of a line in GP tells it to keep the result, but not to print it (you will certainly want to use this feature if the output is several pages long).

Try 27*37. Wow! even multiplication works.

Now this session is getting lengthy, so the second thing one needs to learn is to quit. Each system has its quit signal (to name a few: <#2218#>quit<#2218#>, <#2219#>quit();<#2219#>, <#2220#>exit<#2220#>, <#2221#>system<#2221#>,...). In GP it is <#2222#>\q<#2222#> (backslash), the <#2223#>q<#2223#> being of course for quit. Try it.

Now you've done it! You're out of GP, so how do you want to continue studying this tutorial? Get back in please (see above).

Let's get to more serious stuff. Let's see, I seem to remember that the decimal expansion of 1/7 has some interesting properties. Let's see what GP has to say about this. Type 1/7. What? This computer is making fun of me, it just spits back to me my own input, that's not what I want!

Now stop complaining, and think a little. This system has been written mainly for pure mathematicians, and not for physicists (although they are welcome to use it :-). And mathematically, 1/7 is an element of the field #tex2html_wrap_inline28200# of rational numbers, so how else but 1/7 can the computer give the answer to you? (well maybe 2/14, but why complicate matters?). Seriously, the basic point here is that PARI (hence GP) will almost always try to give you a result which is as precise as possible (we will se why ``almost'' later), hence since here you gave an operation whose result can be represented exactly, that's what it gives you.

OK, but I still want the decimal expansion of 1/7. No problem. Type one of the following: 1./7, 1/7., 1./7., 0. + 1/7,.... Immediately 28 decimals of this fraction appear, and the repeating pattern is 142857. The reason is that you have included in the operations numbers like 0., 1. or 7. which are <#2224#>imprecise<#2224#> real numbers, hence GP cannot give you an exact result.

Why 28 decimals by the way? well, it is the default initial precision, as indicated when you launch GP. This has been chosen so that the computations are very fast, and give already 12 decimals more accuracy than conventional double precision floating point operations. Only large mainframes or supercomputers have 28 digits of precision in their standard libraries, and that is the absolute limit.

Not here of course. You can extend the precision (almost) as much as you like as we will see in a moment.

I'm getting bored, why don't we get on with some more exciting stuff? Well, try <#2225#>exp(1)<#2225#>. Presto, comes out the value of e to 28 digits. Try <#2226#>log(exp(1))<#2226#>. Well, it's not exactly equal to 1, but pretty close! That's what you lose by working numerically.

Now try <#2227#>exp(pi*sqrt(163))<#2227#>. Hmmm, since from our last example we suspect that the last digit may be wrong, can this really be an integer? This is the time to change precision. Type <#2228#>\precision=50<#2228#>, then try <#2229#>exp(pi*sqrt(163))<#2229#> again. We were right to suspect that the last decimal was incorrect, since we get even more nines than before, but it is now convincingly clear that this is not an integer. Maybe it's a bug in PARI, and the result is really an integer? Type <#2230#>sqr(log()/pi)<#2230#> immediately after the preceding computation (<#2231#><#2231#> means the result of the last computed expression. More generally, the results are numbered <#2232#>1, 2, ...<#2232#> <#2233#>including<#2233#> the results that you do not want to see printed by putting a semicolon at the end of the line, and you can evidently use all these quantities in any further computations. <#2234#>sqr<#2234#> is the square function (<#2235#>sqr(x)=x*x<#2235#>), not to be confused with <#2236#>sqrt<#2236#> which is the square root function). The result seems to be indistinguishable from 163, hence it does not seem to be a bug.

In fact it is a known fact that <#2237#>exp(pi*sqrt(n))<#2237#> not only is not an integer or a rational number, but is even a transcendental number when n is a positive rational number.

So GP is just a fancy calculator, able to give me more decimals than I will ever need? Not so, GP is incredibly more powerful than an ordinary calculator, even independently of its arbitrary precision possibilities.


<#2238#>Additional comments<#2238#>

You are supposed to skip this at first, and come back later.

1) It seems that the text implicitly says that as soon as an imprecise number is entered, the result will be imprecise. Is this always true? There is a unique exception: when you multiply an imprecise number by the exact number 0, you will get the exact 0. Try: 0*1.4, and compare with 0.*1.4.

2) Not only can the number of decimal places of real numbers be large, but the number of digits of integers also. Try 100!. It is never necessary to tell in advance to GP the size of the integers that it will encounter, since this is adjusted automatically. On the other hand, for many computations with real numbers, it is necessary to specify a default precision (initially 28 digits).

3) Come back to 28 digits of precision (<#2239#>\precision=28<#2239#>), and type <#2240#>exp(24*pi)<#2240#>. What is this * that you get at the end of the result?

Well, GP never wants you to believe that a result is correct when it is not. We are working with 28 digits of precision, but the integer part of <#2241#>exp(24*pi)<#2241#> has 33 decimal digits. Hence GP dutifully prints out 33 digits, but it prints a * to warn you that the last few digits are wrong (without telling you how many). The * can thus be interpreted as a decimal point with a warning message.

4) To avoid this *, there are two ways. One is of course to increase the precision to more than 33 decimals. Let's try it. To give it a wide margin, we set the precision to 40 decimals. Then we recall our last result (<#2242#><#2242#> or <#2243#>n<#2243#> where <#2244#>n<#2244#> is the number of the result). What? We still have the *! Do you understand why?

Again let's try to see what's happening. The number you recalled had been computed only to 28 decimals, and even if you set the precision to 1000 decimals, GP knows that your number has only 28 digits of accuracy but an integral part with 33 digits. So you haven't improved things by increasing the precision. Or have you? What if we retype <#2245#>exp(24*pi)<#2245#> now that we have 40 digits? Try it. Now we do not have any warning, and we see the beginning of what's after the decimal point. We also see that at 28 decimals the last 6 digits were wrong.

5) There is still another method to avoid the warning: put yourself back into precision 28. Now type <#2246#>\format=e0.28<#2246#>. The e instead of the g which is printed when GP greets you, means that real numbers (by opposition to integers or rational numbers) will be printed in <#2247#>exponential<#2247#> format, i.e. with a E xxx denoting powers of 10. Try again <#2248#>exp(24*pi)<#2248#> in precision 28. Now we don't have any warning, and the reason is clear: GP has to print only a single digit for the integer part, and then it prints out as many decimals as was asked by the format (here 28).

6) <#2249#>Warning<#2249#>. Try the following: starting in precision 28, type successively <#2250#>\format=e0.50<#2250#>, then <#2251#>exp(24*pi)<#2251#>. Do you understand why the result is so bad, and why there are lots of zeros at the end? Convince yourself by typing <#2252#>log(exp(1))<#2252#>. The moral is that the <#2253#>format<#2253#> command changes only the output format, but <#2254#>not<#2254#> the default precision. On the other hand, the <#2255#>precision<#2255#> command changes both the precision and the output format.

by1=0 <#9307#>=0<#9309#><#9309#><#9307#>



<#9308#><#9310#>. Warming up<#9310#><#9308#>


Another thing you better get used to pretty fast is error messages. Try typing 1/0. Could'nt be clearer. Taking again our universal example in precision 28, type <#2257#>floor(exp(24*pi))<#2257#> (<#2258#>floor<#2258#> is the mathematicians' integer part, not to be confused with <#2259#>trunc<#2259#>, which is the computer scientists': <#2260#>floor(- 3.4)<#2260#> is equal to -4 while <#2261#>trunc(- 3.4)<#2261#> is equal to -3). You get a more cryptic error message, which you would immediately understand if you had read the additional comments of the preceding section. Since I told you not to read them, the explananation is simply that GP is unable to compute the integer part of <#2262#>exp(24*pi)<#2262#> given only 28 decimals of accuracy, since it has 33 digits.

Some error messages are even much more cryptic than that and are sometimes not so easy to understand (well, it's nothing compared to TEX's error messages! :-).

For instance, try <#2263#>log(x)<#2263#>. Not really clear, is it? But no matter, it simply tells you that GP simply does not understand what <#2264#>log(x)<#2264#> is (although it does know the <#2265#>log<#2265#> function).

Now let's try <#2266#>sqrt(-1)<#2266#> to see what error message we get now. Haha! GP even knows about complex numbers, so impossible to trick it that way. Similarly, try typing <#2267#>log(-2)<#2267#>, <#2268#>exp(i*pi)<#2268#>, <#2896#>iˆi<#2896#>,.... So we have a lot of real and complex analysis at our disposal (note that there is always a specific branch of multivalued complex transcendental functions which is taken, specified in the manual).

Just for fun, let's try <#2897#>6*zeta(2)/piˆ2<#2897#>. Pretty good? (If you don't know what the Riemann zeta function is don't worry, we won't use it).


Now GP didn't seem to know what <#2271#>log(x)<#2271#> was, although it did know how to compute numerical values of <#2272#>log<#2272#>. This is annoying. Maybe it knows the exponential function? Let's give it a try. Type <#2273#>exp(x)<#2273#>. What's this? If you had had any experience with other systems, the answer should have simply been <#2274#>exp(x)<#2274#> again. But here the answer is the Taylor expansion of the function around <#2275#>x=0<#2275#>, to 16 terms (16 is the default <#2276#>serieslength<#2276#>, which can be changed by typing <#2277#>\serieslength=n<#2277#>, where <#2278#>n<#2278#> is the number of terms that you want in your power series (note the <#2898#>O(xˆ16)<#2898#> which ends the series, and which is trademark of this type of object in GP. It is the familiar ``bigoh'' notation of analysis).

You will thus automatically get the Taylor expansion of any function that can be expanded around <#2280#>x=0<#2280#>, and incidentally this explains why we weren't able to do anything with <#2281#>log(x)<#2281#> which is not defined at 0. By if we try <#2282#>log(1+x)<#2282#>, then it works. But what if we wanted the expansion around a point different from 0? Well, you're able to change <#2283#>x<#2283#> into <#2284#>x-a<#2284#>, aren't you? So for instance you can type <#2285#>log(x+2)<#2285#> to have the expansion of <#2286#>log<#2286#> around <#2287#>x=2<#2287#>.

As exercises, try <#2288#>cos(x)<#2288#>, <#2899#>cos(x)ˆ2+sin(x)ˆ2<#2899#>, <#2291#>exp(cos(x))<#2291#>, <#2292#>exp(exp(x)-1)<#2292#>, <#2293#>gamma(1+x)<#2293#>, with different values of <#2294#>serieslength<#2294#> if you like.

Let's try something else: type <#2900#>(1+x)ˆ3<#2900#>. No bigoh here, since the result is a polynomial. Haha, but I have learnt that if you do not take exponents which are integers greater or equal to 0, you obtain a power series with an infinite number of nonzero terms. Let's try. Type <#2901#>(1+x)ˆ(-3)<#2901#> (the parentheses around -3 are not necessary but make things easier to read). Surprise! Contrary to what we expected, we don't get a power series but a rational function. Again this is for the same reason that 1/7 just gave you 1/7: the result being exact, PARI doesn't see any reason to make it nonexact.

But I still want that power series. To obtain it, just do as in the 1/7 example: type <#2902#>(1+x)ˆ(-3)+O(xˆ<#2299#>16<#2299#>)<#2902#>, <#2903#>(1+O(xˆ<#2301#>16<#2301#>))*(1+x)ˆ(-3)<#2903#>, <#2904#>(1+x+O(xˆ<#2304#>16<#2304#>))ˆ(-3)<#2904#>,etc...

Now try <#2905#>(1+x)ˆ(1/2)<#2905#>. Now we obtain a power series, since the result is an object which PARI does not know how to represent exactly (we could teach PARI about algebraic functions, but then take <#2906#>(1+x)ˆpi<#2906#> as another example). This gives us still another solution to our preceding exercise: we can type <#2907#>(1+x)ˆ(-3.)<#2907#>. Since -3. is not an exact quantity, PARI has no means to know that we are dealing with a rational function, and will instead give you the power series.

Finally, if you want to be really fancy, you can type <#2908#>taylor((1+x)ˆ(-3),x)<#2908#> (look at the entry for <#2310#>taylor<#2310#> for the description of the syntax), but this is in fact almost never used.

To summarize, in this section we have seen that in addition to integers, real numbers and rational numbers, PARI can handle complex numbers, polynomials, power series, rational functions. A large number of functions exist which handle these types, but in this tutorial we will only look at a few.


<#2311#>Additional comments<#2311#>

As before, you are supposed to skip this at first, and come back later.

1) A complex number has a real part and an imaginary part (who would have guessed?). However, beware that when the imaginary part is the exact integer zero, it is not printed, but the complex number is not converted to a real number. Hence it may <#2312#>look<#2312#> like a real number without being one, and this may cause some confusion in programs which expect real numbers. For example, type <#2313#>3+i-i<#2313#>. The answer is, as expected 3. But it is still a complex number. Hence if you then type <#2909#>(1+x)ˆ<#2909#>, instead of getting the polynomial <#2910#>1+3*x+3*xˆ2+xˆ3<#2910#> as expected, you obtain a power series. Worse, when you try to apply an arithmetic function, say the Euler <#2317#>phi<#2317#> function, you get the error message which says that ``arithmetic functions want integer arguments'', which you would have guessed yourself, but the message is difficult to understand since 3 looks like a genuine integer!!! (Please read again if this is not clear. It is a common source of incomprehension).

Similarly, <#2318#>3+x-x<#2318#> is not the integer 3 but the constant polynomial equal to 3.

If you want the final expression to be in the simplest form possible (for example before applying an arithmetic function, or simply because things will go faster afterwards), apply the function <#2319#>simplify<#2319#> to the result.

2) As already stated, power series expansions are always implicitly around <#2320#>x=0<#2320#>. If you want them around <#2321#>x=a<#2321#>, replace <#2322#>x<#2322#> by <#2323#>z+a<#2323#> in the function that you want to expand. For example, to have the expansion of <#2324#>exp(x)<#2324#> around <#2325#>x=1<#2325#>, we simply type <#2326#>exp(z+1)<#2326#>, where <#2327#>z<#2327#> stands for <#2328#>x-a<#2328#>. For complicated functions, it may be simpler to use the substitution function <#2329#>subst<#2329#>. For example, if <#2911#>p=1/(xˆ4+3*xˆ3+5*xˆ2-6*x+7)<#2911#>, you may not want to retype this, replacing <#2333#>x<#2333#> by <#2334#>z+a<#2334#>, so you can write <#2335#>subst(p,x,z+a)<#2335#> (look up the exact description of the <#2336#>subst<#2336#> function).

Now try typing <#2912#>p=1+x+xˆ2+O(xˆ10)<#2912#>, then <#2339#>subst(p,x,z+1)<#2339#>. Do you understand why you get an error message?

by1=0 <#9313#>=0<#9315#><#9315#><#9313#>



<#9314#><#9316#>. The rest of the PARI types<#9316#><#9314#>


Let's handle first some more the basic PARI types.

Type <#2341#>p=x*exp(-x)<#2341#>. As expected, you get the power series expansion to 16 terms (if you have not changed the default). Now type <#2342#>pr=reverse(p)<#2342#>. You are asking here for the <#2343#>reversion<#2343#> of the power series p, in other words the inverse function. This is possible only for power series whose first non-zero coefficient is that of x1. To check the correctness of the result, you can type <#2344#>subst(p,x,pr)<#2344#> or <#2345#>subst(pr,x,p)<#2345#> and you should get back <#2913#>x+O(xˆ17)<#2913#>.

Now the coefficients of <#2347#>pr<#2347#> obey a very simple formula. First, we would like to multiply the coefficient of <#2914#>xˆn<#2914#> by <#2349#>n!<#2349#> (in the case of the exponential function, this would simplify things considerably!). The PARI function <#2350#>laplace<#2350#> does just that. So type <#2351#>ps=laplace(pr)<#2351#>. The coefficients now become integers, which can be immediately recognized by inspection. The coefficient of <#2915#>xˆn<#2915#> is now equal to #math768#nn-1. In other words, we have

#math769#

pr = #tex2html_wrap_indisplay28243##tex2html_wrap_indisplay28244#Xn.

Do you know how to prove this? (If you have never seen this, the proof is difficult.)

Of course PARI knows about vectors (rows and columns are distinguished, even though mathematically there is no difference) and matrices. Type for example <#2361#>[1,2,3,4]<#2361#>. This gives the row vector whose coordinates are 1, 2, 3 and 4. If you want a column vector, type <#2919#>[1,2,3,4]˜<#2919#>, the tilde meaning of course transpose. You don't see much difference in the output, except for the tilde at the end. However, now type <#2363#>\b<#2363#>: lo and behold, the vector does become a column. This command is used mainly for this purpose.

Type <#2364#>m=[a,b,c;d,e,f]<#2364#>. You have just entered a matrix with 2 rows and 3 columns. Note that the matrix is entered by <#2365#>rows<#2365#> and the rows are separated by semicolons ``;''. The matrix is printed naturally in a rectangle shape. If you want it printed horizontally just as you typed it, type <#2366#>\r<#2366#>, or if you want this type of printing to be the permanent default type <#2367#>\p<#2367#> twice (the first time puts GP in a mode which in the present version you do not want to use). Type <#2368#>\p<#2368#> a third time if you want to come back to the original default.

Now type <#2369#>m[1,2]<#2369#>, <#2370#>m[1,]<#2370#>, <#2371#>m[,2]<#2371#>. Are explanations necessary? (In an expression such as <#2372#>m[j,k]<#2372#>, the <#2373#>j<#2373#> always refers to the row number, and the <#2374#>k<#2374#> to the column number, and the first index is always 1, never 0. This default cannot be changed.)

Even better, type <#2375#>m[1,2]=5;m<#2375#> (the semicolon allows us to put several instructions on the same line. It is an absolute necessity when we program in GP). Now type <#2376#>m[1,]=[15,-17]<#2376#>. No problem. Finally type <#2377#>m[,2]=[j,k]<#2377#>. You have an error message since you have typed a row vector, while <#2378#>m[,2]<#2378#> is a column vector. If you type instead <#2920#>m[,2]=[j,k]˜<#2920#> it works.

Type now <#2380#>h=hilbert(20)<#2380#>. You get the so-called ``Hilbert matrix'' whose coefficient of row <#2381#>i<#2381#> and column <#2382#>j<#2382#> is equal to <#2383#>1/(i+j-1)<#2383#>. Incidentally, the matrix <#2384#>h<#2384#> takes too much room. If you don't want to see it, simply type a semi-colon ``;'' at the end of the line (<#2385#>h=hilbert(20);<#2385#>). This is an example of a ``precomputed'' matrix, built-in PARI. There are only a few. We will see later an example of a much more general construction.

What is interesting about Hilbert matrices is that first their inverses and determinants can be computed explicitly (and the inverse has integer coefficients), and second they are numerically very unstable, which make them a severe test for linear algebra packages in numerical analysis. Of course with PARI, no such problem can occur: since the coefficients are given as rational numbers, the computation will be done exactly, so there cannot be any numerical error. Try it. Type <#2386#>d=det(h)<#2386#> (you have to be a little patient, this is quite a complicated computation). The result is a rational number (of course) of numerator equal to 1 and denominator having 226 decimal digits. How do I know, by the way? I did not count! Instead, simply type <#2387#>1.*d<#2387#>. The result is now in exponential format, and the exponent gives us the answer.

Now type <#2388#>hr=1.*h;<#2388#> (do not forget the semicolon, we don't want to see all the junk!), then <#2389#>dr=det(hr)<#2389#>. You notice two things. First the computation, although not instantaneous, is much faster than in the rational case. The reason for this is that PARI is handling real numbers with 28 digits of accuracy, while in the rational case it is handling integers having up to 226 decimal digits.

The second more important fact is that the result is terribly wrong. If you compare with <#2390#>1.*d<#2390#> computed earlier, which is correct, you will see that only 2 decimals agree! This catastrophic unstability is as already mentioned one of the characteristics of Hilbert matrices. In fact, the situation is much worse than that. Type <#2391#>norml2(1/h-1/(h*1.))<#2391#> (the function <#2392#>norml2<#2392#> gives the square of the L2 norm, i.e. the sum of the squares of the coefficients). Again be patient since computing <#2393#>1/h<#2393#> will take even more time (not much) than computing <#2394#>det(h)<#2394#>. The result is larger than 1050, showing that some coefficients of <#2396#>1/(h*1.)<#2396#> are wrong by as much as 1024 (the largest error is in fact equal to #math770#7.6441024 for the coefficient of row 15 and column 14, which is a 28 digit integer).

To obtain the correct result after rounding for the inverse, we have to use a default precision of 56 digits (try it).

Although vectors and matrices can be entered manually, by typing explicitly their elements, very often the elements satisfy a simple law and one uses a different syntax. For example, assume that you want a vector whose <#2399#>k<#2399#>-th coordinate is equal to <#2921#>kˆ2<#2921#>. No problem, type for example <#2922#>vector(10,k,kˆ2)<#2922#> if you want a vector of length 10. Similarly, if you type

<#2402#>matrix(5,5,j,k,1/(j+k-1))<#2402#>

you will get the Hilbert matrix of order 5 (hence the <#2403#>hilbert<#2403#> function is unnecessary). The <#2404#>j<#2404#> and <#2405#>k<#2405#> represent dummy variables which are used to number the rows and columns respectively (in the case of a vector only one is present of course). You must not forget, in addition to the dimensions of the vector or matrix, to indicate explicitly the names of these variables.

<#2406#>Important warning.<#2406#> The letter <#2407#>i<#2407#> is reserved for the complex number equal to the square root of -1. Hence it is absolutely forbidden to use it as a variable. Try typing <#2924#>vector(10,i,iˆ2)<#2924#>, the error message that you get clearly indicates that GP does not consider <#2409#>i<#2409#> as a variable.


The last PARI types which we have not yet played with are types which are closely linked to number theory (hence people not interested in number theory can skip).

The first is the type ``integermod''. Let us see an example. Type <#2925#>n=10ˆ15+3<#2925#>. We want to know whether <#2411#>n<#2411#> is prime or not. Of course we could make use of the builtin facilities of PARI, but let us do otherwise. We first trial divide by the builtin table of primes, by default up to 500000. We slightly cheat here and use the function <#2412#>smallfact<#2412#> which does exactly this. So type <#2413#>smallfact(n)<#2413#>. The result is a 2 column matrix (as all factoring programs), the first column giving the primes and the second their exponents. Here we get a single row, telling us that <#2414#>n<#2414#> is not divisible by any prime up to the default (500000). We could now trial divide further, or even cheat completely and call the PARI function <#2415#>factor<#2415#>, but before we do this let us see how to get an answer ourselves.

By Fermat's little theorem, if <#2416#>n<#2416#> is prime we must have #math771#an-1≡1(mod n) for all <#2420#>a<#2420#> not divisible by <#2421#>n<#2421#>. Hence we could try this with <#2422#>a=2<#2422#> for example. But #math772#2n-1 is a number with approximately #math773#3⋅1014 digits, hence impossible to write down, even less to compute. But instead type <#2425#>a=mod(2,n)<#2425#>. This creates the number 2 considered now as an element of the ring #math774#R = #tex2html_wrap_inline28262#/n#tex2html_wrap_inline28263#. The elements of R, called integermods, can always be represented by numbers smaller than <#2427#>n<#2427#>, hence very small. Fermat's theorem can be rewritten <#2961#>#math775#an-1 =mod(1,n)<#2961#> in the ring R, and this can be computed very efficiently. Type <#2930#>aˆ(n-1)<#2930#>. The result is definitely <#2431#>not<#2431#> equal to <#2432#>mod(1,n)<#2432#>, thus <#2433#>proving<#2433#> that <#2434#>n<#2434#> is not a prime (if we had obtained <#2435#>mod(1,n)<#2435#> on the other hand, it would have given us a hint that <#2436#>n<#2436#> is maybe prime, but never a proof).

To find the factors is another story. One must use less naive techniques than trial division (or be very patient). To finish this example, type <#2437#>factor(n)<#2437#> to see the factors. Since the smallest factor is 14902357, you would have had to be very patient with trial division!

The second specifically number-theoretic type is the p-adic numbers. I have no room for definitions, so please skip if you have no use for such beasts. A p-adic number is entered as a rational or integer valued expression to which is added <#2931#>O(pˆn)<#2931#> (or simply <#2439#>O(p)<#2439#> if <#2440#>n=1<#2440#>) where <#2441#>p<#2441#> is the prime and <#2442#>n<#2442#> the p-adic precision. Apart from the usual arithmetic operations, you can apply a number of transcendental functions. For example, type <#2932#>n=569+O(7ˆ8)<#2932#>. Then type <#2444#>s=sqrt(n)<#2444#>, you obtain one of the square roots of <#2445#>n<#2445#> (if you want to check, type <#2446#>s*s-n<#2446#>). Type now <#2447#>l=log(n)<#2447#>, then <#2448#>e=exp(l)<#2448#>. If you know about p-adic logarithms, you will not be surprised that <#2449#>e<#2449#> is not equal to <#2450#>n<#2450#>. Type <#2933#>(n/e)ˆ6<#2933#>: <#2452#>e<#2452#> is in fact equal to <#2453#>n<#2453#> times a (p-1)-st root of unity.

Incidentally, if you want to get back the integer 569 from the p-adic number <#2454#>n<#2454#>, type <#2455#>trunc(n)<#2455#>.

The third number-theoretic type is the type ``quadratic number''. This type is specially tailored so that we can easily work in a quadratic extension of a base field (usually #tex2html_wrap_inline28273#). It is a generalization of the type ``complex''. To start, we must specify which quadratic field we want to work in. For this, we use the function <#2456#>quadgen<#2456#> applied to the <#2457#>discriminant<#2457#> <#2458#>d<#2458#> (as opposed to the radicand) of the quadratic field. This returns a number (always printed as <#2459#>w<#2459#>) equal to <#2460#>(d+a)/2<#2460#> where <#2461#>a<#2461#> is equal to 0 or 1 according to whether <#2462#>d<#2462#> is even or odd. The behavior of <#2463#>quadgen<#2463#> is a little special: although its result is always printed as <#2464#>w<#2464#>, the variable <#2465#>w<#2465#> itself is not set to that value. Hence it is necessary to write systematically <#2466#>w=quadgen(d)<#2466#> using the variable name <#2467#>w<#2467#> (or <#2468#>w1<#2468#> etc.. if you have several quadratic fields), otherwise you will be confused.

So type <#2469#>w=quadgen(-163)<#2469#>, then <#2470#>char(w,x)<#2470#> which asks for the characteristic polynomial of <#2471#>w<#2471#> expressed with the variable <#2472#>x<#2472#>. The result shows what <#2473#>w<#2473#> will represent. You can also ask for <#2474#>1.*w<#2474#> to see which root of the quadratic has been taken, but this is rarely necessary. We can now play in the field #math776##tex2html_wrap_inline28278#(#tex2html_wrap_inline28279#). Type for example <#2934#>wˆ10, norm(3+4*w), 1/(4+w)<#2934#>. More interesting, type <#2477#>a=mod(1,23)*w<#2477#> then <#2935#>b=aˆ264<#2935#>. This is a generalization of Fermat's theorem to quadratic fields. If you do not want to see the 23 all the time, type <#2480#>lift(b)<#2480#>. Another example, type <#2937#>p#math777#= #tex2html_wrap_inline28288# + w*#tex2html_wrap_inline28289# +5*w + 7<#2937#>, then <#2483#>norm(p)<#2483#> (or even better <#2484#>simplify(norm(p))<#2484#>, see above). We thus obtain the quartic equation over #tex2html_wrap_inline28291# corresponding to the relative quadratic extension over #math778##tex2html_wrap_inline28293#(w) defined by <#2486#>p<#2486#>.

On the other hand, if you type <#2938#>wr=sqrt(wˆ2)<#2938#>, do not expect to get back <#2488#>w<#2488#>. Instead, you get the numerical value, the function <#2489#>sqrt<#2489#> being considered as a ``transcendental'' function, even though it is algebraic. Type <#2490#>algdep(wr,2)<#2490#>. This is one way to get <#2491#>w<#2491#> back. Similarly, type <#2492#>algdep(sqrt(3*w+5),4)<#2492#>. See the users manual for the function <#2493#>algdep<#2493#>.

The fourth number-theoretic type is the type ``polymod'', i.e. polynomial modulo another polynomial. This type is used to work in algebraic extensions, for example elements of number fields (if the base field is #tex2html_wrap_inline28297#), or elements of finite fields (if the base field is #math779##tex2html_wrap_inline28299#/p#tex2html_wrap_inline28300# for a prime p, defined by an integermod). In a sense it is a generalization of the type quadratic number. The syntax used is the same as for integermods. For example, instead of typing <#2494#>w=quadgen(-163)<#2494#>, you can type <#2939#>w=mod(x,xˆ2-x+41)<#2939#>. Then exactly as in the quadratic case you can type <#2940#>wˆ10, norm(3+4*w), 1/(4+w), a=mod(1,23)*w, b=aˆ264<#2940#>, obtaining of course the same results (type <#2498#>lift(...)<#2498#> if you don't want to see the polynomial <#2941#>xˆ2-x+41<#2941#> repeated all the time). Of course, the basic interest is that you can work in any degree, not only quadratic.

There is however a slight difference in behavior. Keeping our <#2500#>w<#2500#>, type <#2501#>1.*<#2501#>. As you can see, the result is not the same. Type <#2502#>sqrt(w)<#2502#>. Here, we obtain a vector with 2 components, the two components being the principal branch of the square root of all the possible embeddings of <#2503#>w<#2503#> in #tex2html_wrap_inline28314# (NOT the two square roots). More generally, if <#2504#>w<#2504#> was of degree n, we would get an n-component vector, and similarly for transcendental functions.

We have at our disposal the usual arithmetic functions, plus a few others. For example, type <#2505#>a=mod(#math780##tex2html_wrap_inline28316#,#tex2html_wrap_inline28319# - #tex2html_wrap_inline28320# - 1)<#2505#> defining a cubic extension. We can for example ask for <#2942#>b=aˆ7<#2942#>. But now assume we want to express <#2507#>a<#2507#> as a polynomial in <#2508#>b<#2508#>. This is possible since <#2509#>b<#2509#> is also a generator of the same field. No problem, type <#2510#>modreverse(b)<#2510#>. This gives a new defining polynomial for the same field (i.e. the characteristic polynomial of <#2511#>b<#2511#>), and expresses <#2512#>a<#2512#> in terms of this new polymod, i.e. in terms of <#2513#>a<#2513#>.

by1=0 <#9356#>=0<#9358#><#9358#><#9356#>



<#9357#><#9359#>. Arithmetic functions<#9359#><#9357#>


Since PARI is aimed at number theorists, it is not surprising that there exists a large number of arithmetic functions (see the list in the corresponding section of the users manual). We have already seen several, such as <#2515#>factor<#2515#>. Note that <#2516#>factor<#2516#> factors not only integers, but also polynomials. Type for example <#2943#>factor(xˆ15-1)<#2943#>. You can also ask to factor a polynomial modulo a prime p (<#2518#>factmod<#2518#>) and even in a finite field which is not the prime field (<#2519#>factfq<#2519#>).

Evidently, you have functions for computing GCD's, extended GCD's, solving the Chinese remainder theorem and so on.

In addition to the factoring facilities, you have a few functions related to primality tesing such as <#2520#>isprime<#2520#>, <#2521#>ispsp<#2521#> and <#2522#>nextprime<#2522#>. Note that in all these cases, only strong pseudoprimes are produced, there is no sophisticated primality test.

The usual multiplicative arithmetic functions exist (the Möbius μ function (<#2523#>mu<#2523#>) the Euler φ function (<#2524#>phi<#2524#>), the ω and Ω functions (<#2525#>omega<#2525#> and <#2526#>bigomega<#2526#>), the sum of divisors functions (<#2527#>sigma<#2527#> and <#2528#>sigmak<#2528#>), etc...

You can compute continued fractions. For example, if you type <#2529#>\precision=1000<#2529#> then <#2530#>cf(exp(1))<#2530#> you obtain the continued fraction of the base of natural logarithms, which as you can see obeys a very simple pattern (can you prove it?).

A number of more sophisticated functions relative to quadratic fields are also available, such as class numbers (<#2531#>classno<#2531#> and <#2532#>hclassno<#2532#>), fundamental units (<#2533#>unit<#2533#>) and regulator (<#2534#>regula<#2534#>), as well as functions for handling binary quadratic forms.

<#9362#><#9362#> <#9363#>=0<#9365#><#9365#><#9363#>

Appendix A : Installation Guide for the UNIX Versions

1) To print the users' manual, type ``<#2536#>make manual<#2536#>'' in the main directory (after having copied an appropriate Makefile as explained below), or ``<#2537#>make<#2537#>'' in the <#2538#>tex<#2538#> subdirectory. This will create a file <#2539#>users.dvi<#2539#> containing the manual and a table of contents, and a separate <#2540#>index.dvi<#2540#> containing the index. You must then send the two .dvi files to your favorite printer in the usual way.

A tutorial for GP is being written. If you want the available part of the tutorial to be included in the manual, uncomment the line <#2541#>\input tutorial<#2541#> in the file <#2542#>users.tex<#2542#>.

2) To compile the library and the calculator (gp).

a) Choose the Makefile appropriate to your system. Choose <#2543#>Makefile.sun3<#2543#> if your machine is 68020/68030/68040 based. In that case, you must also choose which assembly file to use (see 8) below).

Choose <#2544#>Makefile.sun4<#2544#> if your machine is Sparc based.

Choose <#2545#>Makefile.hppa<#2545#> if your machine has the HP-PA architecture.

For any other machine, use <#2546#>Makefile.port<#2546#>. On DECstations, for example, a few extra modifications are necessary.

For example, if you have a sun4, type <#2547#>cp Makefile.sun4 Makefile<#2547#>.

b) If you have the GNU gcc compiler installed (we recommend that you do), then replace in the Makefile <#2548#>CC=cc<#2548#> by <#2549#>CC=gcc<#2549#>, add the flag <#2550#>-g<#2550#> in the CFLAGS if you know how to use dbx or gdb and want to debug PARI yourself, and add the flag <#2551#>-traditional<#2551#> to the compilation options of <#2552#>plot.o<#2552#> if in addition you are under suntools.

c) If you are not running under suntools or X11, change in the Makefile <#2553#>plot.sun<#2553#> to <#2554#>plot.null<#2554#>. If you are using the X11 window system, change <#2555#>plot.sun<#2555#> (or <#2556#>plot.null<#2556#> in the port version) to <#2557#>plot.X<#2557#>. Some slight modifications may have to be made so that the compiler knows where to access the X11 libraries.

d) If you have the GNU readline library installed (distributed with gdb), replace <#2558#>gp.c<#2558#> by <#2559#>gpreadline.c<#2559#>, i.e. <#2560#>mv gp.c gpold.c; mv gpreadline.c gp.c<#2560#>. Then in the Makefile add <#2561#>-lreadline -ltermcap<#2561#> to the list of libraries in the compilation line for gp. Note: if you are compiling with sunview (<#2562#>-lsuntool -lsunwindow -lpixrect<#2562#>) you will have an error message about a redefined function <#2563#>rl_copy<#2563#>. Since the sun source code is not available, the way out is to recompile the GNU readline library by changing in the file readline.c <#2564#>rl_copy<#2564#> to some weird name, say <#2565#>rl_copy_kludge<#2565#>. The use of the readline and history library (suggested to me by E. Roeder) is not yet documented but is similar to emacs commands. However note that it is incompatible with SUN commandtools (but not with shelltools).

e) Some special-purpose application programs may be available in Pari and GP. By default in the distribution they are available under GP, but are not linked in with the other library modules during the creation of the file <#2566#>libpari.a<#2566#>. In the present version 1.37, these are the functions <#2567#>buchimag()<#2567#> and <#2568#>buchreal()<#2568#>, both in the file <#2569#>buch.c<#2569#>. If you want to have the smallest possible GP executable, you will have to do two things. First suppress all occurrences of <#2570#>buch.c<#2570#> and <#2571#>buch.o<#2571#> in the <#2572#>Makefile<#2572#>. Second, in the files <#2573#>anal.c, helpmessages.c<#2573#> and <#2574#>gencom.h<#2574#>, suppress the lines corresponding to <#2575#>buchimag()<#2575#> and <#2576#>buchreal()<#2576#>. If on the contrary you want these functions to be available in library mode as well as under GP, in the <#2577#>Makefile<#2577#> add <#2578#>buch.o<#2578#> to the files which are listed during the creation of <#2579#>libpari.a<#2579#>.

f) Then simply type ``<#2580#>make<#2580#>'' in the distribution directory. Be sure to ``<#2581#>make clean<#2581#>'' before changing to another architecture using the same file system. Note that the non 68020 versions are slower, especially the ``port'' version.

g) To test the executable, run gp on the file <#2582#>testin<#2582#> as follows: <#2583#>gp;SPMlt;testin;SPMgt; fileout <#2583#>. Then do a <#2584#>diff<#2584#> with the file <#2585#>testout<#2585#>. If any difference occurs other than the heading (version number and type), and the functions <#2586#>random()<#2586#> and <#2587#>tchirnhausen()<#2587#> this means something is wrong. Most probably with your installation procedure, but it may be a bug in the system, in which case we would appreciate a report. Note that <#2588#>testin<#2588#> is not a severe test and is quite fast (a few minutes), but does check at least one instance of every function. Do NOT forget the atfer ;SPMgt;, since <#2589#>testin<#2589#> tests one special error message. Testin does not check the optional functions such as buchimag and buchreal. You should check them yourself (you can take as examples the commented calls of these functions which are in the <#2590#>testin<#2590#> file).

h) If you want to test the graphic routines, use instead <#2591#>gp;SPMlt;testplotin<#2591#>. You will have to click 5 times on the mouse button after seeing each image (under X11; under suntools you must kill the images).

The <#2592#>testin<#2592#> script produces a Postscript file <#2593#>pari.ps<#2593#> which you can send to a Postscript printer. The printed output should be similar (although not identical) to the screen images.

3) To install the PARI library so that it can be easily used from a user program, create the directory <#2594#>/usr/include/pari-include<#2594#>, and type ``<#2595#>make install<#2595#>''. This puts the executable <#2596#>gp<#2596#> in <#2597#>/usr/local/bin<#2597#>, the library in the directory <#2598#>/usr/local/lib<#2598#>, and the necessary include files in <#2599#>/usr/include/pari-include<#2599#>. If these directories do not suit your installation, change the <#2600#>LIBDIR<#2600#> or the <#2601#>INCLUDEDIR<#2601#> in the <#2602#>Makefile<#2602#>.

4) Once installed, to link to the PARI library just add <#2603#>-lpari<#2603#> in your link command. A sample makefile (<#2604#>Makesimple<#2604#>) is given for gp itself. All modifications made to the Makefile should of course be made on the Makesimple file.

5) If you want to use <#2605#>gp<#2605#> under <#2606#>gnuemacs<#2606#> (see section 3.10 of the users' manual) change the pathnames in the file <#2607#>pari.el<#2607#> to suit your installation, and read the file <#2608#>pari.txt<#2608#>.

6) If you want to get rid of your .o files and the created binaries in the working directory, type ``<#2609#>make clean<#2609#>''.

7) For the example of section 4.3 of the user's manual, type <#2610#>make<#2610#> in the directory <#2611#>examples<#2611#>. Two complete sample GP programs are also given in that directory (Shanks's SQUFOF factoring method and a general class group and fundamental unit algorithm). See the file <#2612#>Newin1.37<#2612#> for more explanations.

8) The syntax used by the SUN 3 assembler is not standard. On the MacII distribution, the correct Mac assembler syntax is given. In the present distribution, in addition to <#2613#>mp.s<#2613#> which has the SUN 3 syntax, two files called <#2614#>mp.news<#2614#> and <#2615#>mp.ami<#2615#> are included so as to help people having machines with a 680x0 processor (x ;SPMgt; = 2) but a more standard syntax.

This may not correspond to the actual syntax used, but may be closer than <#2616#>mp.s<#2616#>. In principle, apart from whitespace and the different syntax, the semantics of the two files should be identical. In case of conflict, correct <#2617#>mp.news<#2617#> or <#2618#>mp.ami<#2618#> (i.e. NEVER touch <#2619#>mp.s<#2619#>).

The file <#2620#>mp.news<#2620#> has been successfully tested on a Sony NEWS, and the file <#2621#>mp.ami<#2621#> on a Commodore amiga 2500 running Lattice C 5.10.

9) Send bugs, comments, etc...to:

<#2622#>pari@alioth.greco-prog.fr <#2622#>

10) Good luck!

<#9368#><#9368#> <#9369#>=0<#9371#><#9371#><#9369#>

Appendix B : A sample Makefile

We assume that you have installed the PARI library and include files as explained in Appendix A or in the installation guide. If you chose differently any of the directory names, please change them accordingly in the Makefiles.

If the program example that we have given is in the file mattrans.c (say as the first of several matrix transcendental functions), then a sample Makefile is the following:

<#2945#><#2624#><#2624#> CC = cc CFLAGS = -O -I/usr/include/pari-include <#2625#><#2625#> all:;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;mattrans <#2626#><#2626#> mattrans:;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;mattrans.c ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;$(CC) $(CFLAGS) -o mattrans mattrans.c -lpari -lm <#2945#>

<#9374#><#9374#> <#9375#>=0<#9377#><#9377#><#9375#>

Appendix C : A complete program

We give here the listing of the program seen in detail in section 4.3, with the slight modifications explained at the end of that section.

<#2965#><#2628#><#2628#> #include ;SPMlt;genpari.h;SPMgt; <#2629#><#2629#> GEN matexp(); <#2630#><#2630#> main() { ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;GEN x,y; ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;long prec,d; ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;char s[512]; <#2631#><#2631#> ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;init(1000000,2); /* take a million bytes of memory for the stack */ ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;printf(;SPMquot;precision of the computation in decimal digits? ;SPMquot;); ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;scanf(;SPMquot;d;SPMquot;,d);if(d;SPMlt;0) prec=3;else prec=d*K1+3; ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;printf(;SPMquot;input your matrix in GP format:#math781#\n;SPMquot;); ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;s[0]=0;while(!s[0]) gets(s);x=lisexpr(s); ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;y=matexp(x,prec); ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;sor(y,'g',d,0); } <#2632#><#2632#> GEN matexp(x,prec) ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;GEN x; ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;long prec; <#2633#><#2633#> { ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;GEN y,r,s,p1,p2; ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;long tx=typ(x),lx=lg(x),i,k,n,lbot,ltop; <#2634#><#2634#> /* check that x is a square matrix */ <#2635#><#2635#> ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;if(tx!=19) {printf(;SPMquot;This expression is not a matrix#math782#\n;SPMquot;);return(gzero);} ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;if(lx!=lg(x[1])) {printf(;SPMquot;This matrix is not square#math783#\n;SPMquot;);return(gzero);} <#2636#><#2636#> /* convert x to real or complex of real and compute its L2 norm */ <#2637#><#2637#> ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;ltop=avma;s=gzero; ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;r=cgetr(prec+1);gaffsg(1,r);p1=gmul(r,x); ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;for(i=1;i;SPMlt;lx;i++) s=gadd(s,gnorml2(p1[i])); ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;if(typ(s)==2) setlg(s,3); ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;s=gsqrt(s,3); /* we do not need much precision on s */ <#2638#><#2638#> /* if s;SPMlt;1, we are happy */ <#2639#><#2639#> ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;if(expo(s);SPMlt;0) n=0; ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;else {n=expo(s)+1;p1=gmul2n(p1,-n);setexpo(s,-1);} <#2640#><#2640#> /* initialisations before the loop */ <#2641#><#2641#> ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;y=gscalmat(r,lx-1); /* this creates the scalar matrix r#math784#*#tex2html_wrap_inline28344# */ ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;p2=p1;r=s;k=1; ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;lbot=avma;y=gadd(y,p2); <#2643#><#2643#> /* now the main loop */ <#2644#><#2644#> ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;while(expo(r) ;SPMgt;= -32*(prec-1)) ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;{ ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;k++;p2=gdivgs(gmul(p2,p1),k);r=gdivgs(gmul(s,r),k); ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;lbot=avma;y=gadd(y,p2); ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;} <#2645#><#2645#> /* now square back n times if necessary */ <#2646#><#2646#> ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;for(i=0;i;SPMlt;n;i++) {lbot=avma;y=gmul(y,y);} ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;y=gerepile(ltop,lbot,y); ;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;return(y); }<#2965#>

<#9381#><#9381#> <#9382#>=0<#9384#><#9384#><#9382#>

Appendix D : Summary of available Constants

In this appendix we give the list of predefined constants available in the PARI library.

<#2947#><#2648#><#2648#> <#2649#>gzero (zero)<#2649#> see 4.1.1. <#2650#>gun (un)<#2650#> see 4.1.1. <#2651#>gdeux (deux)<#2651#> see 4.1.1. <#2652#>ghalf (lhalf)<#2652#> see 4.1.1. <#2653#>gi<#2653#> see 4.1.1. <#2654#>polun[] (lpolun[])<#2654#> see 4.1.1. <#2655#>polx[] (lpolx[])<#2655#> see 4.1.1.<#2947#>

<#2656#>geuler<#2656#>. This is Euler's constant, and is in the heap, <#2657#>not<#2657#> in the PARI stack. It is not initialized, and if you want to use it you must call <#2658#>consteuler<#2658#>(prec) ( see 3.3.18.).

<#2659#>gpi<#2659#>. This is the number pi, and is in the heap, <#2660#>not<#2660#> in the PARI stack. It is not initialized, and if you want to use it you must call <#2661#>constpi<#2661#>(prec) (see 3.3.27.).

<#2662#>bern<#2662#>(i). This is the 2i-th Bernoulli number (B0 = 1, B2 = 1/6, B4 = - 1/30, etc...) The Bernoulli numbers are in the heap and <#2663#>not<#2663#> in the PARI stack, and are not initialized. To initialize them you must use the function <#2664#>mpbern<#2664#> which has the following syntax:

<#2665#>void mpbern(long n, long prec);<#2665#>

The effect of this function is to create the even numbered bernoulli numbers up to B2n-2 <#2667#>as real numbers<#2667#> of precision prec. They can then be used with the macro <#2668#>bern<#2668#>(i). Note that this is not a function but simply an abbreviation, hence care must be taken that i is inside the right bounds (i.e. #math785#0≤in - 1) before using it, since no checking is done in PARI itself.

Finally, one has access to a table of (differences of) primes through the pointer <#2669#>diffptr<#2669#>. This is used as follows: after <#2670#>init<#2670#> has been called, this table is initialized with the differences of primes up to 500000 (default which can trivially be changed by calling <#2671#>init<#2671#> with different arguments, see 4.1.1). Then one declares <#2672#>byteptr d=diffptr;<#2672#>, where d is the name of the pointer that one uses. This will point to the first difference in the table, i.e. 2. To get to the next difference, just do <#2673#>d++<#2673#>.

In addition, some single or double-precision real numbers are predefined, and their list is in the file <#2674#>gencom.h<#2674#>

=-1 <#9388#><#9388#> <#9389#>=0<#9391#><#9391#><#9389#>

Table of Contents
=users.toc

;''