Calculating $\int_0^{2\pi} (e^{it} - a)^k e^{int} dt$ I'm trying to calculate
$$ \int_0^{2\pi} (e^{it} - a)^k e^{int} dt$$
where $a \in \mathbb{C}$ and $k, n \in \mathbb{Z}$.
My first thought was the residue theorem but I end up with permutations of different cases depending on if $|a| > 1$, $k > n$, $k, n < 0$.  Is there a way to approach the integral that reduces the number of cases I need to consider?
 A: Substituting $e^{it}=z$ simplifies the integral to
$$-i\oint_{\text{unit circle}}(z-a)^kz^{n-1}\,dz$$
By the residue theorem this evaluates as
$$\newcommand{Res}{\operatorname{Res}}2\pi(\Res((z-a)^kz^{n-1},0)[n\le0]+\Res((z-a)^kz^{n-1},a)[|a|<1\land k\le-1])$$
where $[\cdot]$ is the Iverson bracket ($1$ if the predicate inside is true, $0$ otherwise). To evaluate the residues, the following two facts can be used:
$$\Res(z^{-n}(z-a)^m,0)=\begin{cases}
0&n\le0\\
\binom{n-m-2}{n-1}a^{m-n+1}(-1)^m&n>0,m<0\\
\binom m{m-n+1}(-a)^{m-n+1}&n>0,m\ge0
\end{cases}$$
$$\Res(z^n(z-a)^m,a)=\Res((z+a)^nz^m,0)$$
The first fact can be obtained by performing a partial fraction decomposition of $z^{-n}(z-a)^m$; the residue is the coefficient of $\frac1z$. The second fact is obvious by substituting $z+a$ for $z$.

#!/usr/bin/env python3
from mpmath import *

def q1(a, n, k):
    return quad(lambda t: (expj(t)-a)**k * expj(n*t), [0, 2*pi])

def bproduct_res(a, n, m):
    # Res(z**-n (z-a)**m, 0)
    if n <= 0:
        return 0
    if m < 0:
        return binomial(n-m-2, n-1) * power(a, m-n+1) * (-1)**m
    return binomial(m, m-n+1) * power(-a, m-n+1)

def q2(a, n, k):
    rsum = 0
    if n <= 0:
        rsum += bproduct_res(a, 1-n, k)
    if abs(a) < 1 and k <= -1:
        rsum += bproduct_res(-a, -k, n-1)
    return 2*pi*rsum

test_tuples = ((1.4, 3, 4), (1.4, 3, -4), (1.4, -3, 4), (1.4, -3, -4),
               (0.4, 3, 4), (0.4, 3, -4), (0.4, -3, 4), (0.4, -3, -4))
for tup in test_tuples:
    print(chop(q1(*tup)))
    print(chop(q2(*tup)))
    print()

