Integrating $\int_0^{\pi/2} \frac{\sin^2 ax}{\sin^2 x}\,dx$ I am looking for ways to evaluate:
$$\int_0^{\pi/2} \frac{\sin^2 ax}{\sin^2 x}\,dx$$
where, $a$ is any positive real-number. (Real-analytic or complex integration techniques, either will do.)
Sidenote to down/close votes: It was discussed in SE chat room 36 yesterday (incase you haven't checked robjohn's comment) and I decided to post it on main so that robjohn can share his awesome solution!
 A: I think i found a way to tackle this integral which is a little bit different from @robjohn's nice answer. To get started we note the following simple algebraic indentity
$$
\frac{1}{\sin^2(x)}=\frac{-4}{(e^{i x}-e^{-i x})^2}=\frac{-4 e^{2 ix}}{(e^{i x}-1)^2}=-2 i\partial_x\frac{1}{e^{2 ix}-1}
$$
we therefore may rewrite the integral as
$$
I(a)=-2i\int_0^{\pi/2}\sin^2(a x)\left(\partial_x\frac{1}{e^{2 ix}-1}\right)
$$
this is now ideally suited for an integration by parts  which leaves us 
$$
I(a)=-2 i\color{\red}{\sin^2(a \pi/2)}+2ia\underbrace{\int_0^{\pi/2}\frac{\sin(2a x)}{e^{2 ix}-1}}_{J(a)} \quad \color{\red}{(*)}
$$
expanding the denominator in a geometric series and swapping integration and summation we obtain
$$
J(a)=-\sum_{n=0}^{\infty}\int_0^{\pi/2}\sin(2a x)e^{2 i xn}
$$
the resulting integrals are readily performed
$$
J(a)=\frac{1}{2}\left[a\underbrace{\sum_{n=0}^{\infty}\frac{1}{ (a^2-n^2)}}_{\color{\orange}{S_1(a)}}-a\cos (\pi  a)\underbrace{\sum_{n=0}^{\infty}\frac{(-1)^n }{(a^2-n^2)}}_{\color{\green}{S_2(a)}}+i\sin (\pi  a)\underbrace{\sum_{n=0}^{\infty}\frac{(-1)^n n }{(a^2-n^2)}}_{\color{\violet}{S_3(a)}}\right]
$$
The sum $\color{\violet}{S_3(a)}$ was already calculated by Rob, and we don't repeat the corresponding steps here. 
What is then left to show is essentially that $\frac{a}{2}\left(\color{\orange}{S_1(a)}-\cos(\pi a)\color{\green}{S_2(a)}\right)=\color{\red}{\sin^2(a \pi/2)}$ so that the imaginary parts  in $\color{\red}{(*)}$ cancel out. 
We start with $\color{\green}{S_2(a)}$:
$$
\color{\green}{S_2(a)}=\frac{1}{2a}\left(\sum_{n=0}^{\infty}\frac{(-1)^n}{n+a}-\frac{(-1)^n}{n-a}\right)=\frac{1}{2a}\left(\sum_{n\in\mathbb{Z}}\frac{(-1)^n}{a-n}-\frac{1}{a}\right)
$$
Now we can employ for example the pole expansion of $\frac{1}{\sin(z)}$ and obtain
$$
\color{\green}{S_2(a)}=\frac{1}{2a^2}+\frac{\pi}{2\sin(\pi a)a}
$$
To calculate $\color{\orange}{S_1(a)}$ we use the pole expansion of $\cot(z)$ and obtain
$$
\color{\orange}{S_1(a)}=\frac{1}{2a^2}+\frac{\pi \cot(\pi a) }{ 2a}
$$
Using the fact that $1-\cos(x)=2\sin^2(x/2)$ and $\cot(x)=\frac{\cos(x)}{\sin(x)}$ we may indeed conclude that
$$
\frac{a}{2}\left(\color{\orange}{S_1(a)}-\cos(\pi a)\color{\green}{S_2(a)}\right)=\frac{a}{2}\left(2 \frac{\color{\red}{\sin^2(a \pi/2)}}{a}\right)=\color{\red}{\sin^2(a \pi/2)}
$$
so the imaginary part of $\color{red}{(*)}$ is zero and therefore

$$
I(a)=-a\sin (\pi  a)\color{\violet}{S_3(a)}
$$

