25 Fi =
new COEF_TYPE [
m] {0};
28 for (UCOEF_TYPE a = 2; a <
m - 1; ++a) {
30 COEF_TYPE s = 1; COEF_TYPE t = 0;
31 COEF_TYPE u = 0; COEF_TYPE v = 1;
32 COEF_TYPE c = (COEF_TYPE )m; COEF_TYPE d = a;
34 COEF_TYPE q = c / d; COEF_TYPE r = c - q*d;
35 COEF_TYPE w = u*q + s; COEF_TYPE x = v*q + t;
36 s = u; t = v; u = w; v = x;
38 negative = not negative;
40 if (negative)
Fi[a] = m - t;
else Fi[a] = t;
47 Fi =
new COEF_TYPE [
m];
48 for (
unsigned i = 0; i <
m; ++i)
53 Prime_Field::~Prime_Field() {
delete []
Fi; }
133 while (c.
a < 0) c.
a += c.
m;
161 while (c.
a < 0) c.
a += c.
m;
friend Prime_Field_Element operator-(const Prime_Field_Element &, const Prime_Field_Element &)
Does not modify this.
COEF_TYPE * Fi
for , is multiplicative inverse of , mod
void operator-=(const Prime_Field_Element &other)
decreases the value of this.
unsigned m
the number’ modulus, stored here to avoid the expense of accessing it in .
friend Prime_Field_Element operator*(const Prime_Field_Element &, const Prime_Field_Element &)
Does not modify this.
Prime_Field * field() const
The field this element lies in.
void operator+=(const Prime_Field_Element &other)
increases the value of this.
void operator/=(const Prime_Field_Element &other)
Changes the value of this.
Prime_Field_Element zero()
“zero” is the additive identity.
Information necessary for a field modulo a prime.
UCOEF_TYPE m
characteristic/modulus of the field
bool get_print_modulus()
indicates whether to print the modulus
void negate()
“Negates” this.
Prime_Field_Element unity()
“unity” is the multiplicative identity.
COEF_TYPE inverse(COEF_TYPE a)
Returns the inverse of , modulo .
bool print_modulus
determines whether a coefficient's modulus is printed
COEF_TYPE a
the number’s value; descendants should ensure
unsigned modulus() const
Returns the field's modulus.
Prime_Field(UCOEF_TYPE modulus, bool show_modulus=false)
Please read detailed information.
Element of a field of prime characteristic.
unsigned modulus() const
The field's modulus.
bool is_one() const
Is this the multiplicative identity?
Prime_Field * F
the field this element lives in; used to find inverses
Prime_Field_Element(Prime_Field *field)
Constructs a prime field element in the specified field, with the value 0.
void operator*=(const Prime_Field_Element &other)
multiply the value of this by other
void set_print_modulus(bool b)
determines whether to print the modulus
bool like(const Prime_Field_Element &b) const
true iff this and b have the same modulus.
COEF_TYPE inverse() const
Returns the multiplicative inverse of this.
COEF_TYPE value() const
The value of the element. This always satisfies .
friend Prime_Field_Element operator+(const Prime_Field_Element &, const Prime_Field_Element &)
Does not modify this.