source: git/kernel/structs.h @ 5be7db

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