| version 1.1, 2001/10/02 11:16:57 |
version 1.2, 2002/09/11 07:26:42 |
| Line 14 useful as a stand-alone tool. The operations and funct |
|
| Line 14 useful as a stand-alone tool. The operations and funct |
|
| PARI and GP will be described in the next chapter. In the present one, we |
PARI and GP will be described in the next chapter. In the present one, we |
| describe the specific use of the GP programmable calculator. |
describe the specific use of the GP programmable calculator. |
| |
|
| For starting the calculator, the general commandline syntax is: |
For starting the calculator, the general command line syntax is: |
| |
|
| \kbd{gp [-s stacksize] [-p primelimit]} |
\kbd{gp [-s stacksize] [-p primelimit]} |
| |
|
| Line 26 parameters of GP, or \var{defaults}. See \secref{se:de |
|
| Line 26 parameters of GP, or \var{defaults}. See \secref{se:de |
|
| list and explanation of all defaults, there are many more than just those |
list and explanation of all defaults, there are many more than just those |
| two. These defaults can be changed by adding parameters to the input line |
two. These defaults can be changed by adding parameters to the input line |
| as above, or interactively during a GP session or in a preferences file (also |
as above, or interactively during a GP session or in a preferences file (also |
| known as \kbd{gprc}). |
known as \tet{gprc}). |
| |
|
| \unix Some new features were developed on UNIX platforms, and depend heavily |
\unix Some new features were developed on UNIX platforms, and depend heavily |
| on the operating system in use. It is \var{possible} that some of these |
on the operating system in use. It is \var{possible} that some of these |
| Line 252 The hacker's way to check if this is the case would be |
|
| Line 252 The hacker's way to check if this is the case would be |
|
| the string \kbd{RL\_PROMPT\_START\_IGNORE}. If it's there, you are safe. |
the string \kbd{RL\_PROMPT\_START\_IGNORE}. If it's there, you are safe. |
| |
|
| A more sensible way is to make some experiments, and get a more recent |
A more sensible way is to make some experiments, and get a more recent |
| \kbd{readline} if yours doesn't work the way you'd like it to. See the file |
\kbd{readline} if yours doesn't work the way you would like it to. See the |
| \kbd{misc/gprc.dft} for some examples. |
file \kbd{misc/gprc.dft} for some examples. |
| |
|
| \subsecidx{compatible} (default \kbd{0}): The GP function names and syntax |
\subsecidx{compatible} (default \kbd{0}): The GP function names and syntax |
| have changed tremendously between versions 1.xx and 2.00. To help you cope |
have changed tremendously between versions 1.xx and 2.00. To help you cope |
| Line 290 change modifies the function list, i.e.~if you move be |
|
| Line 290 change modifies the function list, i.e.~if you move be |
|
| $\{0,1\}$ and $\{2,3\}$ (variables are unaffected). We of course strongly |
$\{0,1\}$ and $\{2,3\}$ (variables are unaffected). We of course strongly |
| encourage you to try and get used to the setting \kbd{compatible}=0. |
encourage you to try and get used to the setting \kbd{compatible}=0. |
| |
|
| |
Note that the default \tet{new_galois_format} is another compatibility setting, |
| |
which is completely independent of \kbd{compatible}. |
| |
|
| \subsecidx{debug} (default \kbd{0}): debugging level. If it is non-zero, |
\subsecidx{debug} (default \kbd{0}): debugging level. If it is non-zero, |
| some extra messages may be printed (some of it in French), according to |
some extra messages may be printed (some of it in French), according to |
| what is going on (see~\b{g}). |
what is going on (see~\b{g}). |
| Line 362 be \var{appended} at the end. |
|
| Line 365 be \var{appended} at the end. |
|
| \subsecidx{logfile} (default \kbd{"pari.log"}): name of the log file to be |
\subsecidx{logfile} (default \kbd{"pari.log"}): name of the log file to be |
| used when the \kbd{log} toggle is on. Tilde and time expansion are performed. |
used when the \kbd{log} toggle is on. Tilde and time expansion are performed. |
| |
|
| |
\subsecidx{new_galois_format} (default \kbd{0}): if this is set, the |
| |
\tet{polgalois} command will use a different, more consistent, naming scheme |
| |
for Galois groups. This default is provided to ensure that scripts |
| |
can control this behaviour and do not break unexpectedly. Note that the |
| |
default value of $0$ (unset) will change to $1$ (set) in the next major |
| |
version. |
| |
|
| \subsecidx{output} (default \kbd{1}): there are four possible values: 0 |
\subsecidx{output} (default \kbd{1}): there are four possible values: 0 |
| (=~\var{raw}), 1 (=~\var{prettymatrix}), 2 (=~\var{prettyprint}), or 3 |
(=~\var{raw}), 1 (=~\var{prettymatrix}), 2 (=~\var{prettyprint}), or 3 |
| (=~\var{external prettyprint}). This |
(=~\var{external prettyprint}). This |
| Line 394 and~\b{b} respectively (see below). |
|
| Line 404 and~\b{b} respectively (see below). |
|
| in fact any program using the PARI library, needs a stack in which to do |
in fact any program using the PARI library, needs a stack in which to do |
| its computations. \kbd{parisize} is the stack size, in bytes. It is |
its computations. \kbd{parisize} is the stack size, in bytes. It is |
| strongly recommended you increase this default (using the \kbd{-s} |
strongly recommended you increase this default (using the \kbd{-s} |
| command-line switch, or a \kbd{gprc}) if you can afford it. Don't increase |
command-line switch, or a \tet{gprc}) if you can afford it. Don't increase |
| it beyond the actual amount of RAM installed on your computer or GP will |
it beyond the actual amount of RAM installed on your computer or GP will |
| spend most of its time paging. |
spend most of its time paging. |
| |
|
| Line 452 Emacs relies on the prompt being the default one. So, |
|
| Line 462 Emacs relies on the prompt being the default one. So, |
|
| \kbd{.emacs} file (see \kbd{emacs/pariemacs.txt} and \kbd{misc/gprc.dft} for |
\kbd{.emacs} file (see \kbd{emacs/pariemacs.txt} and \kbd{misc/gprc.dft} for |
| examples). |
examples). |
| |
|
| |
\subsecidx{prompt_cont} (default \kbd{""}): a string that will be printed |
| |
to prompt for continuation lines (e.g. in between braces, or after a |
| |
line-terminating backslash). Everything that applies to \kbd{prompt} |
| |
applies to \kbd{prompt\_cont} as well. |
| |
|
| \subsecidx{psfile} (default \kbd{"pari.ps"}): name of the default file where |
\subsecidx{psfile} (default \kbd{"pari.ps"}): name of the default file where |
| GP is to dump its PostScript drawings (these will always be appended, so that |
GP is to dump its PostScript drawings (these will always be appended, so that |
| no previous data are lost). Tilde and time expansion are performed. |
no previous data are lost). Tilde and time expansion are performed. |
| Line 840 polynomial $y$. This allows us to work easily in \idx{ |
|
| Line 855 polynomial $y$. This allows us to work easily in \idx{ |
|
| extensions of the $p$-adic field $\Q_p$, or \idx{finite field}s. |
extensions of the $p$-adic field $\Q_p$, or \idx{finite field}s. |
| |
|
| \label{se:rempolmod} |
\label{se:rempolmod} |
| \misctitle{Important remark.} Since the variables\sidx{variable} occurring |
\misctitle{Important remark.}\sidx{variable (priority)} Since the |
| in a polmod are not free variables, it is essential in order to avoid |
variables\sidx{variable} occurring in a polmod are not free variables, it is |
| inconsistencies that polmods use the same variable in internal operations |
essential in order to avoid inconsistencies that polmods use the same |
| (i.e.~between polmods) and variables of lower priority (which have been |
variable in internal operations (i.e.~between polmods) and variables of lower |
| introduced later in the GP session) for external operations (typically |
priority (which have been introduced later in the GP session) for external |
| between a polynomial and a polmod). For example, PARI will not recognize |
operations (typically between a polynomial and a polmod). For example, PARI |
| that \kbd{Mod(y, y\pow2 + 1)} is the same as \kbd{Mod(x, x\pow2 + 1)}. |
will not recognize that \kbd{Mod(y, y\pow2 + 1)} is the same as \kbd{Mod(x, |
| Hopefully, this problem will pass away when type ``element of a number |
x\pow2 + 1)}. Hopefully, this problem will pass away when type ``element of a |
| field'' is eventually introduced. |
number field'' is eventually introduced. See \secref{se:priority} for a |
| |
definition of ``priority'' and a discussion of (PARI's idea of) multivariate |
| |
polynomial arithmetic. |
| |
|
| On the other hand, \kbd{Mod(x, x\pow2 + 1) + Mod(x, x\pow2 + 1)} |
On the other hand, \kbd{Mod(x, x\pow2 + 1) + Mod(x, x\pow2 + 1)} |
| (which gives \kbd{Mod(2*x, x\pow2 + 1)}) and \kbd{x + Mod(y, y\pow2 + 1)} |
(which gives \kbd{Mod(2*x, x\pow2 + 1)}) and \kbd{x + Mod(y, y\pow2 + 1)} |
| Line 876 functions, which you ought to know about (use \b{u} if |
|
| Line 893 functions, which you ought to know about (use \b{u} if |
|
| memory lapses). The total number of different variable names is limited to |
memory lapses). The total number of different variable names is limited to |
| $16384$ and $65536$ on 32-bit and 64-bit machines respectively, which |
$16384$ and $65536$ on 32-bit and 64-bit machines respectively, which |
| should be enough. If you ever need hundreds of variables, you should |
should be enough. If you ever need hundreds of variables, you should |
| probably be using vectors instead. |
probably be using vectors instead. See \secref{se:priority} for a discussion |
| |
of multivariate polynomial rings. |
| |
|
| \subsec{Power series}\sidx{power series}\label{se:series} |
\subsec{Power series}\sidx{power series}\label{se:series} |
| (type \tet{t_SER}): type a rational function or |
(type \tet{t_SER}): type a rational function or |
| Line 969 is equivalent to |
|
| Line 987 is equivalent to |
|
| $$ x~\var{op}_1~((y~\var{op}_2~z)~\var{op}_2~ (x~\var{op}_3~y)).$$ |
$$ x~\var{op}_1~((y~\var{op}_2~z)~\var{op}_2~ (x~\var{op}_3~y)).$$ |
| |
|
| GP knows quite a lot of different operators, some of them unary (having |
GP knows quite a lot of different operators, some of them unary (having |
| only one argument), some binary. Unary operators are defined for either |
only one argument), some binary, plus special selection operators. Unary |
| |
operators are defined for either |
| prefix (preceding their single argument: \var{op}~$x$) or postfix (following |
prefix (preceding their single argument: \var{op}~$x$) or postfix (following |
| the argument: $x$~\var{op}) position, never both |
the argument: $x$~\var{op}) position, never both |
| (some are syntactically correct in both positions, but with different |
(some are syntactically correct in both positions, but with different |
| Line 987 will probably be more legible). |
|
| Line 1006 will probably be more legible). |
|
| binary unless mentioned otherwise): |
binary unless mentioned otherwise): |
| |
|
| \def\point#1{\noindent $\bullet$ #1\hfill\break\indent\strut} |
\def\point#1{\noindent $\bullet$ #1\hfill\break\indent\strut} |
| \point{Priority 9} |
\point{Priority 10} |
| % |
% |
| \kbd{++} and \kbd{--} (unary, postfix): \kbd{$x$++} assigns the value $x+1$ to |
\kbd{++} and \kbd{--} (unary, postfix): \kbd{$x$++} assigns the value $x+1$ to |
| $x$, then returns the new value of $x$. This corresponds to the C |
$x$, then returns the new value of $x$. This corresponds to the C |
| statement \kbd{++$x$} (there is no prefix \kbd{++} operator in GP). |
statement \kbd{++$x$} (there is no prefix \kbd{++} operator in GP). |
| \kbd{$x$--} does the same with $x-1$. |
\kbd{$x$--} does the same with $x-1$. |
| |
|
| \point{Priority 8} |
\point{Priority 9} |
| % |
% |
| \kbd{\var{op}=}, where \var{op} is any simple binary operator |
\kbd{\var{op}=}, where \var{op} is any simple binary operator |
| (i.e.~a binary operator with no side effects, i.e.~one of those defined below) |
(i.e.~a binary operator with no side effects, i.e.~one of those defined below) |
| which is not a boolean operator (comparison or logical). |
which is not a boolean operator (comparison or logical). |
| \kbd{x~\var{op}=~$y$} assigns $(\kbd{x}~\var{op}~y)$ to~\kbd{x}, |
\kbd{x~\var{op}=~$y$} assigns $(\kbd{x}~\var{op}~y)$ to~\kbd{x}, |
| and returns the new value of~\kbd{x}, \var{not} a reference to the |
and returns the new value of~\kbd{x}, \var{not} a reference to the |
| \idx{variable}~\kbd{x}. (Thus an assignment cannot occur on the lefthand |
\idx{variable}~\kbd{x}. (Thus an assignment cannot occur on the left hand |
| side of another assignment.) |
side of another assignment.) |
| |
|
| \point{Priority 7} |
\point{Priority 8} |
| % |
% |
| \kbd{=} is the assignment operator. The result of \kbd{x~=~$y$} is the value |
\kbd{=} is the assignment operator. The result of \kbd{x~=~$y$} is the value |
| of the expression~$y$, which is also assigned to the variable~\kbd{x}. This |
of the expression~$y$, which is also assigned to the variable~\kbd{x}. This |
| is \var{not} the equality test operator. Beware that a statement like |
is \var{not} the equality test operator. Beware that a statement like |
| \kbd{x~=~1} is always true (i.e.~non-zero), and sets \kbd{x} to~1. |
\kbd{x~=~1} is always true (i.e.~non-zero), and sets \kbd{x} to~1. |
| |
The right hand side of the assignment operator is evaluated before the left |
| |
hand side. If the left hand side cannot be modified, raise an error. |
| |
|
| |
\point{Priority 7} |
| |
\kbd{[ ]} is the selection operator. \kbd{$x$[$i$]} returns the $i$-th |
| |
component of vector $x$; \kbd{$x[$i$,$j$]$}, \kbd{$x[,$j$]$} and |
| |
\kbd{$x$[$i$,]} respectively return the entry of coordinates $(i,j)$, the |
| |
$j$-th column, and the $i$-th row of matrix $x$. If the assignment operator |
| |
(\kbd{=}) immediately follows a sequence of selections, it assigns its |
| |
right hand side to the selected component. E.g \kbd{x[1][1] = 0} is valid; |
| |
but beware that \kbd{(x[1])[1] = 0} is not (because the parentheses force |
| |
the complete evaluation of \kbd{x[1]}, and the result is not modifiable). |
| |
|
| \point{Priority 6} |
\point{Priority 6} |
| % |
% |
| \kbd{!} (unary, prefix): logical \var{not}. \kbd{!$x$} return $1$ if $x$ is |
\kbd{'} (unary, prefix): quote its argument (a variable name) without |
| equal to $0$ (specifically, if \kbd{gcmp0($x$)==1}), and $0$ otherwise. |
evaluating it. |
| |
|
| \kbd{'} (unary, prefix): quote its argument without evaluating it. |
|
| \bprog |
\bprog |
| ? a = x + 1; x = 1; |
? a = x + 1; x = 1; |
| ? subst(a,x,1) |
? subst(a,x,1) |
| Line 1025 equal to $0$ (specifically, if \kbd{gcmp0($x$)==1}), a |
|
| Line 1054 equal to $0$ (specifically, if \kbd{gcmp0($x$)==1}), a |
|
| ? subst(a,'x,1) |
? subst(a,'x,1) |
| %1 = 2 |
%1 = 2 |
| @eprog |
@eprog |
| |
|
| \point{Priority 5} |
|
| % |
% |
| \kbd{\pow}: powering. |
\kbd{\pow}: powering. |
| |
|
| Line 1040 current precision. It behaves as $(f(x))'$ otherwise. |
|
| Line 1067 current precision. It behaves as $(f(x))'$ otherwise. |
|
| |
|
| \kbd{!} (unary, postfix): factorial. $x\kbd{!}=x(x-1)\cdots 1$. |
\kbd{!} (unary, postfix): factorial. $x\kbd{!}=x(x-1)\cdots 1$. |
| |
|
| \kbd{.}: \kbd{$x$.$b$} extracts member $b$ from structure $x$. |
\kbd{.}\var{member} (unary, postfix): \kbd{$x$.\var{member}} extracts |
| |
\var{member} from structure $x$ (see~\secref{se:member}). |
| |
|
| |
\point{Priority 5} |
| |
% |
| |
\kbd{!} (unary, prefix): logical \var{not}. \kbd{!$x$} return $1$ if $x$ is |
| |
equal to $0$ (specifically, if \kbd{gcmp0($x$)==1}), and $0$ otherwise. |
| |
|
| |
\kbd{\#} (unary, prefix): cardinality; \kbd{\#$x$} returns \kbd{length($x$)}. |
| |
|
| \point{Priority 4} |
\point{Priority 4} |
| % |
% |
| \kbd{+}, \kbd{-} (unary, prefix): \kbd{-} toggles the sign of its argument, |
\kbd{+}, \kbd{-} (unary, prefix): \kbd{-} toggles the sign of its argument, |
| Line 1053 current precision. It behaves as $(f(x))'$ otherwise. |
|
| Line 1088 current precision. It behaves as $(f(x))'$ otherwise. |
|
| |
|
| \kbd{/}: exact division (\kbd{3/2}=$3/2$, not $1.5$). |
\kbd{/}: exact division (\kbd{3/2}=$3/2$, not $1.5$). |
| |
|
| \kbd{\bs}, \kbd{\%}: euclidean quotient and remainder, i.e.~if $x = |
\kbd{\bs}, \kbd{\%}: Euclidean quotient and remainder, i.e.~if $x = |
| qy + r$, with $0\le r < y$ (if $x$ and $y$ are polynomials, assume instead |
qy + r$, with $0\le r < y$ (if $x$ and $y$ are polynomials, assume instead |
| that $\deg r< \deg y$ and that the leading terms of $r$ and $x$ have the |
that $\deg r< \deg y$ and that the leading terms of $r$ and $x$ have the |
| same sign), then $\kbd{x \b{ } y} = q$, $\kbd{x\%y} = r$. |
same sign), then $\kbd{x \b{ } y} = q$, $\kbd{x\%y} = r$. |
| |
|
| \kbd{\bs/}: rounded euclidean quotient for integers (rounded towards |
\kbd{\bs/}: rounded Euclidean quotient for integers (rounded towards |
| $+\infty$ when the exact quotient would be a half-integer). |
$+\infty$ when the exact quotient would be a half-integer). |
| |
|
| \kbd{<<}, \kbd{>>}: left and right binary shift: \kbd{x<<n}$~=~x * 2^n$ |
\kbd{<<}, \kbd{>>}: left and right binary shift: \kbd{x<<n}$~=~x * 2^n$ |
| if $n>0$, and $x \b{/} 2^{-n}$ otherwise; and |
if $n>0$, and $x \b{/} 2^{-n}$ otherwise. Right shift is defined by |
| \kbd{x>>n}$~=~$\kbd{x<<(-n)}. |
\kbd{x>>n}$~=~$\kbd{x<<(-n)}. |
| |
|
| \point{Priority 2} |
\point{Priority 2} |
| Line 1090 and aborted as soon as the final truth value is known. |
|
| Line 1125 and aborted as soon as the final truth value is known. |
|
| produce an error since the second argument need not (and will not) be processed |
produce an error since the second argument need not (and will not) be processed |
| when the first is already zero (false). |
when the first is already zero (false). |
| |
|
| \misctitle{Remark:} For the optimal efficiency, you should use the |
\misctitle{Remark:} For optimal efficiency, you should use the |
| \kbd{++}, \kbd{--} and \var{op}\kbd{=} operators whenever possible: |
\kbd{++}, \kbd{--} and \var{op}\kbd{=} operators whenever possible: |
| \bprog |
\bprog |
| ? a = 200000; |
? a = 200000; |
| Line 1142 version $1.900$ on, there\sidx{case distinction} \var{ |
|
| Line 1177 version $1.900$ on, there\sidx{case distinction} \var{ |
|
| between lowercase and uppercase. Also, note that, outside of constant |
between lowercase and uppercase. Also, note that, outside of constant |
| strings, blanks are completely ignored in the input to GP. |
strings, blanks are completely ignored in the input to GP. |
| |
|
| The special variable\sidx{variable (special)} names known to GP are |
The special variable names known to GP are \tet{Euler} (Euler's constant |
| \tet{Euler} (Euler's constant $\gamma=0.577\dots$), \tet{I} (the |
$\gamma=0.577\dots$), \tet{I} (the square root of $-1$), \tet{Pi} |
| square root of $-1$), \tet{Pi} (3.14\dots)~--- which could be thought of as |
(3.14\dots)~--- which could be thought of as functions with no arguments, and |
| functions with no arguments, and which may therefore be invoked without |
which may therefore be invoked without parentheses~---, and \tet{O} which |
| parentheses~---, and \tet{O} which obeys the following syntax: |
obeys the following syntax: |
| |
|
| \kbd{O(\var{expr}\pow k)} |
\kbd{O(\var{expr}\pow k)} |
| |
|
| Line 1248 manipulation package, although it shares some of the f |
|
| Line 1283 manipulation package, although it shares some of the f |
|
| the main consequences of this fact is that all expressions are evaluated as |
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% |
soon as they are written, they never stay in a purely abstract form% |
| \footnote{**}{An obvious but important exception are character strings which |
\footnote{**}{An obvious but important exception are character strings which |
| are evaluated\dots\ essentially to themselves (type \typ{STR}). Not exactly |
are evaluated essentially to themselves (type \typ{STR}). Not exactly |
| so though, since we do some work to treat the quoted characters correctly |
so though, since we do some work to treat the quoted characters correctly |
| (those preceded by a \b{)}.}. |
(those preceded by a \b{)}.}. |
| % |
% |
| Line 1277 to restrict the use of a given variable by declaring i |
|
| Line 1312 to restrict the use of a given variable by declaring i |
|
| \tet{local}. This can be useful to enforce clean programming style, but is in |
\tet{local}. This can be useful to enforce clean programming style, but is in |
| no way mandatory. |
no way mandatory. |
| |
|
| \misctitle{(Technical) Note:} Variables are numbered in the order that they |
\misctitle{(Technical) Note:} |
| appear since the beginning of the session, 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 {\it in the internal representation}, 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 \tet{changevar}. If you |
|
| only want to have them ordered when the result is printed, you can also use |
|
| the function \tet{reorder}, but this won't change anything to the internal |
|
| representation. |
|
| |
|
| \misctitle{(Very technical) Note:} |
|
| Each variable has a stack of values, implemented as a linked list. When a new |
Each variable has a stack of values, implemented as a linked list. When a new |
| scope is entered (during a function call which uses it as a parameter, or if |
scope is entered (during a function call which uses it as a parameter, or if |
| the variable is used as a loop index, see \secref{se:user_defined} and |
the variable is used as a loop index, see \secref{se:user_defined} and |
| Line 1297 the variable is used as a loop index, see \secref{se:u |
|
| Line 1320 the variable is used as a loop index, see \secref{se:u |
|
| stack. If the parameter is not supplied, a special $0$ value called |
stack. If the parameter is not supplied, a special $0$ value called |
| \teb{gnil} is pushed on the stack (this value is not printed if it is |
\teb{gnil} 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 |
returned as the result of a GP expression sequence). Upon exit, the stack |
| decreases. You can \kbd{kill} a variable, decreasing the stack yourself. This |
decreases. You can \kbd{kill} a variable, decreasing the stack yourself. |
| should be used only at the top level of GP, to undo the effect of an |
However, the stack has a bottom: the value of a variable is the monomial of |
| assignment, not from a function. However, the stack has a bottom: the value |
degree 1 in this variable, as is natural for a mathematician. |
| of a variable is the monomial of degree 1 in this variable, as is natural for |
|
| a mathematician. |
|
| |
|
| |
\subsec{Variable priorities:}\sidx{variable (priority)}\label{se:priority} |
| |
PARI has no intelligent ``sparse'' representation of polynomials. So a |
| |
multivariate polynomial in PARI is just a polynomial (in one variable), whose |
| |
coefficients are themselves polynomials, arbitrary but for the fact that they |
| |
do not involve the main variable. All computations are then just done |
| |
formally on the coefficients as if the polynomial was univariate. |
| |
|
| |
This is not symmetrical. So if I enter \kbd{x + y} in a clean session, |
| |
what happens ? This is understood as |
| |
$$ x^1 + y*x^0 \in (\Z[y])[x] $$ |
| |
but how can GP decide that $x$ is ``more important'' than $y$ ? Why not |
| |
$y^1 + x*y^0$, which is the same mathematical entity after all ? |
| |
|
| |
The answer is that variables are ordered implicitly by the GP interpreter: |
| |
when a new identifier (e.g~$x$, or $y$ as above) is input, the corresponding |
| |
variable is registered as having a strictly lower priority than any variable in |
| |
use at this point\footnote{*}{This is not strictly true: if an |
| |
identifier is interpreted as a user function, no variable is registered. Also, |
| |
the variable $x$ is predefined and always has the highest possible priority.} |
| |
% |
| |
. To see the ordering used by GP at any given time, type $\tet{reorder}()$. |
| |
|
| |
Given such an ordering, multivariate polynomials are stored so that the |
| |
variable with the highest priority is the main variable. And so on, |
| |
recursively, until all variables are exhausted. A different storage pattern |
| |
(which could only be obtained via library mode) would produce an illegal |
| |
object, and eventually a disaster. |
| |
|
| |
In any case, if you are working with expressions involving several variables |
| |
and want to have them ordered in a specific manner in the internal |
| |
representation just described, the simplest is just to write down the |
| |
variables one after the other under GP before starting any real computations. |
| |
You could also define variables from your GPRC to have a consistant |
| |
ordering of common variable names in all your GP sessions, e.g read in a file |
| |
\kbd{variables.gp} containing |
| |
\bprog |
| |
x;y;z;t;a;b;c;d |
| |
@eprog |
| |
|
| |
If you already have started working and want to change the names of the |
| |
variables in an object, use the function \tet{changevar}. If you only want to |
| |
have them ordered when the result is printed, you can also use the function |
| |
\tet{reorder}, but this won't change anything to the internal representation, |
| |
and is not recommended. |
| |
|
| |
\misctitle{Important note:} PARI allows Euclidean division of multivariate |
| |
polynomials, but assumes that the computation takes place in the fraction |
| |
field of the coefficient ring (if it is not an integral domain, the result |
| |
will a priori not make sense). This can be very tricky; for instance |
| |
assume $x$ has highest priority (which is always the case), then |
| |
$y$: |
| |
\bprog |
| |
? x % y |
| |
%1 = 0 |
| |
? y % x |
| |
%2 = y \\@com these two take place in $\Q(y)[x]$ |
| |
? x * Mod(1,y) |
| |
%3 = Mod(1, y)*x \\@com in $(\Q(y)/y\Q(y))[x] \sim \Q[x]$ |
| |
? Mod(x,y) |
| |
%4 = 0 |
| |
@eprog |
| |
\noindent In the last exemple, the division by $y$ takes place in |
| |
$\Q(y)[x]$, |
| |
hence the \kbd{Mod} object is a coset in $(\Q(y)[x]) / (y\Q(y)[x])$, which |
| |
is the null ring since $y$ is invertible! So be very wary of variable |
| |
ordering when your computations involve implicit divisions and many |
| |
variables. This also affects functions like \tet{numerator}/\tet{denominator} |
| |
or \tet{content}: |
| |
\bprog |
| |
? denominator(x / y) |
| |
%1 = 1 |
| |
? denominator(y / x) |
| |
%2 = x |
| |
? content(x / y) |
| |
%3 = 1/y |
| |
? content(y / x) |
| |
%4 = 1 |
| |
? content(2 / x) |
| |
%5 = 2 |
| |
@eprog |
| |
\noindent Can you see why ? Hint: $x/y = (1/y) * x$ is in $\Q(y)[x]$ and |
| |
denominator is taken with respect to $\Q(y)(x)$; $y/x = (y*x^0) / x$ is in |
| |
$\Q(y)(x)$ so $y$ is invertible in the coefficient ring. On the other hand, |
| |
$2/x$ involves a single variable and the coefficient ring is simply $\Z$. |
| |
|
| |
These problems arise because the variable ordering defines an {\it |
| |
implicit} variable with respect to which division takes place. This is |
| |
the price to pay to allow \kbd{\%} and \kbd{/} operators on polynomials |
| |
instead of requiring a more cumbersome \kbd{divrem($x$, $y$, \var{var})} |
| |
(which also exists). Unfortunately, in some functions like \tet{content} and |
| |
\tet{denominator}, there is no way to set explicitly a main variable like in |
| |
\tet{divrem} and remove the dependance on implicit orderings. This will |
| |
hopefully be corrected in future versions. |
| |
|
| \subsec{Expressions and expression sequences}. |
\subsec{Expressions and expression sequences}. |
| |
|
| An \idx{expression}\sidx{expression sequence} is formed by combining the |
An \idx{expression}\sidx{expression sequence} is formed by combining the |
| Line 1549 introduced in version 2.0.13. The old syntax |
|
| Line 1664 introduced in version 2.0.13. The old syntax |
|
| local variables become undistinguishable. |
local variables become undistinguishable. |
| |
|
| \subsec{Member functions}.\sidx{member functions} |
\subsec{Member functions}.\sidx{member functions} |
| |
\label{se:member} |
| |
|
| Member functions use the `dot' notation to retrieve information from |
Member functions use the `dot' notation to retrieve information from |
| complicated structures (by default: types \tet{ell}, \tet{nf}, \tet{bnf}, |
complicated structures (by default: types \tet{ell}, \tet{nf}, \tet{bnf}, |
| Line 1657 while the second (before the \kbd{"b"}) is completely |
|
| Line 1773 while the second (before the \kbd{"b"}) is completely |
|
| actually suppresses it, as it would with any number of whitespace characters |
actually suppresses it, as it would with any number of whitespace characters |
| at this point (i.e.~outside of any string). |
at this point (i.e.~outside of any string). |
| |
|
| $\bullet$ If you insert an expression without quotes when GP expects a |
$\bullet$ If you insert any expression when GP expects a string, it gets |
| string, it gets ``expanded'': it is evaluated as a standard GP expression, |
``expanded'': it is evaluated as a standard GP expression, and the final |
| and the final result (as would have been printed if you had typed it by |
result (as would have been printed if you had typed it by itself) is then |
| itself) is then converted to a string, as if you had typed it directly. For |
converted to a string, as if you had typed it directly. For instance \kbd{"a" |
| instance \kbd{"a" 1+1 "b"} is equivalent to \kbd{"a2b"}: three strings get |
1+1 "b"} is equivalent to \kbd{"a2b"}: three strings get created, the middle |
| created, the middle one being the expansion of \kbd{1+1}, and these are then |
one being the expansion of \kbd{1+1}, and these are then concatenated |
| concatenated according to the rule described above. Another tricky point |
according to the rule described above. Another tricky point here: assume you |
| here: assume you did not assign a value to \kbd{aaa} in a GP expression |
did not assign a value to \kbd{aaa} in a GP expression before. Then typing |
| before. Then typing \kbd{aaa} by itself in a string context will actually |
\kbd{aaa} by itself in a string context will actually produce the correct |
| produce the correct output (i.e.~the string whose content is aaa), but in a |
output (i.e.~the string whose content is aaa), but in a fortuitous way. This |
| fortuitous way. This \kbd{aaa} gets expanded to the monomial of degree one in |
\kbd{aaa} gets expanded to the monomial of degree one in the variable |
| the variable \kbd{aaa}, which is of course printed as \kbd{aaa}, and thus |
\kbd{aaa}, which is of course printed as \kbd{aaa}, and thus will expand to |
| will expand to the three letters you were expecting. |
the three letters you were expecting. |
| |
|
| |
\misctitle{Warning:} expression involving strings are not handled in a |
| |
special way; even in string context, the largest possible expression is |
| |
evaluated, hence \kbd{print("a"[1])} is incorrect since \kbd{"a"} is not an |
| |
object whose first component can be extracted. On the other hand |
| |
\kbd{print("a", [1])} is correct (two distinct argument, each converted to a |
| |
string), and so is \kbd{print("a" 1)} (since \kbd{"a"1} is not a valid |
| |
expression, only \kbd{"a"} gets expanded, then \kbd{1}, and the result is |
| |
concatenated as explained above). |
| |
|
| $\bullet$ Since there are cases where expansion is not really desirable, we |
$\bullet$ Since there are cases where expansion is not really desirable, we |
| now distinguish between ``Keywords'' and ``Strings''. String is what has been |
now distinguish between ``Keywords'' and ``Strings''. String is what has been |
| described so far. Keywords are special relatives of Strings which are |
described so far. Keywords are special relatives of Strings which are |
| Line 1794 To our knowledge, only the \kbd{python} and \kbd{perl} |
|
| Line 1919 To our knowledge, only the \kbd{python} and \kbd{perl} |
|
| upgraded to version 2.0 of PARI, the \kbd{CLISP} one being still based on |
upgraded to version 2.0 of PARI, the \kbd{CLISP} one being still based on |
| version 1.39.$xx$. |
version 1.39.$xx$. |
| |
|
| \section{The preferences file}\sidx{startup}\sidx{gprc}\sidx{preferences file} |
\section{The preferences file}\sidx{startup}\sidx{preferences file} |
| \label{se:gprc} |
\label{se:gprc} |
| |
|
| \noindent |
This file, called \tet{gprc} in the sequel, is used to modify or extend GP |
| |
default behaviour, in all GP sessions: e.g customize \kbd{default} values or |
| |
load common user functions and aliases. GP opens the \kbd{gprc} file and |
| |
processes the commands in there, \var{before} doing anything else, |
| |
e.g.~creating the PARI stack. If the file does not exist or cannot be read, |
| |
GP will proceed to the initialization phase at once, eventually emitting a |
| |
prompt. If any explicit command line switches are given, they override the |
| |
values read from the preferences file. |
| |
|
| |
\subsec{Where is it?} |
| When GP is started, it looks for a customization file, or \kbd{gprc} in the |
When GP is started, it looks for a customization file, or \kbd{gprc} in the |
| following places (in this order, only the first one found will be read): |
following places (in this order, only the first one found will be loaded): |
| |
|
| \noindent$\bullet$ On the Macintosh (only), GP looks in the directory which |
\noindent$\bullet$ On the Macintosh (only), GP looks in the directory which |
| contains the GP executable itself for a file called \kbd{gprc}. No other places |
contains the GP executable itself for a file called \kbd{gprc}. No other places |
| Line 1837 your home directory), or |
|
| Line 1971 your home directory), or |
|
| |
|
| \noindent$\bullet$ Finally, if no gprc was found among the user files |
\noindent$\bullet$ Finally, if no gprc was found among the user files |
| mentioned above we look for \kbd{/etc/gprc} (\kbd{\bs etc\bs gprc}) |
mentioned above we look for \kbd{/etc/gprc} (\kbd{\bs etc\bs gprc}) |
| for a system-wide gprc file (you'll need root privileges to set up such a |
for a system-wide gprc file (you will need root privileges to set up such a |
| file yourself). |
file yourself). |
| |
|
| Note that on Unix systems, the \kbd{gprc}'s default name starts with a '.' and |
Note that on Unix systems, the \kbd{gprc}'s default name starts with a '.' and |
| thus is hidden to regular \kbd{ls} commands; you need to type \kbd{ls -a} to |
thus is hidden to regular \kbd{ls} commands; you need to type \kbd{ls -a} to |
| see whether it's already there without your knowing about it. |
list it. |
| |
|
| In any case, GP will open the corresponding file and process the commands in |
\subsec{Syntax} |
| there, \var{before} doing anything else, e.g.~creating the PARI stack. If |
|
| the file doesn't exist or cannot be read, GP will proceed to the |
|
| initialization phase at once, eventually emitting a prompt. If any explicit |
|
| commandline switches are given, they will override the values read from the |
|
| \kbd{gprc} file. |
|
| |
|
| The syntax in this file (and valid in this file only, at this very precise |
The syntax in the \kbd{gprc} file (and valid in this file only) is |
| moment!) is simple-minded, but should be sufficient for most purposes. It |
simple-minded, but should be sufficient for most purposes. The file is read |
| is read line by line, white space being optional as usual (unless surrounded |
line by line; as usual, white space is ignored unless surrounded by quotes |
| by quotes). Two types of lines are first dealt with by a preprocessor: |
and the standard multiline constructions using braces, \kbd{\bs}, or \kbd{=} |
| |
are available (multiline comments between \kbd{/*~\dots~*/} are also |
| |
recognized). |
| |
|
| |
\subsubsec{Preprocessor:} |
| |
Two types of lines are first dealt with by a preprocessor: |
| |
|
| $\bullet$ comments are removed. This applies to all text surrounded by |
$\bullet$ comments are removed. This applies to all text surrounded by |
| \kbd{/*~\dots~*/} as well as everything following \kbd{\bs\bs} on a given |
\kbd{/*~\dots~*/} as well as to everything following \kbd{\bs\bs} on a given |
| line. |
line. |
| |
|
| $\bullet$ lines starting with \kbd{\#if} \var{keyword} are treated as |
$\bullet$ lines starting with \kbd{\#if} \var{boolean} are treated as |
| comments if \var{keyword} is not defined, and read normally otherwise. The |
comments if \var{boolean} evaluates to \kbd{false}, and read normally |
| condition can be negated using either \kbd{\#if not} (or \kbd{\#if !}). Only |
otherwise. The condition can be negated using either \kbd{\#if not} (or |
| two keywords are recognized: |
\kbd{\#if !}). If the rest of the current line is empty, the test applies to |
| |
the next line (same behaviour as \kbd{=} under GP). Only three tests can be |
| |
performed: |
| |
|
| \kbd{EMACS}: defined if GP is running in an Emacs shell (see |
\kbd{EMACS}: \kbd{true} if GP is running in an Emacs or TeXmacs shell (see |
| \secref{se:emacs}). |
\secref{se:emacs}). |
| |
|
| \kbd{READL}: defined if GP is compiled with \kbd{readline} support (see |
\kbd{READL}: \kbd{true} if GP is compiled with \kbd{readline} support (see |
| \secref{se:readline}). |
\secref{se:readline}). |
| |
|
| \noindent For instance you could set your prompt in the following portable |
\kbd{VERSION} \var{op} \var{number}: where \var{op} is in the set |
| way: |
$\{ \kbd{>}, \kbd{<}, \kbd{<=}, \kbd{>=} \}$, and \var{number} is a PARI |
| |
version number of the form \var{Major}.\var{Minor}.\var{patch}, where the |
| |
last two components can be omitted (i.e.~$1$ is understood as versio $1.0.0$). |
| |
This is \kbd{true} if GP's version number satisfies the required |
| |
inequality. |
| |
|
| |
\subsubsec{Commands:} |
| |
After the preprocessing the remaining lines are executed as |
| |
sequence of expressions (as usual, separated by \kbd{;} if necessary). Only |
| |
two kinds of expressions are recognized: |
| |
|
| |
$\bullet$ \var{default} \kbd{=} \var{value}, where \var{default} is one of |
| |
the available defaults (see \secref{se:defaults}), which will be set to |
| |
\var{value} on actual startup. Don't forget the quotes around strings |
| |
(e.g.~for \kbd{prompt} or \kbd{help}). |
| |
|
| |
$\bullet$ \kbd{read "\var{some\_GP\_file}"} where \kbd{\var{some\_GP\_file}} |
| |
is a regular GP script this time, which will be read just before GP prompts |
| |
you for commands, but after initializing the defaults. In particular, file |
| |
input is delayed until the \kbd{gprc} has been fully loaded. This is the |
| |
right place to input files containing \kbd{alias} commands, or your favorite |
| |
macros. |
| |
|
| |
\noindent For instance you could set your prompt in the following portable way: |
| \bprog |
\bprog |
| \\ self modifying prompt looking like @com\hbox{\rm(18:03) \key{gp}\kbd{ >}} |
\\ self modifying prompt looking like @com\hbox{\rm(18:03) \key{gp}\kbd{ >}} |
| prompt = "(\%R) \e[1mgp\e[m > " |
prompt = "(\%R) \e[1mgp\e[m > " |
| |
|
| \\ readline wants non-printing characters to be braced between ^A/^B pairs |
\\ readline wants non-printing characters to be braced between ^A/^B pairs |
| #if READL prompt = "(%R) ^A\e[1m^Bgp^A\e[m^B > " |
#if READL prompt = "(%R) ^A\e[1m^Bgp^A\e[m^B > " |
| |
|
| \\ escape sequences not supported under emacs |
\\ escape sequences not supported under emacs |
| #if EMACS prompt = "(%R) gp > " |
#if EMACS prompt = "(%R) gp > " |
| @eprog |
@eprog |
| |
|
| \noindent After the preprocessing there remain two types of lines: |
\noindent Note that any of the last two lines could be broken in the |
| |
following way |
| |
\bprog |
| |
#if EMACS |
| |
prompt = "(%R) gp > " |
| |
@eprog |
| |
\noindent since the preprocessor directive applies to the next line if the |
| |
current one is empty. |
| |
|
| $\bullet$ lines of the form \var{default} \kbd{=} \var{value}, where |
A sample \kbd{gprc} file called \kbd{misc/gprc.dft} is provided in the |
| \var{default} is one of the available defaults (see \secref{se:defaults}), |
standard distribution. It is a good idea to have a look at it and customize |
| which will be set to \var{value} on actual startup. Don't forget the |
it to your needs. Since this file does not use multiline constructs, here is |
| quotes around strings (e.g.~for \kbd{prompt} or \kbd{help}). |
one (note the terminating \kbd{;} to separate the expressions): |
| |
\bprog |
| $\bullet$ lines of the form \kbd{read "\var{some\_GP\_file}"} where |
#if VERSION > 2.2.3 |
| \kbd{\var{some\_GP\_file}} is a regular GP script this time, which will |
{ |
| be read just before GP prompts you for commands, but after initializing the |
read "my_scripts"; \\ syntax errors in older versions |
| defaults. This is the right place to input files containing \kbd{alias} |
new_galois_format = 1; \\ default introduced in 2.2.4 |
| commands, or your favorite macros. |
} |
| |
#if ! EMACS |
| A sample \kbd{gprc} file called \kbd{gprc.dft} is provided in the |
{ |
| standard distribution (in directory \kbd{lib}). It's a good idea to have a |
colors = "9, 5, no, no, 4, 1, 2"; |
| look at it and customize it to your needs. |
help = "gphelp -detex -ch 4 -cb 0 -cu 2"; |
| |
} |
| |
@eprog |
| |
|
| \section{Using GP under GNU Emacs} |
\section{Using GP under GNU Emacs} |
| \label{se:emacs} |
\label{se:emacs} |