A and B are real, symmetric and positive semi-definite matrices of the same order; is AB diagonalizable? I've already proved this with B positive definite using the fact that $B^{-\frac{1}{2}}$ does exist and AB is similar to $A^{\frac{1}{2}}BA^{\frac{1}{2}}$, but since B is positive semi-definite I don't know if that is true. I also know that $A^{\frac{1}{2}}$ and $B^{\frac{1}{2}}$ are defined.
I´m trying to see that $A^{\frac{1}{2}}BA^{\frac{1}{2}}$ is similar to $A^{\frac{1}{2}}A^{\frac{1}{2}}B$, but i'm having problems with that.
Any hint would help, thanks!
 A: By a change of orthonormal basis, we may assume that
$$
A=\pmatrix{A_{r\times r}'&0\\ 0&0_{(n-r)\times(n-r)}}
\text{ and } B=\pmatrix{B_{r\times r}'&\ast\\ \ast&B_2},
$$
where $A'$ is positive definite. Then, by performing another change of orthonormal basis (or by orthogonally diagonalising $B'$, followed by permuting the diagonal entries of $B'$), we may further assume that
$$
A=\pmatrix{A_1&X^T&0\\ X&A_2&0\\ 0&0&0}
\text{ and } B=\pmatrix{B_1&0&Y^T\\ 0&0&Z^T\\ Y&Z&B_2},
$$
where $A'=\pmatrix{A_1&X^T\\ X&A_2}$ and $B'=\pmatrix{B_1&0\\ 0&0}$, with $B_1$ being positive definite. However, since $B$ is positive semidefinite, the sub-block $Z$ must be zero. It follows that
$$
AB
=\pmatrix{A_1&X^T&0\\ X&A_2&0\\ 0&0&0}\pmatrix{B_1&0&Y^T\\ 0&0&0\\ Y&0&B_2}
=\pmatrix{A_1B_1&0&AY^T\\ XB_1&0&XY^T\\ 0&0&0}
$$
is similar to the positive semidefinite matrix $A_1^{1/2}B_1A_1^{1/2}\oplus0\oplus0$:
\begin{aligned}
&\pmatrix{A_1^{-1/2}&0&A_1^{-1/2}B_1^{-1}Y^T\\ -XA_1^{-1}&I&0\\ 0&0&I}
\pmatrix{A_1B_1&0&AY^T\\ XB_1&0&XY^T\\ 0&0&0}
\pmatrix{A_1^{1/2}&0&-B_1^{-1}Y^T\\ XA_1^{-1/2}&I&-XA_1^{-1}B_1^{-1}Y^T\\ 0&0&I}\\
&=\pmatrix{A_1^{1/2}B_1&0&A_1^{1/2}Y^T\\ 0&0&0\\ 0&0&0}
\pmatrix{A_1^{1/2}&0&-B_1^{-1}Y^T\\ XA_1^{-1/2}&I&-XA_1^{-1}B_1^{-1}Y^T\\ 0&0&I}\\
&=\pmatrix{A_1^{1/2}B_1A_1^{1/2}&0&0\\ 0&0&0\\ 0&0&0}.
\end{aligned}
Hence $AB$ is diagonalisable.
A: preliminaries
$A^\frac{1}{2}BA^\frac{1}{2}$ is real symmetric positive semi-definite because
$\mathbf x^TA^\frac{1}{2}BA^\frac{1}{2}\mathbf x = \big\Vert B^\frac{1}{2}A^\frac{1}{2}\mathbf x\big\Vert_2^2\geq 0$ for any $\mathbf x \in \mathbb R^n$
we also know
$\text{trace}\Big(\big(A^\frac{1}{2}BA^\frac{1}{2}\big)^k\Big)= \text{trace}\Big(\big(AB\big)^k\Big)$
for all natural numbers $k$ so they have the same characteristic polynomials 
$C:=A^\frac{1}{2}BA^\frac{1}{2}$
and for natural numbers $k$ we have the useful identity
$A^\frac{1}{2}C^k A^\frac{1}{2}B = (AB)^{k+1}=  (AB)(AB)^{k} $ 
since $C$ is diagonalizable over reals we proceed with a minimal polynomial argument   
main argument
we have
$p(C) = \mathbf 0$
where $p$ is the minimal polynomial of $C$-- i.e. for this problem: $p$ is the characteristic polynomial of $C$ except there are no repeated roots. This implies  
$\mathbf 0 =A^\frac{1}{2} p(C)A^\frac{1}{2}B =  AB\cdot p(AB)=g\big(AB\big)$ 
Thus the polynomial $g$ annihilates $(AB)$, and $g$ has no repeated roots, except possibly with the eigenvalue zero. 
thus we know that for every distinct $\lambda \gt 0$ of $\big(AB\big)$ we have
$\text{geometric multiplicity}_{\text{of }\lambda}\big(AB\big)= \text{algebraic multiplicity}_{\text{of }\lambda}\big(AB\big) $ 
in other words: all positive eigenvalues of $\big(AB\big)$ are semi-simple 
semisimplicity of $\lambda =0$
underlying ideas in the below inequalities (i) submultiplicativity of rank which holds over any field, (ii) usefulness of matrix square root which is something of a special feature in $\mathbb R$ or $\mathbb C$ associated with positive semi-definiteness, (iii) in $\mathbb R$ or $\mathbb C$ we have
$\text{rank}\big(Z^*Z\big) = \text{rank}\big(Z\big)$ and $\text{rank}\big(Z^*Z\big)=\text{rank}\big(ZZ^*\big)$
for a crude proof of (iii): use Polar Decomposition  
To prove that zero is semisimple-- or equivalently, to prove that there isn't a 'shortage' of eigenvectors associated with the eigenvalue $0$, we need to estimate $(AB)$'s  rank   
$\text{rank}\big(AB\big)$
$=\text{rank}\big(B^*A^*AB\big)$
$=\text{rank}\big(BA^2B\big)$
$\leq\text{rank}\big(B^\frac{1}{2}A^2B\big)$
$\leq\text{rank}\big(B^\frac{1}{2}A^2B^\frac{1}{2}\big)$
$=\text{rank}\big(ABA\big)$
$\leq\text{rank}\big(A^\frac{1}{2}BA\big)$
$\leq\text{rank}\big(A^\frac{1}{2}BA^\frac{1}{2}\big)$ 
If we negate the above and add $n$ we can apply rank-nullity to get
$\text{algebraic multiplicity}_{\text{of }\lambda \text{= 0}}\big(A^\frac{1}{2}BA^\frac{1}{2}\big)$
$=\text{geometric multiplicity}_{\text{of }\lambda \text{= 0}}\big(A^\frac{1}{2}BA^\frac{1}{2}\big) $
$\leq \text{geometric multiplicity}_{\text{of }\lambda \text{= 0}}\big(AB\big) $
$\leq \text{algebraic multiplicity}_{\text{of }\lambda \text{= 0}}\big(AB\big) $
$=\text{algebraic multiplicity}_{\text{of }\lambda \text{= 0}}\big(A^\frac{1}{2}BA^\frac{1}{2}\big)$ 
that is, we have
$\text{geometric multiplicity}_{\text{of }\lambda \text{= 0}}\big(AB\big)= \text{algebraic multiplicity}_{\text{of }\lambda \text{= 0}}\big(AB\big) $ 
so we also know the eigenvalue of $0$ is semi-simple for $\big(AB\big)$, which  completes the proof.  
A: For my own reference, here is a proof modified from user8675309's excellent answer.
If $A$ is nonsingular, then $AB$ is similar to $A^{1/2}BA^{1/2}$ and hence it is diagonalisable.
If $A$ is singular, the minimal polynomial of $A^{1/2}BA^{1/2}$ will be in the form of $f(x)=xg(x)$ for some polynomial $g$. Since $(AB)(AB)^k=A^{1/2}(A^{1/2}BA^{1/2})^kA^{1/2}B$ for every $k\ge0$, we have
$$
ABf(AB)=A^{1/2}\,f(A^{1/2}BA^{1/2})\,A^{1/2}B=0.
$$
Now, for any vector $v$, let $x=g(AB)v$ and $y=B^{1/2}x$. Then
$$
(AB)^2x=(AB)^2g(AB)v=ABf(AB)v=0
$$
and we can make the following series of inferences:
\begin{aligned}
(AB)^2x=0
&\Rightarrow \left(B^{1/2}AB^{1/2}\right)^2y=0\\
&\Rightarrow B^{1/2}AB^{1/2}y=0\\
&\Rightarrow A^{1/2}B^{1/2}y=0\\
&\Rightarrow ABx=A^{1/2}(A^{1/2}B^{1/2}y)=0.\\
\end{aligned}
It follows that $f(AB)v=ABg(AB)v=ABx=0$. Since $v$ is arbitrary, $f$ must annihilate $AB$. As $f$ is the minimal polynomial of the positive semidefinite (hence diagonalisable) matrix $A^{1/2}BA^{1/2}$, it is a product of distinct linear factors. The minimal polynomial of $AB$, which divides the annihilating polynomial $f$, must therefore also be a product of distinct linear factors. Hence $AB$ is diagonalisable. Furthermore, as $AB$ has the same spectrum as $A^{1/2}BA^{1/2}$, the two products are similar to each other.
