1 /** @file exam_inifcns.cpp
3 * This test routine applies assorted tests on initially known higher level
7 * GiNaC Copyright (C) 1999-2002 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
26 /* Assorted tests on other transcendental functions. */
27 static unsigned inifcns_consist_trans(void)
33 chk = asin(1)-acos(0);
35 clog << "asin(1)-acos(0) erroneously returned " << chk
36 << " instead of 0" << endl;
40 // arbitrary check of type sin(f(x)):
41 chk = pow(sin(acos(x)),2) + pow(sin(asin(x)),2)
42 - (1+pow(x,2))*pow(sin(atan(x)),2);
43 if (chk != 1-pow(x,2)) {
44 clog << "sin(acos(x))^2 + sin(asin(x))^2 - (1+x^2)*sin(atan(x))^2 "
45 << "erroneously returned " << chk << " instead of 1-x^2" << endl;
49 // arbitrary check of type cos(f(x)):
50 chk = pow(cos(acos(x)),2) + pow(cos(asin(x)),2)
51 - (1+pow(x,2))*pow(cos(atan(x)),2);
53 clog << "cos(acos(x))^2 + cos(asin(x))^2 - (1+x^2)*cos(atan(x))^2 "
54 << "erroneously returned " << chk << " instead of 0" << endl;
58 // arbitrary check of type tan(f(x)):
59 chk = tan(acos(x))*tan(asin(x)) - tan(atan(x));
61 clog << "tan(acos(x))*tan(asin(x)) - tan(atan(x)) "
62 << "erroneously returned " << chk << " instead of -x+1" << endl;
66 // arbitrary check of type sinh(f(x)):
67 chk = -pow(sinh(acosh(x)),2).expand()*pow(sinh(atanh(x)),2)
68 - pow(sinh(asinh(x)),2);
70 clog << "expand(-(sinh(acosh(x)))^2)*(sinh(atanh(x))^2) - sinh(asinh(x))^2 "
71 << "erroneously returned " << chk << " instead of 0" << endl;
75 // arbitrary check of type cosh(f(x)):
76 chk = (pow(cosh(asinh(x)),2) - 2*pow(cosh(acosh(x)),2))
77 * pow(cosh(atanh(x)),2);
79 clog << "(cosh(asinh(x))^2 - 2*cosh(acosh(x))^2) * cosh(atanh(x))^2 "
80 << "erroneously returned " << chk << " instead of 1" << endl;
84 // arbitrary check of type tanh(f(x)):
85 chk = (pow(tanh(asinh(x)),-2) - pow(tanh(acosh(x)),2)).expand()
86 * pow(tanh(atanh(x)),2);
88 clog << "expand(tanh(acosh(x))^2 - tanh(asinh(x))^(-2)) * tanh(atanh(x))^2 "
89 << "erroneously returned " << chk << " instead of 2" << endl;
93 // check consistency of log and eta phases:
94 for (int r1=-1; r1<=1; ++r1) {
95 for (int i1=-1; i1<=1; ++i1) {
99 for (int r2=-1; r2<=1; ++r2) {
100 for (int i2=-1; i2<=1; ++i2) {
104 if (abs(evalf(eta(x1,x2)-log(x1*x2)+log(x1)+log(x2)))>.1e-12) {
105 clog << "either eta(x,y), log(x), log(y) or log(x*y) is wrong"
106 << " at x==" << x1 << ", y==" << x2 << endl;
117 /* Simple tests on the tgamma function. We stuff in arguments where the results
118 * exists in closed form and check if it's ok. */
119 static unsigned inifcns_consist_gamma(void)
125 for (int i=2; i<8; ++i)
127 if (e != numeric(874)) {
128 clog << "tgamma(1)+...+tgamma(7) erroneously returned "
129 << e << " instead of 874" << endl;
134 for (int i=2; i<8; ++i)
136 if (e != numeric(24883200)) {
137 clog << "tgamma(1)*...*tgamma(7) erroneously returned "
138 << e << " instead of 24883200" << endl;
142 e = tgamma(ex(numeric(5, 2)))*tgamma(ex(numeric(9, 2)))*64;
144 clog << "64*tgamma(5/2)*tgamma(9/2) erroneously returned "
145 << e << " instead of 315*Pi" << endl;
149 e = tgamma(ex(numeric(-13, 2)));
150 for (int i=-13; i<7; i=i+2)
151 e += tgamma(ex(numeric(i, 2)));
152 e = (e*tgamma(ex(numeric(15, 2)))*numeric(512));
153 if (e != numeric(633935)*Pi) {
154 clog << "512*(tgamma(-13/2)+...+tgamma(5/2))*tgamma(15/2) erroneously returned "
155 << e << " instead of 633935*Pi" << endl;
162 /* Simple tests on the Psi-function (aka polygamma-function). We stuff in
163 arguments where the result exists in closed form and check if it's ok. */
164 static unsigned inifcns_consist_psi(void)
170 // We check psi(1) and psi(1/2) implicitly by calculating the curious
171 // little identity tgamma(1)'/tgamma(1) - tgamma(1/2)'/tgamma(1/2) == 2*log(2).
172 e += (tgamma(x).diff(x)/tgamma(x)).subs(x==numeric(1));
173 e -= (tgamma(x).diff(x)/tgamma(x)).subs(x==numeric(1,2));
175 clog << "tgamma(1)'/tgamma(1) - tgamma(1/2)'/tgamma(1/2) erroneously returned "
176 << e << " instead of 2*log(2)" << endl;
183 /* Simple tests on the Riemann Zeta function. We stuff in arguments where the
184 * result exists in closed form and check if it's ok. Of course, this checks
185 * the Bernoulli numbers as a side effect. */
186 static unsigned inifcns_consist_zeta(void)
191 for (int i=0; i<13; i+=2)
192 e += zeta(i)/pow(Pi,i);
193 if (e!=numeric(-204992279,638512875)) {
194 clog << "zeta(0) + zeta(2) + ... + zeta(12) erroneously returned "
195 << e << " instead of -204992279/638512875" << endl;
200 for (int i=-1; i>-16; i--)
202 if (e!=numeric(487871,1633632)) {
203 clog << "zeta(-1) + zeta(-2) + ... + zeta(-15) erroneously returned "
204 << e << " instead of 487871/1633632" << endl;
211 unsigned exam_inifcns(void)
215 cout << "examining consistency of symbolic functions" << flush;
216 clog << "----------consistency of symbolic functions:" << endl;
218 result += inifcns_consist_trans(); cout << '.' << flush;
219 result += inifcns_consist_gamma(); cout << '.' << flush;
220 result += inifcns_consist_psi(); cout << '.' << flush;
221 result += inifcns_consist_zeta(); cout << '.' << flush;
224 cout << " passed " << endl;
225 clog << "(no output)" << endl;
227 cout << " failed " << endl;