synced to 1.2
[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  * The data in the following include file has been produced by the following
31  * Mathematica (V4.1) script:
32  *
33  *
34  *    x={0.2,0.7 ,1,1.4,3.0 }
35  *    y={0,0.3,-0.8,3.0}
36  *    st = OpenAppend["exam_inifcns_nstdsums_data.raw"]
37  *    Do[
38  *      Do[
39  *        Do[Write[st, i]; Write[st,j]; Write[st,x[[k]]+I*y[[l]]];
40  *          Write[ st,N[PolyLog[i,j,x[[k]]+I*y[[l]]]]],{i,3},{j,3}], {k,5}],{l,4}]
41  *    Do[
42  *      Do[
43  *        Do[Write[st, i]; Write[st,j]; Write[st,-x[[k]]+I*y[[l]]];
44  *          Write[ st,N[PolyLog[i,j,-x[[k]]+I*y[[l]]]]],{i,3},{j,3}], {k,5}], {l,4}]
45  *    Close[st]
46  *
47  *    
48  * and postprocessed by the following shell script
49  *
50  *
51  *    #/bin/sh
52  *    IFS=$'\n'
53  *    cat exam_inifcns_nstdsums_data.raw | sed -e 's/\*\^/E/g' > exam_inifcns_nstdsums_data.raw2
54  *    echo 'string data[] = {' > exam_inifcns_nstdsums_data.raw3
55  *    for i in `cat exam_inifcns_nstdsums_data.raw2`; do echo \"$i\",; done >> exam_inifcns_nstdsums_data.raw3
56  *    echo '"-999"};' >> exam_inifcns_nstdsums.h
57  *
58  *
59  */
60 #include "exam_inifcns_nstdsums.h"
61
62
63 // adjust this if you want to process more S(n,p,x) data
64 const int MAX_NDIM = 5;
65 const int MAX_PDIM = 5;
66
67 // signals end of data
68 const int ENDMARK = -999;
69
70 struct point
71 {
72         ex x;
73         ex res;
74 };
75
76 typedef vector<point> vp;
77
78 vp pp[MAX_NDIM][MAX_PDIM];
79
80
81
82 static unsigned inifcns_consist_S(void)
83 {
84         unsigned result = 0;
85         
86         point ppbuf;
87         int i = 0;
88         while (true) {
89                 ex en(data[i++],symbol());
90                 if (en == ENDMARK) {
91                         break;
92                 }
93                 numeric n = ex_to<numeric>(en);
94                 ex ep(data[i++],symbol());
95                 numeric p = ex_to<numeric>(ep);
96                 ex x(data[i++],symbol());
97                 ex res(data[i++],symbol());
98                 
99                 ppbuf.x = x;
100                 ppbuf.res = res;
101
102                 pp[n.to_int()-1][p.to_int()-1].push_back(ppbuf);
103         }
104         
105         vp::iterator it;
106         int error = 0;
107
108         cout << endl << "Calculating ";
109         for (int sum=2; sum<=3; sum++) {
110                 for (int nn=1; nn<sum; nn++) {
111                         vp& da = pp[nn-1][sum-nn-1];
112                         for (it = da.begin(); it!=da.end(); it++) {
113                                 cout << "S(" << nn << "," << sum-nn << "," << it->x << ") " << flush;
114                                 ex res = S(nn,sum-nn,it->x).evalf();
115                                 if (!is_a<numeric>(res)) {
116                                         if ((it->x != -1) || ((sum-nn) == 1)) {
117                                                 clog << "S(" << nn << "," << sum-nn << "," << it->x << ") didn't give numerical result!" << endl;
118                                                 result++;
119                                         }
120                                 } 
121                                 else {
122                                         ex reldiff = abs((it->res-res)/it->res);
123                                         if ((!is_a<numeric>(res)) || (reldiff > numeric("1E-10"))) {
124                                                 clog << "S(" << nn << "," << sum-nn << "," << it->x << ") seems to be wrong:" << endl;
125                                                 clog << "GiNaC           : " << res << endl;
126                                                 clog << "Reference       : " << it->res << endl;
127                                                 clog << "Abs. Difference : " << it->res-res << endl;
128                                                 clog << "Rel. Difference : " << reldiff << endl;
129                                                 result++;
130                                         }
131                                 }
132                         }
133                 }
134
135         }
136         cout << endl;
137
138         return result;
139 }
140
141
142 unsigned exam_inifcns_nstdsums(void)
143 {
144         unsigned result = 0;
145         
146         cout << "examining consistency of nestedsums functions" << flush;
147         clog << "----------consistency of nestedsums functions:" << endl;
148         
149         result += inifcns_consist_S();  cout << '.' << flush;
150         
151         if (!result) {
152                 cout << " passed " << endl;
153                 clog << "(no output)" << endl;
154         } else {
155                 cout << " failed " << endl;
156         }
157         
158         return result;
159 }
160