Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Related Functions | List of all members
vnl_finite_int< N > Class Template Reference

finite modulo-N arithmetic. More...

#include <vnl_finite.h>

Public Member Functions

 vnl_finite_int (int x=0)
 Creates a finite int element. More...
 
 vnl_finite_int (Base const &x)
 
 ~vnl_finite_int ()=default
 
 operator int () const
 
 operator int ()
 
 operator long () const
 
 operator long ()
 
 operator short () const
 
 operator short ()
 
Baseoperator= (Base const &x)
 Assignment. More...
 
Baseoperator= (int x)
 
bool operator== (Base const &x) const
 Comparison of finite int numbers. More...
 
bool operator!= (Base const &x) const
 
bool operator== (int x) const
 
bool operator!= (int x) const
 
Base operator- () const
 Unary minus - returns the additive inverse. More...
 
Base operator+ () const
 Unary plus - returns the current number. More...
 
bool operator! () const
 Unary not - returns true if finite int number is equal to zero. More...
 
Baseoperator+= (Base const &r)
 Plus&assign: replace lhs by lhs + rhs. More...
 
Baseoperator+= (int r)
 
Baseoperator-= (Base const &r)
 Minus&assign: replace lhs by lhs - rhs. More...
 
Baseoperator-= (int r)
 
Baseoperator *= (int r)
 Multiply&assign: replace lhs by lhs * rhs. More...
 
Baseoperator *= (Base const &r)
 Multiply&assign: replace lhs by lhs * rhs. More...
 
Base reciproc () const
 Multiplicative inverse. More...
 
Baseoperator/= (Base const &r)
 Divide&assign. Uses r.reciproc() for efficient computation. More...
 
Baseoperator++ ()
 Pre-increment (++r). More...
 
Baseoperator-- ()
 Pre-decrement (–r). More...
 
Base operator++ (int)
 Post-increment (r++). More...
 
Base operator-- (int)
 Post-decrement (r–). More...
 
bool is_unit () const
 Return true only when x is a unit in this ring. More...
 
bool is_zero_divisor () const
 Return true only when x is a zero divisor, i.e., is not a unit. More...
 
unsigned int additive_order () const
 The additive order of x is the smallest nonnegative r such that r*x == 0. More...
 
unsigned int multiplicative_order () const
 The multiplicative order of x is the smallest r (>0) such that x^r == 1. More...
 
Base pow (int r)
 Return the r-th power of this number. More...
 
unsigned int log () const
 Return the smallest nonnegative exponent r for which x=g^r, where g is the smallest generator. More...
 

Static Public Member Functions

static unsigned int cardinality ()
 The number of different finite_int numbers of this type. More...
 
static unsigned int totient ()
 Return the Euler totient function, i.e., the number of units of this ring. More...
 
static std::vector< unsigned int > decompose ()
 Write N as the unique product of prime factors. More...
 
static bool is_field ()
 Return true when N is a prime number, i.e., when this ring is a field. More...
 
static Base smallest_generator ()
 Return the smallest multiplicative generator of the units in this ring. More...
 
static Base exp (int r)
 Return the inverse of log(), i.e., return g^r where g is the smallest generator. More...
 
static unsigned int gcd (unsigned int l, unsigned int n)
 Calculate the greatest common divisor of l and N. More...
 
static unsigned int gcd (unsigned int l)
 

Private Types

typedef vnl_finite_int< N > Base
 

Private Member Functions

void set_log (unsigned int r) const
 private function to set cached value of lp1_ when available. More...
 

Private Attributes

int val_
 value of this number (smallest nonnegative representation) More...
 
unsigned int mo_
 cached value for multiplicative order More...
 
unsigned int lp1_
 cached value for 1+log() More...
 

Related Functions

(Note that these are not member functions.)

template<int N>
std::ostream & operator<< (std::ostream &s, vnl_finite_int< N > const &r)
 formatted output. More...
 
template<int N>
std::istream & operator>> (std::istream &s, vnl_finite_int< N > &r)
 simple input. More...
 
template<int N>
vnl_finite_int< N > operator+ (vnl_finite_int< N > const &r1, vnl_finite_int< N > const &r2)
 Returns the sum of two finite int numbers. More...
 
template<int N>
vnl_finite_int< N > operator+ (vnl_finite_int< N > const &r1, int r2)
 Returns the sum of two finite int numbers. More...
 
