Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Testing latest pari + WASM + node.js... and it works?! Wow.

28495 views
License: GPL3
ubuntu2004
1
% Copyright (c) 2000 The PARI Group
2
%
3
% This file is part of the PARI/GP documentation
4
%
5
% Permission is granted to copy, distribute and/or modify this document
6
% under the terms of the GNU General Public License
7
\chapter{Overview of the PARI system}
8
9
\section{Introduction}
10
11
\noindent
12
PARI/GP is a specialized computer algebra system, primarily aimed at number
13
theorists, but has been put to good use in many other different fields, from
14
topology or numerical analysis to physics.
15
16
Although quite an amount of symbolic manipulation is possible, PARI does
17
badly compared to systems like Axiom, Magma, Maple, Mathematica, Maxima, or
18
Reduce on such tasks, e.g.~multivariate polynomials, formal integration,
19
etc. On the other hand, the three main advantages of the system are its
20
speed, the possibility of using directly data types which are familiar to
21
mathematicians, and its extensive algebraic number theory module (from
22
the above-mentioned systems, only Magma provides similar features).
23
24
Non-mathematical strong points include the possibility to program either
25
in high-level scripting languages or with the PARI library, a mature system
26
(development started in the mid eighties) that was used to conduct and
27
disseminate original mathematical research, while building a large user
28
community, linked by helpful mailing lists and a tradition of great user
29
support from the developers. And, of course, PARI/GP is Free Software,
30
covered by the GNU General Public License, either version 2 of the License or
31
(at your option) any later version.
32
33
PARI is used in three different ways:
34
35
\quad 1) as a library \tet{libpari}, which can be called from an upper-level
36
language application, for instance written in ANSI C or C$++$;
37
38
\quad 2) as a sophisticated programmable calculator, named \tet{gp}, whose
39
language \tet{GP} contains most of the control instructions of a standard
40
language like C;
41
42
\quad 3) the compiler \tet{gp2c} translates GP code to C, and loads it into
43
the \kbd{gp} interpreter. A typical script compiled by \kbd{gp2c} runs 3 to 10
44
times faster. The generated C code can be edited and optimized by hand. It
45
may also be used as a tutorial to \kbd{libpari} programming.
46
47
The present Chapter 1 gives an overview of the PARI/GP system; \kbd{gp2c} is
48
distributed separately and comes with its own manual. Chapter 2 describes the
49
\kbd{GP} programming language and the \kbd{gp} calculator. Chapter 3
50
describes all routines available in the calculator. Programming in library
51
mode is explained in Chapters 4 and 5 in a separate booklet: \emph{User's
52
Guide to the PARI library} (\kbd{libpari.dvi}.
53
54
A tutorial for \kbd{gp} is provided in the standard distribution: \emph{A
55
tutorial for PARI/GP} (\kbd{tutorial.dvi}) and you should read this first.
56
You can then start over and read the more boring stuff which lies ahead. You
57
can have a quick idea of what is available by looking at the \kbd{gp}
58
reference card (\kbd{refcard.dvi} or \kbd{refcard.ps}). In case of need, you
59
can refer to the complete function description in Chapter 3.
60
61
\subsectitle{How to get the latest version} Everything can be found on
62
PARI's home page:
63
$$\url{http://pari.math.u-bordeaux.fr/}.$$
64
%
65
From that point you may access all sources, some binaries,
66
version information, the complete mailing list archives, frequently asked
67
questions and various tips. All threaded and fully searchable.
68
69
\subsectitle{How to report bugs} Bugs are submitted online to our Bug
70
Tracking System, available from PARI's home page, or directly from the URL
71
$$\url{http://pari.math.u-bordeaux.fr/Bugs/}.$$
72
%
73
Further instructions can be found on that page.
74
75
\section{Multiprecision kernels / Portability}
76
77
The PARI multiprecision kernel comes in three non exclusive flavors. See
78
Appendix~A for how to set up these on your system; various compilers are
79
supported, but the GNU \kbd{gcc} compiler is the definite favorite.
80
81
A first version is written entirely in ANSI C, with a C++-compatible syntax,
82
and should be portable without trouble to any 32 or 64-bit computer having no
83
drastic memory constraints. We do not know any example of a computer where a
84
port was attempted and failed.
85
86
In a second version, time-critical parts of the kernel are written in
87
inlined assembler. At present this includes
88
89
\item the whole ix86 family (Intel, AMD, Cyrix) starting at the 386, up to
90
the Xbox gaming console, including the Opteron 64 bit processor.
91
92
\item three versions for the Sparc architecture: version 7, version 8 with
93
SuperSparc processors, and version 8 with MicroSparc I or II processors.
94
UltraSparcs use the MicroSparc II version;
95
96
\item the DEC Alpha 64-bit processor;
97
98
\item the Intel Itanium 64-bit processor;
99
100
\item the PowerPC equipping old macintoshs (G3, G4, etc.);
101
102
\item the HPPA processors (both 32 and 64 bit);
103
104
A third version uses the GNU MP library to implement most of its
105
multiprecision kernel. It improves significantly on the native one for large
106
operands, say 100 decimal digits of accuracy or more. You \emph{should}
107
enable it if GMP is present on your system. Parts of the first version are
108
still in use within the GMP kernel, but are scheduled to disappear.
109
110
A historical version of the PARI/GP kernel, written in 1985, was specific to
111
680x0 based computers, and was entirely written in MC68020 assembly language.
112
It ran on SUN-3/xx, Sony News, NeXT cubes and on 680x0 based Macs. It is no
113
longer part of the PARI distribution; to run PARI with a 68k assembler
114
micro-kernel, use the GMP kernel!
115
116
\section{The PARI types} \label{se:start}
117
118
\noindent The GP language is not typed in the traditional sense; in
119
particular, variables have no type. In library mode, the type of all PARI
120
objects is \kbd{GEN}, a generic type. On the other hand, it is dynamically
121
typed: each object has a specific internal type, depending on the
122
mathematical object it represents.
123
124
The crucial word is recursiveness: most of the PARI types are recursive. For
125
example, the basic internal type \typ{COMPLEX} exists. However, the
126
components (i.e.~the real and imaginary part) of such a ``complex number''
127
can be of any type. The only sensible ones are integers (we are then in
128
$\Z[i]$), rational numbers ($\Q[i]$), real numbers ($\R[i]=\C$), or even
129
elements of $\Z/n\Z$ (in $(\Z/n\Z)[t]/(t^2+1)$), or $p$-adic numbers when
130
$p\equiv 3 \mod 4$ ($\Q_{p}[i]$). This feature must not be used too rashly in
131
library mode: for example you are in principle allowed to create objects
132
which are ``complex numbers of complex numbers''. (This is not possible under
133
\kbd{gp}.) But do not expect PARI to make sensible use of such objects: you
134
will mainly get nonsense.
135
136
On the other hand, it \emph{is} allowed to have components of different, but
137
compatible, types, which can be freely mixed in basic ring operations $+$ or
138
$\times$. For example, taking again complex numbers, the real part could be
139
an integer, and the imaginary part a rational number. On the other hand, if
140
the real part is a real number, the imaginary part cannot be an integer
141
modulo $n$ !
142
143
Let us now describe the types. As explained above, they are built recursively
144
from basic types which are as follows. We use the letter $T$ to designate any
145
type; the symbolic names \typ{xxx} correspond to the internal representations
146
of the types.\medskip
147
\settabs\+xxxxxx&typexxxxxxxxxxxxx&xxxxxxxxxxxxx&xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\cr
148
%
149
\+&type \tet{t_INT}& $\Z$& Integers (with arbitrary
150
precision)\sidx{integer}\cr
151
%
152
\+&type \tet{t_REAL}& $\R$& Real numbers (with arbitrary precision)\sidx{real
153
number}\cr
154
%
155
\+&type \tet{t_INTMOD}& $\Z/n\Z$& Intmods (integers modulo
156
$n$)\varsidx{intmod}\cr
157
%
158
\+&type \tet{t_FRAC}& $\Q$& Rational numbers (in irreducible
159
form)\sidx{rational number}\cr
160
%
161
\+&type \tet{t_FFELT}& $\F_q$& Finite field element\sidx{finite field
162
element}\cr
163
%
164
%
165
\+&type \tet{t_COMPLEX}& $T[i]$& Complex numbers\sidx{complex number}\cr
166
%
167
\+&type \tet{t_PADIC}& $\Q_p$& $p$-adic\sidx{p-adic number} numbers\cr
168
%
169
\+&type \tet{t_QUAD}& $\Q[w]$& Quadratic Numbers (where
170
$[\Z[w]:\Z]=2$)\sidx{quadratic number}\cr
171
%
172
\+&type \tet{t_POLMOD}& $T[X]/(P)$& Polmods (polynomials modulo
173
$P\in T[X]$)\varsidx{polmod}\cr
174
%
175
\+&type \tet{t_POL}& $T[X]$& Polynomials \sidx{polynomial}\cr
176
%
177
\+&type \tet{t_SER}& $T((X))$& Power series (finite Laurent
178
series)\sidx{power series}\cr
179
%
180
\+&type \tet{t_RFRAC}& $T(X)$& Rational functions (in irreducible
181
form)\sidx{rational function}\cr
182
%
183
\+&type \tet{t_VEC}& $T^n$& Row (i.e.~horizontal) vectors\sidx{row vector}\cr
184
%
185
\+&type \tet{t_COL}& $T^n$& Column (i.e.~vertical) vectors\sidx{column
186
vector}\cr
187
%
188
\+&type \tet{t_MAT}& ${\cal M}_{m,n}(T)$& Matrices\sidx{matrix}\cr
189
%
190
\+&type \tet{t_LIST}& $T^n$& Lists\sidx{list}\cr
191
%
192
\+&type \tet{t_STR}& & Character strings\sidx{string}\cr
193
%
194
\+&type \tet{t_CLOSURE}& & Functions\cr
195
%
196
\+&type \tet{t_ERROR}& & Error messages\cr
197
%
198
\+&type \tet{t_INFINITY}& & $-\infty$ and $+\infty$\cr
199
200
\noindent and where the types $T$ in recursive types can be different in each
201
component. \sidx{scalar type} The first nine basic types, from \typ{INT} to
202
\typ{POLMOD}, are called scalar types because they essentially occur as
203
coefficients of other more complicated objects. Type \typ{POLMOD} is used to
204
define algebraic extensions of a base ring, and as such is a scalar type.
205
206
In addition, there exist the type \tet{t_QFB} for integral
207
binary quadratic forms, and the internal type \tet{t_VECSMALL}. The latter
208
holds vectors of small integers\sidx{vecsmall}, whose absolute value is
209
bounded by $2^{31}$ (resp.~$2^{63}$) on 32-bit, resp.~64-bit, machines. They
210
are used internally to represent permutations, polynomials or matrices over a
211
small finite field, etc.
212
213
Every PARI object (called \tet{GEN} in the sequel) belongs to one of these
214
basic types. Let us have a closer look.
215
216
\subsec{Integers and reals} They are of
217
arbitrary and varying length (each number carrying in its internal
218
\sidx{integer}\sidx{real number}
219
representation its own length or precision) with the following mild
220
restrictions (given for 32-bit machines, the restrictions for 64-bit machines
221
being so weak as to be considered nonexistent): integers must be in absolute
222
value less than $2^{536870815}$ (i.e.~roughly 161614219 decimal digits). The
223
precision of real numbers is also at most 161614219 significant decimal
224
digits, and the binary exponent must be in absolute value less than
225
$2^{29}$, resp. $2^{61}$, on 32-bit, resp.~64-bit machines.
226
227
Integers and real numbers are nonrecursive types.
228
229
\subsec{Intmods, rational numbers, $p$-adic numbers, polmods, and rational
230
functions} These are recursive, but in a restricted way.
231
\sidx{intmod}\sidx{rational number}\sidx{p-adic number}\sidx{polmod}
232
233
For intmods or polmods, there are two components: the modulus, which must
234
be of type integer (resp.\ polynomial), and the representative number (resp.\
235
polynomial).
236
237
For rational numbers or rational functions, there are also only two
238
components: the numerator and the denominator, which must both be of type
239
integer (resp.\ polynomial).
240
241
\def\limproj{{\displaystyle\lim_{\textstyle\longleftarrow}}}
242
243
Finally, $p$-adic numbers have three components: the prime $p$, the
244
``modulus'' $p^k$, and an approximation to the $p$-adic number. Here $\Z_p$
245
is considered as the projective limit $\limproj \Z/p^k\Z$ via its finite
246
quotients, and $\Q_p$ as its field of fractions. Like real numbers, the
247
codewords contain an exponent, giving the $p$-adic valuation of the number,
248
and also the information on the precision of the number, which is
249
redundant with $p^k$, but is included for the sake of efficiency.
250
251
\subsec{Finite field elements}\sidx{finite field element}
252
The exact internal format depends of the finite field size, but it includes
253
the field characteristic $p$, an irreducible polynomial $T\in\F_p[X]$
254
defining the finite field $\F_p[X]/(T)$ and the element expressed as
255
a polynomial in (the class of) $X$.
256
257
\subsec{Complex numbers and quadratic numbers}\sidx{complex
258
number}\sidx{quadratic number} Quadratic numbers are numbers of the form
259
$a+bw$, where $w$ is such that $[\Z[w]:\Z]=2$, and more precisely $w=\sqrt
260
d/2$ when $d\equiv 0 \mod 4$, and $w=(1+\sqrt d)/2$ when $d\equiv 1 \mod 4$,
261
where $d$ is the discriminant of a quadratic order. Complex numbers
262
correspond to the important special case $w=\sqrt{-1}$.
263
264
Complex numbers are partially recursive: the two components $a$
265
and $b$ can be of type \typ{INT}, \typ{REAL}, \typ{INTMOD}, \typ{FRAC}, or
266
\typ{PADIC}, and can be mixed, subject to the limitations mentioned above.
267
For example, $a+bi$ with $a$ and $b$ $p$-adic is in $\Q_p[i]$, but this is
268
equal to $\Q_p$ when $p\equiv 1 \mod 4$, hence we must exclude these $p$ when
269
one explicitly uses a complex $p$-adic type. Quadratic numbers are more
270
restricted: their components may be as above, except that \typ{REAL} is not
271
allowed.
272
273
\subsec{Polynomials, power series, vectors, matrices}
274
\sidx{polynomial}\sidx{power series}\sidx{vector}\sidx{matrix}
275
They are completely recursive, over a commutative base ring: their components
276
can be of any type, and types can be mixed (however beware when doing
277
operations). Note in particular that a polynomial in two variables is simply
278
a polynomial with polynomial coefficients. Polynomials or matrices over
279
noncommutative rings are not supported.
280
281
In the present version \vers{} of PARI, it is not possible to handle
282
conveniently power series of power series, i.e.~power series in several
283
variables. However power series of polynomials (which are power series in
284
several variables of a special type) are OK. This is a difficult design
285
problem: the mathematical problem itself contains some amount of imprecision,
286
and it is not easy to design an intuitive generic interface for such beasts.
287
288
\subsec{Strings} These contain objects just as they would be printed by the
289
\kbd{gp} calculator.
290
291
\subsec{Zero} What is zero? This is a crucial question in all computer
292
systems. The answer we give in PARI is the following. For exact types, all
293
zeros are equivalent and are exact, and thus are usually represented as an
294
integer \idx{zero}. The problem becomes nontrivial for imprecise types:
295
there are infinitely many distinct zeros of each of these types! For
296
$p$-adics and power series the answer is as follows: every such object,
297
including 0, has an exponent $e$. This $p$-adic or $X$-adic zero is
298
understood to be equal to $O(p^e)$ or $O(X^e)$ respectively.
299
\label{se:whatzero}
300
301
Real numbers also have exponents and a real zero is in fact $O(2^e)$ where
302
$e$ is now usually a negative binary exponent. This of course is printed as
303
usual for a floating point number ($0.00\cdots$ or $0.Exx$ depending on the
304
output format) and not with a $O$ symbol as with $p$-adics or power series.
305
With respect to the natural ordering on the reals we make the following
306
convention: whatever its exponent a real zero is smaller than any positive
307
number, and any two real zeroes are equal.
308
309
\section{The PARI philosophy}
310
The basic principles which govern PARI is that operations and functions
311
should, firstly, give as exact a result as possible, and secondly, be
312
permitted if they make any kind of sense.
313
314
In this respect, we make an important distinction between exact and inexact
315
objects: by definition, types \typ{REAL}, \typ{PADIC} or \typ{SER} are
316
imprecise. A PARI object having one of these imprecise types anywhere in
317
its tree is \emph{inexact}, and \emph{exact} otherwise. No loss of accuracy
318
(rounding error) is involved when dealing with exact objects. Specifically,
319
an exact operation between exact objects will yield an exact object. For
320
example, dividing 1 by 3 does not give $0.333\cdots$, but the rational number
321
$(1/3)$. To get the result as a floating point real number, evaluate
322
\kbd{1./3} or \kbd{0.+1/3}.
323
324
Conversely, the result of operations between imprecise objects, although
325
inexact by nature, will be as precise as possible. Consider for example the
326
addition of two real numbers $x$ and $y$. The \idx{accuracy} of the result is
327
\emph{a priori} unpredictable; it depends on the precisions of $x$ and $y$,
328
on their sizes, and also on the size of $x+y$. From this data, PARI works out
329
the right precision for the result. Even if it is working in calculator mode
330
\kbd{gp}, where there is a notion of \idx{default precision}, its value is
331
only used to convert exact types to inexact ones.
332
333
In particular, if an operation involves objects of different accuracies, some
334
digits will be disregarded by PARI. It is a common source of errors to
335
forget, for instance, that a real number is given as $r + 2^e \varepsilon$
336
where $r$ is a rational approximation, $e$ a binary exponent and
337
$\varepsilon$ is a nondescript real number less than 1 in absolute value.
338
Hence, any number less than $2^e$ may be treated as an exact zero:
339
\bprog
340
? 0.E-28 + 1.E-100
341
%1 = 0.E-28
342
? 0.E100 + 1
343
%2 = 0.E100
344
@eprog
345
\noindent As an exercise, if \kbd{a = 2\pow (-100)}, why do \kbd{a + 0.} and
346
\kbd{a * 1.} differ?
347
348
The second principle is that PARI operations are in general quite permissive.
349
For instance taking the exponential of a vector should not make sense.
350
However, it frequently happens that one wants to apply a given function
351
to all elements in a vector. This is easily done using a loop,
352
or using the \tet{apply} built-in function, but in fact PARI assumes that
353
this is exactly what you want to do when you apply a scalar function to a
354
vector. Taking the exponential of a vector will do just that, so no work is
355
necessary. Most transcendental functions work in the same way\footnote{*}{An
356
ambiguity arises with square matrices. PARI always considers that you want to
357
do componentwise function evaluation in this context, hence to get for
358
example the standard exponential of a square matrix you would need to
359
implement a different function.}.
360
361
In the same spirit, when objects of different types are combined they
362
are first automatically mapped to a suitable ring, where the computation
363
becomes meaningful:
364
\bprog
365
? 1/3 + Mod(1,5)
366
%1 = Mod(3, 5)
367
? I + O(5^9)
368
%2 = 2 + 5 + 2*5^2 + 5^3 + 3*5^4 + 4*5^5 + 2*5^6 + 3*5^7 + O(5^9)
369
? Mod(1,15) + Mod(1,10)
370
%3 = Mod(2, 5)
371
@eprog
372
The first example is straightforward: since $3$ is invertible mod $5$, $(1/3)$
373
is easily mapped to $\Z/5\Z$. In the second example, \kbd{I} stands for the
374
customary square root of $-1$; we obtain a $5$-adic number, $5$-adically
375
close to a square root of $-1$. The final example is more problematic, but
376
there are natural maps from $\Z/15\Z$ and $\Z/10\Z$ to $\Z/5\Z$, and the
377
computation takes place there.
378
379
\section{Operations and functions}
380
381
The available operations and functions in PARI are described in detail in
382
Chapter 3. Here is a brief summary:
383
384
\subsec{Standard arithmetic operations}
385
386
\noindent
387
Of course, the four standard operators \kbd{+}, \kbd{-}, \kbd{*}, \kbd{/}
388
exist. We emphasize once more that division is, as far as possible,
389
an exact operation: $4$ divided by $3$ gives \kbd{(4/3)}. In addition to
390
this, operations on integers or polynomials, like \b{} (Euclidean
391
division), \kbd{\%} (Euclidean remainder) exist; for integers, {\b{/}}
392
computes the quotient such that the remainder has smallest possible absolute
393
value. There is also the exponentiation operator \kbd{\pow }, when the
394
exponent is of type integer; otherwise, it is considered as a transcendental
395
function. Finally, the logical operators \kbd{!} (\kbd{not} prefix operator),
396
\kbd{\&\&} (\kbd{and} operator), \kbd{||} (\kbd{or} operator) exist, giving
397
as results \kbd{1} (true) or \kbd{0} (false).
398
399
\subsec{Conversions and similar functions}
400
401
\noindent
402
Many conversion functions are available to convert between different types.
403
For example floor, ceiling, rounding, truncation, etc\dots. Other simple
404
functions are included like real and imaginary part, conjugation, norm,
405
absolute value, changing precision or creating an intmod or a polmod.
406
407
\subsec{Transcendental functions}
408
409
\noindent
410
They usually operate on any complex number, power series, and some also on
411
$p$-adics. The list is ever-expanding and of course contains all the
412
elementary functions (exp/log, trigonometric functions), plus many others
413
(modular functions, Bessel functions, polylogarithms\dots). Recall that by
414
extension, PARI usually allows a transcendental function to operate
415
componentwise on vectors or matrices.
416
417
\subsec{Arithmetic functions}
418
419
\noindent
420
Apart from a few like the factorial function or the Fibonacci numbers, these
421
are functions which explicitly use the prime factor decomposition of
422
integers. The standard functions are included. A number of factoring methods
423
are used by a rather sophisticated factoring engine (to name a few, Shanks's
424
SQUFOF, Pollard's rho, Lenstra's ECM, the MPQS quadratic sieve). These
425
routines output strong pseudoprimes, which may be certified by the APRCL
426
test.
427
428
There is also a large package to work with algebraic number fields. All the
429
usual operations on elements, ideals, prime ideals, etc.~are available.
430
More sophisticated functions are also implemented, like solving Thue
431
equations, finding integral bases and discriminants of number fields,
432
computing class groups and fundamental units, computing in relative number
433
field extensions, Galois and class field theory, and also many functions
434
dealing with elliptic curves over $\Q$ or over local fields.
435
436
\subsec{Other functions}
437
438
\noindent
439
Quite a number of other functions dealing with polynomials (e.g.~finding
440
complex or $p$-adic roots, factoring, etc), power series (e.g.~substitution,
441
reversion), linear algebra (e.g.~determinant, characteristic polynomial,
442
linear systems), and different kinds of recursions are also included. In
443
addition, standard numerical analysis routines like univariate integration
444
(using the double exponential method), real root finding (when the root is
445
bracketed), polynomial interpolation, infinite series evaluation, and
446
plotting are included.
447
\medskip
448
449
And now, you should really have a look at the tutorial before proceeding.
450
\newpage
451
452