An integral identity with a complex parameter Conjecture: For $z\in\mathbb{C}\setminus[-1,1]$, we have
$$
\int_{0}^{\pi}\frac{dx}{|z-\cos x|}=\frac{\pi}{\sqrt{|z^{2}-1}|}.
$$
I know it is true for $z\in\mathbb{R}\setminus[-1,1]$ but not in general.
 A: First note that the function
$$f(z) = \frac{dx}{|z-\cos x|}$$
is an even function. Hence,
$$
I = \int_{0}^{\pi}\frac{dx}{|z-\cos x|} =  \frac{1}{2}\int_{-\pi}^{\pi}\frac{dx}{|z-\cos x|}
$$
If you do the following substitution:
$$ \cos x = \frac{w+w^{-1}}{2} = \frac{w^2+1}{2w}$$
$$dx = \frac{dw}{wi}$$
$$ I = \frac{1}{2}\int_{-\pi}^{\pi}\frac{dx}{|z-\cos x|} =  \frac{1}{i} \oint_{|w|=1} \frac{1}{|w^2+2wz+1|} dw $$
your integral is transformed in a contour integral round the unit complex circle
If $z\in \mathbb{R}$, the function
$$ g(w) = \frac{1}{|w^2+2wz+1|} = \frac{1}{|w+\sqrt{z^2+1}+z||w-\sqrt{z^2+1}+z|}$$ has two singularities:
$$ w_{1} = -\sqrt{z^2-1}-z$$
$$ w_{2} = \sqrt{z^2-1}-z$$
To apply the residue theorem, one of the singularites has to be inside the unit circle:
$$|w_{1}|<1 \Longrightarrow z<-1 $$
$$|w_{2}|<1 \Longrightarrow z>1 $$
Then if $z<- 1$ then
$$I =  \frac{1}{i} \oint_{|w|=1} \frac{1}{|w^2+2wz+1|} dw = 2\pi \operatorname{Res}(g,w_{1}) = 2\pi \lim_{w \to -\sqrt{z^2-1}-z} \frac{w+\sqrt{z^2+1}+z}{|w+\sqrt{z^2+1}+z||w-\sqrt{z^2+1}+z|} = \frac{2\pi}{|-2\sqrt{z^2+1}|} = \frac{\pi}{|\sqrt{z^2+1}|}$$
If $z>1$ then
$$I =  \frac{1}{i} \oint_{|w|=1} \frac{1}{|w^2+2wz+1|} dw = 2\pi \operatorname{Res}(g,w_{2}) = 2\pi \lim_{w \to -\sqrt{z^2-1}+z} \frac{w-\sqrt{z^2+1}+z}{|w+\sqrt{z^2+1}+z||w-\sqrt{z^2+1}+z|} = \frac{2\pi}{|2\sqrt{z^2+1}|} = \frac{\pi}{|\sqrt{z^2+1}|}$$
Note that we have used the following property to calculate these limits:
If $w=x+iy$
$$ \lim_{x\to a, y\to 0} \frac{w}{|w|} = \lim_{x\to a, y\to 0} \frac{x+iy}{\sqrt{x^2+y^2}} = \lim_{x \to a} \frac{x}{|x^2|} = \lim _{x \to a} \frac{x}{|x|} = \operatorname{sign}(a)$$
Hence we can conclude
$$ 
\boxed{\int_{0}^{\pi}\frac{dx}{|z-\cos x|}=\frac{\pi}{|\sqrt{z^{2}-1}|} \quad z\in \mathbb{R}\backslash[-1,1] } $$
The statement is not true in general
Consider $z=i$,
The left hand side is
$$\int_{0}^{\pi} \frac{1}{|i-\cos x|} dx = 2\int_{0}^{\frac{\pi}{2}} \frac{1}{\sqrt{1+\cos^2 x}} dx = 2\int_{0}^{\frac{\pi}{2}} \frac{1}{\sqrt{2-\sin^2 x}}dx = \frac{2}{\sqrt{2}} \int_{0}^{\frac{\pi}{2}} \frac{1}{\sqrt{1-\frac{1}{2}\sin^2 x}} dx = \sqrt{2}K\left(\sqrt{\frac{1}{2}}\right)\approx 2.62 $$
The integral converges and the solution is the complete elliptic integral of the first kind. However, the right hand side of the formula
$$\frac{\pi}{|\sqrt{i^{2}-1}|} =\frac{\pi}{|\sqrt{-2}|}  = \frac{\pi}{\sqrt{2}} \approx 2.22$$
So
$$ 
\int_{0}^{\pi}\frac{dx}{|i-\cos x|}\neq \frac{\pi}{|\sqrt{i^{2}-1}|} $$
