1 /** @file inifcns_consist.cpp
3 * This test routine applies assorted tests on initially known higher level
6 * GiNaC Copyright (C) 1999 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
23 #include <ginac/ginac.h>
25 /* Simple tests on the sine trigonometric function. */
26 static unsigned inifcns_consist_sin(void)
33 for (int n=-10; n<=10; ++n) {
34 if ( sin(n*Pi).eval() != numeric(0) ||
35 !sin(n*Pi).eval().info(info_flags::integer) )
39 clog << "sin(n*Pi) with integer n does not always return exact 0"
44 // sin((n+1/2)*Pi) == {+|-}1?
46 for (int n=-10; n<=10; ++n) {
47 if ( ! sin((n+numeric(1,2))*Pi).eval().info(info_flags::integer) ||
48 !(sin((n+numeric(1,2))*Pi).eval() == numeric(1) ||
49 sin((n+numeric(1,2))*Pi).eval() == numeric(-1)) )
53 clog << "sin((n+1/2)*Pi) with integer n does not always return exact {+|-}1"
61 /* Simple tests on the cosine trigonometric function. */
62 static unsigned inifcns_consist_cos(void)
67 // cos((n+1/2)*Pi) == 0?
69 for (int n=-10; n<=10; ++n) {
70 if ( cos((n+numeric(1,2))*Pi).eval() != numeric(0) ||
71 !cos((n+numeric(1,2))*Pi).eval().info(info_flags::integer) )
75 clog << "cos((n+1/2)*Pi) with integer n does not always return exact 0"
82 for (int n=-10; n<=10; ++n) {
83 if ( ! cos(n*Pi).eval().info(info_flags::integer) ||
84 !(cos(n*Pi).eval() == numeric(1) ||
85 cos(n*Pi).eval() == numeric(-1)) )
89 clog << "cos(n*Pi) with integer n does not always return exact {+|-}1"
97 /* Assorted tests on other transcendental functions. */
98 static unsigned inifcns_consist_trans(void)
104 chk = asin(1)-acos(0);
105 if (!chk.is_zero()) {
106 clog << "asin(1)-acos(0) erroneously returned " << chk
107 << " instead of 0" << endl;
111 // arbitrary check of type sin(f(x)):
112 chk = pow(sin(acos(x)),2) + pow(sin(asin(x)),2)
113 - (1+pow(x,2))*pow(sin(atan(x)),2);
114 if (chk != 1-pow(x,2)) {
115 clog << "sin(acos(x))^2 + sin(asin(x))^2 - (1+x^2)*sin(atan(x))^2 "
116 << "erroneously returned " << chk << " instead of 1-x^2" << endl;
120 // arbitrary check of type cos(f(x)):
121 chk = pow(cos(acos(x)),2) + pow(cos(asin(x)),2)
122 - (1+pow(x,2))*pow(cos(atan(x)),2);
123 if (!chk.is_zero()) {
124 clog << "cos(acos(x))^2 + cos(asin(x))^2 - (1+x^2)*cos(atan(x))^2 "
125 << "erroneously returned " << chk << " instead of 0" << endl;
129 // arbitrary check of type tan(f(x)):
130 chk = tan(acos(x))*tan(asin(x)) - tan(atan(x));
132 clog << "tan(acos(x))*tan(asin(x)) - tan(atan(x)) "
133 << "erroneously returned " << chk << " instead of -x+1" << endl;
137 // arbitrary check of type sinh(f(x)):
138 chk = -pow(sinh(acosh(x)),2).expand()*pow(sinh(atanh(x)),2)
139 - pow(sinh(asinh(x)),2);
140 if (!chk.is_zero()) {
141 clog << "expand(-(sinh(acosh(x)))^2)*(sinh(atanh(x))^2) - sinh(asinh(x))^2 "
142 << "erroneously returned " << chk << " instead of 0" << endl;
146 // arbitrary check of type cosh(f(x)):
147 chk = (pow(cosh(asinh(x)),2) - 2*pow(cosh(acosh(x)),2))
148 * pow(cosh(atanh(x)),2);
150 clog << "(cosh(asinh(x))^2 - 2*cosh(acosh(x))^2) * cosh(atanh(x))^2 "
151 << "erroneously returned " << chk << " instead of 1" << endl;
155 // arbitrary check of type tanh(f(x)):
156 chk = (pow(tanh(asinh(x)),-2) - pow(tanh(acosh(x)),2)).expand()
157 * pow(tanh(atanh(x)),2);
159 clog << "expand(tanh(acosh(x))^2 - tanh(asinh(x))^(-2)) * tanh(atanh(x))^2 "
160 << "erroneously returned " << chk << " instead of 2" << endl;
167 /* Simple tests on the Gamma combinatorial function. We stuff in arguments
168 * where the result exists in closed form and check if it's ok. */
169 static unsigned inifcns_consist_gamma(void)
175 for (int i=2; i<8; ++i) {
178 if ( e != numeric(874) ) {
179 clog << "gamma(1)+...+gamma(7) erroneously returned "
180 << e << " instead of 874" << endl;
185 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)));
205 e = (e*gamma(ex(numeric(15, 2)))*numeric(512));
206 if ( e != numeric(633935)*Pi ) {
207 clog << "512*(gamma(-13/2)+...+gamma(5/2))*gamma(15/2) erroneously returned "
208 << e << " instead of 633935*Pi" << endl;
215 unsigned inifcns_consist(void)
219 cout << "checking consistency of symbolic functions..." << flush;
220 clog << "---------consistency of symbolic functions:" << endl;
222 result += inifcns_consist_sin();
223 result += inifcns_consist_cos();
224 result += inifcns_consist_trans();
225 result += inifcns_consist_gamma();
229 clog << "(no output)" << endl;