From 7d23da3e0ee0d03f90f47585ea27f86ecbfe866b Mon Sep 17 00:00:00 2001 From: Jens Vollinga Date: Tue, 9 Sep 2008 22:41:39 +0200 Subject: [PATCH] Bug fix related to the usage of int instead of cl_I. --- check/exam_factor.cpp | 24 ++++++++++++++++++++++++ ginac/factor.cpp | 21 ++++++++++++++------- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/check/exam_factor.cpp b/check/exam_factor.cpp index fa895c6d..e3552bfc 100644 --- a/check/exam_factor.cpp +++ b/check/exam_factor.cpp @@ -101,6 +101,29 @@ static unsigned exam_factor1() e = ex("(1+4*x)*x^2*(1-4*x+16*x^2)*(3+5*x+92*x^3)", syms); result += check_factor(e); + e = ex("(77+11*x^3+25*x^2+27*x+102*x^4)*(85+57*x^3+92*x^2+29*x+66*x^4)", syms); + result += check_factor(e); + + return result; +} + +static unsigned exam_factor2() +{ + unsigned result = 0; + ex e, d; + symbol x("x"), y("y"), z("z"); + lst syms; + syms = x, y, z; + + e = ex("x+y", syms); + result += check_factor(e); + + e = ex("x+y", syms); + result += check_factor(e); + + e = ex("-2*(x+y)*(x-y)", syms); + result += check_factor(e); + return result; } @@ -111,6 +134,7 @@ unsigned exam_factor() cout << "examining polynomial factorization" << flush; result += exam_factor1(); cout << '.' << flush; + result += exam_factor2(); cout << '.' << flush; return result; } diff --git a/ginac/factor.cpp b/ginac/factor.cpp index 886819a3..73e7d6c1 100644 --- a/ginac/factor.cpp +++ b/ginac/factor.cpp @@ -124,8 +124,8 @@ struct UniPoly // assert: poly is in Z[x] Term t; for ( int i=poly.degree(x); i>=poly.ldegree(x); --i ) { - int coeff = ex_to(poly.coeff(x,i)).to_int(); - if ( coeff ) { + cl_I coeff = the(ex_to(poly.coeff(x,i)).to_cl_N()); + if ( !zerop(coeff) ) { t.c = R->canonhom(coeff); if ( !zerop(t.c) ) { t.exp = i; @@ -1057,7 +1057,7 @@ static ex hensel_univar(const ex& a_, const ex& x, unsigned int p, const UniPoly if ( gamma == 0 ) { gamma = alpha; } - unsigned int gamma_ui = ex_to(abs(gamma)).to_int(); + numeric gamma_ui = ex_to(abs(gamma)); a = a * gamma; UniPoly nu1 = u1_; nu1.unit_normal(); @@ -1078,7 +1078,7 @@ static ex hensel_univar(const ex& a_, const ex& x, unsigned int p, const UniPoly ex w = replace_lc(w1.to_ex(x), x, alpha); ex e = expand(a - u * w); numeric modulus = p; - const numeric maxmodulus(2*B*gamma_ui); + const numeric maxmodulus = 2*numeric(B)*gamma_ui; // step 4 while ( !e.is_zero() && modulus < maxmodulus ) { @@ -1966,7 +1966,8 @@ static ex factor_multivariate(const ex& poly, const exset& syms) /* factor leading coefficient */ pp = pp.collect(x); - ex vn = p.lcoeff(x); + ex vn = pp.lcoeff(x); + pp = pp.expand(); ex vnlst; if ( is_a(vn) ) { vnlst = lst(vn); @@ -2152,9 +2153,15 @@ static ex factor_multivariate(const ex& poly, const exset& syms) maxdegree = uvec[i].degree(); } } - unsigned int B = cl_I_to_uint(normmc * expt_pos(cl_I(2), maxdegree)); + cl_I B = normmc * expt_pos(cl_I(2), maxdegree); + cl_I l = 1; + cl_I pl = prime; + while ( pl < B ) { + l += 1; + pl = pl * prime; + } - ex res = hensel_multivar(poly, x, epv, prime, B, uvec, C); + ex res = hensel_multivar(pp, x, epv, prime, l, uvec, C); if ( res != lst() ) { ex result = cont; for ( size_t i=0; i