CoCoALib-0.9905 date: 23 May 2007


CoCoA::SmallFpDoubleImpl Class Reference

#include <SmallFpDoubleImpl.H>

Collaboration diagram for CoCoA::SmallFpDoubleImpl:

Collaboration graph
[legend]
List of all members.

Public Types

typedef double value_t

Public Member Functions

 SmallFpDoubleImpl (unsigned long p)
 SmallFpDoubleImpl (const ZZ &P)
void myAssignZero (value_t &lhs) const
 lhs = 0
void myAssign (value_t &lhs, value_t x) const
 lhs = x
void myAssign (value_t &lhs, long n) const
 lhs = n
void myAssign (value_t &lhs, const ZZ &N) const
 lhs = N
void myNegate (value_t &lhs, value_t x) const
 lhs = -x
void myAdd (value_t &lhs, value_t x, value_t y) const
 lhs = x+y
void mySub (value_t &lhs, value_t x, value_t y) const
 lhs = x-y
void myMul (value_t &lhs, value_t x, value_t y) const
 lhs = x*y
void myDiv (value_t &lhs, value_t x, value_t y) const
 lhs = x/y
bool myIsDivisible (value_t &lhs, value_t x, value_t y) const
 lhs = x/y, if y is non-zero
void myPower (value_t &lhs, value_t x, unsigned long n) const
 lhs = x^n
void myOutput (std::ostream &out, value_t x) const
 out << x
void myOutput (OpenMathOutput &OMOut, value_t x) const
 OMOut << x.
bool myIsPrintAtom (value_t x) const
bool myIsPrintedWithMinus (value_t x) const
bool myIsZero (value_t x) const
 x == 0
bool myIsOne (value_t x) const
 x == 1
bool myIsMinusOne (value_t x) const
 x == -1
bool myIsInteger (ZZ &N, value_t x) const
 copy value of x into n, result is always true
bool myIsZeroAddMul (value_t &lhs, value_t y, value_t z) const
bool myIsEqual (value_t x, value_t y) const

Static Public Attributes

static const std::size_t DatumSize = sizeof(value_t)

Private Member Functions

 SmallFpDoubleImpl (const SmallFpDoubleImpl &)
SmallFpDoubleImploperator= (const SmallFpDoubleImpl &)
value_t myReduceMod (value_t n) const

Static Private Member Functions

static value_t CheckCtorArg (unsigned long p)
static value_t CheckCtorArg (const ZZ &P)
static value_t CalcDrop (value_t p)
static value_t CalcIterLimit (value_t p)
static value_t MaxInt ()

Private Attributes

const value_t myModulus
const value_t myDrop
const value_t myIterLimit

Detailed Description

      Copyright (c)  2005 John Abbott
      Permission is granted to copy, distribute and/or modify this document
      under the terms of the GNU Free Documentation License, Version 1.2;
      with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
      A copy of the licence is included in the file COPYING in this directory.



User documentation for SmallFpDoubleImpl
========================================

The class [SmallFpDoubleImpl] is NOT INTENDED for use by "casual" CoCoALib
users.  If you wish to compute in finite fields see the documentation in
QuotientRing.txt (in particular the function [NewZmod]), or possibly the
documentation in RingFp.txt, RingFpLog.txt, and RingFpDouble.txt.

Compared to [SmallFpImpl] the main difference is an implementation
detail: values are represnted as [double]s -- on 32-bit computers this
allows a potentially usefully greater range of characteristics at a
probably minor run-time cost.


A [SmallFpDoubleImpl] object cannot be used as a CoCoA ring, even though the
implementation is rather reminiscent of a ring implementation class.
ALL OPERATIONS on values must be effected by calling member functions
of the [SmallFpDoubleImpl] class.  Here is a brief summary.

  SmallFpDoubleImpl ModP(p);   // create SmallFpDoubleImpl object
  int n;
  ZZ N;
  SmallFpImpl::value_t a, b, c;

  ModP.myAssign(a, b);         // a = b;
  ModP.myAssign(a, n);         // a = n%p; (reduce mod p)
  ModP.myAssign(a, N);         // a = N%p; (reduce mod p)
  ModP.myNegate(a, b);         // a = -b;

  ModP.myAdd(a, b, c);         // a = (b+c)%p;
  ModP.mySub(a, b, c);         // a = (b-c)%p;
  ModP.myMul(a, b, c);         // a = (b*c)%p;
  ModP.myDiv(a, b, c);         // a = (b*inv(c))%p;
                                  where inv(c) is inverse of c

  ModP.myIsZero(a);            // a == 0
  ModP.myIsOne(a);             // a == 1
  ModP.myIsMinusOne(a);        // a == -1
  ModP.myIsInteger(N, a);      // N = a (find a preimage)
  ModP.myIsEqual(a, b);        // a == b

  ModP.myOutput(cout, a);      // cout << a;


