Testing latest pari + WASM + node.js... and it works?! Wow.
License: GPL3
ubuntu2004
% Copyright (c) 2000 The PARI Group1%2% This file is part of the PARI/GP documentation3%4% Permission is granted to copy, distribute and/or modify this document5% under the terms of the GNU General Public License6\chapter{Functions and Operations Available in PARI and GP}7\label{se:functions}89The functions and operators available in PARI and in the GP/PARI calculator10are numerous and ever-expanding. Here is a description of the ones available11in version \vers. It should be noted that many of these functions accept12quite different types as arguments, but others are more restricted. The list13of acceptable types will be given for each function or class of functions.14Except when stated otherwise, it is understood that a function or operation15which should make natural sense is legal.1617On the other hand, many routines list explicit preconditions for some of their18argument, e.g. $p$ is a prime number, or $q$ is a positive definite quadratic19form. For reasons of efficiency, all trust the user input and only perform20minimal sanity checks. When a precondition is not satisfied, any of the21following may occur: a regular exception is raised, the PARI stack overflows, a22\kbd{SIGSEGV} or \kbd{SIGBUS} signal is generated, or we enter an infinite23loop. The function can also quietly return a mathematically meaningless24result: junk in, junk out.2526In this chapter, we will describe the functions according to a rough27classification. The general entry looks something like:2829\key{foo}$(x,\{\fl=0\})$: short description.3031The library syntax is \kbd{GEN foo(GEN x, long fl = 0)}.3233\noindent34This means that the GP function \kbd{foo} has one mandatory argument $x$, and35an optional one, $\fl$, whose default value is 0. (The $\{\}$ should not be36typed, it is just a convenient notation we will use throughout to denote37optional arguments.) That is, you can type \kbd{foo(x,2)}, or \kbd{foo(x)},38which is then understood to mean \kbd{foo(x,0)}. As well, a comma or closing39parenthesis, where an optional argument should have been, signals to GP it40should use the default. Thus, the syntax \kbd{foo(x,)} is also accepted as a41synonym for our last expression. When a function has more than one optional42argument, the argument list is filled with user supplied values, in order.43When none are left, the defaults are used instead. Thus, assuming that44\kbd{foo}'s prototype had been45$$\hbox{%46\key{foo}$(\{x=1\},\{y=2\},\{z=3\})$,%47}$$48typing in \kbd{foo(6,4)} would give49you \kbd{foo(6,4,3)}. In the rare case when you want to set some far away50argument, and leave the defaults in between as they stand, you can use the51``empty arg'' trick alluded to above: \kbd{foo(6,,1)} would yield52\kbd{foo(6,2,1)}. By the way, \kbd{foo()} by itself yields53\kbd{foo(1,2,3)} as was to be expected.5455In this rather special case of a function having no mandatory argument, you56can even omit the $()$: a standalone \kbd{foo} would be enough (though we57do not recommend it for your scripts, for the sake of clarity). In defining58GP syntax, we strove to put optional arguments at the end of the argument59list (of course, since they would not make sense otherwise), and in order of60decreasing usefulness so that, most of the time, you will be able to ignore61them.6263Finally, an optional argument (between braces) followed by a star, like64$\{\var{x}\}*$, means that any number of such arguments (possibly none) can65be given. This is in particular used by the various \kbd{print} routines.6667\misctitle{Flags} A \tev{flag} is an argument which, rather than conveying68actual information to the routine, instructs it to change its default69behavior, e.g.~return more or less information. All such70flags are optional, and will be called \fl\ in the function descriptions to71follow. There are two different kind of flags7273\item generic: all valid values for the flag are individually74described (``If \fl\ is equal to $1$, then\dots'').7576\item binary:\sidx{binary flag} use customary binary notation as a77compact way to represent many toggles with just one integer. Let78$(p_0,\dots,p_n)$ be a list of switches (i.e.~of properties which take either79the value $0$ or~$1$), the number $2^3 + 2^5 = 40$ means that $p_3$ and $p_5$80are set (that is, set to $1$), and none of the others are (that is, they81are set to $0$). This is announced as ``The binary digits of $\fl$ mean 1:82$p_0$, 2: $p_1$, 4: $p_2$'', and so on, using the available consecutive83powers of~$2$.8485\misctitle{Mnemonics for binary flags} Numeric flags as mentioned above are86obscure, error-prone, and quite rigid: should the authors want to adopt a new87flag numbering scheme, it would break backward compatibility. The only88advantage of explicit numeric values is that they are fast to type, so their89use is only advised when using the calculator \kbd{gp}.9091As an alternative, one can replace a binary flag by a character string92containing symbolic identifiers (mnemonics). In the function description,93mnemonics corresponding to the various toggles are given after each of them.94They can be negated by prepending \kbd{no\_} to the mnemonic, or by removing95such a prefix. These toggles are grouped together using any punctuation96character (such as ',' or ';'). For instance (taken from description of97$\tet{ploth}(X=a,b,\var{expr},\{\fl=0\},\{n=0\})$)9899\centerline{Binary digits of flags mean: $1=\kbd{Parametric}$,100$2=\kbd{Recursive}$, \dots}101102\noindent so that, instead of $1$, one could use the mnemonic103\kbd{"Parametric; no\_Recursive"}, or simply \kbd{"Parametric"} since104\kbd{Recursive} is unset by default (default value of $\fl$ is $0$,105i.e.~everything unset). People used to the bit-or notation in languages like106C may also use the form \kbd{"Parametric | no\_Recursive"}.107108\misctitle{Pointers} \varsidx{pointer} If a parameter in the function109prototype is prefixed with a \& sign, as in110111\key{foo}$(x,\&e)$112113\noindent it means that, besides the normal return value, the function may114assign a value to $e$ as a side effect. When passing the argument, the \&115sign has to be typed in explicitly. As of version \vers, this \tev{pointer}116argument is optional for all documented functions, hence the \& will always117appear between brackets as in \kbd{Z\_issquare}$(x,\{\&e\})$.118119\misctitle{About library programming}120The \var{library} function \kbd{foo}, as defined at the beginning of this121section, is seen to have two mandatory arguments, $x$ and \fl: no function122seen in the present chapter has been implemented so as to accept a variable123number of arguments, so all arguments are mandatory when programming with the124library (usually, variants are provided corresponding to the various flag values).125We include an \kbd{= default value} token in the prototype to signal how a missing126argument should be encoded. Most of the time, it will be a \kbd{NULL} pointer, or127-1 for a variable number. Refer to the \emph{User's Guide to the PARI library}128for general background and details.129130131