Changeset e20214 in git for Singular/maps.cc


Ignore:
Timestamp:
Jul 13, 1999, 5:06:52 PM (24 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
Children:
2eeb7d1017a21755a73976d7e957ee1db6cc06b2
Parents:
0a5f342e03dda534e299aecb4e831f39b5569cd7
Message:
*hannes: maEval optimized


git-svn-id: file:///usr/local/Singular/svn/trunk@3265 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/maps.cc

    r0a5f34 re20214  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: maps.cc,v 1.14 1999-03-09 12:28:49 obachman Exp $ */
     4/* $Id: maps.cc,v 1.15 1999-07-13 15:06:52 Singular Exp $ */
    55/*
    66* ABSTRACT - the mapping of polynomials to other rings
     
    2222#include "maps.h"
    2323
    24 #define MAX_MAP_DEG 32
     24#define MAX_MAP_DEG 128
    2525
    2626/*2
     
    3737}
    3838
     39
     40/*2
     41* return the image of var(v)^pExp, where var(v) maps to p
     42*/
     43poly maEvalVariable(poly p, int v,int pExp,matrix s)
     44{
     45  if (pExp==1)
     46    return pCopy(p);
     47
     48  poly res;
     49
     50  if((s!=NULL)&&(pExp<MAX_MAP_DEG))
     51  {
     52    int j=2;
     53    poly p0=p;
     54    // find starting point
     55    if(MATELEM(s,v,1)==NULL)
     56    {
     57      MATELEM(s,v,1)=pCopy(p/*theMap->m[v-1]*/);
     58    }
     59    else
     60    {
     61      while((j<=pExp)&&(MATELEM(s,v,j)!=NULL))
     62      {
     63        j++;
     64      }
     65      p0=MATELEM(s,v,j-1);
     66    }
     67    // multiply
     68    for(;j<=pExp;j++)
     69    {
     70      p0=MATELEM(s,v,j)=pMult(pCopy(p0/*MATELEM(s,v,j-1)*/),
     71                              pCopy(p/*theMap->m[v-1]*/));
     72    }
     73    res=pCopy(p0/*MATELEM(s,v,pExp)*/);
     74  }
     75  else //if ((p->next!=NULL)&&(p->next->next==NULL))
     76  {
     77    res=pPower(pCopy(p),pExp);
     78  }
     79  return res;
     80}
     81
     82poly maEvalMonom(map theMap, poly p,ring preimage_r,matrix s)
     83{
     84    poly q=pOne();
     85    pSetCoeff(q,nMap(pGetCoeff(p)));
     86
     87    int i;
     88    for(i=preimage_r->N; i>0; i--)
     89    {
     90      int pExp=pRingGetExp(preimage_r, p,i);
     91      if (pExp != 0)
     92      {
     93        if (theMap->m[i-1]!=NULL)
     94        {
     95          poly p1=theMap->m[i-1];
     96          poly pp=maEvalVariable(p1,i,pExp,s);
     97          q = pMult(q,pp);
     98        }
     99        else
     100        {
     101          pDelete(&q);
     102          break;
     103        }
     104      }
     105    }
     106    int modulComp = pRingGetComp(preimage_r, p);
     107    if (q!=NULL) pSetCompP(q,modulComp);
     108  return q;
     109}
     110
    39111poly maEval(map theMap, poly p,ring preimage_r,matrix s)
    40112{
    41   poly result = NULL,q,pp;
    42   int i,modulComp;
    43   int varnum = preimage_r->N;
    44 
    45 //  for(i=1; i<=varnum; i++)
     113  poly result = NULL;
     114  int i;
     115
     116//  for(i=1; i<=preimage_r->N; i++)
    46117//  {
    47118//    pTest(theMap->m[i-1]);
    48119//  }
    49   while (p!=NULL)
    50   {
    51     q=pOne();
    52     pSetCoeff(q,nMap(pGetCoeff(p)));
    53 
    54     for(i=1; i<=varnum; i++)
    55     {
    56       int pExp=pRingGetExp(preimage_r, p,i);
    57       if (pExp != 0)
    58       {
    59         if (theMap->m[i-1]!=NULL)
    60         {
    61           poly p1=theMap->m[i-1];
    62           if((s!=NULL)&&(pExp<(MAX_MAP_DEG*2)))
    63           {
    64             int e=min(pExp,MAX_MAP_DEG);
    65             if(MATELEM(s,i,e)!=NULL)
    66               pp=pCopy(MATELEM(s,i,e));
    67             else
    68             {
    69               int j=2;
    70               poly p0=p1;
    71               if(MATELEM(s,i,1)==NULL)
    72               {
    73                 MATELEM(s,i,1)=pCopy(p1/*theMap->m[i-1]*/);
    74               }
    75               else
    76               {
    77                 while((j<=e)&&(MATELEM(s,i,j)!=NULL))
    78                 {
    79                   j++;
    80                 }
    81                 p0=MATELEM(s,i,j-1);
    82               }
    83               for(;j<=e;j++)
    84               {
    85                 p0=MATELEM(s,i,j)=pMult(pCopy(p0/*MATELEM(s,i,j-1)*/),
    86                                         pCopy(p1/*theMap->m[i-1]*/));
    87               }
    88               pp=pCopy(p0/*MATELEM(s,i,e)*/);
    89             }
    90             while(e!=pExp/*pRingGetExp(preimage_r, p,i)*/)
    91             {
    92               // e is the current exponent,
    93               // MAX_MAP_DEG the max exponent in the table
    94               // pExp the end exponent
    95               pp=pMult(pp,pCopy(MATELEM(s,i,min(MAX_MAP_DEG,pExp-e))));
    96               e+=min(MAX_MAP_DEG,pExp-e);
    97             }
    98           }
    99           else
    100           {
    101             pp = pPower(pCopy(p1/*theMap->m[i-1]*/),pExp/*pRingGetExp(preimage_r, p,i)*/);
    102           }
    103           q = pMult(q,pp);
    104         }
    105         else
    106         {
    107           pDelete(&q);
    108           break;
    109         }
    110       }
    111     }
    112     modulComp = pRingGetComp(preimage_r, p);
    113     if (q!=NULL) pSetCompP(q,modulComp);
    114     result = pAdd(result,q);
    115     pIter(p);
    116   }
    117   if (currRing->minpoly!=NULL) result=pMult(result,pOne());
     120//  while (p!=NULL)
     121//  {
     122//    poly q=maEvalMonom(theMap,p,preimage_r,s);
     123//    result = pAdd(result,q);
     124//    pIter(p);
     125//  }
     126  if (p!=NULL)
     127  {
     128    int l = pLength(p)-1;
     129    poly* monoms;
     130    if (l>0)
     131    {
     132      monoms = (poly*) Alloc(l*sizeof(poly));
     133
     134      for (i=0; i<l; i++)
     135      {
     136        monoms[i]=maEvalMonom(theMap,p,preimage_r,s);
     137        pIter(p);
     138      }
     139    }
     140    result=maEvalMonom(theMap,p,preimage_r,s);
     141    if (l>0)
     142    {
     143      for(i = l-1; i>=0; i--)
     144      {
     145        result=pAdd(result, monoms[i]);
     146      }
     147      Free((ADDRESS)monoms,l*sizeof(poly));
     148    }
     149    if (currRing->minpoly!=NULL) result=pMult(result,pOne());
     150  }
    118151  pTest(result);
    119152  return result;
     
    280313
    281314void maFindPerm(char **preim_names, int preim_n, char **preim_par, int preim_p,
    282                 char **names,       int n,       char **par,       int nop, 
     315                char **names,       int n,       char **par,       int nop,
    283316                int * perm, int *par_perm, int ch)
    284317{
Note: See TracChangeset for help on using the changeset viewer.