Evaluating $\int {\sin \theta + \cos \theta \over \sqrt{\sin 2\theta} }d\theta$ 
$$\int {\sin \theta + \cos \theta \over \sqrt{\sin 2\theta} }d\theta$$


After simplifying I get, 
$${1\over \sqrt{2}}\int {\tan \theta + 1 \over \sqrt{\tan \theta}} d\theta$$
Substituting $u = \tan \theta$
$${1\over \sqrt{2}}\int {u + 1\over \sqrt{u}(1 + u^2)} du$$
Substituting $t^2 = u$
$${\sqrt{2}}\int {t^2 + 1\over (1 + t^4)} dt = \sqrt{2} \int {1 + 1/t^2 \over(t - 1/t)^2 + 2 }dt$$
Substituting $z = t - 1/t$
$$\sqrt{2} \int {1\over z^2 + 2 }dz =  \arctan\left(\tan \theta - 1\over \sqrt{2\tan \theta} \right) + C = {\arcsin(2\sqrt{\sin2\theta} (\sin\theta - \cos \theta))\over 2} + C$$
Which is far from the right answer of $\arcsin(\sin \theta - \cos \theta) + C$.
Where did I go wrong ?
Edit :
I would like to know where I am wrong rather than knowing how to solve the problem. 
 A: Hint -
Put $\sin\theta - \cos \theta = t$
$(\cos \theta + \sin \theta)\text{d}\theta = \text{d}t$
Also on squaring above equation,
$\sin^2\theta + \cos^2 \theta - 2 \sin \theta \cos \theta = t^2$
$1 - \sin2\theta = t^2$
$\sin2\theta = 1 - t^2$
Then given integral becomes,
$\int \frac{1}{\sqrt {1-t^2}} \text{d}t$
Hope now its easy to solve.
A: Hint:
Try the substitution $u=\sin 2\theta$.
A: Your factor before $\arctan$ should be $1$ rather than $1/2$; except for that, your antiderivative is correct. The error is in the conversion to $\arcsin$. If you use $\arctan \alpha = \arcsin(\alpha/\sqrt{\alpha^2+1})$, you will get the right answer.
Update: Now that the factor 1/2 has been edited away, things are fine up to that point. And actually the last step is almost OK too! (I dismissed it a bit too quickly before.)
The question is only meaningful on an interval where $\sin 2\theta \ge 0$, say $0 \le \theta \le \pi/2$, and the answer $A=\arcsin(\sin\theta-\cos\theta)$ is correct on that whole interval, as is easily verified by differentiation (and note also that $|\sin\theta-\cos\theta| \le 1$ on that interval).
Now it seems that your expression $B$ actually agrees with the expression $A$ on the subinterval $\pi/12 \le \theta \le 5\pi/12$, whereas $B=\text{const.}-A$ on the intervals $0\le \theta \le \pi/12$ and $\le 5\pi/12 \le \theta \le \pi/2$. I haven't really bothered to analyze why this happens, I was just lazy and looked at plots of $A \pm B$. But surely (as Barry Cipra pointed out) it has something to do with the properties of the inverse trig functions; for example $\arcsin(\sin x) = \pi-x$ if $\pi/2 \le x \le \pi$.
A: There appear to be two mistakes, both in the last displayed equation.  First,
$$\sqrt2\int{1\over z^2+2}dz=\arctan\left(z\over\sqrt2\right)+C=\arctan\left(\tan\theta-1\over\sqrt{2\tan\theta}\right)+C$$
(i.e., the $1\over2$ in from of the arctan didn't belong there).  And second, when you convert arctan to arcsin, you really do get $\arcsin(\sin\theta-\cos\theta)$.  I don't know how you got $\arcsin(2\sqrt{\sin2\theta}(\sin\theta-\cos\theta))$, but you can see that it's wrong because it does not differ by a constant from $\arctan((\tan\theta-1)/\sqrt{2\tan\theta})$ for all $0\lt\theta\lt\pi/2$, since both equal $0$ at $\theta=\pi/4$, while $\arcsin(2\sqrt{\sin2\theta}(\sin\theta-\cos\theta))=0$ as $\theta\to0$ whereas
$$\arctan\left(\tan\theta-1\over\sqrt{2\tan\theta}\right)\to-{\pi\over2}\quad\text{as }\theta\to0$$
My recommendation is to have another go at the arctan/arcsin conversion, and if you still don't get the right answer, post your work for that part of the derivation and ping me with a comment so I can take a look at it.  
(Remark, added after posting: I  was offline composing this, and didn't see Hans Lundmark's answer until just now.)
Added in response to OP's comment:  It is true that $y=\arctan((\tan\theta-1)/\sqrt{2\tan\theta})$ implies $\tan y=(\tan\theta-1)/\sqrt{2\tan\theta}$, but it is not always true that $\sin2y=2\tan\theta/(1+\tan^2\theta)$ implies $y={1\over2}\arcsin(2\tan\theta/(1+\tan^2\theta))$.  More generally, if $f$ is any of the trig functions (sin, cos, tan, etc.), and $g$ is its inverse (arcsin, arccos, arctan, etc.), then $f(g(x))=x$ is always true but $g(f(x))=x$ is not always true.  In other words, when converting from arctan to arcsin, you can't work purely formally; you have to consider the ranges and domains of the functions.
