]> www.ginac.de Git - ginac.git/blob - check/time_gammaseries.cpp
Explicit function disambiguation.
[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-2010 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 "ginac.h"
24 #include "timer.h"
25 using namespace GiNaC;
26
27 #include <iostream>
28 #include <vector>
29 using namespace std;
30
31 unsigned tgammaseries(unsigned order)
32 {
33         unsigned result = 0;
34         symbol x;
35
36         ex myseries = series(GiNaC::tgamma(x),x==0,order);
37         // compute the last coefficient numerically:
38         ex last_coeff = myseries.coeff(x,order-1).evalf();
39         // compute a bound for that coefficient using a variation of the leading
40         // term in Stirling's formula:
41         ex bound = exp(-.57721566490153286*(order-1))/(order-1);
42         if (abs((last_coeff-pow(-1,ex(order)))/bound) > 1) {
43                 clog << "The " << order-1
44                      << "th order coefficient in the power series expansion of tgamma(0) was erroneously found to be "
45                      << last_coeff << ", violating a simple estimate." << endl;
46                 ++result;
47         }
48
49         return result;
50 }
51
52 unsigned time_gammaseries()
53 {
54         unsigned result = 0;
55
56         cout << "timing Laurent series expansion of Gamma function" << flush;
57
58         vector<unsigned> sizes;
59         vector<double> times;
60         timer omega;
61
62         sizes.push_back(20);
63         sizes.push_back(25);
64         sizes.push_back(30);
65         sizes.push_back(35);
66
67         for (vector<unsigned>::iterator i=sizes.begin(); i!=sizes.end(); ++i) {
68                 omega.start();
69                 result += tgammaseries(*i);
70                 times.push_back(omega.read());
71                 cout << '.' << flush;
72         }
73
74         // print the report:
75         cout << endl << "       order: ";
76         for (vector<unsigned>::iterator i=sizes.begin(); i!=sizes.end(); ++i)
77                 cout << '\t' << *i;
78         cout << endl << "       time/s:";
79         for (vector<double>::iterator i=times.begin(); i!=times.end(); ++i)
80                 cout << '\t' << *i;
81         cout << endl;
82         
83         return result;
84 }
85
86 extern void randomify_symbol_serials();
87
88 int main(int argc, char** argv)
89 {
90         randomify_symbol_serials();
91         cout << setprecision(2) << showpoint;
92         return time_gammaseries();
93 }