Index: Singular/LIB/nctools.lib
===================================================================
--- Singular/LIB/nctools.lib	(revision 5b4439ab0ec54203e3aae4c8eb6af146fe1b11d5)
+++ Singular/LIB/nctools.lib	(revision 1625c14e1865ffd016b1b23fc908e7e790e66291)
@@ -1,4 +1,4 @@
 ///////////////////////////////////////////////////////////////////////////////
-version="$Id: nctools.lib,v 1.27 2007-07-13 14:05:14 motsak Exp $";
+version="$Id: nctools.lib,v 1.28 2007-07-19 17:18:30 motsak Exp $";
 category="Noncommutative";
 info="
@@ -723,5 +723,6 @@
 PURPOSE:  create the super-commutative algebra (as a GR-algebra) 'over' a basering,
 NOTE: activate this qring with the \"setring\" command. 
-NOTE: as a side effect the basering will be changed to bo the basis G-algebra (without factor).
+NOTE: as a side effect the basering will be changed (if not in a commutative case) to bo the ground G-algebra (without factor).
+NOTE: if b==e then the resulting ring is commutative.
 THEORY: given a basering, this procedure introduces the anticommutative relations x(j)x(i)=-x(i)x(j) for all e>=j>i>=b,
 @* moreover, creates a factor algebra modulo the two-sided ideal, generated by x(b)^2, ..., x(e)^2[ + Q]
@@ -729,5 +730,8 @@
 "
 {
+  int fprot = (find(option(),"prot") != 0);
+  
   string rname=nameof(basering);
+  
   if ( rname == "basering") // i.e. no ring has been set yet
   {
@@ -735,10 +739,11 @@
     return();
   }
-  int N = nvars(basering);
-
+
+  def saveRing = basering;
+  
+  int N = nvars(saveRing);
   int b = 1;
   int e = N;
 
-  def saveRing = basering;
   ideal Q = 0;
 
@@ -749,6 +754,13 @@
       ERROR("First argument 'b' must be an integer!");
       return();
-    }
+    }    
     b = #[1];
+
+    if((b < 1)||(b > N))
+    {
+      ERROR("First argument 'b' must within [1..nvars(basering)]!");
+      return();
+    }    
+    
   }
 
@@ -757,8 +769,21 @@
     if(typeof(#[2]) != "int")
     {
-      ERROR("Last argument 'e' must be an integer!");
+      ERROR("Second argument 'e' must be an integer!");
       return();
     }
     e = #[2];
+
+    if((e < 1)||(e > N))
+    {
+      ERROR("Second argument 'e' must within [1..nvars(basering)]!");
+      return();
+    }
+    
+    if(e < b)
+    {
+      ERROR("Second argument 'e' must be bigger or equal to 'b'!");
+      return();
+    }
+
   }
 
@@ -773,6 +798,17 @@
   }
 
