Changeset 1495df4 in git


Ignore:
Timestamp:
Jul 15, 2008, 6:27:58 PM (15 years ago)
Author:
Motsak Oleksandr <motsak@…>
Branches:
(u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
Children:
e3164c057b351ebc7de36b8955221b4cb648bdbe
Parents:
67dbdb5d3b02ace5998471f519c0e9ae91a1c63b
Message:
*motsak: special multiplication


git-svn-id: file:///usr/local/Singular/svn/trunk@10868 2c84dea3-7e68-4137-9b89-c4e89433aadc
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • Singular/claptmpl.cc

    r67dbdb r1495df4  
    33*  Computer Algebra System SINGULAR     *
    44****************************************/
    5 // $Id: claptmpl.cc,v 1.42 2007-02-23 13:17:55 bricken Exp $
     5// $Id: claptmpl.cc,v 1.43 2008-07-15 16:27:11 motsak Exp $
    66/*
    77* ABSTRACT - instantiation of all templates
     
    202202//  end of file
    203203// ----------------------------------------------------------------------------
     204
     205#ifdef HAVE_PLURAL
     206
     207#include <ncSACache.h> // for CCacheHash etc classes
     208#include <ncSAMult.h> // for CMultiplier etc classes
     209
     210template class CMultiplier<int>;
     211template class CMultiplier<poly>;
     212template class CMultiplier<CPower>;
     213
     214template class CCacheHash<poly>;
     215template class CCacheHash<int>;
     216
     217#endif
     218
    204219#include "tgb_internal.h"
    205220#ifdef HAVE_BOOST
  • Singular/extra.cc

    r67dbdb r1495df4  
    22*  Computer Algebra System SINGULAR      *
    33*****************************************/
    4 /* $Id: extra.cc,v 1.275 2008-07-08 13:03:18 Singular Exp $ */
     4/* $Id: extra.cc,v 1.276 2008-07-15 16:27:11 motsak Exp $ */
    55/*
    66* ABSTRACT: general interface to internals of Singular ("system" command)
     
    8888#include "gring.h"
    8989#include "sca.h"
     90#include <ncSAMult.h> // for CMultiplier etc classes
    9091#include "ipconv.h"
    9192#include "ratgring.h"
     
    788789     
    789790      return FALSE;
    790     }   
     791    }
     792
     793   
    791794    if(strcmp(sys_cmd,"NCGetType")==0)
    792795    {
     
    801804    }
    802805
     806   
    803807    if(strcmp(sys_cmd,"ForceSCA")==0)
    804808    {
     
    827831      return FALSE;
    828832    }
    829 /*==================== PLURAL =================*/
     833
     834    if(strcmp(sys_cmd,"ForceNewNCMultiplication")==0)
     835    {
     836      if( !rIsPluralRing(currRing) )
     837        return TRUE;
     838
     839      if( !ncInitSpecialPairMultiplication(currRing) )
     840        return TRUE;
     841
     842      return FALSE;
     843    }
     844
     845    /*==================== PLURAL =================*/
    830846/*==================== opp ==================================*/
    831847    if (strcmp(sys_cmd, "opp")==0)
  • kernel/Makefile.in

    r67dbdb r1495df4  
    9494    febase.cc feread.cc feResource.cc \
    9595    ffields.cc hdegree.cc hilb.cc hutil.cc \
    96     sca.cc gring.cc gr_kstd2.cc summator.cc\
     96    sca.cc gring.cc gr_kstd2.cc summator.cc ncSAMult.cc ncSACache.cc \
    9797    ideals.cc intvec.cc int64vec.cc \
    9898    khstd.cc kstdfac.cc \
     
    155155        ring.h timer.h dError.h fast_maps.h \
    156156        febase.h shortfl.h mpr_complex.h mpr_global.h \
    157         summator.h sca.h gring.h \
     157        summator.h ncSAMult.h ncSACache.h sca.h gring.h \
    158158        walkProc.h walkMain.h walkSupport.h\
    159159        ffields.h khstd.h sparsmat.h gnumpfl.h gnumpc.h \
  • kernel/gring.cc

    r67dbdb r1495df4  
    77 *  Author:  levandov (Viktor Levandovsky)
    88 *  Created: 8/00 - 11/00
    9  *  Version: $Id: gring.cc,v 1.60 2008-07-08 11:28:21 Singular Exp $
     9 *  Version: $Id: gring.cc,v 1.61 2008-07-15 16:27:58 motsak Exp $
    1010 *******************************************************************/
    1111
     
    4242#include "sca.h"
    4343#include <summator.h>
     44
     45#include <ncSAMult.h> // for CMultiplier etc classes
    4446
    4547
     
    25462548
    25472549  assume( r->GetNC()->ref == 0 );
     2550
     2551  if( rIsSCA(r) && (r->GetNC()->GetGlobalMultiplier() != NULL) )
     2552  {
     2553    delete r->GetNC()->GetGlobalMultiplier();
     2554    r->GetNC()->GetGlobalMultiplier() = NULL;
     2555  }
    25482556
    25492557  int i,j;
  • kernel/gring.h

    r67dbdb r1495df4  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: gring.h,v 1.24 2008-07-02 18:07:10 motsak Exp $ */
     6/* $Id: gring.h,v 1.25 2008-07-15 16:27:58 motsak Exp $ */
    77/*
    88* ABSTRACT additional defines etc for --with-plural
     
    1414#include <structs.h>
    1515#include <ring.h>
     16#include <matpol.h>
    1617
    1718// the part, related to the interface
     
    247248
    248249
     250// inline const nc_struct* GetNC() const { return GetBasering()->GetNC(); };
     251
     252
     253// read only access to NC matrices C/D:
     254// get C_{i,j}, 1 <= row = i < j = col <= N
     255inline poly GetC( const ring r, int i, int j )
     256{
     257  assume(r!= NULL && rIsPluralRing(r));
     258  const matrix C = GetNC(r)->C;
     259  assume(C != NULL);
     260  const int ncols = C->ncols;
     261  assume( (i > 0) && (i < j) && (j <= ncols) );
     262  return ( C->m[ncols * ((i)-1) + (j)-1] );
     263};
     264
     265// get D_{i,j}, 1 <= row = i < j = col <= N
     266inline poly GetD( const ring r, int i, int j )
     267{
     268  assume(r!= NULL && rIsPluralRing(r));
     269  const matrix D = GetNC(r)->D;
     270  assume(D != NULL);
     271  const int ncols = D->ncols;
     272  assume( (i > 0) && (i < j) && (j <= ncols) );
     273  return ( D->m[ncols * ((i)-1) + (j)-1] );
     274};
     275
     276
    249277#ifdef PLURAL_INTERNAL_DECLARATIONS
    250278
  • kernel/ncSACache.cc

    r67dbdb r1495df4  
    33****************************************/
    44/***************************************************************
    5  *  File:    ncSAMult.cc
    6  *  Purpose: implementation of multiplication in simple NC subalgebras
     5 *  File:    ncSACache.cc
     6 *  Purpose: implementation of special Cache+Hash for Multiplier
    77 *  Author:  motsak
    88 *  Created:
    9  *  Version: $Id: ncSACache.cc,v 1.1 2008-07-11 15:53:28 motsak Exp $
     9 *  Version: $Id: ncSACache.cc,v 1.2 2008-07-15 16:27:58 motsak Exp $
    1010 *******************************************************************/
    1111
    1212
    13 #define MYTEST 0
    14 #define OUTPUT 0
     13#define MYTEST 1
     14#define OUTPUT 1
    1515
    1616#if MYTEST
     
    2828
    2929
    30 virtual void CGlobalCacheHash::History(const CGlobalCacheHash::CExponent a, const CGlobalCacheHash::CExponent b, const EHistoryType t)
     30void CGlobalCacheHash::History(const CGlobalCacheHash::CExponent a, const CGlobalCacheHash::CExponent b, const EHistoryType t)
    3131{
    32   Print("GlobalPair!");
     32  Print("History: GlobalPair!");
     33  PrintS("Left : "); p_Write(a, GetBasering());
     34  PrintS("Right: "); p_Write(b, GetBasering());   
    3335}
    3436
    3537
    36 virtual void CSpecialPairCacheHash::History(const CSpecialPairCacheHash::CExponent a, const CSpecialPairCacheHash::CExponent b, const EHistoryType t)
     38void CSpecialPairCacheHash::History(const CSpecialPairCacheHash::CExponent a, const CSpecialPairCacheHash::CExponent b, const EHistoryType t)
    3739{
    3840  Print("SpecialPair!\n");
     41  Print("Left : %d, Right: %d\n", a, b);
    3942}
  • kernel/ncSACache.h

    r67dbdb r1495df4  
    1 #ifndef GRING_SA_MULT_H
    2 #define GRING_SA_MULT_H
     1#ifndef GRING_SA_CACHEHASH_H
     2#define GRING_SA_CACHEHASH_H
    33/*****************************************
    44 *  Computer Algebra System SINGULAR     *
    55 *****************************************/
    6 /* $Id: ncSACache.h,v 1.1 2008-07-11 15:53:28 motsak Exp $ */
     6/* $Id: ncSACache.h,v 1.2 2008-07-15 16:27:58 motsak Exp $ */
    77
    88// #include <ncSACache.h> // for CCacheHash etc classes
    99
    1010#include <structs.h>
    11 
     11#include <febase.h> // for Print!
    1212// //////////////////////////////////////////////////////////////////////// //
    1313//
    14 
    15 
    1614
    1715const int iMaxCacheSize = 20;
     
    2018class CCacheHash
    2119{
     20  private:
     21    ring m_basering;
     22    int m_NVars;
     23   
    2224  public:
     25    CCacheHash(ring r): m_basering(r), m_NVars(r->N){};
     26
     27    const ring GetBasering() const { return m_basering; };
     28    inline int NVars() const { return m_NVars; }
     29   
     30    virtual ~CCacheHash(){};
     31   
    2332    enum EHistoryType {
    2433      MULT_LOOKUP
    25     }
     34    };
    2635
    2736    struct CCacheItem
     
    4554   
    4655    // -1 means no hits!
    47     int Lookup(CExponent a, CExponent b, CCacheItem*& pItems) const
     56    int LookupEE(CExponent a, CExponent b, CCacheItem*& pItems)
    4857    {
    4958      History(a, b, MULT_LOOKUP);
     
    5261    }
    5362
    54     bool Store(CExponent a, CExponent b, poly pProduct)
     63    bool StoreEE(CExponent a, CExponent b, poly pProduct)
    5564    {
     65      Print("StoreEE!\n");
    5666      return false; // the pair was not stored!
    5767    };
     
    5969    virtual void History(const CExponent a, const CExponent b, const EHistoryType t)
    6070    {
    61       Print("Mult!\n");
     71      Print("MultHistory!\n");
    6272    }
    6373
    6474  private: // no copy constuctors!
    65     CCacheHash();
    66     operator =(CCacheHash&);
     75    CCacheHash(const CCacheHash&);
     76    CCacheHash& operator=(const CCacheHash&);
    6777};
    6878
     
    7484    typedef poly CExponent;
    7585
     86    CGlobalCacheHash(ring r): CCacheHash<poly>(r) {};
     87
     88    virtual ~CGlobalCacheHash() {};
     89
    7690  protected:
    7791    virtual void History(CExponent a, CExponent b, const EHistoryType t);
    7892};
    79 
    80 
    8193
    8294class CSpecialPairCacheHash: public CCacheHash<int>
     
    8496  public:
    8597    typedef int CExponent;
    86    
     98
     99    CSpecialPairCacheHash(ring r): CCacheHash<int>(r) {};
     100
     101    virtual ~CSpecialPairCacheHash() {};
     102
    87103  protected:
    88104    virtual void History(const CExponent a, const CExponent b, const EHistoryType t);
    89105};
    90106
     107
     108
     109#endif // GRING_SA_CACHEHASH_H
     110
     111
  • kernel/ncSAMult.cc

    r67dbdb r1495df4  
    77 *  Author:  motsak
    88 *  Created:
    9  *  Version: $Id: ncSAMult.cc,v 1.1 2008-07-04 16:18:42 motsak Exp $
     9 *  Version: $Id: ncSAMult.cc,v 1.2 2008-07-15 16:27:58 motsak Exp $
    1010 *******************************************************************/
    1111
    1212
    13 #define MYTEST 0
    14 #define OUTPUT 0
     13#define MYTEST 1
     14#define OUTPUT 1
    1515
    1616#if MYTEST
     
    2222
    2323#include <ncSAMult.h> // for CMultiplier etc classes
    24 #include <ring.h>
    25 #include <p_polys.h>
    26 #include <sbuckets.h>
    27 
    28 
    29 
    30 
    31 /*
     24#include <sca.h> // for SCA
     25
     26
     27
     28
    3229// poly functions defined in p_Procs: ;
    33 poly gnc_pp_Mult_mm(const poly p, const poly m, const ring r, poly
    34 &last);
    35 poly gnc_p_Mult_mm(poly p, const poly m, const ring r);
    36 poly gnc_mm_Mult_p(const poly m, poly p, const ring r);
    37 poly gnc_mm_Mult_pp(const poly m, const poly p, const ring r);
    38 */
     30static poly gnc_pp_Mult_mm(const poly p, const poly m, const ring r, poly& last)
     31{
     32#if OUTPUT 
     33  Print("gnc_pp_Mult_mm");
     34  PrintLn();
     35#endif
     36  assume( r->GetNC()->GetGlobalMultiplier() != NULL );
     37 
     38  return r->GetNC()->GetGlobalMultiplier()->MultiplyPE(p, m);
     39}
     40
     41static poly gnc_p_Mult_mm(poly p, const poly m, const ring r)
     42{
     43#if OUTPUT 
     44  Print("gnc_p_Mult_mm");
     45  PrintLn();
     46#endif
     47  assume( r->GetNC()->GetGlobalMultiplier() != NULL );
     48
     49  return r->GetNC()->GetGlobalMultiplier()->MultiplyPEDestroy(p, m);
     50}
     51
     52static poly gnc_mm_Mult_p(const poly m, poly p, const ring r)
     53{
     54#if OUTPUT 
     55  Print("gnc_mm_Mult_p");
     56  PrintLn();
     57#endif
     58  assume( r->GetNC()->GetGlobalMultiplier() != NULL );
     59
     60  return r->GetNC()->GetGlobalMultiplier()->MultiplyEPDestroy(m, p);
     61}
     62
     63static poly gnc_mm_Mult_pp(const poly m, const poly p, const ring r)
     64{
     65#if OUTPUT 
     66  Print("gnc_mm_Mult_pp");
     67  PrintLn();
     68#endif
     69 
     70  assume( r->GetNC()->GetGlobalMultiplier() != NULL );
     71
     72  return r->GetNC()->GetGlobalMultiplier()->MultiplyEP(m, p);
     73}
     74
     75
     76
     77
     78static void gnc_p_ProcsSet(ring rGR, p_Procs_s* p_Procs = NULL)
     79{
     80#if OUTPUT 
     81  Print("\ngnc_p_ProcsSet()!!!");
     82  PrintLn();
     83#endif
     84
     85  if( p_Procs == NULL )
     86    p_Procs = rGR->p_Procs;
     87 
     88  // "commutative"
     89  p_Procs->p_Mult_mm  = rGR->p_Procs->p_Mult_mm  = gnc_p_Mult_mm;
     90  p_Procs->pp_Mult_mm = rGR->p_Procs->pp_Mult_mm = gnc_pp_Mult_mm;
     91
     92  p_Procs->p_Minus_mm_Mult_qq = rGR->p_Procs->p_Minus_mm_Mult_qq = NULL;
     93
     94  // non-commutaitve multiplication by monomial from the left
     95  rGR->GetNC()->p_Procs.mm_Mult_p   = gnc_mm_Mult_p;
     96  rGR->GetNC()->p_Procs.mm_Mult_pp  = gnc_mm_Mult_pp;
     97
     98}
     99
     100
     101
     102
     103
     104
     105
     106bool ncInitSpecialPairMultiplication(ring r)
     107{
     108#if OUTPUT 
     109  Print("ncInitSpecialPairMultiplication(ring), ring: \n");
     110  rWrite(r);
     111  PrintLn();
     112#endif
     113  assume(rIsPluralRing(r));
     114  assume(!rIsSCA(r));
     115
     116  r->GetNC()->GetGlobalMultiplier() = new CGlobalMultiplier(r);
     117
     118  gnc_p_ProcsSet(r);
     119  return true;
     120}
     121
     122
     123CGlobalMultiplier::CGlobalMultiplier(ring r): CMultiplier<poly>(r)
     124{
     125#if OUTPUT 
     126  Print("CGlobalMultiplier::CGlobalMultiplier(ring)!");
     127  PrintLn();
     128#endif
     129
     130  m_cache = new CGlobalCacheHash(r);
     131  m_powers = new CPowerMultiplier(r);
     132
     133}
     134
     135
     136CGlobalMultiplier::~CGlobalMultiplier()
     137{
     138#if OUTPUT 
     139  Print("CGlobalMultiplier::~CGlobalMultiplier()!");
     140  PrintLn();
     141#endif
     142
     143  delete m_cache;
     144  delete m_powers;
     145}
     146
     147
     148
     149// Exponent * Exponent
     150// TODO: handle components!!!
     151poly CGlobalMultiplier::MultiplyEE(const CExponent expLeft, const CExponent expRight)
     152{
     153#if OUTPUT 
     154  Print("CGlobalMultiplier::MultiplyEE(expLeft, expRight)!");
     155  PrintLn();
     156#endif
     157
     158  CCacheHash<poly>::CCacheItem* pLookup;
     159  int b = m_cache->LookupEE(expLeft, expRight, pLookup);
     160
     161  // up to now:
     162  assume( b == -1 );
     163
     164  // TODO: use PowerMultiplier!!!!
     165 
     166 
     167  // up to now:
     168  return NULL;
     169}
     170
     171    // Monom * Exponent
     172poly CGlobalMultiplier::MultiplyME(const poly pMonom, const CExponent expRight)
     173{
     174  return MultiplyEE(pMonom, expRight);
     175}
     176
     177    // Exponent * Monom
     178poly CGlobalMultiplier::MultiplyEM(const CExponent expLeft, const poly pMonom)
     179{
     180  return MultiplyEE(expLeft, pMonom);
     181}
     182
     183
     184
     185
     186
     187// Exponent * Exponent
     188poly CCommutativeSpecialPairMultiplier::MultiplyEE(const int expLeft, const int expRight)
     189{
     190  return NULL;
     191}
     192
     193// Monom * Exponent
     194poly CCommutativeSpecialPairMultiplier::MultiplyME(const poly pMonom, const int expRight)
     195{
     196  return NULL;
     197}
     198
     199// Exponent * Monom
     200poly CCommutativeSpecialPairMultiplier::MultiplyEM(const int expLeft, const poly pMonom)
     201{
     202  return NULL;
     203}
     204
     205
     206
     207// factory method!
     208CSpecialPairMultiplier* AnalyzePair(const ring r, int i, int j)
     209{
     210#if OUTPUT 
     211  Print("AnalyzePair(ring, i: %d, j: %d)!", i, j);
     212  PrintLn();
     213#endif
     214
     215  const int N = r->N;
     216
     217  assume(i < j);
     218  assume(i > 0);
     219  assume(j <= N);
     220
     221
     222  const poly c = GetC(r, i, j);
     223  const poly d = GetD(r, i, j);
     224
     225#if OUTPUT 
     226  Print("C_{%d, %d} = ", i, j); p_Write(c, r);
     227  Print("D_{%d, %d} = ", i, j); p_Write(d, r);
     228#endif
     229
     230  if( (d == NULL) && n_IsOne(p_GetCoeff(c, r), r) )
     231    return new CCommutativeSpecialPairMultiplier(r, i, j);
     232
     233  return NULL;
     234}
     235
     236
     237
     238
     239
     240
     241CPowerMultiplier::CPowerMultiplier(ring r): CMultiplier<CPower>(r)
     242{
     243#if OUTPUT 
     244  Print("CPowerMultiplier::CPowerMultiplier(ring)!");
     245  PrintLn();
     246#endif
     247
     248  m_specialpairs = (CSpecialPairMultiplier**)omAlloc0( ((NVars() * (NVars()-1)) / 2) * sizeof(CSpecialPairMultiplier*) );
     249
     250  for( int i = 1; i < NVars(); i++ )
     251    for( int j = i + 1; j <= NVars(); j++ )
     252      GetPair(i, j) = AnalyzePair(GetBasering(), i, j); // factory method!
     253}
     254
     255
     256CPowerMultiplier::~CPowerMultiplier()
     257{
     258#if OUTPUT 
     259  Print("CPowerMultiplier::~CPowerMultiplier()!");
     260  PrintLn();
     261#endif
     262
     263  omFreeSize((ADDRESS)m_specialpairs, ((NVars() * (NVars()-1)) / 2) * sizeof(CSpecialPairMultiplier*) );
     264}
     265
     266
     267// Monom * Exponent
     268// pMonom may NOT be of the form: var(j)^{n}!
     269poly CPowerMultiplier::MultiplyME(const poly pMonom, const CExponent expRight)
     270{
     271  const int j = expRight.Var;
     272  const int n = expRight.Power;
     273 
     274#if OUTPUT 
     275  Print("CPowerMultiplier::MultiplyME(monom * var(%d)^{%d}!", j, n);
     276  PrintLn();
     277#endif
     278
     279  assume( (j > 0) && (j <= NVars()));
     280
     281  if( n == 0 )
     282    return p_Copy(pMonom, GetBasering()); // Copy?!?
     283 
     284
     285  int v = NVars();
     286  int e = p_GetExp(pMonom, v, GetBasering());
     287
     288  while((v > j) && (e == 0))
     289    e = p_GetExp(pMonom, --v, GetBasering());
     290
     291  // TODO: review this!
     292  if( (e == 0) )
     293    return expRight.GetPoly(GetBasering());
     294
     295  if( v == j )
     296  {
     297    poly p = p_Copy(pMonom, GetBasering());   
     298    p_SetExp(p, j, e + n, GetBasering());
     299    return p;
     300  }
     301 
     302  // And now the General Case: v > j!
     303
     304  poly p = MultiplyEE( CPower(v, e), expRight ); // Easy way!
     305
     306  --v;
     307 
     308  while(v > 0)
     309  {
     310    e = p_GetExp(pMonom, v, GetBasering());
     311   
     312    if( e > 0 )
     313      p = MultiplyEPDestroy(CPower(v, e), p);
     314
     315    --v;
     316  }
     317
     318  return p;
     319}
     320
     321// Exponent * Monom
     322// pMonom may NOT be of the form: var(i)^{m}!
     323poly CPowerMultiplier::MultiplyEM(const CExponent expLeft, const poly pMonom)
     324{
     325  // TODO: as above! (difference due to Left/Right semmantics!)
     326  const int j = expLeft.Var;
     327  const int n = expLeft.Power;
     328
     329#if OUTPUT 
     330  Print("CPowerMultiplier::MultiplyEM(var(%d)^{%d} * monom)!", j, n);
     331  PrintLn();
     332#endif
     333
     334  assume( (j > 0) && (j <= NVars()));
     335
     336  if( n == 0 )
     337    return p_Copy(pMonom, GetBasering()); // Copy?!?
     338
     339
     340  int v = 1; // NVars();
     341  int e = p_GetExp(pMonom, v, GetBasering());
     342
     343  while((v < j) && (e == 0))
     344    e = p_GetExp(pMonom, ++v, GetBasering());
     345
     346  // TODO: review this!
     347  if( (e == 0) )
     348    return expLeft.GetPoly(GetBasering());
     349
     350  if( v == j )
     351  {
     352    poly p = p_Copy(pMonom, GetBasering());   
     353    p_SetExp(p, j, e + n, GetBasering());
     354    return p;
     355  }
     356
     357  // And now the General Case: v > j!
     358
     359  poly p = MultiplyEE( expLeft, CPower(v, e) ); // Easy way!
     360
     361  ++v;
     362  while(v <= NVars())
     363  {
     364    e = p_GetExp(pMonom, v, GetBasering());
     365   
     366    if( e > 0 )
     367      p = MultiplyPEDestroy(p, CPower(v, e));
     368         
     369    ++v;
     370  }
     371 
     372}
     373
     374
     375// Exponent * Exponent
     376// Computes: var(j)^{expLeft} * var(i)^{expRight}
     377poly CPowerMultiplier::MultiplyEE(const CExponent expLeft, const CExponent expRight)
     378{
     379#if OUTPUT 
     380  Print("CPowerMultiplier::MultiplyEE)!");
     381  PrintLn();
     382#endif
     383
     384  const int i = expRight.Var, j = expLeft.Var;
     385  const int ei = expRight.Power, ej = expLeft.Power;
     386
     387#if OUTPUT 
     388  Print("Input: var(%d)^{%d} * var(%d)^{%d}", j, ej, i, ei);
     389  PrintLn();
     390#endif
     391
     392  poly product;
     393
     394  if( i >= j )
     395  {
     396    // easy!
     397    product = NULL;
     398  } else
     399  {
     400    assume(1 <= i);
     401    assume(i <  j);
     402    assume(j <= NVars());
     403    assume(ei > 0);
     404    assume(ej > 0);
     405
     406    // No Cache Lookup!? :(
     407
     408    CSpecialPairMultiplier* pSpecialMultiplier = GetPair(i, j);
     409
     410    poly product = NULL;
     411
     412    // Special case?
     413    if( pSpecialMultiplier != NULL )
     414    {
     415      assume( pSpecialMultiplier->GetI() == i );
     416      assume( pSpecialMultiplier->GetJ() == j );
     417      assume( pSpecialMultiplier->GetBasering() == GetBasering() );
     418
     419      product = pSpecialMultiplier->MultiplyEE(ej, ei);
     420    } else
     421    {
     422      // Perform general NC Multiplication:
     423      // TODO
     424
     425      product = NULL;
     426    }
     427  }
     428 
     429  return product; 
     430}
     431
     432
     433
     434
     435
     436
     437CSpecialPairMultiplier::CSpecialPairMultiplier(ring r, int i, int j):
     438    CMultiplier<int>(r), m_i(i), m_j(j)
     439{
     440  assume(i < j);
     441  assume(i > 0);
     442  assume(j <= NVars());
     443}
     444
     445
     446// Monom * Exponent
     447poly CSpecialPairMultiplier::MultiplyME(const poly pMonom, const CExponent expRight)
     448{
     449  return MultiplyEE(p_GetExp(pMonom, GetJ(), GetBasering()), expRight);
     450}
     451
     452    // Exponent * Monom
     453poly CSpecialPairMultiplier::MultiplyEM(const CExponent expLeft, const poly pMonom)
     454{
     455  return MultiplyEE(expLeft, p_GetExp(pMonom, GetI(), GetBasering()));
     456}
     457
     458
     459
     460
  • kernel/ncSAMult.h

    r67dbdb r1495df4  
    44 *  Computer Algebra System SINGULAR     *
    55 *****************************************/
    6 /* $Id: ncSAMult.h,v 1.3 2008-07-11 15:53:28 motsak Exp $ */
     6/* $Id: ncSAMult.h,v 1.4 2008-07-15 16:27:58 motsak Exp $ */
    77#ifdef HAVE_PLURAL
    88
     
    1212#include <ring.h>
    1313#include <summator.h> // for CPolynomialSummator class
     14#include <febase.h> // for Print!
     15#include <p_polys.h>
     16#include <p_Mult_q.h>
    1417
    1518#include <ncSACache.h> // for CCacheHash etc classes
     
    2629  protected:
    2730    ring m_basering;
    28 
    29   public:
    30     CMultiplier(ring rBaseRing): m_basering(rBaseRing) {};
     31    int  m_NVars; // N = number of variables
     32
     33  public:
     34    CMultiplier(ring rBaseRing): m_basering(rBaseRing), m_NVars(rBaseRing->N) {};
     35    virtual ~CMultiplier() {};
    3136
    3237    const ring GetBasering() const { return m_basering; };
     38    inline int NVars() const { return m_NVars; }
     39
    3340
    3441
     
    4148    { return p_Mult_nn(MultiplyEM(expLeft, pTerm), p_GetCoeff(pTerm, GetBasering()), GetBasering()); }
    4249
    43 //
    44 // Main templates!
    45 //
     50    // Main templates:
    4651
    4752    // Poly * Exponent
     
    9499
    95100
    96   protected:
     101//  protected:
    97102
    98103    // Exponent * Exponent
     
    107112  private: // no copy constuctors!
    108113    CMultiplier();
    109     operator =(CMultiplier&);
     114    CMultiplier(const CMultiplier&);
     115    CMultiplier& operator=(const CMultiplier&);
     116   
    110117};
    111118
     
    116123    int m_i;
    117124    int m_j;
    118    
    119   public:
     125
     126    poly m_c_ij;
     127    poly m_d_ij;
     128   
     129   
     130  public:
     131    // 1 <= i < j <= NVars()
    120132    CSpecialPairMultiplier(ring r, int i, int j);
    121   protected:   
     133    virtual ~CSpecialPairMultiplier(){}
     134
     135    inline int GetI() const { return m_i; }
     136    inline int GetJ() const { return m_j; }
     137
     138//  protected:
    122139    typedef int CExponent;
    123140
    124141    // Exponent * Exponent
    125     virtual poly MultiplyEE(const poly expLeft, const CExponent expRight);   
    126 
    127     // Monom * Exponent
     142    // Computes: var(j)^{expLeft} * var(i)^{expRight}
     143    virtual poly MultiplyEE(const CExponent expLeft, const CExponent expRight) = 0;
     144
     145    // Monom * Exponent
     146    // pMonom must be of the form: var(j)^{n}
    128147    virtual poly MultiplyME(const poly pMonom, const CExponent expRight);
    129148
    130149    // Exponent * Monom
     150    // pMonom must be of the form: var(i)^{m}
    131151    virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom);
    132152
    133153};
    134154
    135 /*
     155
    136156class CCommutativeSpecialPairMultiplier: public CSpecialPairMultiplier
    137157{
    138158  public:
    139     // Exponent * Exponent
    140     virtual poly MultiplyEE(const poly expLeft, const CExponent expRight);   
    141 
    142     // Monom * Exponent
    143     virtual poly MultiplyME(const poly pMonom, const CExponent expRight);
    144 
    145     // Exponent * Monom
    146     virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom);
    147 }
    148 */
    149 
    150 
    151 
    152 
    153 class CGlobalMultiplier: public CMultiplier<poly>
     159    CCommutativeSpecialPairMultiplier(ring r, int i, int j):
     160        CSpecialPairMultiplier(r, i, j){};
     161    virtual ~CCommutativeSpecialPairMultiplier() {}
     162   
     163    // Exponent * Exponent
     164    virtual poly MultiplyEE(const int expLeft, const int expRight);   
     165
     166    // Monom * Exponent
     167    virtual poly MultiplyME(const poly pMonom, const int expRight);
     168
     169    // Exponent * Monom
     170    virtual poly MultiplyEM(const int expLeft, const poly pMonom);
     171};
     172
     173
     174
     175
     176
     177struct CPower // represents var(iVar)^{iPower}
     178{
     179  int Var;
     180  int Power;
     181
     182  CPower(int i, int n): Var(i), Power(n) {};
     183
     184  inline poly GetPoly(const ring r, int c = 1) const
     185  {
     186    poly p = p_ISet(c, r);
     187    p_SetExp(p, Var, Power, r);
     188    return p;
     189  };
     190 
     191};
     192
     193
     194
     195
     196
     197
     198class CPowerMultiplier: public CMultiplier<CPower>
    154199{
    155200  private:
    156201    CSpecialPairMultiplier** m_specialpairs; // upper triangular submatrix of pairs 1 <= i < j <= N of a N x N matrix.
    157     int m_NVars; // N = number of variables
    158     CGlobalCacheHash* m_cache;
    159 
    160   public:
    161     CGlobalMultiplier(ring r);
    162 
    163     inline int NVars() const { return m_NVars; }
     202
     203
     204  public:
     205    CPowerMultiplier(ring r);
     206    virtual ~CPowerMultiplier();
    164207
    165208    inline CSpecialPairMultiplier* GetPair(int i, int j) const
     
    168211      assume( i > 0 );
    169212      assume( i < j );
    170       assume( j <= iNVars );
    171 
    172       return m_specialpairs + ( (NVars() * ((i)-1) - ((i) * ((i)-1))/2 + (j)-1) - (i) );
    173     }
    174 
    175 
    176   protected:   
     213      assume( j <= NVars() );
     214
     215      return m_specialpairs[( (NVars() * ((i)-1) - ((i) * ((i)-1))/2 + (j)-1) - (i) )];
     216    }
     217
     218    inline CSpecialPairMultiplier*& GetPair(int i, int j)
     219    {
     220      assume( m_specialpairs != NULL );
     221      assume( i > 0 );
     222      assume( i < j );
     223      assume( j <= NVars() );
     224
     225      return m_specialpairs[( (NVars() * ((i)-1) - ((i) * ((i)-1))/2 + (j)-1) - (i) )];
     226    }
     227   
     228//  protected:
     229    typedef CPower CExponent;
     230
     231    // Exponent * Exponent
     232    // Computes: var(j)^{expLeft} * var(i)^{expRight}
     233    virtual poly MultiplyEE(const CExponent expLeft, const CExponent expRight);
     234
     235    // Monom * Exponent
     236    // pMonom may NOT be of the form: var(j)^{n}!
     237    virtual poly MultiplyME(const poly pMonom, const CExponent expRight);
     238
     239    // Exponent * Monom
     240    // pMonom may NOT be of the form: var(i)^{m}!
     241    virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom);
     242
     243
     244};
     245
     246
     247
     248
     249class CGlobalMultiplier: public CMultiplier<poly>
     250{
     251  private:
     252    CGlobalCacheHash* m_cache;
     253    CPowerMultiplier* m_powers;
     254
     255  public:
     256    typedef CMultiplier<poly> CBaseType;
     257   
     258    CGlobalMultiplier(ring r);
     259    virtual ~CGlobalMultiplier();
     260
     261   
     262 
     263//  protected:   
    177264    typedef poly CExponent;
    178265
     
    180267   
    181268    // Exponent * Exponent
    182     virtual poly MultiplyEE(const poly expLeft, const CExponent expRight);   
     269    // TODO: handle components!!!
     270    virtual poly MultiplyEE(const CExponent expLeft, const CExponent expRight);   
    183271
    184272    // Monom * Exponent
     
    188276    virtual poly MultiplyEM(const CExponent expLeft, const poly pMonom);
    189277
    190 
    191     CSpecialPairMultiplier* AnalyzePair(const ring r, int j, int i);
    192    
    193278};
    194279
  • kernel/structs.h

    r67dbdb r1495df4  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: structs.h,v 1.49 2008-07-07 12:21:43 wienand Exp $ */
     6/* $Id: structs.h,v 1.50 2008-07-15 16:27:58 motsak Exp $ */
    77/*
    88* ABSTRACT
     
    140140class sBucket;
    141141class CPolynomialSummator;
     142class CGlobalMultiplier;
    142143#endif
    143144
     
    468469  short ref;
    469470  nc_type type;
    470   ring basering; // the ring C,D,.. live in
    471 
    472   // initial data:
    473   matrix C;
     471  ring basering; // the ring C,D,.. live in (commutative ring with this NC structure!)
     472
     473  // initial data: square matrices rVar() x rVar()
     474  // logically: upper triangular!!!
     475  // TODO: eliminate this waste of memory!!!!
     476  matrix C;
    474477  matrix D;
    475478
     
    498501        ideal idSCAQuotient; // = NULL by default. // must be deleted in Kill!
    499502      } sca;
     503
    500504    } data;
    501505
     506    CGlobalMultiplier* m_Multiplier;
     507
    502508  public:
     509   
    503510    inline nc_type& ncRingType() { return (type); };
    504511    inline nc_type ncRingType() const { return (type); };
     
    517524        { assume(ncRingType() == nc_exterior); return (data.sca.idSCAQuotient); };
    518525
     526    inline CGlobalMultiplier* GetGlobalMultiplier() const
     527        { assume(ncRingType() != nc_exterior); return (m_Multiplier); };
     528
     529    inline CGlobalMultiplier*& GetGlobalMultiplier()
     530        { assume(ncRingType() != nc_exterior); return (m_Multiplier); };
     531   
    519532  public:
    520533    nc_pProcs p_Procs; // NC procedures.
Note: See TracChangeset for help on using the changeset viewer.