canonicalform.h
Go to the documentation of this file.
1 /* emacs edit mode for this file is -*- C++ -*- */
2 
3 /**
4  * @file canonicalform.h
5  *
6  * Header for factory's main class CanonicalForm
7 **/
8 #ifndef INCL_CANONICALFORM_H
9 #define INCL_CANONICALFORM_H
10 
11 // #include "config.h"
12 
13 #ifndef NOSTREAMIO
14 # ifdef HAVE_IOSTREAM
15 # include <iostream>
16 # define OSTREAM std::ostream
17 # define ISTREAM std::istream
18 # elif defined(HAVE_IOSTREAM_H)
19 # include <iostream.h>
20 # define OSTREAM ostream
21 # define ISTREAM istream
22 # endif
23 #endif /* NOSTREAMIO */
24 
25 #include <stdint.h>
26 
27 #include "cf_defs.h"
28 #include "variable.h"
29 #include <factory/cf_gmp.h>
35 
36 /*BEGINPUBLIC*/
37 
38 #undef CF_INLINE
39 #define CF_INLINE
40 #undef CF_NO_INLINE
41 #define CF_NO_INLINE
42 
43 /*ENDPUBLIC*/
44 
45 #ifdef CF_USE_INLINE
46 #undef CF_INLINE
47 #define CF_INLINE inline
48 #else
49 #undef CF_INLINE
50 #define CF_INLINE
51 #endif
52 
53 /*BEGINPUBLIC*/
54 
55 class InternalCF;
56 
57 inline int is_imm ( const InternalCF * const ptr )
58 {
59  // returns 0 if ptr is not immediate
60  return ( ((int)((intptr_t)ptr)) & 3 );
61 }
62 
63 
64 /**
65  * factory's main class
66  *
67  * a CanonicalForm can represent a polynomial over or a constant in F_p,
68  * F_p(alpha), GF (F_p[t]/(Conway polynomial)), Z, or Q
69  *
70  * @sa int_poly.h, variable.h, ffops.h, gfops.h, imm.h, int_int.h, int_rat.h
71 **/
73 {
74 private:
76 public:
77  // constructors, destructors, selectors
81  CF_INLINE CanonicalForm( const int );
82  CF_INLINE CanonicalForm( const long );
83  CF_INLINE CanonicalForm( const Variable & );
84  CF_INLINE CanonicalForm( const Variable &, int );
85  CanonicalForm( const char *, const int base=10 ); // use with caution - does only handle integers !!!
86 
88 
89  InternalCF* getval() const; // use with caution !!!
90 
91  CanonicalForm deepCopy() const;
92 
93  void mpzval(mpz_t val) const;
94  // predicates
95  CF_NO_INLINE bool isOne() const;
96  CF_NO_INLINE bool isZero() const;
97  inline bool isImm() const { return is_imm( value ); };
98 
99  bool inZ() const;
100  bool inQ() const;
101  bool inFF() const;
102  bool inGF() const;
103  bool inBaseDomain() const;
104  bool inExtension() const;
105  bool inCoeffDomain() const;
106  bool inPolyDomain() const;
107  bool inQuotDomain() const;
108 
109  bool isFFinGF() const;
110  bool isUnivariate() const;
111  bool isHomogeneous() const;
112 
113  // conversion functions
114  long intval() const;
115  CanonicalForm mapinto () const;
116 
117  CanonicalForm lc () const;
118  CanonicalForm Lc () const;
119  CanonicalForm LC () const;
120  CanonicalForm LC ( const Variable & v ) const;
121 
122  int degree () const;
123  int degree ( const Variable & v ) const;
124 
125  CanonicalForm tailcoeff () const;
126  CanonicalForm tailcoeff ( const Variable & v ) const;
127  int taildegree () const;
128 
129  int level () const;
130  Variable mvar () const;
131 
132  CanonicalForm num () const;
133  CanonicalForm den () const;
134 
135  // assignment operators
137  CF_NO_INLINE CanonicalForm& operator = ( const long );
138 
144  CanonicalForm& div ( const CanonicalForm& );
145  CanonicalForm& tryDiv (const CanonicalForm&, const CanonicalForm&, bool& );
146  CanonicalForm& mod ( const CanonicalForm& );
147 
148  // evaluation operators
149  CanonicalForm operator () ( const CanonicalForm & f ) const;
150  CanonicalForm operator () ( const CanonicalForm & f, const Variable & v ) const;
151 
152  CanonicalForm operator [] ( int i ) const;
153 
154  CanonicalForm deriv() const;
155  CanonicalForm deriv( const Variable & x ) const;
156 
157  int sign() const;
158  CanonicalForm sqrt() const;
159  int ilog2() const;
160 
161  // comparison operators
162  friend bool operator == ( const CanonicalForm&, const CanonicalForm& );
163  friend bool operator != ( const CanonicalForm&, const CanonicalForm& );
164  friend bool operator > ( const CanonicalForm&, const CanonicalForm& );
165  friend bool operator < ( const CanonicalForm&, const CanonicalForm& );
166 
167  // arithmetic operators
169 
170  friend void divrem ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& );
171  friend bool divremt ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& );
172  friend bool tryDivremt ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm&, const CanonicalForm&, bool& );
173 
174  friend CanonicalForm bgcd ( const CanonicalForm &, const CanonicalForm & );
176 
177  // input/output
178 #ifndef NOSTREAMIO
179  void print( OSTREAM&, char * ) const;
180  void print( OSTREAM& ) const;
181  friend OSTREAM& operator << ( OSTREAM&, const CanonicalForm& );
183 #endif /* NOSTREAMIO */
184 
185  // obsolete methods
186  CanonicalForm genZero() const;
187  CanonicalForm genOne() const;
188 
189  friend class CFIterator;
190 };
191 
193 operator + ( const CanonicalForm&, const CanonicalForm& );
194 
196 operator - ( const CanonicalForm&, const CanonicalForm& );
197 
199 operator * ( const CanonicalForm&, const CanonicalForm& );
200 
202 operator / ( const CanonicalForm&, const CanonicalForm& );
203 
205 operator % ( const CanonicalForm&, const CanonicalForm& );
206 
208 div ( const CanonicalForm&, const CanonicalForm& );
209 
211 mod ( const CanonicalForm&, const CanonicalForm& );
212 
213 /*ENDPUBLIC*/
214 
215 #ifdef CF_USE_INLINE
216 #include "cf_inline.cc"
217 #endif
218 
219 /*BEGINPUBLIC*/
220 
221 //{{{ function declarations from canonicalform.cc
222 CanonicalForm blcm ( const CanonicalForm & f, const CanonicalForm & g );
223 
224 CanonicalForm power ( const CanonicalForm & f, int n );
225 
226 CanonicalForm power ( const Variable & v, int n );
227 //}}}
228 
229 //{{{ function declarations from cf_gcd.cc
230 CanonicalForm gcd ( const CanonicalForm&, const CanonicalForm& );
231 
232 CanonicalForm gcd_poly ( const CanonicalForm & f, const CanonicalForm & g );
233 
234 CanonicalForm lcm ( const CanonicalForm&, const CanonicalForm& );
235 
236 CanonicalForm pp ( const CanonicalForm& );
237 
239 
240 CanonicalForm content ( const CanonicalForm&, const Variable& );
241 
243 
244 CanonicalForm vcontent ( const CanonicalForm & f, const Variable & x );
245 //}}}
246 
247 //{{{ function declarations from cf_ops.cc
248 CanonicalForm swapvar ( const CanonicalForm &, const Variable &, const Variable & );
249 
250 CanonicalForm replacevar ( const CanonicalForm &, const Variable &, const Variable & );
251 
252 int getNumVars( const CanonicalForm & f );
253 
255 
256 CanonicalForm apply ( const CanonicalForm & f, void (*mf)( CanonicalForm &, int & ) );
257 
258 CanonicalForm mapdomain ( const CanonicalForm & f, CanonicalForm (*mf)( const CanonicalForm & ) );
259 
260 int * degrees ( const CanonicalForm & f, int * degs = 0 );
261 
262 int totaldegree ( const CanonicalForm & f );
263 
264 int totaldegree ( const CanonicalForm & f, const Variable & v1, const Variable & v2 );
265 
266 int size ( const CanonicalForm & f, const Variable & v );
267 
268 int size ( const CanonicalForm & f );
269 
270 CanonicalForm reduce ( const CanonicalForm& f, const CanonicalForm & M);
271 
272 bool hasFirstAlgVar( const CanonicalForm & f, Variable & a);
273 
274 CanonicalForm leftShift (const CanonicalForm& F, int n);
275 //}}}
276 
277 //{{{ inline functions corresponding to CanonicalForm methods
278 //{{{ docu
279 //
280 // - inline functions corresponding to CanonicalForm methods.
281 //
282 // These function exist for convenience only and because it is
283 // more beautiful to write 'degree( f )' than 'f.degree()'.
284 //
285 //}}}
286 inline CanonicalForm
287 lc ( const CanonicalForm & f ) { return f.lc(); }
288 
289 inline CanonicalForm
290 Lc ( const CanonicalForm & f ) { return f.Lc(); }
291 
292 inline CanonicalForm
293 LC ( const CanonicalForm & f ) { return f.LC(); }
294 
295 inline CanonicalForm
296 LC ( const CanonicalForm & f, const Variable & v ) { return f.LC( v ); }
297 
298 inline int
299 degree ( const CanonicalForm & f ) { return f.degree(); }
300 
301 inline int
302 degree ( const CanonicalForm & f, const Variable & v ) { return f.degree( v ); }
303 
304 inline int
305 taildegree ( const CanonicalForm & f ) { return f.taildegree(); }
306 
307 inline CanonicalForm
308 tailcoeff ( const CanonicalForm & f ) { return f.tailcoeff(); }
309 
310 inline CanonicalForm
311 tailcoeff (const CanonicalForm& f, const Variable& v) { return f.tailcoeff(v); }
312 
313 inline int
314 level ( const CanonicalForm & f ) { return f.level(); }
315 
316 inline Variable
317 mvar ( const CanonicalForm & f ) { return f.mvar(); }
318 
319 inline CanonicalForm
320 num ( const CanonicalForm & f ) { return f.num(); }
321 
322 inline CanonicalForm
323 den ( const CanonicalForm & f ) { return f.den(); }
324 
325 inline int
326 sign ( const CanonicalForm & a ) { return a.sign(); }
327 
328 inline CanonicalForm
329 deriv ( const CanonicalForm & f, const Variable & x ) { return f.deriv( x ); }
330 
331 inline CanonicalForm
332 sqrt ( const CanonicalForm & a ) { return a.sqrt(); }
333 
334 inline int
335 ilog2 ( const CanonicalForm & a ) { return a.ilog2(); }
336 
337 inline CanonicalForm
338 mapinto ( const CanonicalForm & f ) { return f.mapinto(); }
339 //}}}
340 
341 //{{{ inline functions
342 inline CanonicalForm
343 head ( const CanonicalForm & f )
344 {
345  if ( f.level() > 0 )
346  return power( f.mvar(), f.degree() ) * f.LC();
347  else
348  return f;
349 }
350 
351 inline int
352 headdegree ( const CanonicalForm & f ) { return totaldegree( head( f ) ); }
353 
354 
355 //}}}
356 
357 //{{{ other function declarations
358 void setCharacteristic( int c ); // -> Fp && Q
359 void setCharacteristic( int c, int n ); // -> PrimePower
360 void setCharacteristic( int c, int n, char name ); // -> GF(q)
361 
362 int getCharacteristic();
363 int getGFDegree();
365 
366 void On( int );
367 void Off( int );
368 bool isOn( int );
369 //}}}
370 
371 //{{{ type definitions
389 //}}}
390 
391 /*ENDPUBLIC*/
392 
393 #endif /* ! INCL_CANONICALFORM_H */
List< CFList > ListCFList
List< CanonicalForm > CFList
List< Variable > Varlist
CanonicalForm icontent(const CanonicalForm &f)
CanonicalForm icontent ( const CanonicalForm & f )
Definition: cf_gcd.cc:71
CanonicalForm power(const CanonicalForm &f, int n)
exponentiation
bool inQ() const
bool isFFinGF() const
friend bool operator==(const CanonicalForm &, const CanonicalForm &)
operator ==() - compare canonical forms on (in)equality.
Variable mvar() const
mvar() returns the main variable of CO or Variable() if CO is in a base domain.
const poly a
Definition: syzextra.cc:212
friend OSTREAM & operator<<(OSTREAM &, const CanonicalForm &)
int level(const CanonicalForm &f)
CanonicalForm & operator%=(const CanonicalForm &)
InternalCF * value
Definition: canonicalform.h:75
CF_NO_INLINE CanonicalForm mod(const CanonicalForm &, const CanonicalForm &)
Definition: cf_inline.cc:564
CanonicalForm deepCopy() const
bool inCoeffDomain() const
void On(int)
switches
#define CF_INLINE
Definition: canonicalform.h:50
Matrix< CanonicalForm > CFMatrix
CanonicalForm num(const CanonicalForm &f)
CanonicalForm deriv(const CanonicalForm &f, const Variable &x)
ListIterator< CanonicalForm > CFListIterator
CanonicalForm reduce(const CanonicalForm &f, const CanonicalForm &M)
polynomials in M.mvar() are considered coefficients M univariate monic polynomial the coefficients of...
Definition: cf_ops.cc:646
CF_INLINE CanonicalForm operator+(const CanonicalForm &, const CanonicalForm &)
CF_INLINE CanonicalForm operator +, -, *, /, % ( const CanonicalForm & lhs, const CanonicalForm & rhs...
Definition: cf_inline.cc:496
f
Definition: cfModGcd.cc:4022
factory's class for variables
Definition: variable.h:32
CanonicalForm vcontent(const CanonicalForm &f, const Variable &x)
CanonicalForm vcontent ( const CanonicalForm & f, const Variable & x )
Definition: cf_gcd.cc:230
friend CF_NO_INLINE CanonicalForm operator-(const CanonicalForm &)
CF_INLINE CanonicalForm operator - ( const CanonicalForm & cf )
Definition: cf_inline.cc:438
int * degrees(const CanonicalForm &f, int *degs=0)
int * degrees ( const CanonicalForm & f, int * degs )
Definition: cf_ops.cc:493
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
ListIterator< CFAFactor > CFAFListIterator
CF_NO_INLINE CanonicalForm operator/(const CanonicalForm &, const CanonicalForm &)
Definition: cf_inline.cc:529
char N base
Definition: ValueTraits.h:144
factory's main class
Definition: canonicalform.h:72
CF_INLINE CanonicalForm operator*(const CanonicalForm &, const CanonicalForm &)
Definition: cf_inline.cc:517
void print(OSTREAM &, char *) const
input/output
CanonicalForm & operator-=(const CanonicalForm &)
List< CFFactor > CFFList
Variable mvar(const CanonicalForm &f)
Array< CanonicalForm > CFArray
g
Definition: cfModGcd.cc:4031
bool inZ() const
predicates
CF_NO_INLINE bool isZero() const
Definition: cf_inline.cc:372
bool inExtension() const
CanonicalForm sqrt() const
CanonicalForm CanonicalForm::sqrt () const.
friend bool divremt(const CanonicalForm &, const CanonicalForm &, CanonicalForm &, CanonicalForm &)
ListIterator< CFList > ListCFListIterator
CanonicalForm deriv() const
deriv() - return the formal derivation of CO.
int taildegree() const
taildegree() returns -1 for the zero polynomial, 0 if CO is in a base domain, otherwise the least deg...
ListIterator< CFFactor > CFFListIterator
CanonicalForm Lc(const CanonicalForm &f)
long intval() const
conversion functions
void setCharacteristic(int c)
Definition: cf_char.cc:23
bool isHomogeneous() const
friend bool operator<(const CanonicalForm &, const CanonicalForm &)
void Off(int)
switches
CanonicalForm lc() const
CanonicalForm CanonicalForm::lc (), Lc (), LC (), LC ( v ) const.
int getCharacteristic()
Definition: cf_char.cc:51
virtual class for internal CanonicalForm's
Definition: int_cf.h:35
CF_NO_INLINE bool isOne() const
CF_INLINE bool CanonicalForm::isOne, isZero () const.
Definition: cf_inline.cc:354
CanonicalForm content(const CanonicalForm &)
CanonicalForm content ( const CanonicalForm & f )
Definition: cf_gcd.cc:180
int level() const
level() returns the level of CO.
bool isOn(int)
switches
CanonicalForm lc(const CanonicalForm &f)
friend void divrem(const CanonicalForm &, const CanonicalForm &, CanonicalForm &, CanonicalForm &)
int degree() const
Returns -1 for the zero polynomial and 0 if CO is in a base domain.
#define CF_NO_INLINE
Definition: canonicalform.h:41
CanonicalForm & tryDiv(const CanonicalForm &, const CanonicalForm &, bool &)
same as divremt but handles zero divisors in case we are in Z_p[x]/(f) where f is not irreducible ...
#define M
Definition: sirandom.c:24
CanonicalForm tailcoeff() const
tailcoeff() - return least coefficient
int taildegree(const CanonicalForm &f)
CanonicalForm swapvar(const CanonicalForm &, const Variable &, const Variable &)
swapvar() - swap variables x1 and x2 in f.
Definition: cf_ops.cc:168
CanonicalForm genOne() const
CanonicalForm genZero() const
genOne(), genZero()
int ilog2() const
int CanonicalForm::ilog2 () const
friend ISTREAM & operator>>(ISTREAM &, CanonicalForm &)
ListIterator< int > IntListIterator
CanonicalForm getVars(const CanonicalForm &f)
CanonicalForm getVars ( const CanonicalForm & f )
Definition: cf_ops.cc:350
bool inFF() const
int headdegree(const CanonicalForm &f)
CanonicalForm apply(const CanonicalForm &f, void(*mf)(CanonicalForm &, int &))
CanonicalForm apply ( const CanonicalForm & f, void (*mf)( CanonicalForm &, int & ) ) ...
Definition: cf_ops.cc:402
AFactor< CanonicalForm > CFAFactor
CanonicalForm & operator*=(const CanonicalForm &)
CanonicalForm pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition: cf_gcd.cc:253
friend bool operator!=(const CanonicalForm &, const CanonicalForm &)
operator !=() returns true iff lhs does not equal rhs.
CanonicalForm Lc() const
definition of configurable inline `CanonicalForm' methods.
bool hasFirstAlgVar(const CanonicalForm &f, Variable &a)
check if poly f contains an algebraic variable a
Definition: cf_ops.cc:665
friend bool operator>(const CanonicalForm &, const CanonicalForm &)
operator >() - compare canonical forms.
CanonicalForm num() const
num() returns the numerator of CO if CO is a rational number, CO itself otherwise.
CanonicalForm mapinto() const
CanonicalForm den() const
den() returns the denominator of CO if CO is a rational number, 1 (from the current domain!) otherwis...
int i
Definition: cfEzgcd.cc:123
CanonicalForm mapinto(const CanonicalForm &f)
CanonicalForm getGFGenerator()
Definition: cf_char.cc:62
factory switches.
CanonicalForm sqrt(const CanonicalForm &a)
CF_INLINE CanonicalForm()
CF_INLINE CanonicalForm::CanonicalForm ()
Definition: cf_inline.cc:126
int ilog2(const CanonicalForm &a)
CanonicalForm & operator+=(const CanonicalForm &)
assignment operators
CanonicalForm operator[](int i) const
operator []() - return i'th coefficient from CO.
CF_NO_INLINE ~CanonicalForm()
CF_INLINE CanonicalForm::~CanonicalForm ()
Definition: cf_inline.cc:253
bool isUnivariate() const
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
class to iterate through CanonicalForm's
Definition: cf_iter.h:44
bool inPolyDomain() const
operations on variables
CanonicalForm & mod(const CanonicalForm &)
bool isImm() const
Definition: canonicalform.h:97
int getNumVars(const CanonicalForm &f)
int getNumVars ( const CanonicalForm & f )
Definition: cf_ops.cc:314
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
char name(const Variable &v)
Definition: variable.h:95
CF_NO_INLINE CanonicalForm div(const CanonicalForm &, const CanonicalForm &)
CF_INLINE CanonicalForm div, mod ( const CanonicalForm & lhs, const CanonicalForm & rhs ) ...
Definition: cf_inline.cc:553
Array< int > Intarray
CanonicalForm LC() const
CanonicalForm head(const CanonicalForm &f)
friend CanonicalForm bgcd(const CanonicalForm &, const CanonicalForm &)
CanonicalForm bgcd ( const CanonicalForm & f, const CanonicalForm & g )
CanonicalForm den(const CanonicalForm &f)
CanonicalForm & div(const CanonicalForm &)
CF_NO_INLINE CanonicalForm operator-(const CanonicalForm &, const CanonicalForm &)
Definition: cf_inline.cc:505
CanonicalForm leftShift(const CanonicalForm &F, int n)
left shift the main variable of F by n
Definition: cf_ops.cc:683
Factor< CanonicalForm > CFFactor
void mpzval(mpz_t val) const
ListIterator< Variable > VarlistIterator
int is_imm(const InternalCF *const ptr)
Definition: canonicalform.h:57
int getGFDegree()
Definition: cf_char.cc:56
Variable x
Definition: cfModGcd.cc:4023
CanonicalForm tailcoeff(const CanonicalForm &f)
int totaldegree(const CanonicalForm &f)
int totaldegree ( const CanonicalForm & f )
Definition: cf_ops.cc:523
#define OSTREAM
Definition: canonicalform.h:16
bool inQuotDomain() const
bool inBaseDomain() const
CanonicalForm operator()(const CanonicalForm &f) const
operator ()() - evaluation operator.
InternalCF * getval() const
CanonicalForm mapdomain(const CanonicalForm &f, CanonicalForm(*mf)(const CanonicalForm &))
CanonicalForm mapdomain ( const CanonicalForm & f, CanonicalForm (*mf)( const CanonicalForm & ) ) ...
Definition: cf_ops.cc:440
friend CanonicalForm bextgcd(const CanonicalForm &, const CanonicalForm &, CanonicalForm &, CanonicalForm &)
CanonicalForm bextgcd ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & a...
CanonicalForm gcd_poly(const CanonicalForm &f, const CanonicalForm &g)
CanonicalForm gcd_poly ( const CanonicalForm & f, const CanonicalForm & g )
Definition: cf_gcd.cc:94
int degree(const CanonicalForm &f)
CanonicalForm blcm(const CanonicalForm &f, const CanonicalForm &g)
CanonicalForm LC(const CanonicalForm &f)
List< CFAFactor > CFAFList
CanonicalForm & operator/=(const CanonicalForm &)
CanonicalForm replacevar(const CanonicalForm &, const Variable &, const Variable &)
CanonicalForm replacevar ( const CanonicalForm & f, const Variable & x1, const Variable & x2 ) ...
Definition: cf_ops.cc:271
friend bool tryDivremt(const CanonicalForm &, const CanonicalForm &, CanonicalForm &, CanonicalForm &, const CanonicalForm &, bool &)
same as divremt but handles zero divisors in case we are in Z_p[x]/(f) where f is not irreducible ...
List< int > IntList
bool inGF() const
#define ISTREAM
Definition: canonicalform.h:17
CanonicalForm lcm(const CanonicalForm &, const CanonicalForm &)
CanonicalForm lcm ( const CanonicalForm & f, const CanonicalForm & g )
Definition: cf_gcd.cc:343
int sign(const CanonicalForm &a)
CF_NO_INLINE CanonicalForm & operator=(const CanonicalForm &)
CF_INLINE CanonicalForm & CanonicalForm::operator = ( const CanonicalForm & cf )
Definition: cf_inline.cc:272
int sign() const
int CanonicalForm::sign () const
CF_NO_INLINE CanonicalForm operator%(const CanonicalForm &, const CanonicalForm &)
Definition: cf_inline.cc:540
CanonicalForm gcd(const CanonicalForm &, const CanonicalForm &)
Definition: cf_gcd.cc:262