source: git/kernel/structs.h @ 06662e

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