Changeset a5bf88 in git


Ignore:
Timestamp:
Jun 22, 1999, 1:24:02 PM (24 years ago)
Author:
Wilfred Pohl <pohl@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
Children:
1eb7af12ba2eda02be4f55b12705297ff94d3b13
Parents:
a36a1a32a3460ef9a46e7836e70238b00c8c5618
Message:
normalize and cleardenom


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

Legend:

Unmodified
Added
Removed
  • Singular/sparsmat.cc

    ra36a1a ra5bf88  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: sparsmat.cc,v 1.8 1999-06-10 09:01:17 pohl Exp $ */
     4/* $Id: sparsmat.cc,v 1.9 1999-06-22 11:24:02 pohl Exp $ */
    55
    66/*
     
    1919#include "ideals.h"
    2020#include "numbers.h"
     21#include "longrat.h"
    2122#include "sparsmat.h"
    2223
     
    5859static smpoly smElemCopy(smpoly);
    5960static float smPolyWeight(smpoly);
    60 static smpoly smPoly2Smpoly(poly p);
    61 static poly smSmpoly2Poly(smpoly a);
     61static smpoly smPoly2Smpoly(poly);
     62static poly smSmpoly2Poly(smpoly);
     63static BOOLEAN smHaveDenom(poly);
     64static number smCleardenom(ideal);
    6265
    6366/* class for sparse matrix:
     
    8992  int inred;           // unreducable part
    9093  int rpiv, cpiv;      // position of the pivot
    91   unsigned short *perm;// permutation of rows
     94  int normalize;       // Normalization flag
     95  EXPONENT_TYPE *perm; // permutation of rows
    9296  float wpoints;       // weight of all points
    9397  float *wrw, *wcl;    // weights of rows and columns
     
    120124  void smSign();
    121125  void smInitPerm();
     126  int smCheckNormalize();
     127  void smNormalize();
    122128public:
    123129  sparse_mat(ideal);
     
    189195    return NULL;
    190196  }
     197  number diag,h=nInit(1);
    191198  poly res,save;
    192199  ring origR;
    193200  sip_sring tmpR;
     201  sparse_mat *det;
    194202  ideal II=smRingCopy(I,&origR,tmpR);
    195   sparse_mat *det = new sparse_mat(II);
    196 
     203
     204  diag = smCleardenom(II);
     205  det = new sparse_mat(II);
    197206  idDelete(&II);
    198207  if (det->smGetAct() == NULL)
     
    214223    smRingClean(origR,tmpR);
    215224  }
     225  if (nEqual(diag,h) == FALSE)
     226  {
     227    pMultN(res,diag);
     228    pNormalize(res);
     229  }
     230  nDelete(&diag);
     231  nDelete(&h);
    216232  return res;
    217233}
     
    312328  tored = nrows; // without border
    313329  i = tored+1;
    314   perm = (unsigned short *)Alloc(sizeof(unsigned short)*(i+1));
     330  perm = (EXPONENT_TYPE *)Alloc(sizeof(EXPONENT_TYPE)*(i+1));
    315331  perm[i] = 0;
    316332  m_row = (smpoly *)Alloc0(sizeof(smpoly)*i);
     
    349365  Free((ADDRESS)wrw, sizeof(float)*i);
    350366  Free((ADDRESS)m_row, sizeof(smpoly)*i);
    351   Free((ADDRESS)perm, sizeof(unsigned short)*(i+1));
     367  Free((ADDRESS)perm, sizeof(EXPONENT_TYPE)*(i+1));
    352368}
    353369
     
    396412    return res;
    397413  }
     414  normalize = 0;
    398415  this->smInitPerm();
    399416  this->smPivot();
     
    520537    return;
    521538  }
     539  normalize = this->smCheckNormalize();
     540  if (normalize) this->smNormalize();
    522541  this->smPivot();
    523542  this->smSelectPR();
     
    538557  loop
    539558  {
     559    if (normalize) this->smNormalize();
    540560    this->smNewPivot();
    541561    this->smSelectPR();
     
    14161436      if (f) SM_DIV(ha, m_res[f]->m);
    14171437      a->m = ha;
     1438      if (normalize) pNormalize(a->m);
    14181439    }
    14191440    a = a->n;
     
    14441465        a->m = ha;
    14451466      }
     1467      if (normalize) pNormalize(a->m);
     1468      a = a->n;
     1469    } while (a != NULL);
     1470  }
     1471}
     1472
     1473/*
     1474* check for denominators
     1475*/
     1476int sparse_mat::smCheckNormalize()
     1477{
     1478  int i;
     1479  smpoly a;
     1480
     1481  for (i=act; i; i--)
     1482  {
     1483    a = m_act[i];
     1484    do
     1485    {
     1486      if(smHaveDenom(a->m)) return 1;
     1487      a = a->n;
     1488    } while (a != NULL);
     1489  }
     1490  return 0;
     1491}
     1492
     1493/*
     1494* normalize
     1495*/
     1496void sparse_mat::smNormalize()
     1497{
     1498  smpoly a;
     1499  int i;
     1500  int e = crd;
     1501
     1502  for (i=act; i; i--)
     1503  {
     1504    a = m_act[i];
     1505    do
     1506    {
     1507      if (e == a->e) pNormalize(a->m);
    14461508      a = a->n;
    14471509    } while (a != NULL);
     
    14631525    if (f) SM_DIV(h, m_res[f]->m);
    14641526    a->m = h;
     1527    if (normalize) pNormalize(a->m);
    14651528    a->f = smPolyWeight(a);
    14661529    return r;
     
    21372200}
    21382201
     2202static BOOLEAN smHaveDenom(poly a)
     2203{
     2204  BOOLEAN sw;
     2205  number x,o=nInit(1);
     2206
     2207  while (a != NULL)
     2208  {
     2209    x = nGetDenom(pGetCoeff(a));
     2210    sw = nEqual(x,o);
     2211    nDelete(&x);
     2212    if (!sw)
     2213    {
     2214      nDelete(&o);
     2215      return TRUE;
     2216    }
     2217    pIter(a);
     2218  }
     2219  nDelete(&o);
     2220  return FALSE;
     2221}
     2222
     2223static number smCleardenom(ideal id)
     2224{
     2225  poly a;
     2226  number x,y,res=nInit(1);
     2227  BOOLEAN sw=FALSE;
     2228
     2229  for (int i=0; i<IDELEMS(id); i++)
     2230  {
     2231    a = id->m[i];
     2232    sw = smHaveDenom(a);
     2233    if (sw) break;
     2234  }
     2235  if (!sw) return res;
     2236  for (int i=0; i<IDELEMS(id); i++)
     2237  {
     2238    a = id->m[i];
     2239    x = nCopy(pGetCoeff(a));
     2240    pCleardenom(a);
     2241    y = nDiv(x,pGetCoeff(a));
     2242    nDelete(&x);
     2243    x = nMult(res,y);
     2244    nNormalize(x);
     2245    nDelete(&res);
     2246    res = x;
     2247  }
     2248  return res;
     2249}
     2250
Note: See TracChangeset for help on using the changeset viewer.