[SCM] an open source computer algebra system branch, cleanedupstream, updated. 6125e540ca6d66c307958938a9d53b245507c323

Bernhard R. Link brlink at debian.org
Tue Apr 24 15:55:16 UTC 2012


The following commit has been merged in the cleanedupstream branch:
commit 01bfe91a427c7e89d399a8c835cafe4e73ebc8fe
Author: Martin Lee <martinlee84 at web.de>
Date:   Tue Mar 6 21:48:34 2012 +0100

    chg: use uniFdivides in factorRecombination
    chg: take care of GF in uniFdivides and univariate *,/,%
    chg: switch on SW_RATIONAL if necessary

diff --git a/factory/facFqBivar.cc b/factory/facFqBivar.cc
index b1631e6..da73150 100644
--- a/factory/facFqBivar.cc
+++ b/factory/facFqBivar.cc
@@ -41,14 +41,14 @@ TIMING_DEFINE_PRINT(fac_uni_factorizer)
 TIMING_DEFINE_PRINT(fac_hensel_lift)
 TIMING_DEFINE_PRINT(fac_factor_recombination)
 
-CanonicalForm prodMod0 (const CFList& L, const CanonicalForm& M)
+CanonicalForm prodMod0 (const CFList& L, const CanonicalForm& M, const modpk& b)
 {
   if (L.isEmpty())
     return 1;
   else if (L.length() == 1)
     return mod (L.getFirst()(0, 1) , M);
   else if (L.length() == 2)
-    return mod (mulNTL (L.getFirst()(0, 1),L.getLast()(0, 1)), M);
+    return mod (mulNTL (L.getFirst()(0, 1),L.getLast()(0, 1), b), M);
   else
   {
     int l= L.length()/2;
@@ -58,9 +58,9 @@ CanonicalForm prodMod0 (const CFList& L, const CanonicalForm& M)
     for (int j= 1; j <= l; j++, i++)
       tmp1.append (i.getItem());
     tmp2= Difference (L, tmp1);
-    buf1= prodMod0 (tmp1, M);
-    buf2= prodMod0 (tmp2, M);
-    return mod (mulNTL (buf1,buf2), M);
+    buf1= prodMod0 (tmp1, M, b);
+    buf2= prodMod0 (tmp2, M, b);
+    return mod (mulNTL (buf1,buf2, b), M);
   }
 }
 
