]> www.ginac.de Git - ginac.git/blob - check/heur_gcd_bug.cpp
Parser: handle abbreviations as advertized in the manual.
[ginac.git] / check / heur_gcd_bug.cpp
1 /** @file heur_gcd_bug.cpp
2  *
3  *  heur_gcd_oops.cpp Check for a bug in heur_gcd().
4  *
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. */
8
9 /*
10  *  GiNaC Copyright (C) 1999-2010 Johannes Gutenberg University Mainz, Germany
11  *
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.
16  *
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.
21  *
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
25  */
26
27 #include "ginac.h"
28 using namespace GiNaC;
29
30 #include <iostream>
31 using namespace std;
32
33 int main(int argc, char** argv)
34 {
35         cout << "checking if heur_gcd() can cope with rational polynomials. ";
36         const symbol x("x");
37         const ex _ex1(1);
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
42         
43         // a2 divides b, so cofactor of a2 should be a (rational) number
44         ex ca2, cb2;
45         ex g2 = gcd(a2, b, &ca2, &cb2);
46         if (!is_a<numeric>(ca2)) {
47                 cerr << "gcd(" << a2 << ", " << b << ") was miscomputed" << endl;
48                 return 1;
49         }
50         ex ca1, cb1;
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;
55                 return 1;
56         }
57         return 0;
58 }