]> www.ginac.de Git - ginac.git/blob - check/heur_gcd_bug.cpp
symbol: get rid of assign/unassign (for performance and other reasons).
[ginac.git] / check / heur_gcd_bug.cpp
1 /**
2  * @file heur_gcd_oops.cpp Check for a bug in heur_gcd().
3  *
4  * heur_gcd() did not check if the arguments are integer polynomials
5  * (and did not convert them to integer polynomials), which lead to
6  * endless loop or (even worse) wrong result.
7  */
8 #include <iostream>
9 #include "ginac.h"
10 using namespace GiNaC;
11 using namespace std;
12
13 int main(int argc, char** argv)
14 {
15         cout << "checking if heur_gcd() can cope with rational polynomials. ";
16         const symbol x("x");
17         const ex _ex1(1);
18         ex a1 = x + numeric(5, 4);
19         ex a2 = x + numeric(5, 2);
20         ex b =  pow(x, 2) + numeric(15, 4)*x + numeric(25, 8);
21         // note: both a1 and a2 divide b
22         
23         // a2 divides b, so cofactor of a2 should be a (rational) number
24         ex ca2, cb2;
25         ex g2 = gcd(a2, b, &ca2, &cb2);
26         if (!is_a<numeric>(ca2)) {
27                 cerr << "gcd(" << a2 << ", " << b << ") was miscomputed" << endl;
28                 return 1;
29         }
30         ex ca1, cb1;
31         // a1 divides b, so cofactor of a1 should be a (rational) number
32         ex g1 = gcd(a1, b, &ca1, &cb1);
33         if (!is_a<numeric>(ca1)) {
34                 cerr << "gcd(" << a1 << ", " << b << ") was miscomputed" << endl;
35                 return 1;
36         }
37         return 0;
38 }
39