source: git/kernel/ncSAMult.h @ 03cecc2

spielwiese
Last change on this file since 03cecc2 was 03cecc2, checked in by Motsak Oleksandr <motsak@…>, 16 years ago
*motsak: done: main special casescvs update! git-svn-id: file:///usr/local/Singular/svn/trunk@10895 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 9.2 KB
Line 
1#ifndef GRING_SA_MULT_H
2#define GRING_SA_MULT_H
3/*****************************************
4 *  Computer Algebra System SINGULAR     *
5 *****************************************/
6/* $Id: ncSAMult.h,v 1.7 2008-07-21 00:05:09 motsak Exp $ */
7#ifdef HAVE_PLURAL
8
9// #include <ncSAMult.h> // for CMultiplier etc classes
10
11#include <structs.h>
12#include <ring.h>
13#include <summator.h> // for CPolynomialSummator class
14#include <febase.h> // for Print!
15#include <p_polys.h>
16#include <p_Mult_q.h>
17
18#include <ncSACache.h> // for CCacheHash etc classes
19
20// //////////////////////////////////////////////////////////////////////// //
21//
22
23bool ncInitSpecialPairMultiplication(ring r);
24
25
26template <typename CExponent>
27class CMultiplier
28{
29  protected:
30    ring m_basering;
31    int  m_NVars; // N = number of variables
32
33  public:
34    CMultiplier(ring rBaseRing): m_basering(rBaseRing), m_NVars(rBaseRing->N) {};
35    virtual ~CMultiplier() {};
36
37    const ring GetBasering() const { return m_basering; };
38    inline int NVars() const { return m_NVars; }
39
40
41    inline poly LM(const poly pTerm, const ring r, int i = 1) const
42    {
43      poly pMonom = p_LmInit(pTerm, r);
44      pSetCoeff0(pMonom, n_Init(i, r));
45      return pMonom;
46    }
47
48    // Term * Exponent -> Monom * Exponent
49    inline poly MultiplyTE(const poly pTerm, const CExponent expRight)
50    {
51      const ring r = GetBasering();
52      poly pMonom = LM(pTerm, r);
53     
54      poly result = p_Mult_nn(MultiplyME(pMonom, expRight), p_GetCoeff(pTerm, r), r);
55
56      p_Delete(&pMonom, r);
57
58      return result;
59    }
60   
61
62    // Exponent * Term -> Exponent * Monom
63    inline poly MultiplyET(const CExponent expLeft, const poly pTerm)
64    {
65      const ring r = GetBasering();
66      poly pMonom = LM(pTerm, r);
67
68      poly result = p_Mult_nn(MultiplyEM(expLeft, pMonom), p_GetCoeff(pTerm, r), r);
69
70      p_Delete(&pMonom, r);
71      return result;
72     
73
74    }
75
76    // Main templates:
77
78    // Poly * Exponent
79    inline poly MultiplyPE(const poly pPoly, const CExponent expRight)
80    {
81      bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (pLength(pPoly) < MIN_LENGTH_BUCKET);
82      CPolynomialSummator sum(GetBasering(), bUsePolynomial);
83
84      for( poly q = pPoly; q !=NULL; q = pNext(q) )
85        sum += MultiplyTE(q, expRight); 
86
87      return sum;
88    }
89
90    // Exponent * Poly
91    inline poly MultiplyEP(const CExponent expLeft, const poly pPoly)
92    {
93      bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (pLength(pPoly) < MIN_LENGTH_BUCKET);
94      CPolynomialSummator sum(GetBasering(), bUsePolynomial);
95
96      for( poly q = pPoly; q !=NULL; q = pNext(q) )
97        sum += MultiplyET(expLeft, q); 
98
99      return sum;
100    }
101
102    // Poly * Exponent
103    inline poly MultiplyPEDestroy(poly pPoly, const CExponent expRight)
104    {
105      bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (pLength(pPoly) < MIN_LENGTH_BUCKET);
106      CPolynomialSummator sum(GetBasering(), bUsePolynomial);
107
108      for( ; pPoly!=NULL; pPoly  = p_LmDeleteAndNext(pPoly, GetBasering()) )
109        sum += MultiplyTE(pPoly, expRight); 
110
111      return sum;
112    }
113
114    // Exponent * Poly
115    inline poly MultiplyEPDestroy(const CExponent expLeft, poly pPoly)
116    {
117      bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (pLength(pPoly) < MIN_LENGTH_BUCKET);
118      CPolynomialSummator sum(GetBasering(), bUsePolynomial);
119
120      for( ; pPoly!=NULL; pPoly  = p_LmDeleteAndNext(pPoly, GetBasering()) )
121        sum += MultiplyET(expLeft, pPoly); 
122
123      return sum;
124    }
125
126
127//  protected:
128
129    // Exponent * Exponent
130    virtual poly MultiplyEE(const CExponent expLeft, const CExponent expRight) = 0;   
131
132    // Monom * Exponent
133    virtual poly MultiplyME(const poly pMonom, const CExponent expRight) = 0;
134   
135    // Exponent * Monom
136    virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom) = 0;
137     
138  private: // no copy constuctors!
139    CMultiplier();
140    CMultiplier(const CMultiplier&);
141    CMultiplier& operator=(const CMultiplier&);
142   
143};
144
145
146class CSpecialPairMultiplier: public CMultiplier<int> 
147{
148  private:
149    int m_i;
150    int m_j;
151
152//    poly m_c_ij;
153//    poly m_d_ij;
154   
155   
156  public:
157    // 1 <= i < j <= NVars()
158    CSpecialPairMultiplier(ring r, int i, int j);
159    virtual ~CSpecialPairMultiplier();
160
161    inline int GetI() const { return m_i; } // X
162    inline int GetJ() const { return m_j; } // Y > X!
163
164//  protected:
165    typedef int CExponent;
166
167    // Exponent * Exponent
168    // Computes: var(j)^{expLeft} * var(i)^{expRight}
169    virtual poly MultiplyEE(const CExponent expLeft, const CExponent expRight) = 0;
170
171    // Monom * Exponent
172    // pMonom must be of the form: var(j)^{n}
173    virtual poly MultiplyME(const poly pMonom, const CExponent expRight);
174
175    // Exponent * Monom
176    // pMonom must be of the form: var(i)^{m}
177    virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom);
178
179};
180
181
182
183
184
185struct CPower // represents var(iVar)^{iPower}
186{
187  int Var;
188  int Power;
189
190  CPower(int i, int n): Var(i), Power(n) {};
191
192  inline poly GetPoly(const ring r, int c = 1) const
193  {
194    poly p = p_ISet(c, r);
195    p_SetExp(p, Var, Power, r);
196    p_Setm(p, r);
197    return p;
198  };
199 
200};
201
202
203
204
205
206
207class CPowerMultiplier: public CMultiplier<CPower>
208{
209  private:
210    CSpecialPairMultiplier** m_specialpairs; // upper triangular submatrix of pairs 1 <= i < j <= N of a N x N matrix.
211
212
213  public:
214    CPowerMultiplier(ring r);
215    virtual ~CPowerMultiplier();
216
217    inline CSpecialPairMultiplier* GetPair(int i, int j) const
218    {
219      assume( m_specialpairs != NULL );
220      assume( i > 0 );
221      assume( i < j );
222      assume( j <= NVars() );
223
224      return m_specialpairs[( (NVars() * ((i)-1) - ((i) * ((i)-1))/2 + (j)-1) - (i) )];
225    }
226
227    inline CSpecialPairMultiplier*& GetPair(int i, int j)
228    {
229      assume( m_specialpairs != NULL );
230      assume( i > 0 );
231      assume( i < j );
232      assume( j <= NVars() );
233
234      return m_specialpairs[( (NVars() * ((i)-1) - ((i) * ((i)-1))/2 + (j)-1) - (i) )];
235    }
236   
237//  protected:
238    typedef CPower CExponent;
239
240    // Exponent * Exponent
241    // Computes: var(j)^{expLeft} * var(i)^{expRight}
242    virtual poly MultiplyEE(const CExponent expLeft, const CExponent expRight);
243
244    // Monom * Exponent
245    // pMonom may NOT be of the form: var(j)^{n}!
246    virtual poly MultiplyME(const poly pMonom, const CExponent expRight);
247
248    // Exponent * Monom
249    // pMonom may NOT be of the form: var(i)^{m}!
250    virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom);
251
252
253};
254
255
256
257
258class CGlobalMultiplier: public CMultiplier<poly>
259{
260  private:
261    CGlobalCacheHash* m_cache;
262    CPowerMultiplier* m_powers;
263
264  public:
265    typedef CMultiplier<poly> CBaseType;
266   
267    CGlobalMultiplier(ring r);
268    virtual ~CGlobalMultiplier();
269
270   
271 
272//  protected:   
273    typedef poly CExponent;
274
275    // the following methods are literally equal!
276   
277    // Exponent * Exponent
278    // TODO: handle components!!!
279    virtual poly MultiplyEE(const CExponent expLeft, const CExponent expRight);   
280
281    // Monom * Exponent
282    virtual poly MultiplyME(const poly pMonom, const CExponent expRight);
283
284    // Exponent * Monom
285    virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom);
286
287};
288
289
290
291//////////////////////////////////////////////////////////////////////////
292class CCommutativeSpecialPairMultiplier: public CSpecialPairMultiplier
293{
294        public:
295                CCommutativeSpecialPairMultiplier(ring r, int i, int j);
296                virtual ~CCommutativeSpecialPairMultiplier();
297
298                // Exponent * Exponent
299                virtual poly MultiplyEE(const int expLeft, const int expRight);   
300};
301
302//////////////////////////////////////////////////////////////////////////
303class CAntiCommutativeSpecialPairMultiplier: public CSpecialPairMultiplier
304{
305        public:
306                CAntiCommutativeSpecialPairMultiplier(ring r, int i, int j);
307                virtual ~CAntiCommutativeSpecialPairMultiplier();
308
309                // Exponent * Exponent
310                virtual poly MultiplyEE(const int expLeft, const int expRight);   
311};
312
313
314//////////////////////////////////////////////////////////////////////////
315class CQuasiCommutativeSpecialPairMultiplier: public CSpecialPairMultiplier
316{
317        private:
318                const number m_q;
319                // TODO: make cache for some 'good' powers!?
320
321  public:
322                CQuasiCommutativeSpecialPairMultiplier(ring r, int i, int j, number q);
323                virtual ~CQuasiCommutativeSpecialPairMultiplier();
324
325                number GetPower(int power);
326
327                // Exponent * Exponent
328                virtual poly MultiplyEE(const int expLeft, const int expRight);   
329};
330
331
332//////////////////////////////////////////////////////////////////////////
333class CWeylSpecialPairMultiplier: public CSpecialPairMultiplier
334{
335  private:
336    const number m_g;
337    // TODO: make cache for some 'good' powers!?
338
339  public:
340    CWeylSpecialPairMultiplier(ring r, int i, int j, number g);
341    virtual ~CWeylSpecialPairMultiplier();
342
343    // Exponent * Exponent
344    virtual poly MultiplyEE(const int expLeft, const int expRight);   
345};
346
347
348//////////////////////////////////////////////////////////////////////////
349class CShiftSpecialPairMultiplier: public CSpecialPairMultiplier
350{
351  private:   
352    const number m_shiftCoef;
353    const int m_shiftVar;
354    // TODO: make cache for some 'good' powers!?
355
356  public:
357    CShiftSpecialPairMultiplier(ring r, int i, int j, int s, number c);
358    virtual ~CShiftSpecialPairMultiplier();
359
360    // Exponent * Exponent
361    virtual poly MultiplyEE(const int expLeft, const int expRight);   
362};
363
364
365#endif // HAVE_PLURAL :(
366#endif //
Note: See TracBrowser for help on using the repository browser.