From e40d1ca945c398398f61171042d22935900dbda1 Mon Sep 17 00:00:00 2001 From: Christian Bauer Date: Thu, 24 Oct 2002 21:06:40 +0000 Subject: [PATCH] synced to 1.0 --- check/exam_paranoia.cpp | 19 +++++++++++++++++++ ginac/add.cpp | 2 +- ginac/power.cpp | 12 ++++++------ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/check/exam_paranoia.cpp b/check/exam_paranoia.cpp index 50b5cabd..68762e96 100644 --- a/check/exam_paranoia.cpp +++ b/check/exam_paranoia.cpp @@ -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; diff --git a/ginac/add.cpp b/ginac/add.cpp index f3721e66..4302c188 100644 --- a/ginac/add.cpp +++ b/ginac/add.cpp @@ -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)); } diff --git a/ginac/power.cpp b/ginac/power.cpp index 90850c67..e5325dd7 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -765,10 +765,10 @@ ex power::expand_add_2(const add & a) const } } else { if (is_exactly_a(r)) { - sum.push_back(expair(expand_mul(ex_to(r),_num2), + sum.push_back(a.combine_ex_with_coeff_to_pair(expand_mul(ex_to(r),_num2), ex_to(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(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((*cit).rest)) { - distrseq.push_back(m.combine_pair_with_coeff_to_pair(*cit,n)); + if (is_exactly_a(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((*cit).coeff).mul(n))); + distrseq.push_back(expair(cit->rest, ex_to(cit->coeff).mul(n))); } ++cit; } - return (new mul(distrseq,ex_to(m.overall_coeff).power_dyn(n)))->setflag(status_flags::dynallocated); + return (new mul(distrseq, ex_to(m.overall_coeff).power_dyn(n)))->setflag(status_flags::dynallocated); } } // namespace GiNaC -- 2.49.0