From: Richard Kreckel Date: Fri, 20 May 2011 20:20:57 +0000 (+0200) Subject: Fixed a bug introduced in last commit. X-Git-Tag: release_1-6-0~8 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=0c2f0f4c6d4118e817c5b9a14a9d0f3ada82e9fe Fixed a bug introduced in last commit. Before, sqrt(2)*x used to be a polynomial in x. Now, it is a polynomial in x again. --- diff --git a/check/exam_paranoia.cpp b/check/exam_paranoia.cpp index 972270f8..52d261c8 100644 --- a/check/exam_paranoia.cpp +++ b/check/exam_paranoia.cpp @@ -497,13 +497,19 @@ static unsigned exam_paranoia19() // Bug in expairseq::is_polynomial (fixed 2011-05-20). static unsigned exam_paranoia20() { + unsigned result = 0; symbol x("x"); - ex e = sqrt(x*x+1)*sqrt(x+1); - if (e.is_polynomial(x)) { + ex e1 = sqrt(x*x+1)*sqrt(x+1); + if (e1.is_polynomial(x)) { clog << "sqrt(x*x+1)*sqrt(x+1) is wrongly reported to be a polynomial in x\n"; - return 1; + ++result; } - return 0; + ex e2 = sqrt(Pi)*x; + if (!e2.is_polynomial(x)) { + clog << "sqrt(Pi)*x is wrongly reported to be no polynomial in x\n"; + ++result; + } + return result; } unsigned exam_paranoia() diff --git a/ginac/add.cpp b/ginac/add.cpp index 553c2d31..42364c07 100644 --- a/ginac/add.cpp +++ b/ginac/add.cpp @@ -260,6 +260,16 @@ bool add::info(unsigned inf) const return inherited::info(inf); } +bool add::is_polynomial(const ex & var) const +{ + for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) { + if (!(i->rest).is_polynomial(var)) { + return false; + } + } + return true; +} + int add::degree(const ex & s) const { int deg = std::numeric_limits::min(); diff --git a/ginac/add.h b/ginac/add.h index 7d96c8c3..4d5bd0ae 100644 --- a/ginac/add.h +++ b/ginac/add.h @@ -47,6 +47,7 @@ public: public: unsigned precedence() const {return 40;} bool info(unsigned inf) const; + bool is_polynomial(const ex & var) const; int degree(const ex & s) const; int ldegree(const ex & s) const; ex coeff(const ex & s, int n=1) const; diff --git a/ginac/expairseq.cpp b/ginac/expairseq.cpp index 88d986ea..2649b4b8 100644 --- a/ginac/expairseq.cpp +++ b/ginac/expairseq.cpp @@ -375,28 +375,6 @@ ex expairseq::conjugate() const return result; } -bool expairseq::is_polynomial(const ex & var) const -{ - if (is_exactly_a(*this)) { - for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) { - if (!(i->rest).is_polynomial(var)) { - return false; - } - } - } - else if (is_exactly_a(*this)) { - for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) { - if (!(i->rest).is_polynomial(var) || !(i->coeff.info(info_flags::integer))) { - return false; - } - } - } - else { - return basic::is_polynomial(var); - } - return true; -} - bool expairseq::match(const ex & pattern, exmap & repl_lst) const { // This differs from basic::match() because we want "a+b+c+d" to diff --git a/ginac/expairseq.h b/ginac/expairseq.h index 7e8d5511..44d6e26b 100644 --- a/ginac/expairseq.h +++ b/ginac/expairseq.h @@ -87,7 +87,6 @@ public: bool match(const ex & pattern, exmap& repl_lst) const; ex subs(const exmap & m, unsigned options = 0) const; ex conjugate() const; - bool is_polynomial(const ex & var) const; void archive(archive_node& n) const; void read_archive(const archive_node& n, lst& syms); diff --git a/ginac/mul.cpp b/ginac/mul.cpp index 6810cb8d..27add930 100644 --- a/ginac/mul.cpp +++ b/ginac/mul.cpp @@ -347,6 +347,17 @@ bool mul::info(unsigned inf) const return inherited::info(inf); } +bool mul::is_polynomial(const ex & var) const +{ + for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) { + if (!i->rest.is_polynomial(var) || + (i->rest.has(var) && !i->coeff.info(info_flags::integer))) { + return false; + } + } + return true; +} + int mul::degree(const ex & s) const { // Sum up degrees of factors diff --git a/ginac/mul.h b/ginac/mul.h index 65f59bde..d28b6276 100644 --- a/ginac/mul.h +++ b/ginac/mul.h @@ -49,6 +49,7 @@ public: public: unsigned precedence() const {return 50;} bool info(unsigned inf) const; + bool is_polynomial(const ex & var) const; int degree(const ex & s) const; int ldegree(const ex & s) const; ex coeff(const ex & s, int n = 1) const;