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>
25 using namespace GiNaC;
27 /* Simple tests on the sine trigonometric function. */
28 static unsigned inifcns_consist_sin(void)
35 for (int n=-10; n<=10; ++n) {
36 if ( sin(n*Pi).eval() != numeric(0) ||
37 !sin(n*Pi).eval().info(info_flags::integer))
41 clog << "sin(n*Pi) with integer n does not always return exact 0"
46 // sin((n+1/2)*Pi) == {+|-}1?
48 for (int n=-10; n<=10; ++n) {
49 if (! sin((n+numeric(1,2))*Pi).eval().info(info_flags::integer) ||
50 !(sin((n+numeric(1,2))*Pi).eval() == numeric(1) ||
51 sin((n+numeric(1,2))*Pi).eval() == numeric(-1)))
55 clog << "sin((n+1/2)*Pi) with integer n does not always return exact {+|-}1"
63 /* Simple tests on the cosine trigonometric function. */
64 static unsigned inifcns_consist_cos(void)
69 // cos((n+1/2)*Pi) == 0?
71 for (int n=-10; n<=10; ++n) {
72 if ( cos((n+numeric(1,2))*Pi).eval() != numeric(0) ||
73 !cos((n+numeric(1,2))*Pi).eval().info(info_flags::integer))
77 clog << "cos((n+1/2)*Pi) with integer n does not always return exact 0"
84 for (int n=-10; n<=10; ++n) {
85 if (! cos(n*Pi).eval().info(info_flags::integer) ||
86 !(cos(n*Pi).eval() == numeric(1) ||
87 cos(n*Pi).eval() == numeric(-1)))
91 clog << "cos(n*Pi) with integer n does not always return exact {+|-}1"
99 /* Assorted tests on other transcendental functions. */
100 static unsigned inifcns_consist_trans(void)
106 chk = asin(1)-acos(0);
107 if (!chk.is_zero()) {
108 clog << "asin(1)-acos(0) erroneously returned " << chk
109 << " instead of 0" << endl;
113 // arbitrary check of type sin(f(x)):
114 chk = pow(sin(acos(x)),2) + pow(sin(asin(x)),2)
115 - (1+pow(x,2))*pow(sin(atan(x)),2);
116 if (chk != 1-pow(x,2)) {
117 clog << "sin(acos(x))^2 + sin(asin(x))^2 - (1+x^2)*sin(atan(x))^2 "
118 << "erroneously returned " << chk << " instead of 1-x^2" << endl;
122 // arbitrary check of type cos(f(x)):
123 chk = pow(cos(acos(x)),2) + pow(cos(asin(x)),2)
124 - (1+pow(x,2))*pow(cos(atan(x)),2);
125 if (!chk.is_zero()) {
126 clog << "cos(acos(x))^2 + cos(asin(x))^2 - (1+x^2)*cos(atan(x))^2 "
127 << "erroneously returned " << chk << " instead of 0" << endl;
131 // arbitrary check of type tan(f(x)):
132 chk = tan(acos(x))*tan(asin(x)) - tan(atan(x));
134 clog << "tan(acos(x))*tan(asin(x)) - tan(atan(x)) "
135 << "erroneously returned " << chk << " instead of -x+1" << endl;
139 // arbitrary check of type sinh(f(x)):
140 chk = -pow(sinh(acosh(x)),2).expand()*pow(sinh(atanh(x)),2)
141 - pow(sinh(asinh(x)),2);
142 if (!chk.is_zero()) {
143 clog << "expand(-(sinh(acosh(x)))^2)*(sinh(atanh(x))^2) - sinh(asinh(x))^2 "
144 << "erroneously returned " << chk << " instead of 0" << endl;
148 // arbitrary check of type cosh(f(x)):
149 chk = (pow(cosh(asinh(x)),2) - 2*pow(cosh(acosh(x)),2))
150 * pow(cosh(atanh(x)),2);
152 clog << "(cosh(asinh(x))^2 - 2*cosh(acosh(x))^2) * cosh(atanh(x))^2 "
153 << "erroneously returned " << chk << " instead of 1" << endl;
157 // arbitrary check of type tanh(f(x)):
158 chk = (pow(tanh(asinh(x)),-2) - pow(tanh(acosh(x)),2)).expand()
159 * pow(tanh(atanh(x)),2);
161 clog << "expand(tanh(acosh(x))^2 - tanh(asinh(x))^(-2)) * tanh(atanh(x))^2 "
162 << "erroneously returned " << chk << " instead of 2" << endl;
169 /* Simple tests on the Gamma combinatorial function. We stuff in arguments
170 * where the result exists in closed form and check if it's ok. */
171 static unsigned inifcns_consist_gamma(void)
177 for (int i=2; i<8; ++i)
179 if (e != numeric(874)) {
180 clog << "gamma(1)+...+gamma(7) erroneously returned "
181 << e << " instead of 874" << endl;
186 for (int i=2; i<8; ++i)
188 if (e != numeric(24883200)) {
189 clog << "gamma(1)*...*gamma(7) erroneously returned "
190 << e << " instead of 24883200" << endl;
194 e = gamma(ex(numeric(5, 2)))*gamma(ex(numeric(9, 2)))*64;
196 clog << "64*gamma(5/2)*gamma(9/2) erroneously returned "
197 << e << " instead of 315*Pi" << endl;
201 e = gamma(ex(numeric(-13, 2)));
202 for (int i=-13; i<7; i=i+2)
203 e += gamma(ex(numeric(i, 2)));
204 e = (e*gamma(ex(numeric(15, 2)))*numeric(512));
205 if (e != numeric(633935)*Pi) {
206 clog << "512*(gamma(-13/2)+...+gamma(5/2))*gamma(15/2) erroneously returned "
207 << e << " instead of 633935*Pi" << endl;
214 /* Simple tests on the Riemann Zeta function. We stuff in arguments where the
215 * result exists in closed form and check if it's ok. Of course, this checks
216 * the Bernoulli numbers as a side effect. */
217 static unsigned inifcns_consist_zeta(void)
222 for (int i=0; i<13; i+=2)
223 e += zeta(i)/pow(Pi,i);
224 if (e!=numeric(-204992279,638512875)) {
225 clog << "zeta(0) + zeta(2) + ... + zeta(12) erroneously returned "
226 << e << " instead of -204992279/638512875" << endl;
231 for (int i=-1; i>-16; i--)
233 if (e!=numeric(487871,1633632)) {
234 clog << "zeta(-1) + zeta(-2) + ... + zeta(-15) erroneously returned "
235 << e << " instead of 487871/1633632" << endl;
242 unsigned inifcns_consist(void)
246 cout << "checking consistency of symbolic functions..." << flush;
247 clog << "---------consistency of symbolic functions:" << endl;
249 result += inifcns_consist_sin();
250 result += inifcns_consist_cos();
251 result += inifcns_consist_trans();
252 result += inifcns_consist_gamma();
253 result += inifcns_consist_zeta();
257 clog << "(no output)" << endl;