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; } A simple patch included in the attachment seems to solve the issue. Best wishes, Vladimir -- Vladimir V. Kisil email: kisilv@maths.leeds.ac.uk -- www: http://maths.leeds.ac.uk/~kisilv/
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.
Dear Alexei, On Mon, 12 Feb 2007, Sheplyakov Alexei wrote:
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.
Agreed, ldegree should only work on things for which it makes sense. If you like to write a patch, I'll commit it. Besides that, our series expansion algorithms generally suck horribly. Maybe, I'll try writing something better sometime. Who knows.
[PATCH] power::series: fix failure when basis is not a rational function
Thanks, comitted now in 1.4. I'll also do 1.3. Best wishes, Chris
Chris Dams wrote:
Besides that, our series expansion algorithms generally suck horribly. Maybe, I'll try writing something better sometime. Who knows.
Doing recurrence relations, like Jens suggested last year? <http://www.ginac.de/pipermail/ginac-devel/2006-April/000954.html> AFAIK, this way, it would be possible to implement reasonably effective limit computations, too. It might be worth having a look at the PhD thesis of Dominik Gruntz: <ftp://ftp.inf.ethz.ch/pub/publications/dissertations/th11432.ps.gz>. Cheers -richy. -- Richard B. Kreckel <http://www.ginac.de/~kreckel/>
Hi! Vladimir Kisil wrote:
/home/amsta/kisilv/GiNaC 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) { } + if (real_ldegree == 0) { int orderloop = 0; do {
Vladimir, what've you been smoking?!? That variable is uninitialized, now. Cheers -richy. -- Richard B. Kreckel <http://www.ginac.de/~kreckel/>
"RC" == Richard B Kreckel <kreckel@ginac.de> writes: RC> Vladimir, what've you been smoking?!? That variable is RC> uninitialized, now.
My compiler seems to assign the zero at initialisation. Of course, this may be made explicitly as in the patch by Alexei, which is better anyway. Best, -- Vladimir V. Kisil email: kisilv@maths.leeds.ac.uk -- www: http://maths.leeds.ac.uk/~kisilv/
participants (4)
-
Chris Dams
-
Richard B. Kreckel
-
varg@theor.jinr.ru
-
Vladimir Kisil