Maintainer documentation for SmallFpDoubleImpl
==============================================

Most functions are implemented inline, and no sanity checks are
performed (except when CoCoA_DEBUG is enabled).  The constructor
does do some checking.  The basic idea is to use the extra precision
available in [double]s to allow larger prime finite fields than are
permitted when 32-bit integers are used for all arithmetic.  If fast
64-bit arithmetic becomes widespread then this class will probably
become obsolete (unless you have a very fast floating point coprocessor?).

[SmallFpDoubleImpl::value_t] is simply [double].  Note that the values
are always non-negative integers with maximum value less than
[myModulus]; i.e. each residue class is represented by its least
non-negative member.  The printed form reflects this choice of
representative.


To avoid problems with "overflow" the constructor checks that all
integers from 0 to p*p+p can be represented exactly.  We need to allow
numbers as big as p*p+p so that [myIsZeroAddMul] can be implemented easily.

It is not strictly necessary that [myModulus] be prime, though division
becomes only a partial map if [myModulus] is composite.  I believe it is
safest to insist that [myModulus] be prime -- the function [myIsDivisible]
does indeed assume that [myModulus] is prime.


Bugs, Shortcomings, and other ideas
===================================

BUG:  The use of [IsSmallPrime] in the ctor prevents use of primes
whose square is too large for an [unsigned long].  Need a specific
function which allows larger primes (on 32-bit machines).

BUG: the function [myIsInteger] assumes that any valid residue is
small enough to fit into a [long].  Strictly C++ does not guarantee
this.

The implementation is simplistic -- I wanted to dash it off quickly
before going on holiday :-)

Precalculating a reciprocal would probably allow faster reduction modulo
[myModulus] in [myReduceMod], [myMul] and [myIsZeroAddMul].

Values are printed out as least non-negative residues.  Perhaps the user
should be allowed to choose symmetric residues instead?

Should there be a function for accessing the value of myModulus?
If so, what should the type of the result be?

Definition at line 45 of file SmallFpDoubleImpl.H.


Member Typedef Documentation

typedef double CoCoA::SmallFpDoubleImpl::value_t
 

Definition at line 55 of file SmallFpDoubleImpl.H.


Constructor & Destructor Documentation

CoCoA::SmallFpDoubleImpl::SmallFpDoubleImpl unsigned long  p  ) 
 

CoCoA::SmallFpDoubleImpl::SmallFpDoubleImpl const ZZ P  ) 
 

CoCoA::SmallFpDoubleImpl::SmallFpDoubleImpl const SmallFpDoubleImpl  )  [private]
 


Member Function Documentation

SmallFpDoubleImpl& CoCoA::SmallFpDoubleImpl::operator= const SmallFpDoubleImpl  )  [private]
 

void CoCoA::SmallFpDoubleImpl::myAssignZero value_t lhs  )  const [inline]
 

lhs = 0

Definition at line 107 of file SmallFpDoubleImpl.H.

void CoCoA::SmallFpDoubleImpl::myAssign value_t lhs,
value_t  x
const [inline]
 

lhs = x

Definition at line 113 of file SmallFpDoubleImpl.H.

References CoCoA_ASSERT, and myReduceMod().

void CoCoA::SmallFpDoubleImpl::myAssign value_t lhs,
long  n
const [inline]
 

lhs = n

Definition at line 120 of file SmallFpDoubleImpl.H.

References myModulus.

void CoCoA::SmallFpDoubleImpl::myAssign value_t lhs,
const ZZ N
const [inline]
 

lhs = N

Definition at line 128 of file SmallFpDoubleImpl.H.

References CoCoA::mpzref(), and myModulus.

void CoCoA::SmallFpDoubleImpl::myNegate value_t lhs,
value_t  x
const [inline]
 

lhs = -x

Definition at line 134 of file SmallFpDoubleImpl.H.

References CoCoA_ASSERT, myModulus, and myReduceMod().

void CoCoA::SmallFpDoubleImpl::myAdd value_t lhs,
value_t  x,
value_t  y
const [inline]
 

lhs = x+y

Definition at line 142 of file SmallFpDoubleImpl.H.

References CoCoA_ASSERT, myModulus, and myReduceMod().

void CoCoA::SmallFpDoubleImpl::mySub value_t lhs,
value_t  x,
value_t  y
const [inline]
 

lhs = x-y

Definition at line 151 of file SmallFpDoubleImpl.H.

References CoCoA_ASSERT, myModulus, and myReduceMod().

void CoCoA::SmallFpDoubleImpl::myMul value_t lhs,
value_t  x,
value_t  y
const [inline]
 

lhs = x*y

Definition at line 160 of file SmallFpDoubleImpl.H.

References CoCoA_ASSERT, and myReduceMod().

void CoCoA::SmallFpDoubleImpl::myDiv value_t lhs,
value_t  x,
value_t  y
const
 

