My Project
Loading...
Searching...
No Matches
cf_generator.cc
Go to the documentation of this file.
1/* emacs edit mode for this file is -*- C++ -*- */
2
3
4#include "config.h"
5
6
7#include "cf_assert.h"
8
9#include "cf_defs.h"
10#include "cf_generator.h"
11#include "imm.h"
12#include "gfops.h"
13#include "ffops.h"
14
16{
17 return 1;
18}
19
21{
22 return mapinto (CanonicalForm (current));
23}
24
26{
27 current++;
28}
29
31{
32 return new IntGenerator();
33}
34
36{
37 return current < ff_prime;
38}
39
41{
42 ASSERT( current < ff_prime, "no more items" );
43 return CanonicalForm( int2imm_p( current ) );
44}
45
47{
48 ASSERT( current < ff_prime, "no more items" );
49 current++;
50}
51
53{
54 return new FFGenerator();
55}
56
58{
59 current = gf_zero();
60}
61
63{
64 return ( current != gf_q + 1 );
65}
66
68{
69 current = gf_zero();
70}
71
73{
74 ASSERT( current != gf_q + 1, "no more items" );
75 return CanonicalForm( int2imm_gf( current ) );
76}
77
79{
80 ASSERT( current != gf_q + 1, "no more items" );
81 if ( gf_iszero( current ) )
82 current = 0;
83 else if ( current == gf_q1 - 1 )
84 current = gf_q + 1;
85 else
86 current++;
87}
88
90{
91 return new GFGenerator();
92}
93
95{
96 ASSERT( 0, "not a valid generator" );
97}
98
100{
101 ASSERT( 0, "not a valid generator" );
102}
103
105{
106 ASSERT( 0, "not a valid generator" );
107 return *this;
108}
109
111{
112 ASSERT( a.level() < 0, "not an algebraic extension" );
113 ASSERT( getCharacteristic() > 0, "not a finite field" );
114 algext = a;
115 n = degree( getMipo( a ) );
116 if ( getGFDegree() > 1 )
117 {
118 gensg = new GFGenerator * [n];
119 for ( int i = 0; i < n; i++ )
120 gensg[i] = new GFGenerator();
121 }
122 else
123 {
124 gensf = new FFGenerator * [n];
125 for ( int i = 0; i < n; i++ )
126 gensf[i] = new FFGenerator();
127 }
128 nomoreitems = false;
129}
130
132{
133 if ( getGFDegree() > 1 )
134 {
135 for ( int i = 0; i < n; i++ )
136 delete gensg[i];
137 delete [] gensg;
138 }
139 else
140 {
141 for ( int i = 0; i < n; i++ )
142 delete gensf[i];
143 delete [] gensf;
144 }
145}
146
148{
149 if ( getGFDegree() > 1 )
150 {
151 for ( int i = 0; i < n; i++ )
152 gensg[i]->reset();
153 }
154 else
155 {
156 for ( int i = 0; i < n; i++ )
157 gensf[i]->reset();
158 }
159 nomoreitems = false;
160}
161
163{
164 ASSERT( ! nomoreitems, "no more items" );
166 if ( getGFDegree() > 1 )
167 {
168 for ( int i = 0; i < n; i++ )
169 result += power( algext, i ) * gensg[i]->item();
170 }
171 else
172 {
173 for ( int i = 0; i < n; i++ )
174 result += power( algext, i ) * gensf[i]->item();
175 }
176 return result;
177}
178
180{
181 ASSERT( ! nomoreitems, "no more items" );
182 int i = 0;
183 bool stop = false;
184 if ( getGFDegree() > 1 )
185 {
186 while ( ! stop && i < n )
187 {
188 gensg[i]->next();
189 if ( ! gensg[i]->hasItems() )
190 {
191 gensg[i]->reset();
192 i++;
193 }
194 else
195 stop = true;
196 }
197 }
198 else
199 {
200 while ( ! stop && i < n )
201 {
202 gensf[i]->next();
203 if ( ! gensf[i]->hasItems() )
204 {
205 gensf[i]->reset();
206 i++;
207 }
208 else
209 stop = true;
210 }
211 }
212 if ( ! stop )
213 nomoreitems = true;
214}
215
217{
218 return new AlgExtGenerator(algext);
219}
220
222{
223 if (getCharacteristic() == 0)
224 return new IntGenerator();
225 else if ( getGFDegree() > 1 )
226 return new GFGenerator();
227 else
228 return new FFGenerator();
229}
CanonicalForm power(const CanonicalForm &f, int n)
exponentiation
CanonicalForm mapinto(const CanonicalForm &f)
int degree(const CanonicalForm &f)
int getGFDegree()
Definition: cf_char.cc:75
int FACTORY_PUBLIC getCharacteristic()
Definition: cf_char.cc:70
int i
Definition: cfEzgcd.cc:132
assertions for Factory
#define ASSERT(expression, message)
Definition: cf_assert.h:99
factory switches.
generate integers, elements of finite fields
generate all elements in F_p(alpha) starting from 0
Definition: cf_generator.h:94
FFGenerator ** gensf
Definition: cf_generator.h:97
CanonicalForm item() const
CFGenerator * clone() const
GFGenerator ** gensg
Definition: cf_generator.h:98
bool hasItems() const
Definition: cf_generator.h:108
AlgExtGenerator & operator=(const AlgExtGenerator &)
Variable algext
Definition: cf_generator.h:96
static CFGenerator * generate()
virtual class for generators
Definition: cf_generator.h:22
factory's main class
Definition: canonicalform.h:86
generate all elements in F_p starting from 0
Definition: cf_generator.h:56
bool hasItems() const
Definition: cf_generator.cc:35
void reset()
Definition: cf_generator.h:63
CanonicalForm item() const
Definition: cf_generator.cc:40
CFGenerator * clone() const
Definition: cf_generator.cc:52
generate all elements in GF starting from 0
Definition: cf_generator.h:75
bool hasItems() const
Definition: cf_generator.cc:62
CanonicalForm item() const
Definition: cf_generator.cc:72
CFGenerator * clone() const
Definition: cf_generator.cc:89
void reset()
Definition: cf_generator.cc:67
generate integers starting from 0
Definition: cf_generator.h:37
CFGenerator * clone() const
Definition: cf_generator.cc:30
CanonicalForm item() const
Definition: cf_generator.cc:20
bool hasItems() const
Definition: cf_generator.cc:15
factory's class for variables
Definition: variable.h:33
int level() const
Definition: variable.h:49
return result
Definition: facAbsBiFact.cc:75
VAR int ff_prime
Definition: ffops.cc:14
operations in a finite prime field F_p.
VAR int gf_q
Definition: gfops.cc:47
VAR int gf_q1
Definition: gfops.cc:50
Operations in GF, where GF is a finite field of size less than 2^16 represented by a root of Conway p...
int gf_zero()
Definition: gfops.h:99
bool gf_iszero(int a)
Definition: gfops.h:43
operations on immediates, that is elements of F_p, GF, Z, Q that fit into intrinsic int,...
InternalCF * int2imm_p(long i)
Definition: imm.h:101
InternalCF * int2imm_gf(long i)
Definition: imm.h:106
CanonicalForm getMipo(const Variable &alpha, const Variable &x)
Definition: variable.cc:207