LatMRG Guide  1.0
A software package to test and search for new linear congruential random number generators
LatMRG::MRGComponent< Int > Class Template Reference

This class is used to to test for full period length of generators and also to store a bit of information about generators without creating a lattice. More...

#include <latmrg/MRGComponent.h>

Public Member Functions

 MRGComponent (const Int &m, int k, DecompType decom1, const char *filem1, DecompType decor, const char *filer)
 Constructor with modulus \(m\) and order \(k\). More...
 
 MRGComponent (Int b, int e, Int r, int k, DecompType decom1, const char *filem1, DecompType decor, const char *filer)
 Same as the other constructors with m=b^e+r. More...
 
 MRGComponent (Modulus< Int > &modul, int k, DecompType decom1, const char *filem1, DecompType decor, const char *filer)
 Constructor similar to the above, except that the modulus of congruence \(m\) is inside the object modul. More...
 
 MRGComponent (const MRGComponent< Int > &comp)
 Copy constructor;. More...
 
 ~MRGComponent ()
 Destructor. More...
 
GenType get_type ()
 Gets the type of this component. More...
 
IntVec getA () const
 Gets the multipliers of the recurrence to \(A\). More...
 
Int & getB ()
 Returns the value of b with b^e+r = m. More...
 
int & getE ()
 Returns the value of e with b^e+r = m. More...
 
int getK () const
 Returns the value of the modulus \(m\) of the recurrence. More...
 
const Int getM () const
 Returns the value of the modulus \(m\) of the recurrence. More...
 
IntMat getMatrix () const
 Gets the matrix multipliers of the recurrence. More...
 
IntVecgetOrbitSeed ()
 Returns const reference of orbitSeed. More...
 
Int & getR ()
 Returns the value of r with b^e+r = m. More...
 
bool maxPeriod (const IntVec &A)
 Returns true if coefficients \(A\) give a MRG with maximal period; returns false otherwise. More...
 
bool maxPeriod (const Int &a)
 Returns true if \(a\) makes for a full period LCG with non-zero carry; returns false otherwise. More...
 
bool maxPeriod (const IntMat &A)
 Returns true if coefficients in \(A\) give a MMRG with maximal period; returns false otherwise. More...
 
bool maxPeriod23 (const IntVec &A)
 Returns true if coefficients \(A\) give a MRG with maximal period; returns false otherwise. More...
 
MRGComponent< Int > & operator= (const MRGComponent< Int > &comp)
 Assignment operator. More...
 
void set_type (GenType type)
 Sets the type of this component. More...
 
void setA (const IntVec &A)
 Sets the multipliers of the recurrence to \(A\). More...
 
void setA (const IntMat &A)
 Sets the matrix of the recurrence to \(A\). More...
 
void setPower2 (std::vector< IntVec > &coeffs)
 
std::string toString ()
 Returns this object as a string. More...
 

Public Attributes

Int m_MWCb
 The modulo of the MWC generator if we study one. More...
 

Private Types

typedef NTL::matrix< Int > IntMat
 
typedef NTL::vector< Int > IntVec
 

Private Member Functions

void init (const Int &m, int k, DecompType decom1, const char *filem1, DecompType decor, const char *filer)
 Does the same as the constructor above with similar arguments. More...
 

Private Attributes

IntFactorization< Int > factor
 The prime factor decomposition of \(m\). More...
 
IntFactorization< Int > ifm1
 The prime factor decomposition of \(m-1\). More...
 
IntFactorization< NTL::ZZ > ifm2
 The prime factor decomposition of \(m-1\). More...
 
IntFactorization< Int > ifr
 The prime factor decomposition of \(r=(m^k-1)/(m-1)\), where \(k\) is the order of the recurrence. More...
 
IntFactorization< NTL::ZZ > ifr2
 The prime factor decomposition of \(r=(m^k-1)/(m-1)\), where \(k\) is the order of the recurrence. More...
 
