source: git/factory/canonicalform.h @ 72bfc8

spielwiese
Last change on this file since 72bfc8 was ee668e, checked in by Jan Engelhardt <jengelh@…>, 12 years ago
factory/build: restore out-of-tree build support When attempting an OOT build, it fails to find <factory/cplusplus.h>, because cplusplus.h is always (even in in-tree builds) produced in "${builddir}", and not "${top_srcdir}/../factory". Furthermore, one must not rely on the basename of ${top_srcdir}, and going above ${top_srcdir} is undefined and may lead to spurious build failures. (Consider a hypothetical chroot on ${top_srcdir}). Therefore, create a directory include/factory and use -Iinclude such that <factory/*> yields a buildable state, move all exported header files there. Previous OOT build log: 17:22 seven:../factory/obj > make CXX cplusplus.o CXXLD cplusplus ./cplusplus > ./cplusplus.h ../bin/makeheader ../factory.template factory.h ../bin/makeheader ../factoryconf.template factoryconf.h YACC readcf.cc make all-am make[1]: Entering directory `/home/jengelh/obs/zu/home/jengelh/science/singsource/factory/obj' CXX libfactory_a-algext.o CXX libfactory_a-canonicalform.o In file included from ../cf_factory.h:12:0, from ../canonicalform.cc:7: ../../factory/cf_gmp.h:14:33: fatal error: factory/cplusplus.h: Ingen slik fil eller filkatalog compilation terminated. make[1]: *** [libfactory_a-canonicalform.o] Error 1 make[1]: Leaving directory `/home/jengelh/obs/zu/home/jengelh/science/singsource/factory/obj' make: *** [all] Error 2
  • Property mode set to 100644
File size: 10.0 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2/* $Id$ */
3
4#ifndef INCL_CANONICALFORM_H
5#define INCL_CANONICALFORM_H
6
7// #include "config.h"
8
9#ifndef NOSTREAMIO
10# ifdef HAVE_IOSTREAM
11#  include <iostream>
12#  define OSTREAM std::ostream
13#  define ISTREAM std::istream
14# elif defined(HAVE_IOSTREAM_H)
15#  include <iostream.h>
16#  define OSTREAM ostream
17#  define ISTREAM istream
18# endif
19#endif /* NOSTREAMIO */
20
21#include "cf_defs.h"
22#include "variable.h"
23#include <factory/templates/ftmpl_list.h>
24#include <factory/templates/ftmpl_array.h>
25#include <factory/templates/ftmpl_factor.h>
26#include <factory/templates/ftmpl_matrix.h>
27
28/*BEGINPUBLIC*/
29
30#undef CF_INLINE
31#define CF_INLINE
32#undef CF_NO_INLINE
33#define CF_NO_INLINE
34
35/*ENDPUBLIC*/
36
37#ifdef CF_USE_INLINE
38#undef CF_INLINE
39#define CF_INLINE inline
40#else
41#undef CF_INLINE
42#define CF_INLINE
43#endif
44
45/*BEGINPUBLIC*/
46
47class InternalCF;
48
49inline int is_imm ( const InternalCF * const ptr )
50{
51    // returns 0 if ptr is not immediate
52    return ( ((int)((long)ptr)) & 3 );
53}
54
55
56int initCanonicalForm( void );
57#ifndef SI_DONT_HAVE_GLOBAL_VARS
58static int cf_is_initialized_now = initCanonicalForm();
59#endif
60
61//{{{ class CanonicalForm
62class CanonicalForm
63{
64private:
65    InternalCF *value;
66public:
67    // constructors, destructors, selectors
68    CF_INLINE CanonicalForm();
69    CF_INLINE CanonicalForm( const CanonicalForm& );
70    CF_INLINE CanonicalForm( InternalCF* );
71    CF_INLINE CanonicalForm( const int );
72    CF_INLINE CanonicalForm( const Variable & );
73    CF_INLINE CanonicalForm( const Variable &, int );
74    CanonicalForm( const char *, const int base=10 ); // use with caution - does only handle integers !!!
75
76    CF_NO_INLINE ~CanonicalForm();
77
78    InternalCF* getval() const; // use with caution !!!
79
80    CanonicalForm deepCopy() const;
81
82    // predicates
83    CF_NO_INLINE bool isOne() const;
84    CF_NO_INLINE bool isZero() const;
85    inline bool isImm() const { return is_imm( value ); };
86
87    bool inZ() const;
88    bool inQ() const;
89    bool inFF() const;
90    bool inGF() const;
91    bool inPP() const;
92    bool inBaseDomain() const;
93    bool inExtension() const;
94    bool inCoeffDomain() const;
95    bool inPolyDomain() const;
96    bool inQuotDomain() const;
97
98    bool isFFinGF() const;
99    bool isUnivariate() const;
100    bool isHomogeneous() const;
101
102    // conversion functions
103    int intval() const;
104    CanonicalForm mapinto () const;
105
106    CanonicalForm lc () const;
107    CanonicalForm Lc () const;
108    CanonicalForm LC () const;
109    CanonicalForm LC ( const Variable & v ) const;
110
111    int degree () const;
112    int degree ( const Variable & v ) const;
113
114    CanonicalForm tailcoeff () const;
115    int taildegree () const;
116
117    int level () const;
118    Variable mvar () const;
119
120    CanonicalForm num () const;
121    CanonicalForm den () const;
122
123    // assignment operators
124    CF_NO_INLINE CanonicalForm& operator = ( const CanonicalForm& );
125    CF_NO_INLINE CanonicalForm& operator = ( const int );
126
127    CanonicalForm& operator += ( const CanonicalForm& );
128    CanonicalForm& operator -= ( const CanonicalForm& );
129    CanonicalForm& operator *= ( const CanonicalForm& );
130    CanonicalForm& operator /= ( const CanonicalForm& );
131    CanonicalForm& operator %= ( const CanonicalForm& );
132    CanonicalForm& div ( const CanonicalForm& );
133    CanonicalForm& tryDiv (const CanonicalForm&, const CanonicalForm&, bool& );
134    CanonicalForm& mod ( const CanonicalForm& );
135
136    // evaluation operators
137    CanonicalForm operator () ( const CanonicalForm & f ) const;
138    CanonicalForm operator () ( const CanonicalForm & f, const Variable & v ) const;
139
140    CanonicalForm operator [] ( int i ) const;
141
142    CanonicalForm deriv() const;
143    CanonicalForm deriv( const Variable & x ) const;
144
145    int sign() const;
146    CanonicalForm sqrt() const;
147    int ilog2() const;
148
149    // comparison operators
150    friend bool operator == ( const CanonicalForm&, const CanonicalForm& );
151    friend bool operator != ( const CanonicalForm&, const CanonicalForm& );
152    friend bool operator > ( const CanonicalForm&, const CanonicalForm& );
153    friend bool operator < ( const CanonicalForm&, const CanonicalForm& );
154
155    // arithmetic operators
156    friend CF_NO_INLINE CanonicalForm operator - ( const CanonicalForm& );
157
158    friend void divrem ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& );
159    friend bool divremt ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& );
160    friend bool tryDivremt ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm&, const CanonicalForm&, bool& );
161
162    friend CanonicalForm bgcd ( const CanonicalForm &, const CanonicalForm & );
163    friend CanonicalForm bextgcd ( const CanonicalForm &, const CanonicalForm &, CanonicalForm &, CanonicalForm & );
164
165    // input/output
166#ifndef NOSTREAMIO
167   void print( OSTREAM&, char * ) const;
168   void print( OSTREAM& ) const;
169   friend OSTREAM& operator << ( OSTREAM&, const CanonicalForm& );
170   friend ISTREAM& operator >> ( ISTREAM&, CanonicalForm& );
171#endif /* NOSTREAMIO */
172
173    // obsolete methods
174    static CanonicalForm genCoeff( int what, int i = 0 );
175    CanonicalForm genZero() const;
176    CanonicalForm genOne() const;
177
178    friend class CFIterator;
179};
180//}}}
181
182CF_INLINE CanonicalForm
183operator + ( const CanonicalForm&, const CanonicalForm& );
184
185CF_NO_INLINE CanonicalForm
186operator - ( const CanonicalForm&, const CanonicalForm& );
187
188CF_INLINE CanonicalForm
189operator * ( const CanonicalForm&, const CanonicalForm& );
190
191CF_NO_INLINE CanonicalForm
192operator / ( const CanonicalForm&, const CanonicalForm& );
193
194CF_NO_INLINE CanonicalForm
195operator % ( const CanonicalForm&, const CanonicalForm& );
196
197CF_NO_INLINE CanonicalForm
198div ( const CanonicalForm&, const CanonicalForm& );
199
200CF_NO_INLINE CanonicalForm
201mod ( const CanonicalForm&, const CanonicalForm& );
202
203/*ENDPUBLIC*/
204
205#ifdef CF_USE_INLINE
206#include "cf_inline.cc"
207#endif
208
209/*BEGINPUBLIC*/
210
211//{{{ function declarations from canonicalform.cc
212CanonicalForm blcm ( const CanonicalForm & f, const CanonicalForm & g );
213
214CanonicalForm power ( const CanonicalForm & f, int n );
215
216CanonicalForm power ( const Variable & v, int n );
217//}}}
218
219//{{{ function declarations from cf_gcd.cc
220CanonicalForm gcd ( const CanonicalForm&, const CanonicalForm& );
221
222CanonicalForm gcd_poly ( const CanonicalForm & f, const CanonicalForm & g );
223
224CanonicalForm extgcd ( const CanonicalForm&, const CanonicalForm&, CanonicalForm&, CanonicalForm& );
225
226CanonicalForm lcm ( const CanonicalForm&, const CanonicalForm& );
227
228CanonicalForm pp ( const CanonicalForm& );
229
230CanonicalForm content ( const CanonicalForm& );
231
232CanonicalForm content ( const CanonicalForm&, const Variable& );
233
234CanonicalForm icontent ( const CanonicalForm & f );
235
236CanonicalForm vcontent ( const CanonicalForm & f, const Variable & x );
237//}}}
238
239//{{{ function declarations from cf_ops.cc
240CanonicalForm swapvar ( const CanonicalForm &, const Variable &, const Variable & );
241
242CanonicalForm replacevar ( const CanonicalForm &, const Variable &, const Variable & );
243
244int getNumVars( const CanonicalForm & f );
245
246CanonicalForm getVars( const CanonicalForm & f );
247
248CanonicalForm apply ( const CanonicalForm & f, void (*mf)( CanonicalForm &, int & ) );
249
250CanonicalForm mapdomain ( const CanonicalForm & f, CanonicalForm (*mf)( const CanonicalForm & ) );
251
252int * degrees ( const CanonicalForm & f, int * degs = 0 );
253
254int totaldegree ( const CanonicalForm & f );
255
256int totaldegree ( const CanonicalForm & f, const Variable & v1, const Variable & v2 );
257
258int size ( const CanonicalForm & f, const Variable & v );
259
260int size ( const CanonicalForm & f );
261
262CanonicalForm reduce ( const CanonicalForm& f, const CanonicalForm & M);
263//}}}
264
265//{{{ inline functions corresponding to CanonicalForm methods
266//{{{ docu
267//
268// - inline functions corresponding to CanonicalForm methods.
269//
270// These function exist for convenience only and because it is
271// more beautiful to write 'degree( f )' than 'f.degree()'.
272//
273//}}}
274inline CanonicalForm
275lc ( const CanonicalForm & f ) { return f.lc(); }
276
277inline CanonicalForm
278Lc ( const CanonicalForm & f ) { return f.Lc(); }
279
280inline CanonicalForm
281LC ( const CanonicalForm & f ) { return f.LC(); }
282
283inline CanonicalForm
284LC ( const CanonicalForm & f, const Variable & v ) { return f.LC( v ); }
285
286inline int
287degree ( const CanonicalForm & f ) { return f.degree(); }
288
289inline int
290degree ( const CanonicalForm & f, const Variable & v ) { return f.degree( v ); }
291
292inline int
293taildegree ( const CanonicalForm & f ) { return f.taildegree(); }
294
295inline CanonicalForm
296tailcoeff ( const CanonicalForm & f ) { return f.tailcoeff(); }
297
298inline int
299level ( const CanonicalForm & f ) { return f.level(); }
300
301inline Variable
302mvar ( const CanonicalForm & f ) { return f.mvar(); }
303
304inline CanonicalForm
305num ( const CanonicalForm & f ) { return f.num(); }
306
307inline CanonicalForm
308den ( const CanonicalForm & f ) { return f.den(); }
309
310inline int
311sign ( const CanonicalForm & a ) { return a.sign(); }
312
313inline CanonicalForm
314deriv ( const CanonicalForm & f, const Variable & x ) { return f.deriv( x ); }
315
316inline CanonicalForm
317sqrt ( const CanonicalForm & a ) { return a.sqrt(); }
318
319inline int
320ilog2 ( const CanonicalForm & a ) { return a.ilog2(); }
321
322inline CanonicalForm
323mapinto ( const CanonicalForm & f ) { return f.mapinto(); }
324//}}}
325
326//{{{ inline functions
327inline CanonicalForm
328head ( const CanonicalForm & f )
329{
330    if ( f.level() > 0 )
331        return power( f.mvar(), f.degree() ) * f.LC();
332    else
333        return f;
334}
335
336inline int
337headdegree ( const CanonicalForm & f ) { return totaldegree( head( f ) ); }
338
339
340//}}}
341
342//{{{ other function declarations
343void setCharacteristic( int c ); // -> Fp && Q
344void setCharacteristic( int c, int n ); // -> PrimePower
345void setCharacteristic( int c, int n, char name ); // -> GF(q)
346
347int getCharacteristic();
348int getGFDegree();
349CanonicalForm getGFGenerator();
350
351void On( int );
352void Off( int );
353bool isOn( int );
354//}}}
355
356//{{{ type definitions
357typedef Factor<CanonicalForm> CFFactor;
358typedef List<CFFactor> CFFList;
359typedef ListIterator<CFFactor> CFFListIterator;
360typedef List<CanonicalForm> CFList;
361typedef ListIterator<CanonicalForm> CFListIterator;
362typedef Array<CanonicalForm> CFArray;
363typedef Matrix<CanonicalForm> CFMatrix;
364//}}}
365
366/*ENDPUBLIC*/
367
368#endif /* ! INCL_CANONICALFORM_H */
Note: See TracBrowser for help on using the repository browser.