Changeset c6a3eb2 in git


Ignore:
Timestamp:
Feb 28, 2011, 2:20:22 PM (13 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '38077648e7239f98078663eb941c3c979511150a')
Children:
89abbe07ab1f0d917faf8b67ce6eb62994353b25
Parents:
8e45403dd5d584f695e8de3d811c76579d3a7a55
git-author:
Hans Schoenemann <hannes@mathematik.uni-kl.de>2011-02-28 14:20:22+01:00
git-committer:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 11:59:33+01:00
Message:
main part of maps.cc
Location:
libpolys/polys
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • libpolys/polys/monomials/maps.cc

    r8e45403 rc6a3eb2  
    77*/
    88
    9 #include <kernel/mod2.h>
    10 #include <kernel/options.h>
    11 #include <kernel/febase.h>
    12 #include <kernel/polys.h>
    13 #include <kernel/numbers.h>
    14 #include <kernel/ring.h>
    15 #include <kernel/ideals.h>
    16 #include <kernel/matpol.h>
     9#include <misc/options.h>
     10#include <monomials/p_polys.h>
     11#include <coeffs/coeffs.h>
     12#include <coeffs/numbers.h>
     13#include <monomials/ring.h>
     14#include <simpleideals.h>
    1715#include <omalloc/omalloc.h>
    18 #include <kernel/kstd1.h>
    19 #include <kernel/longtrans.h>
    20 #include <kernel/maps.h>
    21 #include <kernel/prCopy.h>
     16#include <polys/prCopy.h>
     17#include <polys/ext_fields/longtrans.h>
     18#include <polys/monomials/maps.h>
    2219
    2320#ifdef HAVE_PLURAL
     
    3633* copy a map
    3734*/
    38 map maCopy(map theMap)
     35map maCopy(map theMap, const ring r)
    3936{
    4037  int i;
    4138  map m=(map)idInit(IDELEMS(theMap),0);
    4239  for (i=IDELEMS(theMap)-1; i>=0; i--)
    43       m->m[i] = pCopy(theMap->m[i]);
     40      m->m[i] = p_Copy(theMap->m[i],r);
    4441  m->preimage=omStrDup(theMap->preimage);
    4542  return m;
     
    5047* return the image of var(v)^pExp, where var(v) maps to p
    5148*/
    52 poly maEvalVariable(poly p, int v,int pExp,matrix s)
     49poly maEvalVariable(poly p, int v,int pExp, ideal s, const ring dst_r)
    5350{
    5451  if (pExp==1)
    55     return pCopy(p);
     52    return p_Copy(p,dst_r);
    5653
    5754  poly res;
     
    6461    if(MATELEM(s,v,1)==NULL)
    6562    {
    66       MATELEM(s,v,1)=pCopy(p/*theMap->m[v-1]*/);
     63      MATELEM(s,v,1)=p_Copy(p/*theMap->m[v-1]*/,dst_r);
    6764    }
    6865    else
     
    7774    for(;j<=pExp;j++)
    7875    {
    79       p0=MATELEM(s,v,j)=ppMult_qq(p0, p);
    80       pNormalize(p0);
    81     }
    82     res=pCopy(p0/*MATELEM(s,v,pExp)*/);
     76      p0=MATELEM(s,v,j)=pp_Mult_qq(p0, p,dst_r);
     77      p_Normalize(p0, dst_r);
     78    }
     79    res=p_Copy(p0/*MATELEM(s,v,pExp)*/,dst_r);
    8380  }
    8481  else //if ((p->next!=NULL)&&(p->next->next==NULL))
    8582  {
    86     res=pPower(pCopy(p),pExp);
     83    res=p_Power(p_Copy(p,dst_r),pExp,dst_r);
    8784  }
    8885  return res;
    8986}
    9087
    91 static poly maEvalMonom(map theMap, poly p,ring preimage_r,matrix s, nMapFunc nMap)
    92 {
    93     poly q=pNSet(nMap(pGetCoeff(p)));
     88static poly maEvalMonom(map theMap, poly p,ring preimage_r, ideal s,
     89           nMapFunc nMap, const ring dst_r)
     90{
     91    poly q=p_NSet(nMap(pGetCoeff(p),preimage_r->cf,dst_r->cf),dst_r);
    9492
    9593    int i;
     
    102100        {
    103101          poly p1=theMap->m[i-1];
    104           poly pp=maEvalVariable(p1,i,pExp,s);
    105           q = pMult(q,pp);
     102          poly pp=maEvalVariable(p1,i,pExp,s,dst_r);
     103          q = p_Mult_q(q,pp,dst_r);
    106104        }
    107105        else
    108106        {
    109           pDelete(&q);
     107          p_Delete(&q,dst_r);
    110108          break;
    111109        }
     
    113111    }
    114112    int modulComp = p_GetComp( p,preimage_r);
    115     if (q!=NULL) pSetCompP(q,modulComp);
     113    if (q!=NULL) p_SetCompP(q,modulComp,dst_r);
    116114  return q;
    117115}
    118116
    119 poly maEval(map theMap, poly p,ring preimage_r,nMapFunc nMap,matrix s)
     117poly maEval(map theMap, poly p,ring preimage_r,nMapFunc nMap, ideal s, const ring dst_r)
    120118{
    121119  poly result = NULL;
     
    142140      for (i=0; i<l; i++)
    143141      {
    144         monoms[i]=maEvalMonom(theMap,p,preimage_r,s, nMap);
     142        monoms[i]=maEvalMonom(theMap,p,preimage_r,s, nMap, dst_r);
    145143        pIter(p);
    146144      }
    147145    }
    148     result=maEvalMonom(theMap,p,preimage_r,s, nMap);
     146    result=maEvalMonom(theMap,p,preimage_r,s, nMap, dst_r);
    149147    if (l>0)
    150148    {
    151149      for(i = l-1; i>=0; i--)
    152150      {
    153         result=pAdd(result, monoms[i]);
     151        result=p_Add_q(result, monoms[i], dst_r);
    154152      }
    155153      omFreeSize((ADDRESS)monoms,l*sizeof(poly));
    156154    }
    157     if (currRing->minpoly!=NULL) result=pMinPolyNormalize(result);
    158   }
    159   pTest(result);
     155    if (dst_r->minpoly!=NULL) result=pMinPolyNormalize(result);
     156  }
    160157  return result;
    161158}
     
    166163*be carefull: there is no range check for the variables of p
    167164*/
    168 static poly pChangeSizeOfPoly(ring p_ring, poly p,int minvar,int maxvar)
     165static poly pChangeSizeOfPoly(ring p_ring, poly p,int minvar,int maxvar, const ring dst_r)
    169166{
    170167  int i;
     
    173170
    174171  if (p==NULL) return result;
    175   else result = pInit();
     172  else result = p_Init(dst_r);
    176173  resultWorkP = result;
    177174  while (p!=NULL)
    178175  {
    179176    for (i=minvar;i<=maxvar;i++)
    180       pSetExp(resultWorkP,i-minvar+1,p_GetExp(p,i,p_ring));
    181     pSetComp(resultWorkP,p_GetComp(p,p_ring));
    182     n=nCopy(pGetCoeff(p));
    183     pSetCoeff(resultWorkP,n);
    184     pSetm(resultWorkP);
     177      p_SetExp(resultWorkP,i-minvar+1,p_GetExp(p,i,p_ring),dst_r);
     178    p_SetComp(resultWorkP,p_GetComp(p,p_ring),dst_r);
     179    n=n_Copy(pGetCoeff(p),dst_r->cf);
     180    p_SetCoeff(resultWorkP,n,dst_r);
     181    p_Setm(resultWorkP,dst_r);
    185182    pIter(p);
    186183    if (p!=NULL)
    187184    {
    188       pNext(resultWorkP) = pInit();
     185      pNext(resultWorkP) = p_Init(dst_r);
    189186      pIter(resultWorkP);
    190187    }
     
    199196* (assumes) that both ring have the same coeff.field
    200197*/
    201 ideal maGetPreimage(ring theImageRing, map theMap, ideal id)
    202 {
    203   ring sourcering = currRing;
     198ideal maGetPreimage(ring theImageRing, map theMap, ideal id, const ring dst_r)
     199{
     200  ring sourcering = dst_r;
    204201
    205202#ifdef HAVE_PLURAL
     
    219216  ideal temp2;
    220217
    221   int imagepvariables = theImageRing->N;
    222   int N = pVariables+imagepvariables;
     218  int imagepvariables = rVar(theImageRing);
     219  int N = rVar(dst_r)+imagepvariables;
    223220
    224221  ring tmpR;
     
    229226  }
    230227
    231   if (nSetMap(theImageRing) != nCopy)
     228  if (n_SetMap(theImageRing->cf,dst_r->cf) != ndCopyMap)
    232229  {
    233230    Werror("Coefficient fields/rings must be equal");
     
    235232  }
    236233
    237   // change to new ring
    238   rChangeCurrRing(tmpR);
    239234  if (id==NULL)
    240235    j = 0;
     
    246241  for (i=0;i<sourcering->N;i++)
    247242  {
    248     q = pISet(-1);
    249     pSetExp(q,i+1+imagepvariables,1);
    250     pSetm(q);
     243    q = p_ISet(-1,tmpR);
     244    p_SetExp(q,i+1+imagepvariables,1,tmpR);
     245    p_Setm(q,tmpR);
    251246    if ((i<IDELEMS(theMap)) && (theMap->m[i]!=NULL))
    252247    {
    253       p = pSort(pChangeSizeOfPoly(theImageRing,theMap->m[i],1,imagepvariables));
    254       p=pAdd(p,q);
     248      p = p_SortMerge(
     249        pChangeSizeOfPoly(theImageRing,theMap->m[i],1,imagepvariables,tmpR),
     250        tmpR);
     251      p=p_Add_q(p,q,tmpR);
    255252    }
    256253    else
     
    263260  for (i=sourcering->N;i<sourcering->N+j0;i++)
    264261  {
    265     temp1->m[i] = pSort(pChangeSizeOfPoly(theImageRing,
    266                                     id->m[i-sourcering->N],1,imagepvariables));
     262    temp1->m[i] = p_SortMerge(pChangeSizeOfPoly(theImageRing,
     263                         id->m[i-sourcering->N],1,imagepvariables,tmpR),tmpR);
    267264  }
    268265  for (i=sourcering->N+j0;i<sourcering->N+j;i++)
    269266  {
    270     temp1->m[i] = pSort(pChangeSizeOfPoly(theImageRing,
    271                                     theImageRing->qideal->m[i-sourcering->N-j0],
    272                                     1,imagepvariables));
     267    temp1->m[i] = p_SortMerge(pChangeSizeOfPoly(theImageRing,
     268                              theImageRing->qideal->m[i-sourcering->N-j0],
     269                              1,imagepvariables,tmpR),tmpR);
    273270  }
    274271  // we ignore here homogenity - may be changed later:
    275272  temp2 = kStd(temp1,NULL,isNotHomog,NULL);
    276   idDelete(&temp1);
     273  id_Delete(&temp1,tmpR);
    277274  for (i=0;i<IDELEMS(temp2);i++)
    278275  {
    279     if (pLowVar(temp2->m[i])<imagepvariables) pDelete(&(temp2->m[i]));
     276    if (pLowVar(temp2->m[i])<imagepvariables) p_Delete(&(temp2->m[i]),tmpR);
    280277  }
    281278
    282279  // let's get back to the original ring
    283   rChangeCurrRing(sourcering);
     280  //rChangeCurrRing(sourcering);
    284281  temp1 = idInit(5,1);
    285282  j = 0;
     
    289286    if (p!=NULL)
    290287    {
    291       q = pSort(pChangeSizeOfPoly(tmpR, p,imagepvariables+1,N));
     288      q = p_SortMerge(pChangeSizeOfPoly(tmpR, p,imagepvariables+1,N),sourcering);
    292289      if (j>=IDELEMS(temp1))
    293290      {
     
    375372* embeds poly p from the subring r into the current ring
    376373*/
    377 poly maIMap(ring r, poly p)
     374poly maIMap(ring r, poly p, const ring dst_r)
    378375{
    379376  /* the simplest case:*/
    380   if(r==currRing) return pCopy(p);
    381   nMapFunc nMap=nSetMap(r);
     377  if(r==dst_r) return p_Copy(p,dst_r);
     378  nMapFunc nMap=n_SetMap(r->cf,dst_r->cf);
    382379  int *perm=(int *)omAlloc0((r->N+1)*sizeof(int));
    383380  //int *par_perm=(int *)omAlloc0(rPar(r)*sizeof(int));
    384381  maFindPerm(r->names,r->N, r->parameter, r->P,
    385              currRing->names,currRing->N,currRing->parameter, currRing->P,
    386              perm,NULL, currRing->ch);
    387   poly res=pPermPoly(p,perm,r, nMap /*,par_perm,rPar(r)*/);
     382             dst_r->names,dst_r->N,dst_r->parameter, dst_r->P,
     383             perm,NULL, dst_r->ch);
     384  poly res=p_PermPoly(p,perm,r,dst_r, nMap /*,par_perm,rPar(r)*/);
    388385  omFreeSize((ADDRESS)perm,(r->N+1)*sizeof(int));
    389386  //omFreeSize((ADDRESS)par_perm,rPar(r)*sizeof(int));
     
    464461// This is a very dirty way to cancel monoms whose number equals the
    465462// MinPoly
    466 poly pMinPolyNormalize(poly p)
    467 {
    468   number one = nInit(1);
     463poly pMinPolyNormalize(poly p, const ring r)
     464{
     465  number one = n_Init(1,r->cf);
    469466  spolyrec rp;
    470467
     
    474471  {
    475472    // this returns 0, if p == MinPoly
    476     number product = nMult(pGetCoeff(p), one);
    477     if ((product == NULL)||(nIsZero(product)))
    478     {
    479       pLmDelete(&p);
     473    number product = n_Mult(pGetCoeff(p), one,r->cf);
     474    if ((product == NULL)||(n_IsZero(product,r->cf)))
     475    {
     476      p_LmDelete(&p,r);
    480477    }
    481478    else
    482479    {
    483       pSetCoeff(p, product);
     480      p_SetCoeff(p, product,r);
    484481      pNext(q) = p;
    485482      q = p;
  • libpolys/polys/monomials/maps.h

    r8e45403 rc6a3eb2  
    1616typedef struct sip_smap *         map;
    1717
    18 poly maEval(map theMap, poly p, ring dst_ring, nMapFunc nMap); //,matrix s=NULL);
    19 map maCopy(map theMap, ring dst_ring);
     18poly maEval(map theMap, poly p, ring dst_ring, nMapFunc nMap, ideal s=NULL);
     19map maCopy(map theMap, const ring dst_ring);
    2020
    2121ideal maGetPreimage(ring theImageRing, map theMap,ideal id);
  • libpolys/polys/monomials/p_polys.cc

    r8e45403 rc6a3eb2  
    28852885
    28862886/*2
     2887* handle memory request for sets of polynomials (ideals)
     2888* l is the length of *p, increment is the difference (may be negative)
     2889*/
     2890void pEnlargeSet(poly* *p, int l, int increment)
     2891{
     2892  poly* h;
     2893
     2894  h=(poly*)omReallocSize((poly*)*p,l*sizeof(poly),(l+increment)*sizeof(poly));
     2895  if (increment>0)
     2896  {
     2897    //for (i=l; i<l+increment; i++)
     2898    //  h[i]=NULL;
     2899    memset(&(h[l]),0,increment*sizeof(poly));
     2900  }
     2901  *p=h;
     2902}
     2903
     2904/*2
    28872905*returns a re-ordered copy of a polynomial, with permutation of the variables
    28882906*/
  • libpolys/polys/monomials/p_polys.h

    r8e45403 rc6a3eb2  
    339339inline   poly      pLast(poly a) { int l; return pLast(a, l);}
    340340static inline poly pReverse(poly p);
     341void      pEnlargeSet(poly**p, int length, int increment);
    341342
    342343
     
    381382long pLDeg1c_WFirstTotalDegree(poly p,int *l, ring r);
    382383BOOLEAN p_EqualPolys(poly p1, poly p2, const ring r);
     384
     385long p_Deg(poly a, const ring r);
    383386/***************************************************************
    384387 *
  • libpolys/polys/monomials/ring.cc

    r8e45403 rc6a3eb2  
    33793379static void rOptimizeLDeg(ring r)
    33803380{
    3381   if (r->pFDeg == pDeg)
     3381  if (r->pFDeg == p_Deg)
    33823382  {
    33833383    if (r->pLDeg == pLDeg1)
     
    35203520 
    35213521  if (rOrd_is_Totaldegree_Ordering(r) || rOrd_is_WeightedDegree_Ordering(r))
    3522     r->pFDeg = pDeg;
     3522    r->pFDeg = p_Deg;
    35233523
    35243524  r->pFDegOrig = r->pFDeg;
  • libpolys/polys/monomials/ring.h

    r8e45403 rc6a3eb2  
    5555  int ncols;
    5656  #define IDELEMS(i) ((i)->ncols)
     57  #define MATCOLS(i) ((i)->ncols)
     58  #define MATROWS(i) ((i)->nrows)
     59  #define MATELEM(mat,i,j) ((mat)->m)[MATCOLS((mat)) * ((i)-1) + (j)-1]
    5760};
    5861typedef struct sip_sideal *       ideal;
     62
     63struct sip_smap
     64{
     65  poly *m;
     66  char *preimage;
     67  int nrows;
     68  int ncols;
     69};
     70typedef struct sip_smap *         map;
     71
    5972typedef enum
    6073{
  • libpolys/polys/polys.h

    r8e45403 rc6a3eb2  
    273273inline void    wrp(poly p)        {p_wrp(p, currRing, currRing);}
    274274
    275 void      pEnlargeSet(polyset *p, int length, int increment);
    276275#define   pISet(i) p_ISet(i,currRing)
    277276#define   pNSet(n) p_NSet(n,currRing)
  • libpolys/polys/polys1.cc

    r8e45403 rc6a3eb2  
    3333
    3434
    35 /*2
    36 * handle memory request for sets of polynomials (ideals)
    37 * l is the length of *p, increment is the difference (may be negative)
    38 */
    39 void pEnlargeSet(polyset *p, int l, int increment)
    40 {
    41   polyset h;
    42 
    43   h=(polyset)omReallocSize((poly*)*p,l*sizeof(poly),(l+increment)*sizeof(poly));
    44   if (increment>0)
    45   {
    46     //for (i=l; i<l+increment; i++)
    47     //  h[i]=NULL;
    48     memset(&(h[l]),0,increment*sizeof(poly));
    49   }
    50   *p=h;
    51 }
    52 
    5335poly ppJet(poly p, int m)
    5436{
Note: See TracChangeset for help on using the changeset viewer.