IntVec m_a
 The multipliers \(a_i\) of the recurrence, \(i = 1, …, k\). More...
 
IntMat m_A
 The generator matrix \(A\) of the recurrence for MMRG. More...
 
Int m_b
 Basis b with b^e+r = m. More...
 
int m_e
 Exponent e with b^e+r = m. More...
 
int m_k
 The order \(k\) of the recurrence. More...
 
Int m_r
 Rest r with b^e+r = m. More...
 
GenType m_type = LCG
 The type of generator this stores. More...
 
Modulus< Int > module
 The modulus \(m\) of the recurrence. More...
 
Int nj
 Value needed for the calculation of the multipliers of a combined MRG. More...
 
IntVec orbitSeed
 Contains the starting state of the component for the case when the lattice type is ORBIT. More...
 
Int rho
 The length of the period \(\rho\) for this MRG. More...
 

Detailed Description

template<typename Int>
class LatMRG::MRGComponent< Int >

This class is used to to test for full period length of generators and also to store a bit of information about generators without creating a lattice.

Each MRG component is defined by a modulus \(m\), an order \(k\) and a list of files and factorizations needed check the full period.

This class can also store

  • a vector of multipliers \(a\), where \(a[i-1]\) represents \(a_i\). This MRG satisfies the recurrence

    \[ x_n = (a_1 x_{n-1} + \cdots+ a_k x_{n-k}) \mbox{ mod } m \]

  • or a matrix A in case of MMRG

If it is used to check the period of another generator, the multipliers stored might change.

Member Typedef Documentation

◆ IntMat

template<typename Int >
typedef NTL::matrix<Int> LatMRG::MRGComponent< Int >::IntMat
private

◆ IntVec

template<typename Int >
typedef NTL::vector<Int> LatMRG::MRGComponent< Int >::IntVec
private

Constructor & Destructor Documentation

◆ MRGComponent() [1/4]

template<typename Int >
LatMRG::MRGComponent< Int >::MRGComponent ( const Int &  m,
int  k,
DecompType  decom1,
const char *  filem1,
DecompType  decor,
const char *  filer 
)

Constructor with modulus \(m\) and order \(k\).

Arguments decom1 and decor refer to the prime factor decomposition of \(m-1\) and \(r=(m^k-1)/(m-1)\), respectively. If decor equals DECOMP, the constructor will factorize \(r\). If decor equals DECOMP_WRITE, the constructor will factorize \(r\) and write the prime factors to file filer. If decor equals DECOMP_READ, the constructor will read the factors of \(r\) from file filer. If decor equals DECOMP_PRIME, \(r\) is assumed to be prime. Similar considerations apply to decom1 and filem1 with respect to \(m-1\).

◆ MRGComponent() [2/4]

template<typename Int >
LatMRG::MRGComponent< Int >::MRGComponent ( Int  b,
int  e,
Int  r,
int  k,
DecompType  decom1,
const char *  filem1,
DecompType  decor,
const char *  filer 
)

Same as the other constructors with m=b^e+r.

◆ MRGComponent() [3/4]

template<typename Int >
LatMRG::MRGComponent< Int >::MRGComponent ( Modulus< Int > &  modul,
int  k,
DecompType  decom1,
const char *  filem1,
DecompType  decor,
const char *  filer 
)

Constructor similar to the above, except that the modulus of congruence \(m\) is inside the object modul.

◆ ~MRGComponent()

template<typename Int >
LatMRG::MRGComponent< Int >::~MRGComponent ( )

Destructor.

◆ MRGComponent() [4/4]

template<typename Int >
LatMRG::MRGComponent< Int >::MRGComponent ( const MRGComponent< Int > &  comp)

Copy constructor;.

Member Function Documentation

◆ get_type()

template<typename Int >
GenType LatMRG::MRGComponent< Int >::get_type ( )
inline

Gets the type of this component.

◆ getA()

template<typename Int >
IntVec LatMRG::MRGComponent< Int >::getA ( ) const
inline

