Gröbner basis project
Codebase for research into Gröbner basis computation
|
classes for performing field arithmetic More...
Classes | |
class | Prime_Field |
Information necessary for a field modulo a prime. More... | |
class | Prime_Field_Element |
Element of a field of prime characteristic. More... | |
classes for performing field arithmetic
class Prime_Field |
Information necessary for a field modulo a prime.
This class encapsulates the information necessary for a field modulo a prime: both the modulus \(m\) and a list of inverses of non-zero elements. The constructors do not verify that \(m\) is prime, but expect misbehavior if not.
Definition at line 49 of file fields.hpp.
Public Member Functions | |
Construction | |
Prime_Field (UCOEF_TYPE modulus, bool show_modulus=false) | |
Please read detailed information. More... | |
Prime_Field (const Prime_Field &F) | |
Copy constructor: copies previously-computed inverses. More... | |
Destruction | |
~Prime_Field () | |
Basic properties | |
The following functions give information about the prime field, but do not modify it. | |
unsigned | modulus () const |
Returns the field's modulus. | |
COEF_TYPE | inverse (COEF_TYPE a) |
Returns the inverse of \(a\), modulo \(m\). More... | |
Prime_Field_Element | unity () |
“unity” is the multiplicative identity. | |
Prime_Field_Element | zero () |
“zero” is the additive identity. | |
I/O | |
void | set_print_modulus (bool b) |
determines whether to print the modulus | |
bool | get_print_modulus () |
indicates whether to print the modulus | |
Protected Attributes | |
COEF_TYPE * | Fi |
for \(i\neq0\), \(Fi_i\) is multiplicative inverse of \(i\), mod \(m\) | |
UCOEF_TYPE | m |
characteristic/modulus of the field | |
bool | print_modulus |
determines whether a coefficient's modulus is printed | |
Prime_Field::Prime_Field | ( | UCOEF_TYPE | modulus, |
bool | show_modulus = false |
||
) |
Please read detailed information.
modulus | All computation in this field is done modulo this number; it should be prime, but we do not check this. See this warning. |
show_modulus | indicates whether the modulus is shown when printing an element of this field. You probably don't want this. |
modulus
is prime. If \(m\) is not prime, behavior is undefined, and probably spectacularly bad. Definition at line 23 of file fields.cpp.
Prime_Field::Prime_Field | ( | const Prime_Field & | F | ) |
Copy constructor: copies previously-computed inverses.
F | the source to copy |
Allocates new data, so you can discard F
later if you want.
Definition at line 45 of file fields.cpp.
COEF_TYPE Prime_Field::inverse | ( | COEF_TYPE | a | ) |
Returns the inverse of \(a\), modulo \(m\).
a | the element of this field whose inverse we desire |
Looks up the inverse in a table. If the inverse is not yet known, this function computes it using the Extended Euclidean Algorithm.
Definition at line 55 of file fields.cpp.
class Prime_Field_Element |
Element of a field of prime characteristic.
This class encapsulates an element of a field of prime characteristic (Prime_Field).
this
lives in while this
is still active. Behavior is unpredictable in this circumstance, as the field is necessary for some record keeping, e.g., to look up multiplicative inverses. Definition at line 137 of file fields.hpp.
Public Member Functions | |
Construction | |
Prime_Field_Element (Prime_Field *field) | |
Constructs a prime field element in the specified field, with the value 0. More... | |
Prime_Field_Element (COEF_TYPE value, Prime_Field *field) | |
Constructs a prime field element in the specified field, with the specified value. More... | |
Basic properties | |
The following functions give information about the monomial, but do not modify it. | |
COEF_TYPE | value () const |
The value of the element. This always satisfies \(0\leq a\leq m\). | |
unsigned | modulus () const |
The field's modulus. | |
Prime_Field * | field () const |
The field this element lies in. | |
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 . | |
bool | is_zero () const |
Is this the additive identity? | |
bool | is_one () const |
Is this the multiplicative identity? | |
Modification | |
void | assign (COEF_TYPE val, Prime_Field *K) |
for initializing arrays of Prime_Field_Element | |
Computation | |
Computes something, and may modify | |
void | negate () |
“Negates” this . | |
void | operator+= (const Prime_Field_Element &other) |
increases the value of this . More... | |
void | operator-= (const Prime_Field_Element &other) |
decreases the value of this . More... | |
void | operator*= (const Prime_Field_Element &other) |
multiply the value of this by other More... | |
void | operator*= (const COEF_TYPE b) |
Changes the value of this . More... | |
void | operator/= (const Prime_Field_Element &other) |
Changes the value of this . More... | |
Protected Attributes | |
COEF_TYPE | a |
the number’s value; descendants should ensure \(0\leq a<m\) | |
Prime_Field * | F |
the field this element lives in; used to find inverses | |
unsigned | m |
the number’ modulus, stored here to avoid the expense of accessing it in \(F\). | |
Friends | |
Friend functions for computation | |
Will not modify | |
Prime_Field_Element | operator+ (const Prime_Field_Element &, const Prime_Field_Element &) |
Does not modify this . More... | |
Prime_Field_Element | operator- (const Prime_Field_Element &, const Prime_Field_Element &) |
Does not modify this . More... | |
Prime_Field_Element | operator* (const Prime_Field_Element &, const Prime_Field_Element &) |
Does not modify this . More... | |
Prime_Field_Element | operator+ (const Prime_Field_Element &, const int) |
Does not modify this . | |
Prime_Field_Element | operator- (const Prime_Field_Element &, const int) |
Does not modify this . | |
Prime_Field_Element | operator* (const Prime_Field_Element &, const int) |
Does not modify this . | |
Prime_Field_Element | operator- (const Prime_Field_Element &) |
Does not modify this . If you want to modify this , see negate(). | |
I/O | |
Will not modify | |
ostream & | operator<< (ostream &, const Prime_Field_Element &) |
Prime_Field_Element::Prime_Field_Element | ( | Prime_Field * | field | ) |
Constructs a prime field element in the specified field, with the value 0.
field | this element’s parent |
A pointer to field
is attached to this
in order to find inverses during arithmetic.
this
is still active. Behavior is unpredictable in this circumstance. Definition at line 63 of file fields.cpp.
Prime_Field_Element::Prime_Field_Element | ( | COEF_TYPE | value, |
Prime_Field * | field | ||
) |
Constructs a prime field element in the specified field, with the specified value.
value | the element’s value |
field | the element’s base field |
A pointer to field
is attached to this
in order to find inverses during arithmetic.
this
is still active. Behavior is unpredictable in this circumstance. Definition at line 67 of file fields.cpp.
void Prime_Field_Element::operator*= | ( | const Prime_Field_Element & | other | ) |
multiply the value of this
by other
other | element to multiply |
Definition at line 102 of file fields.cpp.
void Prime_Field_Element::operator*= | ( | const COEF_TYPE | b | ) |
Changes the value of this
.
b | scalar to multiply |
This function is useful for avoiding the construction of a prime field element when you know what you want to multiply.
Definition at line 107 of file fields.cpp.
void Prime_Field_Element::operator+= | ( | const Prime_Field_Element & | other | ) |
increases the value of this
.
other | element to add |
Definition at line 92 of file fields.cpp.
void Prime_Field_Element::operator-= | ( | const Prime_Field_Element & | other | ) |
decreases the value of this
.
other | element to subtract |
Definition at line 97 of file fields.cpp.
void Prime_Field_Element::operator/= | ( | const Prime_Field_Element & | other | ) |
Changes the value of this
.
other | element to multiply |
Multiplies by multiplicative inverse of other
.
Definition at line 112 of file fields.cpp.
|
friend |
Does not modify this
.
Assume the terms have the same modulus. Behavior undefined if not!
Definition at line 138 of file fields.cpp.
|
friend |
Does not modify this
.
Assume the terms have the same modulus. Behavior undefined if not!
Definition at line 118 of file fields.cpp.
|
friend |
Does not modify this
.
Assume the terms have the same modulus. Behavior undefined if not!
Definition at line 128 of file fields.cpp.