]> www.ginac.de Git - ginac.git/blobdiff - ginac/polynomial/pgcd.cpp
pgcd(): avoid infinite loop if the first GCD candidate coincides with GCD
[ginac.git] / ginac / polynomial / pgcd.cpp
index 6e5e6b2ebc4bbaadc6adc1bcc20401f672d5af9d..fac3735e10333390ea42c91a5e229bfd4e5c11df 100644 (file)
@@ -3,7 +3,7 @@
  *  GCD for polynomials in prime field. */
 
 /*
- *  GiNaC Copyright (C) 1999-2009 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2010 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -121,6 +121,8 @@ ex pgcd(const ex& A, const ex& B, const exvector& vars, const long p)
                        // evaluation point is bad. Skip it.
                        continue;
                }
+               if (img_gcd_deg == 0)
+                       return cont_gcd;
 
                // Image has the same degree as the previous one
                // (or at least not higher than the limit)
@@ -132,8 +134,6 @@ ex pgcd(const ex& A, const ex& B, const exvector& vars, const long p)
                const ex H_lcoeff = lcoeff_wrt(H, restvars);
 
                if (H_lcoeff.is_equal(lc_gcd)) {
-                       if ((Hprev-H).expand().smod(pn).is_zero())
-                               continue;
                        ex C /* primitive part of H */, contH /* dummy */;
                        primpart_content(C, contH, H, vars, p);
                        // Normalize GCD so that leading coefficient is 1
@@ -145,8 +145,6 @@ ex pgcd(const ex& A, const ex& B, const exvector& vars, const long p)
                        if (divide_in_z_p(Aprim, C, dummy1, vars, p) &&
                                        divide_in_z_p(Bprim, C, dummy2, vars, p))
                                return (cont_gcd*C).expand().smod(pn);
-                       else if (img_gcd_deg == 0)
-                               return cont_gcd;
                        // else continue building the candidate
                } 
        } while(true);