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