[GiNaC-list] Fwd: Performance problem with series

Frieder Kalisch kalisch at tphys.uni-heidelberg.de
Wed Jan 19 16:53:03 CET 2005


Hi,

here is a very odd performance behaviour of ginac/series: The operation

ex e = 1/(a+sqrt(b*b+x*x));
e = e.series(x==1, 21);

is more than a factor of 10^4(!) faster then outputting the result using
cout << e << endl;
I have measured these times using clocks(). You find the source of the program 
at the end of this email.

What does this mean? This means, that series is very efficient (both time- and 
space-wise), because it reuses intermediate results heavily. On the other 
hand the result is nearly useless, because it is actually _very_ complicated, 
which shows up in any subsequent usage.

In this specific example, a hand-written taylor-series using derivatives was 2 
orders of magnitude slower (for 60th order) to compute the series, but the 
series (20th order) still was printed 1000 times faster than the standard 
series.

In the light of this finding, something needs to be done. I suggest to 
essentially revert the logic of series, namely to compute series by 
differentiation and to fall back to an explicit composition if it does not 
work. Mathematica does it that way according to its documentation. At least 
ginac should provide this mode as an option, either by an additional taylor() 
method for ex or by means of series_options.

Do You agree with this analysis and my conclusions? Are there any other ways 
to solve this problem?

Regards

             Frieder Kalisch

#include <ginac/ginac.h>
#include <iostream>
#include <ctime>

using namespace GiNaC;
using namespace std;

int main(int argc, char **argv)
{
  time_t t0, t1, t2;

  t0 = clock();

  symbol x("x"), a("a"), b("b");

  ex e = 1/(a+sqrt(b*b+x*x));
  e = e.series(x==1, 21);

  t1 = clock();

  cout << e << endl;

  t2 = clock();

  double res = CLOCKS_PER_SEC;

  cerr << (t1-t0)/res << endl
       << (t2-t1)/res << endl;
  return 0;
} // int main(int argc, char **argv)

--
Frieder Kalisch                        Institut für theoretische Physik
kalisch at tphys.uni-heidelberg.de         Philosophenweg 19
+49-6221-549-433                        D-69120 Heidelberg




More information about the GiNaC-list mailing list