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 "imm.h"
17 
18 /// For optimizing if-branches
19 #ifdef __GNUC__
20 #define LIKELY(expression) (__builtin_expect(!!(expression), 1))
21 #define UNLIKELY(expression) (__builtin_expect(!!(expression), 0))
22 #else
23 #define LIKELY(expression) (expression)
24 #define UNLIKELY(expression) (expression)
25 #endif
26 
28 
29 InternalCF *
30 CFFactory::basic ( long value )
31 {
32  switch(currenttype)
33  {
34  case IntegerDomain:
35  if (LIKELY( value >= MINIMMEDIATE && value <= MAXIMMEDIATE ))
36  return int2imm( value );
37  else
38  return new InternalInteger( value );
39 // else if ( currenttype == RationalDomain )
40 // if ( value >= MINIMMEDIATE && value <= MAXIMMEDIATE )
41 // return int2imm( value );
42 // else
43 // return new InternalRational( value );
44  case FiniteFieldDomain:
45  return int2imm_p( ff_norm( value ) );
46  case GaloisFieldDomain:
47  return int2imm_gf( gf_int2gf( value ) );
48  default: {
49  ASSERT( 0, "illegal basic domain!" );
50  return 0;
51  }
52  }
53 }
54 
55 InternalCF *
56 CFFactory::basic ( int type, long value )
57 {
58  if ( type == IntegerDomain )
59  if (LIKELY( value >= MINIMMEDIATE && value <= MAXIMMEDIATE ))
60  return int2imm( value );
61  else
62  return new InternalInteger( value );
63 // else if ( type == RationalDomain )
64 // if ( value >= MINIMMEDIATE && value <= MAXIMMEDIATE )
65 // return int2imm( value );
66 // else
67 // return new InternalRational( value );
68  else if ( type == FiniteFieldDomain )
69  return int2imm_p( ff_norm( value ) );
70  else if ( type == GaloisFieldDomain )
71  return int2imm_gf( gf_int2gf( value ) );
72  else {
73  ASSERT1( 0, "illegal basic domain (type = %d)!", type );
74  return 0;
75  }
76 }
77 
78 InternalCF *
79 CFFactory::basic ( const char * str )
80 {
81  if ( currenttype == IntegerDomain ) {
82  InternalInteger * dummy = new InternalInteger( str );
83  if ( dummy->is_imm() ) {
84  InternalCF * res = int2imm( dummy->intval() );
85  delete dummy;
86  return res;
87  }
88  else
89  return dummy;
90  }
91 // else if ( currenttype == RationalDomain ) {
92 // InternalRational * dummy = new InternalRational( str );
93 // if ( dummy->is_imm() ) {
94 // InternalCF * res = int2imm( dummy->intval() );
95 // delete dummy;
96 // return res;
97 // }
98 // else
99 // return dummy;
100 // }
101  else if ( currenttype == FiniteFieldDomain ) {
102  InternalInteger * dummy = new InternalInteger( str );
103  InternalCF * res = int2imm_p( dummy->intmod( ff_prime ) );
104  delete dummy;
105  return res;
106  }
107  else if ( currenttype == GaloisFieldDomain ) {
108  InternalInteger * dummy = new InternalInteger( str );
109  InternalCF * res = int2imm_gf( gf_int2gf( dummy->intmod( ff_prime ) ) );
110  delete dummy;
111  return res;
112  }
113  else {
114  ASSERT( 0, "illegal basic domain!" );
115  return 0;
116  }
117 }
118 
119 InternalCF *
120 CFFactory::basic ( const char * str, int base )
121 {
122  if ( currenttype == IntegerDomain ) {
123  InternalInteger * dummy = new InternalInteger( str, base );
124  if ( dummy->is_imm() ) {
125  InternalCF * res = int2imm( dummy->intval() );
126  delete dummy;
127  return res;
128  }
129  else
130  return dummy;
131  }
132 // else if ( currenttype == RationalDomain ) {
133 // InternalRational * dummy = new InternalRational( str );
134 // if ( dummy->is_imm() ) {
135 // InternalCF * res = int2imm( dummy->intval() );
136 // delete dummy;
137 // return res;
138 // }
139 // else
140 // return dummy;
141 // }
142  else if ( currenttype == FiniteFieldDomain ) {
143  InternalInteger * dummy = new InternalInteger( str, base );
144  InternalCF * res = int2imm_p( dummy->intmod( ff_prime ) );
145  delete dummy;
146  return res;
147  }
148  else if ( currenttype == GaloisFieldDomain ) {
149  InternalInteger * dummy = new InternalInteger( str, base );
150  InternalCF * res = int2imm_gf( gf_int2gf( dummy->intmod( ff_prime ) ) );
151  delete dummy;
152  return res;
153  }
154  else {
155  ASSERT( 0, "illegal basic domain!" );
156  return 0;
157  }
158 }
159 
160 InternalCF *
161 CFFactory::basic ( int type, const char * const str )
162 {
163  if ( type == IntegerDomain ) {
164  InternalInteger * dummy = new InternalInteger( str );
165  if ( dummy->is_imm() ) {
166  InternalCF * res = int2imm( dummy->intval() );
167  delete dummy;
168  return res;
169  }
170  else
171  return dummy;
172  }
173 // else if ( type == RationalDomain ) {
174 // InternalRational * dummy = new InternalRational( str );
175 // if ( dummy->is_imm() ) {
176 // InternalCF * res = int2imm( dummy->intval() );
177 // delete dummy;
178 // return res;
179 // }
180 // else
181 // return dummy;
182 // }
183  else if ( type == FiniteFieldDomain ) {
184  InternalInteger * dummy = new InternalInteger( str );
185  InternalCF * res = int2imm( dummy->intmod( ff_prime ) );
186  delete dummy;
187  return res;
188  }
189  else if ( type == GaloisFieldDomain ) {
190  InternalInteger * dummy = new InternalInteger( str );
191  InternalCF * res = int2imm_gf( gf_int2gf( dummy->intmod( ff_prime ) ) );
192  delete dummy;
193  return res;
194  }
195  else {
196  ASSERT( 0, "illegal basic domain!" );
197  return 0;
198  }
199 }
200 
201 InternalCF *
202 CFFactory::basic ( int type, long value, bool nonimm )
203 {
204  if ( nonimm )
205  if ( type == IntegerDomain )
206  return new InternalInteger( value );
207  else if ( type == RationalDomain )
208  return new InternalRational( value );
209  else {
210  ASSERT( 0, "illegal basic domain!" );
211  return 0;
212  }
213  else
214  return CFFactory::basic( type, value );
215 }
216 
217 InternalCF *
218 CFFactory::basic ( const mpz_ptr num )
219 {
220  ASSERT (currenttype == IntegerDomain, "Integer domain expected");
221  return new InternalInteger( num );
222 }
223 
224 InternalCF *
226 {
227  InternalRational * res = new InternalRational( num, den );
228  return res->normalize_myself();
229 }
230 
231 InternalCF *
232 CFFactory::rational ( const mpz_ptr num, const mpz_ptr den, bool normalize )
233 {
234  if ( normalize ) {
235  InternalRational * result = new InternalRational( num, den );
236  return result->normalize_myself();
237  }
238  else
239  return new InternalRational( num, den );
240 }
241 
242 InternalCF *
243 CFFactory::poly ( const Variable & v, int exp, const CanonicalForm & c )
244 {
245  if ( v.level() == LEVELBASE )
246  return c.getval();
247  else
248  return new InternalPoly( v, exp, c );
249 }
250 
251 InternalCF *
252 CFFactory::poly ( const Variable & v, int exp )
253 {
254  if ( v.level() == LEVELBASE )
255  return CFFactory::basic( 1L );
256  else
257  return new InternalPoly( v, exp, 1 );
258 }
259 
260 void getmpi ( InternalCF * value, mpz_t mpi)
261 {
262  ASSERT( ! is_imm( value ) && (value->levelcoeff() == IntegerDomain ), "illegal operation" );
263  mpz_init_set (mpi, ((InternalInteger*)value)->thempi);
264 }
265 
Factory&#39;s internal rationals.
const long MINIMMEDIATE
Definition: imm.h:54
static poly normalize(poly next_p, ideal add_generators, syStrategy syzstr, int *g_l, int *p_l, int crit_comp)
Definition: syz3.cc:1026
#define LEVELBASE
Definition: cf_defs.h:16
InternalCF * normalize_myself()
reduce InternalRational to lowest terms
Definition: int_rat.cc:859
gmp_float exp(const gmp_float &a)
Definition: mpr_complex.cc:357
CanonicalForm num(const CanonicalForm &f)
static InternalCF * int2imm(long i)
Definition: imm.h:75
factory&#39;s class for variables
Definition: factory.h:117
char N base
Definition: ValueTraits.h:144
factory&#39;s main class
Definition: canonicalform.h:77
assertions for Factory
static InternalCF * poly(const Variable &v, int exp, const CanonicalForm &c)
Definition: cf_factory.cc:243
InternalCF * int2imm_p(long i)
Definition: imm.h:101
int ff_norm(const int a)
Definition: ffops.h:39
#define LIKELY(expression)
For optimizing if-branches.
Definition: cf_factory.cc:23
virtual class for internal CanonicalForm&#39;s
Definition: int_cf.h:41
#define IntegerDomain
Definition: cf_defs.h:25
virtual int levelcoeff() const
Definition: int_cf.h:68
CanonicalForm res
Definition: facAbsFact.cc:64
static InternalCF * rational(long num, long den)
Definition: cf_factory.cc:225
long intval() const
Definition: int_int.cc:506
int level() const
Definition: factory.h:134
Interface to generate InternalCF&#39;s over various domains from intrinsic types or mpz_t&#39;s.
void getmpi(InternalCF *value, mpz_t mpi)
Definition: cf_factory.cc:260
#define ASSERT1(expression, message, parameter1)
Definition: cf_assert.h:101
static int currenttype
Definition: cf_factory.h:26
InternalCF * int2imm_gf(long i)
Definition: imm.h:106
factory&#39;s class for polynomials
Definition: int_poly.h:71
static InternalCF * basic(long value)
Definition: cf_factory.cc:30
factory switches.
#define RationalDomain
Definition: cf_defs.h:24
int intmod(int p) const
Definition: int_int.cc:511
Factory&#39;s internal polynomials.
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
const long MAXIMMEDIATE
Definition: imm.h:55
CanonicalForm den(const CanonicalForm &f)
int is_imm(const InternalCF *const ptr)
Definition: canonicalform.h:62
operations on immediates, that is elements of F_p, GF, Z, Q that fit into intrinsic int...
#define GaloisFieldDomain
Definition: cf_defs.h:22
int gf_int2gf(int i)
Definition: gfops.h:65
Factory&#39;s internal CanonicalForm&#39;s.
#define ASSERT(expression, message)
Definition: cf_assert.h:99
int ff_prime
Definition: ffops.cc:14
factory&#39;s class for integers
Definition: int_int.h:40
InternalCF * getval() const
bool is_imm() const
Definition: int_int.cc:41
factory&#39;s class for rationals
Definition: int_rat.h:38
return result
Definition: facAbsBiFact.cc:76
Header for factory&#39;s main class CanonicalForm.
Factory&#39;s internal integers.
#define FiniteFieldDomain
Definition: cf_defs.h:23