which agrees with the other answer given
A: There appears to be lots of methods to throw at this one. 
Use parts by letting 
$u=\sin^{2}(ax), \;\ dv=\frac{1}{\sin(x)}dx, \;\ du=2a\sin(ax)\cos(ax)dx, \;\ v=-cot(x)dx$
$$-\sin^{2}(ax)\cot(x)|_{0}^{\frac{\pi}{2}}+2a\int_{0}^{\frac{\pi}{2}}\sin(ax)\cos(ax)\cot(x)dx$$
Since the left part is $0$, and using the identity $2\sin(u)\cos(u)=\sin(2u)$, then we have:
$$a\int_{0}^{\frac{\pi}{2}}\sin(2ax)\cot(x)dx\tag{1}$$
This looks as if there are many ways to go about it. I am going to use the famous relation:
$$\int_{a}^{b}p(x)\cot(x)dx=2\sum_{n=1}^{\infty}\int_{a}^{b}p(x)\sin(2nx)dx$$
It is OK in this case by letting $p(x)=\sin(2ax), \;\ p(0)=0$
Thus,
$$2a\sum_{n=1}^{\infty}\int_{0}^{\frac{\pi}{2}}\sin(2ax)\sin(2nx)dx$$
$$\frac{a}{2}\underbrace{\sum_{n=1}^{\infty}\frac{\sin(\pi(a-n))}{a-n}}_{[1]}-\frac{a}{2}\underbrace{\sum_{n=1}^{\infty}\frac{\sin(\pi(a+n))}{a+n}}_{[2]}$$
I cut to the quick by using tech, but these sums are kind of famous and summing [1]-[2] results in:
$$[1]=\frac{a}{2}\left(\frac{-1}{2}\sin(\pi a)\left(\psi\left(1/2-a/2\right)-\psi\left(1-a/2\right)\right)\right)$$
$$[2]=\frac{a}{2}\left(\frac{-1}{2}\sin(\pi a)\left(\psi\left(a/2+1\right)-\psi\left(a/2+1/2\right)\right)\right)$$
$$[1]-[2]=\text{required result}$$
Other thoughts:  
use parts again on (1)
or
Consider $1/2\int_{0}^{\pi}\frac{1-\cos(ax)}{1-\cos(x)}dx$$
A: We will use
$$
H(x)=\sum_{k=1}^\infty\left(\frac1k-\frac1{k+x}\right)\tag{1}
$$
which Is the standard analytic extension of the Harmonic Numbers.
$$
\begin{align}
&\int_0^{\pi/2}\frac{\sin^2(ax)}{\sin^2(x)}\,\mathrm{d}x\tag{2}\\
&=\frac12\int_{-\pi/2}^{\pi/2}\frac{\left(e^{iax}-e^{-iax}\right)^2}{\left(e^{ix}-e^{-ix}\right)^2}\,\mathrm{d}x\tag{3}\\
&=\frac1{4i}\int_{-\pi}^\pi\frac{\left(e^{iax}-1\right)^2}{\left(e^{ix}-1\right)^2}e^{-iax}\,\mathrm{d}e^{ix}\tag{4}\\
&=\frac1{4i}\int_\gamma\frac{z^a-2+z^{-a}}{\left(z-1\right)^2}\,\mathrm{d}z\tag{5}\\
&=\frac1{4i}\int_0^1\frac{t^a\left(e^{-\pi ia}-e^{\pi ia}\right)+t^{-a}\left(e^{\pi ia}-e^{-\pi ia}\right)}{\left(t+1\right)^2}\,\mathrm{d}t\tag{6}\\
&=\frac{\sin(\pi a)}2\int_0^1\frac{t^{-a}-t^a}{\left(t+1\right)^2}\,\mathrm{d}t\tag{7}\\
&=\frac{\sin(\pi a)}2\sum_{k=0}^\infty(-1)^k(k+1)\int_0^1\left(t^{k-a}-t^{k+a}\right)\,\mathrm{d}t\tag{8}\\
&=\frac{\sin(\pi a)}2\sum_{k=0}^\infty(-1)^k(k+1)\left(\frac1{k+1-a}-\frac1{k+1+a}\right)\tag{9}\\
&=\frac{\sin(\pi a)}2\sum_{k=0}^\infty(-1)^ka\left(\frac1{k+1-a}+\frac1{k+1+a}\right)\tag{10}\\
&=\frac{a\sin(\pi a)}2\sum_{k=1}^\infty\left(\frac1{2k-1-a}-\frac1{2k-a}+\frac1{2k-1+a}-\frac1{2k+a}\right)\tag{11}\\[3pt]
&=\frac{a\sin(\pi a)}4\left(-H\left(\frac{-1-a}2\right)+H\left(\frac{-a}2\right)-H\left(\frac{-1+a}2\right)+H\left(\frac{a}2\right)\right)\tag{12}\\[6pt]
&=\frac{a\sin(\pi a)}4\left(-\psi\left(\frac{1-a}2\right)+\psi\left(\frac{-a}2\right)-\psi\left(\frac{1+a}2\right)+\psi\left(\frac{a}2\right)\right)\tag{13}
\end{align}
$$
Explanation:
$\phantom{1}(3)$: $\sin(x)=\frac{e^{ix}-e^{-ix}}{2i}$
$\phantom{1}(4)$: substitute $x\mapsto x/2$
$\phantom{1}(5)$: $z=e^{ix}$ and $\gamma$ is a ccw unit circle and the negative real axis is a branch cut
$\phantom{1}(6)$: collapse the contour onto the negative real axis
$\phantom{(10)\text{:}}$ set $\color{#C00000}{z=te^{-i\pi}}$ below and $\color{#00A000}{z=te^{i\pi}}$ above the axis
$\phantom{1}(7)$: $\sin(x)=\frac{e^{ix}-e^{-ix}}{2i}$
$\phantom{1}(8)$: apply the power series for $\frac1{(1+x)^2}$
$\phantom{1}(9)$: integrate
$(10)$: algebra
$(11)$: separate the positive and negative terms
$(12)$: apply $(1)$
$(13)$: $H(x)=\gamma+\psi(1+x)=\gamma+\psi(x)+\frac1x$
