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.
}
// Bug in add::eval() could result in numeric terms not being collected into
}
// 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()
{
static unsigned exam_paranoia18()
{
- 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";
clog << "real_part(1+2*(sqrt(2)+1)*(sqrt(2)-1)) failed to evaluate to 3\n";
+
+ 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
}
// Bug in mul::conjugate when factors are evaluated at branch cuts, reported as
}
#endif // def DO_GINAC_ASSERT
}
#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;
if (seq_size == 0) {
// +(;c) -> c
return overall_coeff;
} 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"));
}
} 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<numeric>(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<numeric>(it.rest)))
- oc = oc.mul(ex_to<numeric>(it.rest)).mul(ex_to<numeric>(it.coeff));
- else
- s.push_back(it);
- }
- return dynallocate<add>(std::move(s), ex_to<numeric>(overall_coeff).add_dyn(oc));
- }
-