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{Functions and Operations Available in PARI and GP}
8
\label{se:functions}
9
10
The functions and operators available in PARI and in the GP/PARI calculator
11
are numerous and ever-expanding. Here is a description of the ones available
12
in version \vers. It should be noted that many of these functions accept
13
quite different types as arguments, but others are more restricted. The list
14
of acceptable types will be given for each function or class of functions.
15
Except when stated otherwise, it is understood that a function or operation
16
which should make natural sense is legal.
17
18
On the other hand, many routines list explicit preconditions for some of their
19
argument, e.g. $p$ is a prime number, or $q$ is a positive definite quadratic
20
form. For reasons of efficiency, all trust the user input and only perform
21
minimal sanity checks. When a precondition is not satisfied, any of the
22
following may occur: a regular exception is raised, the PARI stack overflows, a
23
\kbd{SIGSEGV} or \kbd{SIGBUS} signal is generated, or we enter an infinite
24
loop. The function can also quietly return a mathematically meaningless
25
result: junk in, junk out.
26
27
In this chapter, we will describe the functions according to a rough
28
classification. The general entry looks something like:
29
30
\key{foo}$(x,\{\fl=0\})$: short description.
31
32
The library syntax is \kbd{GEN foo(GEN x, long fl = 0)}.
33
34
\noindent
35
This means that the GP function \kbd{foo} has one mandatory argument $x$, and
36
an optional one, $\fl$, whose default value is 0. (The $\{\}$ should not be
37
typed, it is just a convenient notation we will use throughout to denote
38
optional arguments.) That is, you can type \kbd{foo(x,2)}, or \kbd{foo(x)},
39
which is then understood to mean \kbd{foo(x,0)}. As well, a comma or closing
40
parenthesis, where an optional argument should have been, signals to GP it
41
should use the default. Thus, the syntax \kbd{foo(x,)} is also accepted as a
42
synonym for our last expression. When a function has more than one optional
43
argument, the argument list is filled with user supplied values, in order.
44
When none are left, the defaults are used instead. Thus, assuming that
45
\kbd{foo}'s prototype had been
46
$$\hbox{%
47
\key{foo}$(\{x=1\},\{y=2\},\{z=3\})$,%
48
}$$
49
typing in \kbd{foo(6,4)} would give
50
you \kbd{foo(6,4,3)}. In the rare case when you want to set some far away
51
argument, and leave the defaults in between as they stand, you can use the
52
``empty arg'' trick alluded to above: \kbd{foo(6,,1)} would yield
53
\kbd{foo(6,2,1)}. By the way, \kbd{foo()} by itself yields
54
\kbd{foo(1,2,3)} as was to be expected.
55
56
In this rather special case of a function having no mandatory argument, you
57
can even omit the $()$: a standalone \kbd{foo} would be enough (though we
58
do not recommend it for your scripts, for the sake of clarity). In defining
59
GP syntax, we strove to put optional arguments at the end of the argument
60
list (of course, since they would not make sense otherwise), and in order of
61
decreasing usefulness so that, most of the time, you will be able to ignore
62
them.
63
64
Finally, an optional argument (between braces) followed by a star, like
65
$\{\var{x}\}*$, means that any number of such arguments (possibly none) can
66
be given. This is in particular used by the various \kbd{print} routines.
67
68
\misctitle{Flags} A \tev{flag} is an argument which, rather than conveying
69
actual information to the routine, instructs it to change its default
70
behavior, e.g.~return more or less information. All such
71
flags are optional, and will be called \fl\ in the function descriptions to
72
follow. There are two different kind of flags
73
74
\item generic: all valid values for the flag are individually
75
described (``If \fl\ is equal to $1$, then\dots'').
76
77
\item binary:\sidx{binary flag} use customary binary notation as a
78
compact way to represent many toggles with just one integer. Let
79
$(p_0,\dots,p_n)$ be a list of switches (i.e.~of properties which take either
80
the value $0$ or~$1$), the number $2^3 + 2^5 = 40$ means that $p_3$ and $p_5$
81
are set (that is, set to $1$), and none of the others are (that is, they
82
are set to $0$). This is announced as ``The binary digits of $\fl$ mean 1:
83
$p_0$, 2: $p_1$, 4: $p_2$'', and so on, using the available consecutive
84
powers of~$2$.
85
86
\misctitle{Mnemonics for binary flags} Numeric flags as mentioned above are
87
obscure, error-prone, and quite rigid: should the authors want to adopt a new
88
flag numbering scheme, it would break backward compatibility. The only
89
advantage of explicit numeric values is that they are fast to type, so their
90
use is only advised when using the calculator \kbd{gp}.
91
92
As an alternative, one can replace a binary flag by a character string
93
containing symbolic identifiers (mnemonics). In the function description,
94
mnemonics corresponding to the various toggles are given after each of them.
95
They can be negated by prepending \kbd{no\_} to the mnemonic, or by removing
96
such a prefix. These toggles are grouped together using any punctuation
97
character (such as ',' or ';'). For instance (taken from description of
98
$\tet{ploth}(X=a,b,\var{expr},\{\fl=0\},\{n=0\})$)
99
100
\centerline{Binary digits of flags mean: $1=\kbd{Parametric}$,
101
$2=\kbd{Recursive}$, \dots}
102
103
\noindent so that, instead of $1$, one could use the mnemonic
104
\kbd{"Parametric; no\_Recursive"}, or simply \kbd{"Parametric"} since
105
\kbd{Recursive} is unset by default (default value of $\fl$ is $0$,
106
i.e.~everything unset). People used to the bit-or notation in languages like
107
C may also use the form \kbd{"Parametric | no\_Recursive"}.
108
109
\misctitle{Pointers} \varsidx{pointer} If a parameter in the function
110
prototype is prefixed with a \& sign, as in
111
112
\key{foo}$(x,\&e)$
113
114
\noindent it means that, besides the normal return value, the function may
115
assign a value to $e$ as a side effect. When passing the argument, the \&
116
sign has to be typed in explicitly. As of version \vers, this \tev{pointer}
117
argument is optional for all documented functions, hence the \& will always
118
appear between brackets as in \kbd{Z\_issquare}$(x,\{\&e\})$.
119
120
\misctitle{About library programming}
121
The \var{library} function \kbd{foo}, as defined at the beginning of this
122
section, is seen to have two mandatory arguments, $x$ and \fl: no function
123
seen in the present chapter has been implemented so as to accept a variable
124
number of arguments, so all arguments are mandatory when programming with the
125
library (usually, variants are provided corresponding to the various flag values).
126
We include an \kbd{= default value} token in the prototype to signal how a missing
127
argument should be encoded. Most of the time, it will be a \kbd{NULL} pointer, or
128
-1 for a variable number. Refer to the \emph{User's Guide to the PARI library}
129
for general background and details.
130
131