1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /*************************************************************** |
---|
5 | * File: ncSAFormula.cc |
---|
6 | * Purpose: implementation of multiplication by formulas in simple NC subalgebras |
---|
7 | * Author: motsak |
---|
8 | * Created: |
---|
9 | *******************************************************************/ |
---|
10 | |
---|
11 | #define MYTEST 0 |
---|
12 | |
---|
13 | #if MYTEST |
---|
14 | #define OM_CHECK 4 |
---|
15 | #define OM_TRACK 5 |
---|
16 | // these settings must be before "mod2.h" in order to work!!! |
---|
17 | #endif |
---|
18 | |
---|
19 | |
---|
20 | |
---|
21 | |
---|
22 | |
---|
23 | #include <misc/auxiliary.h> |
---|
24 | |
---|
25 | #ifdef HAVE_PLURAL |
---|
26 | |
---|
27 | #define PLURAL_INTERNAL_DECLARATIONS |
---|
28 | |
---|
29 | #ifndef SING_NDEBUG |
---|
30 | #define OUTPUT MYTEST |
---|
31 | #else |
---|
32 | #define OUTPUT 0 |
---|
33 | #endif |
---|
34 | |
---|
35 | #include <reporter/reporter.h> |
---|
36 | |
---|
37 | #include <coeffs/numbers.h> |
---|
38 | #include "coeffrings.h" |
---|
39 | |
---|
40 | #include "nc/ncSAFormula.h" |
---|
41 | // for CFormulaPowerMultiplier |
---|
42 | |
---|
43 | #include "monomials/ring.h" |
---|
44 | #include "monomials/p_polys.h" |
---|
45 | |
---|
46 | #include "nc/sca.h" |
---|
47 | |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | bool ncInitSpecialPowersMultiplication(ring r) |
---|
52 | { |
---|
53 | #if OUTPUT |
---|
54 | Print("ncInitSpecialPowersMultiplication(ring), ring: \n"); |
---|
55 | rWrite(r, TRUE); |
---|
56 | PrintLn(); |
---|
57 | #endif |
---|
58 | |
---|
59 | assume(rIsPluralRing(r)); |
---|
60 | assume(!rIsSCA(r)); |
---|
61 | |
---|
62 | |
---|
63 | if( r->GetNC()->GetFormulaPowerMultiplier() != NULL ) |
---|
64 | { |
---|
65 | WarnS("Already defined!"); |
---|
66 | return false; |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | r->GetNC()->GetFormulaPowerMultiplier() = new CFormulaPowerMultiplier(r); |
---|
71 | |
---|
72 | return true; |
---|
73 | |
---|
74 | } |
---|
75 | |
---|
76 | |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | |
---|
81 | |
---|
82 | // TODO: return q-coeff? |
---|
83 | static inline BOOLEAN AreCommutingVariables(const ring r, int i, int j/*, number *qq*/) |
---|
84 | { |
---|
85 | #if OUTPUT |
---|
86 | Print("AreCommutingVariables(ring, k: %d, i: %d)!", j, i); |
---|
87 | PrintLn(); |
---|
88 | #endif |
---|
89 | |
---|
90 | assume(i != j); |
---|
91 | |
---|
92 | assume(i > 0); |
---|
93 | assume(i <= r->N); |
---|
94 | |
---|
95 | |
---|
96 | assume(j > 0); |
---|
97 | assume(j <= r->N); |
---|
98 | |
---|
99 | const BOOLEAN reverse = (i > j); |
---|
100 | |
---|
101 | if (reverse) { int k = j; j = i; i = k; } |
---|
102 | |
---|
103 | assume(i < j); |
---|
104 | |
---|
105 | { |
---|
106 | const poly d = GetD(r, i, j); |
---|
107 | |
---|
108 | #if OUTPUT |
---|
109 | Print("D_{%d, %d} = ", i, j); p_Write(d, r); |
---|
110 | #endif |
---|
111 | |
---|
112 | if( d != NULL) |
---|
113 | return FALSE; |
---|
114 | } |
---|
115 | |
---|
116 | |
---|
117 | { |
---|
118 | const number q = p_GetCoeff(GetC(r, i, j), r); |
---|
119 | |
---|
120 | if( !n_IsOne(q, r) ) |
---|
121 | return FALSE; |
---|
122 | } |
---|
123 | |
---|
124 | return TRUE; // [VAR(I), VAR(J)] = 0!! |
---|
125 | |
---|
126 | /* |
---|
127 | if (reverse) |
---|
128 | *qq = n_Invers(q, r); |
---|
129 | else |
---|
130 | *qq = n_Copy(q, r); |
---|
131 | return TRUE; |
---|
132 | */ |
---|
133 | } |
---|
134 | |
---|
135 | static inline Enum_ncSAType AnalyzePairType(const ring r, int i, int j) |
---|
136 | { |
---|
137 | #if OUTPUT |
---|
138 | Print("AnalyzePair(ring, i: %d, j: %d):", i, j); |
---|
139 | PrintLn(); |
---|
140 | #endif |
---|
141 | |
---|
142 | const int N = r->N; |
---|
143 | |
---|
144 | assume(i < j); |
---|
145 | assume(i > 0); |
---|
146 | assume(j <= N); |
---|
147 | |
---|
148 | |
---|
149 | const poly c = GetC(r, i, j); |
---|
150 | const number q = p_GetCoeff(c, r); |
---|
151 | const poly d = GetD(r, i, j); |
---|
152 | |
---|
153 | #if 0 && OUTPUT |
---|
154 | Print("C_{%d, %d} = ", i, j); p_Write(c, r); PrintLn(); |
---|
155 | Print("D_{%d, %d} = ", i, j); p_Write(d, r); |
---|
156 | #endif |
---|
157 | |
---|
158 | // const number q = p_GetCoeff(c, r); |
---|
159 | |
---|
160 | if( d == NULL) |
---|
161 | { |
---|
162 | |
---|
163 | if( n_IsOne(q, r) ) // commutative |
---|
164 | return _ncSA_1xy0x0y0; |
---|
165 | |
---|
166 | if( n_IsMOne(q, r) ) // anti-commutative |
---|
167 | return _ncSA_Mxy0x0y0; |
---|
168 | |
---|
169 | return _ncSA_Qxy0x0y0; // quasi-commutative |
---|
170 | } else |
---|
171 | { |
---|
172 | if( n_IsOne(q, r) ) // "Lie" case |
---|
173 | { |
---|
174 | if( pNext(d) == NULL ) // Our Main Special Case: d is only a term! |
---|
175 | { |
---|
176 | // const number g = p_GetCoeff(d, r); // not used for now |
---|
177 | if( p_LmIsConstantComp(d, r) ) // Weyl |
---|
178 | return _ncSA_1xy0x0yG; |
---|
179 | |
---|
180 | const int k = p_IsPurePower(d, r); // k if not pure power |
---|
181 | |
---|
182 | if( k > 0 ) // d = var(k)^?? |
---|
183 | { |
---|
184 | const int exp = p_GetExp(d, k, r); |
---|
185 | |
---|
186 | if (exp == 1) |
---|
187 | { |
---|
188 | if(k == i) // 2 -ubalgebra in var(i) & var(j), with linear relation...? |
---|
189 | return _ncSA_1xyAx0y0; |
---|
190 | |
---|
191 | if(k == j) |
---|
192 | return _ncSA_1xy0xBy0; |
---|
193 | } else if ( exp == 2 && k!= i && k != j) // Homogenized Weyl algebra [x, Dx] = t^2? |
---|
194 | { |
---|
195 | // number qi, qj; |
---|
196 | if (AreCommutingVariables(r, k, i/*, &qi*/) && AreCommutingVariables(r, k, j/*, &qj*/) ) // [x, t] = [Dx, t] = 0? |
---|
197 | { |
---|
198 | const number g = p_GetCoeff(d, r); |
---|
199 | |
---|
200 | if (n_IsOne(g, r)) |
---|
201 | return _ncSA_1xy0x0yT2; // save k!?, G = LC(d) == qi == qj == 1!!! |
---|
202 | } |
---|
203 | } |
---|
204 | } |
---|
205 | } |
---|
206 | } |
---|
207 | // Hmm, what about a more general case of q != 1??? |
---|
208 | } |
---|
209 | #if OUTPUT |
---|
210 | Print("C_{%d, %d} = ", i, j); p_Write(c, r); |
---|
211 | Print("D_{%d, %d} = ", i, j); p_Write(d, r); |
---|
212 | PrintS("====>>>>_ncSA_notImplemented\n"); |
---|
213 | #endif |
---|
214 | |
---|
215 | return _ncSA_notImplemented; |
---|
216 | } |
---|
217 | |
---|
218 | |
---|
219 | CFormulaPowerMultiplier::CFormulaPowerMultiplier(ring r): m_NVars(r->N), m_BaseRing(r) |
---|
220 | { |
---|
221 | #if OUTPUT |
---|
222 | Print("CFormulaPowerMultiplier::CFormulaPowerMultiplier(ring)!"); |
---|
223 | PrintLn(); |
---|
224 | #endif |
---|
225 | |
---|
226 | m_SAPairTypes = (Enum_ncSAType*)omAlloc0( ((NVars() * (NVars()-1)) / 2) * sizeof(Enum_ncSAType) ); |
---|
227 | |
---|
228 | for( int i = 1; i < NVars(); i++ ) |
---|
229 | for( int j = i + 1; j <= NVars(); j++ ) |
---|
230 | GetPair(i, j) = AnalyzePairType(GetBasering(), i, j); |
---|
231 | } |
---|
232 | |
---|
233 | |
---|
234 | |
---|
235 | |
---|
236 | CFormulaPowerMultiplier::~CFormulaPowerMultiplier() |
---|
237 | { |
---|
238 | #if OUTPUT |
---|
239 | Print("CFormulaPowerMultiplier::~CFormulaPowerMultiplier()!"); |
---|
240 | PrintLn(); |
---|
241 | #endif |
---|
242 | |
---|
243 | omFreeSize((ADDRESS)m_SAPairTypes, ((NVars() * (NVars()-1)) / 2) * sizeof(Enum_ncSAType) ); |
---|
244 | } |
---|
245 | |
---|
246 | |
---|
247 | |
---|
248 | |
---|
249 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
250 | static inline void CorrectPolyWRTOrdering(poly &pResult, const ring r) |
---|
251 | { |
---|
252 | if( pNext(pResult) != NULL ) |
---|
253 | { |
---|
254 | const int cmp = p_LmCmp(pResult, pNext(pResult), r); |
---|
255 | assume( cmp != 0 ); // must not be equal!!! |
---|
256 | if( cmp != 1 ) // Wrong order!!! |
---|
257 | pResult = pReverse(pResult); // Reverse!!! |
---|
258 | } |
---|
259 | p_Test(pResult, r); |
---|
260 | } |
---|
261 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
262 | static inline poly ncSA_1xy0x0y0(const int i, const int j, const int n, const int m, const ring r) |
---|
263 | { |
---|
264 | #if OUTPUT |
---|
265 | Print("ncSA_1xy0x0y0(var(%d)^{%d}, var(%d)^{%d}, r)!", j, m, i, n); |
---|
266 | PrintLn(); |
---|
267 | #endif |
---|
268 | |
---|
269 | poly p = p_One( r); |
---|
270 | p_SetExp(p, j, m, r); |
---|
271 | p_SetExp(p, i, n, r); |
---|
272 | p_Setm(p, r); |
---|
273 | |
---|
274 | p_Test(p, r); |
---|
275 | |
---|
276 | return p; |
---|
277 | |
---|
278 | } // return ncSA_1xy0x0y0(GetI(), GetJ(), expRight, expLeft, r); |
---|
279 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
280 | static inline poly ncSA_Mxy0x0y0(const int i, const int j, const int n, const int m, const ring r) |
---|
281 | { |
---|
282 | #if OUTPUT |
---|
283 | Print("ncSA_{M = -1}xy0x0y0(var(%d)^{%d}, var(%d)^{%d}, r)!", j, m, i, n); |
---|
284 | PrintLn(); |
---|
285 | #endif |
---|
286 | |
---|
287 | const int sign = 1 - ((n & (m & 1)) << 1); |
---|
288 | poly p = p_ISet(sign, r); |
---|
289 | p_SetExp(p, j, m, r); |
---|
290 | p_SetExp(p, i, n, r); |
---|
291 | p_Setm(p, r); |
---|
292 | |
---|
293 | |
---|
294 | p_Test(p, r); |
---|
295 | |
---|
296 | return p; |
---|
297 | |
---|
298 | } // return ncSA_Mxy0x0y0(GetI(), GetJ(), expRight, expLeft, r); |
---|
299 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
300 | static inline poly ncSA_Qxy0x0y0(const int i, const int j, const int n, const int m, const number m_q, const ring r) |
---|
301 | { |
---|
302 | #if OUTPUT |
---|
303 | Print("ncSA_Qxy0x0y0(var(%d)^{%d}, var(%d)^{%d}, Q, r)!", j, m, i, n); |
---|
304 | PrintLn(); |
---|
305 | #endif |
---|
306 | |
---|
307 | int min, max; |
---|
308 | |
---|
309 | if( n < m ) |
---|
310 | { |
---|
311 | min = n; |
---|
312 | max = m; |
---|
313 | } else |
---|
314 | { |
---|
315 | min = m; |
---|
316 | max = n; |
---|
317 | } |
---|
318 | |
---|
319 | number qN; |
---|
320 | |
---|
321 | if( max == 1 ) |
---|
322 | qN = n_Copy(m_q, r); |
---|
323 | else |
---|
324 | { |
---|
325 | number t; |
---|
326 | n_Power(m_q, max, &t, r); |
---|
327 | |
---|
328 | if( min > 1 ) |
---|
329 | { |
---|
330 | n_Power(t, min, &qN, r); |
---|
331 | n_Delete(&t, r); |
---|
332 | } |
---|
333 | else |
---|
334 | qN = t; |
---|
335 | } |
---|
336 | |
---|
337 | poly p = p_NSet(qN, r); |
---|
338 | p_SetExp(p, j, m, r); |
---|
339 | p_SetExp(p, i, n, r); |
---|
340 | p_Setm(p, r); |
---|
341 | |
---|
342 | |
---|
343 | p_Test(p, r); |
---|
344 | |
---|
345 | return p; |
---|
346 | |
---|
347 | } // return ncSA_Qxy0x0y0(GetI(), GetJ(), expRight, expLeft, m_q, r); |
---|
348 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
349 | static inline poly ncSA_1xy0x0yG(const int i, const int j, const int n, const int m, const number m_g, const ring r) |
---|
350 | { |
---|
351 | #if OUTPUT |
---|
352 | Print("ncSA_1xy0x0yG(var(%d)^{%d}, var(%d)^{%d}, G, r)!", j, m, i, n); |
---|
353 | PrintLn(); |
---|
354 | number t = n_Copy(m_g, r); |
---|
355 | PrintS("Parameter G: "); n_Write(t, r); |
---|
356 | n_Delete(&t, r); |
---|
357 | #endif |
---|
358 | |
---|
359 | int kn = n; |
---|
360 | int km = m; |
---|
361 | |
---|
362 | number c = n_Init(1, r); |
---|
363 | |
---|
364 | poly p = p_One( r); |
---|
365 | |
---|
366 | p_SetExp(p, j, km--, r); // y ^ (m-k) |
---|
367 | p_SetExp(p, i, kn--, r); // x ^ (n-k) |
---|
368 | |
---|
369 | p_Setm(p, r); // pResult = x^n * y^m |
---|
370 | |
---|
371 | |
---|
372 | poly pResult = p; |
---|
373 | poly pLast = p; |
---|
374 | |
---|
375 | int min = si_min(m, n); |
---|
376 | |
---|
377 | int k = 1; |
---|
378 | |
---|
379 | for(; k < min; k++ ) |
---|
380 | { |
---|
381 | number t = n_Init(km + 1, r); |
---|
382 | n_InpMult(t, m_g, r); // t = ((m - k) + 1) * gamma |
---|
383 | n_InpMult(c, t, r); // c = c'* ((m - k) + 1) * gamma |
---|
384 | n_Delete(&t, r); |
---|
385 | |
---|
386 | t = n_Init(kn + 1, r); |
---|
387 | n_InpMult(c, t, r); // c = (c'* ((m - k) + 1) * gamma) * ((n - k) + 1) |
---|
388 | n_Delete(&t, r); |
---|
389 | |
---|
390 | t = n_Init(k, r); |
---|
391 | c = n_Div(c, t, r); |
---|
392 | n_Delete(&t, r); |
---|
393 | |
---|
394 | // n_Normalize(c, r); |
---|
395 | |
---|
396 | t = n_Copy(c, r); // not the last! |
---|
397 | |
---|
398 | p = p_NSet(t, r); |
---|
399 | |
---|
400 | p_SetExp(p, j, km--, r); // y ^ (m-k) |
---|
401 | p_SetExp(p, i, kn--, r); // x ^ (n-k) |
---|
402 | |
---|
403 | p_Setm(p, r); // pResult = x^n * y^m |
---|
404 | |
---|
405 | pNext(pLast) = p; |
---|
406 | pLast = p; |
---|
407 | } |
---|
408 | |
---|
409 | assume(k == min); |
---|
410 | assume((km == 0) || (kn == 0) ); |
---|
411 | |
---|
412 | { |
---|
413 | n_InpMult(c, m_g, r); // c = c'* gamma |
---|
414 | |
---|
415 | if( km > 0 ) |
---|
416 | { |
---|
417 | number t = n_Init(km + 1, r); |
---|
418 | n_InpMult(c, t, r); // c = (c'* gamma) * (m - k + 1) |
---|
419 | n_Delete(&t, r); |
---|
420 | } |
---|
421 | |
---|
422 | if( kn > 0 ) |
---|
423 | { |
---|
424 | number t = n_Init(kn + 1, r); |
---|
425 | n_InpMult(c, t, r); // c = (c'* gamma) * (n - k + 1) |
---|
426 | n_Delete(&t, r); |
---|
427 | } |
---|
428 | |
---|
429 | number t = n_Init(k, r); // c = ((c'* gamma) * ((n - k + 1) * (m - k + 1))) / k; |
---|
430 | c = n_Div(c, t, r); |
---|
431 | n_Delete(&t, r); |
---|
432 | } |
---|
433 | |
---|
434 | p = p_NSet(c, r); |
---|
435 | |
---|
436 | p_SetExp(p, j, km, r); // y ^ (m-k) |
---|
437 | p_SetExp(p, i, kn, r); // x ^ (n-k) |
---|
438 | |
---|
439 | p_Setm(p, r); // |
---|
440 | |
---|
441 | pNext(pLast) = p; |
---|
442 | |
---|
443 | CorrectPolyWRTOrdering(pResult, r); |
---|
444 | |
---|
445 | return pResult; |
---|
446 | } |
---|
447 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
448 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
449 | static inline poly ncSA_1xy0x0yT2(const int i, const int j, const int n, const int m, const int m_k, const ring r) |
---|
450 | { |
---|
451 | #if OUTPUT |
---|
452 | Print("ncSA_1xy0x0yT2(var(%d)^{%d}, var(%d)^{%d}, t: var(%d), r)!", j, m, i, n, m_k); |
---|
453 | PrintLn(); |
---|
454 | #endif |
---|
455 | |
---|
456 | int kn = n; |
---|
457 | int km = m; |
---|
458 | |
---|
459 | // k == 0! |
---|
460 | number c = n_Init(1, r); |
---|
461 | |
---|
462 | poly p = p_One( r ); |
---|
463 | |
---|
464 | p_SetExp(p, j, km--, r); // y ^ (m) |
---|
465 | p_SetExp(p, i, kn--, r); // x ^ (n) |
---|
466 | // p_SetExp(p, m_k, k << 1, r); // homogenization with var(m_k) ^ (2*k) |
---|
467 | |
---|
468 | p_Setm(p, r); // pResult = x^n * y^m |
---|
469 | |
---|
470 | |
---|
471 | poly pResult = p; |
---|
472 | poly pLast = p; |
---|
473 | |
---|
474 | int min = si_min(m, n); |
---|
475 | |
---|
476 | int k = 1; |
---|
477 | |
---|
478 | for(; k < min; k++ ) |
---|
479 | { |
---|
480 | number t = n_Init(km + 1, r); |
---|
481 | // n_InpMult(t, m_g, r); // t = ((m - k) + 1) * gamma |
---|
482 | n_InpMult(c, t, r); // c = c'* ((m - k) + 1) * gamma |
---|
483 | n_Delete(&t, r); |
---|
484 | |
---|
485 | t = n_Init(kn + 1, r); |
---|
486 | n_InpMult(c, t, r); // c = (c'* ((m - k) + 1) * gamma) * ((n - k) + 1) |
---|
487 | n_Delete(&t, r); |
---|
488 | |
---|
489 | t = n_Init(k, r); |
---|
490 | c = n_Div(c, t, r); |
---|
491 | n_Delete(&t, r); |
---|
492 | |
---|
493 | // // n_Normalize(c, r); |
---|
494 | |
---|
495 | t = n_Copy(c, r); // not the last! |
---|
496 | |
---|
497 | p = p_NSet(t, r); |
---|
498 | |
---|
499 | p_SetExp(p, j, km--, r); // y ^ (m-k) |
---|
500 | p_SetExp(p, i, kn--, r); // x ^ (n-k) |
---|
501 | |
---|
502 | p_SetExp(p, m_k, k << 1, r); // homogenization with var(m_k) ^ (2*k) |
---|
503 | |
---|
504 | p_Setm(p, r); // pResult = x^(n-k) * y^(m-k) |
---|
505 | |
---|
506 | pNext(pLast) = p; |
---|
507 | pLast = p; |
---|
508 | } |
---|
509 | |
---|
510 | assume(k == min); |
---|
511 | assume((km == 0) || (kn == 0) ); |
---|
512 | |
---|
513 | { |
---|
514 | // n_InpMult(c, m_g, r); // c = c'* gamma |
---|
515 | |
---|
516 | if( km > 0 ) |
---|
517 | { |
---|
518 | number t = n_Init(km + 1, r); |
---|
519 | n_InpMult(c, t, r); // c = (c'* gamma) * (m - k + 1) |
---|
520 | n_Delete(&t, r); |
---|
521 | } |
---|
522 | |
---|
523 | if( kn > 0 ) |
---|
524 | { |
---|
525 | number t = n_Init(kn + 1, r); |
---|
526 | n_InpMult(c, t, r); // c = (c'* gamma) * (n - k + 1) |
---|
527 | n_Delete(&t, r); |
---|
528 | } |
---|
529 | |
---|
530 | number t = n_Init(k, r); // c = ((c'* gamma) * ((n - k + 1) * (m - k + 1))) / k; |
---|
531 | c = n_Div(c, t, r); |
---|
532 | n_Delete(&t, r); |
---|
533 | } |
---|
534 | |
---|
535 | p = p_NSet(c, r); |
---|
536 | |
---|
537 | p_SetExp(p, j, km, r); // y ^ (m-k) |
---|
538 | p_SetExp(p, i, kn, r); // x ^ (n-k) |
---|
539 | |
---|
540 | p_SetExp(p, m_k, k << 1, r); // homogenization with var(m_k) ^ (2*k) |
---|
541 | |
---|
542 | p_Setm(p, r); // |
---|
543 | |
---|
544 | pNext(pLast) = p; |
---|
545 | |
---|
546 | CorrectPolyWRTOrdering(pResult, r); |
---|
547 | |
---|
548 | return pResult; |
---|
549 | } |
---|
550 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
551 | |
---|
552 | |
---|
553 | |
---|
554 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
555 | static inline poly ncSA_ShiftAx(int i, int j, int n, int m, const number m_shiftCoef, const ring r) |
---|
556 | { |
---|
557 | // Char == 0, otherwise - problem! |
---|
558 | |
---|
559 | int k = m; // to 0 |
---|
560 | |
---|
561 | number c = n_Init(1, r); // k = m, C_k = 1 |
---|
562 | poly p = p_One( r); |
---|
563 | |
---|
564 | p_SetExp(p, j, k, r); // Y^{k} |
---|
565 | p_SetExp(p, i, n, r); |
---|
566 | |
---|
567 | p_Setm(p, r); // pResult = C_k * x^n * y^k, k == m |
---|
568 | |
---|
569 | |
---|
570 | poly pResult = p; |
---|
571 | poly pLast = p; |
---|
572 | |
---|
573 | number nn = n_Init(n, r); // number(n)! |
---|
574 | n_InpMult(nn, m_shiftCoef, r); // nn = (alpha*n) |
---|
575 | |
---|
576 | --k; |
---|
577 | |
---|
578 | int mk = 1; // mk = (m - k) |
---|
579 | |
---|
580 | for(; k > 0; k-- ) |
---|
581 | { |
---|
582 | number t = n_Init(k + 1, r); // t = k+1 |
---|
583 | n_InpMult(c, t, r); // c = c' * (k+1) |
---|
584 | n_InpMult(c, nn, r); // c = (c' * (k+1)) * (alpha * n) |
---|
585 | |
---|
586 | n_Delete(&t, r); |
---|
587 | t = n_Init(mk++, r); |
---|
588 | c = n_Div(c, t, r); // c = ((c' * (k+1)) * (alpha * n)) / (m-k); |
---|
589 | n_Delete(&t, r); |
---|
590 | |
---|
591 | // n_Normalize(c, r); |
---|
592 | |
---|
593 | t = n_Copy(c, r); // not the last! |
---|
594 | |
---|
595 | p = p_NSet(t, r); |
---|
596 | |
---|
597 | p_SetExp(p, j, k, r); // y^k |
---|
598 | p_SetExp(p, i, n, r); // x^n |
---|
599 | |
---|
600 | p_Setm(p, r); // pResult = x^n * y^m |
---|
601 | |
---|
602 | pNext(pLast) = p; |
---|
603 | pLast = p; |
---|
604 | } |
---|
605 | |
---|
606 | assume(k == 0); |
---|
607 | |
---|
608 | { |
---|
609 | n_InpMult(c, nn, r); // c = (c' * (0+1)) * (alpha * n) |
---|
610 | |
---|
611 | number t = n_Init(m, r); |
---|
612 | c = n_Div(c, t, r); // c = ((c' * (0+1)) * (alpha * n)) / (m-0); |
---|
613 | n_Delete(&t, r); |
---|
614 | } |
---|
615 | |
---|
616 | n_Delete(&nn, r); |
---|
617 | |
---|
618 | p = p_NSet(c, r); |
---|
619 | |
---|
620 | p_SetExp(p, j, k, r); // y^k |
---|
621 | p_SetExp(p, i, n, r); // x^n |
---|
622 | |
---|
623 | p_Setm(p, r); // |
---|
624 | |
---|
625 | pNext(pLast) = p; |
---|
626 | |
---|
627 | CorrectPolyWRTOrdering(pResult, r); |
---|
628 | |
---|
629 | return pResult; |
---|
630 | } |
---|
631 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
632 | static inline poly ncSA_1xyAx0y0(const int i, const int j, const int n, const int m, const number m_shiftCoef, const ring r) |
---|
633 | { |
---|
634 | #if OUTPUT |
---|
635 | Print("ncSA_1xyAx0y0(var(%d)^{%d}, var(%d)^{%d}, A, r)!", j, m, i, n); |
---|
636 | PrintLn(); |
---|
637 | number t = n_Copy(m_shiftCoef, r); |
---|
638 | PrintS("Parameter A: "); n_Write(t, r); |
---|
639 | n_Delete(&t, r); |
---|
640 | #endif |
---|
641 | |
---|
642 | return ncSA_ShiftAx(i, j, n, m, m_shiftCoef, r); |
---|
643 | } |
---|
644 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
645 | static inline poly ncSA_1xy0xBy0(const int i, const int j, const int n, const int m, const number m_shiftCoef, const ring r) |
---|
646 | { |
---|
647 | #if OUTPUT |
---|
648 | Print("ncSA_1xy0xBy0(var(%d)^{%d}, var(%d)^{%d}, B, r)!", j, m, i, n); |
---|
649 | PrintLn(); |
---|
650 | number t = n_Copy(m_shiftCoef, r); |
---|
651 | PrintS("Parameter B: "); n_Write(t, r); |
---|
652 | n_Delete(&t, r); |
---|
653 | #endif |
---|
654 | |
---|
655 | return ncSA_ShiftAx(j, i, m, n, m_shiftCoef, r); |
---|
656 | } |
---|
657 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
658 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
659 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
660 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
661 | |
---|
662 | |
---|
663 | static inline poly ncSA_Multiply( Enum_ncSAType type, const int i, const int j, const int n, const int m, const ring r) |
---|
664 | { |
---|
665 | #if OUTPUT |
---|
666 | Print("ncSA_Multiply(type: %d, ring, (var(%d)^{%d} * var(%d)^{%d}, r)!", (int)type, j, m, i, n); |
---|
667 | PrintLn(); |
---|
668 | #endif |
---|
669 | |
---|
670 | assume( type != _ncSA_notImplemented ); |
---|
671 | assume( (n > 0) && (m > 0) ); |
---|
672 | |
---|
673 | if( type == _ncSA_1xy0x0y0 ) |
---|
674 | return ::ncSA_1xy0x0y0(i, j, n, m, r); |
---|
675 | |
---|
676 | if( type == _ncSA_Mxy0x0y0 ) |
---|
677 | return ::ncSA_Mxy0x0y0(i, j, n, m, r); |
---|
678 | |
---|
679 | if( type == _ncSA_Qxy0x0y0 ) |
---|
680 | { |
---|
681 | const number q = p_GetCoeff(GetC(r, i, j), r); |
---|
682 | return ::ncSA_Qxy0x0y0(i, j, n, m, q, r); |
---|
683 | } |
---|
684 | |
---|
685 | const poly d = GetD(r, i, j); |
---|
686 | const number g = p_GetCoeff(d, r); |
---|
687 | |
---|
688 | if( type == _ncSA_1xy0x0yG ) // Weyl |
---|
689 | return ::ncSA_1xy0x0yG(i, j, n, m, g, r); |
---|
690 | |
---|
691 | if( type == _ncSA_1xy0x0yT2 ) // Homogenous Weyl... |
---|
692 | return ::ncSA_1xy0x0yT2(i, j, n, m, p_IsPurePower(d, r), r); |
---|
693 | |
---|
694 | if( type == _ncSA_1xyAx0y0 ) // Shift 1 |
---|
695 | return ::ncSA_1xyAx0y0(i, j, n, m, g, r); |
---|
696 | |
---|
697 | if( type == _ncSA_1xy0xBy0 ) // Shift 2 |
---|
698 | return ::ncSA_1xy0xBy0(i, j, n, m, g, r); |
---|
699 | |
---|
700 | assume( type == _ncSA_notImplemented ); |
---|
701 | |
---|
702 | return NULL; |
---|
703 | } |
---|
704 | |
---|
705 | |
---|
706 | poly CFormulaPowerMultiplier::Multiply( Enum_ncSAType type, const int i, const int j, const int n, const int m, const ring r) |
---|
707 | { |
---|
708 | return ncSA_Multiply( type, i, j, n, m, r); |
---|
709 | } |
---|
710 | |
---|
711 | |
---|
712 | Enum_ncSAType CFormulaPowerMultiplier::AnalyzePair(const ring r, int i, int j) |
---|
713 | { |
---|
714 | return ::AnalyzePairType( r, i, j); |
---|
715 | } |
---|
716 | |
---|
717 | poly CFormulaPowerMultiplier::Multiply( int i, int j, const int n, const int m) |
---|
718 | { |
---|
719 | return ncSA_Multiply( GetPair(i, j), i, j, n, m, GetBasering()); |
---|
720 | } |
---|
721 | |
---|
722 | |
---|
723 | |
---|
724 | |
---|
725 | poly CFormulaPowerMultiplier::ncSA_1xy0x0y0(const int i, const int j, const int n, const int m, const ring r) |
---|
726 | { |
---|
727 | return ::ncSA_1xy0x0y0(i, j, n, m, r); |
---|
728 | } |
---|
729 | |
---|
730 | poly CFormulaPowerMultiplier::ncSA_Mxy0x0y0(const int i, const int j, const int n, const int m, const ring r) |
---|
731 | { |
---|
732 | return ::ncSA_Mxy0x0y0(i, j, n, m, r); |
---|
733 | } |
---|
734 | |
---|
735 | poly CFormulaPowerMultiplier::ncSA_Qxy0x0y0(const int i, const int j, const int n, const int m, const number m_q, const ring r) |
---|
736 | { |
---|
737 | return ::ncSA_Qxy0x0y0(i, j, n, m, m_q, r); |
---|
738 | } |
---|
739 | |
---|
740 | poly CFormulaPowerMultiplier::ncSA_1xy0x0yG(const int i, const int j, const int n, const int m, const number m_g, const ring r) |
---|
741 | { |
---|
742 | return ::ncSA_1xy0x0yG(i, j, n, m, m_g, r); |
---|
743 | } |
---|
744 | |
---|
745 | poly CFormulaPowerMultiplier::ncSA_1xy0x0yT2(const int i, const int j, const int n, const int m, const int k, const ring r) |
---|
746 | { |
---|
747 | return ::ncSA_1xy0x0yT2(i, j, n, m, k, r); |
---|
748 | } |
---|
749 | |
---|
750 | poly CFormulaPowerMultiplier::ncSA_1xyAx0y0(const int i, const int j, const int n, const int m, const number m_shiftCoef, const ring r) |
---|
751 | { |
---|
752 | return ::ncSA_1xyAx0y0(i, j, n, m, m_shiftCoef, r); |
---|
753 | } |
---|
754 | |
---|
755 | poly CFormulaPowerMultiplier::ncSA_1xy0xBy0(const int i, const int j, const int n, const int m, const number m_shiftCoef, const ring r) |
---|
756 | { |
---|
757 | return ::ncSA_1xy0xBy0(i, j, n, m, m_shiftCoef, r); |
---|
758 | } |
---|
759 | #endif |
---|