+  if( b == e ) // commutative ring!!!
+  {
+    if( fprot == 1)
+    {
+      print("Warning: b==e means that the resulting ring will be commutative!");
+    }
+    Q = std(Q + (var(b)^2));
+    qring @EA = Q; // and it will be internally commutative as well!!!
+    return(@EA);    
+  }
+
 /*
-  // Singular'(Hans) politics: no ring copyes! 
+  // Singular'(H.S.) politics: no ring copies! 
   // in future ncalgebra() should return a new ring!!!
   list CurrRing = ringlist(basering);
@@ -793,15 +829,24 @@
   }
 
-  ncalgebra(@E, 0);
-
-  ideal Q = fetch(saveRing, Q);
-  j = ncols(Q) + 1;
+  ncalgebra(@E, 0); // define ground G-algebra!
+
+  ideal @Q = fetch(saveRing, Q);
+  
+  j = ncols(@Q) + 1;
 
   for ( i=e; i>=b; i--, j++ )
   {
-    Q[j] = var(i)^2;
-  }
-  Q = twostd(Q);
-  qring @EA = Q;
+    @Q[j] = var(i)^2;
+  }
+
+  if( (fprot == 1) and (attrib(basering, "global") != 1) )
+  {
+    print("Warning: Since the current ordering is not global there might be problems computing twostd(Q)!");
+    print("Q:", @Q);
+  }
+  
+  @Q = twostd(@Q); // must be computed within the ground G-algebra => problems with local orderings!
+  
+  qring @EA = @Q;
 
 //   "Alternating variables: [", AltVarStart(), ",", AltVarEnd(), "].";
@@ -832,20 +877,8 @@
 "
 RETURN: list {AltVarStart, AltVarEnd} is currRing is SCA, returns undef otherwise.
+NOTE: rings with only one non-commutative variable are commutative rings which are super-sommutative itself!
 "
 {
   def saveRing = basering;
-  list L = ringlist(saveRing);
-
-  if( size(L)!=6 )
-  {
-    return("The current ring is commutative!");
-  }
-
-  module D = simplify(L[6], 2 + 4);
-
-  if( size(D)>0 )
-  {
-    return("The current ring is not SCA! (D!=0)");
-  }
 
   int i, j;
@@ -854,4 +887,44 @@
   int b = N+1;
   int e =  -1;
+
+  int fprot = (find(option(),"prot") != 0);
+
+
+  if( size(ideal(saveRing)) == 0 )
+  {
+    return("SCA rings are factors by (at least) squares!"); // no squares in the factor ideal!
+  }
+  
+  list L = ringlist(saveRing);
+
+  if( size(L)!=6 )
+  {
+    if(fprot)
+    {
+      print("Warning: The current ring is internally commutative!");
+    }
+
+    for( i = N; i > 0; i-- )
+    {
+      if( NF(var(i)^2, std(0)) == 0 )
+      {
+        if( (fprot == 1) and (i > 1) )
+        {          
+          print("Warning: the SCA representation of the current commutative factor ring may be ambiguous!");
+        }
+                      
+        return( list(i, i) ); // this is not unique in this case! there may be other squares in the factor ideal!
+      }
+    }    
+
+    return("The current commutative ring is not SCA! (Wrong quotient ideal)"); // no squares in the factor ideal!
+  }
+
+  module D = simplify(L[6], 2 + 4);
+
+  if( size(D)>0 )
+  {
+    return("The current ring is not SCA! (D!=0)");
+  }
 
   matrix C = L[5];
@@ -887,5 +960,23 @@
   if( (b > N) || (e < 1))
   {
-    return("The current ring is commutative!");
+    if(fprot)
+    {
+      print("Warning: The current ring is a commutative GR-algebra!");
+    }
+
+    for( i = N; i > 0; i-- )
+    {
+      if( NF(var(i)^2, std(0)) == 0 )
+      {
+        if( (fprot == 1) and (i > 1) )
+        {          
+          print("Warning: the SCA representation of the current factor ring may be ambiguous!");
+        }
+                      
+        return( list(i, i) ); // this is not unique in this case! there may be other squares in the factor ideal!
+      }
+    }
+
+    return("The current commutative GR-algebra is not SCA! (Wrong quotient ideal)"); // no squares in the factor ideal!
   }
 
@@ -912,22 +1003,8 @@
   }
 
-  list LL = list(L[1], L[2], L[3], ideal(0), L[5], L[6]);
-  ideal Q = L[4];
-//  "Q = ", string(Q);
-
-  def  E = ring(LL);
-  setring E; // not a qring!
-//  E;
-
-  ideal Q = fetch(saveRing, Q); // should belong to E!
-  Q = twostd(Q);
-
-//  "Q = ", string(Q);
-
   for( i = b; i <= e; i++ )
   {
-    if( NF(var(i)^2, Q) != 0 )
-    {
-      setring saveRing;
+    if( NF(var(i)^2, std(0)) != 0 )
+    {
       return("The current ring is not SCA! (Wrong quotient ideal)");
     }
@@ -937,23 +1014,6 @@
   // ok. it is a SCA!!!
 
-  ideal QQ;
-
-  for( i = e; i >= b; i-- )
-  {
-    QQ[i - b + 1] = var(i)^2;
-  }
-
-  QQ = twostd(QQ);
-  Q = simplify(NF(Q, QQ),  1 + 2 + 4);
-
-  setring saveRing;
-
-  ideal QQ = fetch(E, Q);
-
-  return(list(b, e, QQ));
-}
-
-
-
+  return(list(b, e));
+}
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -1018,5 +1078,5 @@
 RETURN:  int
 PURPOSE:  returns 1 if basering is a supercommutative algebra and 0 otherwise.
-NOTE:     no error message!
+NOTE:     shows hint message for non-SCA algebras if the 'prot' option is on.
 EXAMPLE: example IsSCA; shows examples
 "
@@ -1027,4 +1087,9 @@
   {
     return(1);
+  }
+
+  if( find(option(),"prot") != 0 )
+  {
+    print(l);
   }
 
