ncSAMult.h
Go to the documentation of this file.
1 #ifndef GRING_SA_MULT_H
2 #define GRING_SA_MULT_H
3 /*****************************************
4  * Computer Algebra System SINGULAR *
5  *****************************************/
6 
7 #ifdef HAVE_PLURAL
8 
9 // #include <ncSAMult.h> // for CMultiplier etc classes
10 
11 #include <misc/options.h>
12 #include <polys/monomials/ring.h>
13 #include <polys/nc/summator.h>// for CPolynomialSummator class
14 #include <reporter/reporter.h> // for Print!
17 
18 //#include <polys/nc/ncSACache.h> // for CCacheHash etc classes
19 #include <polys/nc/ncSAFormula.h> // for CFormulaPowerMultiplier and enum Enum_ncSAType
20 
21 // //////////////////////////////////////////////////////////////////////// //
22 //
23 
25 
26 
27 template <typename CExponent>
29 {
30  protected:
31  const ring m_basering;
32  const int m_NVars; // N = number of variables
33 
34  public:
35  CMultiplier(ring rBaseRing): m_basering(rBaseRing), m_NVars(rBaseRing->N) {};
36  virtual ~CMultiplier() {};
37 
38  inline ring GetBasering() const { return m_basering; };
39  inline int NVars() const { return m_NVars; }
40 
41 
42  inline poly LM(const poly pTerm, const ring r, int i = 1) const
43  {
44  poly pMonom = p_LmInit(pTerm, r);
45  pSetCoeff0(pMonom, n_Init(i, r->cf));
46  return pMonom;
47  }
48 
49  // Term * Exponent -> Monom * Exponent
50  inline poly MultiplyTE(const poly pTerm, const CExponent expRight)
51  {
52  const ring r = GetBasering();
53  poly pMonom = LM(pTerm, r);
54 
55  poly result = p_Mult_nn(MultiplyME(pMonom, expRight), p_GetCoeff(pTerm, r), r);
56 
57  p_Delete(&pMonom, r);
58 
59  return result;
60  }
61 
62 
63  // Exponent * Term -> Exponent * Monom
64  inline poly MultiplyET(const CExponent expLeft, const poly pTerm)
65  {
66  const ring r = GetBasering();
67  poly pMonom = LM(pTerm, r);
68 
69  poly result = p_Mult_nn(MultiplyEM(expLeft, pMonom), p_GetCoeff(pTerm, r), r);
70 
71  p_Delete(&pMonom, r);
72  return result;
73 
74 
75  }
76 
77 // protected:
78 
79  // Exponent * Exponent
80  virtual poly MultiplyEE(const CExponent expLeft, const CExponent expRight) = 0;
81 
82  // Monom * Exponent
83  virtual poly MultiplyME(const poly pMonom, const CExponent expRight) = 0;
84 
85  // Exponent * Monom
86  virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom) = 0;
87 
88  private: // no copy constuctors!
89  CMultiplier();
90  CMultiplier(const CMultiplier&);
92 
93 };
94 
95 
97 {
98  private:
99  int m_i; // 2-gen subalgebra in these variables...
100  int m_j;
101 
102 // poly m_c_ij;
103 // poly m_d_ij;
104 
105 
106  public:
107  // 1 <= i < j <= NVars()
108  CSpecialPairMultiplier(ring r, int i, int j);
109  virtual ~CSpecialPairMultiplier();
110 
111  inline int GetI() const { return m_i; } // X
112  inline int GetJ() const { return m_j; } // Y > X!
113 
114 // protected:
115  typedef int CExponent;
116 
117  // Exponent * Exponent
118  // Computes: var(j)^{expLeft} * var(i)^{expRight}
119  virtual poly MultiplyEE(const CExponent expLeft, const CExponent expRight) = 0;
120 
121  // Monom * Exponent
122  // pMonom must be of the form: var(j)^{n}
123  virtual poly MultiplyME(const poly pMonom, const CExponent expRight);
124 
125  // Exponent * Monom
126  // pMonom must be of the form: var(i)^{m}
127  virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom);
128 
129 };
130 
131 
132 
133 
134 
135 struct CPower // represents var(iVar)^{iPower}
136 {
137  int Var;
138  int Power;
139 
140  CPower(int i, int n): Var(i), Power(n) {};
141 
142 /*
143  inline poly GetPoly(const ring r) const // TODO: search for GetPoly(r, 1) and remove "1"!
144  {
145  poly p = p_One(r);
146  p_SetExp(p, Var, Power, r);
147  p_Setm(p, r);
148  return p;
149  };
150  inline poly GetPoly(const ring r, int c) const
151  {
152  poly p = p_ISet(c, r);
153  p_SetExp(p, Var, Power, r);
154  p_Setm(p, r);
155  return p;
156  };
157 */
158 
159 };
160 
161 
162 
163 
164 
165 
166 class CPowerMultiplier: public CMultiplier<CPower>
167 {
168  private:
169  CSpecialPairMultiplier** m_specialpairs; // upper triangular submatrix of pairs 1 <= i < j <= N of a N x N matrix.
170 
171 
172  public:
173  CPowerMultiplier(ring r);
174  virtual ~CPowerMultiplier();
175 
176  inline CSpecialPairMultiplier* GetPair(int i, int j) const
177  {
178  assume( m_specialpairs != NULL );
179  assume( i > 0 );
180  assume( i < j );
181  assume( j <= NVars() );
182 
183  return m_specialpairs[( (NVars() * ((i)-1) - ((i) * ((i)-1))/2 + (j)-1) - (i) )];
184  }
185 
186  inline CSpecialPairMultiplier*& GetPair(int i, int j)
187  {
188  assume( m_specialpairs != NULL );
189  assume( i > 0 );
190  assume( i < j );
191  assume( j <= NVars() );
192 
193  return m_specialpairs[( (NVars() * ((i)-1) - ((i) * ((i)-1))/2 + (j)-1) - (i) )];
194  }
195 
196 // protected:
197  typedef CPower CExponent;
198 
199  // Exponent * Exponent
200  // Computes: var(j)^{expLeft} * var(i)^{expRight}
201  virtual poly MultiplyEE(const CExponent expLeft, const CExponent expRight);
202 
203  // Monom * Exponent
204  // pMonom may NOT be of the form: var(j)^{n}!
205  virtual poly MultiplyME(const poly pMonom, const CExponent expRight);
206 
207  // Exponent * Monom
208  // pMonom may NOT be of the form: var(i)^{m}!
209  virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom);
210 
211  // Main templates:
212 
213  // Poly * Exponent
214  inline poly MultiplyPE(const poly pPoly, const CExponent expRight)
215  {
216  bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (pLength(pPoly) < MIN_LENGTH_BUCKET);
217  CPolynomialSummator sum(GetBasering(), bUsePolynomial);
218 
219  for( poly q = pPoly; q !=NULL; q = pNext(q) )
220  sum += MultiplyTE(q, expRight);
221 
222  return sum;
223  }
224 
225  // Exponent * Poly
226  inline poly MultiplyEP(const CExponent expLeft, const poly pPoly)
227  {
228  bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (pLength(pPoly) < MIN_LENGTH_BUCKET);
229  CPolynomialSummator sum(GetBasering(), bUsePolynomial);
230 
231  for( poly q = pPoly; q !=NULL; q = pNext(q) )
232  sum += MultiplyET(expLeft, q);
233 
234  return sum;
235  }
236 
237  // Poly * Exponent
238  inline poly MultiplyPEDestroy(poly pPoly, const CExponent expRight)
239  {
240  bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (pLength(pPoly) < MIN_LENGTH_BUCKET);
241  CPolynomialSummator sum(GetBasering(), bUsePolynomial);
242 
243  for( ; pPoly!=NULL; pPoly = p_LmDeleteAndNext(pPoly, GetBasering()) )
244  sum += MultiplyTE(pPoly, expRight);
245 
246  return sum;
247  }
248 
249  // Exponent * Poly
250  inline poly MultiplyEPDestroy(const CExponent expLeft, poly pPoly)
251  {
252  bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (pLength(pPoly) < MIN_LENGTH_BUCKET);
253  CPolynomialSummator sum(GetBasering(), bUsePolynomial);
254 
255  for( ; pPoly!=NULL; pPoly = p_LmDeleteAndNext(pPoly, GetBasering()) )
256  sum += MultiplyET(expLeft, pPoly);
257 
258  return sum;
259  }
260 
261 
262 };
263 
264 
265 
266 class CGlobalMultiplier: public CMultiplier<poly>
267 {
268  private:
269 // CGlobalCacheHash* m_cache;
272 
273  public:
275 
276  CGlobalMultiplier(ring r);
277  virtual ~CGlobalMultiplier();
278 
279 
280 // protected:
281  typedef poly CExponent;
282 
283  // the following methods are literally equal!
284 
285  // Exponent * Exponent
286  // TODO: handle components!!!
287  virtual poly MultiplyEE(const CExponent expLeft, const CExponent expRight);
288 
289  // Monom * Exponent
290  virtual poly MultiplyME(const poly pMonom, const CExponent expRight);
291 
292  // Exponent * Monom
293  virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom);
294 
295 
296  // Main templates:
297 
298  // Poly * Exponent
299  inline poly MultiplyPE(const poly pPoly, const CExponent expRight)
300  {
301  assume( pPoly != NULL ); assume( expRight != NULL );
302  const int iComponentMonom = p_GetComp(expRight, GetBasering());
303 
304  bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (pLength(pPoly) < MIN_LENGTH_BUCKET);
305  CPolynomialSummator sum(GetBasering(), bUsePolynomial);
306 
307 
308  if( iComponentMonom!=0 )
309  {
310  for( poly q = pPoly; q !=NULL; q = pNext(q) )
311  {
312 #ifdef PDEBUG
313  {
314  const int iComponent = p_GetComp(q, GetBasering());
315  assume(iComponent == 0);
316  if( iComponent!=0 )
317  {
318  Werror("MultiplyPE: both sides have non-zero components: %d and %d!\n", iComponent, iComponentMonom);
319  // what should we do further?!?
320  return NULL;
321  }
322 
323  }
324 #endif
325  sum += MultiplyTE(q, expRight); // NO Component!!!
326  }
327  poly t = sum; p_SetCompP(t, iComponentMonom, GetBasering());
328  return t;
329  } // iComponentMonom != 0!
330  else
331  { // iComponentMonom == 0!
332  for( poly q = pPoly; q !=NULL; q = pNext(q) )
333  {
334  const int iComponent = p_GetComp(q, GetBasering());
335 
336 #ifdef PDEBUG
337  if( iComponent!=0 )
338  {
339  Warn("MultiplyPE: Multiplication in the left module from the right by component %d!\n", iComponent);
340  // what should we do further?!?
341  }
342 #endif
343  poly t = MultiplyTE(q, expRight); // NO Component!!!
344  p_SetCompP(t, iComponent, GetBasering());
345  sum += t;
346  }
347  return sum;
348  } // iComponentMonom == 0!
349  }
350 
351  // Exponent * Poly
352  inline poly MultiplyEP(const CExponent expLeft, const poly pPoly)
353  {
354  assume( pPoly != NULL ); assume( expLeft != NULL );
355  const int iComponentMonom = p_GetComp(expLeft, GetBasering());
356 
357  bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (pLength(pPoly) < MIN_LENGTH_BUCKET);
358  CPolynomialSummator sum(GetBasering(), bUsePolynomial);
359 
360  if( iComponentMonom!=0 )
361  {
362  for( poly q = pPoly; q !=NULL; q = pNext(q) )
363  {
364 #ifdef PDEBUG
365  {
366  const int iComponent = p_GetComp(q, GetBasering());
367  assume(iComponent == 0);
368  if( iComponent!=0 )
369  {
370  Werror("MultiplyEP: both sides have non-zero components: %d and %d!\n", iComponent, iComponentMonom);
371  // what should we do further?!?
372  return NULL;
373  }
374  }
375 #endif
376  sum += MultiplyET(expLeft, q);
377  }
378  poly t = sum; p_SetCompP(t, iComponentMonom, GetBasering());
379  return t;
380  } // iComponentMonom != 0!
381  else
382  { // iComponentMonom == 0!
383  for( poly q = pPoly; q !=NULL; q = pNext(q) )
384  {
385  const int iComponent = p_GetComp(q, GetBasering());
386 
387  poly t = MultiplyET(expLeft, q); // NO Component!!!
388  p_SetCompP(t, iComponent, GetBasering());
389  sum += t;
390  }
391  return sum;
392  } // iComponentMonom == 0!
393  }
394 
395  // Poly * Exponent
396  inline poly MultiplyPEDestroy(poly pPoly, const CExponent expRight)
397  {
398  assume( pPoly != NULL ); assume( expRight != NULL );
399  const int iComponentMonom = p_GetComp(expRight, GetBasering());
400 
401  bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (pLength(pPoly) < MIN_LENGTH_BUCKET);
402  CPolynomialSummator sum(GetBasering(), bUsePolynomial);
403 
404 
405  if( iComponentMonom!=0 )
406  {
407  for(poly q = pPoly ; q!=NULL; q = p_LmDeleteAndNext(q, GetBasering()) )
408  {
409 #ifdef PDEBUG
410  {
411  const int iComponent = p_GetComp(q, GetBasering());
412  assume(iComponent == 0);
413  if( iComponent!=0 )
414  {
415  Werror("MultiplyPEDestroy: both sides have non-zero components: %d and %d!\n", iComponent, iComponentMonom);
416  // what should we do further?!?
417  return NULL;
418  }
419 
420  }
421 #endif
422  sum += MultiplyTE(q, expRight); // NO Component!!!
423  }
424  poly t = sum; p_SetCompP(t, iComponentMonom, GetBasering());
425  return t;
426  } // iComponentMonom != 0!
427  else
428  { // iComponentMonom == 0!
429  for(poly q = pPoly ; q!=NULL; q = p_LmDeleteAndNext(q, GetBasering()) )
430  {
431  const int iComponent = p_GetComp(q, GetBasering());
432 
433 #ifdef PDEBUG
434  if( iComponent!=0 )
435  {
436  Warn("MultiplyPEDestroy: Multiplication in the left module from the right by component %d!\n", iComponent);
437  // what should we do further?!?
438  }
439 #endif
440  poly t = MultiplyTE(q, expRight); // NO Component!!!
441  p_SetCompP(t, iComponent, GetBasering());
442  sum += t;
443  }
444  return sum;
445  } // iComponentMonom == 0!
446 
447  }
448 
449  // Exponent * Poly
450  inline poly MultiplyEPDestroy(const CExponent expLeft, poly pPoly)
451  {
452 
453  assume( pPoly != NULL ); assume( expLeft != NULL );
454  const int iComponentMonom = p_GetComp(expLeft, GetBasering());
455 
456  bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (pLength(pPoly) < MIN_LENGTH_BUCKET);
457  CPolynomialSummator sum(GetBasering(), bUsePolynomial);
458 
459  if( iComponentMonom!=0 )
460  {
461  for(poly q = pPoly ; q!=NULL; q = p_LmDeleteAndNext(q, GetBasering()) )
462  {
463 #ifdef PDEBUG
464  {
465  const int iComponent = p_GetComp(q, GetBasering());
466  assume(iComponent == 0);
467  if( iComponent!=0 )
468  {
469  Werror("MultiplyEPDestroy: both sides have non-zero components: %d and %d!\n", iComponent, iComponentMonom);
470  // what should we do further?!?
471  return NULL;
472  }
473  }
474 #endif
475  sum += MultiplyET(expLeft, q);
476  }
477  poly t = sum; p_SetCompP(t, iComponentMonom, GetBasering());
478  return t;
479  } // iComponentMonom != 0!
480  else
481  { // iComponentMonom == 0!
482  for(poly q = pPoly ; q!=NULL; q = p_LmDeleteAndNext(q, GetBasering()) )
483  {
484  const int iComponent = p_GetComp(q, GetBasering());
485 
486  poly t = MultiplyET(expLeft, q); // NO Component!!!
487  p_SetCompP(t, iComponent, GetBasering());
488  sum += t;
489  }
490  return sum;
491  } // iComponentMonom == 0!
492 
493  }
494 
495 
496 
497 
498 };
499 
500 
501 
502 //////////////////////////////////////////////////////////////////////////
504 {
505  public:
506  CCommutativeSpecialPairMultiplier(ring r, int i, int j);
508 
509  // Exponent * Exponent
510  virtual poly MultiplyEE(const int expLeft, const int expRight);
511 };
512 
513 //////////////////////////////////////////////////////////////////////////
515 {
516  public:
517  CAntiCommutativeSpecialPairMultiplier(ring r, int i, int j);
519 
520  // Exponent * Exponent
521  virtual poly MultiplyEE(const int expLeft, const int expRight);
522 };
523 
524 
525 //////////////////////////////////////////////////////////////////////////
527 {
528  private:
529  const number m_q;
530  // TODO: make cache for some 'good' powers!?
531 
532  public:
533  CQuasiCommutativeSpecialPairMultiplier(ring r, int i, int j, number q);
535 
536  // Exponent * Exponent
537  virtual poly MultiplyEE(const int expLeft, const int expRight);
538 };
539 
540 
541 //////////////////////////////////////////////////////////////////////////
543 {
544  private:
545  const number m_g;
546  // TODO: make cache for some 'good' powers!?
547 
548  public:
549  CWeylSpecialPairMultiplier(ring r, int i, int j, number g);
550  virtual ~CWeylSpecialPairMultiplier();
551 
552  // Exponent * Exponent
553  virtual poly MultiplyEE(const int expLeft, const int expRight);
554 };
555 
556 //////////////////////////////////////////////////////////////////////////
558 {
559  private:
560  const int m_k;
561  // TODO: make cache for some 'good' powers!?
562 
563  public:
564  CHWeylSpecialPairMultiplier(ring r, int i, int j, int k);
565  virtual ~CHWeylSpecialPairMultiplier();
566 
567  // Exponent * Exponent
568  virtual poly MultiplyEE(const int expLeft, const int expRight);
569 };
570 
571 
572 //////////////////////////////////////////////////////////////////////////
574 {
575  private:
576  const number m_shiftCoef;
577  const int m_shiftVar;
578  // TODO: make cache for some 'good' powers!?
579 
580  public:
581  CShiftSpecialPairMultiplier(ring r, int i, int j, int s, number c);
582  virtual ~CShiftSpecialPairMultiplier();
583 
584  // Exponent * Exponent
585  virtual poly MultiplyEE(const int expLeft, const int expRight);
586 };
587 
588 
589 
590 // need: enum Enum_ncSAType;
591 
592 //////////////////////////////////////////////////////////////////////////
593 // Using external 'formula' routins
595 {
596  private:
598  public:
599  CExternalSpecialPairMultiplier(ring r, int i, int j, Enum_ncSAType type);
601 
602  // Exponent * Exponent
603  virtual poly MultiplyEE(const int expLeft, const int expRight);
604 };
605 
606 
607 #endif // HAVE_PLURAL :(
608 #endif //
ring GetBasering() const
Definition: ncSAMult.h:38
const CanonicalForm int s
Definition: facAbsFact.cc:55
virtual poly MultiplyME(const poly pMonom, const CExponent expRight)=0
static poly p_LmDeleteAndNext(poly p, const ring r)
Definition: p_polys.h:720
virtual ~CMultiplier()
Definition: ncSAMult.h:36
poly MultiplyTE(const poly pTerm, const CExponent expRight)
Definition: ncSAMult.h:50
CSpecialPairMultiplier ** m_specialpairs
Definition: ncSAMult.h:169
poly LM(const poly pTerm, const ring r, int i=1) const
Definition: ncSAMult.h:42
int GetI() const
Definition: ncSAMult.h:111
#define p_GetComp(p, r)
Definition: monomials.h:72
virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom)=0
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:542
poly MultiplyEPDestroy(const CExponent expLeft, poly pPoly)
Definition: ncSAMult.h:450
#define MIN_LENGTH_BUCKET
Definition: p_Mult_q.h:22
const CFormulaPowerMultiplier * m_RingFormulaMultiplier
Definition: ncSAMult.h:271
CPower(int i, int n)
Definition: ncSAMult.h:140
int Var
Definition: ncSAMult.h:137
poly MultiplyPEDestroy(poly pPoly, const CExponent expRight)
Definition: ncSAMult.h:238
virtual poly MultiplyEE(const CExponent expLeft, const CExponent expRight)=0
g
Definition: cfModGcd.cc:4031
int k
Definition: cfEzgcd.cc:93
int Power
Definition: ncSAMult.h:138
CPower CExponent
Definition: ncSAMult.h:197
const int m_NVars
Definition: ncSAMult.h:32
CSpecialPairMultiplier *& GetPair(int i, int j)
Definition: ncSAMult.h:186
CMultiplier< poly > CBaseType
Definition: ncSAMult.h:274
#define TEST_OPT_NOT_BUCKETS
Definition: options.h:100
CPowerMultiplier * m_powers
Definition: ncSAMult.h:270
poly MultiplyPE(const poly pPoly, const CExponent expRight)
Definition: ncSAMult.h:214
int GetJ() const
Definition: ncSAMult.h:112
const ring r
Definition: syzextra.cc:208
poly MultiplyEP(const CExponent expLeft, const poly pPoly)
Definition: ncSAMult.h:226
poly MultiplyPEDestroy(poly pPoly, const CExponent expRight)
Definition: ncSAMult.h:396
static void p_SetCompP(poly p, int i, ring r)
Definition: p_polys.h:249
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
int j
Definition: myNF.cc:70
#define assume(x)
Definition: mod2.h:403
CMultiplier & operator=(const CMultiplier &)
poly MultiplyEP(const CExponent expLeft, const poly pPoly)
Definition: ncSAMult.h:352
int NVars() const
Definition: ncSAMult.h:39
int i
Definition: cfEzgcd.cc:123
static poly p_Mult_nn(poly p, number n, const ring r)
Definition: p_polys.h:895
static unsigned pLength(poly a)
Definition: p_polys.h:189
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:843
const number m_shiftCoef
Definition: ncSAMult.h:576
#define NULL
Definition: omList.c:10
const ring m_basering
Definition: ncSAMult.h:31
CSpecialPairMultiplier * GetPair(int i, int j) const
Definition: ncSAMult.h:176
#define pNext(p)
Definition: monomials.h:43
static poly p_LmInit(poly p, const ring r)
Definition: p_polys.h:1258
#define pSetCoeff0(p, n)
Definition: monomials.h:67
#define p_GetCoeff(p, r)
Definition: monomials.h:57
poly MultiplyET(const CExponent expLeft, const poly pTerm)
Definition: ncSAMult.h:64
poly MultiplyEPDestroy(const CExponent expLeft, poly pPoly)
Definition: ncSAMult.h:250
BOOLEAN ncInitSpecialPairMultiplication(ring r)
Definition: ncSAMult.cc:266
poly MultiplyPE(const poly pPoly, const CExponent expRight)
Definition: ncSAMult.h:299
CMultiplier(ring rBaseRing)
Definition: ncSAMult.h:35
CPolynomialSummator: unifies bucket and polynomial summation as the later is brocken in buckets :(...
Definition: summator.h:29
polyrec * poly
Definition: hilb.h:10
int BOOLEAN
Definition: auxiliary.h:86
void Werror(const char *fmt,...)
Definition: reporter.cc:189
return result
Definition: facAbsBiFact.cc:76
Enum_ncSAType
Definition: ncSAFormula.h:17
#define Warn
Definition: emacs.cc:80