source: git/kernel/ncSAMult.cc @ 61944d0

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