[GiNaC-devel] [PATCH 2/2] chinrem_gcd: return correct integer content when GCD is a number.

Alexei Sheplyakov alexei.sheplyakov at gmail.com
Fri Dec 3 22:49:49 CET 2010


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.

---
 check/bugme_chinrem_gcd.cpp |   13 +++++++++++++
 ginac/polynomial/mgcd.cpp   |    2 +-
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/check/bugme_chinrem_gcd.cpp b/check/bugme_chinrem_gcd.cpp
index 87c718c..eaca381 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*x^2 + 1");
+	ex B = readme("9*x^2 + 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 7500805..901f075 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;
-- 
1.7.2.3



More information about the GiNaC-devel mailing list