Index: Singular/LIB/normal.lib
===================================================================
--- Singular/LIB/normal.lib	(revision 9fd5f8a67b2159d3a039d7b0b34e704f6a617dfb)
+++ Singular/LIB/normal.lib	(revision 9a3ece8f65037be55d5ca160e93f5c3f1910e6ed)
@@ -2,15 +2,15 @@
 // normal.lib
 // algorithms for computing the normalization based on
-// the ideas of De Jong,Vasconcelos
+// the criterion of Grauert/Remmert and ideas of De Jong & Vasconcelos
 // written by Gert-Martin Greuel and Gerhard Pfister
 ///////////////////////////////////////////////////////////////////////////////
 
-version="$Id: normal.lib,v 1.11 1999-03-15 12:07:19 Singular Exp $";
+version="$Id: normal.lib,v 1.12 1999-05-26 12:25:23 obachman Exp $";
 info="
-LIBRARY: normal.lib: PROCEDURE FOR NORMALIZATION (I)
-
-  normal(ideal I)
-  // computes a set of rings such that their product is the
-  // normalization of the reduced basering/I
+LIBRARY: normal.lib     PROCEDURES FOR NORMALIZATION
+
+ normal(I);             computes the normalization of basering/I
+ extraweight(R);        intvec of variable weights of ring R
+ HomJJ(L);              presentation of End_R(J) as affine ring, L a list      
 ";
 
@@ -20,5 +20,5 @@
 LIB "presolve.lib";
 ///////////////////////////////////////////////////////////////////////////////
-
+static
 proc isR_HomJR (list Li)
 "USAGE:   isR_HomJR (Li);  Li = list: ideal SBid, ideal J, poly p
