]> www.ginac.de Git - ginac.git/commitdiff
Fix bug in power::expand() with the overall coefficient.
authorVladimir V. Kisil <V.Kisilv@leeds.ac.uk>
Mon, 27 Jul 2020 19:03:42 +0000 (21:03 +0200)
committerRichard Kreckel <kreckel@ginac.de>
Mon, 27 Jul 2020 19:03:42 +0000 (21:03 +0200)
The negative sign of overall coefficient had been lost if a
power base contained some sign-definite factors.

check/exam_paranoia.cpp
ginac/power.cpp

index 52466b059b055fe2884636de1aef5a063cfa72c8..7a64e52cc1ab28acdcbc929ffd3d3a66174b365d 100644 (file)
@@ -651,6 +651,28 @@ unsigned exam_paranoia26()
        return 0;
 }
 
        return 0;
 }
 
+// Bug in power expansion
+unsigned exam_paranoia27()
+{
+       unsigned result = 0;
+       symbol x("x"), y("y"), a("a");
+       possymbol s("s"), t("t");
+       exmap pwrs =
+         { {pow((x+1)*(y-2)*(s-3)*(t+4), a), pow((x+1)*(y-2)*(s-3), a)*pow(t+4, a)},
+           {pow(2*(x+1)*(y-2)*(s-3)*(t+4), a), pow(2,a)*pow((x+1)*(y-2)*(s-3), a)*pow(t+4, a)},
+           {pow(-(x+1)*(y-2)*(s-3)*(t+4), a), pow(-(x+1)*(y-2)*(s-3), a)*pow(t+4, a)},
+           {pow(-2*(x+1)*(y-2)*(s-3)*(t+4), a), pow(2,a)*pow(-(x+1)*(y-2)*(s-3), a)*pow(t+4, a)} };
+
+       for (auto e : pwrs) {
+               if (! (e.first.expand()).is_equal(e.second) ) {
+                       clog << "power expansion of " << e.first << " produces error.\n";
+                       ++result;
+               }
+       }
+
+       return result;
+}
+
 unsigned exam_paranoia()
 {
        unsigned result = 0;
 unsigned exam_paranoia()
 {
        unsigned result = 0;
@@ -684,6 +706,7 @@ unsigned exam_paranoia()
        result += exam_paranoia24();  cout << '.' << flush;
        result += exam_paranoia25();  cout << '.' << flush;
        result += exam_paranoia26();  cout << '.' << flush;
        result += exam_paranoia24();  cout << '.' << flush;
        result += exam_paranoia25();  cout << '.' << flush;
        result += exam_paranoia26();  cout << '.' << flush;
+       result += exam_paranoia27();  cout << '.' << flush;
        
        return result;
 }
        
        return result;
 }
index 19b31034e64aea7ad61aca05c0f73f9a15b9a46a..ba7a66f4bc77cb912947fa06975b2ee801e304d9 100644 (file)
@@ -809,9 +809,10 @@ ex power::expand(unsigned options) const
                ex coeff=(possign? _ex1 : _ex_1);
                if (m.overall_coeff.info(info_flags::positive) && m.overall_coeff != _ex1)
                        prodseq.push_back(pow(m.overall_coeff, exponent));
                ex coeff=(possign? _ex1 : _ex_1);
                if (m.overall_coeff.info(info_flags::positive) && m.overall_coeff != _ex1)
                        prodseq.push_back(pow(m.overall_coeff, exponent));
-               else if (m.overall_coeff.info(info_flags::negative) && m.overall_coeff != _ex_1)
+               else if (m.overall_coeff.info(info_flags::negative) && m.overall_coeff != _ex_1) {
                        prodseq.push_back(pow(-m.overall_coeff, exponent));
                        prodseq.push_back(pow(-m.overall_coeff, exponent));
-               else
+                       coeff = -coeff;
+               } else
                        coeff *= m.overall_coeff;
 
                // If positive/negative factors are found, then extract them.
                        coeff *= m.overall_coeff;
 
                // If positive/negative factors are found, then extract them.