Hello! On Mon, Feb 12, 2007 at 12:55:41AM +0000, Vladimir Kisil wrote:
Dear All,
I come across an inability of GiNaC to compute simple series, e.g. in the following example:
#include <iostream> #include <ginac/ginac.h> using namespace std; using namespace GiNaC;
int main(){ possymbol t("t"); cout << pow(2-sqrt(1-t), -1).series(t==0,2) << endl; cout << pow(1-sqrt(1-pow(t,2)), -1).series(t==0,2) << endl; }
BTW, series((1+exp(t), -4), t, 2); works just fine, because (1+exp(t)).ldegree(t) returns zero. I think it should throw an exception just like (1+sqrt(t)).ldegree(t) does.
Index: ginac/pseries.cpp =================================================================== RCS file: /home/cvs/GiNaC/ginac/pseries.cpp,v retrieving revision 1.90 diff -u -r1.90 pseries.cpp --- ginac/pseries.cpp 31 Jan 2007 22:29:20 -0000 1.90 +++ ginac/pseries.cpp 12 Feb 2007 01:02:56 -0000 @@ -1072,7 +1072,11 @@ } const ex& sym = r.lhs(); // find existing minimal degree - int real_ldegree = basis.expand().ldegree(sym-r.rhs()); + int real_ldegree; + try { + real_ldegree = basis.expand().ldegree(sym-r.rhs()); + } catch (std::runtime_error) { }
I don't think ignoring such a generic exception is a good idea. It just hides the bug instead of fixing it. And probably introduces even more bugs... I propose this patch instead: [PATCH] power::series: fix failure when basis is not a rational function Fixes failure to compute series such as (in ginsh notation) series((1+sqrt(1-t))^(-1), t, 2); unable to compute series (power::ldegree(): undefined degree because of non-integer exponent) --- ginac/pseries.cpp | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/ginac/pseries.cpp b/ginac/pseries.cpp index db7cef3..ca14c60 100644 --- a/ginac/pseries.cpp +++ b/ginac/pseries.cpp @@ -1072,7 +1072,10 @@ ex power::series(const relational & r, int order, unsigned options) const } const ex& sym = r.lhs(); // find existing minimal degree - int real_ldegree = basis.expand().ldegree(sym-r.rhs()); + ex eb = basis.expand(); + int real_ldegree = 0; + if (eb.info(rational_function)) + real_ldegree = eb.ldegree(sym-r.rhs()); if (real_ldegree == 0) { int orderloop = 0; do { -- 1.4.4.4 Best regards, Alexei -- All science is either physics or stamp collecting.