]> www.ginac.de Git - ginac.git/commitdiff
Fix elusive bug in expairseq ctor.
authorRichard Kreckel <kreckel@ginac.de>
Sat, 16 Feb 2019 11:58:38 +0000 (12:58 +0100)
committerRichard Kreckel <kreckel@ginac.de>
Sat, 16 Feb 2019 11:58:38 +0000 (12:58 +0100)
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
ginac/expairseq.cpp

index c5f5514959a81d002691b571ebfd2ed32c77ef3c..b5f1260816be3cd2c2249d919a56d56d8ebf5126 100644 (file)
@@ -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;
 }
index 56f9ad10dff366e16b6545bfc7c4a1e27e51d62b..a1361532fc9994c7c920560f3893bca469aea286 100644 (file)
@@ -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<numeric>(it->rest) &&
+           it->coeff.is_equal(_ex1)) {
+               // the pair {<n>, 1} has yet to be absorbed into overall_coeff
+               return true;
+       }
        return false;
 }