Simultaneous congruence diagonalization with a positive form (source code)

= Simultaneous congruence diagonalization with a positive form
{title2=$P^TAP=I,\quad P^TBP=\operatorname{diag}(\lambda_j)$}

If $A$ is real symmetric positive definite and $B$ is real symmetric, let $S=A^{-1/2}$. The matrix $SBS$ is symmetric and has an orthonormal eigenbasis, represented by $Q$. Taking $P=SQ$ gives the two displayed congruences. The diagonal entries are determined by the <generalized eigenvalue problem> $\det(B-\lambda A)=0$, since $P^T(B-\lambda A)P$ is diagonal with entries $\lambda_j-\lambda$. Positive definiteness of the first form is essential to this construction.