]> www.ginac.de Git - ginac.git/commitdiff
Remove useless code in add::eval().
authorRichard Kreckel <kreckel@ginac.de>
Thu, 17 Dec 2015 21:45:50 +0000 (22:45 +0100)
committerRichard Kreckel <kreckel@ginac.de>
Thu, 17 Dec 2015 21:45:50 +0000 (22:45 +0100)
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
ginac/add.cpp

index ad7ee8d25facc53da8d7022113da134c3f8cb986..7be66fdfd8a9ebdb13bbd37618670ecb9779524a 100644 (file)
@@ -440,16 +440,26 @@ static unsigned exam_paranoia17()
 }
 
 // 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()
 {
+       unsigned result = 0;
+
        ex sqrt2 = sqrt(ex(2));
        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";
                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
 }
 
 // Bug in mul::conjugate when factors are evaluated at branch cuts, reported as
index 79994e11c5ddf47e54b84daf883b014b1f1410a4..62c02d2432aaeface643b1b4330ae564acf2a3fd 100644 (file)
@@ -354,7 +354,7 @@ ex add::eval() const
        }
 #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;
@@ -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"));
        }
        } 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));
-       }
-       
+
        return this->hold();
 }
 
        return this->hold();
 }