A Sine-Cosine Integral $\int_{0}^{\frac{\pi}{2}} \frac{ \sin(kx) \ +\ \cos(kx)}{\sin x \ +\ \cos x} \ dx$ What is the value of the integral
\begin{align}
I(k) = \int_{0}^{\frac{\pi}{2}} \frac{ \sin(kx) + \cos(kx)}{\sin(x) + \cos(x)} \ dx
\end{align}
where $k$ is an integer ?
Is it possible to evaluate a related integral
\begin{align}
I(k) = \int_{0}^{\frac{\pi}{2}} \frac{ \sin(kx) - \cos(kx)}{\sin(x) - \cos(x)} \ dx
\end{align}
where $k$ is an integer ?
 A: Hint: $1/\sqrt{2} (\sin x + \cos x) =\sin (x+\pi/4)$
So the integral becomes:
$$\int_{0}^{\pi/4}\frac{ \sin (kx+\pi/4)}{\sin (x+\pi/4)}dx$$ 
Put $x+(\pi/4)=t$
$$\int_{\frac{\pi}{4}}^{\frac{3\pi}{4}} \frac {\sin (kt-(k-1)\pi/4)}{\sin (t)} dt$$
Now consider cases $(k-1) \mod 4=0$ or $1$ or $2$ or $3$. And solve. Hope this helps. 
A: $\newcommand{\+}{^{\dagger}}
 \newcommand{\angles}[1]{\left\langle\, #1 \,\right\rangle}
 \newcommand{\braces}[1]{\left\lbrace\, #1 \,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\, #1 \,\right\rbrack}
 \newcommand{\ceil}[1]{\,\left\lceil\, #1 \,\right\rceil\,}
 \newcommand{\dd}{{\rm d}}
 \newcommand{\down}{\downarrow}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,{\rm e}^{#1}\,}
 \newcommand{\fermi}{\,{\rm f}}
 \newcommand{\floor}[1]{\,\left\lfloor #1 \right\rfloor\,}
 \newcommand{\half}{{1 \over 2}}
 \newcommand{\ic}{{\rm i}}
 \newcommand{\iff}{\Longleftrightarrow}
 \newcommand{\imp}{\Longrightarrow}
 \newcommand{\isdiv}{\,\left.\right\vert\,}
 \newcommand{\ket}[1]{\left\vert #1\right\rangle}
 \newcommand{\ol}[1]{\overline{#1}}
 \newcommand{\pars}[1]{\left(\, #1 \,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\pp}{{\cal P}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\vphantom{\large A}\,#2\,}\,}
 \newcommand{\sech}{\,{\rm sech}}
 \newcommand{\sgn}{\,{\rm sgn}}
 \newcommand{\totald}[3][]{\frac{{\rm d}^{#1} #2}{{\rm d} #3^{#1}}}
 \newcommand{\ul}[1]{\underline{#1}}
 \newcommand{\verts}[1]{\left\vert\, #1 \,\right\vert}
 \newcommand{\wt}[1]{\widetilde{#1}}$
$\ds{{\rm I}\pars{k}\equiv\int_{0}^{\pi/2}{\sin\pars{kx} + \cos\pars{kx}\over
                                           \sin\pars{x} +   \cos\pars{x}}\,\dd x:\
     {\large ?}}$

\begin{align}
{\rm I}\pars{k}&=\int_{0}^{\pi/2}
{\sin\pars{kx + \pi/4} \over \sin\pars{x + \pi/4}}\,\dd x
=\int_{-\pi/4}^{\pi/4}
{\sin\pars{kx + \bracks{k + 1}\pi/4} \over \cos\pars{x}}\,\dd x
\\[3mm]&=2\sin\pars{\bracks{k + 1}\pi \over 4}
\color{#00f}{\Re\int_{0}^{\pi/4}{\expo{\ic kx} \over \cos\pars{x}}\,\dd x}\tag{1}
\end{align}

\begin{align}
&\color{#00f}{\Re\int_{0}^{\pi/4}{\expo{\ic kx} \over \cos\pars{x}}\,\dd x}=\Re
\int_{\verts{z}\ =\ 1 \atop {\vphantom{\Huge A}0\ <\ {\rm Arg}\pars{z}\ <\ \pi/4}}
{z^{k} \over \pars{z^{2} + 1}/\pars{2z}}\,{\dd z \over \ic z}
\\[3mm]&=2\,\Im
\int_{\verts{z}\ =\ 1 \atop {\vphantom{\Huge A}0\ <\ {\rm Arg}\pars{z}\ <\ \pi/4}}
{z^{k} \over z^{2} + 1}\,\dd z
\\[3mm]&=2\,\Im\bracks{-\int_{1}^{0}
{r^{k}\expo{\ic\pi k/4} \over r^{2}\expo{\ic\pi/2} + 1}\,\expo{\ic\pi/4}\,\dd r
-\int_{0}^{1}{x^{k} \over x^{2} + 1}\,\dd x}
\\[3mm]&=2\,\Im\bracks{\expo{\ic\pars{k + 1}\pi/4}
\int_{0}^{1}{r^{k} \over 1 + r^{2}\ic}\,\dd r}
=2\,\Im\bracks{\expo{\ic\pars{k + 1}\pi/4}
\int_{0}^{1}{r^{k}\pars{1 - r^{2}\ic} \over 1 + r^{4}}\,\dd r}
\\[3mm]&=2\sin\pars{\bracks{k + 1}\pi \over 4}
\int_{0}^{1}{r^{k} \over r^{4} + 1}\,\dd r-2\cos\pars{\bracks{k + 1}\pi \over 4}
\int_{0}^{1}{r^{k + 2} \over r^{4} + 1}\,\dd r
\end{align}

We replace the above result in $\pars{1}$:
  $${\rm I}\pars{k}=
4\sin^{2}\pars{\bracks{k + 1}\pi \over 4}
\int_{0}^{1}{r^{k} \over r^{4} + 1}\,\dd r
-2\sin\pars{\bracks{k + 1}\pi \over 2}
\int_{0}^{1}{r^{k + 2} \over r^{4} + 1}\,\dd r
$$
  The remaining integrals can be evaluated by expanding the denominators in powers of $\ds{r}$. We found
  \begin{align}
{\cal J}\pars{\mu}&\equiv\int_{0}^{1}{r^{\mu} \over r^{4} + 1}\,\dd r
={1 \over 16}\sum_{n = 0}^{\infty}
{1 \over \bracks{n + \pars{\mu + 5}/8}\bracks{n + \pars{\mu + 1}/8}}
\\[3mm]&=
{1 \over 8}\bracks{\Psi\pars{\mu + 5 \over 8} - \Psi\pars{\mu + 1\over 8}}\,,
\qquad\qquad \Re\pars{\mu}>-1
\end{align}
  where $\ds{\Psi\pars{z}}$ is the Digamma Function.

\begin{align}&\color{#66f}{\large{\rm I}\pars{k}=
4\sin^{2}\pars{\bracks{k + 1}\pi \over 4}{\cal J}\pars{k}
-2\sin\pars{\bracks{k + 1}\pi \over 2}
{\cal J}\pars{k + 2}}
\\[3mm]&{\large\Re\pars{k} > -1}
\end{align}
A: Depending on even or odd $k$, the integrals
\begin{align}
I_k = \int_{0}^{\frac{\pi}{2}} \frac{ \sin(kx) + \cos(kx)}{\sin x + \cos x} \ dx
\end{align}
exhibit different behaviors. Their close-forms are derived separately below
\begin{align}
I_{2m+1} 
=& \>2\cos\frac{m\pi}2\int_0^{\frac\pi4}\frac{\cos(2m+1)x}{\cos x}dx
=\cos\frac{m\pi}2\left(\frac\pi2-\sum_{k=1}^m \frac{2}k \sin\frac{k \pi}2 \right)
\\
\\
 I_{2m} 
=& \>2\sin\frac{(2m+1)\pi}4\int_0^{\frac\pi4}\frac{\cos(2mx)}{\cos x}dx\\
=&\>2\cos\frac{(2m+1)\pi}4\left(\coth^{-1}\sqrt2-\sum_{k=1}^m \frac{2}{2k-1} \sin\frac{(2k+1)\pi}4\right)
\end{align}
from which
\begin{align}
&I_1=\frac\pi2,\>\>\>I_5=2-\frac\pi2,\>\>\>I_9=\frac\pi2-\frac43,
\>\>\>I_{13}=\frac{26}{15}-\frac\pi2,\cdots\\
&I_3=I_7=I_{11}=I_{15}=\cdots = 0\\
&I_2=2-\sqrt2 \coth^{-1}\sqrt2,\>\>\>
 I_4=\frac43-\sqrt2 \coth^{-1}\sqrt2,\>\>\>\\
 &I_6=\sqrt2 \coth^{-1}\sqrt2-\frac{14}{15},\>\>\>
 I_8=\sqrt2 \coth^{-1}\sqrt2- \frac{128}{105},\cdots\>\>\>
\end{align}
