1 /** @file normalization.cpp
3 * Rational function normalization test suite. */
6 * GiNaC Copyright (C) 1999-2000 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #ifndef NO_NAMESPACE_GINAC
26 using namespace GiNaC;
27 #endif // ndef NO_NAMESPACE_GINAC
29 static symbol w("w"), x("x"), y("y"), z("z");
31 static unsigned check_normal(const ex &e, const ex &d)
34 if (en.compare(d) != 0) {
35 clog << "normal form of " << e << " erroneously returned "
36 << en << " (should be " << d << ")" << endl;
42 static unsigned normal1(void)
48 e = pow(x, 2) - (x+1)*(x-1) - 1;
50 result += check_normal(e, d);
52 // Expansion inside functions
53 e = sin(x*(x+1)-x) + 1;
54 d = sin(pow(x, 2)) + 1;
55 result += check_normal(e, d);
59 d = (x*y + 6) / (x*3);
60 result += check_normal(e, d);
62 e = pow(x, -1) + x/(x+1);
63 d = (pow(x, 2)+x+1)/(x*(x+1));
64 result += check_normal(e, d);
66 // Fraction cancellation
67 e = numeric(1)/2 * z * (2*x + 2*y);
69 result += check_normal(e, d);
71 e = numeric(1)/6 * z * (3*x + 3*y) * (2*x + 2*w);
72 d = z * (x + y) * (x + w);
73 result += check_normal(e, d);
75 e = (3*x + 3*y) * (w/3 + z/3);
76 d = (x + y) * (w + z);
77 result += check_normal(e, d);
79 e = (pow(x, 2) - pow(y, 2)) / pow(x-y, 3);
80 d = (x + y) / (pow(x, 2) + pow(y, 2) - x * y * 2);
81 result += check_normal(e, d);
83 e = (pow(x, -1) + x) / (pow(x , 2) * 2 + 2);
85 result += check_normal(e, d);
87 // Fraction cancellation with rational coefficients
88 e = (pow(x, 2) - pow(y, 2)) / pow(x/2 - y/2, 3);
89 d = (8 * x + 8 * y) / (pow(x, 2) + pow(y, 2) - x * y * 2);
90 result += check_normal(e, d);
92 // Fraction cancellation with rational coefficients
93 e = z/5 * (x/7 + y/10) / (x/14 + y/20);
95 result += check_normal(e, d);
97 // Distribution of powers
99 d = pow(x, 2) / pow(y, 2);
100 result += check_normal(e, d);
102 // Distribution of powers (integer, distribute) and fraction addition
103 e = pow(pow(x, -1) + x, 2);
104 d = pow(pow(x, 2) + 1, 2) / pow(x, 2);
105 result += check_normal(e, d);
107 // Distribution of powers (non-integer, don't distribute) and fraction addition
108 e = pow(pow(x, -1) + x, numeric(1)/2);
109 d = pow((pow(x, 2) + 1) / x, numeric(1)/2);
110 result += check_normal(e, d);
112 // Replacement of functions with temporary symbols and fraction cancellation
113 e = pow(sin(x), 2) - pow(cos(x), 2);
114 e /= sin(x) + cos(x);
116 result += check_normal(e, d);
118 // Replacement of non-integer powers with temporary symbols
119 e = (pow(numeric(2), numeric(1)/2) * x + x) / x;
120 d = pow(numeric(2), numeric(1)/2) + 1;
121 result += check_normal(e, d);
123 // Replacement of complex numbers with temporary symbols
124 e = (x + y + x*I + y*I) / (x + y);
126 result += check_normal(e, d);
128 e = (pow(x, 2) + pow(y, 2)) / (x + y*I);
130 result += check_normal(e, d);
132 // More complex rational function
133 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);
134 d = (y*2 + z*2) / (x + y*2);
135 result += check_normal(e, d);
140 unsigned normalization(void)
144 cout << "checking rational function normalization..." << flush;
145 clog << "---------rational function normalization:" << endl;
151 clog << "(no output)" << endl;