Next: , Previous: , Up: Top   [Contents][Index]


9 Zp — The Integers Modulo a Prime p

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:

Zp::set_si():

	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:

fis the Zp domain performing this operation;
ropis the GMP integer receiving the result; and
opis the source operand.

Zp::set_z():

	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:

fis the Zp domain performing this operation;
ropis the GMP integer receiving the result; and
opis the source operand.

Zp::set_q():

	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:

fis the Zp domain performing this operation;
ropis the GMP integer receiving the result; and
opis the source GMP rational operand.

Zp::add():

	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:

fis the Zp domain performing this operation;
ropis the GMP integer receiving the result;
op1is the first operand; and
op2is the second operand.

Zp::sub():

	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:

fis the Zp domain performing this operation;
ropis the GMP integer receiving the result;
op1is the first operand; and
op2is the second operand.

Zp::neg():

	void	(*neg) (const struct calib_Zp_dom *	f,
			mpz_ptr				rop,
			mpz_srcptr			op);

Set rop to - op in Zp, where:

fis the Zp domain performing this operation;
ropis the GMP integer receiving the result; and
opis the source operand.

Zp::mul():

	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:

fis the Zp domain performing this operation;
ropis the GMP integer receiving the result;
op1is the first operand; and
op2is the second operand.

Zp::ipow():

	void	(*ipow) (const struct calib_Zp_dom *	f,
			 mpz_ptr			rop,
			 mpz_srcptr			op,
			 int				power);

Set rop to op ** power in Zp, where:

fis the Zp domain performing this operation;
ropis the GMP integer receiving the result;
opis the operand to exponentiate; and
poweris the power to take.

The exponent power is allowed to be any integer (positive, negative, or zero).

Zp::inv():

	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:

fis the Zp domain performing this operation;
ropis the GMP integer receiving the result; and
opis the source operand (must not be zero).

Zp::set_random():

	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:

fis the Zp domain performing this operation;
ropis the GMP integer receiving the result; and
randpis the random number generator to use.

Zp::set_genrep():

	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:

fis the Zp domain performing this operation;
ropis the GMP integer receiving the result;
opis the source genrep operand.

Zp::to_genrep():

	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:

fis the Zp domain performing this operation;
opis the source operand.

Next: , Previous: , Up: Top   [Contents][Index]