From 3ea59519b3fa572a2aba7b8540b336dcb2924262 Mon Sep 17 00:00:00 2001 From: Richard Kreckel Date: Sat, 16 Feb 2019 12:58:38 +0100 Subject: [PATCH] Fix elusive bug in expairseq ctor. When an expair turns out to represent a number, that should go into the expairseq's overall_coeff. This was accomplished by class mul, thanks to the override of expair_needs_further_processing(), but not always for class add. This patch fixes the base class' expair_needs_further_processing() with similar logic as that already in place for class mul. Thanks to Mario Prausa for reporting this. --- check/exam_paranoia.cpp | 14 ++++++++++++++ ginac/expairseq.cpp | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/check/exam_paranoia.cpp b/check/exam_paranoia.cpp index c5f55149..b5f12608 100644 --- a/check/exam_paranoia.cpp +++ b/check/exam_paranoia.cpp @@ -623,6 +623,19 @@ static unsigned exam_paranoia24() return result; } +// Bug in add ctor +unsigned exam_paranoia25() +{ + symbol a("a"), b("b"), c("c"); + ex e = -a + 2*b + c; + + if (e.diff(c).nops() > 1) { + clog << "diff(" << e << ",c) was not fully evaluated.\n"; + return 1; + } + return 0; +} + unsigned exam_paranoia() { unsigned result = 0; @@ -654,6 +667,7 @@ unsigned exam_paranoia() result += exam_paranoia22(); cout << '.' << flush; result += exam_paranoia23(); cout << '.' << flush; result += exam_paranoia24(); cout << '.' << flush; + result += exam_paranoia25(); cout << '.' << flush; return result; } diff --git a/ginac/expairseq.cpp b/ginac/expairseq.cpp index 56f9ad10..a1361532 100644 --- a/ginac/expairseq.cpp +++ b/ginac/expairseq.cpp @@ -565,6 +565,11 @@ ex expairseq::recombine_pair_to_ex(const expair &p) const bool expairseq::expair_needs_further_processing(epp it) { + if (is_exactly_a(it->rest) && + it->coeff.is_equal(_ex1)) { + // the pair {, 1} has yet to be absorbed into overall_coeff + return true; + } return false; } -- 2.44.0