ncSAMult.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 /***************************************************************
5  * File: ncSAMult.cc
6  * Purpose: implementation of multiplication 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 
28 #ifndef SING_NDEBUG
29 #define OUTPUT MYTEST
30 #else
31 #define OUTPUT 0
32 #endif
33 
34 # define PLURAL_INTERNAL_DECLARATIONS
35 #include "nc/nc.h"
36 #include "nc/sca.h"
37 
38 #include <misc/options.h>
39 #include <coeffs/numbers.h>
40 #include "coeffrings.h"
41 
42 
43 // #include <kernel/p_Procs.h>
44 #include "monomials/ring.h"
45 #include "monomials/p_polys.h"
46 
47 #include "nc/ncSAMult.h" // for CMultiplier etc classes
48 // #include "nc/sca.h" // for SCA
49 
50 
51 namespace
52 {
53 
54 // poly functions defined in p_Procs: ;
55 static poly ggnc_pp_Mult_mm(const poly p, const poly m, const ring r)
56 {
57  if( (p == NULL) || (m == NULL) )
58  return NULL;
59 
60  assume( (p != NULL) && (m != NULL) && (r != NULL) );
61 
62 #if OUTPUT
63  PrintS("VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ggnc_pp_Mult_mm(p, m) VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ");
64  PrintLn();
65  PrintS("p: "); p_Write(p, r);
66  PrintS("m: "); p_Write(m, r);
67 #endif
68  poly pResult;
69 
70  if (p_IsConstant(m, r))
71  pResult = pp_Mult_nn(p, p_GetCoeff(m,r),r);
72  else
73  {
74  CGlobalMultiplier* const pMultiplier = r->GetNC()->GetGlobalMultiplier();
75  assume( pMultiplier != NULL );
76 
77  poly pMonom = pMultiplier->LM(m, r);
78  pResult = pMultiplier->MultiplyPE(p, pMonom);
79  p_Delete(&pMonom, r);
80  p_Test(pResult, r);
81  pResult = p_Mult_nn(pResult, p_GetCoeff(m, r), r);
82  }
83 
84 #if OUTPUT
85  p_Test(pResult, r);
86 
87  PrintS("ggnc_pp_Mult_mm(p, m) => "); p_Write(pResult, r);
88  PrintS("p: "); p_Write(p, r);
89  PrintS("m: "); p_Write(m, r);
90  PrintS("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ");
91  PrintLn();
92 #endif
93 
94  return pResult;
95 
96 }
97 
98 static poly ggnc_p_Mult_mm(poly p, const poly m, const ring r)
99 {
100  if( (p == NULL) || (m == NULL) )
101  {
102  p_Delete(&p, r);
103  return NULL;
104  }
105 
106  assume( (p != NULL) && (m != NULL) && (r != NULL) );
107 
108 #if OUTPUT
109  PrintS("VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ggnc_p_Mult_mm(p, m) VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ");
110  PrintLn();
111  PrintS("p: ");
112  p_Write(p, r);
113  PrintS("m: ");
114  p_Write(m, r);
115 #endif
116 
117  poly pResult;
118 
119  if (p_IsConstant(m, r))
120  pResult = p_Mult_nn(p, p_GetCoeff(m,r),r);
121  else
122  {
123  CGlobalMultiplier* const pMultiplier = r->GetNC()->GetGlobalMultiplier();
124  assume( pMultiplier != NULL );
125 
126  poly pMonom = pMultiplier->LM(m, r);
127  pResult = pMultiplier->MultiplyPEDestroy(p, pMonom);
128  p_Delete(&pMonom, r);
129  p_Test(pResult, r);
130  pResult = p_Mult_nn(pResult, p_GetCoeff(m, r), r);
131  }
132 
133 #if OUTPUT
134  p_Test(pResult, r);
135 
136  PrintS("ggnc_p_Mult_mm(p, m) => "); p_Write(pResult, r);
137 // PrintS("p: "); p_Write(p, r);
138  PrintS("m: "); p_Write(m, r);
139  PrintS("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ");
140  PrintLn();
141 #endif
142 
143  return pResult;
144 
145 }
146 
147 static poly ggnc_mm_Mult_p(const poly m, poly p, const ring r)
148 {
149  if( (p == NULL) || (m == NULL) )
150  {
151  p_Delete(&p, r);
152  return NULL;
153  }
154 
155  assume( (p != NULL) && (m != NULL) && (r != NULL) );
156 
157  p_Test(m, r);
158  p_Test(p, r);
159 
160 #if OUTPUT
161  PrintS("VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ggnc_mm_Mult_p(m, p) VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ");
162  PrintLn();
163  PrintS("m: "); p_Write(m, r);
164  PrintS("p: "); p_Write(p, r);
165 #endif
166 
167  poly pResult;
168 
169  if (p_IsConstant(m, r))
170  pResult = p_Mult_nn(p, p_GetCoeff(m,r),r);
171  else
172  {
173  CGlobalMultiplier* const pMultiplier = r->GetNC()->GetGlobalMultiplier();
174  assume( pMultiplier != NULL );
175 
176  poly pMonom = pMultiplier->LM(m, r);
177  pResult = pMultiplier->MultiplyEPDestroy(pMonom, p);
178  p_Delete(&pMonom, r);
179  p_Test(pResult, r);
180  pResult = p_Mult_nn(pResult, p_GetCoeff(m, r), r);
181  }
182 
183 #if OUTPUT
184  p_Test(pResult, r);
185 
186  PrintS("ggnc_mm_Mult_p(m, p) => "); p_Write(pResult, r);
187 // PrintS("p: "); p_Write(p, r);
188  PrintS("m: "); p_Write(m, r);
189  PrintS("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ");
190  PrintLn();
191 #endif
192 
193  return pResult;
194 }
195 
196 static poly ggnc_mm_Mult_pp(const poly m, const poly p, const ring r)
197 {
198  if( (p == NULL) || (m == NULL) )
199  {
200  return NULL;
201  }
202 
203  assume( (p != NULL) && (m != NULL) && (r != NULL) );
204 
205  p_Test(m, r);
206  p_Test(p, r);
207 
208 #if OUTPUT
209  PrintS("VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ggnc_mm_Mult_pp(m, p) VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ");
210  PrintLn();
211  PrintS("m: "); p_Write(m, r);
212  PrintS("p: "); p_Write(p, r);
213 #endif
214 
215  poly pResult;
216 
217  if (p_IsConstant(m, r))
218  pResult = pp_Mult_nn(p, p_GetCoeff(m,r),r);
219  else
220  {
221  CGlobalMultiplier* const pMultiplier = r->GetNC()->GetGlobalMultiplier();
222  assume( pMultiplier != NULL );
223 
224  poly pMonom = pMultiplier->LM(m, r);
225  pResult = pMultiplier->MultiplyEP(pMonom, p);
226  p_Delete(&pMonom, r);
227  p_Test(pResult, r);
228  pResult = p_Mult_nn(pResult, p_GetCoeff(m, r), r);
229  }
230 
231 #if OUTPUT
232  p_Test(pResult, r);
233 
234  PrintS("ggnc_mm_Mult_pp(m, p) => "); p_Write(pResult, r);
235  PrintS("p: "); p_Write(p, r);
236  PrintS("m: "); p_Write(m, r);
237  PrintS("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ");
238  PrintLn();
239 #endif
240 
241  return pResult;
242 }
243 
244 static void ggnc_p_ProcsSet(ring rGR, p_Procs_s* p_Procs)
245 {
246 #if OUTPUT
247  PrintS("|ggnc_p_ProcsSet()");
248  PrintLn();
249 #endif
250 
251  assume( p_Procs != NULL );
252 
253  // "commutative"
254  p_Procs->p_Mult_mm = rGR->p_Procs->p_Mult_mm = ggnc_p_Mult_mm;
255  p_Procs->pp_Mult_mm = rGR->p_Procs->pp_Mult_mm = ggnc_pp_Mult_mm;
256 
257  p_Procs->p_Minus_mm_Mult_qq = rGR->p_Procs->p_Minus_mm_Mult_qq = NULL;
258 
259  // non-commutaitve multiplication by monomial from the left
260  rGR->GetNC()->p_Procs.mm_Mult_p = ggnc_mm_Mult_p;
261  rGR->GetNC()->p_Procs.mm_Mult_pp = ggnc_mm_Mult_pp;
262 
263 }
264 
265 }
266 
268 {
269 #if OUTPUT
270  PrintS("ncInitSpecialPairMultiplication(ring), ring: \n");
271  rWrite(r, TRUE);
272  PrintLn();
273 #endif
274 
275  if(!rIsPluralRing(r))// ; // :(((
276  return TRUE;
277 
278  if(rIsSCA(r))
279  return TRUE;
280 
281  if( r->GetNC()->GetGlobalMultiplier() != NULL )
282  {
283  WarnS("Already defined!");
284  return TRUE;
285  }
286 
287  r->GetNC()->GetGlobalMultiplier() = new CGlobalMultiplier(r);
288 
289  ggnc_p_ProcsSet(r, r->p_Procs);
290  return FALSE; // ok!
291 }
292 
293 
295  CMultiplier<poly>(r), m_RingFormulaMultiplier(GetFormulaPowerMultiplier(r))
296 {
297 #if OUTPUT
298  PrintS("CGlobalMultiplier::CGlobalMultiplier(ring)!");
299  PrintLn();
300 #endif
301 
302 // m_cache = new CGlobalCacheHash(r);
303  m_powers = new CPowerMultiplier(r);
304 }
305 
306 
308 {
309 #if OUTPUT
310  PrintS("CGlobalMultiplier::~CGlobalMultiplier()!");
311  PrintLn();
312 #endif
313 
314 // delete m_cache;
315  delete m_powers;
316 
317  // we cannot delete m_RingFormulaMultiplier as it belongs to the ring!
318 }
319 
320 
321 
322 // Exponent * Exponent
323 // TODO: handle components!!!
325 {
326 
327  const ring r = GetBasering();
328 
329 #if OUTPUT
330  PrintS("CGlobalMultiplier::MultiplyEE(expLeft, expRight)!");
331  PrintLn();
332  PrintS("expL: "); p_Write(expLeft, GetBasering());
333  PrintS("expR: "); p_Write(expRight, GetBasering());
334 #endif
335 
336 // CCacheHash<poly>::CCacheItem* pLookup;
337 //
338 // int b = m_cache->LookupEE(expLeft, expRight, pLookup);
339 // // TODO!!!
340 //
341 // // up to now:
342 // assume( b == -1 );
343 
344  // TODO: use PowerMultiplier!!!!
345 
346  poly product = NULL;
347 
348  const int N = NVars();
349  int j = N;
350  int i = 1;
351 
352  int ej = p_GetExp(expLeft, j, r);
353  int ei = p_GetExp(expRight, i, r);
354 
355  while( (i < j) && !((ej != 0) && (ei != 0)) )
356  {
357  if( ei == 0 )
358  ei = p_GetExp(expRight, ++i, r);
359 
360  if( ej == 0 )
361  ej = p_GetExp(expLeft, --j, r);
362  }
363 
364 
365 #if OUTPUT
366  PrintS("<CGlobalMultiplier::MultiplyEE>");
367  PrintLn();
368  Print("i: %d, j: %d", i, j);
369  PrintLn();
370  Print("ei: %d, ej: %d", ei, ej);
371  PrintLn();
372 #endif
373 
374 
375  // | expLeft | * | expRight |
376  // |<<<< ej 0..0| , |0..0 ei >>>>|
377  // |<<<< j <<<N| , |1>>> i >>>>|
378 
379  if( i >= j ) // BUG here!!!???
380  {
381  // either i == j or i = j + 1 => commutative multiple!
382  // TODO: it can be done more efficiently! ()
383  product = p_Head(expRight, r);
384 
385  // | expLeft | * | expRight |
386  // |<<<< ej 0....0| , |0..00 ei >>>>|
387  // |<<<< j i <<<N| , |1>>>j i >>>>|
388 
389  if(i > j)
390  {
391  --i;
392  ei = 0;
393  }
394 
395  if( i == j )
396  {
397  if( ej != 0 )
398  p_SetExp(product, i, ei + ej, r);
399  }
400 
401  --i;
402 
403  for(; i > 0; --i)
404  {
405  const int e = p_GetExp(expLeft, i, r);
406 
407  if( e > 0 )
408  p_SetExp(product, i, e, r);
409  }
410 
411  p_Setm(product, r);
412 
413  } else
414  { // i < j, ei != 0, ej != 0
415 
417 
419  PairType = m_RingFormulaMultiplier->GetPair(i, j);
420 
421 
422  if( PairType == _ncSA_notImplemented )
423  product = m_powers->MultiplyEE( CPower(j, ej), CPower(i, ei) );
424 // return ggnc_uu_Mult_ww_vert(i, a, j, b, r);
425  else
426  // return m_RingFormulaMultiplier->Multiply(j, i, b, a);
427  product = CFormulaPowerMultiplier::Multiply( PairType, i, j, ei, ej, GetBasering());
428 
429 
430 #if OUTPUT
431  PrintS("<CGlobalMultiplier::MultiplyEE> ==> ");
432  PrintLn();
433  Print("i: %d, j: %d", i, j);
434  PrintLn();
435  Print("ei: %d, ej: %d", ei, ej);
436  PrintLn();
437  PrintS("<product>: "); p_Write(product, GetBasering());
438 #endif
439 
440 
441  // TODO: Choose some multiplication strategy!!!
442 
443  while( (product != NULL) && !((i == NVars()) && (j == 1)) )
444  {
445 
446  // make some choice here!:
447 
448  if( i < NVars() )
449  {
450  ei = p_GetExp(expRight, ++i, r);
451 
452  while( (ei == 0) && (i < NVars()) )
453  ei = p_GetExp(expRight, ++i, r);
454 
455  if( ei != 0 )
456  product = m_powers->MultiplyPEDestroy(product, CPower(i, ei));
457  }
458 
459  if( j > 1 )
460  {
461  ej = p_GetExp(expLeft, --j, r);
462 
463  while( (ej == 0) && (1 < j) )
464  ej = p_GetExp(expLeft, --j, r);
465 
466  if( ej != 0 )
467  product = m_powers->MultiplyEPDestroy(CPower(j, ej), product);
468  }
469 
470 
471 #if OUTPUT
472  PrintS("<CGlobalMultiplier::MultiplyEE> ==> ");
473  PrintLn();
474  Print("i: %d, j: %d", i, j);
475  PrintLn();
476  Print("ei: %d, ej: %d", ei, ej);
477  PrintLn();
478  PrintS("<product>: "); p_Write(product, GetBasering());
479 #endif
480 
481  }
482 
483  }
484 
485 // // TODO!
486 //
487 // m_cache->StoreEE( expLeft, expRight, product);
488 // // up to now:
489  return product;
490 }
491 
492  // Monom * Exponent
494 {
495 #if OUTPUT
496  PrintS("CGlobalMultiplier::MultiplyME(monom, expR)!");
497  PrintLn();
498  PrintS("Monom: "); p_Write(pMonom, GetBasering());
499  PrintS("expR: "); p_Write(expRight, GetBasering());
500 #endif
501 
502  return MultiplyEE(pMonom, expRight);
503 }
504 
505  // Exponent * Monom
507 {
508 #if OUTPUT
509  PrintS("CGlobalMultiplier::MultiplyEM(expL, monom)!");
510  PrintLn();
511  PrintS("expL: "); p_Write(expLeft, GetBasering());
512  PrintS("Monom: "); p_Write(pMonom, GetBasering());
513 #endif
514 
515  return MultiplyEE(expLeft, pMonom);
516 }
517 
518 
519 
520 
521 
522 ///////////////////////////////////////////////////////////////////////////////////////////
524  CSpecialPairMultiplier(r, i, j)
525 {
526 #if OUTPUT
527  Print("CCommutativeSpecialPairMultiplier::CCommutativeSpecialPairMultiplier(ring, i: %d, j: %d)!", i, j);
528  PrintLn();
529 #endif
530 }
531 
532 
534 {
535 #if OUTPUT
536  PrintS("CCommutativeSpecialPairMultiplier::~CCommutativeSpecialPairMultiplier()");
537  PrintLn();
538 #endif
539 }
540 
541 // Exponent * Exponent
542 poly CCommutativeSpecialPairMultiplier::MultiplyEE(const int expLeft, const int expRight)
543 {
544 #if OUTPUT
545  Print("CCommutativeSpecialPairMultiplier::MultiplyEE(var(%d)^{%d}, var(%d)^{%d})!", GetJ(), expLeft, GetI(), expRight);
546  PrintLn();
547 #endif
548 
549  const ring r = GetBasering();
550 
551  return CFormulaPowerMultiplier::ncSA_1xy0x0y0(GetI(), GetJ(), expRight, expLeft, r);
552 }
553 
554 ///////////////////////////////////////////////////////////////////////////////////////////
556  CSpecialPairMultiplier(r, i, j)
557 {
558 #if OUTPUT
559  Print("CAntiCommutativeSpecialPairMultiplier::CAntiCommutativeSpecialPairMultiplier(ring, i: %d, j: %d)!", i, j);
560  PrintLn();
561 #endif
562 }
563 
564 
566 {
567 #if OUTPUT
568  PrintS("CAntiCommutativeSpecialPairMultiplier::~CAntiCommutativeSpecialPairMultiplier()");
569  PrintLn();
570 #endif
571 }
572 
573 // Exponent * Exponent
574 poly CAntiCommutativeSpecialPairMultiplier::MultiplyEE(const int expLeft, const int expRight)
575 {
576 #if OUTPUT
577  Print("CAntiCommutativeSpecialPairMultiplier::MultiplyEE(var(%d)^{%d}, var(%d)^{%d})!", GetJ(), expLeft, GetI(), expRight);
578  PrintLn();
579 #endif
580 
581  const ring r = GetBasering();
582 
583  return CFormulaPowerMultiplier::ncSA_Mxy0x0y0(GetI(), GetJ(), expRight, expLeft, r);
584 }
585 
586 ///////////////////////////////////////////////////////////////////////////////////////////
588  CSpecialPairMultiplier(r, i, j), m_q(q)
589 {
590 #if OUTPUT
591  Print("CQuasiCommutativeSpecialPairMultiplier::CQuasiCommutativeSpecialPairMultiplier(ring, i: %d, j: %d, q)!", i, j);
592  PrintLn();
593  PrintS("Parameter q: ");
594  n_Write(q, r);
595 #endif
596 }
597 
598 
600 {
601 #if OUTPUT
602  PrintS("CQuasiCommutativeSpecialPairMultiplier::~CQuasiCommutativeSpecialPairMultiplier()");
603  PrintLn();
604 #endif
605 }
606 
607 // Exponent * Exponent
608 poly CQuasiCommutativeSpecialPairMultiplier::MultiplyEE(const int expLeft, const int expRight)
609 {
610 #if OUTPUT
611  Print("CQuasiCommutativeSpecialPairMultiplier::MultiplyEE(var(%d)^{%d}, var(%d)^{%d})!", GetJ(), expLeft, GetI(), expRight);
612  PrintLn();
613 #endif
614 
615  const ring r = GetBasering();
616 
617  return CFormulaPowerMultiplier::ncSA_Qxy0x0y0(GetI(), GetJ(), expRight, expLeft, m_q, r);
618 }
619 
620 
621 ///////////////////////////////////////////////////////////////////////////////////////////
623  CSpecialPairMultiplier(r, i, j), m_g(g)
624 {
625 #if OUTPUT
626  Print("CWeylSpecialPairMultiplier::CWeylSpecialPairMultiplier(ring, i: %d, j: %d, g)!", i, j);
627  PrintLn();
628  PrintS("Parameter g: ");
629  n_Write(g, r);
630 #endif
631 }
632 
633 
635 {
636 #if OUTPUT
637  PrintS("CWeylSpecialPairMultiplier::~CWeylSpecialPairMultiplier()");
638  PrintLn();
639 #endif
640 }
641 
642 // Exponent * Exponent
643 poly CWeylSpecialPairMultiplier::MultiplyEE(const int expLeft, const int expRight)
644 {
645 #if OUTPUT
646  Print("CWeylSpecialPairMultiplier::MultiplyEE(var(%d)^{%d}, var(%d)^{%d})!", GetJ(), expLeft, GetI(), expRight);
647  PrintLn();
648 #endif
649  // Char == 0, otherwise - problem!
650 
651 
652  const ring r = GetBasering();
653 
654  assume( expLeft*expRight > 0 );
655 
656  return CFormulaPowerMultiplier::ncSA_1xy0x0yG(GetI(), GetJ(), expRight, expLeft, m_g, r);
657 }
658 
659 ///////////////////////////////////////////////////////////////////////////////////////////
661  CSpecialPairMultiplier(r, i, j), m_k(k)
662 {
663 #if OUTPUT
664  Print("CHWeylSpecialPairMultiplier::CHWeylSpecialPairMultiplier(ring, i: %d, j: %d, k: %d)!", i, j, k);
665  PrintLn();
666 #endif
667 }
668 
669 
671 {
672 #if OUTPUT
673  PrintS("CHWeylSpecialPairMultiplier::~CHWeylSpecialPairMultiplier()");
674  PrintLn();
675 #endif
676 }
677 
678 // Exponent * Exponent
679 poly CHWeylSpecialPairMultiplier::MultiplyEE(const int expLeft, const int expRight)
680 {
681 #if OUTPUT
682  Print("CHWeylSpecialPairMultiplier::MultiplyEE(var(%d)^{%d}, var(%d)^{%d})!", GetJ(), expLeft, GetI(), expRight);
683  PrintLn();
684 #endif
685  // Char == 0, otherwise - problem!
686 
687 
688  const ring r = GetBasering();
689 
690  assume( expLeft*expRight > 0 );
691 
692  return CFormulaPowerMultiplier::ncSA_1xy0x0yT2(GetI(), GetJ(), expRight, expLeft, m_k, r);
693 }
694 
695 
696 ///////////////////////////////////////////////////////////////////////////////////////////
698  CSpecialPairMultiplier(r, i, j), m_shiftCoef(c), m_shiftVar(s)
699 {
700 #if OUTPUT
701  Print("CShiftSpecialPairMultiplier::CShiftSpecialPairMultiplier(ring, i: %d, j: %d, s: %d, c)!", i, j, s);
702  PrintLn();
703  PrintS("Parameter c: "); n_Write(c, r);
704 #endif
705 }
706 
707 
709 {
710 #if OUTPUT
711  PrintS("CShiftSpecialPairMultiplier::~CShiftSpecialPairMultiplier()");
712  PrintLn();
713 #endif
714 }
715 
716 // Exponent * Exponent
717 poly CShiftSpecialPairMultiplier::MultiplyEE(const int expLeft, const int expRight)
718 {
719 #if OUTPUT
720  Print("CShiftSpecialPairMultiplier::MultiplyEE(var(%d)^{%d}, var(%d)^{%d})!", GetJ(), expLeft, GetI(), expRight);
721  PrintLn();
722 #endif
723  // Char == 0, otherwise - problem!
724 
725  assume( expLeft*expRight > 0 );
726 
727  const ring r = GetBasering();
728 
729  if( m_shiftVar != GetI() ) // YX = XY + b*Y?
730  return CFormulaPowerMultiplier::ncSA_1xy0xBy0(GetI(), GetJ(), expRight, expLeft, m_shiftCoef, r); // case: (1, 0, beta, 0, 0)
731  else
732  return CFormulaPowerMultiplier::ncSA_1xyAx0y0(GetI(), GetJ(), expRight, expLeft, m_shiftCoef, r); // case: (1, alpha, 0, 0)
733 
734 }
735 
736 
737 
738 ///////////////////////////////////////////////////////////////////////////////////////////
740  CSpecialPairMultiplier(r, i, j), m_ncSAtype(type)
741 {
742 #if OUTPUT
743  Print("CExternalSpecialPairMultiplier::CExternalSpecialPairMultiplier(ring, i: %d, j: %d, type: %d, c)!", i, j, (int)type);
744  PrintLn();
745 #endif
746 }
747 
748 
750 {
751 #if OUTPUT
752  PrintS("CExternalSpecialPairMultiplier::~CExternalSpecialPairMultiplier()");
753  PrintLn();
754 #endif
755 }
756 
757 // Exponent * Exponent
758 poly CExternalSpecialPairMultiplier::MultiplyEE(const int expLeft, const int expRight)
759 {
760 #if OUTPUT
761  Print("CExternalSpecialPairMultiplier::MultiplyEE(var(%d)^{%d}, var(%d)^{%d})!", GetJ(), expLeft, GetI(), expRight);
762  PrintLn();
763 #endif
764  // Char == 0, otherwise - problem!
765 
766  assume( expLeft*expRight > 0 );
767 
768  const ring r = GetBasering();
769 
770  return CFormulaPowerMultiplier::Multiply(m_ncSAtype, GetI(), GetJ(), expRight, expLeft, r);
771 
772 }
773 
774 
775 
776 ///////////////////////////////////////////////////////////////////////////////////////////
777 
778 // factory method!
779 CSpecialPairMultiplier* AnalyzePair(const ring r, int i, int j)
780 {
781 #if OUTPUT
782  Print("AnalyzePair(ring, i: %d, j: %d)!", i, j);
783  PrintLn();
784 #endif
785 
787 
788  if( type == _ncSA_notImplemented ) return NULL;
789 
790 
791  // last possibility:
792  return new CExternalSpecialPairMultiplier(r, i, j, type); // For tests!
793 
794 
795  if( type == _ncSA_1xy0x0y0 )
796  return new CCommutativeSpecialPairMultiplier(r, i, j);
797 
798  if( type == _ncSA_Mxy0x0y0 )
799  return new CAntiCommutativeSpecialPairMultiplier(r, i, j);
800 
801  if( type == _ncSA_Qxy0x0y0 )
802  {
803  const number q = p_GetCoeff(GetC(r, i, j), r);
804  return new CQuasiCommutativeSpecialPairMultiplier(r, i, j, q);
805  }
806 
807  const poly d = GetD(r, i, j);
808 
809  assume( d != NULL );
810  assume( pNext(d) == NULL );
811 
812  const number g = p_GetCoeff(d, r);
813 
814  if( type == _ncSA_1xy0x0yG ) // Weyl
815  return new CWeylSpecialPairMultiplier(r, i, j, g);
816 
817  if( type == _ncSA_1xyAx0y0 ) // Shift 1
818  return new CShiftSpecialPairMultiplier(r, i, j, i, g);
819 
820  if( type == _ncSA_1xy0xBy0 ) // Shift 2
821  return new CShiftSpecialPairMultiplier(r, i, j, j, g);
822 
823  if( type == _ncSA_1xy0x0yT2 ) // simple homogenized Weyl algebra
824  return new CHWeylSpecialPairMultiplier(r, i, j, p_IsPurePower(d, r));
825 
826 }
827 
828 
829 
830 
831 
832 
834 {
835 #if OUTPUT
836  PrintS("CPowerMultiplier::CPowerMultiplier(ring)!");
837  PrintLn();
838 #endif
839 
841 
842  for( int i = 1; i < NVars(); i++ )
843  for( int j = i + 1; j <= NVars(); j++ )
844  GetPair(i, j) = AnalyzePair(GetBasering(), i, j); // factory method!
845 }
846 
847 
849 {
850 #if OUTPUT
851  PrintS("CPowerMultiplier::~CPowerMultiplier()!");
852  PrintLn();
853 #endif
854 
855  omFreeSize((ADDRESS)m_specialpairs, ((NVars() * (NVars()-1)) / 2) * sizeof(CSpecialPairMultiplier*) );
856 }
857 
858 
859 // Monom * Exponent
860 // pMonom may NOT be of the form: var(j)^{n}!
861 poly CPowerMultiplier::MultiplyME(const poly pMonom, const CExponent expRight)
862 {
863  const int j = expRight.Var;
864  const int n = expRight.Power;
865 
866  const ring r = GetBasering();
867 
868 #if OUTPUT
869  Print("CPowerMultiplier::MultiplyME(monom * var(%d)^{%d})!", j, n);
870  PrintLn();
871  PrintS("Monom: "); p_Write(pMonom, r);
872 #endif
873 
874  assume( (j > 0) && (j <= NVars()));
875 
876  if( n == 0 )
877  return p_Head(pMonom, r); // Copy?!?
878 
879 
880  int v = NVars();
881  int e = p_GetExp(pMonom, v, r);
882 
883  while((v > j) && (e == 0))
884  e = p_GetExp(pMonom, --v, r);
885 
886  // TODO: review this!
887  if( v == j )
888  {
889  poly p = p_Head(pMonom, r);
890  p_SetExp(p, v, e + n, r);
891  p_Setm(p, r);
892 
893  return p;
894  }
895 
896  assume( v > j );
897  assume( e > 0 );
898 
899  // And now the General Case: v > j!
900 
901  poly p = MultiplyEE( CPower(v, e), expRight ); // Easy way!
902 
903  --v;
904 
905  while(v > 0)
906  {
907  e = p_GetExp(pMonom, v, GetBasering());
908 
909  if( e > 0 )
910  p = MultiplyEPDestroy(CPower(v, e), p);
911 
912  --v;
913  }
914 
915 #if OUTPUT
916  PrintS("CPowerMultiplier::MultiplyME() ===> ");
917  p_Write(p, GetBasering());
918 #endif
919 
920  return p;
921 }
922 
923 // Exponent * Monom
924 // pMonom may NOT be of the form: var(i)^{m}!
925 poly CPowerMultiplier::MultiplyEM(const CExponent expLeft, const poly pMonom)
926 {
927  const ring r = GetBasering();
928 
929  // TODO: as above! (difference due to Left/Right semmantics!)
930  const int j = expLeft.Var;
931  const int n = expLeft.Power;
932 
933 #if OUTPUT
934  Print("CPowerMultiplier::MultiplyEM(var(%d)^{%d} * monom)!", j, n);
935  PrintLn();
936  PrintS("Monom: "); p_Write(pMonom, r);
937 #endif
938 
939  assume( (j > 0) && (j <= NVars()));
940 
941  if( n == 0 )
942  return p_Head(pMonom, r); // Copy?!?
943 
944 
945  int v = 1; // NVars();
946  int e = p_GetExp(pMonom, v, r);
947 
948  while((v < j) && (e == 0))
949  e = p_GetExp(pMonom, ++v, r);
950 
951  if( v == j )
952  {
953  poly p = p_Head(pMonom, r);
954  p_SetExp(p, j, e + n, r);
955  p_Setm(p, r);
956 
957  return p;
958  }
959 
960  assume( v < j );
961  assume( e > 0 );
962 
963 
964  // And now the General Case: v > j!
965 
966  poly p = MultiplyEE( expLeft, CPower(v, e) ); // Easy way!
967 
968  ++v;
969 
970  while(v <= NVars())
971  {
972  e = p_GetExp(pMonom, v, r);
973 
974  if( e > 0 )
975  p = MultiplyPEDestroy(p, CPower(v, e));
976 
977  ++v;
978  }
979 
980 #if OUTPUT
981  PrintS("CPowerMultiplier::MultiplyEM() ===> ");
982  p_Write(p, r);
983 #endif
984 
985  return p;
986 
987 }
988 
989 
990 // Exponent * Exponent
991 // Computes: var(j)^{expLeft} * var(i)^{expRight}
992 poly CPowerMultiplier::MultiplyEE(const CExponent expLeft, const CExponent expRight)
993 {
994 #if OUTPUT
995  PrintS("CPowerMultiplier::MultiplyEE)!");
996  PrintLn();
997 #endif
998 
999  const int i = expRight.Var, j = expLeft.Var;
1000  const int ei = expRight.Power, ej = expLeft.Power;
1001 
1002 #if OUTPUT
1003  Print("Input: var(%d)^{%d} * var(%d)^{%d}", j, ej, i, ei);
1004  PrintLn();
1005 #endif
1006 
1007  assume(1 <= i);
1008  assume(j <= NVars());
1009  assume(1 <= j);
1010  assume(i <= NVars());
1011  assume(ei > 0);
1012  assume(ej > 0);
1013 
1014  if( i >= j )
1015  {
1016  const ring r = GetBasering();
1017 
1018  poly product = p_One(r);
1019  p_SetExp(product, j, ej, r);
1020  p_SetExp(product, i, ei, r);
1021  p_Setm(product, r);
1022 
1023  return product;
1024 
1025  } else
1026  {
1027  assume(i < j);
1028 
1029  // No Cache Lookup!? :(
1030 
1031  CSpecialPairMultiplier* pSpecialMultiplier = GetPair(i, j);
1032 
1033  // Special case?
1034  if( pSpecialMultiplier != NULL )
1035  {
1036  assume( pSpecialMultiplier->GetI() == i );
1037  assume( pSpecialMultiplier->GetJ() == j );
1038  assume( pSpecialMultiplier->GetBasering() == GetBasering() );
1039 
1040  return pSpecialMultiplier->MultiplyEE(ej, ei);
1041  } else
1042  {
1043  // Perform general NC Multiplication:
1044  // TODO
1045 
1046  WerrorS("Sorry the general case is not implemented this way yet!!!");
1047  assume(0);
1048 
1049  // poly product = NULL;
1050  }
1051  }
1052 
1053  return NULL;
1054 }
1055 
1056 
1057 
1058 
1059 
1060 
1062  CMultiplier<int>(r), m_i(i), m_j(j)
1063 {
1064 #if OUTPUT
1065  Print("CSpecialPairMultiplier::CSpecialPairMultiplier(ring, i: %d, j: %d)!", i, j);
1066  PrintLn();
1067 #endif
1068 
1069  assume(i < j);
1070  assume(i > 0);
1071  assume(j <= NVars());
1072 }
1073 
1074 
1076 {
1077 #if OUTPUT
1078  PrintS("CSpecialPairMultiplier::~CSpecialPairMultiplier()!");
1079  PrintLn();
1080 #endif
1081 }
1082 
1083 
1084 
1085 // Monom * Exponent
1087 {
1088 #if OUTPUT
1089  Print("CSpecialPairMultiplier::MultiplyME(monom, var(%d)^{%d})!", GetI(), expRight);
1090  PrintLn();
1091  PrintS("Monom: "); p_Write(pMonom, GetBasering());
1092 #endif
1093 
1094  return MultiplyEE(p_GetExp(pMonom, GetJ(), GetBasering()), expRight);
1095 }
1096 
1097  // Exponent * Monom
1099 {
1100 #if OUTPUT
1101  Print("CSpecialPairMultiplier::MultiplyEM(var(%d)^{%d}, monom)!", GetJ(), expLeft);
1102  PrintLn();
1103  PrintS("Monom: "); p_Write(pMonom, GetBasering());
1104 #endif
1105 
1106  return MultiplyEE(expLeft, p_GetExp(pMonom, GetI(), GetBasering()));
1107 }
1108 
1109 template class CMultiplier<CPower>;
1110 template class CMultiplier<int>;
1111 template class CMultiplier<spolyrec*>;
1112 
1113 
1114 #endif
CPowerMultiplier(ring r)
Definition: ncSAMult.cc:833
CSpecialPairMultiplier * AnalyzePair(const ring r, int i, int j)
Definition: ncSAMult.cc:779
static poly ncSA_1xy0x0yG(const int i, const int j, const int n, const int m, const number m_g, const ring r)
Definition: ncSAFormula.cc:730
ring GetBasering() const
Definition: ncSAMult.h:40
CAntiCommutativeSpecialPairMultiplier(ring r, int i, int j)
Definition: ncSAMult.cc:555
const CanonicalForm int s
Definition: facAbsFact.cc:55
virtual ~CWeylSpecialPairMultiplier()
Definition: ncSAMult.cc:634
virtual poly MultiplyME(const poly pMonom, const CExponent expRight)
Definition: ncSAMult.cc:493
void PrintLn()
Definition: reporter.cc:310
#define Print
Definition: emacs.cc:83
static poly ncSA_Mxy0x0y0(const int i, const int j, const int n, const int m, const ring r)
Definition: ncSAFormula.cc:720
static CFormulaPowerMultiplier * GetFormulaPowerMultiplier(const ring r)
Definition: ncSAFormula.h:95
virtual poly MultiplyEE(const int expLeft, const int expRight)
Definition: ncSAMult.cc:574
CSpecialPairMultiplier ** m_specialpairs
Definition: ncSAMult.h:171
#define FALSE
Definition: auxiliary.h:97
static poly ncSA_1xyAx0y0(const int i, const int j, const int n, const int m, const number m_shiftCoef, const ring r)
Definition: ncSAFormula.cc:740
return P p
Definition: myNF.cc:203
poly LM(const poly pTerm, const ring r, int i=1) const
Definition: ncSAMult.h:44
int GetI() const
Definition: ncSAMult.h:113
struct p_Procs_s p_Procs_s
Definition: ring.h:29
static poly pp_Mult_nn(poly p, number n, const ring r)
Definition: p_polys.h:922
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
CWeylSpecialPairMultiplier(ring r, int i, int j, number g)
Definition: ncSAMult.cc:622
poly MultiplyEPDestroy(const CExponent expLeft, poly pPoly)
Definition: ncSAMult.h:452
virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom)
Definition: ncSAMult.cc:1098
static poly ncSA_1xy0xBy0(const int i, const int j, const int n, const int m, const number m_shiftCoef, const ring r)
Definition: ncSAFormula.cc:745
const CFormulaPowerMultiplier * m_RingFormulaMultiplier
Definition: ncSAMult.h:273
#define TRUE
Definition: auxiliary.h:101
int Var
Definition: ncSAMult.h:139
poly MultiplyPEDestroy(poly pPoly, const CExponent expRight)
Definition: ncSAMult.h:240
void * ADDRESS
Definition: auxiliary.h:118
CShiftSpecialPairMultiplier(ring r, int i, int j, int s, number c)
Definition: ncSAMult.cc:697
g
Definition: cfModGcd.cc:4031
void WerrorS(const char *s)
Definition: feFopen.cc:24
int k
Definition: cfEzgcd.cc:93
int Power
Definition: ncSAMult.h:140
#define WarnS
Definition: emacs.cc:81
Enum_ncSAType GetPair(int i, int j) const
Definition: ncSAFormula.h:46
static poly Multiply(Enum_ncSAType type, const int i, const int j, const int n, const int m, const ring r)
Definition: ncSAFormula.cc:696
CPowerMultiplier * m_powers
Definition: ncSAMult.h:272
static poly ncSA_Qxy0x0y0(const int i, const int j, const int n, const int m, const number m_q, const ring r)
Definition: ncSAFormula.cc:725
static Enum_ncSAType AnalyzePair(const ring r, int i, int j)
Definition: ncSAFormula.cc:702
CSpecialPairMultiplier(ring r, int i, int j)
Definition: ncSAMult.cc:1061
virtual poly MultiplyME(const poly pMonom, const CExponent expRight)
Definition: ncSAMult.cc:1086
int GetJ() const
Definition: ncSAMult.h:114
static poly p_Head(poly p, const ring r)
Definition: p_polys.h:812
virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom)
Definition: ncSAMult.cc:925
const ring r
Definition: syzextra.cc:208
virtual ~CShiftSpecialPairMultiplier()
Definition: ncSAMult.cc:708
poly MultiplyPEDestroy(poly pPoly, const CExponent expRight)
Definition: ncSAMult.h:398
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
poly p_One(const ring r)
Definition: p_polys.cc:1313
virtual poly MultiplyEE(const int expLeft, const int expRight)
Definition: ncSAMult.cc:542
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent : the integer VarOffset encodes:
Definition: p_polys.h:464
virtual poly MultiplyEE(const int expLeft, const int expRight)
Definition: ncSAMult.cc:643
int j
Definition: myNF.cc:70
CGlobalMultiplier(ring r)
Definition: ncSAMult.cc:294
#define assume(x)
Definition: mod2.h:403
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition: ring.h:404
static BOOLEAN p_IsConstant(const poly p, const ring r)
Definition: p_polys.h:1876
poly MultiplyEP(const CExponent expLeft, const poly pPoly)
Definition: ncSAMult.h:354
virtual ~CGlobalMultiplier()
Definition: ncSAMult.cc:307
virtual poly MultiplyEE(const CExponent expLeft, const CExponent expRight)
Definition: ncSAMult.cc:992
static FORCE_INLINE void n_Write(number &n, const coeffs r, const BOOLEAN bShortOut=TRUE)
Definition: coeffs.h:595
CCommutativeSpecialPairMultiplier(ring r, int i, int j)
Definition: ncSAMult.cc:523
int NVars() const
Definition: ncSAMult.h:41
All the auxiliary stuff.
int m
Definition: cfEzgcd.cc:119
int i
Definition: cfEzgcd.cc:123
void PrintS(const char *s)
Definition: reporter.cc:284
static poly p_Mult_nn(poly p, number n, const ring r)
Definition: p_polys.h:895
CHWeylSpecialPairMultiplier(ring r, int i, int j, int k)
Definition: ncSAMult.cc:660
void rWrite(ring r, BOOLEAN details)
Definition: ring.cc:236
virtual poly MultiplyEE(const int expLeft, const int expRight)
Definition: ncSAMult.cc:758
#define p_Test(p, r)
Definition: p_polys.h:160
virtual ~CPowerMultiplier()
Definition: ncSAMult.cc:848
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:843
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent : VarOffset encodes the position in p->exp
Definition: p_polys.h:483
const number m_shiftCoef
Definition: ncSAMult.h:578
int p_IsPurePower(const poly p, const ring r)
return i, if head depends only on var(i)
Definition: p_polys.cc:1226
virtual poly MultiplyEE(const CExponent expLeft, const CExponent expRight)=0
#define NULL
Definition: omList.c:10
virtual poly MultiplyEE(const int expLeft, const int expRight)
Definition: ncSAMult.cc:717
virtual ~CSpecialPairMultiplier()
Definition: ncSAMult.cc:1075
static poly ncSA_1xy0x0yT2(const int i, const int j, const int n, const int m, const int k, const ring r)
Definition: ncSAFormula.cc:735
CSpecialPairMultiplier * GetPair(int i, int j) const
Definition: ncSAMult.h:178
static bool rIsSCA(const ring r)
Definition: nc.h:206
#define pNext(p)
Definition: monomials.h:43
BOOLEAN ncInitSpecialPairMultiplication(ring r)
Definition: ncSAMult.cc:267
CQuasiCommutativeSpecialPairMultiplier(ring r, int i, int j, number q)
Definition: ncSAMult.cc:587
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:228
#define p_GetCoeff(p, r)
Definition: monomials.h:57
virtual ~CCommutativeSpecialPairMultiplier()
Definition: ncSAMult.cc:533
virtual poly MultiplyEE(const CExponent expLeft, const CExponent expRight)
Definition: ncSAMult.cc:324
static poly GetC(const ring r, int i, int j)
Definition: nc.h:397
virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom)
Definition: ncSAMult.cc:506
poly MultiplyEPDestroy(const CExponent expLeft, poly pPoly)
Definition: ncSAMult.h:252
void p_Write(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:206
poly MultiplyPE(const poly pPoly, const CExponent expRight)
Definition: ncSAMult.h:301
virtual poly MultiplyEE(const int expLeft, const int expRight)
Definition: ncSAMult.cc:608
virtual ~CExternalSpecialPairMultiplier()
Definition: ncSAMult.cc:749
polyrec * poly
Definition: hilb.h:10
static poly ncSA_1xy0x0y0(const int i, const int j, const int n, const int m, const ring r)
Definition: ncSAFormula.cc:715
int BOOLEAN
Definition: auxiliary.h:88
virtual poly MultiplyME(const poly pMonom, const CExponent expRight)
Definition: ncSAMult.cc:861
#define omAlloc0(size)
Definition: omAllocDecl.h:211
Enum_ncSAType
Definition: ncSAFormula.h:17
virtual poly MultiplyEE(const int expLeft, const int expRight)
Definition: ncSAMult.cc:679
virtual ~CHWeylSpecialPairMultiplier()
Definition: ncSAMult.cc:670
CExternalSpecialPairMultiplier(ring r, int i, int j, Enum_ncSAType type)
Definition: ncSAMult.cc:739
static poly GetD(const ring r, int i, int j)
Definition: nc.h:408