]> www.ginac.de Git - ginac.git/commitdiff
[PATCH 2/2] chinrem_gcd: return correct integer content when GCD is a number.
authorAlexei Sheplyakov <alexei.sheplyakov@gmail.com>
Fri, 3 Dec 2010 23:36:50 +0000 (00:36 +0100)
committerRichard Kreckel <kreckel@ginac.de>
Sat, 4 Dec 2010 07:41:54 +0000 (08:41 +0100)
This patch fixes a silly typo and makes chinrem_gcd work correctly with
polynomials which are "almost" (up to an integer coefficient) relatively
prime.

Thanks to Ernst Moritz Hahn for a bug report and a test case.
(cherry picked from commit 00507499530d90533cf029bd503be326d9018138)

check/bugme_chinrem_gcd.cpp
ginac/polynomial/mgcd.cpp

index 87c718c7114cf4ceff3ad617b092ab959c0454b3..9325e338710c20eaf6387342ccebe418fc049e68 100644 (file)
@@ -54,11 +54,24 @@ static void check_extract_integer_content()
        ex g = chinrem_gcd(A, B);
 }
 
+static void integer_coeff_braindamage()
+{
+       parser readme;
+       ex A = readme("3*x2 + 1");
+       ex B = readme("9*x2 + 1");
+       ex g = chinrem_gcd(A, B);
+       if (!g.is_equal(ex(1))) {
+               std::cerr << "expected 1, got " << g << std::endl;
+               throw std::logic_error("chinrem_gcd miscomputed integer content");
+       }
+}
+
 int main(int argc, char** argv)
 {
        cout << "checking for bugs in poly_cra() and friends " << flush;
        check_poly_cra();
        check_extract_integer_content();
+       integer_coeff_braindamage();
        cout << "not found.";
        return 0;
 }
index 7500805e4129cdf008226b50702c3ed39465fbf8..901f075a943f467355752a961183c62d83d0ad56 100644 (file)
@@ -101,7 +101,7 @@ ex chinrem_gcd(const ex& A_, const ex& B_, const exvector& vars)
                Cp = (Cp*numeric(nlc)).expand().smod(pnum);
                exp_vector_t cp_deg = degree_vector(Cp, vars);
                if (zerop(cp_deg))
-                       return numeric(g_lc);
+                       return numeric(c);
                if (zerop(q)) {
                        H = Cp;
                        n = cp_deg;