Loading...
Searching...
No Matches
cf_generator.cc
Go to the documentation of this file.
/* emacs edit mode for this file is -*- C++ -*- */
#include "config.h"
#include "cf_assert.h"
#include "cf_defs.h"
#include "cf_generator.h"
#include "imm.h"
#include "gfops.h"
#include "ffops.h"
bool IntGenerator::hasItems() const
{
return 1;
}
CanonicalForm IntGenerator::item() const
{
return mapinto (CanonicalForm (current));
}
void IntGenerator::next()
{
current++;
}
CFGenerator * IntGenerator::clone () const
{
return new IntGenerator();
}
bool FFGenerator::hasItems() const
{
return current < ff_prime;
}
CanonicalForm FFGenerator::item() const
{
ASSERT( current < ff_prime, "no more items" );
return CanonicalForm( int2imm_p( current ) );
}
void FFGenerator::next()
{
ASSERT( current < ff_prime, "no more items" );
current++;
}
CFGenerator * FFGenerator::clone () const
{
return new FFGenerator();
}
GFGenerator::GFGenerator()
{
current = gf_zero();
}
bool GFGenerator::hasItems() const
{
return ( current != gf_q + 1 );
}
void GFGenerator::reset()
{
current = gf_zero();
}
CanonicalForm GFGenerator::item() const
{
ASSERT( current != gf_q + 1, "no more items" );
return CanonicalForm( int2imm_gf( current ) );
}
void GFGenerator::next()
{
ASSERT( current != gf_q + 1, "no more items" );
if ( gf_iszero( current ) )
current = 0;
else if ( current == gf_q1 - 1 )
current = gf_q + 1;
else
current++;
}
CFGenerator * GFGenerator::clone () const
{
return new GFGenerator();
}
AlgExtGenerator::AlgExtGenerator()
{
ASSERT( 0, "not a valid generator" );
}
AlgExtGenerator::AlgExtGenerator( const AlgExtGenerator & )
{
ASSERT( 0, "not a valid generator" );
}
AlgExtGenerator& AlgExtGenerator::operator= ( const AlgExtGenerator & )
{
ASSERT( 0, "not a valid generator" );
return *this;
}
AlgExtGenerator::AlgExtGenerator( const Variable & a )
{
ASSERT( a.level() < 0, "not an algebraic extension" );
ASSERT( getCharacteristic() > 0, "not a finite field" );
algext = a;
n = degree( getMipo( a ) );
if ( getGFDegree() > 1 )
{
gensg = new GFGenerator * [n];
for ( int i = 0; i < n; i++ )
gensg[i] = new GFGenerator();
}
else
{
gensf = new FFGenerator * [n];
for ( int i = 0; i < n; i++ )
gensf[i] = new FFGenerator();
}
nomoreitems = false;
}
AlgExtGenerator::~AlgExtGenerator()
{
if ( getGFDegree() > 1 )
{
for ( int i = 0; i < n; i++ )
delete gensg[i];
delete [] gensg;
}
else
{
for ( int i = 0; i < n; i++ )
delete gensf[i];
delete [] gensf;
}
}
void AlgExtGenerator::reset()
{
if ( getGFDegree() > 1 )
{
for ( int i = 0; i < n; i++ )
gensg[i]->reset();
}
else
{
for ( int i = 0; i < n; i++ )
gensf[i]->reset();
}
nomoreitems = false;
}
CanonicalForm AlgExtGenerator::item() const
{
ASSERT( ! nomoreitems, "no more items" );
CanonicalForm result = 0;
if ( getGFDegree() > 1 )
{
for ( int i = 0; i < n; i++ )
result += power( algext, i ) * gensg[i]->item();
}
else
{
for ( int i = 0; i < n; i++ )
result += power( algext, i ) * gensf[i]->item();
}
return result;
}
void AlgExtGenerator::next()
{
ASSERT( ! nomoreitems, "no more items" );
int i = 0;
bool stop = false;
if ( getGFDegree() > 1 )
{
while ( ! stop && i < n )
{
gensg[i]->next();
if ( ! gensg[i]->hasItems() )
{
gensg[i]->reset();
i++;
}
else
stop = true;
}
}
else
{
while ( ! stop && i < n )
{
gensf[i]->next();
if ( ! gensf[i]->hasItems() )
{
gensf[i]->reset();
i++;
}
else
stop = true;
}
}
if ( ! stop )
nomoreitems = true;
}
CFGenerator * AlgExtGenerator::clone () const
{
return new AlgExtGenerator(algext);
}
CFGenerator * CFGenFactory::generate()
{
if (getCharacteristic() == 0)
return new IntGenerator();
else if ( getGFDegree() > 1 )
return new GFGenerator();
else
return new FFGenerator();
}
i
int i
Definition cfEzgcd.cc:132
cf_assert.h
assertions for Factory
ASSERT
#define ASSERT(expression, message)
Definition cf_assert.h:99
cf_defs.h
factory switches.
cf_generator.h
generate integers, elements of finite fields
AlgExtGenerator::gensf
FFGenerator ** gensf
Definition cf_generator.h:97
AlgExtGenerator::n
int n
Definition cf_generator.h:99
AlgExtGenerator::reset
void reset()
Definition cf_generator.cc:147
AlgExtGenerator::gensg
GFGenerator ** gensg
Definition cf_generator.h:98
AlgExtGenerator::item
CanonicalForm item() const
Definition cf_generator.cc:162
AlgExtGenerator::clone
CFGenerator * clone() const
Definition cf_generator.cc:216
AlgExtGenerator::hasItems
bool hasItems() const
Definition cf_generator.h:108
AlgExtGenerator::nomoreitems
bool nomoreitems
Definition cf_generator.h:100
AlgExtGenerator::AlgExtGenerator
AlgExtGenerator()
Definition cf_generator.cc:94
AlgExtGenerator::~AlgExtGenerator
~AlgExtGenerator()
Definition cf_generator.cc:131
AlgExtGenerator::operator=
AlgExtGenerator & operator=(const AlgExtGenerator &)
Definition cf_generator.cc:104
AlgExtGenerator::next
void next()
Definition cf_generator.cc:179
AlgExtGenerator::algext
Variable algext
Definition cf_generator.h:96
CFGenFactory::generate
static CFGenerator * generate()
Definition cf_generator.cc:221
CFGenerator
virtual class for generators
Definition cf_generator.h:22
CFGenerator::CFGenerator
CFGenerator()
Definition cf_generator.h:24
CanonicalForm
factory's main class
Definition canonicalform.h:86
FFGenerator
generate all elements in F_p starting from 0
Definition cf_generator.h:56
FFGenerator::current
int current
Definition cf_generator.h:58
FFGenerator::FFGenerator
FFGenerator()
Definition cf_generator.h:60
FFGenerator::hasItems
bool hasItems() const
Definition cf_generator.cc:35
FFGenerator::item
CanonicalForm item() const
Definition cf_generator.cc:40
FFGenerator::clone
CFGenerator * clone() const
Definition cf_generator.cc:52
FFGenerator::next
void next()
Definition cf_generator.cc:46
GFGenerator
generate all elements in GF starting from 0
Definition cf_generator.h:75
GFGenerator::hasItems
bool hasItems() const
Definition cf_generator.cc:62
GFGenerator::item
CanonicalForm item() const
Definition cf_generator.cc:72
GFGenerator::next
void next()
Definition cf_generator.cc:78
GFGenerator::clone
CFGenerator * clone() const
Definition cf_generator.cc:89
GFGenerator::current
int current
Definition cf_generator.h:77
GFGenerator::GFGenerator
GFGenerator()
Definition cf_generator.cc:57
GFGenerator::reset
void reset()
Definition cf_generator.cc:67
IntGenerator
generate integers starting from 0
Definition cf_generator.h:37
IntGenerator::clone
CFGenerator * clone() const
Definition cf_generator.cc:30
IntGenerator::item
CanonicalForm item() const
Definition cf_generator.cc:20
IntGenerator::next
void next()
Definition cf_generator.cc:25
IntGenerator::current
int current
Definition cf_generator.h:39
IntGenerator::hasItems
bool hasItems() const
Definition cf_generator.cc:15
IntGenerator::IntGenerator
IntGenerator()
Definition cf_generator.h:41
Variable
factory's class for variables
Definition factory.h:127
Variable::level
int level() const
Definition factory.h:143
result
return result
Definition facAbsBiFact.cc:76
ff_prime
VAR int ff_prime
Definition ffops.cc:23
ffops.h
operations in a finite prime field F_p.
gf_q
VAR int gf_q
Definition gfops.cc:47
gf_q1
VAR int gf_q1
Definition gfops.cc:50
gfops.h
Operations in GF, where GF is a finite field of size less than 2^16 represented by a root of Conway p...
gf_zero
int gf_zero()
Definition gfops.h:99
gf_iszero
bool gf_iszero(int a)
Definition gfops.h:43
imm.h
operations on immediates, that is elements of F_p, GF, Z, Q that fit into intrinsic int,...
int2imm_p
InternalCF * int2imm_p(long i)
Definition imm.h:101
int2imm_gf
InternalCF * int2imm_gf(long i)
Definition imm.h:106
mapinto
CanonicalForm mapinto(const CanonicalForm &f)
Definition factory.h:496
degree
int degree(const CanonicalForm &f)
Definition factory.h:457
getGFDegree
int getGFDegree()
Definition cf_char.cc:75
getMipo
CanonicalForm getMipo(const Variable &alpha, const Variable &x)
Definition variable.cc:207
power
CanonicalForm FACTORY_PUBLIC power(const CanonicalForm &f, int n)
exponentiation
Definition canonicalform.cc:1896
getCharacteristic
int FACTORY_PUBLIC getCharacteristic()
Definition cf_char.cc:70