]> www.ginac.de Git - ginac.git/commitdiff
Segregate sqfree() tests into file of its own.
authorRichard Kreckel <kreckel@ginac.de>
Fri, 21 Aug 2020 15:45:08 +0000 (17:45 +0200)
committerRichard Kreckel <kreckel@ginac.de>
Fri, 21 Aug 2020 15:45:08 +0000 (17:45 +0200)
check/.gitignore
check/CMakeLists.txt
check/Makefile.am
check/exam_misc.cpp
check/exam_paranoia.cpp
check/exam_sqrfree.cpp [new file with mode: 0644]

index 283496f6711ad4817f1a4555244ce31747046778..341eaf9c675eca0072e9332c3b6e6b201dd486b8 100644 (file)
@@ -5,7 +5,6 @@ bugme_chinrem_gcd
 check_inifcns
 check_lsolve
 check_matrices
-check_mul_info
 check_numeric
 exam.gar
 exam_archive
@@ -23,6 +22,7 @@ exam_matrices
 exam_misc
 exam_mod_gcd
 exam_normalization
+exam_sqrfree
 exam_numeric
 exam_numeric_archive
 exam_paranoia
@@ -31,7 +31,6 @@ exam_powerlaws
 exam_pseries
 exam_real_imag
 exam_structure
-factor_univariate_bug
 match_bug
 parser_bugs
 pgcd_infinite_loop
index bd6b76049540efac9837dccec8c203c871a0b001..82e78e184c551ce8f149fb510d382fa113363504 100644 (file)
@@ -20,6 +20,7 @@ set(ginac_tests
        exam_polygcd
        exam_collect_common_factors
        exam_normalization
+       exam_sqrfree
        exam_factor
        exam_pseries
        exam_matrices
index 5f1d02e2590228aeeff29ae8327121667d8db178..1fffd9f77ef1df9710bdc15c76992e650ddddb3b 100644 (file)
@@ -18,6 +18,7 @@ EXAMS = exam_paranoia \
        exam_polygcd  \
        exam_collect_common_factors \
        exam_normalization  \
+       exam_sqrfree  \
        exam_factor \
        exam_pseries  \
        exam_matrices  \
@@ -116,6 +117,9 @@ exam_collect_common_factors_LDADD = ../ginac/libginac.la
 exam_normalization_SOURCES = exam_normalization.cpp
 exam_normalization_LDADD = ../ginac/libginac.la
 
+exam_sqrfree_SOURCES = exam_sqrfree.cpp
+exam_sqrfree_LDADD = ../ginac/libginac.la
+
 exam_factor_SOURCES = exam_factor.cpp
 exam_factor_LDADD = ../ginac/libginac.la
 
index 73cde37a3e65128cabed8189c7e4cceba029596b..93b6f8e7d2de414eefb707babcb54b1ef6960c0f 100644 (file)
@@ -89,49 +89,6 @@ static unsigned exam_expand_power()
        return result;
 }
 
