1 /** @file inifcns_consist.cpp
3 * This test routine applies assorted tests on initially known higher level
7 * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <ginac/ginac.h>
26 #ifndef NO_GINAC_NAMESPACE
27 using namespace GiNaC;
28 #endif // ndef NO_GINAC_NAMESPACE
30 /* Simple tests on the sine trigonometric function. */
31 static unsigned inifcns_consist_sin(void)
38 for (int n=-10; n<=10; ++n) {
39 if ( sin(n*Pi).eval() != numeric(0) ||
40 !sin(n*Pi).eval().info(info_flags::integer))
44 clog << "sin(n*Pi) with integer n does not always return exact 0"
49 // sin((n+1/2)*Pi) == {+|-}1?
51 for (int n=-10; n<=10; ++n) {
52 if (! sin((n+numeric(1,2))*Pi).eval().info(info_flags::integer) ||
53 !(sin((n+numeric(1,2))*Pi).eval() == numeric(1) ||
54 sin((n+numeric(1,2))*Pi).eval() == numeric(-1)))
58 clog << "sin((n+1/2)*Pi) with integer n does not always return exact {+|-}1"
66 /* Simple tests on the cosine trigonometric function. */
67 static unsigned inifcns_consist_cos(void)
72 // cos((n+1/2)*Pi) == 0?
74 for (int n=-10; n<=10; ++n) {
75 if ( cos((n+numeric(1,2))*Pi).eval() != numeric(0) ||
76 !cos((n+numeric(1,2))*Pi).eval().info(info_flags::integer))
80 clog << "cos((n+1/2)*Pi) with integer n does not always return exact 0"
87 for (int n=-10; n<=10; ++n) {
88 if (! cos(n*Pi).eval().info(info_flags::integer) ||
89 !(cos(n*Pi).eval() == numeric(1) ||
90 cos(n*Pi).eval() == numeric(-1)))
94 clog << "cos(n*Pi) with integer n does not always return exact {+|-}1"
102 /* Assorted tests on other transcendental functions. */
103 static unsigned inifcns_consist_trans(void)
109 chk = asin(1)-acos(0);
110 if (!chk.is_zero()) {
111 clog << "asin(1)-acos(0) erroneously returned " << chk
112 << " instead of 0" << endl;
116 // arbitrary check of type sin(f(x)):
117 chk = pow(sin(acos(x)),2) + pow(sin(asin(x)),2)
118 - (1+pow(x,2))*pow(sin(atan(x)),2);
119 if (chk != 1-pow(x,2)) {
120 clog << "sin(acos(x))^2 + sin(asin(x))^2 - (1+x^2)*sin(atan(x))^2 "
121 << "erroneously returned " << chk << " instead of 1-x^2" << endl;
125 // arbitrary check of type cos(f(x)):
126 chk = pow(cos(acos(x)),2) + pow(cos(asin(x)),2)
127 - (1+pow(x,2))*pow(cos(atan(x)),2);
128 if (!chk.is_zero()) {
129 clog << "cos(acos(x))^2 + cos(asin(x))^2 - (1+x^2)*cos(atan(x))^2 "
130 << "erroneously returned " << chk << " instead of 0" << endl;
134 // arbitrary check of type tan(f(x)):
135 chk = tan(acos(x))*tan(asin(x)) - tan(atan(x));
137 clog << "tan(acos(x))*tan(asin(x)) - tan(atan(x)) "
138 << "erroneously returned " << chk << " instead of -x+1" << endl;
142 // arbitrary check of type sinh(f(x)):
143 chk = -pow(sinh(acosh(x)),2).expand()*pow(sinh(atanh(x)),2)
144 - pow(sinh(asinh(x)),2);
145 if (!chk.is_zero()) {
146 clog << "expand(-(sinh(acosh(x)))^2)*(sinh(atanh(x))^2) - sinh(asinh(x))^2 "
147 << "erroneously returned " << chk << " instead of 0" << endl;
151 // arbitrary check of type cosh(f(x)):
152 chk = (pow(cosh(asinh(x)),2) - 2*pow(cosh(acosh(x)),2))
153 * pow(cosh(atanh(x)),2);
155 clog << "(cosh(asinh(x))^2 - 2*cosh(acosh(x))^2) * cosh(atanh(x))^2 "
156 << "erroneously returned " << chk << " instead of 1" << endl;
160 // arbitrary check of type tanh(f(x)):
161 chk = (pow(tanh(asinh(x)),-2) - pow(tanh(acosh(x)),2)).expand()
162 * pow(tanh(atanh(x)),2);
164 clog << "expand(tanh(acosh(x))^2 - tanh(asinh(x))^(-2)) * tanh(atanh(x))^2 "
165 << "erroneously returned " << chk << " instead of 2" << endl;
172 /* Simple tests on the Gamma combinatorial function. We stuff in arguments
173 * where the result exists in closed form and check if it's ok. */
174 static unsigned inifcns_consist_gamma(void)
180 for (int i=2; i<8; ++i)
182 if (e != numeric(874)) {
183 clog << "gamma(1)+...+gamma(7) erroneously returned "
184 << e << " instead of 874" << endl;
189 for (int i=2; i<8; ++i)
191 if (e != numeric(24883200)) {
192 clog << "gamma(1)*...*gamma(7) erroneously returned "
193 << e << " instead of 24883200" << endl;
197 e = gamma(ex(numeric(5, 2)))*gamma(ex(numeric(9, 2)))*64;
199 clog << "64*gamma(5/2)*gamma(9/2) erroneously returned "
200 << e << " instead of 315*Pi" << endl;
204 e = gamma(ex(numeric(-13, 2)));
205 for (int i=-13; i<7; i=i+2)
206 e += gamma(ex(numeric(i, 2)));
207 e = (e*gamma(ex(numeric(15, 2)))*numeric(512));
208 if (e != numeric(633935)*Pi) {
209 clog << "512*(gamma(-13/2)+...+gamma(5/2))*gamma(15/2) erroneously returned "
210 << e << " instead of 633935*Pi" << endl;
217 /* Simple tests on the Riemann Zeta function. We stuff in arguments where the
218 * result exists in closed form and check if it's ok. Of course, this checks
219 * the Bernoulli numbers as a side effect. */
220 static unsigned inifcns_consist_zeta(void)
225 for (int i=0; i<13; i+=2)
226 e += zeta(i)/pow(Pi,i);
227 if (e!=numeric(-204992279,638512875)) {
228 clog << "zeta(0) + zeta(2) + ... + zeta(12) erroneously returned "
229 << e << " instead of -204992279/638512875" << endl;
234 for (int i=-1; i>-16; i--)
236 if (e!=numeric(487871,1633632)) {
237 clog << "zeta(-1) + zeta(-2) + ... + zeta(-15) erroneously returned "
238 << e << " instead of 487871/1633632" << endl;
245 unsigned inifcns_consist(void)
249 cout << "checking consistency of symbolic functions..." << flush;
250 clog << "---------consistency of symbolic functions:" << endl;
252 result += inifcns_consist_sin();
253 result += inifcns_consist_cos();
254 result += inifcns_consist_trans();
255 result += inifcns_consist_gamma();
256 result += inifcns_consist_zeta();
260 clog << "(no output)" << endl;