Gets the multipliers of the recurrence to \(A\).

◆ getB()

template<typename Int >
Int& LatMRG::MRGComponent< Int >::getB ( )
inline

Returns the value of b with b^e+r = m.

◆ getE()

template<typename Int >
int& LatMRG::MRGComponent< Int >::getE ( )
inline

Returns the value of e with b^e+r = m.

◆ getK()

template<typename Int >
int LatMRG::MRGComponent< Int >::getK ( ) const
inline

Returns the value of the modulus \(m\) of the recurrence.

◆ getM()

template<typename Int >
const Int LatMRG::MRGComponent< Int >::getM ( ) const
inline

Returns the value of the modulus \(m\) of the recurrence.

◆ getMatrix()

template<typename Int >
IntMat LatMRG::MRGComponent< Int >::getMatrix ( ) const
inline

Gets the matrix multipliers of the recurrence.

◆ getOrbitSeed()

template<typename Int >
IntVec& LatMRG::MRGComponent< Int >::getOrbitSeed ( )
inline

Returns const reference of orbitSeed.

◆ getR()

template<typename Int >
Int& LatMRG::MRGComponent< Int >::getR ( )
inline

Returns the value of r with b^e+r = m.

◆ init()

template<typename Int >
void LatMRG::MRGComponent< Int >::init ( const Int &  m,
int  k,
DecompType  decom1,
const char *  filem1,
DecompType  decor,
const char *  filer 
)
private

Does the same as the constructor above with similar arguments.

◆ maxPeriod() [1/3]

template<typename Int >
bool LatMRG::MRGComponent< Int >::maxPeriod ( const IntVec A)

Returns true if coefficients \(A\) give a MRG with maximal period; returns false otherwise.

Note that when calling this class it is necessary that a[i] = a_i.

◆ maxPeriod() [2/3]

template<typename Int >
bool LatMRG::MRGComponent< Int >::maxPeriod ( const Int &  a)

Returns true if \(a\) makes for a full period LCG with non-zero carry; returns false otherwise.

This checks the 2 following conditions :

  • If \(q\) is prime and divides \(m\), it must divide \(a-1\).
  • If 4 divides \(m\), it must divide \(a-1\).

The user must choose the carry himself. Any carry relatively prime to \(m\) will give full period.

◆ maxPeriod() [3/3]

template<typename Int >
bool LatMRG::MRGComponent< Int >::maxPeriod ( const IntMat A)

Returns true if coefficients in \(A\) give a MMRG with maximal period; returns false otherwise.

◆ maxPeriod23()

template<typename Int >
bool LatMRG::MRGComponent< Int >::maxPeriod23 ( const IntVec A)

Returns true if coefficients \(A\) give a MRG with maximal period; returns false otherwise.

