source: git/kernel/ncSAMult.cc @ 098f98f

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