Elimination of variables the old-fashioned way I'm trying to eliminate variables in some fairly simple sets of equations. A typical example is: 
$$ 9 x^2 + 18 xy + 9 y^2 - 32 = 256z$$
$$ 9 x^2 + 6 xy - 3 y^2 - 8 = 376z$$
$$ 9 x^2 - 6 xy  + y^2 = 512z$$
I'd like to eliminate $x$ and $y$. Mathematica tells me that the answer is $ 161 z^2 -162z + 1 = 0 $. OK. Good.
But how would I do this elimination manually (without Mathematica). I'm hoping that there is some fairly simple mechanical process that I can express in a few hundred lines of C code.
I realize that general elimination procedures are pretty complex, but this sort of problem looks quite special and therefore easier (I hope). Roughly speaking, it's just a system of "linear" equations in the variables $x^2$, $xy$, $y^2$, and $z$. Is there some sort of diagonalization process that can be applied, for example ?
Edit:
From the proposed answer below, I see that things can be simplified by setting $p=3x+3y$ and $q = 3x-y$. Then the equations become:
$$p^2 = 32 + 256z$$
$$pq = 8 + 376z$$
$$q^2 = 512z$$
I can then eliminate $p$ and $q$. Is there always a linear transformation that simplifies the problem in this way? If there is, how do I compute it?
 A: You can use gaussian elimination (or other equivalent methods) to find expressions for $x^2$, $xy$ and $y^2$ in terms of $z$ - treating them as independent variables, and substitute these to get an equation for z. Then you still have to solve for $x$ and $y$. 
There is an easier way in this case, but in a general case this makes progress.
A: Mark's idea with the unknowns $\,x^2\,,\,xy\,,\,y^2\,$ , using the augmented matrix:
$$\begin{pmatrix} 9&18&9&\;\;256z+32\\9&6&\!\!\!\!-3&\;\;376z+8\\9&\!\!\!\!-6&1&\;\;512z\end{pmatrix}\stackrel{\begin{cases}R_2-R_1\\R_3-R_1\end{cases}}\longrightarrow \begin{pmatrix} 9&18&9&\;\;256z+32\\0&\!\!\!\!-12&\!\!\!\!-6&\;\;120z-24\\0&\!\!\!\!-24&\!\!\!\!-8&\;\;256z\end{pmatrix}\longrightarrow$$
$$\stackrel{R_3-2R_2}\longrightarrow \begin{pmatrix} 9&18&9&\;\;256z+32\\0&\!\!\!\!-12&\!\!\!\!-6&\;\;120z-24\\0&0&4&\;\;16z+48\end{pmatrix}$$
We get thus 
$$\text{From}\,\,R_3\,:\;\;4y^2=16z+48\Longrightarrow y=\pm\sqrt{4z+12}$$
$$\text{From}\,\,R_2\wedge R_3\,\,\text{above}\;\;-12xy-6y^2=120z-24\Longrightarrow $$
$$\pm 2x\sqrt{4z+12}-16z-48=20z-4\Longrightarrow \pm x\sqrt{4z+12}=18z+22\Longrightarrow$$
$$x=\pm\frac{9z+11}{z+3}$$
and etc. 
A: Clever Observant Solution (as in Mark's comment)
Denote the right-hand sides by $a$, $b$, $c$. In other words, $a = 32+256z$, $b = 8 + 376z$, $c = 512z$. Also, let $p = 3x + 3y$ and $q = 3x - y$. Then the equations become simply:
$$ p^2 = a \quad ; \quad pq = b \quad ; \quad q^2 = c$$
From this, we get $b^2 - ac = 0$. Substituting for $a$, $b$, $c$ gives us the same result we got from Mathematica: $161z^2 -162z + 1 = 0$.
Dumb Mechanical Solution (which is what I need)
Let $M$ be the matrix
$$ M = \begin{pmatrix} 9&18&9\\9&6&\!\!\!\!-3\\9&\!\!\!\!-6&1\end{pmatrix}$$
and let $u = x^2$, $v = xy$, $w = y^2$. Then the original equations can be written as
$M.[u, v, w]^t = [a, b, c]^t$.
Using standard techniques (eigenvalues or Gaussian elimination), we can find a diagonal matrix $D$ and an invertible matrix $P$ such that $P^{-1}MP = D$. The solution of the system of equations is then $[u, v, w]^t = PD^{-1}P^{-1}[a, b, c]^t$. Setting $v^2 = uw$ again gives us the equation $161z^2 -162z + 1 = 0$.
A: Factorize the left sides to separate x and y, and it's easy later.
