source: git/kernel/ncSAMult.h @ 9e8da7

spielwiese
Last change on this file since 9e8da7 was 599326, checked in by Kai Krüger <krueger@…>, 14 years ago
Anne, Kai, Frank: - changes to #include "..." statements to allow cleaner build structure - affected directories: omalloc, kernel, Singular - not yet done: IntergerProgramming git-svn-id: file:///usr/local/Singular/svn/trunk@13032 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 16.4 KB
Line 
1#ifndef GRING_SA_MULT_H
2#define GRING_SA_MULT_H
3/*****************************************
4 *  Computer Algebra System SINGULAR     *
5 *****************************************/
6/* $Id$ */
7#ifdef HAVE_PLURAL
8
9// #include <ncSAMult.h> // for CMultiplier etc classes
10
11#include <kernel/options.h>
12#include <kernel/ring.h>
13#include <kernel/summator.h> // for CPolynomialSummator class
14#include <kernel/febase.h> // for Print!
15#include <kernel/p_polys.h>
16#include <kernel/p_Mult_q.h>
17
18#include <kernel/ncSACache.h> // for CCacheHash etc classes
19#include <kernel/ncSAFormula.h> // for CFormulaPowerMultiplier and enum Enum_ncSAType
20
21// //////////////////////////////////////////////////////////////////////// //
22//
23
24bool ncInitSpecialPairMultiplication(ring r);
25
26
27template <typename CExponent>
28class CMultiplier
29{
30  protected:
31    ring m_basering;
32    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    const 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));
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&);
91    CMultiplier& operator=(const CMultiplier&);
92   
93};
94
95
96class CSpecialPairMultiplier: public CMultiplier<int> 
97{
98  private:
99    int m_i;
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
135struct 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
166class 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
266class CGlobalMultiplier: public CMultiplier<poly>
267{
268  private:
269    CGlobalCacheHash* m_cache;
270    CPowerMultiplier* m_powers;
271    const CFormulaPowerMultiplier* m_RingFormulaMultiplier;
272
273  public:
274    typedef CMultiplier<poly> CBaseType;
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//////////////////////////////////////////////////////////////////////////
503class CCommutativeSpecialPairMultiplier: public CSpecialPairMultiplier
504{
505        public:
506                CCommutativeSpecialPairMultiplier(ring r, int i, int j);
507                virtual ~CCommutativeSpecialPairMultiplier();
508
509                // Exponent * Exponent
510                virtual poly MultiplyEE(const int expLeft, const int expRight);   
511};
512
513//////////////////////////////////////////////////////////////////////////
514class CAntiCommutativeSpecialPairMultiplier: public CSpecialPairMultiplier
515{
516        public:
517                CAntiCommutativeSpecialPairMultiplier(ring r, int i, int j);
518                virtual ~CAntiCommutativeSpecialPairMultiplier();
519
520                // Exponent * Exponent
521                virtual poly MultiplyEE(const int expLeft, const int expRight);   
522};
523
524
525//////////////////////////////////////////////////////////////////////////
526class CQuasiCommutativeSpecialPairMultiplier: public CSpecialPairMultiplier
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);
534                virtual ~CQuasiCommutativeSpecialPairMultiplier();
535
536                // Exponent * Exponent
537                virtual poly MultiplyEE(const int expLeft, const int expRight);   
538};
539
540
541//////////////////////////////////////////////////////////////////////////
542class CWeylSpecialPairMultiplier: public CSpecialPairMultiplier
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
557//////////////////////////////////////////////////////////////////////////
558class CShiftSpecialPairMultiplier: public CSpecialPairMultiplier
559{
560  private:   
561    const number m_shiftCoef;
562    const int m_shiftVar;
563    // TODO: make cache for some 'good' powers!?
564
565  public:
566    CShiftSpecialPairMultiplier(ring r, int i, int j, int s, number c);
567    virtual ~CShiftSpecialPairMultiplier();
568
569    // Exponent * Exponent
570    virtual poly MultiplyEE(const int expLeft, const int expRight);   
571};
572
573
574
575// need: enum Enum_ncSAType;
576
577//////////////////////////////////////////////////////////////////////////
578// Using external 'formula' routins
579class CExternalSpecialPairMultiplier: public CSpecialPairMultiplier
580{
581  private:
582    Enum_ncSAType m_ncSAtype;
583  public:
584    CExternalSpecialPairMultiplier(ring r, int i, int j, Enum_ncSAType type);
585    virtual ~CExternalSpecialPairMultiplier();
586
587    // Exponent * Exponent
588    virtual poly MultiplyEE(const int expLeft, const int expRight);   
589};
590
591
592#endif // HAVE_PLURAL :(
593#endif //
Note: See TracBrowser for help on using the repository browser.