Skip to content

residue(exp(-1 / z), z, 0) gives wrong answer #27156

Open
@yang-tsao

Description

When I run the following code:

from sympy import *
z = Symbol("z")
print(residue(exp(-1 / z), z, 0))

It prints $0$. However, the residue should be $-1$.
Proof:

$$e^z=1+\frac{z}{1!}+\frac{z^2}{2!}+\frac{z^3}{3!}+\cdots$$

This may also be written in the following manner.

$$e^z=\sum_{j=0}^\infty \frac{{z}^j}{j!}$$

Now, for $f(z)=e^{-1/z}$ (which happens to have a singularity at $z=0$) we can write:

$$e^{-\frac{1}{z}}=\sum_{j=0}^\infty \frac{(\frac{1}{-z})^j}{j!}=\sum_{j=0}^\infty \frac{(-1)^j}{j!\cdot z^j}$$

We know the residue would be the coefficient of the term containing the $−1^\text{th}$ power of $(z−z_o)$.
Coefficent of $j^\text{th}$ term would be:

$$\frac{(-1)^j}{j!}$$

Clearly, the term we're looking for can be obtained at $j=1$.
So,

$$\mathrm{Res}(e^{-\frac{1}{z}})=-1$$

It seems that in sympy/series/residues.py, the expansion only considers $x$ approaching from $+$ direction (default option for nseries).

for n in (0, 1, 2, 4, 8, 16, 32):
    s = expr.nseries(x, n=n)
    if not s.has(Order) or s.getn() >= 0:
        break

Taking the '-' direction into consideration may alleviate this problem. However, as the series is complex, it is still not rigorous:

for n in (0, 1, 2, 4, 8, 16, 32):
    s = expr.nseries(x, n=n, dir="+-")
    if not s.has(Order) or s.getn() >= 0:
        break

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions