]> www.ginac.de Git - ginac.git/blob - check/time_gammaseries.cpp
multiple zeta values: make crandall_Z helper function reentrant.
[ginac.git] / check / time_gammaseries.cpp
1 /** @file time_gammaseries.cpp
2  *
3  *  Some timings on series expansion of the Gamma function around a pole. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2008 Johannes Gutenberg University Mainz, Germany
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #include <iostream>
24 #include <vector>
25 #include "ginac.h"
26 #include "timer.h"
27 using namespace std;
28 using namespace GiNaC;
29
30 unsigned tgammaseries(unsigned order)
31 {
32         unsigned result = 0;
33         symbol x;
34
35         ex myseries = series(tgamma(x),x==0,order);
36         // compute the last coefficient numerically:
37         ex last_coeff = myseries.coeff(x,order-1).evalf();
38         // compute a bound for that coefficient using a variation of the leading
39         // term in Stirling's formula:
40         ex bound = exp(-.57721566490153286*(order-1))/(order-1);
41         if (abs((last_coeff-pow(-1,order))/bound) > 1) {
42                 clog << "The " << order-1
43                      << "th order coefficient in the power series expansion of tgamma(0) was erroneously found to be "
44                      << last_coeff << ", violating a simple estimate." << endl;
45                 ++result;
46         }
47
48         return result;
49 }
50
51 unsigned time_gammaseries()
52 {
53         unsigned result = 0;
54
55         cout << "timing Laurent series expansion of Gamma function" << flush;
56
57         vector<unsigned> sizes;
58         vector<double> times;
59         timer omega;
60
61         sizes.push_back(20);
62         sizes.push_back(25);
63         sizes.push_back(30);
64         sizes.push_back(35);
65
66         for (vector<unsigned>::iterator i=sizes.begin(); i!=sizes.end(); ++i) {
67                 omega.start();
68                 result += tgammaseries(*i);
69                 times.push_back(omega.read());
70                 cout << '.' << flush;
71         }
72
73         // print the report:
74         cout << endl << "       order: ";
75         for (vector<unsigned>::iterator i=sizes.begin(); i!=sizes.end(); ++i)
76                 cout << '\t' << *i;
77         cout << endl << "       time/s:";
78         for (vector<double>::iterator i=times.begin(); i!=times.end(); ++i)
79                 cout << '\t' << *i;
80         cout << endl;
81         
82         return result;
83 }
84
85 extern void randomify_symbol_serials();
86
87 int main(int argc, char** argv)
88 {
89         randomify_symbol_serials();
90         cout << setprecision(2) << showpoint;
91         return time_gammaseries();
92 }