GF2 Class Reference

Integers modulo 2. More...

`#include <gf2.h>`

## Public Types

using | Self_t = GF2
| Element type.
using | RandIter = GIV_randIter<Self_t, bool>
| Random.

## Public Member Functions

Object Management
| GF2 ()
| Default constructor.
| GF2 (int p, int exp=1)
| Default constructor.
| GF2 (const GF2 &F)
| Copy constructor.
GF2 & | operator= (const GF2 &F)
| Assignment operator.
Element | minElement () const
| Accessors.
Element | maxElement () const
| Default constructor.
Residu_t | residu () const
| Access to the modulus.
Residu_t | size () const
| Default constructor.
Residu_t | characteristic () const
| Default constructor.
Residu_t | cardinality () const
| Default constructor.
template<class T>
T & | characteristic (T &p) const
| Default constructor.
template<class T>
T & | cardinality (T &p) const
| Default constructor.
Element & | init (Element &x, const int32_t &y) const
| Initialization of field base element from an Integer.
Element & | init (Element &x, const uint32_t &y) const
| Default constructor.
Element & | init (Element &x, const int64_t &y) const
| Default constructor.
Element & | init (Element &x, const uint64_t &y) const
| Default constructor.
Element & | init (Element &x, const float &y) const
| Default constructor.
Element & | init (Element &x, const double &y) const
| Default constructor.
Element & | init (Element &x, const Integer &y) const
| Default constructor.
Element & | init (Element &x) const
| Default constructor.
BitReference | init (BitReference x, const Integer &y=0) const
| Default constructor.
Integer & | convert (Integer &x, const Element &y) const
| Conversion of field base element to a template class T.
BitReference | convert (BitReference x, const Element &y) const
| Default constructor.
template<class T>
T & | convert (T &x, const Element &y) const
| Default constructor.
Element & | assign (Element &x, const Element &y) const
| Assignment of one field base element to another.
BitReference | assign (BitReference x, const Element &y) const
| Default constructor.
Integer & | cardinality (Integer &c) const
| Cardinality.
Integer & | characteristic (Integer &c) const
| Characteristic.
Arithmetic Operations
x <- y op z; x <- op y These operations require all elements, including x, to be initialized before the operation is called. Uninitialized field base elements will give undefined results.
bool | areEqual (const Element &x, const Element &y) const
| Equality of two elements.
bool | isZero (const Element &x) const
| Zero equality.
bool | isOne (const Element &x) const
| One equality.
bool | isUnit (const Element &x) const
| Invertibility.
bool | isMOne (const Element &x) const
| MOne equality.
Element & | add (Element &x, const Element &y, const Element &z) const
| Addition.
BitReference | add (BitReference x, const Element &y, const Element &z) const
| Equality of two elements.
Element & | sub (Element &x, const Element &y, const Element &z) const
| Subtraction.
BitReference | sub (BitReference x, const Element &y, const Element &z) const
| Equality of two elements.
Element & | mul (Element &x, const Element &y, const Element &z) const
| Multiplication.
BitReference | mul (BitReference x, const Element &y, const Element &z) const
| Equality of two elements.
Element & | div (Element &x, const Element &y, const Element &z) const
| Division.
BitReference | div (BitReference x, const Element &y, const Element &z) const
| Equality of two elements.
Element & | neg (Element &x, const Element &y) const
| Additive Inverse (Negation).
BitReference | neg (BitReference x, const Element &y) const
| Equality of two elements.
Element & | inv (Element &x, const Element &y) const
| Multiplicative Inverse.
BitReference | inv (BitReference x, const Element &y) const
| Equality of two elements.
BitReference | axpy (BitReference r, const Element &a, const Element &x, const Element &y) const
| Natural AXPY.
Element & | axpy (Element &r, const Element &a, const Element &x, const Element &y) const
| Equality of two elements.
BitReference | axmy (BitReference r, const Element &a, const Element &x, const Element &y) const
| Natural AXMY.
Element & | axmy (Element &r, const Element &a, const Element &x, const Element &y) const
| Equality of two elements.
BitReference | maxpy (BitReference r, const Element &a, const Element &x, const Element &y) const
| Natural MAXPY.
Element & | maxpy (Element &r, const Element &a, const Element &x, const Element &y) const
| Equality of two elements.
Input/Output Operations
std::ostream & | write (std::ostream &os) const
| Print field.
std::istream & | read (std::istream &is)
| Read field.
std::ostream & | write (std::ostream &os, const Element &x) const
| Print field base element.
std::istream & | read (std::istream &is, Element &x) const
| Read field base element.
std::istream & | read (std::istream &is, BitReference x) const
| Print field.

