Changeset a5ceaf in git


Ignore:
Timestamp:
Jun 2, 1999, 4:09:36 PM (25 years ago)
Author:
Wilfred Pohl <pohl@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'b4f17ed1d25f93d46dbe29e4b499baecc2fd51bb')
Children:
c801beb15dbf5f6a7997a33c6be813e2a7b471c1
Parents:
1e7da0633882bafa6663fdd72dc3ddf832a44096
Message:
det for sparse


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

Legend:

Unmodified
Added
Removed
  • Singular/sparsmat.cc

    r1e7da06 ra5ceaf  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: sparsmat.cc,v 1.5 1999-03-15 16:55:42 Singular Exp $ */
     4/* $Id: sparsmat.cc,v 1.6 1999-06-02 14:09:34 pohl Exp $ */
    55
    66/*
     
    115115  void smMultCol();
    116116  poly smMultPoly(smpoly);
     117  void smActDel();
     118  void smColDel();
     119  void smPivDel();
     120  void smSign();
    117121public:
    118122  sparse_mat(ideal);
    119123  ~sparse_mat();
     124  int smGetSign() { return sign; }
    120125  smpoly * smGetAct() { return m_act; }
    121126  int smGetRed() { return tored; }
    122127  ideal smRes2Mod();
     128  poly smDet();
    123129  void smBareiss(int, int);
    124130  void smNewBareiss(int, int);
     
    126132};
    127133
    128 /* ----------------- basics (used from 'C') ------------------ */
    129 
    130 lists smCallBareiss(ideal I, int x, int y)
    131 {
    132   lists res=(lists)Alloc(sizeof(slists));
    133   ideal II = idCopy(I);
    134   sparse_mat *bareiss = new sparse_mat(II);
    135   intvec *v;
    136   ideal m;
    137 
    138   idDelete(&II);
    139   if (bareiss->smGetAct() == NULL)
    140   {
    141     Free((ADDRESS)res, sizeof(slists));
    142     return NULL;
    143   }
    144   bareiss->smBareiss(x, y);
    145   m = bareiss->smRes2Mod();
    146   v = new intvec(bareiss->smGetRed());
    147   bareiss->smToIntvec(v);
    148   delete bareiss;
    149   res->Init(2);
    150   res->m[0].rtyp=MODUL_CMD;
    151   res->m[0].data=(void *)m;
    152   res->m[1].rtyp=INTVEC_CMD;
    153   res->m[1].data=(void *)v;
    154   return res;
    155 }
    156 
    157 lists smCallNewBareiss(ideal I, int x, int y)
    158 {
    159   lists res=(lists)Alloc(sizeof(slists));
     134/* ----------------- ops with rings ------------------ */
     135ideal smRingCopy(ideal I, ring *ri, sip_sring &tmpR)
     136{
    160137  ring origR =NULL;
    161   sip_sring tmpR;
    162138  ideal II;
    163139  if (currRing->order[0]!=ringorder_c)
     
    186162    II=idCopy(I);
    187163  }
     164  *ri = origR;
     165  return II;
     166}
     167
     168void smRingClean(ring origR, ip_sring &tmpR)
     169{
     170  rChangeCurrRing(origR,TRUE);
     171  rUnComplete(&tmpR);
     172  Free((ADDRESS)tmpR.order,3*sizeof(int));
     173  Free((ADDRESS)tmpR.block0,3*sizeof(int));
     174  Free((ADDRESS)tmpR.block1,3*sizeof(int));
     175}
     176
     177/* ----------------- basics (used from 'C') ------------------ */
     178/*2
     179*returns the determinant of the module I;
     180*uses Bareiss algorithm
     181*/
     182poly smCallDet(ideal I)
     183{
     184  int r=idRankFreeModule(I);
     185  if (I->ncols != r)
     186  {
     187    Werror("det of %d x %d module (matrix)",r,I->ncols);
     188    return NULL;
     189  }
     190  poly res,save;
     191  ring origR;
     192  sip_sring tmpR;
     193  ideal II=smRingCopy(I,&origR,tmpR);
     194  sparse_mat *det = new sparse_mat(II);
     195
     196  idDelete(&II);
     197  if (det->smGetAct() == NULL)
     198  {
     199    delete det;
     200    if (origR!=NULL) smRingClean(origR,tmpR);
     201    return NULL;
     202  }
     203  res=det->smDet();
     204  if(det->smGetSign()<0) res=pNeg(res);
     205  delete det;
     206  if (origR!=NULL)
     207  {
     208    rChangeCurrRing(origR,TRUE);
     209    save = res;
     210    res = pFetchCopy(&tmpR, save);
     211    rChangeCurrRing(&tmpR,FALSE);
     212    pDelete(&save);
     213    smRingClean(origR,tmpR);
     214  }
     215  return res;
     216}
     217
     218lists smCallBareiss(ideal I, int x, int y)
     219{
     220  lists res=(lists)Alloc(sizeof(slists));
     221  ideal II = idCopy(I);
     222  sparse_mat *bareiss = new sparse_mat(II);
     223  intvec *v;
     224  ideal m;
     225
     226  idDelete(&II);
     227  if (bareiss->smGetAct() == NULL)
     228  {
     229    Free((ADDRESS)res, sizeof(slists));
     230    return NULL;
     231  }
     232  bareiss->smBareiss(x, y);
     233  m = bareiss->smRes2Mod();
     234  v = new intvec(bareiss->smGetRed());
     235  bareiss->smToIntvec(v);
     236  delete bareiss;
     237  res->Init(2);
     238  res->m[0].rtyp=MODUL_CMD;
     239  res->m[0].data=(void *)m;
     240  res->m[1].rtyp=INTVEC_CMD;
     241  res->m[1].data=(void *)v;
     242  return res;
     243}
     244
     245lists smCallNewBareiss(ideal I, int x, int y)
     246{
     247  ring origR;
     248  sip_sring tmpR;
     249  lists res=(lists)Alloc(sizeof(slists));
     250  ideal II=smRingCopy(I,&origR,tmpR);
    188251  sparse_mat *bareiss = new sparse_mat(II);
    189252  ideal mm=II;
     
    194257  {
    195258    delete bareiss;
    196     if (origR!=NULL)
    197     {
    198       rChangeCurrRing(origR,TRUE);
    199       rUnComplete(&tmpR);
    200       Free((ADDRESS)tmpR.order,3*sizeof(int));
    201       Free((ADDRESS)tmpR.block0,3*sizeof(int));
    202       Free((ADDRESS)tmpR.block1,3*sizeof(int));
    203     }
     259    if (origR!=NULL) smRingClean(origR,tmpR);
    204260    v=new intvec(1,pVariables);
    205261  }
     
    217273      mm=idInit(IDELEMS(m),m->rank);
    218274      int k;
    219       for (k=0;k<IDELEMS(m);k++) mm->m[k] = pFetchCopy(origR, m->m[k]);
     275      for (k=0;k<IDELEMS(m);k++) mm->m[k] = pFetchCopy(&tmpR, m->m[k]);
    220276      rChangeCurrRing(&tmpR,FALSE);
    221277      idDelete(&m);
    222       rChangeCurrRing(origR,TRUE);
    223       rUnComplete(&tmpR);
    224       Free((ADDRESS)tmpR.order,3*sizeof(int));
    225       Free((ADDRESS)tmpR.block0,3*sizeof(int));
    226       Free((ADDRESS)tmpR.block1,3*sizeof(int));
     278      smRingClean(origR,tmpR);
    227279    }
    228280    else
     
    259311  tored = nrows; // without border
    260312  i = tored+1;
    261   perm = (unsigned short *)Alloc(sizeof(unsigned short)*i);
     313  perm = (unsigned short *)Alloc(sizeof(unsigned short)*(i+1));
     314  perm[i] = 0;
    262315  m_row = (smpoly *)Alloc0(sizeof(smpoly)*i);
    263316  wrw = (float *)Alloc(sizeof(float)*i);
     
    295348  Free((ADDRESS)wrw, sizeof(float)*i);
    296349  Free((ADDRESS)m_row, sizeof(smpoly)*i);
    297   Free((ADDRESS)perm, sizeof(unsigned short)*i);
     350  Free((ADDRESS)perm, sizeof(unsigned short)*(i+1));
    298351}
    299352
     
    322375}
    323376
     377/* ---------------- the algorithm's ------------------ */
     378/*
     379* the determinant (up to sign), uses new Bareiss elimination
     380*/
     381poly sparse_mat::smDet()
     382{
     383  int y;
     384  poly res = NULL;
     385
     386  if (sign == 0)
     387  {
     388    this->smActDel();
     389    return NULL;
     390  }
     391  if (act < 2)
     392  {
     393    if (act != 0) res = m_act[1]->m;
     394    Free((void *)m_act[1], sizeof(smprec));
     395    return res;
     396  }
     397  this->smPivot();
     398  this->smSign();
     399  this->smSelectPR();
     400  this->sm1Elim();
     401  crd++;
     402  this->smColDel();
     403  act--;
     404  this->smZeroElim();
     405  if (sign == 0)
     406  {
     407    this->smActDel();
     408    return NULL;
     409  }
     410  if (act < 2)
     411  {
     412    if (act != 0) res = m_act[1]->m;
     413    Free((void *)m_act[1], sizeof(smprec));
     414    return res;
     415  }
     416  loop
     417  {
     418    m_res[crd] = piv;
     419    this->smNewPivot();
     420    this->smSign();
     421    this->smSelectPR();
     422    this->smMultCol();
     423    this->smHElim();
     424    crd++;
     425    this->smColDel();
     426    act--;
     427    this->smZeroElim();
     428    if (sign == 0)
     429    {
     430      this->smPivDel();
     431      this->smActDel();
     432      return NULL;
     433    }
     434    if (act < 2)
     435    {
     436      this->smPivDel();
     437      if (act != 0) res = m_act[1]->m;
     438      Free((void *)m_act[1], sizeof(smprec));   
     439      return res;
     440    }
     441  }
     442}
     443
    324444/*
    325445* the Bareiss elimination:
     
    339459    if (act != 0)
    340460    {
    341       oldpiv = NULL;
    342461      this->smCopToRes();
    343462    }
     
    402521    if (act != 0)
    403522    {
    404       oldpiv = NULL;
    405523      this->smCopToRes();
    406524    }
     
    13021420}
    13031421
     1422/*
     1423* delete the m_act finaly
     1424*/
     1425void sparse_mat::smActDel()
     1426{
     1427  smpoly a;
     1428  int i;
     1429
     1430  for (i=act; i; i--)
     1431  {
     1432    a = m_act[i];
     1433    do
     1434    {
     1435      smElemDelete(&a);
     1436    } while (a != NULL);
     1437  }
     1438}
     1439
     1440/*
     1441* delete the pivotcol
     1442*/
     1443void sparse_mat::smColDel()
     1444{
     1445  smpoly a = m_act[act];
     1446
     1447  while (a != NULL)
     1448  {
     1449    smElemDelete(&a);
     1450  }
     1451}
     1452
     1453/*
     1454* delete pivot elements
     1455*/
     1456void sparse_mat::smPivDel()
     1457{
     1458  int i=crd-1;
     1459
     1460  while (i != 0)
     1461  {
     1462    smElemDelete(&m_res[i]);
     1463    i--;
     1464  }
     1465}
     1466
     1467/*
     1468* the sign of the determinant
     1469*/
     1470void sparse_mat::smSign()
     1471{
     1472  int j,i=1;
     1473  if (cpiv!=act) sign=-sign;
     1474  if ((act%2)==0) sign=-sign;
     1475  j=perm[1];
     1476  while(j<rpiv)
     1477  {
     1478    sign=-sign;
     1479    i++;
     1480    j=perm[i];
     1481  }
     1482  while(perm[i]!=0)
     1483  {
     1484    perm[i]=perm[i+1];
     1485    i++;
     1486  }
     1487}
     1488
    13041489/* ----------------- arithmetic ------------------ */
    13051490
     
    14861671}
    14871672
    1488 /*2
     1673/*n
    14891674* exact division a/b
    14901675* a is a result of smMultDiv
  • Singular/sparsmat.h

    r1e7da06 ra5ceaf  
    88 *
    99 *******************************************************************/
    10 /* $Id: sparsmat.h,v 1.1 1999-02-10 16:00:06 Singular Exp $ */
     10/* $Id: sparsmat.h,v 1.2 1999-06-02 14:09:36 pohl Exp $ */
    1111
    1212
     
    1616void smSpecialPolyDiv(poly, poly);
    1717
     18poly smCallDet(ideal I);
    1819lists smCallBareiss(ideal smat, int x, int y);
    1920lists smCallNewBareiss(ideal smat, int x, int y);
Note: See TracChangeset for help on using the changeset viewer.