<s>[INST] Prove $\int_0^\infty \frac{x^{k-1} + x^{-k-1}}{x^a + x^{-a}}dx = \frac{\pi}{a \cos(\frac{\pi k}{2a})}$. I need help in proving this identity
$$\int_0^\infty \frac{x^{k-1} + x^{-k-1}}{x^a + x^{-a}}dx = \frac{\pi}{a \cos(\frac{\pi k}{2a})}$$
for $0<k<a.$ It might be done using residues, but I don't know which contour to choose. 
 [/INST] \begin{align*}
I &= \int^\infty_0 \frac{x^{k - 1} + x^{-kn - 1}}{x^a + x^{-a}} \, dx\\
&= \int^\infty_0 \frac{x^{k - 1} + x^{-k - 1}}{x^{-a} (x^{2a} + 1)} \, dx\\
&= \int^\infty_0 \frac{x^{k + a -1} + x^{a - k - 1}}{x^{2a} + 1} \, dx
\end{align*}
Let $t = x^{2a}, x = t^{\frac{1}{2a}}, dx = \frac{1}{2a} t^{\frac{1 - 2a}{2a}} \, dt$ while the limits of integration remain unchanged. Thus
\begin{align*}
I &= \int^\infty_0 \frac{t^{\frac{k + a - 1}{2a}} + t^{\frac{a - k - 1}{2a}}}{1 + t} \cdot \frac{1}{2a} t^{\frac{1 - 2a}{2a}} \, dt\\
&= \frac{1}{2a} \int^\infty_0 \int^\infty_0 \frac{t^{\frac{k - a}{2a}} + t^{\frac{-a-k}{2a}}}{1 + t} \, dt\\
&= \frac{1}{2a} \int^\infty_0 \frac{t^{\frac{k + a}{2a} - 1}}{(1 + t)^{\frac{k + a}{2a} + \frac{a - k}{2a}}} \, dt + \frac{1}{2a} \int^\infty_0 \frac{t^{\frac{a - k}{2a} - 1}}{(1 + t)^{\frac{a - k}{2a} + \frac{k + a}{2a}}} \, dt\\
&= \frac{1}{2a} \mbox{B} \left (\frac{k + a}{2a}, \frac{a - k}{2a} \right ) + \frac{1}{2a} \mbox{B} \left (\frac{k - a}{2a}, \frac{a + k}{2a} \right )
\end{align*}
Here $\displaystyle{\mbox{B} (m,n)}$ is the beta function. Since $\mbox{B}(m,n) = \mbox{B}(n,m)$ we have
\begin{align*}
I &= \frac{1}{a} \mbox{B} \left (\frac{k + a}{2a}, \frac{a - k}{2a} \right )\\ 
&= \frac{1}{a} \cdot \frac{\Gamma \left (\frac{k + a}{2a} \right ) \Gamma \left (\frac{a - k}{2a} \right )}{\Gamma \left (\frac{k + a}{2a} + \frac{a - k}{2a} \right )}, \quad \mbox{since} \,\, \mbox{B}(m,n) = \frac{\Gamma (m) \Gamma (n)}{\Gamma (m + n)}\\
&= \frac{1}{a} \Gamma \left (\frac{1}{2} + \frac{k}{2a} \right ) \Gamma \left (\frac{1}{2} - \frac{k}{2a} \right ), \quad \mbox{since} \,\, \Gamma (1) = 1\\
&= \frac{\pi}{a \cos \left (\frac{k\pi}{2} \right )}
\end{align*}
as required to show. Note in the last line the following reflection formula for the gamma function has been used
$$\Gamma \left (\frac{1}{2} + x \right ) \Gamma \left (\frac{1}{2} - x \right ) = \frac{\pi}{\cos (x \pi)}.$$
</s>