template<int N>
vnl_finite_int< N > operator+ (int r2, vnl_finite_int< N > const &r1)
 Returns the sum of two finite int numbers. More...
 
template<int N>
vnl_finite_int< N > operator- (vnl_finite_int< N > const &r1, vnl_finite_int< N > const &r2)
 Returns the difference of two finite int numbers. More...
 
template<int N>
vnl_finite_int< N > operator- (vnl_finite_int< N > const &r1, int r2)
 Returns the difference of two finite int numbers. More...
 
template<int N>
vnl_finite_int< N > operator- (int r2, vnl_finite_int< N > const &r1)
 Returns the difference of two finite int numbers. More...
 
template<int N>
vnl_finite_int< N > operator * (vnl_finite_int< N > const &r1, vnl_finite_int< N > const &r2)
 Returns the product of two finite int numbers. More...
 
template<int N>
vnl_finite_int< N > operator * (vnl_finite_int< N > const &r1, int r2)
 Returns the product of two finite int numbers. More...
 
template<int N>
vnl_finite_int< N > operator * (int r2, vnl_finite_int< N > const &r1)
 Returns the product of two finite int numbers. More...
 
template<int N>
vnl_finite_int< N > operator/ (vnl_finite_int< N > const &r1, vnl_finite_int< N > const &r2)
 Returns the quotient of two finite int numbers. More...
 
template<int N>
vnl_finite_int< N > operator/ (vnl_finite_int< N > const &r1, int r2)
 Returns the quotient of two finite int numbers. More...
 
template<int N>
vnl_finite_int< N > operator/ (int r1, vnl_finite_int< N > const &r2)
 Returns the quotient of two finite int numbers. More...
 
template<int N>
bool operator== (int r1, vnl_finite_int< N > const &r2)
 
template<int N>
bool operator!= (int r1, vnl_finite_int< N > const &r2)
 
template<int N>
vnl_finite_int< N > squared_magnitude (vnl_finite_int< N > const &x)
 
template<int N>
vnl_finite_int< N > sqr (vnl_finite_int< N > const &x)
 
template<int N>
bool isnan (vnl_finite_int< N > const &)
 
template<int N>
bool isfinite (vnl_finite_int< N > const &)
 

Detailed Description

template<int N>
class vnl_finite_int< N >

finite modulo-N arithmetic.

The templated vnl_finite_int<N> provides arithmetic "modulo N", i.e., arithmetic in the finite (Galois) field GF(N) in case N is a prime or just in the finite ring (or semi-field) of integers modulo N otherwise. In that case division makes no sense (unless no zero divisor is involved), but all other operations remain valid.

Definition at line 52 of file vnl_finite.h.

Member Typedef Documentation

◆ Base

template<int N>
typedef vnl_finite_int<N> vnl_finite_int< N >::Base
private

Definition at line 57 of file vnl_finite.h.

Constructor & Destructor Documentation

◆ vnl_finite_int() [1/2]

template<int N>
vnl_finite_int< N >::vnl_finite_int ( int  x = 0)
inline

Creates a finite int element.

Default constructor gives 0. Also serves as automatic cast from int to vnl_finite_int.

Definition at line 65 of file vnl_finite.h.

◆ vnl_finite_int() [2/2]

template<int N>
vnl_finite_int< N >::vnl_finite_int ( Base const &  x)
inline

Definition at line 67 of file vnl_finite.h.

◆ ~vnl_finite_int()

template<int N>
vnl_finite_int< N >::~vnl_finite_int ( )
inlinedefault

Member Function Documentation

◆ additive_order()

template<int N>
unsigned int vnl_finite_int< N >::additive_order ( ) const
inline

The additive order of x is the smallest nonnegative r such that r*x == 0.

Definition at line 191 of file vnl_finite.h.

◆ cardinality()

template<int N>
static unsigned int vnl_finite_int< N >::cardinality ( )
inlinestatic

The number of different finite_int numbers of this type.

Definition at line 60 of file vnl_finite.h.

◆ decompose()

template<int N>
static std::vector<unsigned int> vnl_finite_int< N >::decompose ( )
inlinestatic

Write N as the unique product of prime factors.

Definition at line 166 of file vnl_finite.h.

◆ exp()

template<int N>
static Base vnl_finite_int< N >::exp ( int  r)
inlinestatic

Return the inverse of log(), i.e., return g^r where g is the smallest generator.

Definition at line 247 of file vnl_finite.h.

