1 /** @file exam_sqrfree.cpp
6 * GiNaC Copyright (C) 1999-2021 Johannes Gutenberg University Mainz, Germany
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 using namespace GiNaC;
29 static unsigned exam_sqrfree1()
35 e1 = (1+x)*pow((2+x),2)*pow((3+x),3)*pow((4+x),4);
36 e2 = sqrfree(expand(e1), lst{x});
38 clog << "sqrfree(expand(" << e1 << ")) erroneously returned "
46 static unsigned exam_sqrfree2()
49 symbol x("x"), y("y");
52 e1 = (x+y)*pow((x+2*y),2)*pow((x+3*y),3)*pow((x+4*y),4);
53 e2 = sqrfree(expand(e1));
55 clog << "sqrfree(expand(" << e1 << ")) erroneously returned "
59 e2 = sqrfree(expand(e1), lst{x});
61 clog << "sqrfree(expand(" << e1 << "),[x]) erroneously returned "
65 e2 = sqrfree(expand(e1), lst{y});
67 clog << "sqrfree(expand(" << e1 << "),[y]) erroneously returned "
71 e2 = sqrfree(expand(e1), lst{x,y});
73 clog << "sqrfree(expand(" << e1 << "),[x,y]) erroneously returned "
81 static unsigned exam_sqrfree3()
84 symbol x("x"), y("y"), z("z");
87 e1 = (x+y)*pow(x, 2)*(-z-1);
88 e2 = sqrfree(expand(e1));
89 if (!expand(e1 - e2).is_zero()) {
90 clog << "sqrfree(expand(" << e1 << ")) erroneously returned "
95 e1 = (x+y)*pow(x, 3)*(-z-1);
96 e2 = sqrfree(expand(e1));
97 if (!expand(e1 - e2).is_zero()) {
98 clog << "sqrfree(expand(" << e1 << ")) erroneously returned "
106 // Bug in sqrfree_yun (fixed 2016-02-02).
107 static unsigned exam_hidden_zero1()
113 e = (x-1)*(x+1) - x*x + 1; // an unexpanded 0...
117 clog << "sqrfree(" << e << ") returns " << f << " instead of 0\n";
120 } catch (const exception &err) {
121 clog << "sqrfree(" << e << ") throws " << err.what() << endl;
125 e = pow(x-1,3) - expand(pow(x-1,3)); // ...still after differentiating...
129 clog << "sqrfree(" << e << ") returns " << f << " instead of 0\n";
132 } catch (const exception &err) {
133 clog << "sqrfree(" << e << ") throws " << err.what() << endl;
137 e = pow(x-1,4) - expand(pow(x-1,4)); // ...and after differentiating twice.
141 clog << "sqrfree(" << e << ") returns " << f << " instead of 0\n";
144 } catch (const exception &err) {
145 clog << "sqrfree(" << e << ") throws " << err.what() << endl;
152 static unsigned exam_hidden_zero2()
155 symbol x("x"), y("y");
158 e1 = (1 + 3*x + 3*pow(x,2) + pow(x,3) - pow(1+x,3)) * y;
161 clog << "sqrfree(" << e1 << ") erroneously returned "
166 e1 = (pow(x,2)-2*x*y+pow(y,2)-pow(x-y,2)) * x;
169 clog << "sqrfree(" << e1 << ") erroneously returned "
174 e1 = (pow(x,2)-2*x*y+pow(y,2)-pow(x-y,2)) * (x+y);
177 clog << "sqrfree(" << e1 << ") erroneously returned "
185 unsigned exam_sqrfree()
189 cout << "examining square-free factorization" << flush;
191 result += exam_sqrfree1(); cout << '.' << flush;
192 result += exam_sqrfree2(); cout << '.' << flush;
193 result += exam_sqrfree3(); cout << '.' << flush;
194 result += exam_hidden_zero1(); cout << '.' << flush;
195 result += exam_hidden_zero2(); cout << '.' << flush;
200 int main(int argc, char** argv)
202 return exam_sqrfree();