source: git/kernel/structs.h @ 4ecc5a4

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