Changeset 6ed15c in git for Singular/LIB/solve.lib


Ignore:
Timestamp:
May 2, 2005, 9:43:22 AM (19 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
6eff86e3417d554a62456e5d4f0634e215db4891
Parents:
d1a54b1d03b681db8f1032e2f169a09db7a0faf7
Message:
*lossen: new lib


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

Legend:

Unmodified
Added
Removed
  • Singular/LIB/solve.lib

    rd1a54b r6ed15c  
    11///////////////////////////////////////////////////////////////////////////////
    2 version="$Id: solve.lib,v 1.28 2005-04-25 16:57:36 Singular Exp $";
     2version="$Id: solve.lib,v 1.29 2005-05-02 07:43:22 Singular Exp $";
    33category="Symbolic-numerical solving";
    44info="
     
    4646         parameters.
    4747RETURN:  list of (complex) roots of the polynomial f, depending on n. The
    48          result is of type
    49  string: if the basering is not complex,
    50  number: otherwise.
     48         result is of type@*
     49          string: if the basering is not complex,@*
     50          number: otherwise.
    5151NOTE:    If printlevel >0: displays comments ( default = 0 ).
    5252         If s != 0 and if the procedure stops with ERROR, try a higher
     
    516516
    517517proc solve( ideal G, list # )
    518 "USAGE:   solve(G [, m, n, l] ); G = ideal,
    519          m, n, l = integers (control parameters of the method)
     518"USAGE:   solve(G [, m, n [, l]] [,\"oldring\"] [,\"nodisplay\"] ); G = ideal,
     519         m, n, l = integers (control parameters of the method), outR ring
    520520         m: precision of output in digits ( 4 <= m) and of the
    521521            generated ring of complex numbers;
     
    525525         l: precision of internal computation in decimal digits ( l >=8 )
    526526            only if the basering is not complex or complex with smaller
    527             precision,
    528          ( default: m, n, l = 8, 0, 30 or
    529                     for (n != 0 and size(#) = 2) l = 60 )
     527            precision, @*
     528         [default: (m,n,l) = (8,0,30), or if only (m,n) are set explicitly
     529          with n!=0, then (m,n,l) = (m,n,60) ]
    530530ASSUME:  the ideal is 0-dimensional;@*
    531          basering has characteristic 0 and is either complex or
    532          without parameters;
    533 RETURN:  list of solutions of the ideal G, depending on n; one solution is a
    534          list of complex numbers in the generated output ring (the new
    535          basering).
    536  The result is a list L
    537     n  = 0: a list of all different solutions (L[i]),
    538     n != 0: a list of two elements,
    539             L[i][1] contains all different solutions with the same multiplicity
    540             L[i][2] the multiplicity
    541  L is ordered w.r.t. multiplicity (the smallest first).
    542 NOTE:    If the problem is not 0-dim. the procedure stops with ERROR, if the
    543          ideal G is not a lex. standard basis, it is generated with internal
    544          computation (Hilbert driven), if the input-ring (with char 0) has
    545          the name \"<A>\", the lexicographical and complex output-ring has the
    546          name \"<A>C\".
     531         basering has characteristic 0 and is either complex or without
     532         parameters;
     533RETURN:  (1) If called without the additional parameter @code{\"oldring\"}: @*
     534         ring @code{R} with the same number of variables but with complex
     535         coefficients (and precision m). @code{R} comes with a list
     536         @code{SOL} of numbers, in which complex roots of G are stored: @*
     537         * If n  = 0, @code{SOL} is the list of all different solutions, each
     538         of them being represented by a list of numbers. @*
     539         * If n != 0, @code{SOL} is a list of two list: SOL[i][1] is the list
     540         of all different solutions with the multiplicity SOL[i][2].@*
     541         SOL is ordered w.r.t. multiplicity (the smallest first). @*
     542         (2) If called with the additional parameter @code{\"oldring\"}, the
     543         procedure looks for an appropriate ring (on the Top level) in which
     544         the solutions can be stored (interactive). @*
     545         The user may then select an appropriate ring and choose a name for
     546         the output list in this ring. The list is exported directly to the
     547         selected ring and the return value is a string \"result exported to\"
     548         + name of the selected ring.
     549NOTE:    If the problem is not 0-dim. the procedure stops with ERROR. If the
     550         ideal G is not a lexicographic Groebner basis, the lexicographic
     551         Groebner basis is computed internally (Hilbert driven).  @*
     552         The computed solutions are displayed, unless @code{solve} is called
     553         with the additional parameter @code{\"nodisplay\"}.
    547554EXAMPLE: example solve; shows an example
    548555"
     
    550557// test if basering admissible
    551558  if (char(basering)!=0){ERROR("characteristic of basering not 0");}
    552   if ((charstr(basering)[1]=="0") and (npars(basering)!=0)){ERROR("basering has parameters");}
     559  if ((charstr(basering)[1]=="0") and (npars(basering)!=0)){
     560    ERROR("basering has parameters");
     561  }
    553562
    554563// some global settings and control
     564  int oldr, nodisp, ii, jj;
     565  list LL;
    555566  int outprec = 8;
    556567  int mu = 0;
    557568  int prec = 30;
    558   if (size(#)>0){outprec = #[1];if (outprec<4){outprec = 4;}}
    559   if (size(#)>1){mu = #[2];}
    560   if (size(#)>2){prec = #[3];if (prec<8){prec = 8;}}
    561   else {if(mu!=0){prec = 60;}}
     569  // check additional parameters...
     570  if (size(#)>0){
     571    int sofar=1;
     572    if (typeof(#[1])=="int"){
     573      outprec = #[1];
     574      if (outprec<4){outprec = 4;}
     575      if (size(#)>1){
     576        if (typeof(#[2])=="int"){
     577          mu = #[2];
     578          if (size(#)>2){
     579            if (typeof(#[3])=="int"){
     580              prec = #[3];
     581              if (prec<8){prec = 8;}
     582            }
     583            else {
     584              if(mu!=0){prec = 60;}
     585              if (#[3]=="oldring"){ oldr=1; }
     586              if (#[3]=="nodisplay"){ nodisp=1; }
     587            }
     588            sofar=3;
     589          }
     590        }
     591        else {
     592          if (#[2]=="oldring"){ oldr=1; }
     593          if (#[2]=="nodisplay"){ nodisp=1; }
     594        }
     595        sofar=2;
     596      }
     597    }
     598    else {
     599      if (#[1]=="oldring"){ oldr=1; }
     600      if (#[1]=="nodisplay"){ nodisp=1; }
     601    }   
     602    for (ii=sofar+1;ii<=size(#);ii++) { // check for additional strings
     603       if (#[ii]=="oldring"){ oldr=1; }
     604       if (#[ii]=="nodisplay"){ nodisp=1; }
     605    }
     606  }   
    562607  if (outprec>prec){prec = outprec;}
    563   string rinC = nameof(basering)+"C";
     608
     609  // if interaktive version is chosen -- choice of basering (Top::`outR`)
     610  // and name for list of solutions (outL):
     611  if (oldr==1) {
     612    list Out;
     613    LL=names(Top);
     614    for (ii=1;ii<=size(LL);ii++)
     615    {
     616      if (typeof(`LL[ii]`)=="ring") {
     617        if (find(charstr(`LL[ii]`),"complex,"+string(outprec))){
     618          jj++;
     619          Out[jj]=LL[ii];
     620        }
     621      }
     622    }
     623    if (size(Out)>0) {
     624      print("// *** You may select between the following rings for storing "+
     625            "the list of");
     626      print("// *** complex solutions:");
     627      Out;
     628      print("// *** Enter the number of the chosen ring");
     629      print("// ***  (0: none of them => new ring created and returned)");
     630      string chosen;
     631      while (chosen=="") { chosen=read(""); }
     632      execute("def tchosen = "+chosen);
     633      if (typeof(tchosen)=="int") {
     634        if ((tchosen>0) and (tchosen<=size(Out))) {
     635          string outR = Out[tchosen];
     636          print("// *** You have chosen the ring "+ outR +". In this ring"
     637                +" the following objects");
     638          print("//*** are defined:");
     639          listvar(Top::`outR`);
     640          print("// *** Enter a name for the list of solutions (different "+
     641                "from existing names):");
     642          string outL;
     643          while (outL==""){ outL=read(""); }
     644        }
     645      }
     646    }
     647    else {
     648      print("No appropriate ring for storing the list of solutions found " +
     649             "=> new ring created and returned");
     650    }
     651    if (not(defined(outR))) { oldr=0; }   
     652  }
     653
     654//  string rinC = nameof(basering)+"C";
    564655  string sord = ordstr(basering);
    565656  int nv = nvars(basering);
     
    578669  if (sb){if (dim(G)!=0){ERROR("ideal not zero-dimensional");}}
    579670
    580 // the trivial homog case
     671// the trivial homogeneous case (unique solution: (0,...0))
    581672  if (homog(G))
    582673  {
     
    587678      ideal G = std(imap(rin,G));
    588679      if (dim(G)!=0){ERROR("ideal not zero-dimensional");}
    589     }
    590     changering(rinC,outprec);
    591     list ret0;
    592     if (mu==0){ret0[1] = zerolist(nv);}
    593     else{ret0[1] = list(zerolist(nv),list(vdim(G)));}
    594     option(set,ovec);
    595     keepring basering;
    596     return(ret0);
     680      int vdG=vdim(G);
     681    }
     682    if (oldr!=1) {
     683      execute("ring rinC =(complex,"+string(outprec)+
     684                 "),("+varstr(basering)+"),lp;");
     685      list SOL;
     686      if (mu==0){SOL[1] = zerolist(nv);}
     687      else{SOL[1] = list(zerolist(nv),list(vdG));}
     688      export SOL;
     689      if (nodisp==0) { print(SOL); }
     690      option(set,ovec);
     691      dbprint( printlevel-voice+3,"
     692// 'solve' created a ring, in which a list SOL of numbers (the complex solutions)
     693// is stored.
     694// To access the list of complex solutions, type (if the name R was assigned
     695// to the return value):
     696        setring R; SOL; ");
     697      return(rinC);
     698    }
     699    else {
     700      setring (Top::`outR`);
     701      list SOL;
     702      if (mu==0){SOL[1] = zerolist(nv);}
     703      else{SOL[1] = list(zerolist(nv),list(vdG));}
     704      execute("def "+outL + "=SOL;");
     705      execute("export "+outL+";");
     706      if (nodisp==0) { print(SOL); }
     707      option(set,ovec);
     708      kill SOL;
     709      return("result exported to "+outR+" as list "+outL);
     710    }
    597711  }
    598712
    599713// look for reduced standard basis in lex
    600   if (sb*lp==0)
    601   {
    602     if (sb==0)
    603     {
    604       execute("ring dphilb=("+charstr(rin)+"),("+
    605       varstr(rin)+"),dp;");
     714  if (sb*lp==0) {
     715    if (sb==0) {
     716      execute("ring dphilb=("+charstr(rin)+"),("+ varstr(rin)+"),dp;");
    606717      ideal G = imap(rin,G);
    607718      G = std(G);
    608719      if (dim(G)!=0){ERROR("ideal not zero-dimensional");}
    609720    }
    610     else
    611     {
     721    else {
    612722      def dphilb = basering;     
    613723    }   
    614     execute("ring lexhilb=("+charstr(rin)+"),("+
    615     varstr(rin)+"),lp;");
     724    execute("ring lexhilb=("+charstr(rin)+"),("+ varstr(rin)+"),lp;");
    616725    option(redTail);
    617726    ideal H = fglm(dphilb,G);
     
    619728    H = simplify(H,2);
    620729    if (lp){setring rin;}
    621     else
    622     {
     730    else {
    623731      execute("ring lplex=("+charstr(rin)+"),("+
    624732      varstr(rin)+"),lp;");
     
    631739// only 1 variable
    632740  def hr = basering;
    633   if (nv==1)
    634   {
    635     if ((mu==0) and (charstr(basering)[1]=="0")) // special case
    636     {
     741  if (nv==1) {
     742    if ((mu==0) and (charstr(basering)[1]=="0")) { // special case
    637743      list L = laguerre_solve(H[1],prec,prec,mu,0); // list of strings
    638       changering(rinC,outprec);
    639       list sp;
    640       for (int ii=1; ii<=size(L); ii++ )
    641       {
    642         execute("sp[ii]="+L[ii]);
    643       }
    644       keepring basering;
    645       return(sp);
    646     }
    647     else
    648     {
     744      if (oldr!=1) {
     745        execute("ring rinC =(complex,"+string(outprec)+
     746                   "),("+varstr(basering)+"),lp;");
     747        list SOL;
     748        for (ii=1; ii<=size(L); ii++ ) { execute("SOL[ii]="+L[ii]+";"); }
     749        export SOL;
     750        if (nodisp==0) { print(SOL); }
     751        option(set,ovec);
     752        dbprint( printlevel-voice+3,"
     753// 'solve' created a ring, in which a list SOL of numbers (the complex solutions)
     754// is stored.
     755// To access the list of complex solutions, type (if the name R was assigned
     756// to the return value):
     757        setring R; SOL; ");
     758        return(rinC);
     759      }
     760      else {
     761        setring (Top::`outR`);
     762        list SOL;
     763        for (ii=1; ii<=size(L); ii++ ) { execute("SOL[ii]="+L[ii]+";"); }
     764        execute("def "+outL + "=SOL;");
     765        execute("export "+outL+";");
     766        if (nodisp==0) { print(SOL); }
     767        option(set,ovec);
     768        kill SOL;
     769        return("result exported to "+outR+" as list "+outL);
     770      }
     771    }
     772    else {
    649773      execute("ring internC=(complex,"+string(prec)+
    650774                 "),("+varstr(basering)+"),lp;");
    651 
    652775      ideal H = imap(hr,H);
    653776      list sp = splittolist(splitsqrfree(H[1],var(1)));
    654       int jj = size(sp);
     777      jj = size(sp);
    655778      while(jj>0)
    656779      {
     
    659782      }
    660783      setring hr;
    661       changering(rinC,outprec);
    662       list sp=imap(internC,sp);
    663 
    664       keepring basering;
    665       if(mu!=0){return(sp);}
    666       jj = size(sp);
    667       list ll=sp[jj][1];
    668       while(jj>1)
    669       {
    670         jj--;
    671         ll = sp[jj][1]+ll;
    672       }
    673       return(ll);
     784      if (oldr!=1) {
     785        execute("ring rinC =(complex,"+string(outprec)+
     786                 "),("+varstr(basering)+"),lp;");
     787        list SOL;
     788        list sp=imap(internC,sp);
     789        if(mu!=0){ SOL=sp; }
     790        else {
     791          jj = size(sp);
     792          SOL=sp[jj][1];
     793          while(jj>1) {
     794            jj--;
     795            SOL = sp[jj][1]+SOL;
     796          }
     797        }
     798        export SOL;
     799        if (nodisp==0) { print(SOL); }
     800        option(set,ovec);
     801        dbprint( printlevel-voice+3,"
     802// 'solve' created a ring, in which a list SOL of numbers (the complex solutions)
     803// is stored.
     804// To access the list of complex solutions, type (if the name R was assigned
     805// to the return value):
     806        setring R; SOL; ");
     807        return(rinC);
     808      }
     809      else {
     810        setring (Top::`outR`);
     811        list SOL;
     812        list sp=imap(internC,sp);
     813        if(mu!=0){ SOL=sp; }
     814        else {
     815          jj = size(sp);
     816          SOL=sp[jj][1];
     817          while(jj>1) {
     818            jj--;
     819            SOL = sp[jj][1]+SOL;
     820          }
     821        }
     822        kill sp;
     823        execute("def "+outL + "=SOL;");
     824        execute("export "+outL+";");
     825        if (nodisp==0) { print(SOL); }
     826        option(set,ovec);
     827        kill SOL;
     828        return("result exported to "+outR+" as list "+outL);
     829      }
    674830    }   
    675831  }   
     
    695851  else
    696852  {
    697     changering(rinC,prec);
     853    execute("ring rinC =(complex,"+string(outprec)+
     854                 "),("+varstr(basering)+"),lp;");
    698855  }
    699856  list triC = imap(hr,sp);
     
    724881// final computations
    725882  option(set,ovec);
    726   if (outprec==prec)
    727   {
    728     keepring basering;
    729     return(ret1);
    730   }
    731   changering(rinC,outprec);
    732   keepring basering;
    733   return(imap(internC,ret1));
     883  if (outprec==prec) { // we are in ring rinC
     884    if (oldr!=1) {
     885      list SOL=ret1;
     886      export SOL;
     887      if (nodisp==0) { print(SOL); }
     888      dbprint( printlevel-voice+3,"
     889// 'solve' created a ring, in which a list SOL of numbers (the complex solutions)
     890// is stored.
     891// To access the list of complex solutions, type (if the name R was assigned
     892// to the return value):
     893        setring R; SOL; ");
     894      return(rinC);
     895    }
     896    else {
     897      setring (Top::`outR`);
     898      list SOL=imap(rinC,ret1);
     899      execute("def "+outL + "=SOL;");
     900      execute("export "+outL+";");
     901      if (nodisp==0) { print(SOL); }
     902      kill SOL;
     903      return("result exported to "+outR+" as list "+outL);   
     904    }
     905  }
     906  else {
     907    if (oldr!=1) {
     908      execute("ring rinC =(complex,"+string(outprec)+
     909                 "),("+varstr(basering)+"),lp;");
     910      list SOL=imap(internC,ret1);
     911      export SOL;
     912      if (nodisp==0) { print(SOL); }
     913      dbprint( printlevel-voice+3,"
     914// 'solve' created a ring, in which a list SOL of numbers (the complex solutions)
     915// is stored.
     916// To access the list of complex solutions, type (if the name R was assigned
     917// to the return value):
     918        setring R; SOL; ");
     919      return(rinC);
     920    }
     921    else {
     922      setring (Top::`outR`);
     923      list SOL=imap(internC,ret1);
     924      execute("def "+outL + "=SOL;");
     925      execute("export "+outL+";");
     926      if (nodisp==0) { print(SOL); }
     927      kill SOL;
     928      return("result exported to "+outR+" as list "+outL);   
     929    }
     930  }
    734931}
    735932example
     
    737934    "EXAMPLE:";echo=2;
    738935    // Find all roots of a multivariate ideal using triangular sets:
    739     int d=4;// with these 3 parameters you may construct
    740     int t=3;// very hard problems for 'solve'
    741     int s=2;
     936    int d,t,s = 4,3,2 ;
    742937    int i;
    743     ring A=0,(x(1..d)),dp;
     938    ring A=0,x(1..d),dp;
    744939    poly p=-1;
    745     for(i=d;i>0;i--){p=p+x(i)^s;}
    746     ideal I=x(d)^t-x(d)^s+p;
    747     for(i=d-1;i>0;i--){I=x(i)^t-x(i)^s+p,I;}
     940    for (i=d; i>0; i--) { p=p+x(i)^s; }
     941    ideal I = x(d)^t-x(d)^s+p;
     942    for (i=d-1; i>0; i--) { I=x(i)^t-x(i)^s+p,I; }
    748943    I;
    749     // the mutiplicity is
     944    // the multiplicity is
    750945    vdim(std(I));
    751     list l1=solve(I,6,0);
    752     // the current ring is
    753     AC;
     946    def AC=solve(I,6,0,"nodisplay");  // solutions should not be displayed
     947    // list of solutions is stored in AC as the list SOL (default name)
     948    setring AC;
     949    size(SOL);               // number of different solutions
     950    SOL[5];                  // the 5th solution
    754951    // you must start with char. 0
    755952    setring A;
    756     list l2=solve(I,6,1);
    757     // the number of different solutions is
    758     size(l1);
    759     // this is equal to
    760     size(l2[1][1])+size(l2[2][1]);
    761     // the number of solutions with multiplicity is
    762     size(l2[1][1])*l2[1][2]+size(l2[2][1])*l2[2][2];
    763     // the solutions with multiplicity
    764     l2[2][2];
    765     // are
    766     l2[2][1];
     953    def AC1=solve(I,6,1,"nodisplay");
     954    setring AC1;
     955    size(SOL);               // number of different multiplicities
     956    SOL[1][1][1];            // a solution with
     957    SOL[1][2];               // multiplicity 1
     958    SOL[2][1][1];            // a solution with
     959    SOL[2][2];               // multiplicity 12
     960    // the number of different solutions is equal to
     961    size(SOL[1][1])+size(SOL[2][1]);
     962    // the number of complex solutions (counted with multiplicities) is
     963    size(SOL[1][1])*SOL[1][2]+size(SOL[2][1])*SOL[2][2];
    767964}
    768965//////////////////////////////////////////////////////////////////////////////
    769966//                subprocedures for solve
    770967
    771 /* ----------------------- support ----------------------- */
    772 /*
    773 * the complex ring with precision outprec
    774 * has the well defined name: rinC
    775 * 1. if such a ring exists with the precision outprec,
    776 *    this will be the current ring
    777 * 2. otherwise such a ring will be created
    778 */
    779 static proc changering(string rinC, int outprec)
    780 {
    781   string rinDC = "ring "+rinC+"=(complex,"+string(outprec)+
    782                  "),("+varstr(basering)+"),lp;";
    783   string h = "int ex=defined("+rinC+");";
    784 
    785   execute(h);
    786   if (ex)
    787   {
    788     h = "setring "+rinC+";";
    789     execute(h);
    790     if (system("getPrecDigits")==outprec)
    791     {"// name of current ring: "+rinC;}
    792     else
    793     {
    794       execute("kill "+rinC+";");
    795       execute(rinDC);
    796       execute("export "+rinC+";");
    797       "// name of new current ring: "+rinC;
    798     }
    799   }
    800   else
    801   {
    802     execute(rinDC);
    803     execute("export "+rinC+";");
    804     "// name of new current ring: "+rinC;
    805   }
    806   keepring basering;
    807 }
    808968
    809969/*
     
    13351495    interpolate( 3, v, 4 );
    13361496}
     1497
    13371498///////////////////////////////////////////////////////////////////////////////
    1338 
     1499// changed for Singular 3
     1500// Return value is now a list: (rlist, rn@)
    13391501static proc psubst( int d, int dd, int n, list resl,
    1340                     ideal fi, int elem, int nv, int prec )
     1502                    ideal fi, int elem, int nv, int prec, int rn@, list rlist)
    13411503{
    13421504    //   nv: number of ring variables         (fixed value)
     
    13491511    //    d: actual variable
    13501512
     1513    list LL;
     1514    int pdebug;
    13511515    int olddd=dd;
    13521516
    1353     if ( pdebug>=1 )
    1354     {"// 0 step "+string(dd)+" of "+string(elem);}
     1517    dbprint(printlevel-voice+2, "// 0 step "+string(dd)+" of "+string(elem) );
    13551518
    13561519    if ( dd <= elem )
     
    13621525        int thedd;
    13631526
    1364         if ( pdebug>=1 )
    1365         {"// 1 dd = "+string(dd);}
     1527        dbprint( printlevel-voice+1,"// 1 dd = "+string(dd) );
    13661528
    13671529        thedd=0;
     
    13721534            if ( n-1 > 0 )
    13731535            {
    1374                 if ( pdebug>=2 )
    1375                 {
     1536                dbprint( printlevel-voice,
    13761537                    "// 2 ps=fi["+string(dd+1)+"]"+" size="
    13771538                        +string(size(coeffs(ps,var(n-1))))
    1378                         +"  leadexp(ps)="+string(leadexp(ps));
    1379                 }
     1539                        +"  leadexp(ps)="+string(leadexp(ps)) );
     1540
    13801541                if ( size(coeffs(ps,var(n-1))) == 1 )
    13811542                {
     
    13921553            else
    13931554            {
    1394                 if ( pdebug>=2 )
    1395                 {
     1555                dbprint( printlevel-voice,
    13961556                    "// 2 ps=fi["+string(dd+1)+"]"+"  leadexp(ps)="
    1397                         +string(leadexp(ps));
    1398                 }
     1557                        +string(leadexp(ps)) );
    13991558                dd++;
    14001559            }
     
    14031562        ps= fi[thedd];
    14041563
    1405         if ( pdebug>=1 )
    1406         {
     1564        dbprint( printlevel-voice+1,
    14071565            "// 3    fi["+string(thedd-1)+"]"+"  leadexp(fi[thedd-1])="
    1408                 +string(leadexp(fi[thedd-1]));
     1566                +string(leadexp(fi[thedd-1])) );
     1567        dbprint( printlevel-voice+1,
    14091568            "// 3 ps=fi["+string(thedd)+"]"+"  leadexp(ps)="
    1410                 +string(leadexp(ps));
    1411         }
     1569                +string(leadexp(ps)) );
    14121570
    14131571        for ( k= nv; k > nv-d; k-- )
    14141572        {
    1415             if ( pdebug>=2 )
    1416             {
     1573            dbprint( printlevel-voice,
    14171574                "// 4 subst(fi["+string(thedd)+"],"
    1418                     +string(var(k))+","+string(resl[k])+");";
    1419             }
     1575                    +string(var(k))+","+string(resl[k])+");" );
    14201576            ps = subst(ps,var(k),resl[k]);
    14211577        }
    14221578
    1423         if ( pdebug>=2 )
    1424         { "// 5 substituted ps="+string(ps); }
     1579        dbprint( printlevel-voice, "// 5 substituted ps="+string(ps) );
    14251580
    14261581        if ( ps != 0 )
     
    14301585        else
    14311586        {
    1432             if ( pdebug>=1 )
    1433             { "// 30 ps == 0, thats not cool..."; }
    1434             lsr=@ln; // lsr=number(0);
     1587            dbprint( printlevel-voice+1,"// 30 ps == 0, thats not cool...");
     1588            lsr=list(number(0));
    14351589        }
    14361590
    1437         if ( pdebug>=1 )
    1438         { "// 6 laguerre_solve found roots: lsr["+string(size(lsr))+"]"; }
     1591        dbprint( printlevel-voice+1,
     1592         "// 6 laguerre_solve found roots: lsr["+string(size(lsr))+"]" );
    14391593
    14401594        if ( size(lsr) > 1 )
    14411595        {
    1442             if ( pdebug>=1 )
    1443             {
     1596            dbprint( printlevel-voice+1, 
    14441597                "// 10 checking roots found before, range "
    1445                     +string(dd-olddd)+" -- "+string(dd);
    1446                 "// 10 thedd = "+string(thedd);
    1447             }
     1598                    +string(dd-olddd)+" -- "+string(dd) );
     1599            dbprint( printlevel-voice+1, 
     1600                "// 10 thedd = "+string(thedd) );
    14481601
    14491602            int i,j,l;
     
    15251678                "Numerical problem: No root found...";
    15261679                "Output may be incorrect!";
    1527                 nares=@ln;
     1680                nares=list(number(0));
    15281681            }
    15291682
     
    15411694                        rn@++; 
    15421695                    }
    1543                     psubst( d+1, dd+1, n-1, resl, fi, elem, nv, prec );
     1696                    LL = psubst( d+1, dd+1, n-1, resl, fi, elem, nv, prec,
     1697                                 rn@, rlist );
     1698                    rlist = LL[1];
     1699                    rn@ = LL[2];
    15441700                }
    15451701                else
    15461702                {
    1547                     if ( i > 1 ) {  rn@++; }  //bug found by O.Labs
    1548                     if ( pdebug>=1 )
    1549                     {"// 30_1 <"+string(rn@)+"> "+string(size(resl))+" <-----";}
    1550                     if ( pdebug>=2 )
    1551                     { resl; }
    1552                     rlist[rn@]=resl;
     1703                   if ( i > 1 ) {  rn@++; }  //bug found by O.Labs
     1704                   if ( pdebug>=1 )
     1705                   {"// 30_1 <"+string(rn@)+"> "+string(size(resl))+" <-----";}
     1706                   if ( pdebug>=2 ){ resl; }
     1707                   rlist[rn@]=resl;
    15531708                }
    15541709            }
     
    15621717            if ( dd < elem )
    15631718            {
    1564                 psubst( d+1, dd+1, n-1, resl, fi, elem, nv, prec );
     1719                LL= psubst( d+1, dd+1, n-1, resl, fi, elem, nv, prec,
     1720                            rn@, rlist );
     1721                rlist = LL[1];
     1722                rn@ = LL[2];
    15651723            }
    15661724            else
     
    15741732        }
    15751733    }
     1734    return(list(rlist,rn@));
    15761735}
    15771736
     
    15811740"USAGE:   fglm_solve(i [, p] ); i ideal, p integer
    15821741ASSUME:  the ground field has char 0.
    1583 RETURN:  a list of numbers, the complex roots of i;
    1584          p>0: gives precision of complex numbers in decimal digits (default:
    1585          p=30).
     1742RETURN:  ring @code{R} with the same number of variables but with complex
     1743         coefficients (and precision p). @code{R} comes with a list
     1744         @code{rlist} of numbers, in which the complex roots of i are stored.@*
     1745         p>0: gives precision of complex numbers in decimal digits [default:
     1746         p=30].
    15861747NOTE:    The procedure uses a standard basis of i to determine all complex
    15871748         roots of i.
    1588          It creates a ring rC with the same number of variables but with
    1589          complex coefficients (and precision p).
    15901749EXAMPLE: example fglm_solve; shows an example
    15911750"
     
    15981757    }
    15991758
    1600     lex_solve(stdfglm(fi),prec);
    1601     keepring basering;
     1759    def R = lex_solve(stdfglm(fi),prec);
     1760    dbprint( printlevel-voice+3,"
     1761// 'fglm_solve' created a ring, in which a list rlist of numbers (the
     1762// complex solutions) is stored.
     1763// To access the list of complex solutions, type (if the name R was assigned
     1764// to the return value):
     1765        setring R; rlist; ");
     1766    return(R);
    16021767}
    16031768example
     
    16061771    ring r = 0,(x,y),lp;
    16071772    // compute the intersection points of two curves
    1608     ideal s=  x2 + y2 - 10, x2 + xy + 2y2 - 16;
    1609     fglm_solve(s,10);
    1610     rlist;
     1773    ideal s =  x2 + y2 - 10, x2 + xy + 2y2 - 16;
     1774    def R = fglm_solve(s,10);
     1775    setring R; rlist;
    16111776}
    16121777
     
    16181783ASSUME:  i is a reduced lexicographical Groebner bases of a zero-dimensional
    16191784         ideal, sorted by increasing leading terms.
    1620 RETURN:  nothing
    1621 CREATE:  The procedure creates a complec ring with the same variables but
    1622          with complex coefficients (and precision p).
    1623          In this ring a list rlist of numbers is created, in which the complex
    1624          roots of i are stored.
     1785RETURN:  ring @code{R} with the same number of variables but with complex
     1786         coefficients (and precision p). @code{R} comes with a list
     1787         @code{rlist} of numbers, in which the complex roots of i are stored.
    16251788EXAMPLE: example lex_solve; shows an example
    16261789"
    16271790{
    16281791    int prec=30;
     1792    list LL;
    16291793
    16301794    if ( size(#)>=1  && typeof(#[1])=="int")
     
    16331797    }
    16341798
    1635     if ( !defined(pdebug) )
    1636     {
    1637         int pdebug;
    1638         pdebug=0;
    1639         export pdebug;
    1640     }
    1641 
    1642     string orings= nameof(basering);
     1799    if ( !defined(pdebug) ) { int pdebug; }
    16431800    def oring= basering;
    16441801
    16451802    // change the ground field to complex numbers
    1646     string nrings= "ring "+orings+"C=(complex,"+string(prec)
     1803    string nrings= "ring RC =(complex,"+string(prec)
    16471804        +"),("+varstr(basering)+"),lp;";
    16481805    execute(nrings);
    16491806
    1650     if ( pdebug>=0 )
    1651     { "// name of new ring: "+string(nameof(basering));}
    1652 
    16531807    // map fi from old to new ring
    16541808    ideal fi= imap(oring,fi);
    1655 
    1656     // list with entry 0 (number)
    1657     number nn=0;
    1658     if ( !defined(@ln) )
    1659     {
    1660         list @ln;
    1661         export @ln;
    1662     }
    1663     @ln=nn;
    16641809
    16651810    int idelem= size(fi);
     
    16741819    }
    16751820
    1676     if ( !defined(rn@) )
    1677     {
    1678         int rn@;
    1679         export rn@;
    1680     }
    1681     rn@=0;
    1682 
    16831821    li= laguerre_solve(fi[1],prec,prec,0);
    16841822    lis= size(li);
    16851823
    1686     if ( pdebug>=1 )
    1687     {"// laguerre found roots: "+string(size(li));}
     1824    dbprint(printlevel-voice+2,"// laguerre found roots: "+string(size(li)));
     1825    int rn@;
    16881826
    16891827    for ( j= 1; j <= lis; j++ )
    16901828    {
    1691         if ( pdebug>=1 )
    1692         {"// root "+string(j);}
     1829        dbprint(printlevel-voice+1,"// root "+string(j) );
    16931830        rn@++;
    16941831        resl[nv]= li[j];
    1695         psubst( 1, 2, nv-1, resl, fi, idelem, nv, prec );
    1696     }
    1697 
    1698     if ( pdebug>=0 )
    1699     {"// list of roots: "+nameof(rlist);}
    1700 
    1701     // keep the ring and exit
    1702     keepring basering;
     1832        LL = psubst( 1, 2, nv-1, resl, fi, idelem, nv, prec, rn@, rlist );
     1833        rlist=LL[1];
     1834        rn@=LL[2];
     1835    }
     1836
     1837    dbprint( printlevel-voice+3,"
     1838// 'lex_solve' created a ring, in which a list rlist of numbers (the
     1839// complex solutions) is stored.
     1840// To access the list of complex solutions, type (if the name R was assigned
     1841// to the return value):
     1842        setring R; rlist; ");
     1843
     1844    return(RC);
    17031845}
    17041846example
     
    17071849    ring r = 0,(x,y),lp;
    17081850    // compute the intersection points of two curves
    1709     ideal s=  x2 + y2 - 10, x2 + xy + 2y2 - 16;
    1710     lex_solve(stdfglm(s),10);
    1711     rlist;
     1851    ideal s =  x2 + y2 - 10, x2 + xy + 2y2 - 16;
     1852    def R = lex_solve(stdfglm(s),10);
     1853    setring R; rlist;
    17121854}
    17131855
     
    17181860         p>0: gives precision of complex numbers in digits (default: p=30).
    17191861ASSUME:  the ground field has char 0;  i is a zero-dimensional ideal
    1720 RETURN:  nothing
    1721 CREATE:  The procedure creates a ring rC with the same number of variables but
    1722          with complex coefficients (and precision p).@*
    1723          In rC a list rlist of numbers is created, in which the complex
    1724          roots of i are stored.@*
    1725          The proc uses a triangular system (Lazard's Algorithm with
    1726          factorization) computed from a standard basis to determine recursively
    1727          all complex roots with Laguerre's algorithm of input ideal i.
     1862RETURN:  ring @code{R} with the same number of variables but with complex
     1863         coefficients (and precision p). @code{R} comes with a list
     1864         @code{rlist} of numbers, in which the complex roots of i are stored.
     1865NOTE:    The proc uses a triangular system (Lazard's Algorithm with
     1866         factorization) computed from a standard basis to determine
     1867         recursively all complex roots of the input ideal i with Laguerre's
     1868         algorithm.
    17281869EXAMPLE: example triangLf_solve; shows an example
    17291870"
     
    17361877    }
    17371878
    1738     triang_solve(triangLfak(stdfglm(fi)),prec);
    1739     keepring basering;
     1879    def R=triang_solve(triangLfak(stdfglm(fi)),prec);
     1880    dbprint( printlevel-voice+3,"
     1881// 'triangLf_solve' created a ring, in which a list rlist of numbers (the
     1882// complex solutions) is stored.
     1883// To access the list of complex solutions, type (if the name R was assigned
     1884// to the return value):
     1885        setring R; rlist; ");
     1886    return(R);
    17401887}
    17411888example
     
    17441891    ring r = 0,(x,y),lp;
    17451892    // compute the intersection points of two curves
    1746     ideal s= x2 + y2 - 10, x2 + xy + 2y2 - 16;
    1747     triangLf_solve(s,10);
    1748     rlist;
     1893    ideal s = x2 + y2 - 10, x2 + xy + 2y2 - 16;
     1894    def R = triangLf_solve(s,10);
     1895    setring R; rlist;
    17491896}
    17501897
     
    17561903ASSUME:  the ground field has char 0;@*
    17571904         i zero-dimensional ideal
    1758 RETURN:  nothing
    1759 CREATE:  The procedure creates a ring rC with the same number of variables but
    1760          with complex coefficients (and precision p).@*
    1761          In rC a list rlist of numbers is created, in which the complex
    1762          roots of i are stored.@*
    1763          The proc uses a triangular system (Moellers Algorithm) computed from a
     1905RETURN:  ring @code{R} with the same number of variables but with complex
     1906         coefficients (and precision p). @code{R} comes with a list
     1907         @code{rlist} of numbers, in which the complex roots of i are stored.
     1908NOTE:    The proc uses a triangular system (Moellers Algorithm) computed from a
    17641909         standard basis to determine recursively all complex roots with
    17651910         Laguerre's algorithm of input ideal i.
     
    17741919    }
    17751920
    1776     triang_solve(triangM(stdfglm(fi)),prec);
    1777     keepring basering;
     1921    def R = triang_solve(triangM(stdfglm(fi)),prec);
     1922    dbprint( printlevel-voice+3,"
     1923// 'triangM_solve' created a ring, in which a list rlist of numbers (the
     1924// complex solutions) is stored.
     1925// To access the list of complex solutions, type (if the name R was assigned
     1926// to the return value):
     1927        setring R; rlist; ");
     1928    return(R);
    17781929}
    17791930example
     
    17821933    ring r = 0,(x,y),lp;
    17831934    // compute the intersection points of two curves
    1784     ideal s=  x2 + y2 - 10, x2 + xy + 2y2 - 16;
    1785     triangM_solve(s,10);
    1786     rlist;
     1935    ideal s =  x2 + y2 - 10, x2 + xy + 2y2 - 16;
     1936    def R = triangM_solve(s,10);
     1937    setring R; rlist;
    17871938}
    17881939
     
    17931944         p>0: gives precision of complex numbers in digits (default: p=30).
    17941945ASSUME:  the ground field has char 0; i is a zero-dimensional ideal.
    1795 RETURN:  nothing
    1796 CREATE:  The procedure creates a ring rC with the same number of variables but
    1797          with complex coefficients (and precision p).@*
    1798          In rC a list rlist of numbers is created, in which the complex
    1799          roots of i are stored.@*
    1800          The proc uses a triangular system (Lazard's Algorithm) computed from
     1946RETURN:  ring @code{R} with the same number of variables but with complex
     1947         coefficients (and precision p). @code{R} comes with a list
     1948         @code{rlist} of numbers, in which the complex roots of i are stored.
     1949NOTE:    The proc uses a triangular system (Lazard's Algorithm) computed from
    18011950         a standard basis to determine recursively all complex roots with
    18021951         Laguerre's algorithm of input ideal i.
     
    18111960    }
    18121961
    1813     triang_solve(triangL(stdfglm(fi)),prec);
    1814     keepring basering;
     1962    def R=triang_solve(triangL(stdfglm(fi)),prec);
     1963    dbprint( printlevel-voice+3,"
     1964// 'triangL_solve' created a ring, in which a list rlist of numbers (the
     1965// complex solutions) is stored.
     1966// To access the list of complex solutions, type (if the name R was assigned
     1967// to the return value):
     1968        setring R; rlist; ");
     1969    return(R);
    18151970}
    18161971example
     
    18191974    ring r = 0,(x,y),lp;
    18201975    // compute the intersection points of two curves
    1821     ideal s=  x2 + y2 - 10, x2 + xy + 2y2 - 16;
    1822     triangL_solve(s,10);
    1823     rlist;
     1976    ideal s =  x2 + y2 - 10, x2 + xy + 2y2 - 16;
     1977    def R = triangL_solve(s,10);
     1978    setring R; rlist;
    18241979}
    18251980
     
    18281983
    18291984proc triang_solve( list lfi, int prec, list # )
    1830 "USAGE:   triang_solve(l,p [, d] ); l=list, p,d=integers,@*
     1985"USAGE:   triang_solve(l,p [,d] ); l=list, p,d=integers@*
    18311986         l a list of finitely many triangular systems, such that the union of
    18321987         their varieties equals the variety of the initial ideal.@*
     
    18371992         l was computed using Algorithm of Lazard or Algorithm of Moeller
    18381993         (see triang.lib).
    1839 RETURN:  nothing
    1840 CREATE:  The procedure creates a ring rC with the same number of variables but
    1841          with complex coefficients (and precision p).@*
    1842          In rC a list rlist of numbers is created, in which the complex
    1843          roots of i are stored.@*
     1994RETURN:  ring @code{R} with the same number of variables but with complex
     1995         coefficients (and precision p). @code{R} comes with a list
     1996         @code{rlist} of numbers, in which the complex roots of l are stored.@*
    18441997EXAMPLE: example triang_solve; shows an example
    18451998"
    18461999{
    1847     if ( !defined(pdebug) )
    1848     {
    1849         int pdebug;
    1850         export pdebug;
    1851     }
    1852     pdebug=0;
    1853 
    1854     string orings= nameof(basering);
    18552000    def oring= basering;
     2001    list LL;
    18562002
    18572003    // change the ground field to complex numbers
    1858     string nrings= "ring "+orings+"C=(real,"+string(prec)
     2004    string nrings= "ring RC =(complex,"+string(prec)
    18592005        +",I),("+varstr(basering)+"),lp;";
    18602006    execute(nrings);
    18612007
    1862     if ( pdebug>=0 )
    1863     { "// name of new ring: "+string(nameof(basering));}
    1864 
    18652008    // list with entry 0 (number)
    18662009    number nn=0;
    1867     if ( !defined(@ln) )
    1868     {
    1869         list @ln;
    1870         export @ln;
    1871     }
    1872     @ln=nn;
    18732010
    18742011    // set number of digits for zero-comparison of roots
     
    18762013    {
    18772014        int myCompDigits;
    1878         export  myCompDigits;
    18792015    }
    18802016    if ( size(#)>=1  && typeof(#[1])=="int" )
     
    18872023    }
    18882024
    1889     if ( pdebug>=1 )
    1890     {"// myCompDigits="+string(myCompDigits);}
     2025    dbprint( printlevel-voice+2,"// myCompDigits="+string(myCompDigits) );
    18912026
    18922027    int idelem;
    18932028    int nv= nvars(basering);
    1894     int i,j,k,lis;
     2029    int i,j,lis;
    18952030    list resu,li;
    18962031
     
    19012036    }
    19022037
    1903     if ( !defined(rn@) )
    1904     {
    1905         int rn@;
    1906         export rn@;
    1907     }
    1908     rn@=0;
     2038    int rn@=0;
    19092039
    19102040    // map the list
    19112041    list lfi= imap(oring,lfi);
    1912 
    19132042    int slfi= size(lfi);
     2043
    19142044    ideal fi;
    1915 
    19162045    for ( i= 1; i <= slfi; i++ )
    19172046    {
     
    19252054        lis= size(li);
    19262055
    1927         if ( pdebug>=1 )
    1928         {"// laguerre found roots: "+string(size(li));}
     2056        dbprint( printlevel-voice+2,"// laguerre found roots: "+string(lis) );
    19292057
    19302058        for ( j= 1; j <= lis; j++ )
    19312059        {
    1932             if ( pdebug>=1 )
    1933             {"// root "+string(j);}
     2060            dbprint( printlevel-voice+2,"// root "+string(j) );
    19342061            rn@++;
    19352062            resu[nv]= li[j];
    1936             psubst( 1, 2, nv-1, resu, fi, idelem, nv, myCompDigits );
     2063            LL = psubst( 1, 2, nv-1, resu, fi, idelem, nv, myCompDigits,
     2064                         rn@, rlist );
     2065            rlist = LL[1];
     2066            rn@ = LL[2];
    19372067        }
    19382068    }
    19392069
    1940     if ( pdebug>=0 )
    1941     {"// list of roots: "+nameof(rlist);}
    1942     // keep the ring and exit
    1943     keepring basering;
     2070    dbprint( printlevel-voice+3,"
     2071// 'triang_solve' created a ring, in which a list rlist of numbers (the
     2072// complex solutions) is stored.
     2073// To access the list of complex solutions, type (if the name R was assigned
     2074// to the return value):
     2075        setring R; rlist; ");
     2076
     2077    return(RC);
    19442078}
    19452079example
     
    19492083    // compute the intersection points of two curves
    19502084    ideal s=  x2 + y2 - 10, x2 + xy + 2y2 - 16;
    1951     triang_solve(triangLfak(stdfglm(s)),10);
    1952     rlist;
     2085    def R=triang_solve(triangLfak(stdfglm(s)),10);
     2086    setring R; rlist;
    19532087}
    19542088
Note: See TracChangeset for help on using the changeset viewer.