@@ -485,7 +485,8 @@ factorRecombination (CFList& factors, CanonicalForm& F,
   TT= copy (factors);
   bool recombination= false;
   CanonicalForm test;
-  CanonicalForm buf0= buf (0, x)*LCBuf;
+  CanonicalForm buf0= mulNTL (buf (0, x), LCBuf, b);
+  bool isRat= (isOn (SW_RATIONAL) && getCharacteristic() == 0) || getCharacteristic() > 0;
   while (T.length() >= 2*s && s <= thres)
   {
     while (nosubset == false)
@@ -519,12 +520,10 @@ factorRecombination (CFList& factors, CanonicalForm& F,
         continue;
       else
       {
-        test= prodMod0 (S, M);
-        test *= LCBuf;
-        test = mod (test, M);
-        if (b.getp() != 0)
-          test= b(test);
-        if (fdivides (test, buf0))
+        test= prodMod0 (S, M, b);
+        test= mulNTL (test, LCBuf, b);
+        test= mod (test, M);
+        if (uniFdivides (test, buf0))
         {
           S.insert (LCBuf);
           g= prodMod (S, M);
@@ -532,6 +531,8 @@ factorRecombination (CFList& factors, CanonicalForm& F,
           if (b.getp() != 0)
             g= b(g);
           g /= content (g, x);
+          if (!isRat)
+            On (SW_RATIONAL);
           if (fdivides (g, buf, quot))
           {
             recombination= true;
@@ -541,7 +542,9 @@ factorRecombination (CFList& factors, CanonicalForm& F,
             T= Difference (T, S);
             l -= degree (g);
             M= power (y, l);
-            buf0= buf (0, x)*LCBuf;
+            if (!isRat)
+              Off (SW_RATIONAL);
+            buf0= mulNTL (buf (0, x), LCBuf, b);
             // compute new possible degree pattern
             bufDegs2= DegreePattern (T);
             bufDegs1.intersect (bufDegs2);
@@ -567,6 +570,8 @@ factorRecombination (CFList& factors, CanonicalForm& F,
             indexUpdate (v, s, T.length(), nosubset);
             if (nosubset) break;
           }
+          if (!isRat)
+            Off (SW_RATIONAL);
         }
       }
     }
@@ -659,6 +664,7 @@ earlyFactorDetection (CFList& reconstructedFactors, CanonicalForm& F, CFList&
   CanonicalForm buf0= mulNTL (buf (0,x), LCBuf, b);
   CanonicalForm buf1= mulNTL (buf (1,x), LCBuf, b);
   CanonicalForm test0, test1;
+  bool isRat= (isOn (SW_RATIONAL) && getCharacteristic() == 0) || getCharacteristic() > 0;
   for (CFListIterator i= factors; i.hasItem(); i++, l++)
   {
     if (!bufDegs1.find (degree (i.getItem(), 1)) || factorsFoundIndex[l] == 1)
@@ -675,6 +681,8 @@ earlyFactorDetection (CFList& reconstructedFactors, CanonicalForm& F, CFList&
           if (b.getp() != 0)
             g= b(g);
           g /= content (g, x);
+          if (!isRat)
+            On (SW_RATIONAL);
           if (fdivides (g, buf, quot))
           {
             reconstructedFactors.append (g);
@@ -682,6 +690,8 @@ earlyFactorDetection (CFList& reconstructedFactors, CanonicalForm& F, CFList&
             buf= quot;
             d -= degree (g);
             LCBuf= LC (buf, x);
+            if (!isRat)
+              Off (SW_RATIONAL);
             buf0= mulNTL (buf (0,x), LCBuf, b);
             buf1= mulNTL (buf (1,x), LCBuf, b);
             T= Difference (T, CFList (i.getItem()));
@@ -697,6 +707,8 @@ earlyFactorDetection (CFList& reconstructedFactors, CanonicalForm& F, CFList&
               break;
             }
           }
+          if (!isRat)
+            Off (SW_RATIONAL);
         }
       }
     }
diff --git a/factory/facFqBivar.h b/factory/facFqBivar.h
index 8d6b684..bd2a0cf 100644
--- a/factory/facFqBivar.h
+++ b/factory/facFqBivar.h
@@ -577,7 +577,8 @@ GFBiFactorize (const CanonicalForm & G, ///< [in] a bivariate poly
 /// @sa prodMod()
 CanonicalForm prodMod0 (const CFList& L,       ///< [in] a list of compressed,
                                                ///< bivariate polynomials
-                        const CanonicalForm& M ///< [in] a power of Variable (2)
+                        const CanonicalForm& M,///< [in] a power of Variable (2)
+                        const modpk& b= modpk()///< [in] coeff bound
                        );
 
 /// find an evaluation point p, s.t. F(p,y) is squarefree and
diff --git a/factory/facMul.cc b/factory/facMul.cc
index 026afb8..1b70cd4 100644
--- a/factory/facMul.cc
+++ b/factory/facMul.cc
@@ -396,6 +396,8 @@ newtonDiv (const CanonicalForm& F, const CanonicalForm& G, CanonicalForm& Q)
 CanonicalForm
 mulNTL (const CanonicalForm& F, const CanonicalForm& G, const modpk& b)
 {
+  if (CFFactory::gettype() == GaloisFieldDomain)
+    return F*G;
   if (F.inCoeffDomain() || G.inCoeffDomain() || getCharacteristic() == 0)
   {
     Variable alpha;
@@ -479,8 +481,6 @@ mulNTL (const CanonicalForm& F, const CanonicalForm& G, const modpk& b)
   }
   ASSERT (F.isUnivariate() && G.isUnivariate(), "expected univariate polys");
   ASSERT (F.level() == G.level(), "expected polys of same level");
-  if (CFFactory::gettype() == GaloisFieldDomain)
-    return F*G;
   zz_p::init (getCharacteristic());
   Variable alpha;
   CanonicalForm result;
@@ -516,6 +516,8 @@ mulNTL (const CanonicalForm& F, const CanonicalForm& G, const modpk& b)
 CanonicalForm
 modNTL (const CanonicalForm& F, const CanonicalForm& G, const modpk& b)
 {
+  if (CFFactory::gettype() == GaloisFieldDomain)
+    return mod (F, G);
   if (F.inCoeffDomain() && G.isUnivariate())
   {
     if (b.getp() != 0)
@@ -592,8 +594,6 @@ modNTL (const CanonicalForm& F, const CanonicalForm& G, const modpk& b)
 
   ASSERT (F.isUnivariate() && G.isUnivariate(), "expected univariate polys");
   ASSERT (F.level() == G.level(), "expected polys of same level");
-  if (CFFactory::gettype() == GaloisFieldDomain)
-    return mod (F, G);
   zz_p::init (getCharacteristic());
   Variable alpha;
   CanonicalForm result;
@@ -629,6 +629,8 @@ modNTL (const CanonicalForm& F, const CanonicalForm& G, const modpk& b)
 CanonicalForm
 divNTL (const CanonicalForm& F, const CanonicalForm& G, const modpk& b)
 {
+  if (CFFactory::gettype() == GaloisFieldDomain)
+    return div (F, G);
   if (F.inCoeffDomain() && G.isUnivariate())
   {
     if (b.getp() != 0)
@@ -735,8 +737,6 @@ divNTL (const CanonicalForm& F, const CanonicalForm& G, const modpk& b)
 
   ASSERT (F.isUnivariate() && G.isUnivariate(), "expected univariate polys");
   ASSERT (F.level() == G.level(), "expected polys of same level");
-  if (CFFactory::gettype() == GaloisFieldDomain)
-    return div (F, G);
   zz_p::init (getCharacteristic());
   Variable alpha;
   CanonicalForm result;
@@ -2798,6 +2798,12 @@ void divrem (const CanonicalForm& F, const CanonicalForm& G, CanonicalForm& Q,
 bool
 uniFdivides (const CanonicalForm& A, const CanonicalForm& B)
 {
+  if (B.isZero())
+    return true;
+  if (A.isZero())
+    return false;
+  if (CFFactory::gettype() == GaloisFieldDomain)
+    return fdivides (A, B);
   int p= getCharacteristic();
   if (p > 0)
   {
@@ -2805,6 +2811,13 @@ uniFdivides (const CanonicalForm& A, const CanonicalForm& B)
     Variable alpha;
     if (hasFirstAlgVar (A, alpha) || hasFirstAlgVar (B, alpha))
     {
+      if (A.inCoeffDomain() || B.inCoeffDomain())
+      {
+        if (A.inCoeffDomain())
+          return true;
+        else
+          return false;
+      }
       zz_pX NTLMipo= convertFacCF2NTLzzpX (getMipo (alpha));
       zz_pE::init (NTLMipo);
       zz_pEX NTLA= convertFacCF2NTLzz_pEX (A, NTLMipo);
@@ -2831,8 +2844,6 @@ uniFdivides (const CanonicalForm& A, const CanonicalForm& B)
   if (!hasFirstAlgVar (A, alpha) && !hasFirstAlgVar (B, alpha))
   {
     fmpq_poly_t FLINTA,FLINTB;
-    fmpq_poly_init (FLINTA);
-    fmpq_poly_init (FLINTB);
     convertFacCF2Fmpq_poly_t (FLINTA, A);
     convertFacCF2Fmpq_poly_t (FLINTB, B);
     fmpq_poly_rem (FLINTA, FLINTB, FLINTA);
@@ -2852,7 +2863,13 @@ uniFdivides (const CanonicalForm& A, const CanonicalForm& B)
     Off (SW_RATIONAL);
   return R.isZero();
 #else
-  return fdivides (A, B); //maybe NTL?
+  bool isRat= isOn (SW_RATIONAL);
+  if (!isRat)
+    On (SW_RATIONAL);
+  bool result= fdivides (A, B);
+  if (!isRat)
+    Off (SW_RATIONAL);
+  return result; //maybe NTL?
 #endif
 }
 

-- 
an open source computer algebra system



More information about the debian-science-commits mailing list