Rational quadratic forms The quadratic form
$$10x^2+20y^2+2z^2+4xy-6xz+8yz$$
can be written as $x^TAx$, where A = [ [10,2,-3] , [2,20,4] , [-3,4,2] ]
Using diagonalization, this can be written in the form $a_1y_1^2+a_2y_2^2+a_3y_3^2$
But how do I get the alternative form
$$(x+2y)^2+(3x-z)^2+(4y+z)^2$$
In general, how can I check if a quadratic form can be transformed in this way in
$\mathbb Q$ ?
The eigenvalues do not help because in my example there are only irrational
eigenvalues.
 A: Define $u=x+2y,v=3x-z, w=4y+z$ and $r=\{x,y,x\}^T, R=\{u,v,w\}^T$.
Then we have
$$\left(\begin{matrix}u \\v \\w \end{matrix}\right)=\left(\begin{matrix}1 & 2 & 0\\3 & 0 & -1\\0 & 4 & 1\end{matrix}\right)\left(\begin{matrix}x \\y \\z \end{matrix}\right) \implies R =Pr \implies r=P^{-1}R......(1)$$
where
$$P:=\left(\begin{matrix}1 & 2 & 0\\3 & 0 & -1\\0 & 4 & 1\end{matrix}\right)$$
$$I=10x^2+20y^2+2z^2+4xy-6xz+8yz=r^TAr$$ 
$$\implies I=R^TBR$$
where 
$$B:=(P^{-1})^TAP^{-1}=\left(\begin{matrix}1 & 0 & 0\\0 & 1 & 0\\0 & 0 & 1\end{matrix}\right)......(2)$$
Thus if the basis $u,v,w$ are known as linear combinations of $x,y,z$, then we can always find matrix $B$.  However if we require that $B$ is an identity matrix, then we may not be able to solve $P^{-1}$ from (2).
A: I won't give all possible detail, but this is actually a number theory question. For a change of variable such as requested, it is necessary for the matrix $A$ to be positive definite, or at least semidefinite. If definite, the determinant, now nonzero, must be a (rational) square, because you are asking for $A = P^T P$ for some rational $P.$  
After that, it is the Hasse-Minkowski principle. If successful for all primes, (we already checked the prime called $\infty$) there is a rational matrix $P.$ In favorable circumstances, this will also be integral, as here. I suspect that integral is always possible if there is a rational solution, 3 by 3, for $A = P^T P$ with $A$ integral. Need to thing about that; it matters that $x^2 + y^2 + z^2$ has class number 1.
However, it is easy enough for there to be no rational solution, even with positive and square determinant, for example
$$ x^2 + 3 y^2 + 3 z^2.$$
A little experimentation will show that there is no integral solution. You might think that there is room for a rational solution (matrix $P$) but this fails, as the form is anisotropic in $\mathbb Q_3.$
I think what you are looking for, a procedure, is called Hermite Reduction. 
