My Project
Toggle main menu visibility
Loading...
Searching...
No Matches
factory
cf_factory.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_factory.h
"
11
#include "
canonicalform.h
"
12
#include "
int_cf.h
"
13
#include "
int_int.h
"
14
#include "
int_rat.h
"
15
#include "
int_poly.h
"
16
#include "
int_pp.h
"
17
#include "
imm.h
"
18
19
/// For optimizing if-branches
20
#ifdef __GNUC__
21
#define LIKELY(expression) (__builtin_expect(!!(expression), 1))
22
#define UNLIKELY(expression) (__builtin_expect(!!(expression), 0))
23
#else
24
#define LIKELY(expression) (expression)
25
#define UNLIKELY(expression) (expression)
26
#endif
27
28
int
CFFactory::currenttype
=
IntegerDomain
;
29
30
InternalCF
*
31
CFFactory::basic
(
long
value )
32
{
33
switch
(
currenttype
)
34
{
35
case
IntegerDomain
:
36
if
(
LIKELY
( value >=
MINIMMEDIATE
&& value <=
MAXIMMEDIATE
))
37
return
int2imm( value );
38
else
39
return
new
InternalInteger
( value );
40
// else if ( currenttype == RationalDomain )
41
// if ( value >= MINIMMEDIATE && value <= MAXIMMEDIATE )
42
// return int2imm( value );
43
// else
44
// return new InternalRational( value );
45
case
FiniteFieldDomain
:
46
return
int2imm_p
(
ff_norm
( value ) );
47
case
GaloisFieldDomain
:
48
return
int2imm_gf
(
gf_int2gf
( value ) );
49
#ifndef HAVE_NTL
50
case
PrimePowerDomain
:
51
return
new
InternalPrimePower
( value );
52
#endif
53
default
: {
54
ASSERT
( 0,
"illegal basic domain!"
);
55
return
0;
56
}
57
}
58
}
59
60
InternalCF
*
61
CFFactory::basic
(
int
value )
62
{
63
switch
(
currenttype
)
64
{
65
case
IntegerDomain
:
66
#if SIZEOF_LONG == 8
67
return
int2imm( value );
68
#else
69
if
(
LIKELY
( value >=
MINIMMEDIATE
&& value <=
MAXIMMEDIATE
))
70
return
int2imm( value );
71
else
72
return
new
InternalInteger
( value );
73
#endif
74
case
RationalDomain
:
75
#if SIZEOF_LONG == 8
76
return
int2imm( value );
77
#else
78
if
(
LIKELY
( value >=
MINIMMEDIATE
&& value <=
MAXIMMEDIATE
))
79
return
int2imm( value );
80
else
81
return
new
InternalRational
( value );
82
#endif
83
case
FiniteFieldDomain
:
84
return
int2imm_p
(
ff_norm
( value ) );
85
case
GaloisFieldDomain
:
86
return
int2imm_gf
(
gf_int2gf
( value ) );
87
#ifndef HAVE_NTL
88
case
PrimePowerDomain
:
89
return
new
InternalPrimePower
( value );
90
#endif
91
default
: {
92
ASSERT
( 0,
"illegal basic domain!"
);
93
return
0;
94
}
95
}
96
}
97
98
InternalCF
*
99
CFFactory::basic
(
int
type,
long
value )
100
{
101
if
( type ==
IntegerDomain
)
102
if
(
LIKELY
( value >=
MINIMMEDIATE
&& value <=
MAXIMMEDIATE
))
103
return
int2imm( value );
104
else
105
return
new
InternalInteger
( value );
106
// else if ( type == RationalDomain )
107
// if ( value >= MINIMMEDIATE && value <= MAXIMMEDIATE )
108
// return int2imm( value );
109
// else
110
// return new InternalRational( value );
111
else
if
( type ==
FiniteFieldDomain
)
112
return
int2imm_p
(
ff_norm
( value ) );
113
else
if
( type ==
GaloisFieldDomain
)
114
return
int2imm_gf
(
gf_int2gf
( value ) );
115
else
{
116
ASSERT1
( 0,
"illegal basic domain (type = %d)!"
, type );
117
return
0;
118
}
119
}
120
121
InternalCF
*
122
CFFactory::basic
(
const
char
* str )
123
{
124
if
(
currenttype
==
IntegerDomain
) {
125
InternalInteger
* dummy =
new
InternalInteger
( str );
126
if
( dummy->
is_imm
() ) {
127
InternalCF
*
res
= int2imm( dummy->
intval
() );
128
delete
dummy;
129
return
res
;
130
}
131
else
132
return
dummy;
133
}
134
// else if ( currenttype == RationalDomain ) {
135
// InternalRational * dummy = new InternalRational( str );
136
// if ( dummy->is_imm() ) {
137
// InternalCF * res = int2imm( dummy->intval() );
138
// delete dummy;
139
// return res;
140
// }
141
// else
142
// return dummy;
143
// }
144
else
if
(
currenttype
==
FiniteFieldDomain
) {
145
InternalInteger
* dummy =
new
InternalInteger
( str );
146
InternalCF
*
res
=
int2imm_p
( dummy->
intmod
(
ff_prime
) );
147
delete
dummy;
148
return
res
;
149
}
150
else
if
(
currenttype
==
GaloisFieldDomain
) {
151
InternalInteger
* dummy =
new
InternalInteger
( str );
152
InternalCF
*
res
=
int2imm_gf
(
gf_int2gf
( dummy->
intmod
(
ff_prime
) ) );
153
delete
dummy;
154
return
res
;
155
}
156
else
{
157
ASSERT
( 0,
"illegal basic domain!"
);
158
return
0;
159
}
160
}
161
162
InternalCF
*
163
CFFactory::basic
(
const
char
* str,
int
base )
164
{
165
if
(
currenttype
==
IntegerDomain
) {
166
InternalInteger
* dummy =
new
InternalInteger
( str, base );
167
if
( dummy->
is_imm
() ) {
168
InternalCF
*
res
= int2imm( dummy->
intval
() );
169
delete
dummy;
170
return
res
;
171
}
172
else
173
return
dummy;
174
}
175
// else if ( currenttype == RationalDomain ) {
176
// InternalRational * dummy = new InternalRational( str );
177
// if ( dummy->is_imm() ) {
178
// InternalCF * res = int2imm( dummy->intval() );
179
// delete dummy;
180
// return res;
181
// }
182
// else
183
// return dummy;
184
// }
185
else
if
(
currenttype
==
FiniteFieldDomain
) {
186
InternalInteger
* dummy =
new
InternalInteger
( str, base );
187
InternalCF
*
res
=
int2imm_p
( dummy->
intmod
(
ff_prime
) );
188
delete
dummy;
189
return
res
;
190
}
191
else
if
(
currenttype
==
GaloisFieldDomain
) {
192
InternalInteger
* dummy =
new
InternalInteger
( str, base );
193
InternalCF
*
res
=
int2imm_gf
(
gf_int2gf
( dummy->
intmod
(
ff_prime
) ) );
194
delete
dummy;
195
return
res
;
196
}
197
else
{
198
ASSERT
( 0,
"illegal basic domain!"
);
199
return
0;
200
}
201
}
202
203
InternalCF
*
204
CFFactory::basic
(
int
type,
const
char
*
const
str )
205
{
206
if
( type ==
IntegerDomain
) {
207
InternalInteger
* dummy =
new
InternalInteger
( str );
208
if
( dummy->
is_imm
() ) {
209
InternalCF
*
res
= int2imm( dummy->
intval
() );
210
delete
dummy;
211
return
res
;
212
}
213
else
214
return
dummy;
215
}
216
// else if ( type == RationalDomain ) {
217
// InternalRational * dummy = new InternalRational( str );
218
// if ( dummy->is_imm() ) {
219
// InternalCF * res = int2imm( dummy->intval() );
220
// delete dummy;
221
// return res;
222
// }
223
// else
224
// return dummy;
225
// }
226
else
if
( type ==
FiniteFieldDomain
) {
227
InternalInteger
* dummy =
new
InternalInteger
( str );
228
InternalCF
*
res
= int2imm( dummy->
intmod
(
ff_prime
) );
229
delete
dummy;
230
return
res
;
231
}
232
else
if
( type ==
GaloisFieldDomain
) {
233
InternalInteger
* dummy =
new
InternalInteger
( str );
234
InternalCF
*
res
=
int2imm_gf
(
gf_int2gf
( dummy->
intmod
(
ff_prime
) ) );
235
delete
dummy;
236
return
res
;
237
}
238
else
{
239
ASSERT
( 0,
"illegal basic domain!"
);
240
return
0;
241
}
242
}
243
244
InternalCF
*
245
CFFactory::basic
(
int
type,
long
value,
bool
nonimm )
246
{
247
if
( nonimm )
248
if
( type ==
IntegerDomain
)
249
return
new
InternalInteger
( value );
250
else
if
( type ==
RationalDomain
)
251
return
new
InternalRational
( value );
252
else
{
253
ASSERT
( 0,
"illegal basic domain!"
);
254
return
0;
255
}
256
else
257
return
CFFactory::basic
( type, value );
258
}
259
260
InternalCF
*
261
CFFactory::basic
(
const
mpz_ptr
num
)
262
{
263
ASSERT
(
currenttype
==
IntegerDomain
,
"Integer domain expected"
);
264
return
new
InternalInteger
(
num
);
265
}
266
267
InternalCF
*
268
CFFactory::rational
(
long
num
,
long
den
)
269
{
270
InternalRational
*
res
=
new
InternalRational
(
num
,
den
);
271
return
res
->normalize_myself();
272
}
273
274
InternalCF
*
275
CFFactory::rational
(
const
mpz_ptr
num
,
const
mpz_ptr
den
,
bool
normalize
)
276
{
277
if
(
normalize
) {
278
InternalRational
*
result
=
new
InternalRational
(
num
,
den
);
279
return
result
->normalize_myself();
280
}
281
else
282
return
new
InternalRational
(
num
,
den
);
283
}
284
285
InternalCF
*
286
CFFactory::poly
(
const
Variable
&
v
,
int
exp
,
const
CanonicalForm
& c )
287
{
288
if
(
v
.
level
() ==
LEVELBASE
)
289
return
c.
getval
();
290
else
291
return
new
InternalPoly
(
v
,
exp
, c );
292
}
293
294
InternalCF
*
295
CFFactory::poly
(
const
Variable
&
v
,
int
exp
)
296
{
297
if
(
v
.
level
() ==
LEVELBASE
)
298
return
CFFactory::basic
( 1L );
299
else
300
return
new
InternalPoly
(
v
,
exp
, 1 );
301
}
302
303
void
getmpi
(
InternalCF
* value, mpz_t mpi)
304
{
305
ASSERT
( !
is_imm
( value ) && (value->
levelcoeff
() ==
IntegerDomain
|| value->
levelcoeff
() ==
PrimePowerDomain
),
"illegal operation"
);
306
mpz_init_set (mpi, ((
InternalInteger
*)value)->
thempi
);
307
}
LIKELY
#define LIKELY(X)
Definition
auxiliary.h:404
canonicalform.h
Header for factory's main class CanonicalForm.
num
CanonicalForm num(const CanonicalForm &f)
Definition
canonicalform.h:337
den
CanonicalForm den(const CanonicalForm &f)
Definition
canonicalform.h:340
normalize
CanonicalForm normalize(const CanonicalForm &F)
normalize a poly, i.e. in char 0 clear denominators, remove integer content in char p divide by leadi...
Definition
cfCharSetsUtil.cc:590
cf_assert.h
assertions for Factory
ASSERT1
#define ASSERT1(expression, message, parameter1)
Definition
cf_assert.h:101
ASSERT
#define ASSERT(expression, message)
Definition
cf_assert.h:99
cf_defs.h
factory switches.
LEVELBASE
#define LEVELBASE
Definition
cf_defs.h:25
PrimePowerDomain
#define PrimePowerDomain
Definition
cf_defs.h:17
FiniteFieldDomain
#define FiniteFieldDomain
Definition
cf_defs.h:19
RationalDomain
#define RationalDomain
Definition
cf_defs.h:20
IntegerDomain
#define IntegerDomain
Definition
cf_defs.h:21
GaloisFieldDomain
#define GaloisFieldDomain
Definition
cf_defs.h:18
cf_factory.h
Interface to generate InternalCF's over various domains from intrinsic types or mpz_t's.
CFFactory::basic
static InternalCF * basic(int value)
Definition
cf_factory.cc:61
CFFactory::poly
static InternalCF * poly(const Variable &v, int exp, const CanonicalForm &c)
Definition
cf_factory.cc:286
CFFactory::rational
static InternalCF * rational(long num, long den)
Definition
cf_factory.cc:268
CFFactory::currenttype
static int currenttype
Definition
cf_factory.h:26
CanonicalForm
factory's main class
Definition
canonicalform.h:86
CanonicalForm::getval
InternalCF * getval() const
Definition
canonicalform.cc:34
InternalCF
virtual class for internal CanonicalForm's
Definition
int_cf.h:47
InternalCF::InternalCF
InternalCF()
Definition
int_cf.h:55
InternalCF::levelcoeff
virtual int levelcoeff() const
Definition
int_cf.h:68
InternalInteger
factory's class for integers
Definition
int_int.h:56
InternalInteger::thempi
mpz_t thempi
Definition
int_int.h:58
InternalInteger::InternalInteger
InternalInteger()
Definition
int_int.h:85
InternalInteger::intval
long intval() const
Definition
int_int.cc:506
InternalInteger::is_imm
bool is_imm() const
Definition
int_int.cc:41
InternalInteger::getmpi
friend void getmpi(InternalCF *value, mpz_t mpi)
Definition
cf_factory.cc:303
InternalInteger::intmod
int intmod(int p) const
Definition
int_int.cc:511
InternalPoly::InternalPoly
InternalPoly()
Definition
int_poly.cc:53
InternalPrimePower::InternalPrimePower
InternalPrimePower()
InternalRational
factory's class for rationals
Definition
int_rat.h:55
InternalRational::InternalRational
InternalRational()
Definition
int_rat.cc:34
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
res
CanonicalForm res
Definition
facAbsFact.cc:60
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition
facBivar.h:39
ff_prime
VAR int ff_prime
Definition
ffops.cc:23
ff_norm
int ff_norm(const int a)
Definition
ffops.h:39
gf_int2gf
int gf_int2gf(int i)
Definition
gfops.h:65
imm.h
operations on immediates, that is elements of F_p, GF, Z, Q that fit into intrinsic int,...
MAXIMMEDIATE
const long MAXIMMEDIATE
Definition
imm.h:55
int2imm_p
InternalCF * int2imm_p(long i)
Definition
imm.h:101
MINIMMEDIATE
const long MINIMMEDIATE
Definition
imm.h:54
int2imm_gf
InternalCF * int2imm_gf(long i)
Definition
imm.h:106
int_cf.h
Factory's internal CanonicalForm's.
int_int.h
Factory's internal integers.
int_poly.h
Factory's internal polynomials.
int_pp.h
int_rat.h
Factory's internal rationals.
exp
gmp_float exp(const gmp_float &a)
Definition
mpr_complex.cc:349
Generated on
for My Project by
doxygen 1.18.0
for
Singular