From da3cc1d79533680f0722be73abe95aedcac96b72 Mon Sep 17 00:00:00 2001 From: Richard Kreckel Date: Thu, 17 Dec 2015 22:45:50 +0100 Subject: [PATCH] Remove useless code in add::eval(). With commit ae6c004b, we have actually a more rigorous solution for the bug fixed first (and wrongly) on September 23 2010 with commit 89d5356b. This patch removes the now useless code and adds the new regression check from master, just in case. --- check/exam_paranoia.cpp | 20 +++++++++++++++----- ginac/add.cpp | 24 ++---------------------- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/check/exam_paranoia.cpp b/check/exam_paranoia.cpp index ad7ee8d2..7be66fdf 100644 --- a/check/exam_paranoia.cpp +++ b/check/exam_paranoia.cpp @@ -440,16 +440,26 @@ static unsigned exam_paranoia17() } // Bug in add::eval() could result in numeric terms not being collected into -// the overall coefficient. Fixed on Sep 22, 2010 +// the overall coefficient. Fixed first on Sep 22, 2010 and again on Dec 17 2015 static unsigned exam_paranoia18() { + unsigned result = 0; + ex sqrt2 = sqrt(ex(2)); - ex e = 1+2*(sqrt2+1)*(sqrt2-1); - if ( e.real_part() != 3 ) { + ex e1 = 1 + 2*(sqrt2+1)*(sqrt2-1); + if (e1.real_part() != 3) { clog << "real_part(1+2*(sqrt(2)+1)*(sqrt(2)-1)) failed to evaluate to 3\n"; - return 1; + ++result; } - return 0; + + ex sqrt3 = sqrt(ex(3)); + ex e2 = 2 + 2*(sqrt2+1)*(sqrt2-1) - 2*(sqrt3+1)*(sqrt3-1); + if (e2.real_part() != 0) { + clog << "real_part(2+2*(sqrt(2)+1)*(sqrt(2)-1)-3*(sqrt(3)+1)*(sqrt(3)-1)) failed to evaluate to 0\n"; + ++result; + } + + return result; } // Bug in mul::conjugate when factors are evaluated at branch cuts, reported as diff --git a/ginac/add.cpp b/ginac/add.cpp index 79994e11..62c02d24 100644 --- a/ginac/add.cpp +++ b/ginac/add.cpp @@ -354,7 +354,7 @@ ex add::eval() const } #endif // def DO_GINAC_ASSERT - int seq_size = seq.size(); + size_t seq_size = seq.size(); if (seq_size == 0) { // +(;c) -> c return overall_coeff; @@ -364,27 +364,7 @@ ex add::eval() const } else if (!overall_coeff.is_zero() && seq[0].rest.return_type() != return_types::commutative) { throw (std::logic_error("add::eval(): sum of non-commutative objects has non-zero numeric term")); } - - // if any terms in the sum still are purely numeric, then they are more - // appropriately collected into the overall coefficient - int terms_to_collect = 0; - for (auto & it : seq) { - if (unlikely(is_a(it.rest))) - ++terms_to_collect; - } - if (terms_to_collect) { - epvector s; - s.reserve(seq_size - terms_to_collect); - numeric oc = *_num1_p; - for (auto & it : seq) { - if (unlikely(is_a(it.rest))) - oc = oc.mul(ex_to(it.rest)).mul(ex_to(it.coeff)); - else - s.push_back(it); - } - return dynallocate(std::move(s), ex_to(overall_coeff).add_dyn(oc)); - } - + return this->hold(); } -- 2.49.0