-static unsigned exam_sqrfree()
-{
-       unsigned result = 0;
-       symbol x("x"), y("y");
-       ex e1, e2;
-       
-       e1 = (1+x)*pow((2+x),2)*pow((3+x),3)*pow((4+x),4);
-       e2 = sqrfree(expand(e1),lst{x});
-       if (e1 != e2) {
-               clog << "sqrfree(expand(" << e1 << ")) erroneously returned "
-                    << e2 << endl;
-               ++result;
-       }
-       
-       e1 = (x+y)*pow((x+2*y),2)*pow((x+3*y),3)*pow((x+4*y),4);
-       e2 = sqrfree(expand(e1));
-       if (e1 != e2) {
-               clog << "sqrfree(expand(" << e1 << ")) erroneously returned "
-                    << e2 << endl;
-               ++result;
-       }
-       e2 = sqrfree(expand(e1),lst{x});
-       if (e1 != e2) {
-               clog << "sqrfree(expand(" << e1 << "),[x]) erroneously returned "
-                    << e2 << endl;
-               ++result;
-       }
-       e2 = sqrfree(expand(e1),lst{y});
-       if (e1 != e2) {
-               clog << "sqrfree(expand(" << e1 << "),[y]) erroneously returned "
-                    << e2 << endl;
-               ++result;
-       }
-       e2 = sqrfree(expand(e1),lst{x,y});
-       if (e1 != e2) {
-               clog << "sqrfree(expand(" << e1 << "),[x,y]) erroneously returned "
-                    << e2 << endl;
-               ++result;
-       }
-       
-       return result;
-}
-
 /* Arithmetic Operators should behave just as one expects from built-in types.
  * When somebody screws up the operators this routine will most probably fail
  * to compile.  Unfortunately we can only test the stuff that is allowed, not
@@ -307,7 +264,6 @@ unsigned exam_misc()
        result += exam_expand_subs();  cout << '.' << flush;
        result += exam_expand_subs2();  cout << '.' << flush;
        result += exam_expand_power(); cout << '.' << flush;
-       result += exam_sqrfree(); cout << '.' << flush;
        result += exam_operator_semantics(); cout << '.' << flush;
        result += exam_subs(); cout << '.' << flush;
        result += exam_joris(); cout << '.' << flush;
index 7977bd2e88f5440990f2c4b389237f726a0cb1f3..c53bb7a43231ef1ccc56b34210eb8403d418d08c 100644 (file)
@@ -588,54 +588,8 @@ static unsigned exam_paranoia23()
        return result;
 }
 
-// Bug in sqrfree_yun (fixed 2016-02-02).
-static unsigned exam_paranoia24()
-{
-       unsigned result = 0;
-       symbol x("x");
-       ex e;
-
-       e = (x-1)*(x+1) - x*x + 1;  // an unexpanded 0...
-       try {
-               ex f = sqrfree(e);
-               if (!f.is_zero()) {
-                       clog << "sqrfree(" << e << ") returns " << f << " instead of 0\n";
-                       ++result;
-               }
-       } catch (const exception &err) {
-               clog << "sqrfree(" << e << ") throws " << err.what() << endl;
-               ++result;
-       }
-
-       e = pow(x-1,3) - expand(pow(x-1,3));  // ...still after differentiating...
-       try {
-               ex f = sqrfree(e);
-               if (!f.is_zero()) {
-                       clog << "sqrfree(" << e << ") returns " << f << " instead of 0\n";
-                       ++result;
-               }
-       } catch (const exception &err) {
-               clog << "sqrfree(" << e << ") throws " << err.what() << endl;
-               ++result;
-       }
-
-       e = pow(x-1,4) - expand(pow(x-1,4));  // ...and after differentiating twice.
-       try {
-               ex f = sqrfree(e);
-               if (!f.is_zero()) {
-                       clog << "sqrfree(" << e << ") returns " << f << " instead of 0\n";
-                       ++result;
-               }
-       } catch (const exception &err) {
-               clog << "sqrfree(" << e << ") throws " << err.what() << endl;
-               ++result;
-       }
-
-       return result;
-}
-
 // Bug in add ctor
-unsigned exam_paranoia25()
+unsigned exam_paranoia24()
 {
        symbol a("a"), b("b"), c("c");
        ex e = -a + 2*b + c;
@@ -648,7 +602,7 @@ unsigned exam_paranoia25()
 }
 
 // Bug in partial fraction expansion
-unsigned exam_paranoia26()
+unsigned exam_paranoia25()
 {
        symbol x("x");
        ex ex1=pow(x,4)/(x-1)/4;
@@ -663,7 +617,7 @@ unsigned exam_paranoia26()
 }
 
 // Bug in power expansion
-unsigned exam_paranoia27()
+unsigned exam_paranoia26()
 {
        unsigned result = 0;
        symbol x("x"), y("y"), a("a");
@@ -718,7 +672,6 @@ unsigned exam_paranoia()
        result += exam_paranoia24();  cout << '.' << flush;
        result += exam_paranoia25();  cout << '.' << flush;
        result += exam_paranoia26();  cout << '.' << flush;
-       result += exam_paranoia27();  cout << '.' << flush;
        
        return result;
 }
diff --git a/check/exam_sqrfree.cpp b/check/exam_sqrfree.cpp
new file mode 100644 (file)
index 0000000..237ea52
--- /dev/null
@@ -0,0 +1,203 @@
+/** @file exam_sqrfree.cpp
+ *
+ */
+
+/*
+ *  GiNaC Copyright (C) 1999-2020 Johannes Gutenberg University Mainz, Germany
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "ginac.h"
+using namespace GiNaC;
+
+#include <iostream>
+using namespace std;
+
+static unsigned exam_sqrfree1()
+{
+       unsigned result = 0;
+       symbol x("x");
+       ex e1, e2;
+
+       e1 = (1+x)*pow((2+x),2)*pow((3+x),3)*pow((4+x),4);
+       e2 = sqrfree(expand(e1), lst{x});
+       if (e1 != e2) {
+               clog << "sqrfree(expand(" << e1 << ")) erroneously returned "
+                    << e2 << endl;
+               ++result;
+       }
+
+       return result;
+}
+
+static unsigned exam_sqrfree2()
+{
+       unsigned result = 0;
+       symbol x("x"), y("y");
+       ex e1, e2;
+
+       e1 = (x+y)*pow((x+2*y),2)*pow((x+3*y),3)*pow((x+4*y),4);
+       e2 = sqrfree(expand(e1));
+       if (e1 != e2) {
+               clog << "sqrfree(expand(" << e1 << ")) erroneously returned "
+                    << e2 << endl;
+               ++result;
+       }
+       e2 = sqrfree(expand(e1), lst{x});
+       if (e1 != e2) {
+               clog << "sqrfree(expand(" << e1 << "),[x]) erroneously returned "
+                    << e2 << endl;
+               ++result;
+       }
+       e2 = sqrfree(expand(e1), lst{y});
+       if (e1 != e2) {
+               clog << "sqrfree(expand(" << e1 << "),[y]) erroneously returned "
+                    << e2 << endl;
+               ++result;
+       }
+       e2 = sqrfree(expand(e1), lst{x,y});
+       if (e1 != e2) {
+               clog << "sqrfree(expand(" << e1 << "),[x,y]) erroneously returned "
+                    << e2 << endl;
+               ++result;
+       }
+
+       return result;
+}
+
+static unsigned exam_sqrfree3()
+{
+       unsigned result = 0;
+       symbol x("x"), y("y"), z("z");
+       ex e1, e2;
+
+       e1 = (x+y)*pow(x, 2)*(-z-1);
+       e2 = sqrfree(expand(e1));
+       if (!expand(e1 - e2).is_zero()) {
+               clog << "sqrfree(expand(" << e1 << ")) erroneously returned "
+                    << e2 << endl;
+               ++result;
+       }
+
+       e1 = (x+y)*pow(x, 3)*(-z-1);
+       e2 = sqrfree(expand(e1));
+       if (!expand(e1 - e2).is_zero()) {
+               clog << "sqrfree(expand(" << e1 << ")) erroneously returned "
+                    << e2 << endl;
+               ++result;
+       }
+
+       return result;
+}
+
+// Bug in sqrfree_yun (fixed 2016-02-02).
+static unsigned exam_hidden_zero1()
+{
+       unsigned result = 0;
+       symbol x("x");
+       ex e;
+
+       e = (x-1)*(x+1) - x*x + 1;  // an unexpanded 0...
+       try {
+                ex f = sqrfree(e);
+                if (!f.is_zero()) {
+                        clog << "sqrfree(" << e << ") returns " << f << " instead of 0\n";
+                        ++result;
+                }
+        } catch (const exception &err) {
+                clog << "sqrfree(" << e << ") throws " << err.what() << endl;
+                ++result;
+        }
+
+       e = pow(x-1,3) - expand(pow(x-1,3));  // ...still after differentiating...
+       try {
+                ex f = sqrfree(e);
+                if (!f.is_zero()) {
+                        clog << "sqrfree(" << e << ") returns " << f << " instead of 0\n";
+                        ++result;
+                }
+        } catch (const exception &err) {
+                clog << "sqrfree(" << e << ") throws " << err.what() << endl;
+                ++result;
+        }
+
+       e = pow(x-1,4) - expand(pow(x-1,4));  // ...and after differentiating twice.
+       try {
+                ex f = sqrfree(e);
+                if (!f.is_zero()) {
+                        clog << "sqrfree(" << e << ") returns " << f << " instead of 0\n";
+                        ++result;
+                }
+        } catch (const exception &err) {
+                clog << "sqrfree(" << e << ") throws " << err.what() << endl;
+                ++result;
+        }
+
+       return result;
+}
+
+static unsigned exam_hidden_zero2()
+{
+       unsigned result = 0;
+       symbol x("x"), y("y");
+       ex e1, e2;
+
+       e1 = (1 + 3*x + 3*pow(x,2) + pow(x,3) - pow(1+x,3)) * y;
+       e2 = sqrfree(e1);
+       if (!e2.is_zero()) {
+               clog << "sqrfree(" << e1 << ") erroneously returned "
+                    << e2 << endl;
+               ++result;
+       }
+
+       e1 = (pow(x,2)-2*x*y+pow(y,2)-pow(x-y,2)) * x;
+       e2 = sqrfree(e1);
+       if (!e2.is_zero()) {
+               clog << "sqrfree(" << e1 << ") erroneously returned "
+                    << e2 << endl;
+               ++result;
+       }
+
+       e1 = (pow(x,2)-2*x*y+pow(y,2)-pow(x-y,2)) * (x+y);
+       e2 = sqrfree(e1);
+       if (!e2.is_zero()) {
+               clog << "sqrfree(" << e1 << ") erroneously returned "
+                    << e2 << endl;
+               ++result;
+       }
+
+       return result;
+}
+
+unsigned exam_sqrfree()
+{
+       unsigned result = 0;
+
+       cout << "examining square-free factorization" << flush;
+
+       result += exam_sqrfree1();  cout << '.' << flush;
+       result += exam_sqrfree2();  cout << '.' << flush;
+       result += exam_sqrfree3();  cout << '.' << flush;
+       result += exam_hidden_zero1();  cout << '.' << flush;
+       result += exam_hidden_zero2();  cout << '.' << flush;
+
+       return result;
+}
+
+int main(int argc, char** argv)
+{
+       return exam_sqrfree();
+}