On Tue, 25 Aug 2009, Stefano Ferri wrote:
< I hope not to be bugging you too much if I ask you some details about
< your code... It works fine for my purpose, but for me it is not so
< elementary to understand as you said before... I thougth I did
< understand it, but it's not so... my ignorance...
< I've also noticed that ratlimit is as slow as tlimit if I do
< expand(u), it's because of its dependance on num and denom? Moreover,
< these two functions yields different results if called on a factored
< or an expanded expression. Ratlimit gets rid of these problems?
Stefano,
I don't have a good answer to your question, because the answer requires
an understanding of the source code. However, I figured that since the
limit of a rational function is essentially a simple algebraic computation, it
would be possible to write a special purpose procedure that outperformed
the more general routines.
I have rewritten ratlimit to take into account your comment about
expand(u), and Stavros' comments. I think you'll find it works much
faster, and doesn't produce the silly errors noted by Stavros.
As always: caveat emptor.
Leo
Sample output:
(%i9) ratlimit(u,_bk,inf)
Evaluation took 0.1400 seconds (0.1400 elapsed) using 2.915 MB.
(%o9) -l^3*q/(24*E*I)
(%i10) tlimit(u,_bk,inf)
Evaluation took 5.2200 seconds (5.2100 elapsed) using 117.831 MB.
(%o10) -l^3*q/(24*E*I)
(%i11) ratlimit(1/u+u,_bk,inf)
Evaluation took 0.3400 seconds (0.3300 elapsed) using 6.066 MB.
(%o11) -24*E*I/(l^3*q)-l^3*q/(24*E*I)
(%i12) tlimit(1/u+u,_bk,inf)
Evaluation took 10.0800 seconds (10.0900 elapsed) using 227.069 MB.
(%o12) -(576*E^2*I^2+l^6*q^2)/(24*l^3*q*E*I)
(%i13) ratlimit(v,_bk,inf)
Evaluation took 1.3500 seconds (1.3600 elapsed) using 25.945 MB.
(%o13) -l^3*q/(24*E*I)
(%i14) tlimit(v,_bk,inf)
Evaluation took 5.4600 seconds (5.4500 elapsed) using 119.985 MB.
(%o14) -l^3*q/(24*E*I)
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
-------------- next part --------------
/* -*- Mode: maxima; Package: MAXIMA -*- */
/*
* $Id: ratlimit.mac,v 1.1 2009/08/26 16:34:09 work Exp work $
*
* Author: Leo Butler (l.butler at ed.ac.uk)
*
* This file contains Maxima code (http://maxima.sourceforge.net/)
*
* It is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This software is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this file. If not, see http://www.gnu.org/licenses/.
*/
kill(ratlimit)$
declare(ratlimit,additive)$
declare(ratlimit,multiplicative)$
ratlimit(f,x,l) :=
if atom(f) then limit(f,x,l)
elseif op(f)="/" then block([d,n,dd],
d : denom(f),
n : num(f),
dd : hipow(d,x),
d : tlimit(x^(-dd)*d,x,l),
n : tlimit(x^(-dd)*n,x,l),
n/d)
elseif op(f)="*" or op(f)="+" then limit(map(lambda([_t],ratlimit(_t,x,l)),f)) /*use limit(..) to convert inf+1->inf*/
else limit(f,x,l)$
/* Test cases */
u : ((995328*sqrt(2)*l*q*A^3*E^8-5971968*l^2*q*_bk*A^2*E^7
+5971968*sqrt(2)*l^3*q*_bk^2*A*E^6
-3981312*l^4*q*_bk^3*E^5)
*I^5
+(82944*sqrt(2)*l^3*q*A^4*E^8-995328*l^4*q*_bk*A^3*E^7
+995328*sqrt(2)*l^5*q*_bk^2*A^2*E^6
+663552*l^6*q*_bk^3*A*E^5
-995328*sqrt(2)*l^7*q*_bk^4*E^4)
*I^4
+(-41472*l^6*q*_bk*A^4*E^7+48384*sqrt(2)*l^7*q*_bk^2*A^3*E^6
+290304*l^8*q*_bk^3*A^2*E^5
-207360*sqrt(2)*l^9*q*_bk^4*A*E^4
-193536*l^10*q*_bk^5*E^3)
*I^3
+(31104*l^10*q*_bk^3*A^3*E^5-20736*sqrt(2)*l^11*q*_bk^4*A^2*E^4
-48384*l^12*q*_bk^5*A*E^3
-9216*sqrt(2)*l^13*q*_bk^6*E^2)
*I^2
+(1296*l^12*q*_bk^3*A^4*E^5-1620*sqrt(2)*l^13*q*_bk^4*A^3*E^4
-4968*l^14*q*_bk^5*A^2*E^3
-1848*sqrt(2)*l^15*q*_bk^6*A*E^2
-432*l^16*q*_bk^7*E)
*I-81*sqrt(2)*l^15*q*_bk^4*A^4*E^4-216*l^16*q*_bk^5*A^3*E^3
-108*sqrt(2)*l^17*q*_bk^6*A^2*E^2-48*l^18*q*_bk^7*A*E
-4*sqrt(2)*l^19*q*_bk^8)
/((1990656*sqrt(2)*A^4*E^9-15925248*l*_bk*A^3*E^8
+23887872*sqrt(2)*l^2*_bk^2*A^2*E^7
-31850496*l^3*_bk^3*A*E^6
+7962624*sqrt(2)*l^4*_bk^4*E^5)
*I^5
+(-1990656*l^3*_bk*A^4*E^8+5308416*sqrt(2)*l^4*_bk^2*A^3*E^7
-7962624*l^5*_bk^3*A^2*E^6
+2654208*l^7*_bk^5*E^4)
*I^4
+(373248*sqrt(2)*l^6*_bk^2*A^4*E^7-995328*l^7*_bk^3*A^3*E^6
-165888*sqrt(2)*l^8*_bk^4*A^2*E^5
+663552*l^9*_bk^5*A*E^4
+165888*sqrt(2)*l^10*_bk^6*E^3)
*I^3
+(-62208*l^9*_bk^3*A^4*E^6+82944*l^11*_bk^5*A^2*E^4
+36864*sqrt(2)*l^12*_bk^6*A*E^3
+9216*l^13*_bk^7*E^2)
*I^2
+(1944*sqrt(2)*l^12*_bk^4*A^4*E^5+5184*l^13*_bk^5*A^3*E^4
+2592*sqrt(2)*l^14*_bk^6*A^2*E^3
+1152*l^15*_bk^7*A*E^2
+96*sqrt(2)*l^16*_bk^8*E)
*I)$
v : expand(u)$
ratlimit(u,_bk,inf);
tlimit(u,_bk,inf);
ratlimit(u+1/u,_bk,inf);
tlimit(u+1/u,_bk,inf);
ratlimit(v,_bk,inf);
tlimit(v,_bk,inf);
ratlimit(exp(-x)/x,x,inf);
ratlimit(exp(x)/(x^2+1),x,inf);
ratlimit(exp(x)/(x^2+1)+1,x,inf);