]> www.ginac.de Git - ginac.git/commitdiff
Fix pow(+(...),2).expand().
authorRichard Kreckel <kreckel@ginac.de>
Sat, 18 Jul 2015 21:56:55 +0000 (23:56 +0200)
committerRichard Kreckel <kreckel@ginac.de>
Sat, 18 Jul 2015 21:56:55 +0000 (23:56 +0200)
Due to a failure to expand result terms, expand((sqrt(1+x)+y*sqrt(1+x))^2)
returned 1+y^2+x+x*y^2+2*y*(1+x). Note that 2*y*(1+x) was not expanded
to 2*y+2*y*x.

check/exam_paranoia.cpp
ginac/power.cpp

index 51bd3a55ee1baaa61d54a0f166f876d47f61dab6..711c64a67c8472805d59eaa992fdbc0d2c1ff940 100644 (file)
@@ -556,6 +556,18 @@ static unsigned exam_paranoia21()
        return 0;
 }
 
+// Bug in power::expand (fixed 2015-07-18).
+static unsigned exam_paranoia22()
+{
+       symbol x("x"), y("y");
+       ex e = pow(sqrt(1+x)+y*sqrt(1+x), 2).expand();
+       if (e.nops() != 6) {
+               clog << "(sqrt(1+x)+y*sqrt(1+x))^2 was wrongly expanded to " << e << "\n";
+               return 1;
+       }
+       return 0;
+}
+
 unsigned exam_paranoia()
 {
        unsigned result = 0;
@@ -584,6 +596,7 @@ unsigned exam_paranoia()
        result += exam_paranoia20();  cout << '.' << flush;
        result += is_polynomial_false_positive(); cout << '.' << flush;
        result += exam_paranoia21();  cout << '.' << flush;
+       result += exam_paranoia22();  cout << '.' << flush;
        
        return result;
 }
index b2460fda8661d234dc8c4b6fb30890c5d1920465..6fa619cafcfb6a878c5dab22fac32cfd1e4e7b29 100644 (file)
@@ -1051,14 +1051,14 @@ ex power::expand_add_2(const add & a, unsigned options) const
                for (epvector::const_iterator cit1=cit0+1; cit1!=last; ++cit1) {
                        const ex & r1 = cit1->rest;
                        const ex & c1 = cit1->coeff;
-                       sum.push_back(a.combine_ex_with_coeff_to_pair((new mul(r,r1))->setflag(status_flags::dynallocated),
+                       sum.push_back(a.combine_ex_with_coeff_to_pair(mul(r,r1).expand(options),
                                                                      _num2_p->mul(ex_to<numeric>(c)).mul_dyn(ex_to<numeric>(c1))));
                }
        }
        
        GINAC_ASSERT(sum.size()==(a.seq.size()*(a.seq.size()+1))/2);
        
-       // second part: add terms coming from overall_factor (if != 0)
+       // second part: add terms coming from overall_coeff (if != 0)
        if (!a.overall_coeff.is_zero()) {
                epvector::const_iterator i = a.seq.begin(), end = a.seq.end();
                while (i != end) {