From 59fa68b8930779dfc419291d028b57b0d91d33d0 Mon Sep 17 00:00:00 2001 From: Alexei Sheplyakov Date: Sat, 4 Dec 2010 00:36:50 +0100 Subject: [PATCH] [PATCH 2/2] chinrem_gcd: return correct integer content when GCD is a number. 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 | 13 +++++++++++++ ginac/polynomial/mgcd.cpp | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/check/bugme_chinrem_gcd.cpp b/check/bugme_chinrem_gcd.cpp index 87c718c7..9325e338 100644 --- a/check/bugme_chinrem_gcd.cpp +++ b/check/bugme_chinrem_gcd.cpp @@ -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; } diff --git a/ginac/polynomial/mgcd.cpp b/ginac/polynomial/mgcd.cpp index 7500805e..901f075a 100644 --- a/ginac/polynomial/mgcd.cpp +++ b/ginac/polynomial/mgcd.cpp @@ -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; -- 2.44.0