source: git/kernel/structs.h @ 01e7a1d

spielwiese
Last change on this file since 01e7a1d was 01e7a1d, checked in by Hans Schoenemann <hannes@…>, 14 years ago
typedef poly -> polys-impl.h
  • Property mode set to 100644
File size: 18.6 KB
Line 
1#ifndef STRUCTS_H
2#define STRUCTS_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id$ */
7/*
8* ABSTRACT
9*/
10
11/* for memset: */
12#include <string.h>
13/* for omBin */
14#include <omalloc/omalloc.h>
15#ifdef HAVE_RINGS
16#include <kernel/si_gmp.h>
17#endif
18
19
20/* standard types */
21#ifdef HAVE_RINGS
22typedef unsigned long NATNUMBER;
23typedef mpz_ptr int_number;
24#endif
25#if (SIZEOF_LONG == 8)
26typedef int BOOLEAN;
27/* testet on x86_64, gcc 3.4.6: 2 % */
28/* testet on IA64, gcc 3.4.6: 1 % */
29#else
30/* testet on athlon, gcc 2.95.4: 1 % */
31typedef short BOOLEAN;
32#endif
33
34typedef void * ADDRESS;
35#define BITSET  unsigned int
36
37#if defined(SI_CPU_I386) || defined(SI_CPU_X86_64)
38  // the following settings seems to be better on i386 and x86_64 processors
39  // define if a*b is with mod instead of tables
40  #define HAVE_MULT_MOD
41  // #define HAVE_GENERIC_ADD
42  // #ifdef HAVE_MULT_MOD
43  // #define HAVE_DIV_MOD
44  // #endif
45#elif defined(SI_CPU_IA64)
46  // the following settings seems to be better on itanium processors
47  // #define HAVE_MULT_MOD
48  #define HAVE_GENERIC_ADD
49  // #ifdef HAVE_MULT_MOD
50  // #define HAVE_DIV_MOD
51  // #endif
52#elif defined(SI_CPU_SPARC)
53  // #define HAVE_GENERIC_ADD
54  #define HAVE_MULT_MOD
55  #ifdef HAVE_MULT_MOD
56  #define HAVE_DIV_MOD
57  #endif
58#elif defined(SI_CPU_PPC)
59  // the following settings seems to be better on ppc processors
60  // testet on: ppc_Linux, 740/750 PowerMac G3, 512k L2 cache
61  #define HAVE_MULT_MOD
62  // #ifdef HAVE_MULT_MOD
63  // #define HAVE_DIV_MOD
64  // #endif
65#endif
66
67#if SIZEOF_LONG == 4
68typedef long long int64;
69#elif SIZEOF_LONG == 8
70typedef long int64;
71#else
72#error int64 undefined
73#endif
74
75
76enum n_coeffType
77{
78  n_unknown=0,
79  n_Zp,
80  n_Q,
81  n_R,
82  n_GF,
83  n_long_R,
84  n_Zp_a,
85  n_Q_a,
86  n_long_C
87#ifdef HAVE_RINGS
88  ,n_Z,
89  n_Zm,
90  n_Zpn,
91  n_Z2n
92#endif
93};
94
95// #ifdef HAVE_PLURAL
96enum nc_type
97{
98  nc_error = -1, // Something's gone wrong!
99  nc_general = 0, /* yx=q xy+... */
100  nc_skew, /*1*/ /* yx=q xy */
101  nc_comm, /*2*/ /* yx= xy */
102  nc_lie,  /*3*/ /* yx=xy+... */
103  nc_undef, /*4*/  /* for internal reasons */
104
105  nc_exterior /*5*/ // Exterior Algebra(SCA): yx= -xy & (!:) x^2 = 0
106};
107// #endif
108
109struct snumber;
110typedef struct snumber *   number;
111typedef number (*numberfunc)(number a,number b);
112typedef number (*nMapFunc)(number a);
113
114/* C++-part */
115#ifdef __cplusplus
116class ip_smatrix;
117class intvec;
118class sleftv;
119class slists;
120class sattr;
121class skStrategy;
122class ssyStrategy;
123class procinfo;
124class kBucket;
125class sBucket;
126class CPolynomialSummator;
127class CGlobalMultiplier;
128class CFormulaPowerMultiplier;
129#endif
130
131struct n_Procs_s;
132struct sip_sring;
133struct sip_link;
134struct spolynom;
135
136struct sip_package;
137typedef struct sip_package ip_package;
138typedef ip_package *       package;
139
140// forward for ideals.h:
141struct sip_sideal;
142struct sip_smap;
143typedef struct sip_smap *         map;
144typedef struct sip_sideal *       ideal;
145
146
147typedef struct  n_Procs_s  n_Procs_s;
148
149// #ifdef HAVE_PLURAL
150struct nc_struct;
151typedef struct nc_struct   nc_struct;
152// #endif
153
154typedef struct spolyrec    polyrec;
155typedef struct sip_sring   ip_sring;
156typedef struct sip_link    ip_link;
157
158/* the pointer types */
159typedef char *             char_ptr;
160typedef int  *             int_ptr;
161typedef ip_sring *         ring;
162typedef poly *             polyset;
163
164#ifdef __cplusplus
165typedef ip_smatrix *       matrix;
166typedef ip_link *          si_link;
167typedef sleftv *           leftv;
168typedef slists *           lists;
169typedef sattr *            attr;
170typedef skStrategy *       kStrategy;
171typedef ssyStrategy *      syStrategy;
172typedef procinfo *         procinfov;
173typedef kBucket*           kBucket_pt;
174typedef sBucket*           sBucket_pt;
175typedef struct p_Procs_s p_Procs_s;
176
177struct n_Procs_s
178{
179   n_Procs_s* next;
180   // the union stuff
181   // Zp:
182   int npPrimeM;
183   int npPminus1M;
184   #ifdef HAVE_DIV_MOD
185   unsigned short *npInvTable;
186   #endif
187   #if !defined(HAVE_DIV_MOD) || !defined(HAVE_MULT_MOD)
188   unsigned short *npExpTable;
189   unsigned short *npLogTable;
190   #endif
191   // Zp_a, Q_a
192
193   // general stuff
194   numberfunc nMult, nSub ,nAdd ,nDiv, nIntDiv, nIntMod, nExactDiv;
195   number  (*cfInit)(int i,const ring r);
196   number  (*nPar)(int i);
197   int     (*nParDeg)(number n);
198   int     (*nSize)(number n);
199   int     (*n_Int)(number &n, const ring r);
200#ifdef HAVE_RINGS
201   int     (*nDivComp)(number a,number b);
202   BOOLEAN (*nIsUnit)(number a);
203   number  (*nGetUnit)(number a);
204   number  (*nExtGcd)(number a, number b, number *s, number *t);
205#endif
206   number  (*nNeg)(number a);
207   number  (*nInvers)(number a);
208   number  (*nCopy)(number a);
209   number  (*cfCopy)(number a, const ring r);
210   number  (*nRePart)(number a);
211   number  (*nImPart)(number a);
212   void    (*cfWrite)(number &a, const ring r);
213   const char *  (*nRead)(const char * s, number * a);
214   void    (*nNormalize)(number &a);
215   BOOLEAN (*nGreater)(number a,number b),
216#ifdef HAVE_RINGS
217           (*nDivBy)(number a, number b),
218#endif
219           (*nEqual)(number a,number b),
220           (*nIsZero)(number a),
221           (*nIsOne)(number a),
222           (*nIsMOne)(number a),
223           (*nGreaterZero)(number a);
224   void    (*nPower)(number a, int i, number * result);
225   number  (*cfGetDenom)(number &n, const ring r);
226   number  (*cfGetNumerator)(number &n, const ring r);
227   number  (*nGcd)(number a, number b, const ring r);
228   number  (*nLcm)(number a, number b, const ring r);
229   void    (*cfDelete)(number * a, const ring r);
230   nMapFunc (*cfSetMap)(const ring src, const ring dst);
231   char *  (*nName)(number n);
232   void    (*nInpMult)(number &a, number b, ring r);
233#ifdef LDEBUG
234   BOOLEAN (*nDBTest)(number a, const char *f,const int l);
235#endif
236
237   number nNULL; /* the 0 as constant */
238   int     char_flag;
239   int     ref;
240   n_coeffType type;
241   short   nChar;
242};
243
244/* the function pointer types */
245
246typedef long     (*pLDegProc)(poly p, int *length, ring r);
247typedef long     (*pFDegProc)(poly p, ring r);
248typedef void     (*p_SetmProc)(poly p, const ring r);
249
250typedef enum
251{
252  ro_dp, // ordering is a degree ordering
253  ro_wp, // ordering is a weighted degree ordering
254  ro_wp64, // ordering is a weighted64 degree ordering
255  ro_wp_neg, // ordering is a weighted degree ordering
256             // with possibly negative weights
257  ro_cp,    // ordering duplicates variables
258  ro_syzcomp, // ordering indicates "subset" of component number (ringorder_S)
259  ro_syz, // ordering  with component number >syzcomp is lower (ringorder_s)
260  ro_isTemp, ro_is, // Induced Syzygy (Schreyer) ordering (and prefix data placeholder dummy) (ringorder_IS)
261  ro_none
262}
263ro_typ;
264
265// ordering is a degree ordering
266struct sro_dp
267{
268  short place;  // where degree is stored (in L):
269  short start;  // bounds of ordering (in E):
270  short end;
271};
272typedef struct sro_dp sro_dp;
273
274// ordering is a weighted degree ordering
275struct sro_wp
276{
277  short place;  // where weighted degree is stored (in L)
278  short start;  // bounds of ordering (in E)
279  short end;
280  int *weights; // pointers into wvhdl field
281};
282typedef struct sro_wp sro_wp;
283
284// ordering is a weighted degree ordering
285struct sro_wp64
286{
287    short place;  // where weighted degree is stored (in L)
288    short start;  // bounds of ordering (in E)
289    short end;
290    int64 *weights64; // pointers into wvhdl field
291};
292typedef struct sro_wp64 sro_wp64;
293
294// ordering duplicates variables
295struct sro_cp
296{
297  short place;  // where start is copied to (in E)
298  short start;  // bounds of sources of copied variables (in E)
299  short end;
300};
301typedef struct sro_cp sro_cp;
302
303// ordering indicates "subset" of component number
304struct sro_syzcomp
305{
306  short place;  // where the index is stored (in L)
307  long *ShiftedComponents; // pointer into index field
308  int* Components;
309#ifdef PDEBUG
310  long length;
311#endif
312};
313typedef struct sro_syzcomp sro_syzcomp;
314
315// ordering  with component number >syzcomp is lower
316struct sro_syz
317{
318  short place;       // where the index is stored (in L)
319  int limit;         // syzcomp
320  int* syz_index;    // mapping Component -> SyzIndex for Comp <= limit
321  int  curr_index;   // SyzIndex for Component > limit
322};
323
324typedef struct sro_syz sro_syz;
325// Induced Syzygy (Schreyer) ordering is built inductively as follows:
326// we look for changes made by ordering blocks which are between prefix/suffix markers:
327// that is: which variables where placed by them and where (judging by v)
328
329// due to prefix/suffix nature we need some placeholder:
330// prefix stores here initial state
331// suffix cleares this up
332struct sro_ISTemp
333{
334  short start; // 1st member SHOULD be short "place"
335  int   suffixpos;
336  int*  pVarOffset; // copy!
337};
338
339// So this is the actuall thing!
340// suffix uses last sro_ISTemp (cleares it up afterwards) and
341// creates this block
342struct sro_IS
343{
344  short start, end;  // which part of L we want to want to update...
345  int*  pVarOffset; // same as prefix!
346
347  int limit; // first referenced component
348
349  // reference poly set?? // Should it be owned by ring?!!!
350  ideal F; // reference leading (module)-monomials set. owned by ring...
351  const intvec* componentWeights; // component weights! owned by ring...
352};
353
354typedef struct sro_IS sro_IS;
355typedef struct sro_ISTemp sro_ISTemp;
356
357struct sro_ord
358{
359  ro_typ  ord_typ;
360  int     order_index; // comes from r->order[order_index]
361  union
362  {
363     sro_dp dp;
364     sro_wp wp;
365     sro_wp64 wp64;
366     sro_cp cp;
367     sro_syzcomp syzcomp;
368     sro_syz syz;
369     sro_IS is;
370     sro_ISTemp isTemp;
371  } data;
372};
373
374#ifdef HAVE_PLURAL
375// NC pProcs:
376typedef poly (*mm_Mult_p_Proc_Ptr)(const poly m, poly p, const ring r);
377typedef poly (*mm_Mult_pp_Proc_Ptr)(const poly m, const poly p, const ring r);
378
379typedef ideal (*GB_Proc_Ptr)(const ideal F, const ideal Q, const intvec *w, const intvec *hilb, kStrategy strat);
380
381typedef poly (*SPoly_Proc_Ptr)(const poly p1, const poly p2, const ring r);
382typedef poly (*SPolyReduce_Proc_Ptr)(const poly p1, poly p2, const ring r);
383
384typedef void (*bucket_Proc_Ptr)(kBucket_pt b, poly p, number *c);
385
386struct nc_pProcs
387{
388public:
389  mm_Mult_p_Proc_Ptr                    mm_Mult_p;
390  mm_Mult_pp_Proc_Ptr                   mm_Mult_pp;
391
392  bucket_Proc_Ptr                       BucketPolyRed;
393  bucket_Proc_Ptr                       BucketPolyRed_Z;
394
395  SPoly_Proc_Ptr                        SPoly;
396  SPolyReduce_Proc_Ptr                  ReduceSPoly;
397
398  GB_Proc_Ptr                           GB;
399//                                         GlobalGB, // BBA
400//                                         LocalGB;  // MORA
401};
402
403
404struct nc_struct
405{
406  nc_type type;
407  //ring basering; // the ring C,D,.. live in (commutative ring with this NC structure!)
408
409  // initial data: square matrices rVar() x rVar()
410  // logically: upper triangular!!!
411  // TODO: eliminate this waste of memory!!!!
412  matrix C; 
413  matrix D;
414
415  // computed data:
416  matrix *MT; // size 0.. (rVar()*rVar()-1)/2
417  matrix COM;
418  int *MTsize; // size 0.. (rVar()*rVar()-1)/2
419
420  // IsSkewConstant indicates whethere coeffs C_ij are all equal,
421  // effective together with nc_type=nc_skew
422  int IsSkewConstant;
423
424  private:
425    // internal data for different implementations
426    // if dynamic => must be deallocated in destructor (nc_rKill!)
427    union
428    {
429      struct
430      {
431        // treat variables from iAltVarsStart till iAltVarsEnd as alternating vars.
432        // these variables should have odd degree, though that will not be checked
433        // iAltVarsStart, iAltVarsEnd are only used together with nc_type=nc_exterior
434        // 1 <= iAltVarsStart <= iAltVarsEnd <= r->N
435        unsigned int iFirstAltVar, iLastAltVar; // = 0 by default
436
437        // for factors of super-commutative algebras we need
438        // the part of general quotient ideal modulo squares!   
439        ideal idSCAQuotient; // = NULL by default. // must be deleted in Kill!
440      } sca;
441    } data;
442
443    CGlobalMultiplier* m_Multiplier;
444    CFormulaPowerMultiplier* m_PowerMultiplier;
445
446  public:
447   
448    inline nc_type& ncRingType() { return (type); };
449    inline nc_type ncRingType() const { return (type); };
450
451    inline unsigned int& FirstAltVar() 
452        { assume(ncRingType() == nc_exterior); return (data.sca.iFirstAltVar); };
453    inline unsigned int& LastAltVar () 
454        { assume(ncRingType() == nc_exterior); return (data.sca.iLastAltVar ); };
455
456    inline unsigned int FirstAltVar() const 
457        { assume(ncRingType() == nc_exterior); return (data.sca.iFirstAltVar); };
458    inline unsigned int LastAltVar () const 
459        { assume(ncRingType() == nc_exterior); return (data.sca.iLastAltVar ); };
460
461    inline ideal& SCAQuotient() 
462        { assume(ncRingType() == nc_exterior); return (data.sca.idSCAQuotient); };
463
464    inline CGlobalMultiplier* GetGlobalMultiplier() const
465        { return (m_Multiplier); };
466
467    inline CGlobalMultiplier*& GetGlobalMultiplier()
468        { return (m_Multiplier); };
469
470
471    inline CFormulaPowerMultiplier* GetFormulaPowerMultiplier() const
472        { return (m_PowerMultiplier); };
473
474    inline CFormulaPowerMultiplier*& GetFormulaPowerMultiplier()
475        { return (m_PowerMultiplier); };
476   
477  public:
478    nc_pProcs p_Procs; // NC procedures.
479
480};
481#endif
482
483class idrec;
484typedef idrec *   idhdl;
485
486struct sip_sring
487{
488// each entry must have a description and a procedure defining it,
489// general ordering: pointer/structs, long, int, short, BOOLEAN/char/enum
490// general defining procedures: rInit, rComplete, interpreter, ??
491  idhdl      idroot; /* local objects , interpreter*/
492  int*       order;  /* array of orderings, rInit/rSleftvOrdering2Ordering */
493  int*       block0; /* starting pos., rInit/rSleftvOrdering2Ordering*/
494  int*       block1; /* ending pos., rInit/rSleftvOrdering2Ordering*/
495  char**     parameter; /* names of parameters, rInit */
496  number     minpoly;  /* for Q_a/Zp_a, rInit */
497  ideal      minideal;
498  int**      wvhdl;  /* array of weight vectors, rInit/rSleftvOrdering2Ordering */
499  char **    names;  /* array of variable names, rInit */
500
501  // what follows below here should be set by rComplete, _only_
502  long      *ordsgn;  /* array of +/- 1 (or 0) for comparing monomials */
503                       /*  ExpL_Size entries*/
504
505  // is NULL for lp or N == 1, otherwise non-NULL (with OrdSize > 0 entries) */
506  sro_ord*   typ;   /* array of orderings + sizes, OrdSize entries */
507  /* if NegWeightL_Size > 0, then NegWeightL_Offset[0..size_1] is index of longs
508  in ExpVector whose values need an offset due to negative weights */
509  /* array of NegWeigtL_Size indicies */
510  int*      NegWeightL_Offset;
511
512  int*     VarOffset;
513
514  ideal      qideal; /* extension to the ring structure: qring, rInit */
515
516  int*     firstwv;
517
518  omBin    PolyBin; /* Bin from where monoms are allocated */
519#ifdef HAVE_RINGS
520  unsigned int  ringtype;  /* cring = 0 => coefficient field, cring = 1 => coeffs from Z/2^m */
521  int_number    ringflaga; /* Z/(ringflag^ringflagb)=Z/nrnModul*/
522  unsigned long ringflagb;
523  unsigned long nr2mModul;  /* Z/nr2mModul */
524  int_number    nrnModul;
525#endif
526  unsigned long options; /* ring dependent options */
527
528  int        ch;  /* characteristic, rInit */
529  int        ref; /* reference counter to the ring, interpreter */
530
531  short      float_len; /* additional char-flags, rInit */
532  short      float_len2; /* additional char-flags, rInit */
533
534  short      N;      /* number of vars, rInit */
535
536  short      P;      /* number of pars, rInit */
537  short      OrdSgn; /* 1 for polynomial rings, -1 otherwise, rInit */
538
539  short     firstBlockEnds;
540#ifdef HAVE_PLURAL
541  short     real_var_start, real_var_end;
542#endif
543
544#ifdef HAVE_SHIFTBBA
545  short          isLPring; /* 0 for non-letterplace rings, otherwise the number of LP blocks, at least 1, known also as lV */
546#endif
547
548  BOOLEAN   VectorOut;
549  BOOLEAN   ShortOut;
550  BOOLEAN   CanShortOut;
551  BOOLEAN   LexOrder; // TRUE if the monomial ordering has polynomial and power series blocks
552  BOOLEAN   MixedOrder; // TRUE for global/local mixed orderings, FALSE otherwise
553
554  BOOLEAN   ComponentOrder; // ???
555
556  // what follows below here should be set by rComplete, _only_
557  // contains component, but no weight fields in E */
558  short      ExpL_Size; // size of exponent vector in long
559  short      CmpL_Size; // portions which need to be compared
560  /* number of long vars in exp vector:
561     long vars are those longs in the exponent vector which are
562     occupied by variables, only */
563  short      VarL_Size;
564  short      BitsPerExp; /* number of bits per exponent */
565  short      ExpPerLong; /* maximal number of Exponents per long */
566  short      pCompIndex; /* p->exp.e[pCompIndex] is the component */
567  short      pOrdIndex; /* p->exp[pOrdIndex] is pGetOrd(p) */
568  short      OrdSize; /* size of ord vector (in sro_ord) */
569
570  /* if >= 0, long vars in exp vector are consecutive and start there
571     if <  0, long vars in exp vector are not consecutive */
572  short     VarL_LowIndex;
573  // number of exponents in r->VarL_Offset[0]
574  // is minimal number of exponents in a long var
575  short     MinExpPerLong;
576
577  short     NegWeightL_Size;
578  /* array of size VarL_Size,
579     VarL_Offset[i] gets i-th long var in exp vector */
580  int*      VarL_Offset;
581
582  /* mask for getting single exponents */
583  unsigned long bitmask;
584  /* mask used for divisiblity tests */
585  unsigned long divmask; // rComplete
586
587  p_Procs_s*    p_Procs; // rComplete/p_ProcsSet
588
589  /* FDeg and LDeg */
590  pFDegProc     pFDeg; // rComplete/rSetDegStuff
591  pLDegProc     pLDeg; // rComplete/rSetDegStuff
592
593  /* as it was determined by rComplete */
594  pFDegProc     pFDegOrig;
595  /* and as it was determined before rOptimizeLDeg */
596  pLDegProc     pLDegOrig;
597
598  p_SetmProc    p_Setm;
599  n_Procs_s*    cf;
600  ring          algring;
601#ifdef HAVE_PLURAL
602  private:
603    nc_struct*    _nc; // private
604  public:
605    inline const nc_struct* GetNC() const { return _nc; }; // public!!!
606    inline nc_struct*& GetNC() { return _nc; }; // public!!!
607#endif
608};
609
610#endif /* __cplusplus */
611
612
613
614/*
615**  7. runtime procedures/global data
616*/
617
618/* 7.1 C-routines : */
619
620
621#ifdef __cplusplus
622extern "C" {
623#endif
624void  m2_end(int i) __attribute__((noreturn));
625#ifdef __cplusplus
626}
627#endif
628
629/* 7.2 C++-routines : */
630
631#ifdef __cplusplus
632int   inits(void);
633int   IsPrime(int i);
634extern int siSeed;
635int siRand();
636#endif
637
638#define loop for(;;)
639
640#ifndef ABS
641#define ABS(x) ((x)<0?(-(x)):(x))
642#endif
643
644#if defined(__cplusplus)
645static inline int si_max(const int a, const int b)  { return (a>b) ? a : b; }
646static inline int si_min(const int a, const int b)  { return (a<b) ? a : b; }
647static inline long si_max(const long a, const long b)  { return (a>b) ? a : b; }
648static inline unsigned long si_max(const unsigned long a, const unsigned long b)  { return (a>b) ? a : b; }
649static inline long si_min(const long a, const long b)  { return (a<b) ? a : b; }
650static inline unsigned long si_min(const unsigned long a, const unsigned long b)  { return (a<b) ? a : b; }
651#else
652#define si_max(A,B) ((A) > (B) ? (A) : (B))
653#define si_min(A,B) ((A) < (B) ? (A) : (B))
654#endif
655
656extern omBin char_ptr_bin;
657extern omBin sleftv_bin;
658
659#endif
660
Note: See TracBrowser for help on using the repository browser.