1 /** @file time_gammaseries.cpp
3 * Some timings on series expansion of the Gamma function around a pole. */
6 * GiNaC Copyright (C) 1999-2015 Johannes Gutenberg University Mainz, Germany
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.
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.
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
25 using namespace GiNaC;
31 unsigned tgammaseries(unsigned order)
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;
52 unsigned time_gammaseries()
56 cout << "timing Laurent series expansion of Gamma function" << flush;
58 vector<unsigned> sizes;
67 for (vector<unsigned>::iterator i=sizes.begin(); i!=sizes.end(); ++i) {
69 result += tgammaseries(*i);
70 times.push_back(omega.read());
75 cout << endl << " order: ";
76 for (vector<unsigned>::iterator i=sizes.begin(); i!=sizes.end(); ++i)
78 cout << endl << " time/s:";
79 for (vector<double>::iterator i=times.begin(); i!=times.end(); ++i)
86 extern void randomify_symbol_serials();
88 int main(int argc, char** argv)
90 randomify_symbol_serials();
91 cout << setprecision(2) << showpoint;
92 return time_gammaseries();