]> www.ginac.de Git - ginac.git/blob - check/exam_inifcns.cpp
added missing factor I in gamma5 trace
[ginac.git] / check / exam_inifcns.cpp
1 /** @file exam_inifcns.cpp
2  *
3  *  This test routine applies assorted tests on initially known higher level
4  *  functions. */
5
6 /*
7  *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
8  *
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.
13  *
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.
18  *
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
22  */
23
24 #include "exams.h"
25
26 /* Assorted tests on other transcendental functions. */
27 static unsigned inifcns_consist_trans(void)
28 {
29         unsigned result = 0;
30         symbol x("x");
31         ex chk;
32         
33         chk = asin(1)-acos(0);
34         if (!chk.is_zero()) {
35                 clog << "asin(1)-acos(0) erroneously returned " << chk
36                      << " instead of 0" << endl;
37                 ++result;
38         }
39         
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;
46                 ++result;
47         }
48         
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);
52         if (!chk.is_zero()) {
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;
55                 ++result;
56         }
57         
58         // arbitrary check of type tan(f(x)):
59         chk = tan(acos(x))*tan(asin(x)) - tan(atan(x));
60         if (chk != 1-x) {
61                 clog << "tan(acos(x))*tan(asin(x)) - tan(atan(x)) "
62                      << "erroneously returned " << chk << " instead of -x+1" << endl;
63                 ++result;
64         }
65         
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);
69         if (!chk.is_zero()) {
70                 clog << "expand(-(sinh(acosh(x)))^2)*(sinh(atanh(x))^2) - sinh(asinh(x))^2 "
71                      << "erroneously returned " << chk << " instead of 0" << endl;
72                 ++result;
73         }
74         
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);
78         if (chk != 1) {
79                 clog << "(cosh(asinh(x))^2 - 2*cosh(acosh(x))^2) * cosh(atanh(x))^2 "
80                      << "erroneously returned " << chk << " instead of 1" << endl;
81                 ++result;
82         }
83         
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);
87         if (chk != 2) {
88                 clog << "expand(tanh(acosh(x))^2 - tanh(asinh(x))^(-2)) * tanh(atanh(x))^2 "
89                      << "erroneously returned " << chk << " instead of 2" << endl;
90                 ++result;
91         }
92         
93         return result;
94 }
95
96 /* Simple tests on the tgamma function.  We stuff in arguments where the results
97  * exists in closed form and check if it's ok. */
98 static unsigned inifcns_consist_gamma(void)
99 {
100         unsigned result = 0;
101         ex e;
102         
103         e = tgamma(ex(1));
104         for (int i=2; i<8; ++i)
105                 e += tgamma(ex(i));
106         if (e != numeric(874)) {
107                 clog << "tgamma(1)+...+tgamma(7) erroneously returned "
108                      << e << " instead of 874" << endl;
109                 ++result;
110         }
111         
112         e = tgamma(ex(1));
113         for (int i=2; i<8; ++i)
114                 e *= tgamma(ex(i));     
115         if (e != numeric(24883200)) {
116                 clog << "tgamma(1)*...*tgamma(7) erroneously returned "
117                      << e << " instead of 24883200" << endl;
118                 ++result;
119         }
120         
121         e = tgamma(ex(numeric(5, 2)))*tgamma(ex(numeric(9, 2)))*64;
122         if (e != 315*Pi) {
123                 clog << "64*tgamma(5/2)*tgamma(9/2) erroneously returned "
124                      << e << " instead of 315*Pi" << endl;
125                 ++result;
126         }
127         
128         e = tgamma(ex(numeric(-13, 2)));
129         for (int i=-13; i<7; i=i+2)
130                 e += tgamma(ex(numeric(i, 2)));
131         e = (e*tgamma(ex(numeric(15, 2)))*numeric(512));
132         if (e != numeric(633935)*Pi) {
133                 clog << "512*(tgamma(-13/2)+...+tgamma(5/2))*tgamma(15/2) erroneously returned "
134                      << e << " instead of 633935*Pi" << endl;
135                 ++result;
136         }
137         
138         return result;
139 }
140
141 /* Simple tests on the Psi-function (aka polygamma-function).  We stuff in
142    arguments where the result exists in closed form and check if it's ok. */
143 static unsigned inifcns_consist_psi(void)
144 {
145         unsigned result = 0;
146         symbol x;
147         ex e, f;
148         
149         // We check psi(1) and psi(1/2) implicitly by calculating the curious
150         // little identity tgamma(1)'/tgamma(1) - tgamma(1/2)'/tgamma(1/2) == 2*log(2).
151         e += (tgamma(x).diff(x)/tgamma(x)).subs(x==numeric(1));
152         e -= (tgamma(x).diff(x)/tgamma(x)).subs(x==numeric(1,2));
153         if (e!=2*log(2)) {
154                 clog << "tgamma(1)'/tgamma(1) - tgamma(1/2)'/tgamma(1/2) erroneously returned "
155                      << e << " instead of 2*log(2)" << endl;
156                 ++result;
157         }
158         
159         return result;
160 }
161
162 /* Simple tests on the Riemann Zeta function.  We stuff in arguments where the
163  * result exists in closed form and check if it's ok.  Of course, this checks
164  * the Bernoulli numbers as a side effect. */
165 static unsigned inifcns_consist_zeta(void)
166 {
167         unsigned result = 0;
168         ex e;
169         
170         for (int i=0; i<13; i+=2)
171                 e += zeta(i)/pow(Pi,i);
172         if (e!=numeric(-204992279,638512875)) {
173                 clog << "zeta(0) + zeta(2) + ... + zeta(12) erroneously returned "
174                      << e << " instead of -204992279/638512875" << endl;
175                 ++result;
176         }
177         
178         e = 0;
179         for (int i=-1; i>-16; i--)
180                 e += zeta(i);
181         if (e!=numeric(487871,1633632)) {
182                 clog << "zeta(-1) + zeta(-2) + ... + zeta(-15) erroneously returned "
183                      << e << " instead of 487871/1633632" << endl;
184                 ++result;
185         }
186         
187         return result;
188 }
189
190 unsigned exam_inifcns(void)
191 {
192         unsigned result = 0;
193         
194         cout << "examining consistency of symbolic functions" << flush;
195         clog << "----------consistency of symbolic functions:" << endl;
196         
197         result += inifcns_consist_trans();  cout << '.' << flush;
198         result += inifcns_consist_gamma();  cout << '.' << flush;
199         result += inifcns_consist_psi();  cout << '.' << flush;
200         result += inifcns_consist_zeta();  cout << '.' << flush;
201         
202         if (!result) {
203                 cout << " passed " << endl;
204                 clog << "(no output)" << endl;
205         } else {
206                 cout << " failed " << endl;
207         }
208         
209         return result;
210 }