Paritwine allows to easily switch between number types from the GNU
multiprecision ecosystem (mpz, mpq, mpfr, mpc) and corresponding types in
libpari, as well as to use functions from the GNU libraries in GP.
NUMBER TRANSFORMATIONS
----------------------
The exported functions are given in paritwine.h. For each GNU
multiprecision type X from mpz, mpq, mpfr and mpc, there are functions
X_set_GEN
X_get_GEN
The first one takes an argument x of type X and g of type GEN, and assigns
the value of g to x if the types are compatible. The second one takes as
argument x of type X and returns a GEN with the same value, allocated on the
Pari stack.
The functions pari_mpfr_init2, pari_mpc_init2 and pari_mpc_init3 work
exactly as their counterparts without the pari prefix, except that they
allocate the mantissae on the Pari stack instead of using the GMP memory
allocation functions. They should not be freed with calls to mpfr_clear or
mpc_clear, but with the usual Pari stack handling ("avma").
pari_mpfr_init_set_GEN and pari_mpc_init_set_GEN combine such an
initialisation with an assignment; as precision, they use the precision of
the source variable if it is of a floating point type, or the default
precision if it is an integer or a rational number. If you are unsure what
is meant by this paragraph, you probably do not wish to use these functions.
USER FUNCTIONS IN GP
--------------------
If you wish to use functions relying on GMP, GNU MPFR, GNU MPC or CMH in a
GP session, you need to write a wrapper function in paritwine-user.c and
declare it in paritwine-user.h. The function should take GEN arguments,
transform them to mpz, mpq, mpfr or mpc, compute with them in the desired
way, and transform the result back into a GEN. By calling
make
this function will be automatically included into the library
libparitwine.so. The functions must then be made available inside your GP
session using the "install" command.
As examples, paritwine-user.c implements correctly rounded multiplications
of real and complex numbers using MPFR and MPC, as well as the erf and zeta
functions from MPFR. The file example.gp shows how to install and use these
functions in a GP script.