◆ gcd() [1/2]

template<int N>
static unsigned int vnl_finite_int< N >::gcd ( unsigned int  l,
unsigned int  n 
)
inlinestatic

Calculate the greatest common divisor of l and N.

Definition at line 254 of file vnl_finite.h.

◆ gcd() [2/2]

template<int N>
static unsigned int vnl_finite_int< N >::gcd ( unsigned int  l)
inlinestatic

Definition at line 259 of file vnl_finite.h.

◆ is_field()

template<int N>
static bool vnl_finite_int< N >::is_field ( )
inlinestatic

Return true when N is a prime number, i.e., when this ring is a field.

Definition at line 177 of file vnl_finite.h.

◆ is_unit()

template<int N>
bool vnl_finite_int< N >::is_unit ( ) const
inline

Return true only when x is a unit in this ring.

In a field, all numbers except 0 are units. The total number of units is given by the Euler totient function.

Definition at line 185 of file vnl_finite.h.

◆ is_zero_divisor()

template<int N>
bool vnl_finite_int< N >::is_zero_divisor ( ) const
inline

Return true only when x is a zero divisor, i.e., is not a unit.

Definition at line 188 of file vnl_finite.h.

◆ log()

template<int N>
unsigned int vnl_finite_int< N >::log ( ) const
inline

Return the smallest nonnegative exponent r for which x=g^r, where g is the smallest generator.

Definition at line 233 of file vnl_finite.h.

◆ multiplicative_order()

template<int N>
unsigned int vnl_finite_int< N >::multiplicative_order ( ) const
inline

The multiplicative order of x is the smallest r (>0) such that x^r == 1.

Definition at line 194 of file vnl_finite.h.

◆ operator *=() [1/2]

template<int N>
Base& vnl_finite_int< N >::operator *= ( int  r)
inline

Multiply&assign: replace lhs by lhs * rhs.

Definition at line 103 of file vnl_finite.h.

◆ operator *=() [2/2]

template<int N>
Base& vnl_finite_int< N >::operator *= ( Base const &  r)
inline

Multiply&assign: replace lhs by lhs * rhs.

Definition at line 110 of file vnl_finite.h.

◆ operator int() [1/2]

template<int N>
vnl_finite_int< N >::operator int ( ) const
inline

Definition at line 71 of file vnl_finite.h.

◆ operator int() [2/2]

template<int N>
vnl_finite_int< N >::operator int ( )
inline

Definition at line 72 of file vnl_finite.h.

◆ operator long() [1/2]

template<int N>
vnl_finite_int< N >::operator long ( ) const
inline

Definition at line 73 of file vnl_finite.h.

◆ operator long() [2/2]

template<int N>
vnl_finite_int< N >::operator long ( )
inline

Definition at line 74 of file vnl_finite.h.

◆ operator short() [1/2]

template<int N>
vnl_finite_int< N >::operator short ( ) const
inline

Definition at line 75 of file vnl_finite.h.

◆ operator short() [2/2]

template<int N>
vnl_finite_int< N >::operator short ( )
inline

Definition at line 76 of file vnl_finite.h.

◆ operator!()

template<int N>
bool vnl_finite_int< N >::operator! ( ) const
inline

Unary not - returns true if finite int number is equal to zero.

Definition at line 94 of file vnl_finite.h.

◆ operator!=() [1/2]

template<int N>
bool vnl_finite_int< N >::operator!= ( Base const &  x) const
inline

Definition at line 85 of file vnl_finite.h.

◆ operator!=() [2/2]

template<int N>
bool vnl_finite_int< N >::operator!= ( int  x) const
inline

Definition at line 87 of file vnl_finite.h.

◆ operator+()

template<int N>
Base vnl_finite_int< N >::operator+ ( ) const
inline

Unary plus - returns the current number.

Definition at line 92 of file vnl_finite.h.

◆ operator++() [1/2]

template<int N>
Base& vnl_finite_int< N >::operator++ ( )
inline

Pre-increment (++r).

Definition at line 157 of file vnl_finite.h.

◆ operator++() [2/2]

template<int N>
Base vnl_finite_int< N >::operator++ ( int  )
inline

Post-increment (r++).

Definition at line 161 of file vnl_finite.h.

◆ operator+=() [1/2]

template<int N>
Base& vnl_finite_int< N >::operator+= ( Base const &  r)
inline

Plus&assign: replace lhs by lhs + rhs.

