pole_error when expanding power into series
series(cos(x)^(sin(x)/x),x==0,5);
series(((a^x+b^x)/2)^(1/x),x==0,2);
Hello, I recently came across Ginac and I found it was an excellent tool. The speed of series expansion is amazing compared to my hand-held calculator. However, ginac 1.5.8 is unable to expand expressions like : cos(x)^(sin(x)/x), even if it expands well sin(x)/x. Using ginac compiled from git some days ago, ginac-git/ginsh/ginsh [...] power::eval(): division by zero power::eval(): division by zero I found out that was caused by ginac's attempt to use taylor formula in these cases (in power::series in pseries.cpp line 1129 and 1134). I give you a patch for it, that enables that kind of calculations : (in patched ginsh)
series(cos(x)^(sin(x)/x),x==0,5); 1+(-1/2)*x^2+1/8*x^4+Order(x^5) series(((a^x+b^x)/2)^(1/x),x==0,2); (exp(1/2*log(b)+1/2*log(a)))+(-1/8*exp(1/2*log(b)+1/2*log(a))*(2*log(b)*log(a)- log(a)^2-log(b)^2))*x+Order(x^2)
(or human-simplified sqrt(a*b)+(1/8*sqrt(a*b)*(log(a)-log(b))^2*x+Order(x^2) ) The exponential simplification is none of my abilities in Ginac. Bye Camille Gillot
Hello, On Tue, Nov 2, 2010 at 1:34 PM, Camille Gillot <k1000.jlo@wanadoo.fr> wrote:
However, ginac 1.5.8 is unable to expand expressions like :
cos(x)^(sin(x)/x), even if it expands well sin(x)/x.
+ if(!is_a<numeric>(exponent)) { + ex new_exponent = (exponent*log(basis)).series(r,order,options); + return exp(new_exponent).series(r,order,options); + }
I think such transformation is way too aggressive (the exponent might not depend on x, there might be no singularity at all, etc). I'll try to fix this in a more careful way. Best regards, Alexei
You're absolutely right. The is_a<numeric>(exponent) test should be replaced by just a exponent.has(r.lhs()). Another version may be :
if(exponent.has(r.lhs())) { try { // detect exponent singularity exponent.subs(r);
// if none, try taylor return basic::series(r, order, options);
} catch(pole_error &) { // in case of singularity, use this ex new_e = exponent*log(basis); new_e = new_e.series(r,order,options); return exp(new_e).series(r,order,options); } }
I don't know which version is the best, this one will speed up the simple series, but will try twice for the singularities. Thanks for taking time fixing this. C. Gillot Le mardi 02 novembre 2010 15:35:00, Alexei Sheplyakov a écrit :
Hello,
On Tue, Nov 2, 2010 at 1:34 PM, Camille Gillot <k1000.jlo@wanadoo.fr> wrote:
However, ginac 1.5.8 is unable to expand expressions like :
cos(x)^(sin(x)/x), even if it expands well sin(x)/x.
+ if(!is_a<numeric>(exponent)) { + ex new_exponent = (exponent*log(basis)).series(r,order,options); + return exp(new_exponent).series(r,order,options); + }
I think such transformation is way too aggressive (the exponent might not depend on x, there might be no singularity at all, etc). I'll try to fix this in a more careful way.
Best regards, Alexei _______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de https://www.cebix.net/mailman/listinfo/ginac-list
participants (2)
-
Alexei Sheplyakov
-
Camille Gillot