1 // check/normalization.cpp
3 /* Rational function normalization test-suite. */
5 #include <ginac/ginac.h>
7 static symbol x("x"), y("y"), z("z");
9 static unsigned check_normal(const ex &e, const ex &d)
12 if (en.compare(d) != 0) {
13 clog << "normal form of " << e << " is " << en << " (should be " << d << ")" << endl;
19 static unsigned normal1(void)
25 e = pow(x, 2) - (x+1)*(x-1) - 1;
27 result += check_normal(e, d);
29 // Expansion inside functions
30 e = sin(x*(x+1)-x) + 1;
31 d = sin(pow(x, 2)) + 1;
32 result += check_normal(e, d);
35 e = numeric(2)/x + y/3;
37 result += check_normal(e, d);
40 e = pow(x, -1) + x/(x+1);
41 d = (pow(x, 2)+x+1)/(x*(x+1));
42 result += check_normal(e, d);
44 // Fraction cancellation
45 e = (pow(x, 2) - pow(y, 2)) / pow(x-y, 3);
46 d = (x + y) / (pow(x, 2) + pow(y, 2) - x * y * 2);
47 result += check_normal(e, d);
49 // Fraction cancellation
50 e = (pow(x, -1) + x) / (pow(x , 2) * 2 + 2);
52 result += check_normal(e, d);
54 // Distribution of powers
56 d = pow(x, 2) / pow(y, 2);
57 result += check_normal(e, d);
59 // Distribution of powers (integer, distribute) and fraction addition
60 e = pow(pow(x, -1) + x, 2);
61 d = pow(pow(x, 2) + 1, 2) / pow(x, 2);
62 result += check_normal(e, d);
64 // Distribution of powers (non-integer, don't distribute) and fraction addition
65 e = pow(pow(x, -1) + x, numeric(1)/2);
66 d = pow((pow(x, 2) + 1) / x, numeric(1)/2);
67 result += check_normal(e, d);
69 // Replacement of functions with temporary symbols and fraction cancellation
70 e = pow(sin(x), 2) - pow(cos(x), 2);
73 result += check_normal(e, d);
75 // Replacement of non-integer powers with temporary symbols
76 e = (pow(numeric(2), numeric(1)/2) * x + x) / x;
77 d = pow(numeric(2), numeric(1)/2) + 1;
78 result += check_normal(e, d);
80 // Replacement of complex numbers with temporary symbols
81 e = (x + y + x*I + y*I) / (x + y);
83 result += check_normal(e, d);
85 e = (pow(x, 2) + pow(y, 2)) / (x + y*I);
87 result += check_normal(e, d);
89 // More complex rational function
90 e = (pow(x-y*2,4)/pow(pow(x,2)-pow(y,2)*4,2)+1)*(x+y*2)*(y+z)/(pow(x,2)+pow(y,2)*4);
91 d = (y*2 + z*2) / (x + y*2);
92 result += check_normal(e, d);
97 unsigned normalization(void)
101 cout << "checking rational function normalization..." << flush;
102 clog << "---------rational function normalization:" << endl;
108 clog << "(no output)" << endl;