Definition at line 97 of file vnl_finite.h.

◆ operator+=() [2/2]

template<int N>
Base& vnl_finite_int< N >::operator+= ( int  r)
inline

Definition at line 98 of file vnl_finite.h.

◆ operator-()

template<int N>
Base vnl_finite_int< N >::operator- ( ) const
inline

Unary minus - returns the additive inverse.

Definition at line 90 of file vnl_finite.h.

◆ operator--() [1/2]

template<int N>
Base& vnl_finite_int< N >::operator-- ( )
inline

Pre-decrement (–r).

Definition at line 159 of file vnl_finite.h.

◆ operator--() [2/2]

template<int N>
Base vnl_finite_int< N >::operator-- ( int  )
inline

Post-decrement (r–).

Definition at line 163 of file vnl_finite.h.

◆ operator-=() [1/2]

template<int N>
Base& vnl_finite_int< N >::operator-= ( Base const &  r)
inline

Minus&assign: replace lhs by lhs - rhs.

Definition at line 100 of file vnl_finite.h.

◆ operator-=() [2/2]

template<int N>
Base& vnl_finite_int< N >::operator-= ( int  r)
inline

Definition at line 101 of file vnl_finite.h.

◆ operator/=()

template<int N>
Base& vnl_finite_int< N >::operator/= ( Base const &  r)
inline

Divide&assign. Uses r.reciproc() for efficient computation.

Definition at line 151 of file vnl_finite.h.

◆ operator=() [1/2]

template<int N>
Base& vnl_finite_int< N >::operator= ( Base const &  x)
inline

Assignment.

Definition at line 79 of file vnl_finite.h.

◆ operator=() [2/2]

template<int N>
Base& vnl_finite_int< N >::operator= ( int  x)
inline

Definition at line 80 of file vnl_finite.h.

◆ operator==() [1/2]

template<int N>
bool vnl_finite_int< N >::operator== ( Base const &  x) const
inline

Comparison of finite int numbers.

Note that finite ints have no order, so < and > make no sense.

Definition at line 84 of file vnl_finite.h.

◆ operator==() [2/2]

template<int N>
bool vnl_finite_int< N >::operator== ( int  x) const
inline

Definition at line 86 of file vnl_finite.h.

◆ pow()

template<int N>
Base vnl_finite_int< N >::pow ( int  r)
inline

Return the r-th power of this number.

Definition at line 224 of file vnl_finite.h.

◆ reciproc()

template<int N>
Base vnl_finite_int< N >::reciproc ( ) const
inline

Multiplicative inverse.

Uses exp() and log() for efficient computation, unless log() is not defined.

Definition at line 138 of file vnl_finite.h.

◆ set_log()

template<int N>
void vnl_finite_int< N >::set_log ( unsigned int  r) const
inlineprivate

private function to set cached value of lp1_ when available.

Definition at line 263 of file vnl_finite.h.

◆ smallest_generator()

template<int N>
static Base vnl_finite_int< N >::smallest_generator ( )
inlinestatic

Return the smallest multiplicative generator of the units in this ring.

This is only possible if the units form a cyclic group for multiplication. If not, smallest_generator() returns 1 to indicate this fact. Note that the multiplication group of a finite field is always cyclic.

Definition at line 206 of file vnl_finite.h.

◆ totient()

template<int N>
static unsigned int vnl_finite_int< N >::totient ( )
inlinestatic

Return the Euler totient function, i.e., the number of units of this ring.

This number also equals the periodicity of the exponent: every unit, when raised to this power, yields 1.

Definition at line 122 of file vnl_finite.h.

Friends And Related Function Documentation

◆ isfinite()

template<int N>
bool isfinite ( vnl_finite_int< N > const &  )
related

Definition at line 412 of file vnl_finite.h.

◆ isnan()

template<int N>
bool isnan ( vnl_finite_int< N > const &  )
related

Definition at line 407 of file vnl_finite.h.

◆ operator *() [1/3]

template<int N>
vnl_finite_int< N > operator * ( vnl_finite_int< N > const &  r1,
vnl_finite_int< N > const &  r2 
)
related

Returns the product of two finite int numbers.

Definition at line 336 of file vnl_finite.h.

◆ operator *() [2/3]

template<int N>
vnl_finite_int< N > operator * ( vnl_finite_int< N > const &  r1,
int  r2 
)
related

Returns the product of two finite int numbers.

