Let $A:\mathbb{R}^n\to\mathbb{R}^n$ be an invertible linear map, $B^2=A^TA$. Let $U=AB^{-1}$. Show that $U$ is unitary. Let $A:\mathbb{R}^n\to\mathbb{R}^n$ be an invertible linear map, there is a symmetric positive definite $B$ such that $B^2=A^TA$. Let $U=AB^{-1}$. Show that $U$ is unitary.  
The solution says, let $U=AB^{-1}$ where $B^2=A^TA$ and $BA=AB$, so $B^{-1}A=AB^{-1}$. Then 
\begin{align}
& \langle Uv,Uv \rangle=\langle AB^{-1}v,AB^{-1}v \rangle=\langle B^{-1}Av,B^{-1}Av \rangle \\
= & \langle Av,(B^T)^{-1}B^{-1}Av \rangle \\
= & \langle v,AA^{-2}Av \rangle = \langle v,v \rangle
\end{align}
How can I get $BA=AB$ and $= \langle v,AA^{-2}Av \rangle$ in the above solution? Thanks.
 A: $U=AB^{-1}$ where $B=(A^TA)^{\frac{1}{2}}$.  Using the standard inner product  
$\langle U\mathbf v,U\mathbf v \rangle$
$=\langle AB^{-1}\mathbf v,AB^{-1}\mathbf v \rangle$
$=\langle B^{-1}\mathbf v,(A^TA)B^{-1}\mathbf v \rangle$
$=\langle B^{-1}\mathbf v,(A^TA)^\frac{1}{2} (A^TA)^\frac{1}{2} B^{-1}\mathbf v \rangle$
$=\langle (A^TA)^\frac{1}{2} B^{-1}\mathbf v,(A^TA)^\frac{1}{2} B^{-1}\mathbf v \rangle$
$=\langle \mathbf v,\mathbf v \rangle$ 
addendum
a word of caution about the "official solution"
the official solution seems to indicate $AB = BA$
if this is true then we can multiply each side on the right by B to get
$A(A^TA) =AB^2= BAB = B^2A = (A^TA)A$
but this is implies $A$ is normal, see e.g here
If $A$ commutes with $A^*A$, does it follow that $A$ is normal? 
which yields a contradiction, since not all of $GL_n(\mathbb R)$ is normal.  
A: Another approach to showing $U$ unitary, one which sidesteps the issue of showing $AB = BA$:
With
$U = AB^{-1}, \tag 1$
$U^T = (B^{-1})^TA^T;\tag 2$
we have
$BB^{-1} = I, \tag 3$
whence
$(B^{-1})^TB^T = I^T = I, \tag 3$
whence
$(B^{-1})^T = (B^T)^{-1} = B^{-1}, \tag 4$
since
$B^T = B; \tag 5$
thus (2) becomes
$U^T = B^{-1}A^T, \tag 6$
whence
$U^TU =  B^{-1}A^TAB^{-1} = B^{-1}B^2B^{-1} = I; \tag 7$
that is, $U$ is orthogonal; since $A$ and $B$ are real matrices, so is $U$, and hence 
$U^\ast = U, \tag 8$
which leads to
$U^\dagger = (U^\ast)^T = U^T, \tag 9$
and $U$ is in fact unitary as well:
$U^\dagger U = U^TU = I. \tag{10}$