@@ -153,6 +153,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 
-proc HomJJ (list Li,list #)
-"USAGE:   HomJJ (Li);  Li = list: SBid,id,J,poly p
+proc HomJJ (list Li)
+"USAGE:   HomJJ (Li);  Li = list: ideal SBid, ideal id, ideal J, poly p
 ASSUME:  R    = P/id,  P = basering, a polynomial ring, id an ideal of P,
          SBid = standard basis of id,
@@ -166,4 +166,5 @@
                endphi describes the canonical map R -> Hom_R(J,J)
          _[2]: an integer which is 1 if phi is an isomorphism, 0 if not
+NOTE:    printlevel >=1: display comments (default: printlevel=0)
 EXAMPLE: example HomJJ;  shows an example
 "
@@ -174,8 +175,6 @@
    intvec rw,rw1;
    list L;
-   if( size(#) >=1 )
-   {
-      if( typeof(#[1]) == "int" ) { y = #[1]; }
-   }
+   
+   y = printlevel-voice+2;  // y=printlevel (default: y=0)
  def P = basering;
    ideal SBid, id, J = Li[1], Li[2], Li[3];
@@ -219,12 +218,9 @@
 //---------- computation of p*Hom(J,J) as R-ideal -----------------------------
    f  = quotient(p*J,J);
-   if(y==1)
-   {
-      "the module Hom(rad(J),rad(J)) presented by the values on";
-      "the non-zerodivisor";
-      "  ";
-      p;
-      " ";
-      f;
+   if ( y>=1 )
+   { "// the module p*Hom(rad(J),rad(J)) = p*J:J, p a non-zerodivisor";
+      
+      "// p"; p;
+      "// f=p*J:J";f;
    }
    f2 = std(p);
@@ -271,6 +267,6 @@
       L=lastRing;
       L = insert(L,1,1);
-      dbprint(printlevel-voice+3,"// case R = Hom(J,J)");
-      if(y==1)
+      dbprint(y,"// case R = Hom(J,J)");
+      if(y>=1)
       {
          "R=Hom(rad(J),rad(J))";
@@ -300,5 +296,5 @@
       return(L);
    }
-   if(y==1)
+   if(y>=1)
    {
       "R is not equal to Hom(rad(J),rad(J)), we have to try again";
@@ -340,5 +336,5 @@
    list L1;
 
-//---------- computation of Hom(J,J) as ring ----------------------------------
+//---------- computation of Hom(J,J) as affine ring ---------------------------
 // determine kernel of: R[T1,...,Tq] -> J:J >-> R[1/p]=R[t]/(t*p-1),
 // Ti -> fi/p -> t*fi (p=f1=f[1]), to get ring structure. This is of course
@@ -350,5 +346,5 @@
    T = matrix(ideal(T(1..q)),1,q);
    Lin = ideal(T*syzf);
-   if(y==1)
+   if(y>=1)
    {
       "the ring structure of Hom(rad(J),rad(J)) as R-algebra";
@@ -367,5 +363,5 @@
       }
    }
-   if(y==1)
+   if(y>=1)
    {
       "the quadratic relations";
@@ -402,5 +398,5 @@
   // export(endid);
   // export(endphi);
-   if(y==1)
+   if(y>=1)
    {
       "the new ring after reduction of the number of variables";
@@ -439,33 +435,28 @@
   list Li = std(id),id,J,p;
   list L   = HomJJ(Li);
-  def end = L[1];      // defines ring L[1], containing ideals endid and endphi
-  setring end;         // makes end the basering
+  def end = L[1];    // defines ring L[1], containing ideals endid and endphi
+  setring end;       // makes end the basering
   end;
-  endid;               // end/endid is isomorphic to End(r/id) as ring
-  map psi = r,endphi;  // defines the canonical map r/id -> End(r/id)
+  endid;             // end/endid is isomorphic to End(r/id) as ring
+  map psi = r,endphi;// defines the canonical map r/id -> End(r/id)
   psi;
-
-  ring r   = 32003,(x,y,z),dp;
-  ideal id = x2-xy-xz+yz;
-  ideal J =y-z,x-z;
-  poly p = x+16001y+16001z;
-  list Li = std(id),id,J,p;
-  list L   = HomJJ(Li,0);
-  def end = L[1];      // defines ring L[1], containing ideals endid and endphi
-  setring end;         // makes end the basering
-  end;
-  endid;               // end/endid is isomorphic to End(r/id) as ring
-
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 proc normal(ideal id, list #)
-"USAGE:   normal(i,choose);  i ideal,choose empty or 1
-         in case you choose 1 the factorizing Buchberger algorithm
-         is not used which is sometimes more efficient
-RETURN:  a list of rings L=R1,...,Rk, in each Ri are two ideals
-         Si,Mi such that the product of Ri/Mi is the normalization
-         Si is a standardbasis of Mi
-NOTE:    to use the rings: def r=L[i];setring r;
+"USAGE:   normal(i [,choose]);  i ideal, choose empty or 1
+         if choose=1 the factorizing Buchberger algorithm is not used
+         (which is sometimes more efficient)
+RETURN:  a list L of rings, in each ring L[i] are two ideals
+         norid, normap such that the product of the L[i]/norid is the
+         normalization of basering/id and normap is the map from basering/id
+         to L[i]/norid
+NOTE:    to use the rings type: def r=L[i]; setring r; norid; normap;
+         increasing printlevel displays more comments (default: printlevel=0)
+COMMENT: The algoritm works in principle for any basering and reduced ideal.
+         The implementation should work correctly for any global (p-) ordering,
+         however, this is not fully tested.
+         If the input ideal i is weighted homogeneous a weighted ordering may
+         be used (qhweight(i); computes weights).
 EXAMPLE: example normal; shows an example
 "
@@ -473,4 +464,14 @@
    int i,j,y;
    list result,prim,keepresult;
+   y=printlevel-voice+2;
+
+   if ( find(ordstr(basering),"s")+find(ordstr(basering),"M") != 0)
+   {
+     "
+// Not implemented for this ordering,
+// please change to global ordering!";
+     return(result);
+   }
+
 
    if(size(#)==0)
@@ -535,4 +536,10 @@
           attrib(prim[1],"isRegInCodim2",0);
       }
+      dbprint(y+1,"
+// If the name of your list is L type:
+//          def r=L[i]; setring r; norid; normap;
+// then r/norid is the i-th ring of the normaliztion
+// and normap the map of the basring to r/norid");
+
       return(normalizationPrimes(prim[1],maxideal(1)));
    }
@@ -548,5 +555,5 @@
       }
 
-      if(y==1)
+      if(y>=1)
       {
          "we have ";size(prim);"components";
@@ -554,5 +561,5 @@
       for(i=1;i<=size(prim);i++)
       {
-         if(y==1)
+         if(y>=1)
          {
             "we are in loop";i;
@@ -592,4 +599,11 @@
          }
       }
+
+      dbprint(y+1,"
+// If the name of your list is L type:
+//          def r=L[i]; setring r; norid; normap;
+// then r/norid is the i-th ring of the normaliztion
+// and normap the map of the basring to r/norid");
+  
       return(result);
    }
@@ -597,9 +611,16 @@
 example
 { "EXAMPLE:"; echo = 2;
-   ring  r = 0,(x,y,z),dp;
-
+   ring r=32003,(x,y,z),wp(2,1,2);
+   ideal i=z3-xy4;
+   list pr=normal(i);
+   pr;
+   def r1=pr[1];
+   setring r1;
+   norid;
+   normap;
 }
 
-
+///////////////////////////////////////////////////////////////////////////////
+static
 proc normalizationPrimes(ideal i,ideal ihp, list #)
 "USAGE:   normalizationPrimes(i);  i prime ideal
@@ -608,9 +629,11 @@
          S is a standardbasis of M
 NOTE:    to use the ring: def r=L[1];setring r;
+         printlevel >=1: display comments (default: printlevel=0)
 EXAMPLE: example normalizationPrimes; shows an example
 "
 {
-   int y;
-   if(y==1)
+   int y = printlevel-voice+2;  // y=printlevel (default: y=0)
+  
+   if(y>=1)
    {
       "START one normalization loop with the ideal";
@@ -625,5 +648,5 @@
    def BAS=basering;
    list result,keepresult1,keepresult2;
-   ideal J,SB,MB,KK;
+   ideal J,SB,MB;
    int depth,lauf,prdim;
    int ti=timer;
@@ -631,5 +654,5 @@
    if(size(i)==0)
    {
-      if(y==1)
+      if(y>=1)
       {
           "the ideal was the zero-ideal";
@@ -637,8 +660,8 @@
          execute "ring newR7="+charstr(basering)+",("+varstr(basering)+"),("
                       +ordstr(basering)+");";
-         ideal KK=ideal(0);
-         ideal PP=fetch(BAS,ihp);
-         export PP;
-         export KK;
+         ideal norid=ideal(0);
+         ideal normap=fetch(BAS,ihp);
+         export norid;
+         export normap;
          result=newR7;
          setring BAS;
@@ -647,5 +670,5 @@
    }
 
-   if(y==1)
+   if(y>=1)
    {
       "                                  ";
@@ -656,5 +679,5 @@
    list SM=mstd(i);
 
-   if(y==1)
+   if(y>=1)
    {
       " the dimension is                 ";
@@ -727,5 +750,5 @@
       if(dim(JM[1])==-1)
       {
-         if(y==1)
+         if(y>=1)
          {
             "the ideal was smooth";
@@ -736,12 +759,8 @@
          def newR6=LL[1];
          setring newR6;
-         ideal KK=endid;
-         ideal PP=endphi;
-//        execute "ring newR6="+charstr(basering)+",("+varstr(basering)+"),("
-//                      +ordstr(basering)+");";
-//         ideal KK=fetch(BAS,MB);
-//         ideal PP=fetch(BAS,ihp);
-         export PP;
-         export KK;
+         ideal norid=endid;
+         ideal normap=endphi;
+         export norid;
+         export normap;
          result=newR6;
          setring BAS;
@@ -753,5 +772,5 @@
    if((dim(SM[1])==0)&&(homog(SM[2])==1))
    {
-      if(y==1)
+      if(y>=1)
       {
          "the ideal was zero-dimensional and homogeneous";
@@ -762,12 +781,8 @@
       def newR5=LL[1];
       setring newR5;
-      ideal KK=endid;
-      ideal PP=endphi;
-//      execute "ring newR5="+charstr(basering)+",("+varstr(basering)+"),("
-//                      +ordstr(basering)+");";
-//      ideal KK=fetch(BAS,MB);
-//      ideal PP=fetch(BAS,ihp);
-      export PP;
-      export KK;
+      ideal norid=endid;
+      ideal normap=endphi;
+      export norid;
+      export normap;
       result=newR5;
       setring BAS;
@@ -781,5 +796,5 @@
         &&(homog(SM[2])==1))
    {
-      if(y==1)
+      if(y>=1)
       {
          "the ideal defines a line";
@@ -790,12 +805,8 @@
       def newR4=LL[1];
       setring newR4;
-      ideal KK=endid;
-      ideal PP=endphi;
-//      execute "ring newR4="+charstr(basering)+",("+varstr(basering)+"),("
-//                      +ordstr(basering)+");";
-//      ideal KK=fetch(BAS,MB);
-//      ideal PP=fetch(BAS,ihp);
-      export PP;
-      export KK;
+      ideal norid=endid;
+      ideal normap=endphi;
+      export norid;
+      export normap;
       result=newR4;
       setring BAS;
@@ -812,25 +823,9 @@
       attrib(SM[2],"isCompleteIntersection",1);
       attrib(SM[2],"isEquidimensional",1);
-      if(y==1)
+      if(y>=1)
       {
          "it is a complete Intersection";
       }
    }
-//   if(attrib(i,"isIsolatedSingularity")==0)
-//   {
-//      list L=sres(SM[2],0);
-//      prdim=ncols(betti(L))-1;
-//      depth=nvars(basering)-prdim;
-//   }
-
-  // if(attrib(SM[2],"isCohenMacaulay")==0)
-  // {
-  //    test for CohenMacaulay
-  //    if((dim(SM[1]))==depth)
-  //    {
-  //    attrib(SM[2],"isCohenMacaulay",1);
-  //    "it is CohenMacaulay";
-  //    }
-  // }
 
    //compute the singular locus+lower dimensional components
@@ -841,5 +836,5 @@
       J=minor(jacob(SM[2]),nvars(basering)-dim(SM[1]));
       //ti=timer;
-      if(y==1)
+      if(y>=1)
       {
          "SB of singular locus will be computed";
@@ -848,11 +843,7 @@
 
     //kills the embeded components
-//    if(homog(SM[2])==1)
-//    {
-//       sin=sat(sin,maxideal(1))[1];
-//    }
 
       list JM=mstd(sin);
-      if(y==1)
+      if(y>=1)
       {
          "                                  ";
@@ -867,5 +858,5 @@
       if(dim(JM[1])==-1)
       {
-         if(y==1)
+         if(y>=1)
          {
             "it is smooth";
@@ -874,14 +865,10 @@
          intvec rw;
          list LL=substpart(MB,ihp,0,rw);
-//         execute "ring newR3="+charstr(basering)+",("+varstr(basering)+"),("
-//                      +ordstr(basering)+");";
          def newR3=LL[1];
          setring newR3;
-//         ideal KK=fetch(BAS,MB);
-//         ideal PP=fetch(BAS,ihp);
-         ideal KK=endid;
-         ideal PP=endphi;
-         export PP;
-         export KK;
+         ideal norid=endid;
+         ideal normap=endphi;
+         export norid;
+         export normap;
          result=newR3;
          setring BAS;
@@ -916,5 +903,5 @@
       if(size(qAnn)==0)
       {
-         if(y==1)
+         if(y>=1)
          {
             "                                  ";
@@ -928,22 +915,7 @@
          //Hom(I,R)=R
          list RR;
-  //       list RR=SM[1],maxideal(1),SL[1];
-  //       "test with Hom(I,R)";
-  //       ti=timer;
-  //       if(isR_HomJR(RR)==1)
-  //       {
-  //         "it was normal";
-  //          timer-ti;
-  //          SB=SM[1];
-  //          SM=SM[2];
-  //          export SB,MB;
-  //          result=BAS;
-  //          return(result);
-  //       }
-  //       timer-ti;
          RR=SM[1],SM[2],maxideal(1),SL[1];
          ti=timer;
          RR=HomJJ(RR,y);
-   //      timer-ti;
          if(RR[2]==0)
          {
@@ -961,8 +933,8 @@
          execute "ring newR7="+charstr(basering)+",("+varstr(basering)+"),("
                       +ordstr(basering)+");";
-         ideal KK=fetch(BAS,MB);
-         ideal PP=fetch(BAS,ihp);
-         export PP;
-         export KK;
+         ideal norid=fetch(BAS,MB);
+         ideal normap=fetch(BAS,ihp);
+         export norid;
+         export normap;
          result=newR7;
          setring BAS;
@@ -1014,44 +986,11 @@
    {
       list RR;
- //      "test with Hom(I,I) before the radical computation";
-        //again test for normality
-        //Hom(I,R)=R
- //     list RR=SM[1],JM[2],SL[1];
- //     "test with Hom(I,R)";
- //     ti=timer;
- //     if(isR_HomJR(RR)==1)
- //     {
- //      "it was normal";
- //        timer-ti;
- //        SB=SM[1];
- //        SM=SM[2];
- //        export SB,MB;
- //        result=BAS;
- //        return(result);
- //     }
- //     timer-ti;
-
- //     list  RR=SM[1],SM[2],JM[2],SL[1];
- //     ti=timer;
       list RS;
- //   list RS=HomJJ(RR);
- //   timer-ti;
- //     if(RS[2]==0)
- //     {
- //        "Hom(I,I) was sucessfull without radical";
- //        def newR=RS[1];
- //        setring newR;
- //        list tluser=normalizationPrimes(SM);
- //        setring BAS;
- //        return(tluser);
- //     }
 
       //now we have to compute the radical
-      if(y==1)
+      if(y>=1)
       {
          "radical computation";
       }
-//      ti=timer;
-
 
       if((attrib(JM[2],"isRad")==0)&&(attrib(SM[2],"isEquidimensional")==0))
@@ -1077,33 +1016,17 @@
           }
       }
-//    timer-ti;
 
       JM=J,J;
 
       //evtl. fuer SL[1] anderen Nichtnullteiler aus J waehlen
-      // SL=simplify(reduce(J,SM[1]),2);
-      // Ann=quotient(SM[2],SL[1]);
-      // qAnn=simplify(reduce(Ann,SM[1]),2);
-      // if(size(qAnn)!=0)
-      // {
-        // keepresult1=normalizationPrimes(qAnn+SM[2]);
-        // keepresult2=normalizationPrimes(SL[1]+SM[2]);
-        // for(lauf=1;lauf<=size(keepresult2);j++)
-        // {
-        //    keepresult1=insert(keepresult1,keepresult2[lauf]);
-        // }
-        // return(keepresult1);
-      // }
       RR=SM[1],SM[2],JM[2],SL[1];
 
 //   evtl eine geeignete Potenz von JM?
-     if(y==1)
+     if(y>=1)
      {
         "compute Hom(rad(J),rad(J)):";
      }
-//   ti=timer;
 
      RS=HomJJ(RR,y);
-//   timer-ti;
 
       if(RS[2]==1)
@@ -1112,10 +1035,9 @@
          setring lastR;
          map psi1=BAS,endphi;
-         ideal KK=endid;
-         ideal PP=psi1(ihp);
-         export PP;
-         export KK;
+         ideal norid=endid;
+         ideal normap=psi1(ihp);
+         export norid;
+         export normap;
          setring BAS;
-        // return(RS[1]);
          return(lastR);
       }
@@ -1129,5 +1051,4 @@
       list tluser=
              normalizationPrimes(endid,psi(ihp),simplify(psi(MJ)+endid,4));
-            // normalizationPrimes(endid);
       setring BAS;
       return(tluser);
@@ -1139,5 +1060,5 @@
       execute "ring newR1="+charstr(basering)+",("+varstr(basering)+"),("
                       +ordstr(basering)+");";
-      if(y==1)
+      if(y>=1)
       {
          "zero-divisor found";
@@ -1164,5 +1085,4 @@
       ideal new2=quotient(SM[2],Ann)+SM[2];
 // evtl. qAnn nehmen
-//      ideal new2=SL[1]+SM[2];
       execute "ring newR2="+charstr(basering)+",("+varstr(basering)+"),("
                       +ordstr(basering)+");";
@@ -1196,24 +1116,25 @@
 example
 { "EXAMPLE:";echo = 2;
-   LIB"normal.lib";
    //Huneke
-ring qr=31991,(a,b,c,d,e),dp;
-ideal i=
-5abcde-a5-b5-c5-d5-e5,
-ab3c+bc3d+a3be+cd3e+ade3,
-a2bc2+b2cd2+a2d2e+ab2e2+c2de2,
-abc5-b4c2d-2a2b2cde+ac3d2e-a4de2+bcd2e3+abe5,
-ab2c4-b5cd-a2b3de+2abc2d2e+ad4e2-a2bce3-cde5,
-a3b2cd-bc2d4+ab2c3e-b5de-d6e+3abcd2e2-a2be4-de6,
-a4b2c-abc2d3-ab5e-b3c2de-ad5e+2a2bcde2+cd2e4,
-b6c+bc6+a2b4e-3ab2c2de+c4d2e-a3cde2-abd3e2+bce5;
-
-list pr=normal(i);
-def r1=pr[1];
-setring r1;
-KK;
+   ring qr=31991,(a,b,c,d,e),dp;
+   ideal i=
+   5abcde-a5-b5-c5-d5-e5,
+   ab3c+bc3d+a3be+cd3e+ade3,
+   a2bc2+b2cd2+a2d2e+ab2e2+c2de2,
+   abc5-b4c2d-2a2b2cde+ac3d2e-a4de2+bcd2e3+abe5,
+   ab2c4-b5cd-a2b3de+2abc2d2e+ad4e2-a2bce3-cde5,
+   a3b2cd-bc2d4+ab2c3e-b5de-d6e+3abcd2e2-a2be4-de6,
+   a4b2c-abc2d3-ab5e-b3c2de-ad5e+2a2bcde2+cd2e4,
+   b6c+bc6+a2b4e-3ab2c2de+c4d2e-a3cde2-abd3e2+bce5;
+
+   list pr=normalizationPrimes(i);
+   def r1=pr[1];
+   setring r1;
+   norid;
+   normap;
 }
-
-proc substpart(ideal endid,ideal endphi, int homo, intvec rw)
+///////////////////////////////////////////////////////////////////////////////
+static
+proc substpart(ideal endid, ideal endphi, int homo, intvec rw)
 {
    def newRing=basering;
@@ -1297,5 +1218,6 @@
    return(L);
 }
-
+///////////////////////////////////////////////////////////////////////////////
+static
 proc diagon(ideal i)
 {
@@ -1308,9 +1230,6 @@
 /////////////////////////////////////////////////////////////////////////////
 /*
+                           Examples:
 LIB"normal.lib";
-int aa=timer;list pr=normal(i);timer-aa;
-
-
-
 //Huneke
 ring qr=31991,(a,b,c,d,e),dp;
