]> www.ginac.de Git - ginac.git/commitdiff
synced to 1.0
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 24 Oct 2002 21:06:40 +0000 (21:06 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 24 Oct 2002 21:06:40 +0000 (21:06 +0000)
check/exam_paranoia.cpp
ginac/add.cpp
ginac/power.cpp

index 50b5cabd9eb1630eb6730cfd303ecb2f64d4c83d..68762e963621f543da2afb3b5a50cbe0cc7046eb 100644 (file)
@@ -352,6 +352,24 @@ static unsigned exam_paranoia14(void)
        return result;
 }
 
+// Under certain conditions, power::expand_add_2() could produce non-canonical
+// numeric expairs. Fixed on Oct 24, 2002.
+static unsigned exam_paranoia15(void)
+{
+       unsigned result = 0;
+
+       ex q = (pow(pow(2, numeric(1, 2))*2+1, 2)).expand();
+       // this used to produce "1+4*sqrt(2)+4*2" which would never evaluate
+       // to "9+4*sqrt(2)"
+
+       if (!(q-9-4*pow(2, numeric(1, 2))).is_zero()) {
+               clog << "expand((sqrt(2)*2+1)^2) erroneously returned " << q << " instead of 9-4*sqrt(2)\n";
+               ++result;
+       }
+
+       return result;
+}
+
 unsigned exam_paranoia(void)
 {
        unsigned result = 0;
@@ -373,6 +391,7 @@ unsigned exam_paranoia(void)
        result += exam_paranoia12();  cout << '.' << flush;
        result += exam_paranoia13();  cout << '.' << flush;
        result += exam_paranoia14();  cout << '.' << flush;
+       result += exam_paranoia15();  cout << '.' << flush;
        
        if (!result) {
                cout << " passed " << endl;
index f3721e66f042ccec5e28936ee85ad56c8b8598a0..4302c188a669daa4484a87f488f0a5f5bdc59c5b 100644 (file)
@@ -520,7 +520,7 @@ ex add::expand(unsigned options) const
                // the terms have not changed, so it is safe to declare this expanded
                return (options == 0) ? setflag(status_flags::expanded) : *this;
        }
-       
+
        return (new add(vp, overall_coeff))->setflag(status_flags::dynallocated | (options == 0 ? status_flags::expanded : 0));
 }
 
index 90850c67ede0476bfcec000a8e32d12033761417..e5325dd7d5115551d0183caec74f4fb0ae8e4760 100644 (file)
@@ -765,10 +765,10 @@ ex power::expand_add_2(const add & a) const
                        }
                } else {
                        if (is_exactly_a<mul>(r)) {
-                               sum.push_back(expair(expand_mul(ex_to<mul>(r),_num2),
+                               sum.push_back(a.combine_ex_with_coeff_to_pair(expand_mul(ex_to<mul>(r),_num2),
                                                     ex_to<numeric>(c).power_dyn(_num2)));
                        } else {
-                               sum.push_back(expair((new power(r,_ex2))->setflag(status_flags::dynallocated),
+                               sum.push_back(a.combine_ex_with_coeff_to_pair((new power(r,_ex2))->setflag(status_flags::dynallocated),
                                                     ex_to<numeric>(c).power_dyn(_num2)));
                        }
                }
@@ -812,16 +812,16 @@ ex power::expand_mul(const mul & m, const numeric & n) const
        epvector::const_iterator last = m.seq.end();
        epvector::const_iterator cit = m.seq.begin();
        while (cit!=last) {
-               if (is_exactly_a<numeric>((*cit).rest)) {
-                       distrseq.push_back(m.combine_pair_with_coeff_to_pair(*cit,n));
+               if (is_exactly_a<numeric>(cit->rest)) {
+                       distrseq.push_back(m.combine_pair_with_coeff_to_pair(*cit, n));
                } else {
                        // it is safe not to call mul::combine_pair_with_coeff_to_pair()
                        // since n is an integer
-                       distrseq.push_back(expair((*cit).rest, ex_to<numeric>((*cit).coeff).mul(n)));
+                       distrseq.push_back(expair(cit->rest, ex_to<numeric>(cit->coeff).mul(n)));
                }
                ++cit;
        }
-       return (new mul(distrseq,ex_to<numeric>(m.overall_coeff).power_dyn(n)))->setflag(status_flags::dynallocated);
+       return (new mul(distrseq, ex_to<numeric>(m.overall_coeff).power_dyn(n)))->setflag(status_flags::dynallocated);
 }
 
 } // namespace GiNaC