Gröbner basis project
Codebase for research into Gröbner basis computation
Fields

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...
 

Detailed Description

classes for performing field arithmetic


Class Documentation

◆ Prime_Field

class Prime_Field

Information necessary for a field modulo a prime.

Author
John Perry
Date
2015

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.

Warning
The constructor does not check whether the supplied modulus is prime. If \(m\) is not prime, behavior is undefined, and probably spectacularly bad.
Examples:
test_4by4.cpp, test_cab_es1.cpp, test_cab_es2.cpp, test_cab_es4.cpp, test_cab_es5.cpp, test_cab_es6.cpp, test_cab_es9.cpp, test_cyclic4.cpp, test_cyclicn.cpp, test_dynamic.cpp, test_monomials.cpp, and user_interface.cpp.

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
 

Constructor & Destructor Documentation

◆ Prime_Field() [1/2]

Prime_Field::Prime_Field ( UCOEF_TYPE  modulus,
bool  show_modulus = false 
)

Please read detailed information.

Parameters
modulusAll computation in this field is done modulo this number; it should be prime, but we do not check this. See this warning.
show_modulusindicates whether the modulus is shown when printing an element of this field. You probably don't want this.
Warning
This constructor does not check whether 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() [2/2]

Prime_Field::Prime_Field ( const Prime_Field F)

Copy constructor: copies previously-computed inverses.

Parameters
Fthe source to copy

Allocates new data, so you can discard F later if you want.

Definition at line 45 of file fields.cpp.

Member Function Documentation

◆ inverse()

COEF_TYPE Prime_Field::inverse ( COEF_TYPE  a)

Returns the inverse of \(a\), modulo \(m\).

Parameters
athe element of this field whose inverse we desire
Returns
\( a^{-1} \)

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.

◆ Prime_Field_Element

class Prime_Field_Element

Element of a field of prime characteristic.

Author
John Perry
Date
2015

This class encapsulates an element of a field of prime characteristic (Prime_Field).

Warning
Do not delete the prime field that 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.
Examples:
test_4by4.cpp, test_cab_es1.cpp, test_cab_es2.cpp, test_cab_es4.cpp, test_cab_es5.cpp, test_cab_es6.cpp, test_cab_es9.cpp, and test_cyclic4.cpp.

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_Fieldfield () 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 this.

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_FieldF
 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 this.

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 this.

ostream & operator<< (ostream &, const Prime_Field_Element &)
 

Constructor & Destructor Documentation

◆ Prime_Field_Element() [1/2]

Prime_Field_Element::Prime_Field_Element ( Prime_Field field)

Constructs a prime field element in the specified field, with the value 0.

Parameters
fieldthis element’s parent

A pointer to field is attached to this in order to find inverses during arithmetic.

Warning
Do not delete this field while this is still active. Behavior is unpredictable in this circumstance.

Definition at line 63 of file fields.cpp.

◆ Prime_Field_Element() [2/2]

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.

Parameters
valuethe element’s value
fieldthe element’s base field

A pointer to field is attached to this in order to find inverses during arithmetic.

Warning
Do not delete this field while this is still active. Behavior is unpredictable in this circumstance.

Definition at line 67 of file fields.cpp.

Member Function Documentation

◆ operator*=() [1/2]

void Prime_Field_Element::operator*= ( const Prime_Field_Element other)

multiply the value of this by other

Parameters
otherelement to multiply

Definition at line 102 of file fields.cpp.

◆ operator*=() [2/2]

void Prime_Field_Element::operator*= ( const COEF_TYPE  b)

Changes the value of this.

Parameters
bscalar 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.

◆ operator+=()

void Prime_Field_Element::operator+= ( const Prime_Field_Element other)

increases the value of this.

Parameters
otherelement to add

Definition at line 92 of file fields.cpp.

◆ operator-=()

void Prime_Field_Element::operator-= ( const Prime_Field_Element other)

decreases the value of this.

Parameters
otherelement to subtract

Definition at line 97 of file fields.cpp.

◆ operator/=()

void Prime_Field_Element::operator/= ( const Prime_Field_Element other)

Changes the value of this.

Parameters
otherelement to multiply

Multiplies by multiplicative inverse of other.

Definition at line 112 of file fields.cpp.

Friends And Related Function Documentation

◆ operator*

Prime_Field_Element operator* ( const Prime_Field_Element a,
const Prime_Field_Element b 
)
friend

Does not modify this.

Assume the terms have the same modulus. Behavior undefined if not!

Definition at line 138 of file fields.cpp.

◆ operator+

Prime_Field_Element operator+ ( const Prime_Field_Element a,
const Prime_Field_Element b 
)
friend

Does not modify this.

Assume the terms have the same modulus. Behavior undefined if not!

Definition at line 118 of file fields.cpp.

◆ operator-

Prime_Field_Element operator- ( const Prime_Field_Element a,
const Prime_Field_Element b 
)
friend

Does not modify this.

Assume the terms have the same modulus. Behavior undefined if not!

Definition at line 128 of file fields.cpp.