1 /** @file time_gammaseries.cpp
3 * Some timings on series expansion of the Gamma function around a pole. */
6 * GiNaC Copyright (C) 1999-2004 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 unsigned tgammaseries(unsigned order)
30 ex myseries = series(tgamma(x),x==0,order);
31 // compute the last coefficient numerically:
32 ex last_coeff = myseries.coeff(x,order-1).evalf();
33 // compute a bound for that coefficient using a variation of the leading
34 // term in Stirling's formula:
35 ex bound = exp(-.57721566490153286*(order-1))/(order-1);
36 if (abs((last_coeff-pow(-1,order))/bound) > 1) {
37 clog << "The " << order-1
38 << "th order coefficient in the power series expansion of tgamma(0) was erroneously found to be "
39 << last_coeff << ", violating a simple estimate." << endl;
46 unsigned time_gammaseries(void)
50 cout << "timing Laurent series expansion of Gamma function" << flush;
51 clog << "-------Laurent series expansion of Gamma function:" << endl;
53 vector<unsigned> sizes;
62 for (vector<unsigned>::iterator i=sizes.begin(); i!=sizes.end(); ++i) {
64 result += tgammaseries(*i);
65 times.push_back(omega.read());
71 clog << "(no output)" << endl;
76 cout << endl << " order: ";
77 for (vector<unsigned>::iterator i=sizes.begin(); i!=sizes.end(); ++i)
79 cout << endl << " time/s:";
80 for (vector<double>::iterator i=times.begin(); i!=times.end(); ++i)
81 cout << '\t' << int(1000*(*i))*0.001;