<s>[INST] Diagonalizing symmetric real bilinear form I am given the following symmetric matrix:
$$
        A=\begin{pmatrix}
        1 & 2 & 0 & 1\\
        2 & 0 & 3 & 0\\
        0 & 3 & -1 & 1\\
        1 & 0 & 1 & 4\\
        \end{pmatrix}\in M_4(\Bbb R)
$$
Let $f\in Bil(V), f(u,v)=u^tAv.$
I want to find a base $B \subset \Bbb R^4$ such that the matrix representing $f $ in respect to $B$ is diagonal.
I took $
        v_1=\begin{pmatrix}
        1 \\
        0  \\
        0  \\
        0
        \end{pmatrix}
$ and found a vector space $V_2=\{v\in\Bbb R^4$| $f(v,v_1)=0\}$, and got $V_2 =sp\{ \begin{pmatrix}
        -2 \\
        1  \\
        0  \\
        0
        \end{pmatrix},\begin{pmatrix}
        0 \\
        0  \\
        1  \\
        0
        \end{pmatrix},\begin{pmatrix}
        -1 \\
        0  \\
        0  \\
        1
        \end{pmatrix}\} =sp\{v_2,v_3,v_4\}$
Now, the matrix in repect to $B=\{v_1,v_2,v_3,v_4\}$ looks like this:$$
        \begin{pmatrix}
        1 & 0 & 0 & 0\\
        0 & -4 & 3 & -2\\
        0 & 3 & -1 & 1\\
        0 & -2 & 1 & 3\\
        \end{pmatrix}
$$
I want to continue inductively, but I'm not sure how to procceed. 
 [/INST] The method of repeated completing squares also leads, by nature, to rational entries in this case. However, that is not the end of the story, as the given form is $SL_4 \mathbb Z$ equivalent to a diagonal form. In brief,
$$  (w + 2x+z)^2 + (x-2y+z)^2 - (9x-9y+13z)^2 + 19 (2x-2y+3z)^2 = w^2 - y^2 + 4z^2 + 4wx +6xy +2wz +2yz  $$
$$
A =
\left(
\begin{array}{rrrr}
1 & 2 & 0 & 1 \\
2 & 0 & 3 & 0 \\
0 & 3 & -1 & 1 \\
1 & 0 & 1 & 4
\end{array}
\right)
$$
$$
Q =
\left(
\begin{array}{rrrr}
1 & 2 & 0 & 1 \\
0 & 1 & -2 & 1 \\
0 & 9 & -9 & 13 \\
0 & 2 & -2 & 3
\end{array}
\right)
$$
and
$$
D =
\left(
\begin{array}{rrrr}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 19
\end{array}
\right)
$$
The one-line formula above is just
$$  Q^T D Q = A  $$
As far as the order the question was asked, we take
$$
P = Q^{-1} =
\left(
\begin{array}{rrrr}
1 & 2 & -6 & 25 \\
0 & -1 & 4 & -17 \\
0 & -1 & 1 & -4 \\
0 & 0 & -2 & 9
\end{array}
\right)
$$
to get
$$  P^T A P = D.  $$ Indeed,
$$
P^T  =
\left(
\begin{array}{rrrr}
1 & 0 & 0 & 0 \\
2 & -1 & -1 & 0 \\
-6 & 4 & 1 & -2 \\
25 & -17 & -4 & 9
\end{array}
\right)
$$ and
$$
\left(
\begin{array}{rrrr}
1 & 0 & 0 & 0 \\
2 & -1 & -1 & 0 \\
-6 & 4 & 1 & -2 \\
25 & -17 & -4 & 9
\end{array}
\right)
\left(
\begin{array}{rrrr}
1 & 2 & 0 & 1 \\
2 & 0 & 3 & 0 \\
0 & 3 & -1 & 1 \\
1 & 0 & 1 & 4
\end{array}
\right)
\left(
\begin{array}{rrrr}
1 & 2 & -6 & 25 \\
0 & -1 & 4 & -17 \\
0 & -1 & 1 & -4 \\
0 & 0 & -2 & 9
\end{array}
\right) =
\left(
\begin{array}{rrrr}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 \\
0 & 0 & 0 & 19
\end{array}
\right)
$$
</s>