p_Procs_Set.h
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 /***************************************************************
5  * File: p_Procs_Set.h
6  * Purpose: Procedures for setting p_Procs at run time
7  * Note: this file is included by p_Procs_Dynamic/Static.cc
8  * The macros
9  * DoSetProc(what, field, length, ord)
10  * InitSetProc(field, length ord)
11  * have to be defined before this file is included
12  * Author: obachman (Olaf Bachmann)
13  * Created: 12/00
14  *******************************************************************/
15 
16 #include "reporter/reporter.h"
17 #include "misc/auxiliary.h"
18 
19 // extract p_Procs properties from a ring
20 static inline p_Field p_FieldIs(ring r)
21 {
22  if (rField_is_Zp(r))
23  return FieldZp;
24  if (rField_is_R(r)) return FieldR;
25  if (rField_is_GF(r)) return FieldGF;
26  if (rField_is_Q(r)) return FieldQ;
27 #ifdef HAVE_MORE_FIELDS_IMPLEMENTED
28  if (rField_is_long_R(r)) return FieldLong_R;
29  if (rField_is_long_C(r)) return FieldLong_C;
30  if (rField_is_Zp_a(r)) return FieldZp_a;
31  if (rField_is_Q_a(r)) return FieldQ_a;
32 #endif
33  if (rField_is_Ring(r)) return RingGeneral;
34  return FieldGeneral;
35 }
36 
37 static inline p_Length p_LengthIs(ring r)
38 {
39  assume(r->ExpL_Size > 0);
40  // here is a quick hack to take care of p_MemAddAdjust
41  if (r->NegWeightL_Offset != NULL) return LengthGeneral;
42  if (r->ExpL_Size == 1) return LengthOne;
43  if (r->ExpL_Size == 2) return LengthTwo;
44  if (r->ExpL_Size == 3) return LengthThree;
45  if (r->ExpL_Size == 4) return LengthFour;
46  if (r->ExpL_Size == 5) return LengthFive;
47  if (r->ExpL_Size == 6) return LengthSix;
48  if (r->ExpL_Size == 7) return LengthSeven;
49  if (r->ExpL_Size == 8) return LengthEight;
50  return LengthGeneral;
51 }
52 
53 static inline int p_IsNomog(long* sgn, int l)
54 {
55  int i;
56  for (i=0;i<l;i++)
57  if (sgn[i] > 0) return 0;
58 
59  return 1;
60 }
61 
62 static inline int p_IsPomog(long* sgn, int l)
63 {
64  int i;
65  for (i=0;i<l;i++)
66  if (sgn[i] < 0) return 0;
67  return 1;
68 }
69 
70 static inline p_Ord p_OrdIs(ring r)
71 {
72  long* sgn = r->ordsgn;
73  long l = r->ExpL_Size;
74  int zero = 0;
75 
76  if (sgn[l-1] == 0)
77  {
78  l--;
79  zero = 1;
80  }
81 
82  // we always favour the pomog cases
83  if (p_IsPomog(sgn,l)) return (zero ? OrdPomogZero : OrdPomog);
84  if (p_IsNomog(sgn,l)) return (zero ? OrdNomogZero : OrdNomog);
85 
86  assume(l > 1);
87 
88  if (sgn[0] == -1 && p_IsPomog(&sgn[1], l-1))
89  return (zero ? OrdNegPomogZero : OrdNegPomog);
90  if (sgn[l-1] == -1 && p_IsPomog(sgn, l-1))
91  return (zero ? OrdPomogNegZero : OrdPomogNeg);
92 
93  if (sgn[0] == 1 && p_IsNomog(&sgn[1], l-1))
94  return (zero ? OrdPosNomogZero : OrdPosNomog);
95  if (sgn[l-1] == 1 && p_IsNomog(sgn, l-1))
96  return (zero ? OrdNomogPosZero : OrdNomogPos);
97 
98  assume(l > 2);
99 
100  if (sgn[0] == 1 && sgn[1] == 1 && p_IsNomog(&sgn[2], l-2))
101  return (zero ? OrdPosPosNomogZero : OrdPosPosNomog);
102 
103  if (sgn[0] == 1 && sgn[l-1] == 1 && p_IsNomog(&sgn[1], l-2))
104  return (zero ? OrdPosNomogPosZero : OrdPosNomogPos);
105 
106  if (sgn[0] == -1 && sgn[1] == 1 && p_IsNomog(&sgn[2], l-2))
107  return (zero ? OrdNegPosNomogZero : OrdNegPosNomog);
108 
109  return OrdGeneral;
110 }
111 
112 // fields of this struct are set by DoSetProc
114 
115 #ifdef RDEBUG
116 // if set, then SetProcs sets only names, instead of functions
117 static int set_names = 0;
118 #endif
119 
120 // (which##_Proc_Ptr)F ->-> cast_vptr_to_A<which##_Proc_Ptr>(F)?
121 #define CheckProc(which) \
122 do \
123 { \
124  if (p_Procs->which == NULL) \
125  { \
126  dReportBug("p_Procs is NULL"); \
127  WarnS("Singular will work properly, but much slower"); \
128  WarnS("If you chose a coef ring, it may not work at all");\
129  p_Procs->which = (which##_Proc_Ptr)( \
130  which##__FieldGeneral_LengthGeneral_OrdGeneral); \
131  } \
132 } \
133 while (0);
134 
135 void nc_p_ProcsSet(ring rGR, p_Procs_s* p_Procs);
136 
137 // Choose a set of p_Procs
138 void p_ProcsSet(ring r, p_Procs_s* p_Procs)
139 {
140  p_Field field = p_FieldIs(r);
142  p_Ord ord = p_OrdIs(r);
143 
144  assume(p_Procs != NULL);
145  memset(p_Procs, 0, sizeof(p_Procs_s));
146  _p_procs = p_Procs;
147 
148  SetProcs(field, length, ord);
149  extern poly p_Mult_nn_pthread(poly p, const number n, const ring r);
150  #ifdef NV_OPS
151  if ((field==FieldZp) && (r->cf->ch>NV_MAX_PRIME))
152  {
153  // set all (mult/div.) routines to FieldGeneral-variants
154  SetProcs(FieldGeneral, length,ord); // p_Mult_nn, ...
155  // set all non-mult/div. routines to FieldZp-variants
156  SetProcs_nv(FieldZp, length,ord); // p_Delete, p_ShallowCopyDelete...
157  }
158  if (field==RingGeneral)
159  {
160  if (nCoeff_is_Domain(r->cf))
161  SetProcs_ring(FieldGeneral,length,ord);
162  // FieldGeneral vs. RingGeneral: HAVE_ZERODIVISORS
163  else
164  SetProcs_ring(RingGeneral,length,ord);
165  }
166  #endif
167  CheckProc(p_Copy);
175  CheckProc(pp_Mult_mm_Noether);
177  CheckProc(p_Neg);
179  CheckProc(pp_Mult_Coeff_mm_DivSelectMult);
181  CheckProc(p_kBucketSetLm);
182 
183 /*
184  assume(p_Procs->pp_Mult_mm_Noether != pp_Mult_mm_Noether__FieldGeneral_LengthGeneral_OrdGeneral ||
185  p_Procs->p_Minus_mm_Mult_qq == p_Minus_mm_Mult_qq__FieldGeneral_LengthGeneral_OrdGeneral ||
186  r->OrdSgn == 1 || r->LexOrder);
187 */
188 #ifdef HAVE_PLURAL
189 #ifndef SING_NDEBUG
190  if (rIsPluralRing(r))
191  {
192  dReportError("Setting pProcs in p_ProcsSet (rDebugPrint!?)!!!");
193  nc_p_ProcsSet(r, _p_procs); // Setup non-commutative p_Procs table!
194  }
195 #endif
196 #endif
197 }
198 
199 #ifdef RDEBUG
200 void p_Debug_GetSpecNames(const ring r, const char* &field, const char* &length, const char* &ord)
201 {
202  /*p_Field e_field =*/ (void) p_FieldIs(r);
203  /*p_Length e_length =*/ (void) p_LengthIs(r);
204  /*p_Ord e_ord =*/ (void) p_OrdIs(r);
205 
206  field = p_FieldEnum_2_String(p_FieldIs(r));
207  length = p_LengthEnum_2_String(p_LengthIs(r));
208  ord = p_OrdEnum_2_String(p_OrdIs(r));
209 }
210 
211 void p_Debug_GetProcNames(const ring r, p_Procs_s* p_Procs)
212 {
213  set_names = 1;
214  p_ProcsSet(r, p_Procs); // changes p_Procs!!!
215  set_names = 0;
216 }
217 #endif // RDEBUG
void p_ProcsSet(ring r, p_Procs_s *p_Procs)
Definition: p_Procs_Set.h:138
static int p_IsNomog(long *sgn, int l)
Definition: p_Procs_Set.h:53
static p_Field p_FieldIs(ring r)
Definition: p_Procs_Set.h:20
static int p_IsPomog(long *sgn, int l)
Definition: p_Procs_Set.h:62
static BOOLEAN rField_is_Zp_a(const ring r)
Definition: ring.h:521
int sgn(const Rational &a)
Definition: GMPrat.cc:433
static poly p_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:997
struct p_Procs_s p_Procs_s
Definition: ring.h:30
static BOOLEAN rField_is_R(const ring r)
Definition: ring.h:510
#define SetProcs(field, length, ord)
Definition: p_Procs_Impl.h:662
static int set_names
Definition: p_Procs_Set.h:117
static poly pp_Mult_nn(poly p, number n, const ring r)
Definition: p_polys.h:948
void p_Debug_GetSpecNames(const ring r, const char *&field, const char *&length, const char *&ord)
Definition: p_Procs_Set.h:200
static const char * p_OrdEnum_2_String(p_Ord ord)
Definition: p_Procs_Impl.h:237
static BOOLEAN rField_is_Q_a(const ring r)
Definition: ring.h:531
static poly pp_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:987
#define CheckProc(which)
Definition: p_Procs_Set.h:121
static p_Length p_LengthIs(ring r)
Definition: p_Procs_Set.h:37
static BOOLEAN rField_is_GF(const ring r)
Definition: ring.h:513
static p_Ord p_OrdIs(ring r)
Definition: p_Procs_Set.h:70
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:812
p_Length
Definition: p_Procs_Impl.h:122
#define assume(x)
Definition: mod2.h:390
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition: ring.h:404
p_Field
Definition: p_Procs_Impl.h:106
#define SetProcs_ring(field, length, ord)
Definition: p_Procs_Impl.h:698
All the auxiliary stuff.
static poly p_ShallowCopyDelete(poly p, const ring r, omBin bin)
Definition: p_polys.h:884
int i
Definition: cfEzgcd.cc:125
static poly p_Mult_nn(poly p, number n, const ring r)
Definition: p_polys.h:914
static BOOLEAN rField_is_Q(const ring r)
Definition: ring.h:501
void p_Debug_GetProcNames(const ring r, p_Procs_s *p_Procs)
Definition: p_Procs_Set.h:211
static BOOLEAN rField_is_long_C(const ring r)
Definition: ring.h:537
#define NV_MAX_PRIME
Definition: modulop.h:29
static BOOLEAN rField_is_Zp(const ring r)
Definition: ring.h:495
static const char * p_LengthEnum_2_String(p_Length length)
Definition: p_Procs_Impl.h:219
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:857
p_Ord
Definition: p_Procs_Impl.h:135
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:477
static FORCE_INLINE BOOLEAN nCoeff_is_Domain(const coeffs r)
returns TRUE, if r is a field or r has no zero divisors (i.e is a domain)
Definition: coeffs.h:770
#define NULL
Definition: omList.c:10
static poly p_Merge_q(poly p, poly q, const ring r)
Definition: p_polys.h:1158
static BOOLEAN rField_is_long_R(const ring r)
Definition: ring.h:534
static BOOLEAN length(leftv result, leftv arg)
Definition: interval.cc:267
static p_Procs_s * _p_procs
Definition: p_Procs_Set.h:113
void nc_p_ProcsSet(ring rGR, p_Procs_s *p_Procs)
Definition: old.gring.cc:3204
static poly p_Minus_mm_Mult_qq(poly p, const poly m, const poly q, int &lp, int lq, const poly spNoether, const ring r)
Definition: p_polys.h:1006
int dReportError(const char *fmt,...)
Definition: dError.cc:45
static poly p_Neg(poly p, const ring r)
Definition: p_polys.h:1043
int p
Definition: cfModGcd.cc:4019
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:892
static poly pp_Mult_Coeff_mm_DivSelect(poly p, const poly m, const ring r)
Definition: p_polys.h:1026
int l
Definition: cfEzgcd.cc:93
static const char * p_FieldEnum_2_String(p_Field field)
Definition: p_Procs_Impl.h:198