## Inplace Arithmetic Operations

x <- x op y; x <- op x
Element & | addin (Element &x, const Element &y) const
| Inplace Addition.
BitReference | addin (BitReference x, const Element &y) const
| Inplace Addition.
Element & | subin (Element &x, const Element &y) const
| Inplace Subtraction.
BitReference | subin (BitReference x, const Element &y) const
| Inplace Addition.
Element & | mulin (Element &x, const Element &y) const
| Inplace Multiplication.
BitReference | mulin (BitReference x, const Element &y) const
| Inplace Addition.
Element & | divin (Element &x, const Element &y) const
| Inplace Division.
BitReference | divin (BitReference x, const Element &y) const
| Inplace Addition.
Element & | negin (Element &x) const
| Inplace Additive Inverse (Inplace Negation).
BitReference | negin (BitReference x) const
| Inplace Addition.
Element & | invin (Element &x) const
| Inplace Multiplicative Inverse.
BitReference | invin (BitReference x) const
| Inplace Addition.
Element & | axpyin (Element &r, const Element &a, const Element &x) const
| Inplace AXPY.
BitReference | axpyin (BitReference r, const Element &a, const Element &x) const
| Inplace Addition.
Element & | axmyin (Element &r, const Element &a, const Element &x) const
| Inplace AXMY.
BitReference | axmyin (BitReference r, const Element &a, const Element &x) const
| Inplace Addition.
Element & | maxpyin (Element &r, const Element &a, const Element &x) const
| Inplace MAXPY.
BitReference | maxpyin (BitReference r, const Element &a, const Element &x) const
| Inplace Addition.
static int | maxCardinality ()
| Inplace Addition.

## Detailed Description

Integers modulo 2.

This is a tuned implementation of the field of integers modulo

1. In particular, when one constructs a VectorDomain object over this field, highly optimized bit operations will be used to make vector arithmetic very fast.

## Constructor & Destructor Documentation

## GF2()

GF2 | ( | const GF2 & | F | ) |

inline

Copy constructor.

Constructs Givaro::GF2 object by copying the field. This is required to allow field objects to be passed by value into functions.

Parameters

  F | Givaro::GF2 object.

## Member Function Documentation

## operator=()

GF2 & operator= | ( | const GF2 & | F | ) |

inline

Assignment operator.

Required by the archetype

Parameters

  F | constant reference to Givaro::Modular object

Returns
  reference to Givaro::Modular object for self

## init()

Element & init | ( | Element & | x,
|  | const int32_t & | y ) const

inline

Initialization of field base element from an Integer.

Behaves like C++ allocator construct. This function assumes the output field base element x has already been constructed, but that it is not already initialized. This is not a specialization of the template function because such a specialization is not allowed inside the class declaration.

Returns
  reference to field base element.

Parameters

  x | field base element to contain output (reference returned).
  y | Integer.

## convert()

Integer & convert | ( | Integer & | x,
|  | const Element & | y ) const

inline

Conversion of field base element to a template class T.

This function assumes the output field base element x has already been constructed, but that it is not already initialized.

Returns
  reference to template class T.

Parameters

  x | template class T to contain output (reference returned).
  y | constant field base element.

## assign()

Element & assign | ( | Element & | x,
|  | const Element & | y ) const

inline

Assignment of one field base element to another.

This function assumes both field base elements have already been constructed and initialized.

Returns
  reference to x

Parameters

  x | field base element (reference returned).
  y | field base element.

## cardinality()

Integer & cardinality | ( | Integer & | c | ) | const

inline

Cardinality.

Return Integer representing cardinality of the domain. Returns a non-negative Integer for all domains with finite cardinality, and returns -1 to signify a domain of infinite cardinality.

