source: git/kernel/ncSAMult.h @ 1495df4

spielwiese
Last change on this file since 1495df4 was 1495df4, checked in by Motsak Oleksandr <motsak@…>, 15 years ago
*motsak: special multiplication git-svn-id: file:///usr/local/Singular/svn/trunk@10868 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 7.1 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.4 2008-07-15 16:27:58 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
42    // Term * Exponent -> Monom * Exponent
43    inline poly MultiplyTE(const poly pTerm, const CExponent expRight)
44    { return p_Mult_nn(MultiplyME(pTerm, expRight), p_GetCoeff(pTerm, GetBasering()), GetBasering()); }
45
46    // Exponent * Term -> Exponent * Monom
47    inline poly MultiplyET(const CExponent expLeft, const poly pTerm)
48    { return p_Mult_nn(MultiplyEM(expLeft, pTerm), p_GetCoeff(pTerm, GetBasering()), GetBasering()); }
49
50    // Main templates:
51
52    // Poly * Exponent
53    inline poly MultiplyPE(const poly pPoly, const CExponent expRight)
54    {
55      bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (pLength(pPoly) < MIN_LENGTH_BUCKET);
56      CPolynomialSummator sum(GetBasering(), bUsePolynomial);
57
58      for( poly q = pPoly; q !=NULL; q = pNext(q) )
59        sum += MultiplyTE(q, expRight); 
60
61      return sum;
62    }
63
64    // Exponent * Poly
65    inline poly MultiplyEP(const CExponent expLeft, const poly pPoly)
66    {
67      bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (pLength(pPoly) < MIN_LENGTH_BUCKET);
68      CPolynomialSummator sum(GetBasering(), bUsePolynomial);
69
70      for( poly q = pPoly; q !=NULL; q = pNext(q) )
71        sum += MultiplyET(expLeft, q); 
72
73      return sum;
74    }
75
76    // Poly * Exponent
77    inline poly MultiplyPEDestroy(poly pPoly, const CExponent expRight)
78    {
79      bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (pLength(pPoly) < MIN_LENGTH_BUCKET);
80      CPolynomialSummator sum(GetBasering(), bUsePolynomial);
81
82      for( ; pPoly!=NULL; pPoly  = p_LmDeleteAndNext(pPoly, GetBasering()) )
83        sum += MultiplyTE(pPoly, expRight); 
84
85      return sum;
86    }
87
88    // Exponent * Poly
89    inline poly MultiplyEPDestroy(const CExponent expLeft, poly pPoly)
90    {
91      bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (pLength(pPoly) < MIN_LENGTH_BUCKET);
92      CPolynomialSummator sum(GetBasering(), bUsePolynomial);
93
94      for( ; pPoly!=NULL; pPoly  = p_LmDeleteAndNext(pPoly, GetBasering()) )
95        sum += MultiplyET(expLeft, pPoly); 
96
97      return sum;
98    }
99
100
101//  protected:
102
103    // Exponent * Exponent
104    virtual poly MultiplyEE(const CExponent expLeft, const CExponent expRight) = 0;   
105
106    // Monom * Exponent
107    virtual poly MultiplyME(const poly pMonom, const CExponent expRight) = 0;
108   
109    // Exponent * Monom
110    virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom) = 0;
111     
112  private: // no copy constuctors!
113    CMultiplier();
114    CMultiplier(const CMultiplier&);
115    CMultiplier& operator=(const CMultiplier&);
116   
117};
118
119
120class CSpecialPairMultiplier: public CMultiplier<int> 
121{
122  private:
123    int m_i;
124    int m_j;
125
126    poly m_c_ij;
127    poly m_d_ij;
128   
129   
130  public:
131    // 1 <= i < j <= NVars()
132    CSpecialPairMultiplier(ring r, int i, int j);
133    virtual ~CSpecialPairMultiplier(){}
134
135    inline int GetI() const { return m_i; }
136    inline int GetJ() const { return m_j; }
137
138//  protected:
139    typedef int CExponent;
140
141    // Exponent * Exponent
142    // Computes: var(j)^{expLeft} * var(i)^{expRight}
143    virtual poly MultiplyEE(const CExponent expLeft, const CExponent expRight) = 0;
144
145    // Monom * Exponent
146    // pMonom must be of the form: var(j)^{n}
147    virtual poly MultiplyME(const poly pMonom, const CExponent expRight);
148
149    // Exponent * Monom
150    // pMonom must be of the form: var(i)^{m}
151    virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom);
152
153};
154
155
156class CCommutativeSpecialPairMultiplier: public CSpecialPairMultiplier
157{
158  public:
159    CCommutativeSpecialPairMultiplier(ring r, int i, int j):
160        CSpecialPairMultiplier(r, i, j){};
161    virtual ~CCommutativeSpecialPairMultiplier() {}
162   
163    // Exponent * Exponent
164    virtual poly MultiplyEE(const int expLeft, const int expRight);   
165
166    // Monom * Exponent
167    virtual poly MultiplyME(const poly pMonom, const int expRight);
168
169    // Exponent * Monom
170    virtual poly MultiplyEM(const int expLeft, const poly pMonom);
171};
172
173
174
175
176
177struct CPower // represents var(iVar)^{iPower}
178{
179  int Var;
180  int Power;
181
182  CPower(int i, int n): Var(i), Power(n) {};
183
184  inline poly GetPoly(const ring r, int c = 1) const
185  {
186    poly p = p_ISet(c, r);
187    p_SetExp(p, Var, Power, r);
188    return p;
189  };
190 
191};
192
193
194
195
196
197
198class CPowerMultiplier: public CMultiplier<CPower>
199{
200  private:
201    CSpecialPairMultiplier** m_specialpairs; // upper triangular submatrix of pairs 1 <= i < j <= N of a N x N matrix.
202
203
204  public:
205    CPowerMultiplier(ring r);
206    virtual ~CPowerMultiplier();
207
208    inline CSpecialPairMultiplier* GetPair(int i, int j) const
209    {
210      assume( m_specialpairs != NULL );
211      assume( i > 0 );
212      assume( i < j );
213      assume( j <= NVars() );
214
215      return m_specialpairs[( (NVars() * ((i)-1) - ((i) * ((i)-1))/2 + (j)-1) - (i) )];
216    }
217
218    inline CSpecialPairMultiplier*& GetPair(int i, int j)
219    {
220      assume( m_specialpairs != NULL );
221      assume( i > 0 );
222      assume( i < j );
223      assume( j <= NVars() );
224
225      return m_specialpairs[( (NVars() * ((i)-1) - ((i) * ((i)-1))/2 + (j)-1) - (i) )];
226    }
227   
228//  protected:
229    typedef CPower CExponent;
230
231    // Exponent * Exponent
232    // Computes: var(j)^{expLeft} * var(i)^{expRight}
233    virtual poly MultiplyEE(const CExponent expLeft, const CExponent expRight);
234
235    // Monom * Exponent
236    // pMonom may NOT be of the form: var(j)^{n}!
237    virtual poly MultiplyME(const poly pMonom, const CExponent expRight);
238
239    // Exponent * Monom
240    // pMonom may NOT be of the form: var(i)^{m}!
241    virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom);
242
243
244};
245
246
247
248
249class CGlobalMultiplier: public CMultiplier<poly>
250{
251  private:
252    CGlobalCacheHash* m_cache;
253    CPowerMultiplier* m_powers;
254
255  public:
256    typedef CMultiplier<poly> CBaseType;
257   
258    CGlobalMultiplier(ring r);
259    virtual ~CGlobalMultiplier();
260
261   
262 
263//  protected:   
264    typedef poly CExponent;
265
266    // the following methods are literally equal!
267   
268    // Exponent * Exponent
269    // TODO: handle components!!!
270    virtual poly MultiplyEE(const CExponent expLeft, const CExponent expRight);   
271
272    // Monom * Exponent
273    virtual poly MultiplyME(const poly pMonom, const CExponent expRight);
274
275    // Exponent * Monom
276    virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom);
277
278};
279
280
281
282#endif // HAVE_PLURAL :(
283#endif //
Note: See TracBrowser for help on using the repository browser.