Numeric integration of Greens Function over singularity I'm currently using python to numerically evaluate the follow expression at various values of $r$ and $\theta$.
\begin{equation*}
f(r,\theta) = \int_{-\pi}^{\pi}\int_{0}^{R}\frac{\exp(ikS)}{2 \pi S}W_k(r^*,\theta^*)r^*dr^*d\theta^*
\end{equation*}
where:
\begin{equation*}
 S = \sqrt{r^2 + r^{*2} - 2rr^*\cos(\theta-\theta^*)}
\end{equation*}
I'm looking for advice on how to deal with the singularity at $(r,\theta) = (r^*,\theta^*)$.
I know that I need to remove these singular points from the numeric integration, evaluate them analytically, and add their contribution back.  In doing this, however, I am not sure what value to use for $S$.  
Since the size of a differential element is approximately $(dr)$ by $(r d\theta)$, it seems appropriate to choose one of the following options:


*

*$S = \min\bigg(\frac{dr}{2}, \frac{rd\theta}{2} \bigg)$

*$S = \sqrt{\bigg(\frac{dr}{2} \bigg)^2+\bigg(\frac{rd\theta}{2} \bigg)^2}$


However when I try any of these values, I cannot accurately recover the reported result.  Where am I going wrong?
 A: Regularizing the integral may be handy in your case
$$
\int\limits_{-\pi}^{\pi}\int\limits_{0}^R \frac{\exp(ikS)}{2\pi S} W(r^*,\theta^*)r^* dr^*d\theta^* = \\ =
\int\limits_{-\pi}^{\pi}\int\limits_{0}^R \frac{\exp(ikS) - 1}{2\pi S}W(r^*,\theta^*)r^* dr^*d\theta^* + 
\int\limits_{-\pi}^{\pi}\int\limits_{0}^R \frac{W(r^*,\theta^*)-W(r,\theta)}{2\pi S}r^* dr^*d\theta^* + \\
+W(r,\theta)\int\limits_{-\pi}^{\pi}\int\limits_{0}^R \frac{1}{2\pi S}r^* dr^*d\theta^*.
$$
Assuming the last integral is computed analytically. We can rotate the coordinatte system to get rid of $\theta$:
$$
\int\limits_{-\pi}^{\pi}\int\limits_{0}^R \frac{1}{2\pi \sqrt{r^2 + r^{*2}-2rr^*\cos(\theta - \theta^*)}}r^* dr^*d\theta^* = \Big|\psi = \theta^* - \theta\Big| = \\ =
\int\limits_{-\pi}^{\pi}\int\limits_{0}^R \frac{1}{2\pi \sqrt{r^2 + r^{*2}-2rr^*\cos\psi}}r^* dr^*d\psi = 
\int\limits_0^R \frac{K\left(-\frac{4\pi rr^*}{(r-r^*)^2}\right)}{\pi|r-r^*|}r^*dr^*
+
\int\limits_0^R\frac{K\left(-\frac{4\pi rr^*}{(r+r^*)^2}\right)}{\pi|r+r^*|} r^*dr^*
$$
The last was obtained with Wolfram Mathematica, but seems to be correct. The last step is removing singularity from $\frac{K\left(-\frac{4\pi rr^*}{(r-r^*)^2}\right)}{\pi|r-r^*|}$. I've asked about asymptotics in Complete elliptic integral of the first kind $K(m)$ asymptotc expansion at $m = -\infty$ .
