1 /** @file heur_gcd_bug.cpp
3 * heur_gcd_oops.cpp Check for a bug in heur_gcd().
5 * heur_gcd() did not check if the arguments are integer polynomials
6 * (and did not convert them to integer polynomials), which lead to
7 * endless loop or (even worse) wrong result. */
10 * GiNaC Copyright (C) 1999-2018 Johannes Gutenberg University Mainz, Germany
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 using namespace GiNaC;
33 int main(int argc, char** argv)
35 cout << "checking if heur_gcd() can cope with rational polynomials. ";
38 ex a1 = x + numeric(5, 4);
39 ex a2 = x + numeric(5, 2);
40 ex b = pow(x, 2) + numeric(15, 4)*x + numeric(25, 8);
41 // note: both a1 and a2 divide b
43 // a2 divides b, so cofactor of a2 should be a (rational) number
45 ex g2 = gcd(a2, b, &ca2, &cb2);
46 if (!is_a<numeric>(ca2)) {
47 cerr << "gcd(" << a2 << ", " << b << ") was miscomputed" << endl;
51 // a1 divides b, so cofactor of a1 should be a (rational) number
52 ex g1 = gcd(a1, b, &ca1, &cb1);
53 if (!is_a<numeric>(ca1)) {
54 cerr << "gcd(" << a1 << ", " << b << ") was miscomputed" << endl;