Gentlemen, I came across a small problem, when calculating series expansions. The following code hangs, when attempting to compute the expansion: #include <iostream> #include <ginac/ginac.h> using namespace std; using namespace GiNaC; int main() { symbol x("x"); ex e1 = pow(2,x)*( 1/x*(-(1+x)/(1-x)) + (1+x)/x/(1-x)); cout << e1 << endl; cout << e1.expand() << endl; cout << e1.series(x,1) << endl; } I tried it with GiNaC 1.3.7 as well as 1.3.1 and 1.3.0. e1 is actually a complicated zero, and the correct answer should we O(x). Best wishes, Stefan
Dear Stefan,
I came across a small problem, when calculating series expansions. The following code hangs, when attempting to compute the expansion:
Yes, this is a known problem. It is not that easy to solve in general, unfortunately. If I finish my patch for introducing inner products into GiNaC, I think I will have a look at this. Best wishes, Chris
Dear Chris, attached is a patch (against GiNaC 1.3.7) which should fix the problem. A few explanations: If one does a series expansion up to n of a product A*B we have to know the ldegree of B in order to determine how far we have to expand A (and vice versa). Currently the implementation finds for each factor the ldegree first, by expanding it to order 1,2,3,4,etc until a non-vanishing ldegree is found. If a factor is a complicated zero, a non-vanishing ldegree is never found and the algorithms loops for eternity. In addition, this is quite inefficient, if a factor has a large ldegree: Then this factor is expanded up to its ldegree, although we only asked for an expansion up to n. The patch splits the computation of the ldegrees into two stages: In the first stage all negative ldegrees are computed.
Dear Stefan,
attached is a patch (against GiNaC 1.3.7) which should fix the problem.
I committed this patch. Thanks for it. I also added the failed check that you posted to the exams. BTW: if you submit any more patches, could you please make a diff from the old file to the new instead of the other way around? Best wishes, Chris
participants (3)
-
Chris Dams
-
Chris.Dams@mi.infn.it
-
Stefan Weinzierl