<s>[INST] Find invertible matrix $Q$ From the book "Bilinear forms and their matrices" by Prof. Joel Kamnitzer:

Consider: $$ A=\pmatrix{0 & 4 \\ 4 & 2} $$
  After doing simultaneous row and column operations we reach:
  $$ Q^tAQ= \pmatrix{-8 & 0 \\ 0 & 2} $$

And then he implies that $ Q= \pmatrix{1 & 0 \\ -2 & 1 }$ , which indeed verifies the result, but I do not know how he found that matrix. So I found the post "How to diagonalize a matrix" and tried to follow those steps. However the eigenvalues I found involve $\sqrt{17}$, and that number does not go away once I try to diagonlize the matrix. So I must be doing something wrong.
So, how can one find Q? A general solution is of course welcome too.
 [/INST] Algorithm discussed at http://math.stackexchange.com/questions/1388421/reference-for-linear-algebra-books-that-teach-reverse-hermite-method-for-symmetr
https://en.wikipedia.org/wiki/Sylvester%27s_law_of_inertia
$$ H = \left( 
\begin{array}{rr} 
0 & 4 \\ 
4 & 2 \\ 
\end{array}
\right) 
$$
$$  D_0 = H  $$
$$ E_j^T D_{j-1} E_j = D_j  $$
$$  P_{j-1} E_j = P_j  $$
$$ E_j^{-1} Q_{j-1}  = Q_j  $$
$$  P_j Q_j = Q_j P_j = I  $$
$$ P_j^T H P_j = D_j  $$
$$ Q_j^T D_j Q_j = H  $$
$$ H = \left( 
\begin{array}{rr} 
0 & 4 \\ 
4 & 2 \\ 
\end{array}
\right) 
$$
==============================================
$$ E_{1} = \left( 
\begin{array}{rr} 
0 & 1 \\ 
1 & 0 \\ 
\end{array}
\right) 
$$
$$  P_{1} = \left( 
\begin{array}{rr} 
0 & 1 \\ 
1 & 0 \\ 
\end{array}
\right) 
, \; \; \; Q_{1} = \left( 
\begin{array}{rr} 
0 & 1 \\ 
1 & 0 \\ 
\end{array}
\right) 
, \; \; \; D_{1} = \left( 
\begin{array}{rr} 
2 & 4 \\ 
4 & 0 \\ 
\end{array}
\right) 
$$
==============================================
$$ E_{2} = \left( 
\begin{array}{rr} 
1 &  - 2 \\ 
0 & 1 \\ 
\end{array}
\right) 
$$
$$  P_{2} = \left( 
\begin{array}{rr} 
0 & 1 \\ 
1 &  - 2 \\ 
\end{array}
\right) 
, \; \; \; Q_{2} = \left( 
\begin{array}{rr} 
2 & 1 \\ 
1 & 0 \\ 
\end{array}
\right) 
, \; \; \; D_{2} = \left( 
\begin{array}{rr} 
2 & 0 \\ 
0 &  - 8 \\ 
\end{array}
\right) 
$$
==============================================
$$ P^T H P = D  $$
$$\left( 
\begin{array}{rr} 
0 & 1 \\ 
1 &  - 2 \\ 
\end{array}
\right) 
\left( 
\begin{array}{rr} 
0 & 4 \\ 
4 & 2 \\ 
\end{array}
\right) 
\left( 
\begin{array}{rr} 
0 & 1 \\ 
1 &  - 2 \\ 
\end{array}
\right) 
 = \left( 
\begin{array}{rr} 
2 & 0 \\ 
0 &  - 8 \\ 
\end{array}
\right) 
$$
$$ Q^T D Q = H  $$
$$\left( 
\begin{array}{rr} 
2 & 1 \\ 
1 & 0 \\ 
\end{array}
\right) 
\left( 
\begin{array}{rr} 
2 & 0 \\ 
0 &  - 8 \\ 
\end{array}
\right) 
\left( 
\begin{array}{rr} 
2 & 1 \\ 
1 & 0 \\ 
\end{array}
\right) 
 = \left( 
\begin{array}{rr} 
0 & 4 \\ 
4 & 2 \\ 
\end{array}
\right) 
$$
..............
</s>