Returns
  Integer representing cardinality of the domain

## characteristic()

Integer & characteristic | ( | Integer & | c | ) | const

inline

Characteristic.

Return Integer representing characteristic of the domain. Returns a positive Integer to all domains with finite characteristic, and returns 0 to signify a domain of infinite characteristic.

Returns
  Integer representing characteristic of the domain.

## areEqual()

bool areEqual | ( | const Element & | x,
|  | const Element & | y ) const

inline

Equality of two elements.

This function assumes both field base elements have already been constructed and initialized.

Returns
  boolean true if equal, false if not.

Parameters

  x | field base element
  y | field base element

## isZero()

bool isZero | ( | const Element & | x | ) | const

inline

Zero equality.

Test if field base element is equal to zero. This function assumes the field base element has already been constructed and initialized.

Returns
  boolean true if equals zero, false if not.

Parameters

  x | field base element.

## isOne()

bool isOne | ( | const Element & | x | ) | const

inline

One equality.

Test if field base element is equal to one. This function assumes the field base element has already been constructed and initialized.

Returns
  boolean true if equals one, false if not.

Parameters

  x | field base element.

## isUnit()

bool isUnit | ( | const Element & | x | ) | const

inline

Invertibility.

Test if field base element is invertible. This function assumes the field base element has already been constructed and initialized.

Returns
  boolean true if equals one, false if not.

Parameters

  x | field base element.

## isMOne()

bool isMOne | ( | const Element & | x | ) | const

inline

MOne equality.

Test if field base element is equal to one. This function assumes the field base element has already been constructed and initialized.

Returns
  boolean true if equals one, false if not.

Parameters

  x | field base element.

## write() [1/2]

std::ostream & write | ( | std::ostream & | os | ) | const

inline

Print field.

Returns
  output stream to which field is written.

Parameters

  os | output stream to which field is written.

## read() [1/3]

std::istream & read | ( | std::istream & | is | ) |

inline

Read field.

Returns
  input stream from which field is read.

Parameters

  is | input stream from which field is read.

## write() [2/2]

std::ostream & write | ( | std::ostream & | os,
|  | const Element & | x ) const

inline

Print field base element.

This function assumes the field base element has already been constructed and initialized.

Returns
  output stream to which field base element is written.

Parameters

  os | output stream to which field base element is written.
  x | field base element.

## read() [2/3]

std::istream & read | ( | std::istream & | is,
|  | Element & | x ) const

inline

Read field base element.

Precondition
  This function assumes the field base element has already been constructed and initialized.

Returns
  input stream from which field base element is read.

Parameters

  is | input stream from which field base element is read.
  x | field base element.

## read() [3/3]

std::istream & read | ( | std::istream & | is,
|  | BitReference | x ) const

inline

Print field.

Returns
  output stream to which field is written.

Parameters

  os | output stream to which field is written.

## add() [1/2]

GF2::Element & add | ( | Element & | x,
|  | const Element & | y,
|  | const Element & | z ) const

inline

Addition.

x = y + z This function assumes all the field base elements have already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).
  y | field base element.
  z | field base element.

## add() [2/2]

GF2::BitReference add | ( | BitReference | x,
|  | const Element & | y,
|  | const Element & | z ) const

inline

Equality of two elements.

This function assumes both field base elements have already been constructed and initialized.

Returns
  boolean true if equal, false if not.

Parameters

  x | field base element
  y | field base element

## sub() [1/2]

GF2::Element & sub | ( | Element & | x,
|  | const Element & | y,
|  | const Element & | z ) const

inline

Subtraction.

x = y - z This function assumes all the field base elements have already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).
  y | field base element.
  z | field base element.

## sub() [2/2]

GF2::BitReference sub | ( | BitReference | x,
|  | const Element & | y,
|  | const Element & | z ) const

inline

Equality of two elements.

This function assumes both field base elements have already been constructed and initialized.

Returns
  boolean true if equal, false if not.

Parameters

  x | field base element
  y | field base element

## mul() [1/2]

GF2::Element & mul | ( | Element & | x,
|  | const Element & | y,
|  | const Element & | z ) const

