Changeset 782fcd8 in git


Ignore:
Timestamp:
Jul 6, 2000, 3:32:25 PM (24 years ago)
Author:
Wilfred Pohl <pohl@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
80c3d12cb5c52a12ef67dfc3e65568716ca01a42
Parents:
638c809b49d290a8bcb1aa0d3f1ca8d9890f77f4
Message:
linear solving in bareiss


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

Legend:

Unmodified
Added
Removed
  • Singular/LIB/ntsolve.lib

    r638c809 r782fcd8  
    11///////////////////////////////////////////////////////////////////////////////
    2 version="$Id: ntsolve.lib,v 1.5 2000-01-12 11:01:39 pohl Exp $";
     2version="$Id: ntsolve.lib,v 1.6 2000-07-06 13:32:25 pohl Exp $";
    33info="
    44LIBRARY: ntsolve.lib ONE REAL SOLUTION OF POLYNOMIAL SYSTEMS (NEWTON ITERATION)
     
    1010///////////////////////////////////////////////////////////////////////////////
    1111
    12 proc nt_solve( ideal gls, vector ini, intvec ipar )
     12proc nt_solve( ideal gls, ideal ini, intvec ipar )
    1313"USAGE:   nt_solve(gls,ini,ipar);
    1414         gls: the equations
    15          ini: the vector of initial values
     15         ini: the ideal of initial values
    1616         ipar: control
    1717           ipar[1] - max. number of iterations
     
    2424ASSUME:  gls is a zerodimensional ideal with
    2525         nvars(basering) = size(gls) (> 1)
    26 RETURN:  vector of one solution (if found)
     26RETURN:  ideal of one solution (if found)
    2727         0 (else)
    2828EXAMPLE: example nt_solve; shows an example
     
    3535    if (size(ini) != di){
    3636      ERROR("wrong number of initial values");}
     37    int prec = system("getPrecDigits"); // precision
    3738
    3839    int i1,i2,i3;
     
    4041    int itmax, acc, prot;
    4142    if (i1 < 1){itmax = 100;}else{itmax = ipar[1];}
    42     if (i1 < 2){acc = 10;}else{acc = ipar[2];}
     43    if (i1 < 2){acc = prec/2;}else{acc = ipar[2];}
    4344    if (i1 < 3){prot = 0;}else{prot = ipar[3];}
    44 
    45     int prec = acc+5; // precision in the working ring
     45    if ((acc <= 0)||(acc > prec-1)){acc = prec-1;}
     46
    4647    int dpl = di+1;
    4748    string out; // for prot != 0 and more
    48     intvec permut; // the permutations in bareiss
    4949    out = "ring rnewton=(real,prec),("+varstr(basering)+"),(c,dp);";
    5050    execute(out);
     
    5757      setring rn; kill rnewton;
    5858      ERROR("one var not in equation");}
    59     vector direction,ini1;
     59    list direction;
     60    ideal ini1;
    6061    ini1 = imap(rn,ini);
    6162    number dum,y1,y2,y3,genau;
     
    6970      nt = subst(nt,var(i1),ini1[i1]);}
    7071    // now we have in sub the general structure
    71     // and in nt the strukture with subst. vars
     72    // and in nt the structure with subst. vars
    7273
    7374    // compute initial error
     
    8182
    8283    // find newton direction
    83     list bar = bareiss(nt,1,-1);
    84     nt = bar[1];
    85     permut = bar[2];
    86     kill bar;
    87     direction=nt[di][dpl]/leadcoef(nt[di][di])*gen(di);
    88     for(i1=di-1;i1>0;i1--){
    89       y3 = leadcoef(nt[i1][dpl]);
    90       for(i2=di;i2>i1;i2--){
    91         y3 = y3-leadcoef(direction[i2])*leadcoef(nt[i1][i2]);}
    92       direction = direction+(y3/leadcoef(nt[i1][i1])*gen(i1));}
     84    direction=bareiss(nt,1,-1);
    9385
    9486    // find dumping
    95     dum = linesearch(gls1,ini1,direction,permut,y1,dum,genau);
     87    dum = linesearch(gls1,ini1,direction[1],y1,dum,genau);
     88    if (i3%5 == 0)
     89    {
     90      if (dum <= 0.000001)
     91      {
     92        dum = 1.0;
     93      }
     94    }
    9695    if(prot){out="  dumping = "+string(dum);out;}
    9796
    9897    // new value
    9998    for(i1=di;i1>0;i1--){
    100       ini1=ini1-dum*direction[i1]*gen(permut[i1]);}
     99      ini1[i1]=ini1[i1]-dum*direction[1][i1];}
    101100    nt = sub;
    102101    for (i1=di;i1>0;i1--){
     
    107106  }
    108107
     108    if (y1>y2){
     109      "WARNING: no convergence";}
    109110    setring rn;
    110     if (y1>y2){
    111       kill rnewton;
    112       ERROR("no convergence");}
    113111    ini = imap(rnewton,ini1);
    114112    kill rnewton;
     
    118116{
    119117    "EXAMPLE:";echo=2;
    120     ring rsq = (real,16),(x,y,z,w),(c,lp);
     118    ring rsq = (real,40),(x,y,z,w),lp;
    121119    ideal gls =  x2+y2+z2-10, y2+z3+w-8, xy+yz+xz+w5 - 1,w3+y;
    122     vector ini = [3.1,2.9,1.1,0.5];
    123     intvec ipar = 200,8,1;
    124     vector sol = nt_solve(gls,ini,ipar);
     120    ideal ini = 3.1,2.9,1.1,0.5;
     121    intvec ipar = 200,0,1;
     122    ideal sol = nt_solve(gls,ini,ipar);
    125123    sol;
    126124}
     
    129127static proc sqrt (number wr, number wa, number wg)
    130128{
    131   number we=wr*wg;
     129  number es,we;
    132130  number wb=wa;
    133131  number wf=wb*wb-wr;
    134   while (wf>we)
     132  if(wf>0){
     133    es=wf;}
     134  else{
     135    es=-wf;}
     136  we=wg*es;
     137  while (es>we)
    135138  {
    136139    wf=wf/(wb+wb);
    137140    wb=wb-wf;
    138141    wf=wb*wb-wr;
     142    if(wf>0){
     143      es=wf;}
     144    else{
     145      es=-wf;}
    139146  }
    140147  return(wb);
    141 }
    142 
    143 static proc vl2norm (vector H, number wg)
    144 {
    145   number wa,wb;
    146   int wi;
    147   wa = leadcoef(H[1]);
    148   wa = wa*wa;
    149   for(wi=size(H);wi>1;wi--)
    150   {
    151     wb=leadcoef(H[wi]);
    152     wa=wa+wb*wb;
    153   }
    154   return(sqrt(wa,wa,wg));
    155148}
    156149
     
    185178
    186179static
    187 proc linesearch(ideal nl, vector aa, vector bb, intvec pe,
     180proc linesearch(ideal nl, ideal aa, ideal bb,
    188181number z1, number tt, number gg)
    189182{
    190183  int ii,d;
    191   vector cc;
    192   ideal jn;
    193   number z2,z3,e1;
     184  ideal cc,jn;
     185  number ss,z2,z3,mm;
     186
     187  mm=0.000001;
     188  ss=tt;
    194189  d=size(nl);
    195190  cc=aa;
    196   for(ii=d;ii>0;ii--){cc=cc-tt*bb[ii]*gen(pe[ii]);}
     191  for(ii=d;ii>0;ii--){cc[ii]=cc[ii]-ss*bb[ii];}
    197192  jn=nl;
    198193  for(ii=d;ii>0;ii--){jn=subst(jn,var(ii),cc[ii]);}
    199194  z2=il2norm(jn,gg);
    200195  z3=-1;
    201   e1=1.0e-6;
    202196  while(z2>=z1)
    203197  {
    204     if(tt<e1){return (e1);}
    205     tt=0.5*tt;
     198    ss=0.5*ss;
     199    if(ss<mm){return (mm);}
    206200    cc=aa;
    207201    for(ii=d;ii>0;ii--)
    208202    {
    209       cc=cc-tt*bb[ii]*gen(pe[ii]);
     203      cc[ii]=cc[ii]-ss*bb[ii];
    210204    }
    211205    jn=nl;
     
    218212    while(z3<z2)
    219213    {
    220       tt=tt+tt;
     214      ss=ss+ss;
    221215      cc=aa;
    222216      for(ii=d;ii>0;ii--)
    223217      {
    224         cc=cc-tt*bb[ii]*gen(pe[ii]);
     218        cc[ii]=cc[ii]-ss*bb[ii];
    225219      }
    226220      jn=nl;
     
    232226  z2=z2-z1;
    233227  z3=z3-z1;
    234   tt=0.25*tt*(z3-4*z2)/(z3-2*z2);
    235   if(tt<e1){return (e1);}
    236   return(tt);
     228  ss=0.25*ss*(z3-4*z2)/(z3-2*z2);
     229  if(ss>1.0){return (1.0);}
     230  if(ss<mm){return (mm);}
     231  return(ss);
    237232}
    238233///////////////////////////////////////////////////////////////////////////////
  • Singular/ideals.cc

    r638c809 r782fcd8  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: ideals.cc,v 1.95 2000-05-24 14:32:37 siebert Exp $ */
     4/* $Id: ideals.cc,v 1.96 2000-07-06 13:30:01 pohl Exp $ */
    55/*
    66* ABSTRACT - all basic methods to manipulate ideals
     
    314314}
    315315
     316/*2
     317*test if the ideal has only constant polynomials
     318*/
     319BOOLEAN idIsConstant(ideal id)
     320{
     321  int k;
     322  for (k = IDELEMS(id)-1; k>=0; k--)
     323  {
     324    if (pIsConstantPoly(id->m[k]) == FALSE)
     325      return FALSE;
     326  }
     327  return TRUE;
     328}
    316329
    317330/*2
  • Singular/iparith.cc

    r638c809 r782fcd8  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: iparith.cc,v 1.216 2000-06-06 15:46:34 Singular Exp $ */
     4/* $Id: iparith.cc,v 1.217 2000-07-06 13:30:02 pohl Exp $ */
    55
    66/*
     
    39843984static BOOLEAN jjBAREISS3(leftv res, leftv u, leftv v, leftv w)
    39853985{
    3986   lists l=smCallNewBareiss((ideal)u->Data(),(int)v->Data(),(int)w->Data());
     3986  lists l;
     3987  int k=(int)w->Data();
     3988  if (k>=0)
     3989  {
     3990    l=smCallNewBareiss((ideal)u->Data(),(int)v->Data(),(int)w->Data());
     3991  }
     3992  else
     3993  {
     3994    l=smCallSolv((ideal)u->Data());
     3995  }
    39873996  res->data = (char *)l;
    39883997  return FALSE;
  • Singular/polys1.cc

    r638c809 r782fcd8  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: polys1.cc,v 1.37 2000-05-05 09:46:57 Singular Exp $ */
     4/* $Id: polys1.cc,v 1.38 2000-07-06 13:30:04 pohl Exp $ */
    55
    66/*
     
    4242    }
    4343    if (pGetComp(p)) return FALSE;
     44  }
     45  return TRUE;
     46}
     47
     48/*2
     49*test if the polynom is a constant
     50*/
     51BOOLEAN   pIsConstantPoly(poly p)
     52{
     53  while(p!=NULL)
     54  {
     55    for (int i=pVariables;i;i--)
     56    {
     57      if (pGetExp(p,i)!=0) return FALSE;
     58    }
     59    pIter(p);
    4460  }
    4561  return TRUE;
  • Singular/sparsmat.cc

    r638c809 r782fcd8  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: sparsmat.cc,v 1.29 2000-06-21 07:32:20 pohl Exp $ */
     4/* $Id: sparsmat.cc,v 1.30 2000-07-06 13:30:04 pohl Exp $ */
    55
    66/*
     
    9797  void smFinalMult();
    9898  void smSparseHomog();
    99   void smRealPivot();
    10099  void smWeights();
    101100  void smPivot();
     
    472471    if (act < 2)
    473472    {
     473      if (TEST_OPT_PROT) PrintS(".\n");
    474474      this->smFinalMult();
    475475      this->smPivDel();
     
    532532    if (act < y)
    533533    {
     534      if (TEST_OPT_PROT) PrintS(".\n");
    534535      this->smCopToRes();
    535536      return;
     
    543544*   - the method will finish for number of unreduced columns < y
    544545*/
    545 void sparse_mat::smNewBareiss(int x, int y0)
    546 {
    547   int y=y0;
     546void sparse_mat::smNewBareiss(int x, int y)
     547{
    548548  if ((x > 0) && (x < nrows))
    549549  {
     
    559559  normalize = this->smCheckNormalize();
    560560  if (normalize) this->smNormalize();
    561   if(y0>=0)
    562     this->smPivot();
    563   else
    564     this->smRealPivot();
     561  this->smPivot();
    565562  this->smSelectPR();
    566563  this->sm1Elim();
     
    581578  {
    582579    if (normalize) this->smNormalize();
    583     if(y0>=0)
    584       this->smNewPivot();
    585     else
    586       this->smRealPivot();
     580    this->smNewPivot();
    587581    this->smSelectPR();
    588582    this->smMultCol();
     
    597591    if (act <= y)
    598592    {
     593      if (TEST_OPT_PROT) PrintS(".\n");
    599594      this->smFinalMult();
    600595      this->smCopToRes();
     
    605600
    606601/* ----------------- pivot method ------------------ */
    607 
    608 void sparse_mat::smRealPivot()
    609 {
    610   smpoly a;
    611   number nopt,n1;
    612   int i, copt, ropt;
    613 
    614   nopt=nInit(0);
    615   for (i=act; i; i--)
    616   {
    617     a = m_act[i];
    618     loop
    619     {
    620       if (a->pos > tored)
    621         break;
    622       n1=pGetCoeff(a->m);
    623       if(nGreaterZero(n1))
    624       {
    625         if(nGreater(n1,nopt))
    626         {
    627           nDelete(&nopt);
    628           nopt=nCopy(n1);
    629           copt=i;
    630           ropt=a->pos;
    631         }
    632       }
    633       else
    634       {
    635         n1=nNeg(n1);
    636         if(nGreater(n1,nopt))
    637         {
    638           nDelete(&nopt);
    639           nopt=nCopy(n1);
    640           copt=i;
    641           ropt=a->pos;
    642         }
    643         n1=nNeg(n1);
    644       }
    645       a = a->n;
    646       if (a == NULL)
    647         break;
    648     }
    649   }
    650   rpiv = ropt;
    651   cpiv = copt;
    652   nDelete(&nopt);
    653   if (cpiv != act)
    654   {
    655     a = m_act[act];
    656     m_act[act] = m_act[cpiv];
    657     m_act[cpiv] = a;
    658   }
    659 }
    660602
    661603/*
     
    24132355  void smRowToCol();
    24142356  void smSelectPR();
    2415   void smRealWeights();
    24162357  void smRealPivot();
    24172358  void smZeroToredElim();
     
    24342375* uses  Gauss-elimination
    24352376*/
    2436 ideal smCallSolv(ideal I)
     2377lists smCallSolv(ideal I)
    24372378{
    24382379  sparse_number_mat *linsolv;
     
    24402381  ring origR;
    24412382  sip_sring tmpR;
    2442   ideal rr, res;
    2443 
     2383  ideal rr, ss;
     2384  lists res;
     2385
     2386  if (idIsConstant(I)==FALSE)
     2387  {
     2388    WerrorS("symbol in equation");
     2389    return NULL;
     2390  }
    24442391  I->rank = idRankFreeModule(I);
    24452392  if (smCheckSolv(I)) return NULL;
     2393  res=(lists)AllocSizeOf(slists);
    24462394  rr=smRingCopy(I,&origR,tmpR);
    2447   res = NULL;
     2395  ss = NULL;
    24482396  linsolv = new sparse_number_mat(rr);
    24492397  linsolv->smTriangular();
     
    24512399  {
    24522400    linsolv->smSolv();
    2453     res = linsolv->smRes2Ideal();
     2401    ss = linsolv->smRes2Ideal();
    24542402  }
    24552403  else
    24562404    WerrorS("singular problem for linsolv");
    24572405  delete linsolv;
    2458   if ((origR!=NULL) && (res!=NULL))
     2406  if ((origR!=NULL) && (ss!=NULL))
    24592407  {
    24602408    rChangeCurrRing(origR,TRUE);
    2461     rr = idInit(IDELEMS(res), 1);
    2462     for (k=0;k<IDELEMS(res);k++)
    2463       rr->m[k] = prCopyR(res->m[k], &tmpR);
     2409    rr = idInit(IDELEMS(ss), 1);
     2410    for (k=0;k<IDELEMS(ss);k++)
     2411      rr->m[k] = prCopyR(ss->m[k], &tmpR);
    24642412    rChangeCurrRing(&tmpR,FALSE);
    2465     idDelete(&res);
    2466     res = rr;
     2413    idDelete(&ss);
     2414    ss = rr;
    24672415  }
    24682416  if(origR!=NULL)
    24692417    smRingClean(origR,tmpR);
     2418  res->Init(1);
     2419  res->m[0].rtyp=IDEAL_CMD;
     2420  res->m[0].data=(void *)ss;
    24702421  return res;
    24712422}
     
    25392490    if (sing != 0) return;
    25402491  }
     2492  if (TEST_OPT_PROT) PrintS(".\n");
    25412493  piv = m_act[1];
    25422494  rpiv = piv->pos;
     
    26462598
    26472599/*
    2648 * prepare smPivot, compute weights for rows and columns
    2649 * and the weight for all points
    2650 */
    2651 void sparse_number_mat::smRealWeights()
    2652 {
    2653   int wc;
     2600* compute pivot
     2601*/
     2602void sparse_number_mat::smRealPivot()
     2603{
    26542604  smnumber a;
    2655   int i;
    2656 
    2657   for (i=tored; i; i--) wrw[i] = 0; // ???
    2658   for (i=act; i; i--)
    2659   {
    2660     wc = 0;
    2661     a = m_act[i];
    2662     loop
    2663     {
    2664       wc++;
    2665       wrw[a->pos]++;
    2666       a = a->n;
    2667       if ((a == NULL) || (a->pos > tored))
    2668         break;
    2669     }
    2670     wcl[i] = wc;
    2671   }
    2672 }
    2673 
    2674 /*
    2675 * compute pivot
    2676 */
    2677 void sparse_number_mat::smRealPivot()
    2678 {
    2679   int wopt = 1<<30;
    2680   int w;
    2681   smnumber a;
    2682   number x, xo, xu;
     2605  number x, xo;
    26832606  int i, copt, ropt;
    26842607
    2685   this->smRealWeights();
    2686   nNew(&xo);
    2687   nNew(&xu);
     2608  xo=nInit(0);
    26882609  for (i=act; i; i--)
    26892610  {
     
    26912612    while ((a!=NULL) && (a->pos<=tored))
    26922613    {
    2693       w = (wcl[i]-1)*(wrw[a->pos]-1);
    2694       if (w==0) // row or column with only one point
    2695       {
    2696         rpiv = a->pos;
    2697         if (i != act)
    2698         {
    2699           a = m_act[act];
    2700           m_act[act] = m_act[i];
    2701           m_act[i] = a;
    2702         }
    2703         return;
    2704       }
    2705       if (w == wopt)
    2706       {
    2707         x = a->m;
    2708         if (nGreater(x,xo) || nGreater(xu,x))
    2709         {
    2710           nDelete(&xu);
     2614      x = a->m;
     2615      if (nGreaterZero(x))
     2616      {
     2617        if (nGreater(x,xo))
     2618        {
    27112619          nDelete(&xo);
    27122620          xo = nCopy(x);
    2713           xu = nCopy(x);
    2714           if (nGreaterZero(xu)) xu = nNeg(xu);
    2715           else xo = nNeg(xo);
    27162621          copt = i;
    27172622          ropt = a->pos;
    27182623        }
    27192624      }
    2720       else if (w < wopt)
    2721       {
    2722         x = a->m;
    2723         wopt = w;
    2724         nDelete(&xu);
    2725         nDelete(&xo);
    2726         xo = nCopy(x);
    2727         xu = nCopy(x);
    2728         if (nGreaterZero(xu)) xu = nNeg(xu);
    2729         else xo = nNeg(xo);
    2730         copt = i;
    2731         ropt = a->pos;
     2625      else
     2626      {
     2627        xo = nNeg(xo);
     2628        if (nGreater(xo,x))
     2629        {
     2630          nDelete(&xo);
     2631          xo = nCopy(x);
     2632          copt = i;
     2633          ropt = a->pos;
     2634        }
     2635        xo = nNeg(xo);
    27322636      }
    27332637      a = a->n;
     
    27422646  }
    27432647  nDelete(&xo);
    2744   nDelete(&xu);
    27452648}
    27462649
     
    28342737  int i;
    28352738
     2739  if (TEST_OPT_PROT)
     2740  {
     2741    if ((crd+1)%10)
     2742      PrintS(".");
     2743    else
     2744      PrintS(".\n");
     2745  }
    28362746  a = m_act[act];
    28372747  if (a->pos < rpiv)
Note: See TracChangeset for help on using the changeset viewer.