Changeset 5d9aa6 in git


Ignore:
Timestamp:
Apr 13, 2011, 8:49:42 PM (13 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
Children:
503a31399a9b66dd3306a8251a9a5042a4509f5c
Parents:
0a3a629f65533731dfccd53a13103d906918010b
git-author:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2011-04-13 20:49:42+02:00
git-committer:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 12:12:33+01:00
Message:
FIX: further fixes in matpol
ADD: sparse matrices (sparsmat.*) - needed for matpol (Berreiss?)
Location:
libpolys/polys
Files:
3 edited
2 moved

Legend:

Unmodified
Added
Removed
  • libpolys/polys/Makefile.am

    r0a3a629 r5d9aa6  
    3636        pDebug.cc pInline0.cc polys0.cc prCopy.cc \
    3737        kbuckets.cc sbuckets.cc ${USE_P_PROCS_STATIC_CC} ${USE_P_PROCS_DYNAMIC_CC} weight.cc \
    38   simpleideals.cc matpol.cc
     38  simpleideals.cc matpol.cc sparsmat.cc
    3939
    4040BUILT_SOURCES = templates/p_Procs.inc
     
    4444include_HEADERS = \
    4545        monomials/ring.h nc/nc.h \
     46  nc/sca.h nc/summator.h nc/ncSAFormula.h nc/ncSACache.h nc/ncSAMult.h \
    4647        pInline0.h operations/pShallowCopyDelete.h \
    4748        templates/p_MemAdd.h templates/p_MemCmp.h templates/p_MemCopy.h operations/p_Mult_q.h \
     
    4950        templates/p_Procs_Dynamic.h templates/p_Procs_Impl.h templates/p_Procs_Set.h templates/p_Procs_Static.h \
    5051        monomials/p_polys.h monomials/polys-impl.h monomials/maps.h polys.h prCopy.h prCopyMacros.h \
    51         kbuckets.h sbuckets.h simpleideals.h weight.h
     52        kbuckets.h sbuckets.h simpleideals.h weight.h \
     53  matpol.h sparsmat.h
    5254
    5355P_PROCS_CPPFLAGS_COMMON = -DHAVE_CONFIG_H -DDYNAMIC_VERSION
  • libpolys/polys/matpol.cc

    r0a3a629 r5d9aa6  
    3737#include "prCopy.h"
    3838
     39#include "sparsmat.h"
     40   
    3941//omBin ip_smatrix_bin = omGetSpecBin(sizeof(ip_smatrix));
    4042#define ip_smatrix_bin sip_sideal_bin
     
    4547static void mpReplace(int j, int n, int &sign, int *perm);
    4648static int mpNextperm(perm * z, int max);
    47 static poly mpLeibnitz(matrix a);
    48 static poly minuscopy (poly p);
    49 static poly pInsert(poly p1, poly p2);
    50 static poly mpExdiv ( poly m, poly d, poly vars);
    51 static poly mpSelect (poly fro, poly what);
    52 
    53 static void mpPartClean(matrix, int, int);
    54 static void mpFinalClean(matrix);
    55 static int mpPrepareRow (matrix, int, int);
    56 static int mpPreparePiv (matrix, int, int);
    57 static int mpPivBar(matrix, int, int);
    58 static int mpPivRow(matrix, int, int);
    59 static float mpPolyWeight(poly);
    60 static void mpSwapRow(matrix, int, int, int);
    61 static void mpSwapCol(matrix, int, int, int);
    62 static void mpElimBar(matrix, matrix, poly, int, int);
    63 
    64 /*2
    65 * create a r x c zero-matrix
    66 */
     49static poly mp_Leibnitz(matrix a, const ring);
     50static poly minuscopy (poly p, const ring);
     51static poly p_Insert(poly p1, poly p2, const ring);
     52static poly mp_Exdiv ( poly m, poly d, poly vars, const ring);
     53static poly mp_Select (poly fro, poly what, const ring);
     54
     55static void mp_PartClean(matrix, int, int, const ring);
     56static void mp_FinalClean(matrix, const ring);
     57static int mp_PrepareRow (matrix, int, int, const ring);
     58static int mp_PreparePiv (matrix, int, int, const ring);
     59static int mp_PivBar(matrix, int, int, const ring);
     60static int mp_PivRow(matrix, int, int, const ring);
     61static float mp_PolyWeight(poly, const ring);
     62static void mp_SwapRow(matrix, int, int, int, const ring);
     63static void mp_SwapCol(matrix, int, int, int, const ring);
     64static void mp_ElimBar(matrix, matrix, poly, int, int, const ring);
     65
     66/// create a r x c zero-matrix
    6767matrix mpNew(int r, int c)
    6868{
     
    8080  {
    8181    int s=r*c*sizeof(poly);
    82     rc->m = (polyset)omAlloc0(s);
     82    rc->m = (poly*)omAlloc0(s);
    8383    //if (rc->m==NULL)
    8484    //{
     
    9090}
    9191
    92 /// copies matrix a to b
    93 matrix mpCopy (matrix a, const ring r)
    94 {
    95   idTest((ideal)a);
     92/// copies matrix a (from ring r to r)
     93matrix mp_Copy (matrix a, const ring r)
     94{
     95  id_Test((ideal)a, r);
    9696  poly t;
    9797  int i, m=MATROWS(a), n=MATCOLS(a);
     
    103103    if (t!=NULL)
    104104    {
    105       pNormalize(t);
    106       b->m[i] = pCopy(t);
     105      p_Normalize(t, r);
     106      b->m[i] = p_Copy(t, r);
    107107    }
    108108  }
     
    111111}
    112112
    113 /*2
    114 *copies matrix a from rSrc into rDst
    115 */
    116 matrix mpCopy(const matrix a, const ring rSrc, const ring rDst)
    117 {
    118   const ring save = currRing;
    119 
    120 #ifndef NDEBUG
    121   if( currRing != rSrc )
    122     rChangeCurrRing(rSrc);
    123   idTest((ideal)a);
    124 #endif
     113/// copies matrix a from rSrc into rDst
     114matrix mp_Copy(const matrix a, const ring rSrc, const ring rDst)
     115{
     116  id_Test((ideal)a, rSrc);
    125117
    126118  poly t;
     
    140132  b->rank=a->rank;
    141133
    142 #ifndef NDEBUG
    143   if( currRing != rDst )
    144     rChangeCurrRing(rDst);
    145   idTest((ideal)b);
    146 #endif
    147 
    148   if( save != currRing )
    149     rChangeCurrRing(save);
     134  id_Test((ideal)b, rDst);
    150135
    151136  return b;
     
    154139
    155140
    156 /*2
    157 * make it a p * unit matrix
    158 */
    159 matrix mpInitP(int r, int c, poly p)
     141/// make it a p * unit matrix
     142matrix mp_InitP(int r, int c, poly p, const ring _R)
    160143{
    161144  matrix rc = mpNew(r,c);
    162145  int i=si_min(r,c), n = c*(i-1)+i-1, inc = c+1;
    163146
    164   pNormalize(p);
     147  p_Normalize(p, _R);
    165148  while (n>0)
    166149  {
    167     rc->m[n] = pCopy(p);
     150    rc->m[n] = p_Copy(p, _R);
    168151    n -= inc;
    169152  }
     
    172155}
    173156
    174 /*2
    175 * make it a v * unit matrix
    176 */
    177 matrix mpInitI(int r, int c, int v)
    178 {
    179   return mpInitP(r,c,pISet(v));
    180 }
    181 
    182 /*2
    183 * c = f*a
    184 */
    185 matrix mpMultI(matrix a, int f)
     157/// make it a v * unit matrix
     158matrix mp_InitI(int r, int c, int v, const ring R)
     159{
     160  return mp_InitP(r, c, p_ISet(v, R), R);
     161}
     162
     163/// c = f*a
     164matrix mp_MultI(matrix a, int f, const ring R)
    186165{
    187166  int k, n = a->nrows, m = a->ncols;
    188   poly p = pISet(f);
     167  poly p = p_ISet(f, R);
    189168  matrix c = mpNew(n,m);
    190169
    191170  for (k=m*n-1; k>0; k--)
    192     c->m[k] = ppMult_qq(a->m[k], p);
    193   c->m[0] = pMult(pCopy(a->m[0]), p);
     171    c->m[k] = pp_Mult_qq(a->m[k], p, R);
     172  c->m[0] = p_Mult_q(p_Copy(a->m[0], R), p, R);
    194173  return c;
    195174}
    196175
    197 /*2
    198 * multiply a matrix 'a' by a poly 'p', destroy the args
    199 */
    200 matrix mpMultP(matrix a, poly p)
     176/// multiply a matrix 'a' by a poly 'p', destroy the args
     177matrix mp_MultP(matrix a, poly p, const ring R)
    201178{
    202179  int k, n = a->nrows, m = a->ncols;
    203180
    204   pNormalize(p);
     181  p_Normalize(p, R);
    205182  for (k=m*n-1; k>0; k--)
    206183  {
    207184    if (a->m[k]!=NULL)
    208       a->m[k] = pMult(a->m[k], pCopy(p));
    209   }
    210   a->m[0] = pMult(a->m[0], p);
     185      a->m[k] = p_Mult_q(a->m[k], p_Copy(p, R), R);
     186  }
     187  a->m[0] = p_Mult_q(a->m[0], p, R);
    211188  return a;
    212189}
     
    215192* multiply a poly 'p' by a matrix 'a', destroy the args
    216193*/
    217 matrix pMultMp(poly p, matrix a)
     194matrix pMultMp(poly p, matrix a, const ring R)
    218195{
    219196  int k, n = a->nrows, m = a->ncols;
    220197
    221   pNormalize(p);
     198  p_Normalize(p, R);
    222199  for (k=m*n-1; k>0; k--)
    223200  {
    224201    if (a->m[k]!=NULL)
    225       a->m[k] = pMult(pCopy(p), a->m[k]);
    226   }
    227   a->m[0] = pMult(p, a->m[0]);
     202      a->m[k] = p_Mult_q(p_Copy(p, R), a->m[k], R);
     203  }
     204  a->m[0] = p_Mult_q(p, a->m[0], R);
    228205  return a;
    229206}
    230207
    231 matrix mpAdd(matrix a, matrix b)
     208matrix mp_Add(matrix a, matrix b, const ring R)
    232209{
    233210  int k, n = a->nrows, m = a->ncols;
     
    242219  matrix c = mpNew(n,m);
    243220  for (k=m*n-1; k>=0; k--)
    244     c->m[k] = pAdd(pCopy(a->m[k]), pCopy(b->m[k]));
     221    c->m[k] = p_Add_q(p_Copy(a->m[k], R), p_Copy(b->m[k], R), R);
    245222  return c;
    246223}
    247224
    248 matrix mpSub(matrix a, matrix b)
     225matrix mp_Sub(matrix a, matrix b, const ring R)
    249226{
    250227  int k, n = a->nrows, m = a->ncols;
     
    259236  matrix c = mpNew(n,m);
    260237  for (k=m*n-1; k>=0; k--)
    261     c->m[k] = pSub(pCopy(a->m[k]), pCopy(b->m[k]));
     238    c->m[k] = p_Sub(p_Copy(a->m[k], R), p_Copy(b->m[k], R), R);
    262239  return c;
    263240}
    264241
    265 matrix mpMult(matrix a, matrix b)
     242matrix mp_Mult(matrix a, matrix b, const ring R)
    266243{
    267244  int i, j, k;
     
    293270          {
    294271            poly *cij=&(MATELEM(c,i,j));
    295             poly s = ppMult_qq(aik /*MATELEM(a,i,k)*/, bkj/*MATELEM(b,k,j)*/);
     272            poly s = pp_Mult_qq(aik /*MATELEM(a,i,k)*/, bkj/*MATELEM(b,k,j)*/, R);
    296273            if (/*MATELEM(c,i,j)*/ (*cij)==NULL) (*cij)=s;
    297             else (*cij) = pAdd((*cij) /*MATELEM(c,i,j)*/ ,s);
     274            else (*cij) = p_Add_q((*cij) /*MATELEM(c,i,j)*/ ,s, R);
    298275          }
    299276        }
     
    303280    }
    304281  }
    305   for(i=m*q-1;i>=0;i--) pNormalize(c->m[i]);
     282  for(i=m*q-1;i>=0;i--) p_Normalize(c->m[i], R);
    306283  return c;
    307284}
    308285
    309 matrix mpTransp(matrix a)
     286matrix mp_Transp(matrix a, const ring R)
    310287{
    311288  int    i, j, r = MATROWS(a), c = MATCOLS(a);
     
    318295    for (j=0; j<r; j++)
    319296    {
    320       if (a->m[j*c+i]!=NULL) *p = pCopy(a->m[j*c+i]);
     297      if (a->m[j*c+i]!=NULL) *p = p_Copy(a->m[j*c+i], R);
    321298      p++;
    322299    }
     
    328305*returns the trace of matrix a
    329306*/
    330 poly mpTrace ( matrix a)
     307poly mp_Trace ( matrix a, const ring R)
    331308{
    332309  int i;
     
    335312
    336313  for (i=1; i<=n; i++)
    337     t = pAdd(t, pCopy(MATELEM(a,i,i)));
     314    t = p_Add_q(t, p_Copy(MATELEM(a,i,i), R), R);
    338315  return t;
    339316}
     
    342319*returns the trace of the product of a and b
    343320*/
    344 poly TraceOfProd ( matrix a, matrix b, int n)
     321poly TraceOfProd ( matrix a, matrix b, int n, const ring _R)
    345322{
    346323  int i, j;
     
    351328    for (j=1; j<=n; j++)
    352329    {
    353       p = ppMult_qq(MATELEM(a,i,j), MATELEM(b,j,i));
    354       t = pAdd(t, p);
     330      p = pp_Mult_qq(MATELEM(a,i,j), MATELEM(b,j,i), _R);
     331      t = p_Add_q(t, p, _R);
    355332    }
    356333  }
     
    388365  int       *qrow, *qcol;
    389366  poly      *Xarray;
     367  ring      _R;
     368 
    390369  void mpInitMat();
    391370  poly * mpRowAdr(int);
     
    396375  void mpColSwap(int, int);
    397376  public:
    398   mp_permmatrix() : a_m(0) {}
    399   mp_permmatrix(matrix);
     377  mp_permmatrix() : a_m(0), _R(NULL) {}
     378  mp_permmatrix(matrix, const ring);
    400379  mp_permmatrix(mp_permmatrix *);
    401380  ~mp_permmatrix();
     
    421400#define SIZE_OF_SYSTEM_PAGE 4096
    422401#endif
    423 /*2
    424 * entries of a are minors and go to result (only if not in R)
    425 */
    426 void mpMinorToResult(ideal result, int &elems, matrix a, int r, int c,
    427                      ideal R)
     402
     403/*
     404/// entries of a are minors and go to result (only if not in R)
     405void mp_MinorToResult(ideal result, int &elems, matrix a, int r, int c,
     406                     ideal R, const ring _R)
    428407{
    429408  poly *q1;
     
    471450}
    472451
    473 /*2
    474 * produces recursively the ideal of all arxar-minors of a
    475 */
    476 void mpRecMin(int ar,ideal result,int &elems,matrix a,int lr,int lc,
    477               poly barDiv, ideal R)
     452/// produces recursively the ideal of all arxar-minors of a
     453void mp_RecMin(int ar,ideal result,int &elems,matrix a,int lr,int lc,
     454              poly barDiv, ideal R, const ring _R)
    478455{
    479456  int k;
     
    483460  loop
    484461  {
    485 /*--- look for an optimal row and bring it to last position ------------*/
     462// --- look for an optimal row and bring it to last position ------------
    486463    if(mpPrepareRow(a,lr,lc)==0) break;
    487 /*--- now take all pivots from the last row ------------*/
     464// --- now take all pivots from the last row ------------
    488465    k = lc;
    489466    loop
     
    501478    }
    502479    if (ar>=kr) break;
    503 /*--- now we have to take out the last row...------------*/
     480// --- now we have to take out the last row...------------
    504481    lr = kr;
    505482    kr--;
     
    507484  mpFinalClean(nextLevel);
    508485}
     486*/
     487
    509488
    510489/*2
     
    512491*uses Bareiss algorithm
    513492*/
    514 poly mpDetBareiss (matrix a)
     493poly mp_DetBareiss (matrix a, const ring R)
    515494{
    516495  int s;
     
    521500    return NULL;
    522501  }
    523   matrix c = mpCopy(a);
    524   mp_permmatrix *Bareiss = new mp_permmatrix(c);
     502  matrix c = mp_Copy(a, R);
     503  mp_permmatrix *Bareiss = new mp_permmatrix(c, R);
    525504  row_col_weight w(Bareiss->mpGetRdim(), Bareiss->mpGetCdim());
    526505
     
    541520  res = MATELEM(c,1,1);
    542521  MATELEM(c,1,1) = NULL;
    543   idDelete((ideal *)&c);
     522  id_Delete((ideal *)&c, R);
    544523  if (s < 0)
    545     res = pNeg(res);
     524    res = p_Neg(res, R);
    546525  return res;
    547526}
     
    551530*uses Newtons formulea for symmetric functions
    552531*/
    553 poly mpDet (matrix m)
     532poly mp_Det (matrix m, const ring R)
    554533{
    555534  int i,j,k,n;
     
    565544    return NULL;
    566545  }
    567   k=rChar();
     546  k=rChar(R);
    568547  if ((k > 0) && (k <= n))
    569     return mpLeibnitz(m);
    570   ONE = nInit(1);
    571   ma[1]=mpCopy(m);
     548    return mp_Leibnitz(m, R);
     549  ONE = n_Init(1, R);
     550  ma[1]=mp_Copy(m, R);
    572551  k = (n+1) / 2;
    573552  s = mpNew(1, n);
    574   MATELEM(s,1,1) = mpTrace(m);
     553  MATELEM(s,1,1) = mp_Trace(m, R);
    575554  for (i=2; i<=k; i++)
    576555  {
    577556    //ma[i] = mpNew(n,n);
    578     ma[i]=mpMult(ma[i-1], ma[1]);
    579     MATELEM(s,1,i) = mpTrace(ma[i]);
    580     pTest(MATELEM(s,1,i));
     557    ma[i]=mp_Mult(ma[i-1], ma[1], R);
     558    MATELEM(s,1,i) = mp_Trace(ma[i], R);
     559    p_Test(MATELEM(s,1,i), R);
    581560  }
    582561  for (i=k+1; i<=n; i++)
    583562  {
    584     MATELEM(s,1,i) = TraceOfProd(ma[i / 2], ma[(i+1) / 2], n);
    585     pTest(MATELEM(s,1,i));
     563    MATELEM(s,1,i) = TraceOfProd(ma[i / 2], ma[(i+1) / 2], n, R);
     564    p_Test(MATELEM(s,1,i), R);
    586565  }
    587566  for (i=1; i<=k; i++)
    588     idDelete((ideal *)&(ma[i]));
     567    id_Delete((ideal *)&(ma[i]), R);
    589568/* the array s contains the traces of the powers of the matrix m,
    590569*  these are the power sums of the eigenvalues of m */
    591570  a = mpNew(1,n);
    592   MATELEM(a,1,1) = minuscopy(MATELEM(s,1,1));
     571  MATELEM(a,1,1) = minuscopy(MATELEM(s,1,1), R);
    593572  for (i=2; i<=n; i++)
    594573  {
    595     p = pCopy(MATELEM(s,1,i));
     574    p = p_Copy(MATELEM(s,1,i), R);
    596575    for (j=i-1; j>=1; j--)
    597576    {
    598       q = ppMult_qq(MATELEM(s,1,j), MATELEM(a,1,i-j));
    599       pTest(q);
    600       p = pAdd(p,q);
     577      q = pp_Mult_qq(MATELEM(s,1,j), MATELEM(a,1,i-j), R);
     578      p_Test(q, R);
     579      p = p_Add_q(p,q, R);
    601580    }
    602581    // c= -1/i
    603     d = nInit(-(int)i);
    604     c = nDiv(ONE, d);
    605     nDelete(&d);
    606 
    607     pMult_nn(p, c);
    608     pTest(p);
     582    d = n_Init(-(int)i, R);
     583    c = n_Div(ONE, d, R);
     584    n_Delete(&d, R);
     585
     586    p_Mult_nn(p, c, R);
     587    p_Test(p, R);
    609588    MATELEM(a,1,i) = p;
    610     nDelete(&c);
     589    n_Delete(&c, R);
    611590  }
    612591/* the array a contains the elementary symmetric functions of the
     
    614593  for (i=1; i<=n-1; i++)
    615594  {
    616     //pDelete(&(MATELEM(a,1,i)));
    617     pDelete(&(MATELEM(s,1,i)));
    618   }
    619   pDelete(&(MATELEM(s,1,n)));
     595    //p_Delete(&(MATELEM(a,1,i)), R);
     596    p_Delete(&(MATELEM(s,1,i)), R);
     597  }
     598  p_Delete(&(MATELEM(s,1,n)), R);
    620599/* up to a sign, the determinant is the n-th elementary symmetric function */
    621600  if ((n/2)*2 < n)
    622601  {
    623     d = nInit(-1);
    624     pMult_nn(MATELEM(a,1,n), d);
    625     nDelete(&d);
    626   }
    627   nDelete(&ONE);
    628   idDelete((ideal *)&s);
     602    d = n_Init(-1, R);
     603    p_Mult_nn(MATELEM(a,1,n), d, R);
     604    n_Delete(&d, R);
     605  }
     606  n_Delete(&ONE, R);
     607  id_Delete((ideal *)&s, R);
    629608  poly result=MATELEM(a,1,n);
    630609  MATELEM(a,1,n)=NULL;
    631   idDelete((ideal *)&a);
     610  id_Delete((ideal *)&a, R);
    632611  return result;
    633612}
     
    636615* compute all ar-minors of the matrix a
    637616*/
    638 matrix mpWedge(matrix a, int ar)
     617matrix mp_Wedge(matrix a, int ar, const ring R)
    639618{
    640619  int     i,j,k,l;
     
    699678//    {
    700679//      p=pHomogen(MATELEM(a,i,j),v);
    701 //      pDelete(&(MATELEM(a,i,j)));
     680//      p_Delete(&(MATELEM(a,i,j)), ?);
    702681//      MATELEM(a,i,j)=p;
    703682//    }
     
    710689* var has to be the number of a variable
    711690*/
    712 matrix mpCoeffs (ideal I, int var)
     691matrix mp_Coeffs (ideal I, int var, const ring R)
    713692{
    714693  poly h,f;
     
    721700    while (f!=NULL)
    722701    {
    723       l=pGetExp(f,var);
     702      l=p_GetExp(f,var, R);
    724703      if (l>m) m=l;
    725704      pIter(f);
     
    735714    while (f!=NULL)
    736715    {
    737       l=pGetExp(f,var);
    738       pSetExp(f,var,0);
    739       c=si_max((int)pGetComp(f),1);
    740       pSetComp(f,0);
    741       pSetm(f);
     716      l=p_GetExp(f,var, R);
     717      p_SetExp(f,var,0, R);
     718      c=si_max((int)p_GetComp(f, R),1);
     719      p_SetComp(f,0, R);
     720      p_Setm(f, R);
    742721      /* now add the resulting monomial to co*/
    743722      h=pNext(f);
    744723      pNext(f)=NULL;
    745724      //MATELEM(co,c*(m+1)-l,i+1)
    746       //  =pAdd(MATELEM(co,c*(m+1)-l,i+1),f);
     725      //  =p_Add_q(MATELEM(co,c*(m+1)-l,i+1),f, R);
    747726      MATELEM(co,(c-1)*(m+1)+l+1,i+1)
    748         =pAdd(MATELEM(co,(c-1)*(m+1)+l+1,i+1),f);
     727        =p_Add_q(MATELEM(co,(c-1)*(m+1)+l+1,i+1),f, R);
    749728      /* iterate f*/
    750729      f=h;
    751730    }
    752731  }
    753   idDelete(&I);
     732  id_Delete(&I, R);
    754733  return co;
    755734}
     
    760739* build the matrix of the corresponding monomials in m
    761740*/
    762 void   mpMonomials(matrix c, int r, int var, matrix m)
     741void   mp_Monomials(matrix c, int r, int var, matrix m, const ring R)
    763742{
    764743  /* clear contents of m*/
     
    768747    for(l=MATCOLS(m);l>0;l--)
    769748    {
    770       pDelete(&MATELEM(m,k,l));
     749      p_Delete(&MATELEM(m,k,l), R);
    771750    }
    772751  }
     
    780759  int p=MATCOLS(m)/r-1;
    781760  /* fill in the powers of x_var=h*/
    782   poly h=pOne();
     761  poly h=p_One(R);
    783762  for(k=r;k>0; k--)
    784763  {
    785     MATELEM(m,k,k*(p+1))=pOne();
     764    MATELEM(m,k,k*(p+1))=p_One(R);
    786765  }
    787766  for(l=p;l>=0; l--)
     
    791770    for(k=r;k>0; k--)
    792771    {
    793       MATELEM(m,k,k*(p+1)-l)=pCopy(h);
    794     }
    795   }
    796   pDelete(&h);
    797 }
    798 
    799 matrix mpCoeffProc (poly f, poly vars)
     772      MATELEM(m,k,k*(p+1)-l)=p_Copy(h, R);
     773    }
     774  }
     775  p_Delete(&h), R;
     776}
     777
     778matrix mp_CoeffProc (poly f, poly vars, const ring R)
    800779{
    801780  assume(vars!=NULL);
     
    808787  {
    809788    co = mpNew(2, 1);
    810     MATELEM(co,1,1) = pOne();
     789    MATELEM(co,1,1) = p_One(R);
    811790    MATELEM(co,2,1) = NULL;
    812791    return co;
     
    849828        if (h!=NULL)
    850829        {
    851           MATELEM(co,2,i) = pAdd(MATELEM(co,2,i), h);
     830          MATELEM(co,2,i) = p_Add_q(MATELEM(co,2,i), h, R);
    852831          break;
    853832        }
     
    861840          if (h!=NULL)
    862841          {
    863             MATELEM(co,2,pos_of_1) = pAdd(MATELEM(co,2,pos_of_1), h);
     842            MATELEM(co,2,pos_of_1) = p_Add_q(MATELEM(co,2,pos_of_1), h, R);
    864843          }
    865844        }
     
    878857* consider all variables in vars
    879858*/
    880 static poly mpExdiv ( poly m, poly d, poly vars)
     859static poly mp_Exdiv ( poly m, poly d, poly vars, const ring _R)
    881860{
    882861  int i;
     
    888867      if (pGetExp(d,i) != pGetExp(h,i))
    889868      {
    890         pDelete(&h);
     869        p_Delete(&h, _R);
    891870        return NULL;
    892871      }
     
    898877}
    899878
    900 void mpCoef2(poly v, poly mon, matrix *c, matrix *m)
     879void mp_Coef2(poly v, poly mon, matrix *c, matrix *m, const ring _R)
    901880{
    902881  polyset s;
     
    947926        {
    948927          pSetComp(h,0);
    949           MATELEM(*c,j,i) = pAdd(MATELEM(*c,j,i), h);
     928          MATELEM(*c,j,i) = p_Add_q(MATELEM(*c,j,i), h, _R);
    950929          break;
    951930        }
     
    961940
    962941
    963 BOOLEAN mpEqual(matrix a, matrix b)
     942BOOLEAN mp_Equal(matrix a, matrix b, const ring _R)
    964943{
    965944  if ((MATCOLS(a)!=MATCOLS(b)) || (MATROWS(a)!=MATROWS(b)))
     
    974953    else
    975954      if (b->m[i]==NULL) return FALSE;
    976       else if (pCmp(a->m[i],b->m[i])!=0) return FALSE;
     955      else if (p_Cmp(a->m[i],b->m[i], _R)!=0) return FALSE;
    977956    i--;
    978957  }
     
    981960  {
    982961#if 0
    983     poly tt=pSub(pCopy(a->m[i]),pCopy(b->m[i]));
     962    poly tt=p_Sub(p_Copy(a->m[i], _R),p_Copy(b->m[i], _R), _R);
    984963    if (tt!=NULL)
    985964    {
    986       pDelete(&tt);
     965      p_Delete(&tt, _R);
    987966      return FALSE;
    988967    }
    989968#else
    990     if(!pEqualPolys(a->m[i],b->m[i])) return FALSE;
     969    if(!p_EqualPolys(a->m[i],b->m[i], _R)) return FALSE;
    991970#endif
    992971    i--;
     
    1014993}
    1015994
    1016 mp_permmatrix::mp_permmatrix(matrix A) : sign(1)
     995mp_permmatrix::mp_permmatrix(matrix A, const ring r) : sign(1),  _R(r)
    1017996{
    1018997  a_m = A->nrows;
     
    10301009  a_n = M->s_n;
    10311010  sign = M->sign;
     1011  _R = M->_R;
     1012 
    10321013  this->mpInitMat();
    10331014  Xarray = (poly *)omAlloc0(a_m*a_n*sizeof(poly));
     
    10581039    {
    10591040      for (k=a_m*a_n-1; k>=0; k--)
    1060         pDelete(&Xarray[k]);
     1041        p_Delete(&Xarray[k], _R);
    10611042      omFreeSize((ADDRESS)Xarray,a_m*a_n*sizeof(poly));
    10621043    }
     
    10861067void mp_permmatrix::mpDelElem(int r, int c)
    10871068{
    1088   pDelete(&Xarray[a_n*qrow[r]+qcol[c]]);
     1069  p_Delete(&Xarray[a_n*qrow[r]+qcol[c]], _R);
    10891070}
    10901071
     
    11161097          {
    11171098            q1 = SM_MULT(a[jj], piv, div);
    1118             pDelete(&a[jj]);
    1119             q2 = pAdd(q2, q1);
     1099            p_Delete(&a[jj]), _R;
     1100            q2 = p_Add_q(q2, q1, _R);
    11201101          }
    11211102        }
     
    11281109        a[jj] = q2;
    11291110      }
    1130       pDelete(&a[qcol[s_n]]);
     1111      p_Delete(&a[qcol[s_n]], _R);
    11311112    }
    11321113    else
     
    11381119        {
    11391120          q2 = SM_MULT(a[jj], piv, div);
    1140           pDelete(&a[jj]);
     1121          p_Delete(&a[jj], _R);
    11411122          if (div)
    11421123            SM_DIV(q2, div);
     
    11781159          fo = f1;
    11791160          if (iopt >= 0)
    1180             pDelete(&(this->mpRowAdr(iopt)[qcol[0]]));
     1161            p_Delete(&(this->mpRowAdr(iopt)[qcol[0]]), _R);
    11811162          iopt = i;
    11821163        }
    11831164        else
    1184           pDelete(&(this->mpRowAdr(i)[qcol[0]]));
     1165          p_Delete(&(this->mpRowAdr(i)[qcol[0]]), _R);
    11851166      }
    11861167    }
     
    12571238        fo = f1;
    12581239        if (iopt >= 0)
    1259         pDelete(&(this->mpRowAdr(iopt)[qcol[0]]));
     1240        p_Delete(&(this->mpRowAdr(iopt)[qcol[0]]), _R);
    12601241        iopt = row;
    12611242      }
    12621243      else
    1263         pDelete(&(this->mpRowAdr(row)[qcol[0]]));
     1244        p_Delete(&(this->mpRowAdr(row)[qcol[0]]), _R);
    12641245    }
    12651246    if (iopt >= 0)
     
    14581439}
    14591440
    1460 /*
    1461 * perform replacement for pivot strategy in Bareiss algorithm
    1462 * change sign of determinant
    1463 */
     1441/// perform replacement for pivot strategy in Bareiss algorithm
     1442/// change sign of determinant
    14641443static void mpReplace(int j, int n, int &sign, int *perm)
    14651444{
     
    15271506}
    15281507
    1529 static poly mpLeibnitz(matrix a)
     1508static poly mp_Leibnitz(matrix a, const ring _R)
    15301509{
    15311510  int i, e, n;
     
    15351514  n = MATROWS(a);
    15361515  memset(&z,0,(n+2)*sizeof(int));
    1537   p = pOne();
     1516  p = p_One(_R);
    15381517  for (i=1; i <= n; i++)
    1539     p = pMult(p, pCopy(MATELEM(a, i, i)));
     1518    p = p_Mult_q(p, p_Copy(MATELEM(a, i, i), _R), _R);
    15401519  d = p;
    15411520  for (i=1; i<= n; i++)
     
    15481527    {
    15491528      e = mpNextperm((perm *)&z, n);
    1550       p = pOne();
     1529      p = p_One(_R);
    15511530      for (i = 1; i <= n; i++)
    1552         p = pMult(p, pCopy(MATELEM(a, i, z[i])));
     1531        p = p_Mult_q(p, p_Copy(MATELEM(a, i, z[i]), _R), _R);
    15531532      if (z[0] > 0)
    1554         d = pAdd(d, p);
     1533        d = p_Add_q(d, p, _R);
    15551534      else
    1556         d = pSub(d, p);
     1535        d = p_Sub_q(d, p, _R);
    15571536    }
    15581537  }
     
    15601539}
    15611540
    1562 static poly minuscopy (poly p)
     1541static poly minuscopy (poly p, const ring R)
    15631542{
    15641543  poly w;
    15651544  number  e;
    1566   e = nInit(-1);
    1567   w = pCopy(p);
    1568   pMult_nn(w, e);
    1569   nDelete(&e);
     1545  e = n_Init(-1, R);
     1546  w = p_Copy(p, R);
     1547  p_Mult_nn(w, e, R);
     1548  n_Delete(&e, R);
    15701549  return w;
    15711550}
     
    15751554* arguments are destroyed
    15761555*/
    1577 static poly pInsert(poly p1, poly p2)
     1556static poly p_Insert(poly p1, poly p2, const ring R)
    15781557{
    15791558  poly a1, p, a2, a;
     
    15841563  a1 = p1;
    15851564  a2 = p2;
    1586   a = p  = pOne();
     1565  a = p  = p_One(R);
    15871566  loop
    15881567  {
     
    16331612*    x^i*y^j (i, j >= 0) that appear in fro
    16341613*/
    1635 static poly mpSelect (poly fro, poly what)
     1614static poly mp_Select (poly fro, poly what, const ring _R)
    16361615{
    16371616  int i;
     
    16401619  while (fro!=NULL)
    16411620  {
    1642     h = pOne();
     1621    h = p_One(_R);
    16431622    for (i=1; i<=pVariables; i++)
    1644       pSetExp(h,i, pGetExp(fro,i) * pGetExp(what, i));
    1645     pSetComp(h, pGetComp(fro));
    1646     pSetm(h);
    1647     res = pInsert(h, res);
     1623      p_SetExp(h,i, p_GetExp(fro,i, _R) * p_GetExp(what, i, _R), _R);
     1624    p_SetComp(h, p_GetComp(fro, _R), _R);
     1625    p_Setm(h, _R);
     1626    res = p_Insert(h, res, _R);
    16481627    fro = fro->next;
    16491628  }
     
    16671646*/
    16681647
    1669 static void mpPartClean(matrix a, int lr, int lc)
     1648static void mp_PartClean(matrix a, int lr, int lc, const ring _R)
    16701649{
    16711650  poly *q1;
     
    16751654  {
    16761655    q1 = &(a->m)[i*a->ncols];
    1677     for (j=lc-1;j>=0;j--) if(q1[j]) pDelete(&q1[j]);
    1678   }
    1679 }
    1680 
    1681 static void mpFinalClean(matrix a)
     1656    for (j=lc-1;j>=0;j--) if(q1[j]) p_Delete(&q1[j], _R);
     1657  }
     1658}
     1659
     1660static void mp_FinalClean(matrix a, const ring _R)
    16821661{
    16831662  omFreeSize((ADDRESS)a->m,a->nrows*a->ncols*sizeof(poly));
     
    16891668*  for application in minor
    16901669*/
    1691 static int mpPrepareRow (matrix a, int lr, int lc)
     1670static int mp_PrepareRow (matrix a, int lr, int lc, const ring _R)
    16921671{
    16931672  int r;
    16941673
    1695   r = mpPivBar(a,lr,lc);
     1674  r = mp_PivBar(a,lr,lc, _R);
    16961675  if(r==0) return 0;
    1697   if(r<lr) mpSwapRow(a, r, lr, lc);
     1676  if(r<lr) mp_SwapRow(a, r, lr, lc, _R);
    16981677  return 1;
    16991678}
     
    17031682*  for application in minor
    17041683*/
    1705 static int mpPreparePiv (matrix a, int lr, int lc)
     1684static int mp_PreparePiv (matrix a, int lr, int lc, const ring _R)
    17061685{
    17071686  int c;
    17081687
    1709   c = mpPivRow(a, lr, lc);
     1688  c = mp_PivRow(a, lr, lc, _R);
    17101689  if(c==0) return 0;
    1711   if(c<lc) mpSwapCol(a, c, lr, lc);
     1690  if(c<lc) mp_SwapCol(a, c, lr, lc, _R);
    17121691  return 1;
    17131692}
     
    17161695* find best row
    17171696*/
    1718 static int mpPivBar(matrix a, int lr, int lc)
     1697static int mp_PivBar(matrix a, int lr, int lc, const ring _R)
    17191698{
    17201699  float f1, f2;
     
    17311710    {
    17321711      if (q1[j]!=NULL)
    1733         f2 += mpPolyWeight(q1[j]);
     1712        f2 += mp_PolyWeight(q1[j], _R);
    17341713    }
    17351714    if ((f2!=0.0) && (f2<f1))
     
    17461725* find pivot in the last row
    17471726*/
    1748 static int mpPivRow(matrix a, int lr, int lc)
     1727static int mp_PivRow(matrix a, int lr, int lc, const ring _R)
    17491728{
    17501729  float f1, f2;
     
    17591738    if (q1[j]!=NULL)
    17601739    {
    1761       f2 = mpPolyWeight(q1[j]);
     1740      f2 = mp_PolyWeight(q1[j], _R);
    17621741      if (f2<f1)
    17631742      {
     
    17741753* weigth of a polynomial, for pivot strategy
    17751754*/
    1776 static float mpPolyWeight(poly p)
     1755static float mp_PolyWeight(poly p, const ring _R)
    17771756{
    17781757  int i;
     
    17811760  if (pNext(p) == NULL)
    17821761  {
    1783     res = (float)nSize(pGetCoeff(p));
     1762    res = (float)n_Size(p_GetCoeff(p, _R), _R);
    17841763    for (i=pVariables;i>0;i--)
    17851764    {
    1786       if(pGetExp(p,i)!=0)
     1765      if(p_GetExp(p,i, _R)!=0)
    17871766      {
    17881767        res += 2.0;
     
    17961775    do
    17971776    {
    1798       res += (float)nSize(pGetCoeff(p))+2.0;
     1777      res += (float)n_Size(p_GetCoeff(p, _R), _R) + 2.0;
    17991778      pIter(p);
    18001779    }
     
    18081787  poly sw;
    18091788  int j;
    1810   polyset a2 = a->m, a1 = &a2[a->ncols*(pos-1)];
     1789  poly* a2 = a->m, a1 = &a2[a->ncols*(pos-1)];
    18111790
    18121791  a2 = &a2[a->ncols*(lr-1)];
     
    18231802  poly sw;
    18241803  int j;
    1825   polyset a2 = a->m, a1 = &a2[pos-1];
     1804  poly* a2 = a->m, a1 = &a2[pos-1];
    18261805
    18271806  a2 = &a2[lc-1];
     
    18341813}
    18351814
    1836 static void mpElimBar(matrix a0, matrix re, poly div, int lr, int lc)
     1815static void mp_ElimBar(matrix a0, matrix re, poly div, int lr, int lc, const ring _R)
    18371816{
    18381817  int r=lr-1, c=lc-1;
     
    18611840          {
    18621841            q2 = SM_MULT(ap[j], elim, div);
    1863             q1 = pAdd(q1,q2);
     1842            q1 = p_Add_q(q1,q2, _R);
    18641843          }
    18651844        }
     
    18901869}
    18911870
    1892 BOOLEAN mpIsDiagUnit(matrix U)
     1871BOOLEAN mp_IsDiagUnit(matrix U, const ring _R)
    18931872{
    18941873  if(MATROWS(U)!=MATCOLS(U))
     
    19001879      if (i==j)
    19011880      {
    1902         if (!pIsUnit(MATELEM(U,i,i))) return FALSE;
     1881        if (!p_IsUnit(MATELEM(U,i,i), _R)) return FALSE;
    19031882      }
    19041883      else if (MATELEM(U,i,j)!=NULL) return FALSE;
     
    19081887}
    19091888
    1910 void iiWriteMatrix(matrix im, const char *n, int dim,int spaces)
     1889void iiWriteMatrix(matrix im, const char *n, int dim, const ring r, int spaces)
    19111890{
    19121891  int i,ii = MATROWS(im)-1;
     
    19231902      else if (dim == 1) Print("%s[%u]=",n,j+1);
    19241903      else if (dim == 0) Print("%s=",n);
    1925       if ((i<ii)||(j<jj)) pWrite(*pp++);
    1926       else                pWrite0(*pp);
    1927     }
    1928   }
    1929 }
    1930 
    1931 char * iiStringMatrix(matrix im, int dim,char ch)
     1904      if ((i<ii)||(j<jj)) p_Write(*pp++, r);
     1905      else                p_Write0(*pp, r);
     1906    }
     1907  }
     1908}
     1909
     1910char * iiStringMatrix(matrix im, int dim, , const ring r, char ch)
    19321911{
    19331912  int i,ii = MATROWS(im);
     
    19401919    for (j=0; j<jj; j++)
    19411920    {
    1942       pString0(*pp++);
     1921      p_String0(*pp++, r);
    19431922      s=StringAppend("%c",ch);
    19441923      if (dim > 1) s = StringAppendS("\n");
     
    19491928}
    19501929
    1951 void   mpDelete(matrix* a, const ring r)
     1930void   mp_Delete(matrix* a, const ring r)
    19521931{
    19531932  id_Delete((ideal *) a, r);
  • libpolys/polys/simpleideals.h

    r0a3a629 r5d9aa6  
    102102intvec *id_Sort(ideal id,BOOLEAN nolex, const ring r);
    103103
     104
     105int     binom (int n,int r);
     106
    104107#endif
Note: See TracChangeset for help on using the changeset viewer.