Generalized "square root" of a real positive definite symmetric matrix with respect to another Related post: Square root of Positive Definite Matrix, which is a special case of this question ($A = I$).
Let $A$ and $B$ be real, symmetric, positive definite matrices of the same size $n \times n$.  The question is:  Does there exist a symmetric matrix $S$, such that $S A S = B$?  If there is, how to construct it?  If there is not, what conditions we can impose on $A$ and $B$, so that $S$ exists?
I know that in the case of $AB = BA$, $S$ exists.  But how is it in the general case?

Define $S$ by
$$ S = A^{-\frac{1}{2}} \left( A^{\frac{1}{2}} B A^{\frac{1}{2}}\right)^{\frac{1}{2}} A^{-\frac{1}{2}}. $$
Then $S$ is symmetric and so, by Theorem 2 of Wigner's "On Weakly Positive Matrices", $S$ is positive definite and
$$ SAS = A^{-\frac{1}{2}} \left( A^{\frac{1}{2}} B A^{\frac{1}{2}}\right)^{\frac{1}{2}} A^{\frac{1}{2}} A^{-\frac{1}{2}} \left( A^{\frac{1}{2}} B A^{\frac{1}{2}}\right)^{\frac{1}{2}} A^{-\frac{1}{2}} = A^{-\frac{1}{2}} \left( A^{\frac{1}{2}} B A^{\frac{1}{2}}\right) A^{-\frac{1}{2}} = B.   $$
The matrix $S$ is the unique positive definite matrix satisfying $SAS = B$. To see this, let $S$ be a positive definite matrix satisfying $SAS = B$ and define $S' = A^{\frac{1}{2}}SA^{\frac{1}{2}}$. Then $S'$ is also positive definite and we have
$$ S'^2 = A^{\frac{1}{2}}SA^{\frac{1}{2}}A^{\frac{1}{2}}SA^{\frac{1}{2}} = A^{\frac{1}{2}}BA^{\frac{1}{2}}. $$
The right hand side is also positive definite and so, by the uniqueness of the positive definite square root, $S'$ is determined uniquely which implies that $S$ is determined uniquely (as $A$ is invertible).
