My Project
Loading...
Searching...
No Matches
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
29
31CFFactory::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 );
46 return int2imm_p( ff_norm( value ) );
48 return int2imm_gf( gf_int2gf( value ) );
49 #ifndef HAVE_NTL
51 return new InternalPrimePower( value );
52 #endif
53 default: {
54 ASSERT( 0, "illegal basic domain!" );
55 return 0;
56 }
57 }
58}
59
61CFFactory::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
84 return int2imm_p( ff_norm( value ) );
86 return int2imm_gf( gf_int2gf( value ) );
87 #ifndef HAVE_NTL
89 return new InternalPrimePower( value );
90 #endif
91 default: {
92 ASSERT( 0, "illegal basic domain!" );
93 return 0;
94 }
95 }
96}
97
99CFFactory::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
122CFFactory::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
163CFFactory::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
204CFFactory::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
245CFFactory::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
261CFFactory::basic ( const mpz_ptr num )
262{
263 ASSERT (currenttype == IntegerDomain, "Integer domain expected");
264 return new InternalInteger( num );
265}
266
269{
271 return res->normalize_myself();
272}
273
275CFFactory::rational ( const mpz_ptr num, const mpz_ptr den, bool normalize )
276{
277 if ( normalize ) {
279 return result->normalize_myself();
280 }
281 else
282 return new InternalRational( num, den );
283}
284
286CFFactory::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
296{
297 if ( v.level() == LEVELBASE )
298 return CFFactory::basic( 1L );
299 else
300 return new InternalPoly( v, exp, 1 );
301}
302
303void 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}
#define LIKELY(X)
Definition: auxiliary.h:403
Header for factory's main class CanonicalForm.
int is_imm(const InternalCF *const ptr)
Definition: canonicalform.h:65
CanonicalForm num(const CanonicalForm &f)
CanonicalForm den(const CanonicalForm &f)
assertions for Factory
#define ASSERT1(expression, message, parameter1)
Definition: cf_assert.h:101
#define ASSERT(expression, message)
Definition: cf_assert.h:99
factory switches.
#define LEVELBASE
Definition: cf_defs.h:25
#define PrimePowerDomain
Definition: cf_defs.h:17
#define FiniteFieldDomain
Definition: cf_defs.h:19
#define RationalDomain
Definition: cf_defs.h:20
#define IntegerDomain
Definition: cf_defs.h:21
#define GaloisFieldDomain
Definition: cf_defs.h:18
void getmpi(InternalCF *value, mpz_t mpi)
Definition: cf_factory.cc:303
Interface to generate InternalCF's over various domains from intrinsic types or mpz_t's.
static InternalCF * basic(int value)
Definition: cf_factory.cc:61
static InternalCF * poly(const Variable &v, int exp, const CanonicalForm &c)
Definition: cf_factory.cc:286
static InternalCF * rational(long num, long den)
Definition: cf_factory.cc:268
static int currenttype
Definition: cf_factory.h:26
factory's main class
Definition: canonicalform.h:86
InternalCF * getval() const
virtual class for internal CanonicalForm's
Definition: int_cf.h:47
virtual int levelcoeff() const
Definition: int_cf.h:68
factory's class for integers
Definition: int_int.h:41
long intval() const
Definition: int_int.cc:506
bool is_imm() const
Definition: int_int.cc:41
int intmod(int p) const
Definition: int_int.cc:511
factory's class for polynomials
Definition: int_poly.h:71
factory's class for rationals
Definition: int_rat.h:39
factory's class for variables
Definition: variable.h:33
int level() const
Definition: variable.h:49
return result
Definition: facAbsBiFact.cc:75
CanonicalForm res
Definition: facAbsFact.cc:60
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:39
VAR int ff_prime
Definition: ffops.cc:14
int ff_norm(const int a)
Definition: ffops.h:39
int gf_int2gf(int i)
Definition: gfops.h:65
operations on immediates, that is elements of F_p, GF, Z, Q that fit into intrinsic int,...
const long MAXIMMEDIATE
Definition: imm.h:55
InternalCF * int2imm_p(long i)
Definition: imm.h:101
const long MINIMMEDIATE
Definition: imm.h:54
InternalCF * int2imm_gf(long i)
Definition: imm.h:106
static InternalCF * int2imm(long i)
Definition: imm.h:75
Factory's internal CanonicalForm's.
Factory's internal integers.
Factory's internal polynomials.
Factory's internal rationals.
gmp_float exp(const gmp_float &a)
Definition: mpr_complex.cc:357
static poly normalize(poly next_p, ideal add_generators, syStrategy syzstr, int *g_l, int *p_l, int crit_comp)
Definition: syz3.cc:1027