CALIB provides the Zp domain, representing the field of
integers modulo a given prime p.
The Zp domain does not provide a separate “value object,” but
rather represents Zp values directly using GMP integers.
Because GMP integers do not have anywhere to record the CALIB domain
to which they belong, most Zp operations require that the
particular Zp domain be passed as an argument (usually the
first argument), so that the particular prime p is available
for computing over integers modulo p.
One may access CALIB’s Zp domain as follows:
#include "calib/Zp.h" ... mpz_t big_prime; struct calib_Zp_dom * Zp_23; struct calib_Zp_dom * Zp_big; Zp_23 = calib_make_Zp_dom_ui (23); mpz_init_set_ui (big_prime, 18446744073709551557); Zp_big = calib_make_Zp_dom (big_prime); ... calib_Zp_free_dom (Zp_big); calib_Zp_free_dom (Zp_23);
The struct calib_Zp_dom object contains the following members
(pointers to functions) that provide operations of the domain:
void (*set_si) (const struct calib_Zp_dom * f, mpz_ptr rop, calib_si_t op);
Set rop to op in Zp (op is reduced modulo
p before assigning to rop), where:
f | is the Zp domain performing this operation; |
rop | is the GMP integer receiving the result; and |
op | is the source operand. |
void (*set_z) (const struct calib_Zp_dom * f, mpz_ptr rop, mpz_srcptr op);
Set rop to op in Zp (op is reduced modulo
p before assigning to rop), where:
f | is the Zp domain performing this operation; |
rop | is the GMP integer receiving the result; and |
op | is the source operand. |
void (*set_q) (const struct calib_Zp_dom * f, mpz_ptr rop, mpq_srcptr op);
Set rop to op in Zp (op is reduced modulo
p before assigning to rop), where:
f | is the Zp domain performing this operation; |
rop | is the GMP integer receiving the result; and |
op | is the source GMP rational operand. |
void (*add) (const struct calib_Zp_dom * f, mpz_ptr rop, mpz_srcptr op1, mpz_srcptr op2);
Set rop to op1 + op2 in Zp, where:
f | is the Zp domain performing this operation; |
rop | is the GMP integer receiving the result; |
op1 | is the first operand; and |
op2 | is the second operand. |
void (*sub) (const struct calib_Zp_dom * f, mpz_ptr rop, mpz_srcptr op1, mpz_srcptr op2);
Set rop to op1 - op2 in Zp, where:
f | is the Zp domain performing this operation; |
rop | is the GMP integer receiving the result; |
op1 | is the first operand; and |
op2 | is the second operand. |
void (*neg) (const struct calib_Zp_dom * f, mpz_ptr rop, mpz_srcptr op);
Set rop to - op in Zp, where:
f | is the Zp domain performing this operation; |
rop | is the GMP integer receiving the result; and |
op | is the source operand. |
void (*mul) (const struct calib_Zp_dom * f, mpz_ptr rop, mpz_srcptr op1, mpz_srcptr op2);
Set rop to op1 * op2 in Zp, where:
f | is the Zp domain performing this operation; |
rop | is the GMP integer receiving the result; |
op1 | is the first operand; and |
op2 | is the second operand. |
void (*ipow) (const struct calib_Zp_dom * f, mpz_ptr rop, mpz_srcptr op, int power);
Set rop to op ** power in Zp, where:
f | is the Zp domain performing this operation; |
rop | is the GMP integer receiving the result; |
op | is the operand to exponentiate; and |
power | is the power to take. |
The exponent power is allowed to be any integer (positive,
negative, or zero).
void (*inv) (const struct calib_Zp_dom * f, mpz_ptr rop, mpz_srcptr op);
Set rop to the multiplicative inverse of op in Zp,
where:
f | is the Zp domain performing this operation; |
rop | is the GMP integer receiving the result; and |
op | is the source operand (must not be zero). |
void (*set_random) (const struct calib_Zp_dom * f, mpz_ptr rop, struct calib_Random * randp);
Set rop to be a randomly selected value in Zp, where:
f | is the Zp domain performing this operation; |
rop | is the GMP integer receiving the result; and |
randp | is the random number generator to use. |
void (*set_genrep) (const struct calib_Zp_dom * f, mpz_ptr rop, const struct calib_genrep * op);
Converts operand op (in “genrep” form that must be either an
integer or rational constant) into the corresponding member of Zp,
storing the result in rop, where:
f | is the Zp domain performing this operation; |
rop | is the GMP integer receiving the result; |
op | is the source genrep operand. |
struct calib_genrep * (*to_genrep) (const struct calib_Zp_dom * f, mpz_srcptr op);
Converts operand op into the corresponding member of Zp,
returning the result as a dynamically-allocated “genrep”, where:
f | is the Zp domain performing this operation; |
op | is the source operand. |