Before, sqrt(2)*x used to be a polynomial in x.
Now, it is a polynomial in x again.
// 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()
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<int>::min();
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;
return result;
}
-bool expairseq::is_polynomial(const ex & var) const
-{
- if (is_exactly_a<add>(*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<mul>(*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
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);
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
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;