]> www.ginac.de Git - ginac.git/blob - check/exam_inifcns_nstdsums.cpp
Updated checks.
[ginac.git] / check / exam_inifcns_nstdsums.cpp
1 /** @file exam_inifcns_nstdsums.cpp
2  *
3  *  This test routine applies assorted tests on initially known higher level
4  *  functions. */
5
6 /*
7  *  GiNaC Copyright (C) 1999-2003 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 #include <fstream>
27
28
29 ////////////////////////////////////////////////////////////////////////////////
30 ////////////////////////////////////////////////////////////////////////////////
31 //  S exam
32 ////////////////////////////////////////////////////////////////////////////////
33 ////////////////////////////////////////////////////////////////////////////////
34
35
36 /*
37  * The data in the following include file has been produced by the following
38  * Mathematica (V4.1) script:
39  *
40  *
41  *    x={2/10,1,14/10,30/10}
42  *    y={0,3/10,-14/10}
43  *    st = OpenAppend["exam_inifcns_nstdsums_data.raw"]
44  *    $NumberMarks = False
45  *    Do[
46  *      Do[
47  *        Do[Write[st, i]; Write[st,j]; Write[st,x[[k]]+I*y[[l]]];
48  *          Write[st,Chop[N[PolyLog[i,j,x[[k]]+I*y[[l]]],25]]],{i,3},{j,3}], {k,4}],{l,3}]
49  *    Do[
50  *      Do[
51  *        Do[Write[st, i]; Write[st,j]; Write[st,-x[[k]]+I*y[[l]]];
52  *          Write[st,Chop[N[PolyLog[i,j,-x[[k]]+I*y[[l]]],25]]],{i,3},{j,3}], {k,4}], {l,3}]
53  *    Close[st]
54  *
55  *    
56  * and postprocessed by the following shell script
57  *
58  *
59  *    #/bin/sh
60  *    IFS=$'\n'
61  *    cat exam_inifcns_nstdsums_data.raw | sed -e 's/\*\^/E/g' > exam_inifcns_nstdsums_data.raw2
62  *    echo 'const char *data[] = {' > exam_inifcns_nstdsums_data.raw3
63  *    for i in `cat exam_inifcns_nstdsums_data.raw2`; do echo \"$i\",; done >> exam_inifcns_nstdsums_data.raw3
64  *    echo '"-999"};' >> exam_inifcns_nstdsums.h
65  *
66  *
67  */
68 #include "exam_inifcns_nstdsums.h"
69
70
71 // signals end of data
72 const int ENDMARK = -999;
73
74
75 static unsigned inifcns_test_S()
76 {
77         int digitsbuf = Digits;
78         // precision of data
79         Digits = 22;
80         ex prec = 5 * pow(10, -(int)Digits);
81         
82         unsigned result = 0;
83         
84         int i = 0;
85         while (true) {
86                 ex n(data[i++],symbol());
87                 if (n == ENDMARK) {
88                         break;
89                 }
90                 ex p(data[i++],symbol());
91                 ex x(data[i++],symbol());
92                 ex res(data[i++],symbol());
93                 ex res2 = S(n, p, x).evalf();
94                 if (abs(res-res2) > prec) {
95                         clog << "S(" << n << "," << p << "," << x << ") seems to be wrong:" << endl;
96                         clog << "GiNaC           : " << res2 << endl;
97                         clog << "Reference       : " << res << endl;
98                         clog << "Abs. Difference : " << res2-res << endl;
99                         if (res2 != 0) {
100                                 ex reldiff = abs((res2-res)/res2);
101                                 clog << "Rel. Difference : " << reldiff << endl;
102                         }
103                         result++;
104                 }
105                 if (i % 80) {
106                         cout << "." << flush;
107                 }
108         }
109
110         Digits = digitsbuf;
111
112         return result;
113 }
114
115
116 ////////////////////////////////////////////////////////////////////////////////
117 ////////////////////////////////////////////////////////////////////////////////
118 //  zeta exam
119 ////////////////////////////////////////////////////////////////////////////////
120 ////////////////////////////////////////////////////////////////////////////////
121
122
123 static unsigned inifcns_test_zeta()
124 {
125         int digitsbuf = Digits;
126         
127         unsigned result = 0;
128
129         lst res;
130         
131         res.append(zeta(lst(2,1)) - zeta(3));
132         res.append(zeta(lst(2,1,1,1,1)) - zeta(6));
133         res.append(zeta(lst(6,3)) - (zeta(9)*83/2 - zeta(2)*zeta(7)*21 - zeta(2)*zeta(2)*zeta(5)*12/5));
134         res.append(zeta(lst(4,2,3)) - (-zeta(9)*59 + zeta(2)*zeta(7)*28 + pow(zeta(2),2)*zeta(5)*4 -
135                                        pow(zeta(3),3)/3 + pow(zeta(2),3)*zeta(3)*8/21));
136         res.append(zeta(lst(3,1,3,1,3,1,3,1)) - (2*pow(Pi,16)/factorial(18)));
137         
138         for (lst::const_iterator it = res.begin(); it != res.end(); it++) {
139                 Digits = 17;
140                 ex prec = 5 * pow(10, -(int)Digits);
141                 ex diff = abs((*it).evalf());
142                 if (diff > prec) {
143                         clog << *it << " seems to be wrong: " << diff << endl;
144                         clog << "Digits: " << Digits << endl;
145                         result++;
146                 }
147                 cout << "." << flush;
148                 Digits = 40;
149                 prec = 5 * pow(10, -(int)Digits);
150                 diff = abs((*it).evalf());
151                 if (diff > prec) {
152                         clog << *it << " seems to be wrong: " << diff << endl;
153                         clog << "Digits: " << Digits << endl;
154                         result++;
155                 }
156                 cout << "." << flush;
157         }
158
159         Digits = digitsbuf;
160
161         return result;
162 }
163
164
165 unsigned exam_inifcns_nstdsums(void)
166 {
167         unsigned result = 0;
168         
169         cout << "examining consistency of nestedsums functions" << flush;
170         clog << "----------consistency of nestedsums functions:" << endl;
171         
172         cout << "zeta" << flush;
173         result += inifcns_test_zeta();
174         cout << "S" << flush;
175         result += inifcns_test_S();
176         
177         if (!result) {
178                 cout << " passed " << endl;
179                 clog << "(no output)" << endl;
180         } else {
181                 cout << " failed " << endl;
182         }
183         
184         return result;
185 }