inline

Multiplication.

x = y * z This function assumes all the field base elements have already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).
  y | field base element.
  z | field base element.

## mul() [2/2]

GF2::BitReference mul | ( | BitReference | x,
|  | const Element & | y,
|  | const Element & | z ) const

inline

Equality of two elements.

This function assumes both field base elements have already been constructed and initialized.

Returns
  boolean true if equal, false if not.

Parameters

  x | field base element
  y | field base element

## div() [1/2]

GF2::Element & div | ( | Element & | x,
|  | const Element & | y,
|  | const Element & | z ) const

inline

Division.

x = y / z This function assumes all the field base elements have already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).
  y | field base element.
  z | field base element.

## div() [2/2]

GF2::BitReference div | ( | BitReference | x,
|  | const Element & | y,
|  | const Element & | z ) const

inline

Equality of two elements.

This function assumes both field base elements have already been constructed and initialized.

Returns
  boolean true if equal, false if not.

Parameters

  x | field base element
  y | field base element

## neg() [1/2]

GF2::Element & neg | ( | Element & | x,
|  | const Element & | y ) const

inline

Additive Inverse (Negation).

x = - y This function assumes both field base elements have already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).
  y | field base element.

## neg() [2/2]

GF2::BitReference neg | ( | BitReference | x,
|  | const Element & | y ) const

inline

Equality of two elements.

This function assumes both field base elements have already been constructed and initialized.

Returns
  boolean true if equal, false if not.

Parameters

  x | field base element
  y | field base element

## inv() [1/2]

GF2::Element & inv | ( | Element & | x,
|  | const Element & | y ) const

inline

Multiplicative Inverse.

x = 1 / y This function assumes both field base elements have already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).
  y | field base element.

## inv() [2/2]

GF2::BitReference inv | ( | BitReference | x,
|  | const Element & | y ) const

inline

Equality of two elements.

This function assumes both field base elements have already been constructed and initialized.

Returns
  boolean true if equal, false if not.

Parameters

  x | field base element
  y | field base element

## axpy() [1/2]

GF2::BitReference axpy | ( | BitReference | r,
|  | const Element & | a,
|  | const Element & | x,
|  | const Element & | y ) const

inline

Natural AXPY.

Returns
  reference to r.

Parameters

  r |
  a |
  x |
  y |

## axpy() [2/2]

GF2::Element & axpy | ( | Element & | r,
|  | const Element & | a,
|  | const Element & | x,
|  | const Element & | y ) const

inline

Equality of two elements.

This function assumes both field base elements have already been constructed and initialized.

Returns
  boolean true if equal, false if not.

Parameters

  x | field base element
  y | field base element

## axmy() [1/2]

GF2::BitReference axmy | ( | BitReference | r,
|  | const Element & | a,
|  | const Element & | x,
|  | const Element & | y ) const

inline

Natural AXMY.

Returns
  reference to r.

Parameters

  r |
  a |
  x |
  y |

## axmy() [2/2]

GF2::Element & axmy | ( | Element & | r,
|  | const Element & | a,
|  | const Element & | x,
|  | const Element & | y ) const

inline

Equality of two elements.

This function assumes both field base elements have already been constructed and initialized.

Returns
  boolean true if equal, false if not.

Parameters

  x | field base element
  y | field base element

## maxpy() [1/2]

GF2::BitReference maxpy | ( | BitReference | r,
|  | const Element & | a,
|  | const Element & | x,
|  | const Element & | y ) const

inline

Natural MAXPY.

Returns
  reference to r.

Parameters

  r |
  a |
  x |
  y |

## maxpy() [2/2]

GF2::Element & maxpy | ( | Element & | r,
|  | const Element & | a,
|  | const Element & | x,
|  | const Element & | y ) const

inline

Equality of two elements.

This function assumes both field base elements have already been constructed and initialized.

Returns
  boolean true if equal, false if not.

Parameters

  x | field base element
  y | field base element

## addin() [1/2]

GF2::Element & addin | ( | Element & | x,
|  | const Element & | y ) const

inline

Inplace Addition.

x += y This function assumes both field base elements have already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).
  y | field base element.