This method supposes that condition 1 is true and tests only conditions 2 and 3. See method isPrimitive of class PolyPE on page (FIXME: page#) of this guide.

◆ operator=()

template<typename Int >
MRGComponent< Int > & LatMRG::MRGComponent< Int >::operator= ( const MRGComponent< Int > &  comp)

Assignment operator.

◆ set_type()

template<typename Int >
void LatMRG::MRGComponent< Int >::set_type ( GenType  type)
inline

Sets the type of this component.

◆ setA() [1/2]

template<typename Int >
void LatMRG::MRGComponent< Int >::setA ( const IntVec A)

Sets the multipliers of the recurrence to \(A\).

◆ setA() [2/2]

template<typename Int >
void LatMRG::MRGComponent< Int >::setA ( const IntMat A)

Sets the matrix of the recurrence to \(A\).

◆ setPower2()

template<typename Int >
void LatMRG::MRGComponent< Int >::setPower2 ( std::vector< IntVec > &  coeffs)

◆ toString()

template<typename Int >
std::string LatMRG::MRGComponent< Int >::toString ( )

Returns this object as a string.

Member Data Documentation

◆ factor

template<typename Int >
IntFactorization<Int> LatMRG::MRGComponent< Int >::factor
private

The prime factor decomposition of \(m\).

Used to compute the full period of a LCG with a carry.

◆ ifm1

template<typename Int >
IntFactorization<Int> LatMRG::MRGComponent< Int >::ifm1
private

The prime factor decomposition of \(m-1\).

◆ ifm2

template<typename Int >
IntFactorization<NTL::ZZ> LatMRG::MRGComponent< Int >::ifm2
private

The prime factor decomposition of \(m-1\).

This is used when computing the full period of a matrix generator. This is because we use NTL to compute the characteristic polynomial of the matrix since it is already implemented.

◆ ifr

template<typename Int >
IntFactorization<Int> LatMRG::MRGComponent< Int >::ifr
private

The prime factor decomposition of \(r=(m^k-1)/(m-1)\), where \(k\) is the order of the recurrence.

◆ ifr2

template<typename Int >
IntFactorization<NTL::ZZ> LatMRG::MRGComponent< Int >::ifr2
private

The prime factor decomposition of \(r=(m^k-1)/(m-1)\), where \(k\) is the order of the recurrence.

This is used when computing the full period of a matrix generator. This is because we use NTL to compute the characteristic polynomial of the matrix since it is already implemented.

◆ m_a

template<typename Int >
IntVec LatMRG::MRGComponent< Int >::m_a
private

The multipliers \(a_i\) of the recurrence, \(i = 1, …, k\).

◆ m_A

template<typename Int >
IntMat LatMRG::MRGComponent< Int >::m_A
private

The generator matrix \(A\) of the recurrence for MMRG.

◆ m_b

template<typename Int >
Int LatMRG::MRGComponent< Int >::m_b
private

Basis b with b^e+r = m.

◆ m_e

template<typename Int >
int LatMRG::MRGComponent< Int >::m_e
private

Exponent e with b^e+r = m.

◆ m_k

template<typename Int >
int LatMRG::MRGComponent< Int >::m_k
private

The order \(k\) of the recurrence.

◆ m_MWCb

template<typename Int >
Int LatMRG::MRGComponent< Int >::m_MWCb

The modulo of the MWC generator if we study one.

This is because the we check MWC period with module.m as the modulo of the equivalent LCG.

◆ m_r

template<typename Int >
Int LatMRG::MRGComponent< Int >::m_r
private

Rest r with b^e+r = m.

◆ m_type

template<typename Int >
GenType LatMRG::MRGComponent< Int >::m_type = LCG
private

The type of generator this stores.

Should be MRG, MMRG or MWC. The default value is LCG.

◆ module

template<typename Int >
Modulus<Int> LatMRG::MRGComponent< Int >::module
private

The modulus \(m\) of the recurrence.

◆ nj

template<typename Int >
Int LatMRG::MRGComponent< Int >::nj
private

Value needed for the calculation of the multipliers of a combined MRG.

It is defined by

\[ n_j = (m/m_j)^{-1} \mbox{ mod } m_j \qquad\mbox{ for } j = 1,…,J, \]

where \(n_j = \) nj, \(m_j\) is this object’s modulus m, \(m\) is the calculated modulus for the combined MRG (see class MRGLatticeFactory), and \((m/m_j)^{-1} \mbox{ mod } m_j\) is the inverse of \(m/m_j\) modulo \(m_j\). This value is calculated by MRGLatticeFactory and stored here for simplicity.

◆ orbitSeed

template<typename Int >
IntVec LatMRG::MRGComponent< Int >::orbitSeed
private

Contains the starting state of the component for the case when the lattice type is ORBIT.

It is made of \(k\) numbers.

◆ rho

template<typename Int >
Int LatMRG::MRGComponent< Int >::rho
private

The length of the period \(\rho\) for this MRG.

For now, the recurrence is assumed to correspond to a primitive polynomial and rho is calculated as

\[ \rho= m^k - 1 \]

This value is calculated by MRGLatticeFactory and stored here for simplicity.


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