]> www.ginac.de Git - ginac.git/commitdiff
Fixed a bug introduced in last commit.
authorRichard Kreckel <kreckel@ginac.de>
Fri, 20 May 2011 20:20:57 +0000 (22:20 +0200)
committerRichard Kreckel <kreckel@ginac.de>
Fri, 20 May 2011 20:20:57 +0000 (22:20 +0200)
Before, sqrt(2)*x used to be a polynomial in x.
Now, it is a polynomial in x again.

check/exam_paranoia.cpp
ginac/add.cpp
ginac/add.h
ginac/expairseq.cpp
ginac/expairseq.h
ginac/mul.cpp
ginac/mul.h

index 972270f835c22a92795fb096a91f0685f4fb4a66..52d261c8b46712962084e373de2de19ae28603c2 100644 (file)
@@ -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()
index 553c2d31985be5842adff90280421dbc7be117fd..42364c07c54f3f00d6d4a801327b08b5314ea669 100644 (file)
@@ -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<int>::min();
index 7d96c8c30ed2d2fdff91d933acb14d6d55bbbdd4..4d5bd0aee7242ce0690139c7cdf61050637f39a0 100644 (file)
@@ -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;
index 88d986ea50f84d05be5b7e0922ff9f39c5f7627e..2649b4b8b6c28d51089c00fe012ed48dbe028e72 100644 (file)
@@ -375,28 +375,6 @@ ex expairseq::conjugate() 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
index 7e8d55111d01b94d6d8e3039a8b42861baf160b0..44d6e26b146f28dd53ce8b888d08a39e12295fd3 100644 (file)
@@ -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);
index 6810cb8dbb408360fbb37e672e15e8db54becfd5..27add930cf56863ae7d635d3031e4dc2b1d7ea9f 100644 (file)
@@ -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
index 65f59bde36469ebc902e2af5004500f70310b71b..d28b6276c8b3d91039f9a5d0276e4a80bb490731 100644 (file)
@@ -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;