From: Richard Kreckel Date: Fri, 21 Aug 2020 15:45:08 +0000 (+0200) Subject: Segregate sqfree() tests into file of its own. X-Git-Tag: release_1-8-0~27 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=9e79f663bc37462a414ed1e41158b34e115b3ab5;ds=sidebyside Segregate sqfree() tests into file of its own. --- diff --git a/check/.gitignore b/check/.gitignore index 283496f6..341eaf9c 100644 --- a/check/.gitignore +++ b/check/.gitignore @@ -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 diff --git a/check/CMakeLists.txt b/check/CMakeLists.txt index bd6b7604..82e78e18 100644 --- a/check/CMakeLists.txt +++ b/check/CMakeLists.txt @@ -20,6 +20,7 @@ set(ginac_tests exam_polygcd exam_collect_common_factors exam_normalization + exam_sqrfree exam_factor exam_pseries exam_matrices diff --git a/check/Makefile.am b/check/Makefile.am index 5f1d02e2..1fffd9f7 100644 --- a/check/Makefile.am +++ b/check/Makefile.am @@ -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 diff --git a/check/exam_misc.cpp b/check/exam_misc.cpp index 73cde37a..93b6f8e7 100644 --- a/check/exam_misc.cpp +++ b/check/exam_misc.cpp @@ -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; diff --git a/check/exam_paranoia.cpp b/check/exam_paranoia.cpp index 7977bd2e..c53bb7a4 100644 --- a/check/exam_paranoia.cpp +++ b/check/exam_paranoia.cpp @@ -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 index 00000000..237ea52b --- /dev/null +++ b/check/exam_sqrfree.cpp @@ -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 +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(); +}