lhs = x/y

Referenced by myIsDivisible().

bool CoCoA::SmallFpDoubleImpl::myIsDivisible value_t lhs,
value_t  x,
value_t  y
const [inline]
 

lhs = x/y, if y is non-zero

Definition at line 168 of file SmallFpDoubleImpl.H.

References CoCoA_ASSERT, myDiv(), and myReduceMod().

void CoCoA::SmallFpDoubleImpl::myPower value_t lhs,
value_t  x,
unsigned long  n
const
 

lhs = x^n

void CoCoA::SmallFpDoubleImpl::myOutput std::ostream &  out,
value_t  x
const
 

out << x

void CoCoA::SmallFpDoubleImpl::myOutput OpenMathOutput OMOut,
value_t  x
const
 

OMOut << x.

bool CoCoA::SmallFpDoubleImpl::myIsPrintAtom value_t  x  )  const [inline]
 

Definition at line 178 of file SmallFpDoubleImpl.H.

References CoCoA_ASSERT, and myReduceMod().

bool CoCoA::SmallFpDoubleImpl::myIsPrintedWithMinus value_t  x  )  const [inline]
 

Definition at line 185 of file SmallFpDoubleImpl.H.

References CoCoA_ASSERT, and myReduceMod().

bool CoCoA::SmallFpDoubleImpl::myIsZero value_t  x  )  const [inline]
 

x == 0

Definition at line 192 of file SmallFpDoubleImpl.H.

References CoCoA_ASSERT, and myReduceMod().

Referenced by myIsZeroAddMul().

bool CoCoA::SmallFpDoubleImpl::myIsOne value_t  x  )  const [inline]
 

x == 1

Definition at line 199 of file SmallFpDoubleImpl.H.

References CoCoA_ASSERT, and myReduceMod().

bool CoCoA::SmallFpDoubleImpl::myIsMinusOne value_t  x  )  const [inline]
 

x == -1

Definition at line 206 of file SmallFpDoubleImpl.H.

References CoCoA_ASSERT, myModulus, and myReduceMod().

bool CoCoA::SmallFpDoubleImpl::myIsInteger ZZ N,
value_t  x
const [inline]
 

copy value of x into n, result is always true

Definition at line 213 of file SmallFpDoubleImpl.H.

bool CoCoA::SmallFpDoubleImpl::myIsZeroAddMul value_t lhs,
value_t  y,
value_t  z
const [inline]
 

Definition at line 220 of file SmallFpDoubleImpl.H.

References CoCoA_ASSERT, myIsZero(), and myReduceMod().

bool CoCoA::SmallFpDoubleImpl::myIsEqual value_t  x,
value_t  y
const [inline]
 

Definition at line 229 of file SmallFpDoubleImpl.H.

References CoCoA_ASSERT, and myReduceMod().

static value_t CoCoA::SmallFpDoubleImpl::CheckCtorArg unsigned long  p  )  [static, private]
 

static value_t CoCoA::SmallFpDoubleImpl::CheckCtorArg const ZZ P  )  [static, private]
 

static value_t CoCoA::SmallFpDoubleImpl::CalcDrop value_t  p  )  [static, private]
 

static value_t CoCoA::SmallFpDoubleImpl::CalcIterLimit value_t  p  )  [static, private]
 

static value_t CoCoA::SmallFpDoubleImpl::MaxInt  )  [static, private]
 

SmallFpDoubleImpl::value_t CoCoA::SmallFpDoubleImpl::myReduceMod value_t  n  )  const [inline, private]
 

Definition at line 100 of file SmallFpDoubleImpl.H.

References myModulus.

Referenced by myAdd(), myAssign(), myIsDivisible(), myIsEqual(), myIsMinusOne(), myIsOne(), myIsPrintAtom(), myIsPrintedWithMinus(), myIsZero(), myIsZeroAddMul(), myMul(), myNegate(), and mySub().


Member Data Documentation

const std::size_t CoCoA::SmallFpDoubleImpl::DatumSize = sizeof(value_t) [static]
 

Definition at line 56 of file SmallFpDoubleImpl.H.

const value_t CoCoA::SmallFpDoubleImpl::myModulus [private]
 

Definition at line 82 of file SmallFpDoubleImpl.H.

Referenced by myAdd(), myAssign(), myIsMinusOne(), myNegate(), myReduceMod(), and mySub().

const value_t CoCoA::SmallFpDoubleImpl::myDrop [private]
 

Definition at line 83 of file SmallFpDoubleImpl.H.

const value_t CoCoA::SmallFpDoubleImpl::myIterLimit [private]
 

Definition at line 84 of file SmallFpDoubleImpl.H.


The documentation for this class was generated from the following file:
Generated on Wed May 23 13:44:51 2007 for CoCoALib by  doxygen 1.4.6