]> www.ginac.de Git - ginac.git/blob - check/exam_inifcns_nstdsums.cpp
0ad9f1a80fc1e34d08285dca689a8c852a277e1e
[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 struct point
30 {
31         ex x;
32         ex res;
33 };
34
35
36 const int NDIM = 5;
37 const int PDIM = 5;
38
39 typedef vector<point> vp;
40
41 vp pp[NDIM][PDIM];
42
43
44 static unsigned inifcns_consist_S(void)
45 {
46         unsigned result = 0;
47         
48         ifstream in("exam_inifcns_nstdsums_data");
49
50         if (!in) {
51                 clog << "exam_inifcns_nstdsums_data not readable!" << endl;
52                 return 666;
53         }
54
55         string str;
56         point ppbuf;
57
58         while (1) {
59                 getline(in,str);
60                 if (!in)
61                         break;
62                 ex en(str,symbol());
63                 getline(in,str);
64                 if (!in)
65                         break;
66                 ex ep(str,symbol());
67                 getline(in,str);
68                 if (!in)
69                         break;
70                 ex x(str,symbol());
71                 getline(in,str);
72                 if (!in)
73                         break;
74                 ex res(str,symbol());
75
76                 numeric n = ex_to<numeric>(en);
77                 numeric p = ex_to<numeric>(ep);
78
79                 ppbuf.x = x;
80                 ppbuf.res = res;
81
82                 pp[n.to_int()-1][p.to_int()-1].push_back(ppbuf);
83         }
84
85         in.close();
86
87         vp::iterator it;
88         int error = 0;
89
90         cout << endl << "Calculating ";
91         for (int sum=2; sum<=3; sum++) {
92                 for (int nn=1; nn<sum; nn++) {
93                         vp& da = pp[nn-1][sum-nn-1];
94                         for (it = da.begin(); it!=da.end(); it++) {
95                                 cout << "S(" << nn << "," << sum-nn << "," << it->x << ") " << flush;
96                                 ex res = S(nn,sum-nn,it->x).evalf();
97                                 if (!is_a<numeric>(res)) {
98                                         if ((it->x != -1) || ((sum-nn) == 1)) {
99                                                 clog << "S(" << nn << "," << sum-nn << "," << it->x << ") didn't give numerical result!" << endl;
100                                                 result++;
101                                         }
102                                 } 
103                                 else {
104                                         ex reldiff = abs((it->res-res)/it->res);
105                                         if ((!is_a<numeric>(res)) || (reldiff > numeric("1E-10"))) {
106                                                 clog << "S(" << nn << "," << sum-nn << "," << it->x << ") seems to be wrong:" << endl;
107                                                 clog << "GiNaC           : " << res << endl;
108                                                 clog << "Reference       : " << it->res << endl;
109                                                 clog << "Abs. Difference : " << it->res-res << endl;
110                                                 clog << "Rel. Difference : " << reldiff << endl;
111                                                 result++;
112                                         }
113                                 }
114                         }
115                 }
116
117         }
118         cout << endl;
119
120         return result;
121 }
122
123
124 unsigned exam_inifcns_nstdsums(void)
125 {
126         unsigned result = 0;
127         
128         cout << "examining consistency of nestedsums functions" << flush;
129         clog << "----------consistency of nestedsums functions:" << endl;
130         
131         result += inifcns_consist_S();  cout << '.' << flush;
132         
133         if (!result) {
134                 cout << " passed " << endl;
135                 clog << "(no output)" << endl;
136         } else {
137                 cout << " failed " << endl;
138         }
139         
140         return result;
141 }
142