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