]> www.ginac.de Git - ginac.git/blob - check/exam_inifcns_nstdsums.cpp
Daily bugfix in the polynomial factorization (code didn't catch polynomial "x"
[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-2008 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22  */
23
24 #include <iostream>
25 #include <fstream>
26 #include "ginac.h"
27 using namespace std;
28 using namespace GiNaC;
29
30
31
32 ////////////////////////////////////////////////////////////////////////////////
33 ////////////////////////////////////////////////////////////////////////////////
34 //  S exam
35 ////////////////////////////////////////////////////////////////////////////////
36 ////////////////////////////////////////////////////////////////////////////////
37
38
39 /*
40  * The data in the following include file has been produced by the following
41  * Mathematica (V4.1) script:
42  *
43  *
44  *    x={2/10,1,14/10,30/10}
45  *    y={0,3/10,-14/10}
46  *    st = OpenAppend["exam_inifcns_nstdsums_data.raw"]
47  *    $NumberMarks = False
48  *    Do[
49  *      Do[
50  *        Do[Write[st, i]; Write[st,j]; Write[st,x[[k]]+I*y[[l]]];
51  *          Write[st,Chop[N[PolyLog[i,j,x[[k]]+I*y[[l]]],25]]],{i,3},{j,3}], {k,4}],{l,3}]
52  *    Do[
53  *      Do[
54  *        Do[Write[st, i]; Write[st,j]; Write[st,-x[[k]]+I*y[[l]]];
55  *          Write[st,Chop[N[PolyLog[i,j,-x[[k]]+I*y[[l]]],25]]],{i,3},{j,3}], {k,4}], {l,3}]
56  *    Close[st]
57  *
58  *    
59  * and postprocessed by the following shell script
60  *
61  *
62  *    #/bin/sh
63  *    IFS=$'\n'
64  *    cat exam_inifcns_nstdsums_data.raw | sed -e 's/\*\^/E/g' > exam_inifcns_nstdsums_data.raw2
65  *    echo 'const char *data[] = {' > exam_inifcns_nstdsums_data.raw3
66  *    for i in `cat exam_inifcns_nstdsums_data.raw2`; do echo \"$i\",; done >> exam_inifcns_nstdsums_data.raw3
67  *    echo '"-999"};' >> exam_inifcns_nstdsums.h
68  *
69  *
70  */
71 #include "exam_inifcns_nstdsums.h"
72
73
74 // signals end of data
75 const int ENDMARK = -999;
76
77
78 static unsigned inifcns_test_S()
79 {
80         int digitsbuf = Digits;
81         // precision of data
82         Digits = 22;
83         ex prec = 5 * pow(10, -(int)Digits);
84         
85         unsigned result = 0;
86         
87         int i = 0;
88         while (true) {
89                 ex n(data[i++],symbol());
90                 if (n == ENDMARK) {
91                         break;
92                 }
93                 ex p(data[i++],symbol());
94                 ex x(data[i++],symbol());
95                 ex res(data[i++],symbol());
96                 ex res2 = S(n, p, x).evalf();
97                 if (abs(res-res2) > prec) {
98                         clog << "S(" << n << "," << p << "," << x << ") seems to be wrong:" << endl;
99                         clog << "GiNaC           : " << res2 << endl;
100                         clog << "Reference       : " << res << endl;
101                         clog << "Abs. Difference : " << res2-res << endl;
102                         if (res2 != 0) {
103                                 ex reldiff = abs((res2-res)/res2);
104                                 clog << "Rel. Difference : " << reldiff << endl;
105                         }
106                         result++;
107                 }
108                 if (i % 80) {
109                         cout << "." << flush;
110                 }
111         }
112
113         Digits = digitsbuf;
114
115         return result;
116 }
117
118
119 ////////////////////////////////////////////////////////////////////////////////
120 ////////////////////////////////////////////////////////////////////////////////
121 //  H/Li exam
122 ////////////////////////////////////////////////////////////////////////////////
123 ////////////////////////////////////////////////////////////////////////////////
124
125
126 static unsigned inifcns_test_HLi()
127 {
128         int digitsbuf = Digits;
129         Digits = 17;
130         ex prec = 5 * pow(10, -(int)Digits);
131         numeric almostone("0.999999999999999999");
132         unsigned result = 0;
133
134         lst res;
135         
136         res.append(H(lst(2,1),numeric(1)/2).hold() - (zeta(3)/8 - pow(log(2),3)/6));
137         res.append(H(lst(2,1,3),numeric(1)/3).hold() - Li(lst(2,1,3),lst(numeric(1)/3,1,1)).hold());
138         res.append(H(lst(2,1,3),numeric(98)/100).hold() - Li(lst(2,1,3),lst(numeric(98)/100,1,1)).hold());
139         res.append(H(lst(2,1,3),numeric(245)/100).hold() - Li(lst(2,1,3),lst(numeric(245)/100,1,1)).hold());
140         res.append(H(lst(4,1,1,1),numeric(1)/3).hold() - S(3,4,numeric(1)/3).hold());
141         res.append(H(lst(4,1,1,1),numeric(98)/100).hold() - S(3,4,numeric(98)/100).hold());
142         res.append(H(lst(4,1,1,1),numeric(245)/100).hold() - S(3,4,numeric(245)/100).hold());
143         res.append(H(lst(2,2,3),almostone).hold() - zeta(lst(2,2,3)));
144         res.append(H(lst(-3,-1,2,1),almostone).hold() - zeta(lst(3,1,2,1),lst(-1,1,-1,1)));
145         res.append(H(lst(-2,1,3),numeric(1)/3).hold() - -Li(lst(2,1,3),lst(-numeric(1)/3,-1,1)).hold());
146         res.append(H(lst(-2,1,3),numeric(98)/100).hold() - -Li(lst(2,1,3),lst(-numeric(98)/100,-1,1)).hold());
147         res.append(H(lst(-2,1,3),numeric(245)/100).hold() - -Li(lst(2,1,3),lst(-numeric(245)/100,-1,1)).hold());
148         res.append(H(lst(-3,1,-2,0,0),numeric(3)/10).hold() - convert_H_to_Li(lst(-3,1,-2,0,0),numeric(3)/10).eval());
149         
150         for (lst::const_iterator it = res.begin(); it != res.end(); it++) {
151                 ex diff = abs((*it).evalf());
152                 if (diff > prec) {
153                         clog << *it << " seems to be wrong: " << diff << endl;
154                         result++;
155                 }
156                 cout << "." << flush;
157         }
158
159         Digits = digitsbuf;
160
161         // conjugate test
162         numeric cdif = ex_to<numeric>(H(lst(2,2,1),5.0-5.0*I) - H(lst(2,2,1),5.0+5.0*I));
163         numeric cadd = ex_to<numeric>(H(lst(2,2,1),5.0-5.0*I) + H(lst(2,2,1),5.0+5.0*I));
164         if ((cdif.real() > prec) || (cadd.imag() > prec)) {
165                 clog << "complex conjugation test of H({2,2,1},5.0-5.0*I) seems to be wrong: " << cdif << " " << cadd << endl;
166                 result++;
167         }
168
169         return result;
170 }
171
172
173 ////////////////////////////////////////////////////////////////////////////////
174 ////////////////////////////////////////////////////////////////////////////////
175 //  zeta exam
176 ////////////////////////////////////////////////////////////////////////////////
177 ////////////////////////////////////////////////////////////////////////////////
178
179
180 static unsigned inifcns_test_zeta()
181 {
182         int digitsbuf = Digits;
183         
184         unsigned result = 0;
185
186         lst res;
187         
188         res.append(zeta(lst(2,1)) - zeta(3));
189         res.append(zeta(lst(2,1,1,1,1)) - zeta(6));
190         res.append(zeta(lst(6,3)) - (zeta(9)*83/2 - zeta(2)*zeta(7)*21 - zeta(2)*zeta(2)*zeta(5)*12/5));
191         res.append(zeta(lst(4,2,3)) - (-zeta(9)*59 + zeta(2)*zeta(7)*28 + pow(zeta(2),2)*zeta(5)*4 -
192                                        pow(zeta(3),3)/3 + pow(zeta(2),3)*zeta(3)*8/21));
193         res.append(zeta(lst(3,1,3,1,3,1,3,1)) - (2*pow(Pi,16)/factorial(18)));
194         res.append(zeta(lst(2),lst(-1)) - -zeta(2)/2);
195         res.append(zeta(lst(1,2),lst(-1,1)) - (-zeta(3)/4 - zeta(lst(1),lst(-1))*zeta(2)/2));
196         res.append(zeta(lst(2,1,1),lst(-1,-1,1)) - (-pow(zeta(2),2)*23/40 - pow(zeta(lst(1),lst(-1)),2)*zeta(2)*3/4
197                                                     - zeta(lst(3,1),lst(-1,1))*3/2 - zeta(lst(1),lst(-1))*zeta(3)*21/8));
198         
199         for (lst::const_iterator it = res.begin(); it != res.end(); it++) {
200                 Digits = 17;
201                 ex prec = 5 * pow(10, -(int)Digits);
202                 ex diff = abs((*it).evalf());
203                 if (diff > prec) {
204                         clog << *it << " seems to be wrong: " << diff << endl;
205                         clog << "Digits: " << Digits << endl;
206                         result++;
207                 }
208                 cout << "." << flush;
209                 Digits = 40;
210                 prec = 5 * pow(10, -(int)Digits);
211                 diff = abs((*it).evalf());
212                 if (diff > prec) {
213                         clog << *it << " seems to be wrong: " << diff << endl;
214                         clog << "Digits: " << Digits << endl;
215                         result++;
216                 }
217                 cout << "." << flush;
218         }
219
220         Digits = digitsbuf;
221
222         return result;
223 }
224
225
226 ////////////////////////////////////////////////////////////////////////////////
227 ////////////////////////////////////////////////////////////////////////////////
228 //  H/Li exam
229 ////////////////////////////////////////////////////////////////////////////////
230 ////////////////////////////////////////////////////////////////////////////////
231
232
233 static unsigned inifcns_test_LiG()
234 {
235         int digitsbuf = Digits;
236         Digits = 17;
237         ex prec = 5 * pow(10, -(int)Digits);
238         numeric almostone("0.99999999999999999999");
239         unsigned result = 0;
240
241         lst res;
242         
243         res.append(Li(lst(4), lst(6)).hold() - Li(4, 6.0));
244         res.append(G(lst(0,0,5.0,0,2.0,0,0,0,3.0),0.5).hold()
245                    + Li(lst(3,2,4), lst(numeric(1,10), numeric(5,2), numeric(2,3))));
246         res.append(Li(lst(2,1,1), lst(almostone, almostone, almostone)) - zeta(lst(2,1,1)));
247
248         // check Li_{1,1} against known expression
249         symbol x("x"), y("y");
250         ex eps = 1e-30*I;
251         ex s1 = Li(lst(1,1),lst(x,y));
252         ex s2 = log(1-1/x/y-eps)*log((1-1/x-eps)/(1/x/y-1/x)) + Li(2,(1-1/x/y-eps)/(1/x-1/x/y))
253                         - log(-1/x/y-eps)*log((-1/x-eps)/(1/x/y-1/x)) - Li(2,(-1/x/y-eps)/(1/x-1/x/y))
254                         - log(-1/x/y-eps)*log(1-1/x-eps) + log(-1/x/y-eps)*log(-1/x-eps);
255         res.append(s1.subs(lst(x==numeric(1)/2, y==3)) - s2.subs(lst(x==numeric(1)/2, y==3)));
256         res.append(s1.subs(lst(x==numeric(3)/2, y==numeric(1)/2)) - s2.subs(lst(x==numeric(3)/2, y==numeric(1)/2)));
257         res.append(s1.subs(lst(x==2, y==numeric(4)/5)) - s2.subs(lst(x==2, y==numeric(4)/5)));
258
259         // shuffle and quasi-shuffle identities
260         res.append(G(lst(0,0.2),1).hold() * G(lst(0.5),1).hold() - G(lst(0.5,0,0.2),1).hold()
261                         - G(lst(0,0.5,0.2),1).hold() - G(lst(0,0.2,0.5),1).hold());
262         res.append(G(lst(0,0.5),1).hold() * G(lst(0.6),1).hold() - G(lst(0,0.5,0.5*0.6),1).hold()
263                         - G(lst(0.6,0,0.5*0.6),1).hold() + G(lst(0,0,0.5*0.6),1).hold());
264         res.append(Li(lst(2),lst(numeric(1,5))).hold() * Li(lst(3),lst(7)).hold() - Li(lst(2,3),lst(numeric(1,5),7)).hold()
265                         - Li(lst(3,2),lst(7,numeric(1,5))).hold() - Li(lst(5),lst(numeric(7,5))).hold());
266         symbol a1, a2, a3, a4;
267         res.append((G(lst(a1,a2),1) * G(lst(a3,a4),1) - G(lst(a1,a2,a3,a4),1)
268                         - G(lst(a1,a3,a2,a4),1) - G(lst(a3,a1,a2,a4),1)
269                         - G(lst(a1,a3,a4,a2),1) - G(lst(a3,a1,a4,a2),1) - G(lst(a3,a4,a1,a2),1))
270                                 .subs(lst(a1==numeric(1)/10, a2==numeric(3)/10, a3==numeric(7)/10, a4==5)));
271         res.append(G(lst(-0.009),1).hold() * G(lst(-8,1.4999),1).hold() - G(lst(-0.009,-8,1.4999),1).hold()
272                         - G(lst(-8,-0.009,1.4999),1).hold() - G(lst(-8,1.4999,-0.009),1).hold());
273         res.append(G(lst(sqrt(numeric(1)/2)+I*sqrt(numeric(1)/2)),1).hold() * G(lst(1.51,-0.999),1).hold()
274                         - G(lst(sqrt(numeric(1)/2)+I*sqrt(numeric(1)/2),1.51,-0.999),1).hold()
275                         - G(lst(1.51,sqrt(numeric(1)/2)+I*sqrt(numeric(1)/2),-0.999),1).hold()
276                         - G(lst(1.51,-0.999,sqrt(numeric(1)/2)+I*sqrt(numeric(1)/2)),1).hold());
277         // checks for hoelder convolution which is used if one argument has a distance to one smaller than 0.01 
278         res.append(G(lst(0, 1.2, 1, 1.01), 1).hold() - G(lst(0, 1.2, 1, numeric("1.009999999999999999")), 1).hold());
279
280         for (lst::const_iterator it = res.begin(); it != res.end(); it++) {
281                 ex diff = abs((*it).evalf());
282                 if (diff > prec) {
283                         clog << *it << " seems to be wrong: " << diff << endl;
284                         result++;
285                 }
286                 cout << "." << flush;
287         }
288
289         return result;
290 }
291
292
293 ////////////////////////////////////////////////////////////////////////////////
294 ////////////////////////////////////////////////////////////////////////////////
295 //  legacy exam - checking for historical bugs
296 ////////////////////////////////////////////////////////////////////////////////
297 ////////////////////////////////////////////////////////////////////////////////
298
299
300 static unsigned inifcns_test_legacy()
301 {
302         Digits = 17;
303         ex prec = 5 * pow(10, -(int)Digits);
304
305         unsigned result = 0;
306
307         ex r1 = zeta(lst(1,1,1,1,1,1),lst(-1,-1,-1,1,1,1));
308         if ((r1.evalf() - numeric("-0.0012588769028204890704")) > prec) {
309                 clog << "zeta({1,1,1,1,1,1},{-1,-1,-1,1,1,1}) seems to be wrong." << endl;
310                 result++;
311         }
312
313         ex x1 = exp(2*Pi*I/13).evalf();
314         ex x2 = exp(24*Pi*I/13).evalf();
315         ex r2 = Li(lst(2),lst(x1)).hold().evalf();
316         ex r3 = Li(lst(2),lst(x2)).hold().evalf();
317         if ( abs(r2-conjugate(r3)) > prec ) {
318                 clog << "Legacy test 2 seems to be wrong." << endl;
319                 result++;
320         }
321
322         ex x3 = exp(5*Pi*I/3).evalf();
323         ex r4 = Li(lst(3),lst(x3)).hold().evalf();
324         if ( abs(r4 - numeric("0.40068563438653142847-0.95698384815740185713*I")) > prec ) {
325                 clog << "Legacy test 3 seems to be wrong." << endl;
326                 result++;
327         }
328
329         Digits = 100;
330         prec = 5 * pow(10, -(int)Digits);
331         ex x0 = 1.;
332            x1 = exp(Pi*I/3).evalf();
333            x2 = exp(2*Pi*I/3).evalf();
334            x3 = -1.;
335         ex x4 = exp(4*Pi*I/3).evalf();
336         ex x5 = exp(5*Pi*I/3).evalf();
337
338         ex r5 = Li(lst(1,1,1,1),lst(x2,x4,x3,x0)).hold().evalf();
339         ex r6 = Li(lst(1,1,1,1),lst(x4,x2,x3,x0)).hold().evalf();
340         if ( abs(r5-conjugate(r6)) > prec ) {
341                 clog << "Legacy test 4 seems to be wrong." << endl;
342                 result++;
343         }
344
345         ex r7 = Li(lst(1,2,1),lst(x3,x2,x4)).hold().evalf()
346                 +Li(lst(1,1,2),lst(x3,x2,x4)).hold().evalf()
347                 +Li(lst(1,1,1,1),lst(x3,x0,x2,x4)).hold().evalf()
348                 +Li(lst(1,1,1,1),lst(x3,x2,x0,x4)).hold().evalf()
349                 +Li(lst(1,1,1,1),lst(x3,x2,x4,x0)).hold().evalf()
350                 +Li(lst(1,2,1),lst(x2,x1,x0)).hold().evalf()
351                 +Li(lst(1,1,2),lst(x2,x3,x4)).hold().evalf()
352                 +Li(lst(1,1,1,1),lst(x2,x4,x3,x0)).hold().evalf()
353                 +Li(lst(1,1,1,1),lst(x2,x3,x4,x0)).hold().evalf()
354                 +Li(lst(1,1,1,1),lst(x2,x3,x0,x4)).hold().evalf()
355                 +Li(lst(2,2),lst(x5,x4)).hold().evalf()
356                 +Li(lst(2,1,1),lst(x5,x0,x4)).hold().evalf()
357                 +Li(lst(2,1,1),lst(x5,x4,x0)).hold().evalf()
358                 -Li(lst(1,1),lst(x3,x0)).hold().evalf()*Li(lst(1,1),lst(x2,x4)).hold().evalf();
359         if ( abs(r7) > prec ) {
360                 clog << "Legacy test 5 seems to be wrong." << endl;
361                 result++;
362         }
363
364         return result;
365 }
366
367
368 unsigned exam_inifcns_nstdsums(void)
369 {
370         unsigned result = 0;
371         
372         cout << "examining consistency of nestedsums functions" << flush;
373         
374         result += inifcns_test_zeta();
375         result += inifcns_test_S();
376         result += inifcns_test_HLi();
377         result += inifcns_test_LiG();
378         result += inifcns_test_legacy();
379         
380         return result;
381 }
382
383 int main(int argc, char** argv)
384 {
385         return exam_inifcns_nstdsums();
386 }