Definition at line 344 of file vnl_finite.h.

◆ operator *() [3/3]

template<int N>
vnl_finite_int< N > operator * ( int  r2,
vnl_finite_int< N > const &  r1 
)
related

Returns the product of two finite int numbers.

Definition at line 352 of file vnl_finite.h.

◆ operator!=()

template<int N>
bool operator!= ( int  r1,
vnl_finite_int< N > const &  r2 
)
related

Definition at line 390 of file vnl_finite.h.

◆ operator+() [1/3]

template<int N>
vnl_finite_int< N > operator+ ( vnl_finite_int< N > const &  r1,
vnl_finite_int< N > const &  r2 
)
related

Returns the sum of two finite int numbers.

Definition at line 288 of file vnl_finite.h.

◆ operator+() [2/3]

template<int N>
vnl_finite_int< N > operator+ ( vnl_finite_int< N > const &  r1,
int  r2 
)
related

Returns the sum of two finite int numbers.

Definition at line 296 of file vnl_finite.h.

◆ operator+() [3/3]

template<int N>
vnl_finite_int< N > operator+ ( int  r2,
vnl_finite_int< N > const &  r1 
)
related

Returns the sum of two finite int numbers.

Definition at line 304 of file vnl_finite.h.

◆ operator-() [1/3]

template<int N>
vnl_finite_int< N > operator- ( vnl_finite_int< N > const &  r1,
vnl_finite_int< N > const &  r2 
)
related

Returns the difference of two finite int numbers.

Definition at line 312 of file vnl_finite.h.

◆ operator-() [2/3]

template<int N>
vnl_finite_int< N > operator- ( vnl_finite_int< N > const &  r1,
int  r2 
)
related

Returns the difference of two finite int numbers.

Definition at line 320 of file vnl_finite.h.

◆ operator-() [3/3]

template<int N>
vnl_finite_int< N > operator- ( int  r2,
vnl_finite_int< N > const &  r1 
)
related

Returns the difference of two finite int numbers.

Definition at line 328 of file vnl_finite.h.

◆ operator/() [1/3]

template<int N>
vnl_finite_int< N > operator/ ( vnl_finite_int< N > const &  r1,
vnl_finite_int< N > const &  r2 
)
related

Returns the quotient of two finite int numbers.

Uses r2.reciproc() for efficient computation.

Definition at line 361 of file vnl_finite.h.

◆ operator/() [2/3]

template<int N>
vnl_finite_int< N > operator/ ( vnl_finite_int< N > const &  r1,
int  r2 
)
related

Returns the quotient of two finite int numbers.

Definition at line 369 of file vnl_finite.h.

◆ operator/() [3/3]

template<int N>
vnl_finite_int< N > operator/ ( int  r1,
vnl_finite_int< N > const &  r2 
)
related

Returns the quotient of two finite int numbers.

Definition at line 377 of file vnl_finite.h.

◆ operator<<()

template<int N>
std::ostream & operator<< ( std::ostream &  s,
vnl_finite_int< N > const &  r 
)
related

formatted output.

Definition at line 272 of file vnl_finite.h.

◆ operator==()

template<int N>
bool operator== ( int  r1,
vnl_finite_int< N > const &  r2 
)
related

Definition at line 385 of file vnl_finite.h.

◆ operator>>()

template<int N>
std::istream & operator>> ( std::istream &  s,
vnl_finite_int< N > &  r 
)
related

simple input.

Definition at line 280 of file vnl_finite.h.

◆ sqr()

template<int N>
vnl_finite_int< N > sqr ( vnl_finite_int< N > const &  x)
related

Definition at line 402 of file vnl_finite.h.

◆ squared_magnitude()

template<int N>
vnl_finite_int< N > squared_magnitude ( vnl_finite_int< N > const &  x)
related

Definition at line 397 of file vnl_finite.h.

Member Data Documentation

◆ lp1_

template<int N>
unsigned int vnl_finite_int< N >::lp1_
mutableprivate

cached value for 1+log()

Definition at line 266 of file vnl_finite.h.

◆ mo_

template<int N>
unsigned int vnl_finite_int< N >::mo_
mutableprivate

cached value for multiplicative order

Definition at line 265 of file vnl_finite.h.

◆ val_

template<int N>
int vnl_finite_int< N >::val_
private

value of this number (smallest nonnegative representation)

Definition at line 55 of file vnl_finite.h.


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