Index: factory/facFactorize.cc
===================================================================
--- factory/facFactorize.cc	(revision e0af3ef0dd8793dabc30eac5d848f0b020acd362)
+++ factory/facFactorize.cc	(revision 8a30b16f7366d41b6243988673b9dc25cb0da4a5)
@@ -268,6 +268,7 @@
 
   CFMap N, M;
-  CFArray dummy= CFArray (1);
+  CFArray dummy= CFArray (2);
   dummy [0]= LCF;
+  dummy [1]= Variable (2);
   compress (dummy, M, N);
   CanonicalForm F= M (LCF);
@@ -321,7 +322,18 @@
   CFList evalSqrfPartF, bufFactors;
   CFArray evalPoint= CFArray (evaluation.length() - 1);
+  CFArray buf= CFArray (evaluation.length());
+  CFArray swap= CFArray (evaluation.length());
   CFListIterator iter= evaluation;
-  for (int i= evaluation.length() - 2; i > -1; i--, iter++)
-    evalPoint[i]= iter.getItem();
+  CanonicalForm vars=getVars (LCF);
+  for (int i= evaluation.length() +1; i > 1; i--, iter++)
+  {
+    buf[i-2]=iter.getItem();
+    if (degree (vars, i) > 0)
+      swap[M(Variable (i)).level()-1]=buf[i-2];
+  }
+  buf= swap;
+  for (int i= 0; i < evaluation.length() - 1; i++)
+    evalPoint[i]= buf[i+1];
+
   //TODO sqrfPartF einmal berechnen nicht stÃ€ndig
   int pass= testFactors (F, factors, sqrfPartF,
@@ -335,9 +347,8 @@
   {
     int lev= 0;
+    CanonicalForm bufF;
+    CFList bufBufFactors;
     for (int i= 0; i < length; i++)
     {
-      CanonicalForm bufF, swap;
-      CFList bufBufFactors;
-      CFArray buf;
       if (!differentSecondVarLCs [i].isEmpty())
       {
@@ -363,19 +374,10 @@
         bufBufFactors= bufFactors;
         evalPoint= CFArray (evaluation.length() - 1);
-        buf= CFArray (evaluation.length());
-        iter= evaluation;
-        int k= evaluation.length() - 1;
-        for (; iter.hasItem(); iter++, k--)
-          buf[k]= iter.getItem();
-        swap= buf[z.level() - 1];
-        buf[z.level() - 1]= buf[0];
-        buf[0]= 0;
-        int l= 0;
-        for (k= 0; k < evaluation.length(); k++)
+        for (int k= 0; k < evaluation.length()-1; k++)
         {
-          if (buf[k].isZero())
-            continue;
-          evalPoint[l]= buf[k];
-          l++;
+          if (k+1 != lev)
+            evalPoint[k]= buf[k+1];
+          else
+            evalPoint[k]= buf[0];
         }
         pass= testFactors (bufF, bufBufFactors, sqrfPartF, bufFactors,
@@ -421,27 +423,10 @@
   bufFactors= factors;
   CFList evaluation2;
-  if (y == x)
-    evaluation2= evaluation;
-  else
-  {
-    CanonicalForm tmp;
-    evaluation2= evaluation;
-    int i= evaluation.length() + 1;
-    for (CFListIterator iter= evaluation2; iter.hasItem(); iter++, i--)
-    {
-      if (i == y.level())
-      {
-        tmp= iter.getItem();
-        iter.getItem()= evaluation2.getLast();
-        evaluation2.removeLast();
-        evaluation2.append (tmp);
-        break;
-      }
-    }
-  }
+  for (int i= 0; i < F.level()-1; i++)
+    evaluation2.insert (evalPoint[i]);
 
   CFList interMedResult;
   CanonicalForm oldSqrfPartF= sqrfPartF;
-  sqrfPartF= shift2Zero (sqrfPartF, evalSqrfPartF, evaluation2, 1);
+  sqrfPartF= shift2Zero (sqrfPartF, evalSqrfPartF, evaluation2);
   if (factors.length() > 1)
   {
@@ -451,5 +436,5 @@
       leadingCoeffs.append (LC1);
 
-    CFList LC1eval= evaluateAtEval (LC1, evaluation2, 1);
+    CFList LC1eval= evaluateAtEval (LC1, evaluation2,2);
     CFList oldFactors= factors;
     for (CFListIterator i= oldFactors; i.hasItem(); i++)
@@ -460,5 +445,5 @@
     if (size (oldSqrfPartFPowLC)/getNumVars (oldSqrfPartFPowLC) < 500 &&
         LucksWangSparseHeuristic (oldSqrfPartFPowLC,
-                                  oldFactors, 1, leadingCoeffs, factors))
+                                  oldFactors, 2, leadingCoeffs, factors))
     {
       interMedResult= recoverFactors (oldSqrfPartF, factors);
@@ -475,8 +460,5 @@
 
       for (CFListIterator i= factors; i.hasItem(); i++)
-      {
-        i.getItem()= i.getItem() (x + evaluation2.getLast(), x);
         i.getItem() *= LC1 (0,2)/Lc (i.getItem());
-      }
       factors.insert (1);
 
@@ -522,8 +504,8 @@
       }
       for (CFListIterator iter= factors; iter.hasItem(); iter++)
-        iter.getItem()= reverseShift (iter.getItem(), evaluation2, 1);
+        iter.getItem()= reverseShift (iter.getItem(), evaluation2);
 
       interMedResult=
-      recoverFactors (reverseShift(evalSqrfPartF.getLast(),evaluation2,1),
+      recoverFactors (reverseShift(evalSqrfPartF.getLast(),evaluation2),
                       factors);
     }
Index: factory/facFqFactorize.cc
===================================================================
--- factory/facFqFactorize.cc	(revision e0af3ef0dd8793dabc30eac5d848f0b020acd362)
+++ factory/facFqFactorize.cc	(revision 8a30b16f7366d41b6243988673b9dc25cb0da4a5)
@@ -1220,5 +1220,5 @@
       {
         CFListIterator iter1= result;
-        for (CFListIterator iter2= differentSecondVarFactors[i]; iter2.hasItem();
+        for (CFListIterator iter2= differentSecondVarFactors[i];iter2.hasItem();
              iter2++, iter1++)
         {
@@ -1233,6 +1233,7 @@
 
   Variable v;
-  CFListIterator iter1;
+  CFListIterator iter1, iter2;
   CanonicalForm tmp, g;
+  CFList multiplier;
   for (int i= 0; i < length; i++)
   {
@@ -1243,25 +1244,31 @@
 
     v= Variable (i + 3);
-    for (CFListIterator iter2= differentSecondVarFactors[i]; iter2.hasItem();
+    tmp= 1;
+    for (iter2= differentSecondVarFactors[i]; iter2.hasItem();
          iter2++, iter1++)
     {
       if (degree (iter2.getItem(),v) == degree (iter1.getItem(),v))
+      {
+        multiplier.append (1);
         continue;
-      tmp= iter1.getItem();
-      for (int j= tmp.level(); j > 1; j--)
-      {
-        if (j == i + 3)
-          continue;
-        tmp= tmp (0, j);
       }
       g= gcd (iter2.getItem(), content);
-      if (degree (g) > 0)
-      {
-        if (!tmp.isZero())
-          iter2.getItem() /= tmp;
-        content /= g;
-        iter1.getItem() *= g;
-      }
-    }
+      if (!g.inCoeffDomain())
+      {
+        tmp *= g;
+        multiplier.append (g);
+      }
+      else
+        multiplier.append (1);
+    }
+    if (!tmp.isOne() && fdivides (tmp, content))
+    {
+      iter1= l;
+      iter1++;
+      content /= tmp;
+      for (iter2= multiplier; iter2.hasItem(); iter1++, iter2++)
+        iter1.getItem() *= iter2.getItem();
+    }
+    multiplier= CFList();
   }
 
@@ -1433,6 +1440,7 @@
 
   CFMap N, M;
-  CFArray dummy= CFArray (1);
+  CFArray dummy= CFArray (2);
   dummy [0]= LCF;
+  dummy [1]= Variable (2);
   compress (dummy, M, N);
   CanonicalForm F= M (LCF);
@@ -1486,7 +1494,17 @@
   CFList evalSqrfPartF, bufFactors;
   CFArray evalPoint= CFArray (evaluation.length() - 1);
+  CFArray buf= CFArray (evaluation.length());
+  CFArray swap= CFArray (evaluation.length());
   CFListIterator iter= evaluation;
-  for (int i= evaluation.length() - 2; i > -1; i--, iter++)
-    evalPoint[i]= iter.getItem();
+  CanonicalForm vars=getVars (LCF);
+  for (int i= evaluation.length() +1; i > 1; i--, iter++)
+  {
+    buf[i-2]=iter.getItem();
+    if (degree (vars, i) > 0)
+      swap[M(Variable (i)).level()-1]=buf[i-2];
+  }
+  buf= swap;
+  for (int i= 0; i < evaluation.length() - 1; i++)
+    evalPoint[i]= buf[i+1];
 
   int pass= testFactors (F, factors, alpha, sqrfPartF,
@@ -1501,6 +1519,5 @@
     // LCF is non-constant here
     CFList bufBufFactors;
-    CanonicalForm bufF, swap;
-    CFArray buf;
+    CanonicalForm bufF;
     for (int i= 0; i < lSecondVarLCs; i++)
     {
@@ -1528,19 +1545,10 @@
         bufBufFactors= bufFactors;
         evalPoint= CFArray (evaluation.length() - 1);
-        buf= CFArray (evaluation.length());
-        iter= evaluation;
-        int k= evaluation.length() - 1;
-        for (; iter.hasItem(); iter++, k--)
-          buf[k]= iter.getItem();
-        swap= buf[z.level() - 1];
-        buf[z.level() - 1]= buf[0];
-        buf[0]= 0;
-        int l= 0;
-        for (k= 0; k < evaluation.length(); k++)
-        {
-          if (buf[k].isZero())
-            continue;
-          evalPoint[l]= buf[k];
-          l++;
+        for (int k= 0; k < evaluation.length()-1; k++)
+        {
+          if (k+1 != lev)
+            evalPoint[k]= buf[k+1];
+          else
+            evalPoint[k]= buf[0];
         }
         pass= testFactors (bufF, bufBufFactors, alpha, sqrfPartF, bufFactors,
@@ -1585,27 +1593,10 @@
   bufFactors= factors;
   CFList evaluation2;
-  if (y == x)
-    evaluation2= evaluation;
-  else
-  {
-    CanonicalForm tmp;
-    evaluation2= evaluation;
-    int i= evaluation.length() + 1;
-    for (CFListIterator iter= evaluation2; iter.hasItem(); iter++, i--)
-    {
-      if (i == y.level())
-      {
-        tmp= iter.getItem();
-        iter.getItem()= evaluation2.getLast();
-        evaluation2.removeLast();
-        evaluation2.append (tmp);
-        break;
-      }
-    }
-  }
+  for (int i= 0; i < F.level()-1; i++)
+    evaluation2.insert (evalPoint[i]);
 
   CFList interMedResult;
   CanonicalForm oldSqrfPartF= sqrfPartF;
-  sqrfPartF= shift2Zero (sqrfPartF, evalSqrfPartF, evaluation2, 1);
+  sqrfPartF= shift2Zero (sqrfPartF, evalSqrfPartF, evaluation2);
   if (factors.length() > 1)
   {
@@ -1615,5 +1606,5 @@
       leadingCoeffs.append (LC1);
 
-    CFList LC1eval= evaluateAtEval (LC1, evaluation2, 1);
+    CFList LC1eval= evaluateAtEval (LC1, evaluation2, 2);
     CFList oldFactors= factors;
     for (CFListIterator i= oldFactors; i.hasItem(); i++)
@@ -1624,5 +1615,5 @@
     if (size (oldSqrfPartFPowLC)/getNumVars (oldSqrfPartFPowLC) < 500 &&
         LucksWangSparseHeuristic (oldSqrfPartFPowLC,
-                                  oldFactors, 1, leadingCoeffs, factors))
+                                  oldFactors, 2, leadingCoeffs, factors))
     {
       interMedResult= recoverFactors (oldSqrfPartF, factors);
@@ -1639,8 +1630,5 @@
 
       for (CFListIterator i= factors; i.hasItem(); i++)
-      {
-        i.getItem()= i.getItem() (x + evaluation2.getLast(), x);
         i.getItem() *= LC1 (0,2)/Lc (i.getItem());
-      }
       factors.insert (1);
 
@@ -1686,8 +1674,8 @@
       }
       for (CFListIterator iter= factors; iter.hasItem(); iter++)
-        iter.getItem()= reverseShift (iter.getItem(), evaluation2, 1);
+        iter.getItem()= reverseShift (iter.getItem(), evaluation2);
 
       interMedResult=
-      recoverFactors (reverseShift(evalSqrfPartF.getLast(),evaluation2,1),
+      recoverFactors (reverseShift(evalSqrfPartF.getLast(),evaluation2),
                       factors);
     }
@@ -1916,4 +1904,12 @@
 }
 
+CFList conv (const CFArray & A)
+{
+  CFList result;
+  for (int i= A.max(); i >= A.min(); i--)
+    result.insert (A[i]);
+  return result;
+}
+
 void getLeadingCoeffs (const CanonicalForm& A, CFList*& Aeval,
                        const CFList& uniFactors, const CFList& evaluation
@@ -1924,6 +1920,7 @@
   CFListIterator iter, iter2;
   Variable v;
-  CFList l, LCs, buf;
-  int pos;
+  CFList LCs, buf;
+  CFArray l;
+  int pos, index;
   for (int j= 0; j < A.level() - 2; j++)
   {
@@ -1946,18 +1943,21 @@
                                  evalPoint, v);
 
-      l= CFList();
       buf= buildUniFactors (Aeval[j], evalPoint, v);
-      for (iter= uniFactors; iter.hasItem(); iter++)
-      {
-        pos= findItem (buf, iter.getItem());
+      l= CFArray (uniFactors.length());
+      index= 1;
+      for (iter= buf; iter.hasItem(); iter++, index++)
+      {
+        pos= findItem (uniFactors, iter.getItem());
         if (pos)
-          l.append (getItem (Aeval[j], pos));
-      }
-      Aeval [j]= l;
-
+          l[pos-1]= getItem (Aeval[j], index);
+      }
+      buf= conv (l);
+      Aeval [j]= buf;
+
+      buf= buildUniFactors (Aeval[j], evalPoint, v);
       LCs= CFList();
       for (iter= Aeval[j]; iter.hasItem(); iter++)
         LCs.append (LC (iter.getItem(), 1));
-      normalize (LCs);
+      //normalize (LCs);
       Aeval[j]= LCs;
     }