## addin() [2/2]

GF2::BitReference addin | ( | BitReference | x,
|  | const Element & | y ) const

inline

Inplace Addition.

x += y This function assumes both field base elements have already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).
  y | field base element.

## subin() [1/2]

GF2::Element & subin | ( | Element & | x,
|  | const Element & | y ) const

inline

Inplace Subtraction.

x -= y This function assumes both field base elements have already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).
  y | field base element.

## subin() [2/2]

GF2::BitReference subin | ( | BitReference | x,
|  | const Element & | y ) const

inline

Inplace Addition.

x += y This function assumes both field base elements have already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).
  y | field base element.

## mulin() [1/2]

GF2::Element & mulin | ( | Element & | x,
|  | const Element & | y ) const

inline

Inplace Multiplication.

x *= y This function assumes both field base elements have already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).
  y | field base element.

## mulin() [2/2]

GF2::BitReference mulin | ( | BitReference | x,
|  | const Element & | y ) const

inline

Inplace Addition.

x += y This function assumes both field base elements have already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).
  y | field base element.

## divin() [1/2]

GF2::Element & divin | ( | Element & | x,
|  | const Element & | y ) const

inline

Inplace Division.

x /= y This function assumes both field base elements have already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).
  y | field base element.

## divin() [2/2]

GF2::BitReference divin | ( | BitReference | x,
|  | const Element & | y ) const

inline

Inplace Addition.

x += y This function assumes both field base elements have already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).
  y | field base element.

## negin() [1/2]

GF2::Element & negin | ( | Element & | x | ) | const

inline

Inplace Additive Inverse (Inplace Negation).

x = - x This function assumes the field base element has already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).

## negin() [2/2]

GF2::BitReference negin | ( | BitReference | x | ) | const

inline

Inplace Addition.

x += y This function assumes both field base elements have already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).
  y | field base element.

## invin() [1/2]

GF2::Element & invin | ( | Element & | x | ) | const

inline

Inplace Multiplicative Inverse.

x = 1 / x This function assumes the field base elementhas already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).

## invin() [2/2]

GF2::BitReference invin | ( | BitReference | x | ) | const

inline

Inplace Addition.

x += y This function assumes both field base elements have already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).
  y | field base element.

## axpyin() [1/2]

GF2::Element & axpyin | ( | Element & | r,
|  | const Element & | a,
|  | const Element & | x ) const

inline

Inplace AXPY.

Returns
  reference to r.

Parameters

  r | field element (reference returned).
  a | field element.
  x | field element.

## axpyin() [2/2]

GF2::BitReference axpyin | ( | BitReference | r,
|  | const Element & | a,
|  | const Element & | x ) const

inline

Inplace Addition.

x += y This function assumes both field base elements have already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).
  y | field base element.

## axmyin() [1/2]

GF2::Element & axmyin | ( | Element & | r,
|  | const Element & | a,
|  | const Element & | x ) const

inline

Inplace AXMY.

Returns
  reference to r.

Parameters

  r | field element (reference returned).
  a | field element.
  x | field element.

## axmyin() [2/2]

GF2::BitReference axmyin | ( | BitReference | r,
|  | const Element & | a,
|  | const Element & | x ) const

inline

Inplace Addition.

x += y This function assumes both field base elements have already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).
  y | field base element.

## maxpyin() [1/2]

GF2::Element & maxpyin | ( | Element & | r,
|  | const Element & | a,
|  | const Element & | x ) const

inline

Inplace MAXPY.

Returns
  reference to r.

Parameters

  r | field element (reference returned).
  a | field element.
  x | field element.

## maxpyin() [2/2]

GF2::BitReference maxpyin | ( | BitReference | r,
|  | const Element & | a,
|  | const Element & | x ) const

inline

Inplace Addition.

x += y This function assumes both field base elements have already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).
  y | field base element.

## maxCardinality()

int maxCardinality | ( |  | ) |

inline static

Inplace Addition.

x += y This function assumes both field base elements have already been constructed and initialized.

Returns
  reference to x.

Parameters

  x | field base element (reference returned).
  y | field base element.

The documentation for this class was generated from the following files:

- gf2.h
- gf2.inl