source: git/kernel/ncSAMult.cc @ cafd4ff

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