]> www.ginac.de Git - ginac.git/blobdiff - check/paranoia_check.cpp
- added check for latest normal() bug
[ginac.git] / check / paranoia_check.cpp
index c5f3557337c003ae636ee4a132a72c673cf1ec76..125fb7339ed904a66470fb121028243e7c713316 100644 (file)
@@ -85,7 +85,8 @@ static unsigned paranoia_check2(void)
              << g.eval() << endl;
         ++result;
     }
-    // This actually worked already back in April 1999.  But we are very paranoic!
+    // This actually worked already back in April 1999.
+    // But we are *very* paranoic!
     if (!g.expand().eval().is_zero()) {
         clog << "e = (x + z*x); f = e*y; eval(expand(f - e*y)) erroneously returned "
              << g.expand().eval() << endl;
@@ -215,12 +216,16 @@ static unsigned paranoia_check8(void)
     symbol x("x");
 
     ex e = -x / (x+1);
-    ex f = e.normal();
-
-    // The bug caused a division by zero in normal(), so the following
-    // check is actually quite bogus...
-    if (!f.is_equal(e)) {
-        clog << "normal(-x/(x+1)) returns " << f << " instead of -x/(x+1)\n";
+    ex f;
+    
+    try {
+        f = e.normal();
+        if (!f.is_equal(e)) {
+            clog << "normal(-x/(x+1)) returns " << f << " instead of -x/(x+1)\n";
+            ++result;
+        }
+    } catch (const exception &e) {
+        clog << "normal(-x/(x+1) throws " << e.what() << endl;
         ++result;
     }
     return result;
@@ -271,6 +276,26 @@ static unsigned paranoia_check10(void)
     return result;
 }
 
+// After the rewriting of basic::normal() & Co. to return {num, den} lists,
+// add::normal() forgot to multiply the denominator of the overall_coeff of
+// its expanded and normalized children with the denominator of the expanded
+// child (did you get this? Well, never mind...). Fixed on Feb 21th 2000.
+static unsigned paranoia_check11(void)
+{
+    unsigned result = 0;
+       symbol x("x");
+
+       ex e = ((-5-2*x)-((2-5*x)/(-2+x))*(3+2*x))/(5-4*x);
+       ex f = e.normal();
+       ex d = (4+10*x+8*pow(x,2))/(x-2)/(5-4*x);
+
+       if (!(f - d).expand().is_zero()) {
+               clog << "normal(" << e << ") returns " << f << " instead of " << d << endl;
+               ++result;
+       }
+    return result;
+}
+
 unsigned paranoia_check(void)
 {
     unsigned result = 0;
@@ -288,6 +313,7 @@ unsigned paranoia_check(void)
     result += paranoia_check8();
     result += paranoia_check9();
     result += paranoia_check10();
+    result += paranoia_check11();
 
     if (!result) {
         cout << " passed ";