Classes | Namespaces | Functions
vnl_finite.h File Reference

modulo-N arithmetic (finite ring Z_N and Z_N[X]) More...

#include <iostream>
#include <vector>
#include <cstddef>
#include <cassert>
#include "vnl/vnl_export.h"

Go to the source code of this file.

Classes

class  vnl_finite_int< N >
 finite modulo-N arithmetic. More...
 
class  vnl_finite_int_poly< N, M >
 finite modulo-N arithmetic with polynomials of degree < M. More...
 

Namespaces

 vnl_math
 real numerical constants.
 

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 > vnl_math::squared_magnitude (vnl_finite_int< N > const &x)
 
template<int N>
vnl_finite_int< N > vnl_math::sqr (vnl_finite_int< N > const &x)
 
template<int N>
bool vnl_math::isnan (vnl_finite_int< N > const &)
 
template<int N>
bool vnl_math::isfinite (vnl_finite_int< N > const &)
 
template<int N, int M>
vnl_finite_int_poly< N, M > operator+ (vnl_finite_int_poly< N, M > const &r1, vnl_finite_int_poly< N, M > const &r2)
 Returns the sum of two finite int polynomials. More...
 
template<int N, int M>
vnl_finite_int_poly< N, M > operator- (vnl_finite_int_poly< N, M > const &r1, vnl_finite_int_poly< N, M > const &r2)
 Returns the difference of two finite int polynomials. More...
 
template<int N, int M>
vnl_finite_int_poly< N, M > operator * (vnl_finite_int_poly< N, M > const &r1, vnl_finite_int< N > const &r2)
 Returns a scalar multiple of a finite int polynomial. More...
 
template<int N, int M>
vnl_finite_int_poly< N, M > operator * (vnl_finite_int< N > const &r2, vnl_finite_int_poly< N, M > const &r1)
 Returns a scalar multiple of a finite int polynomial. More...
 
template<int N, int M>
vnl_finite_int_poly< N, M > operator * (vnl_finite_int_poly< N, M > const &r1, vnl_finite_int_poly< N, M > const &r2)
 Multiplies two finite int polynomials. More...
 
template<int N, int M>
std::ostream & operator<< (std::ostream &s, vnl_finite_int_poly< N, M > const &r)
 formatted output. More...
 

Detailed Description

modulo-N arithmetic (finite ring Z_N and Z_N[X])

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.

Note that this does not cover finite fields with non-prime sizes (4,8,9,...). These are covered by the vnl_finite_int_poly<N,M> class, which implements arithmetic with polynomials of degree < M over vnl_finite_int<N>. Multiplication is defined modulo a degree M polynomial.

For N prime, and when the "modulo" polynomial is irreducible, vnl_finite_int_poly<N,M> implements the finite field GF(N^M).

Author
Peter Vanroose, K.U.Leuven, ESAT/PSI.
Date
5 May 2002.
 Modifications
  1 June 2002 - Peter Vanroose - added totient(), decompose(), is_unit(), order(), log(), exp().
  4 June 2002 - Peter Vanroose - renamed class and file name
  8 June 2002 - Peter Vanroose - added vnl_finite_int_poly<N,M>
  16 Dec 2007 - Peter Vanroose - more efficient implementation of Ntothe()

Definition in file vnl_finite.h.

Function Documentation

◆ operator *() [1/6]

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

Returns the product of two finite int numbers.

Definition at line 336 of file vnl_finite.h.

◆ operator *() [2/6]

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

Returns the product of two finite int numbers.

Definition at line 344 of file vnl_finite.h.

◆ operator *() [3/6]

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

Returns the product of two finite int numbers.

Definition at line 352 of file vnl_finite.h.

◆ operator *() [4/6]

template<int N, int M>
vnl_finite_int_poly< N, M > operator * ( vnl_finite_int_poly< N, M > const &  r1,
vnl_finite_int< N > const &  r2 
)
inline

Returns a scalar multiple of a finite int polynomial.

Definition at line 608 of file vnl_finite.h.

◆ operator *() [5/6]

template<int N, int M>
vnl_finite_int_poly< N, M > operator * ( vnl_finite_int< N > const &  r2,
vnl_finite_int_poly< N, M > const &  r1 
)
inline

Returns a scalar multiple of a finite int polynomial.

Definition at line 617 of file vnl_finite.h.

◆ operator *() [6/6]

template<int N, int M>
vnl_finite_int_poly< N, M > operator * ( vnl_finite_int_poly< N, M > const &  r1,
vnl_finite_int_poly< N, M > const &  r2 
)
inline

Multiplies two finite int polynomials.

NOTE: this requires the "modulo" polynomial to be set. Do this by calling modulo_polynomial(p), where p is a vector of length M+1.

Definition at line 627 of file vnl_finite.h.

◆ operator!=()

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

Definition at line 390 of file vnl_finite.h.

◆ operator+() [1/4]

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

Returns the sum of two finite int numbers.

Definition at line 288 of file vnl_finite.h.

◆ operator+() [2/4]

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

Returns the sum of two finite int numbers.

Definition at line 296 of file vnl_finite.h.

◆ operator+() [3/4]

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

Returns the sum of two finite int numbers.

Definition at line 304 of file vnl_finite.h.

◆ operator+() [4/4]

template<int N, int M>
vnl_finite_int_poly< N, M > operator+ ( vnl_finite_int_poly< N, M > const &  r1,
vnl_finite_int_poly< N, M > const &  r2 
)
inline

Returns the sum of two finite int polynomials.

Definition at line 591 of file vnl_finite.h.

◆ operator-() [1/4]

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

Returns the difference of two finite int numbers.

Definition at line 312 of file vnl_finite.h.

◆ operator-() [2/4]

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

Returns the difference of two finite int numbers.

Definition at line 320 of file vnl_finite.h.

◆ operator-() [3/4]

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

Returns the difference of two finite int numbers.

Definition at line 328 of file vnl_finite.h.

◆ operator-() [4/4]

template<int N, int M>
vnl_finite_int_poly< N, M > operator- ( vnl_finite_int_poly< N, M > const &  r1,
vnl_finite_int_poly< N, M > const &  r2 
)
inline

Returns the difference of two finite int polynomials.

Definition at line 599 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 
)
inline

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 
)
inline

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 
)
inline

Returns the quotient of two finite int numbers.

Definition at line 377 of file vnl_finite.h.

◆ operator<<() [1/2]

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

formatted output.

Definition at line 272 of file vnl_finite.h.

◆ operator<<() [2/2]

template<int N, int M>
std::ostream & operator<< ( std::ostream &  s,
vnl_finite_int_poly< N, M > const &  r 
)
inline

formatted output.

Definition at line 635 of file vnl_finite.h.

◆ operator==()

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

Definition at line 385 of file vnl_finite.h.

◆ operator>>()

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

simple input.

Definition at line 280 of file vnl_finite.h.