-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Description
It seems like sometimes some cancellations involving logarithms are not taken into account by .limit
. Here is an example:
>>> a, b, c = sym.symbols('a, b, c', positive=True)
>>> A = sym.log(a/b) - (sym.log(a) - sym.log(b))
>>> A.limit(a, sym.oo)
0 # correct
>>> (A * c).limit(a, sym.oo)
-c*log(b) # wrong!!
The expression A
is equivalent to zero, so its limit is (correctly) picked up as zero. However, when I multiply it by a symbol, the cancellation is not picked up. This doesn't happen when c
is a concrete number, or when a, b
are not declared positive
.
This may seem like a trivial problem and one that I shouldn't need SymPy for, but I actually came across it when doing something much more complicated, which boils down to lome logarithms. Here it is, for completeness:
>>> tau, x, c = sym.symbols('tau, x, c', positive=True)
>>> res = manualintegrate(1 / x / (1+x)**2 * tau**2 / (tau**2 + x**2) * x**2, x)
>>> res.limit()
0 # wrong, with consequences for my research
>>> res.simplify().limit()
pi*tau**3/(tau**2 + 1)**2 # correct
>>> res.series(x, sym.oo, 1).removeO()
pi*tau**3/(tau**4 + 2*tau**2 + 1) # also correct
In this example, if I omit the positive=True
, even the second result (taking the limit after .simplify()
) is wrong: it also gives zero! The series expansion remains correct.
(I'm running version 1.8, apologies, if this has been fixed since the latest release.)