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.3 2008-07-11 15:53:28 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 | |
---|
15 | #include <ncSACache.h> // for CCacheHash etc classes |
---|
16 | |
---|
17 | // //////////////////////////////////////////////////////////////////////// // |
---|
18 | // |
---|
19 | |
---|
20 | bool ncInitSpecialPairMultiplication(ring r); |
---|
21 | |
---|
22 | |
---|
23 | template <typename CExponent> |
---|
24 | class CMultiplier |
---|
25 | { |
---|
26 | protected: |
---|
27 | ring m_basering; |
---|
28 | |
---|
29 | public: |
---|
30 | CMultiplier(ring rBaseRing): m_basering(rBaseRing) {}; |
---|
31 | |
---|
32 | const ring GetBasering() const { return m_basering; }; |
---|
33 | |
---|
34 | |
---|
35 | // Term * Exponent -> Monom * Exponent |
---|
36 | inline poly MultiplyTE(const poly pTerm, const CExponent expRight) |
---|
37 | { return p_Mult_nn(MultiplyME(pTerm, expRight), p_GetCoeff(pTerm, GetBasering()), GetBasering()); } |
---|
38 | |
---|
39 | // Exponent * Term -> Exponent * Monom |
---|
40 | inline poly MultiplyET(const CExponent expLeft, const poly pTerm) |
---|
41 | { return p_Mult_nn(MultiplyEM(expLeft, pTerm), p_GetCoeff(pTerm, GetBasering()), GetBasering()); } |
---|
42 | |
---|
43 | // |
---|
44 | // Main templates! |
---|
45 | // |
---|
46 | |
---|
47 | // Poly * Exponent |
---|
48 | inline poly MultiplyPE(const poly pPoly, const CExponent expRight) |
---|
49 | { |
---|
50 | bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (pLength(pPoly) < MIN_LENGTH_BUCKET); |
---|
51 | CPolynomialSummator sum(GetBasering(), bUsePolynomial); |
---|
52 | |
---|
53 | for( poly q = pPoly; q !=NULL; q = pNext(q) ) |
---|
54 | sum += MultiplyTE(q, expRight); |
---|
55 | |
---|
56 | return sum; |
---|
57 | } |
---|
58 | |
---|
59 | // Exponent * Poly |
---|
60 | inline poly MultiplyEP(const CExponent expLeft, const poly pPoly) |
---|
61 | { |
---|
62 | bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (pLength(pPoly) < MIN_LENGTH_BUCKET); |
---|
63 | CPolynomialSummator sum(GetBasering(), bUsePolynomial); |
---|
64 | |
---|
65 | for( poly q = pPoly; q !=NULL; q = pNext(q) ) |
---|
66 | sum += MultiplyET(expLeft, q); |
---|
67 | |
---|
68 | return sum; |
---|
69 | } |
---|
70 | |
---|
71 | // Poly * Exponent |
---|
72 | inline poly MultiplyPEDestroy(poly pPoly, const CExponent expRight) |
---|
73 | { |
---|
74 | bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (pLength(pPoly) < MIN_LENGTH_BUCKET); |
---|
75 | CPolynomialSummator sum(GetBasering(), bUsePolynomial); |
---|
76 | |
---|
77 | for( ; pPoly!=NULL; pPoly = p_LmDeleteAndNext(pPoly, GetBasering()) ) |
---|
78 | sum += MultiplyTE(pPoly, expRight); |
---|
79 | |
---|
80 | return sum; |
---|
81 | } |
---|
82 | |
---|
83 | // Exponent * Poly |
---|
84 | inline poly MultiplyEPDestroy(const CExponent expLeft, poly pPoly) |
---|
85 | { |
---|
86 | bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (pLength(pPoly) < MIN_LENGTH_BUCKET); |
---|
87 | CPolynomialSummator sum(GetBasering(), bUsePolynomial); |
---|
88 | |
---|
89 | for( ; pPoly!=NULL; pPoly = p_LmDeleteAndNext(pPoly, GetBasering()) ) |
---|
90 | sum += MultiplyET(expLeft, pPoly); |
---|
91 | |
---|
92 | return sum; |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | protected: |
---|
97 | |
---|
98 | // Exponent * Exponent |
---|
99 | virtual poly MultiplyEE(const CExponent expLeft, const CExponent expRight) = 0; |
---|
100 | |
---|
101 | // Monom * Exponent |
---|
102 | virtual poly MultiplyME(const poly pMonom, const CExponent expRight) = 0; |
---|
103 | |
---|
104 | // Exponent * Monom |
---|
105 | virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom) = 0; |
---|
106 | |
---|
107 | private: // no copy constuctors! |
---|
108 | CMultiplier(); |
---|
109 | operator =(CMultiplier&); |
---|
110 | }; |
---|
111 | |
---|
112 | |
---|
113 | class CSpecialPairMultiplier: public CMultiplier<int> |
---|
114 | { |
---|
115 | private: |
---|
116 | int m_i; |
---|
117 | int m_j; |
---|
118 | |
---|
119 | public: |
---|
120 | CSpecialPairMultiplier(ring r, int i, int j); |
---|
121 | protected: |
---|
122 | typedef int CExponent; |
---|
123 | |
---|
124 | // Exponent * Exponent |
---|
125 | virtual poly MultiplyEE(const poly expLeft, const CExponent expRight); |
---|
126 | |
---|
127 | // Monom * Exponent |
---|
128 | virtual poly MultiplyME(const poly pMonom, const CExponent expRight); |
---|
129 | |
---|
130 | // Exponent * Monom |
---|
131 | virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom); |
---|
132 | |
---|
133 | }; |
---|
134 | |
---|
135 | /* |
---|
136 | class CCommutativeSpecialPairMultiplier: public CSpecialPairMultiplier |
---|
137 | { |
---|
138 | public: |
---|
139 | // Exponent * Exponent |
---|
140 | virtual poly MultiplyEE(const poly expLeft, const CExponent expRight); |
---|
141 | |
---|
142 | // Monom * Exponent |
---|
143 | virtual poly MultiplyME(const poly pMonom, const CExponent expRight); |
---|
144 | |
---|
145 | // Exponent * Monom |
---|
146 | virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom); |
---|
147 | } |
---|
148 | */ |
---|
149 | |
---|
150 | |
---|
151 | |
---|
152 | |
---|
153 | class CGlobalMultiplier: public CMultiplier<poly> |
---|
154 | { |
---|
155 | private: |
---|
156 | CSpecialPairMultiplier** m_specialpairs; // upper triangular submatrix of pairs 1 <= i < j <= N of a N x N matrix. |
---|
157 | int m_NVars; // N = number of variables |
---|
158 | CGlobalCacheHash* m_cache; |
---|
159 | |
---|
160 | public: |
---|
161 | CGlobalMultiplier(ring r); |
---|
162 | |
---|
163 | inline int NVars() const { return m_NVars; } |
---|
164 | |
---|
165 | inline CSpecialPairMultiplier* GetPair(int i, int j) const |
---|
166 | { |
---|
167 | assume( m_specialpairs != NULL ); |
---|
168 | assume( i > 0 ); |
---|
169 | assume( i < j ); |
---|
170 | assume( j <= iNVars ); |
---|
171 | |
---|
172 | return m_specialpairs + ( (NVars() * ((i)-1) - ((i) * ((i)-1))/2 + (j)-1) - (i) ); |
---|
173 | } |
---|
174 | |
---|
175 | |
---|
176 | protected: |
---|
177 | typedef poly CExponent; |
---|
178 | |
---|
179 | // the following methods are literally equal! |
---|
180 | |
---|
181 | // Exponent * Exponent |
---|
182 | virtual poly MultiplyEE(const poly expLeft, const CExponent expRight); |
---|
183 | |
---|
184 | // Monom * Exponent |
---|
185 | virtual poly MultiplyME(const poly pMonom, const CExponent expRight); |
---|
186 | |
---|
187 | // Exponent * Monom |
---|
188 | virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom); |
---|
189 | |
---|
190 | |
---|
191 | CSpecialPairMultiplier* AnalyzePair(const ring r, int j, int i); |
---|
192 | |
---|
193 | }; |
---|
194 | |
---|
195 | |
---|
196 | |
---|
197 | #endif // HAVE_PLURAL :( |
---|
198 | #endif // |
---|