From 321d5c941f81b1d0b86de91f3f17c5af5b6e4642 Mon Sep 17 00:00:00 2001 From: Jens Vollinga Date: Thu, 21 Aug 2008 22:37:09 +0200 Subject: [PATCH] Daily bugfix in the polynomial factorization (code didn't catch polynomial "x" and cln::sqrt conversion was buggy). --- check/exam_factor.cpp | 7 ++++++- ginac/factor.cpp | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/check/exam_factor.cpp b/check/exam_factor.cpp index bf1751a5..7e156487 100644 --- a/check/exam_factor.cpp +++ b/check/exam_factor.cpp @@ -83,12 +83,17 @@ static unsigned exam_factor1() result += check_factor(e); e = ex("x*(2+x^2)*(1+x+x^3+x^2+x^6+x^5+x^4)*(1+x)^2*(1-x+x^2)^2*(-1+x)", syms); - result += check_factor(e); e = ex("(x+4+x^2-x^3+43*x^4)*(x+1-x^2-3*x^3+4*x^4)", syms); result += check_factor(e); + e = ex("-x^2*(x-1)*(1+x^2)", syms); + result += check_factor(e); + + e = x; + result += check_factor(e); + return result; } diff --git a/ginac/factor.cpp b/ginac/factor.cpp index 5489b4ce..9b06e6e1 100644 --- a/ginac/factor.cpp +++ b/ginac/factor.cpp @@ -888,7 +888,7 @@ static ex hensel_univar(const ex& a_, const ex& x, unsigned int p, const UniPoly for ( int i=a.degree(x); i>=a.ldegree(x); --i ) { maxcoeff += pow(abs(a.coeff(x, i)),2); } - cl_I normmc = ceiling1(the(cln::sqrt(ex_to(maxcoeff).to_cl_N()))); + cl_I normmc = ceiling1(the(cln::sqrt(ex_to(maxcoeff).to_cl_N()))); unsigned int maxdegree = (u1_.degree() > w1_.degree()) ? u1_.degree() : w1_.degree(); unsigned int B = cl_I_to_uint(normmc * expt_pos(cl_I(2), maxdegree)); @@ -1233,6 +1233,9 @@ ex factor(const ex& poly) } return res; } + if ( is_a(sfpoly) ) { + return poly; + } // case: (polynomial) ex f = factor_sqrfree(sfpoly); return f; -- 2.44.0