<s>[INST] Find an orthonormal basis and the signature of the quadratic form 
Consider the quadratic form given by the matrix below (in the canonical basis)
\begin{pmatrix}
1 & 1 & -1\\
1 & 1 & 3\\
-1 & 3 & 1
\end{pmatrix}
Find an orthonormal basis of it and find its signature.


First I calculated the eigenvalues, which are $4, \frac{-1+ \sqrt{17}}{2}, \frac{-1-\sqrt{17}}{2}$. Then I calculated the eigenvectors associated to $4$ and $\frac{-1+ \sqrt{17}}{2}$ and normalized them, which gave me
\begin{align}
    e_1 &= \frac{1}{\sqrt{2}}\begin{bmatrix}
           0 \\
           1 \\
            1
         \end{bmatrix}, \quad
e_2 = \frac{\sqrt{2}}{\sqrt{17+3\sqrt{17}}}\begin{bmatrix}
           -\frac{3+\sqrt{17}}{2} \\
           -1 \\
            1
         \end{bmatrix}
  \end{align}
And the third vector of the basis I want to be orthogonal to $e_1$ and $e_2$, so
$$e_3 = \frac{1}{\sqrt{17+3\sqrt{17}}} e_1 \wedge e_2 =\frac{1}{\sqrt{17+3\sqrt{17}}} \begin{bmatrix}
           2 \\
           -\frac{3+\sqrt{17}}{2} \\
            \frac{3+\sqrt{17}}{2}
         \end{bmatrix} $$
I can't detail the calculations because they are very big. Perhaps someone can confirm the results. For the signature I know that the two possibilities are $(0,3)$ and $(2,1)$ but I don't know how to find the right one.
 [/INST] Using SymPy:
>>> from sympy import *
>>> A = Matrix([[ 1, 1,-1],
                [ 1, 1, 3],
                [-1, 3, 1]])
>>> Q, D = A.diagonalize(normalize=True)
>>> D
Matrix([
[4,                 0,                 0],
[0, -1/2 + sqrt(17)/2,                 0],
[0,                 0, -sqrt(17)/2 - 1/2]])
>>> simplify(Q)
Matrix([
[        0, -sqrt(2)*(3 + sqrt(17))/(2*sqrt(3*sqrt(17) + 17)), sqrt(2)*(-3 + sqrt(17))/(2*sqrt(17 - 3*sqrt(17)))],
[sqrt(2)/2,                    -sqrt(2)/sqrt(3*sqrt(17) + 17),                    -sqrt(2)/sqrt(17 - 3*sqrt(17))],
[sqrt(2)/2,                     sqrt(2)/sqrt(3*sqrt(17) + 17),                     sqrt(2)/sqrt(17 - 3*sqrt(17))]])

Using function latex, we obtain
$$Q = \left[\begin{matrix}0 & - \frac{\sqrt{2} \left(3 + \sqrt{17}\right)}{2 \sqrt{3 \sqrt{17} + 17}} & \frac{\sqrt{2} \left(-3 + \sqrt{17}\right)}{2 \sqrt{17 - 3 \sqrt{17}}}\\\frac{\sqrt{2}}{2} & - \frac{\sqrt{2}}{\sqrt{3 \sqrt{17} + 17}} & - \frac{\sqrt{2}}{\sqrt{17 - 3 \sqrt{17}}}\\\frac{\sqrt{2}}{2} & \frac{\sqrt{2}}{\sqrt{3 \sqrt{17} + 17}} & \frac{\sqrt{2}}{\sqrt{17 - 3 \sqrt{17}}}\end{matrix}\right]$$
</s>