Appendix - Summary of Available Constants
In this appendix we give the list of predefined constants available in the PARI library. All of them are in the heap and not on the PARI stack. We start by recalling the universal objects introduced in Label se:intro4:
t_INT: gen_0, gen_1, gen_m1, gen_2 t_FRAC: ghalf t_COMPLEX: gi t_POL: pol_1[..], pol_x[..]
Only polynomials in the variables 0
and MAXVARN
are
defined initially. Use fetch_var()
(see Label se:fetch_var) to
create new ones.
The other objects are not initialized by default:
bern
(i). This is the 2i
-th Bernoulli number (B_0 = 1
, B_2 = 1/6
,
B_4 = -1/30
, etc...). To initialize them, use the function:
void
mpbern(long n, long prec)
This creates the even numbered Bernoulli numbers up to B_{2n-2}
as real numbers of precision prec
. They can then be used with
the macro bern(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. 0 <= i <= n-1
) before using it, since no checking is
done by PARI itself.
geuler
. This is Euler's constant. It is initialized by the first call
to mpeuler
(see Label se:euler).
gpi
. This is the number Pi. It is initialized by the first call to
mppi
(see Label se:pi).
The use of both geuler
and gpi
is deprecated since it is always
possible that some library function increases the precision of the constant
after you've computed it, hence modifying the computation accuracy
without your asking for it and increasing your running times for no good
reason. You should always use mpeuler
and mppi
(note that only
the first call will actually compute the constant, unless a higher precision
is required).
In addition, some single or double-precision real numbers (like PI
) are
predefined, and their list is in the file paricom.h
.
Finally, one has access to a table of (differences of) primes through the
pointer diffptr
. This is used as follows: when
void
pari_init(size_t size, ulong maxprime)
is called, this table is initialized with the successive
differences of primes up to (just a little beyond) maxprime
(see Label se:intro4). The prime table will occupy roughly
maxprime/
log (maxprime)
bytes in memory, so be sensible when
choosing maxprime
(it is 500000
by default under gp
). In any case,
the implementation requires that maxprime < 2^{BIL} - 2048
, whatever
memory is available.
The largest prime computable using this table is available as the output of
ulong
maxprime()
After the following initializations (the names p
and ptr are arbitrary of
course)
byteptr ptr = diffptr; ulong p = 0;
calling the macro NEXT_PRIME_VIADIFF_CHECK(p, ptr)
repeatedly will
assign the successive prime numbers to p
. Overrunning the prime table boundary
will raise the error primer1
, which will just print the error message:
*** not enough precomputed primes
and then abort the computations. The alternative macro
NEXT_PRIME_VIADIFF
operates in the same way, but will omit that check, and
is slightly faster. It should be used in the following way:
byteptr ptr = diffptr; ulong p = 0;
if (maxprime() < goal) pari_err(primer1); /* not enough primes */ while (p <= goal) /* run through all primes up to C<goal> */ { NEXT_PRIME_VIADIFF(p, ptr); ... }
Here, we use the general error handling function pari_err
(see
Label se:err), with the codeword primer1
, raising the ``not enough
primes'' error.
You can use the function initprimes
from the file arith2.c
to
compute a new table on the fly and assign it to diffptr
or to a
similar variable of your own. Beware that before changing diffptr
,
you should really free the (malloc
ed) precomputed table first, and then
all pointers into the old table will become invalid.
PARI currently guarantees that the first 6547 primes, up to and including
65557, are present in the table, even if you set maxprime
to zero.
in the pari_init
call.