1

We know that completing $ax^2+bxy+cz^2$ into forms of $k_{1}(a_{1}x+b_{1}y)^2+k_{2}(a_{2}x+b_{2}y)^2$ is easy and have some fixed routine. But the 3 variable case $$ax^2+by^2+cz^2+dxy+exz+fyx$$does not seem as trivial. Is there any general formula that will complete this into a linear combination of 3 squares?

For example, $$xy+xz-3yz=\frac{1}{3}x^2-\frac{3}{4}(\frac{2}{3}x-y-z)^2+\frac{3}{4}(y-z)^2$$ In this example I used undetermined coefficients method, but it is complicated and have too many variables.

Jimmy R.
  • 35,868
  • Yes. Rewrite your quadratic form as $v^T Av$ where $v = (x, y, z)$ and $A$ is a symmetric matrix, then compute the eigenvectors and eigenvalues of $A$. Look up the spectral theorem and/or diagonalization of quadratic forms. – Qiaochu Yuan Dec 13 '15 at 09:47
  • 1
    @QiaochuYuan, completing the square is Hermite's method and refers to $Q^T A Q = D,$ where $\det Q = \pm 1,$ rational entries, but not orthogonal, and the entries of $D$ are not the eigenvalues. As soon as we have at least three variables, the eigenvalues may not be tractable. See http://math.stackexchange.com/questions/395634/given-a-4-times-4-symmetric-matrix-is-there-an-efficient-way-to-find-its-eige with bad eigenvalues but nice undergraduate algorithm. – Will Jagy Dec 13 '15 at 18:20
  • 2
    Fair enough, you may not want to require that $Q$ is orthogonal. – Qiaochu Yuan Dec 13 '15 at 18:22

2 Answers2

1

I think I will type in the answer first in a readble manner. Finding it is Hermite's method, standard stuff in any book about quadratic forms. It is traditional to write forms in three variables as $$ g(x,y,z) = a x^2 + b y^2 + c z^2 + d y z + e z x + f x y. $$ Note the $zx$ order, everything cyclic...

With variables as coefficients, we cannot cover the occasional difficulties. Define $$ \delta = 4 a b - f^2 $$ and $$ \Delta = 4abc + def - a d^2 - b e^2 - c f^2. $$ Note that $\delta$ is minus the discriminant of the binary form $a x^2 + f x y + b y^2.$ Then $\Delta$ is the discriminant of Brandt and Intrau, minus the discriminant of Watson, and the same as Lehman, for $g$ itself.

In order to avoid denominators, we get $$ 4a \delta g(x,y,z) = \delta (2ax + f y + e z)^2 + (\delta y + (2ad-ef)z)^2 + 4 a \Delta z^2. $$

When $\Delta = 0,$ this just says that $g$ is not full rank, it is really a binary form in disguise. If $\delta = 0,$ it is probably best to permute the variables, in order to permute the coefficients and so make both $a$ and $\delta$ nonzero. As I said, we cannot cover every possible problem when using variable coefficients.

If desired, there is an algorithmic method; depending on the use, one may need to invert a certain matrix at the end. However, that matrix will be three by three with determinant $1,$ so the inverse is not difficult. See answer by el.Salvador at Given a $4\times 4$ symmetric matrix, is there an efficient way to find its eigenvalues and diagonalize it?

Will Jagy
  • 139,541
0

Thought I would display what el.Slavador's algorithm from Given a $4\times 4$ symmetric matrix, is there an efficient way to find its eigenvalues and diagonalize it? does for your form $xy + zx - 3yz.$ I had to double to get integers in $M,$ not really important. It boils down to $$ \left(\frac{1}{2} \, x + \frac{1}{2} \, y - z \right)^2 - \frac{1}{4} (-x+y+4z)^2 + 3 z^2 = xy + zx - 3yz. $$

$$ Q^T D Q = H $$ $$\left( \begin{array}{rrr} \frac{ 1 }{ 2 } & - 1 & 0 \\ \frac{ 1 }{ 2 } & 1 & 0 \\ - 1 & 4 & 1 \\ \end{array} \right) \left( \begin{array}{rrr} 2 & 0 & 0 \\ 0 & - \frac{ 1 }{ 2 } & 0 \\ 0 & 0 & 6 \\ \end{array} \right) \left( \begin{array}{rrr} \frac{ 1 }{ 2 } & \frac{ 1 }{ 2 } & - 1 \\ - 1 & 1 & 4 \\ 0 & 0 & 1 \\ \end{array} \right) = \left( \begin{array}{rrr} 0 & 1 & 1 \\ 1 & 0 & - 3 \\ 1 & - 3 & 0 \\ \end{array} \right) $$

$$ 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 = I $$ $$ P_j^T H P_j = D_j $$ $$ Q_j^T D_j Q_j = H $$

$$ H = \left( \begin{array}{rrr} 0 & 1 & 1 \\ 1 & 0 & - 3 \\ 1 & - 3 & 0 \\ \end{array} \right) $$

==============================================

$$ E_{1} = \left( \begin{array}{rrr} 1 & 0 & 0 \\ 1 & 1 & 0 \\ 0 & 0 & 1 \\ \end{array} \right) $$ $$ P_{1} = \left( \begin{array}{rrr} 1 & 0 & 0 \\ 1 & 1 & 0 \\ 0 & 0 & 1 \\ \end{array} \right) , \; \; \; Q_{1} = \left( \begin{array}{rrr} 1 & 0 & 0 \\ - 1 & 1 & 0 \\ 0 & 0 & 1 \\ \end{array} \right) , \; \; \; D_{1} = \left( \begin{array}{rrr} 2 & 1 & - 2 \\ 1 & 0 & - 3 \\ - 2 & - 3 & 0 \\ \end{array} \right) $$

==============================================

$$ E_{2} = \left( \begin{array}{rrr} 1 & - \frac{ 1 }{ 2 } & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ \end{array} \right) $$ $$ P_{2} = \left( \begin{array}{rrr} 1 & - \frac{ 1 }{ 2 } & 0 \\ 1 & \frac{ 1 }{ 2 } & 0 \\ 0 & 0 & 1 \\ \end{array} \right) , \; \; \; Q_{2} = \left( \begin{array}{rrr} \frac{ 1 }{ 2 } & \frac{ 1 }{ 2 } & 0 \\ - 1 & 1 & 0 \\ 0 & 0 & 1 \\ \end{array} \right) , \; \; \; D_{2} = \left( \begin{array}{rrr} 2 & 0 & - 2 \\ 0 & - \frac{ 1 }{ 2 } & - 2 \\ - 2 & - 2 & 0 \\ \end{array} \right) $$

==============================================

$$ E_{3} = \left( \begin{array}{rrr} 1 & 0 & 1 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ \end{array} \right) $$ $$ P_{3} = \left( \begin{array}{rrr} 1 & - \frac{ 1 }{ 2 } & 1 \\ 1 & \frac{ 1 }{ 2 } & 1 \\ 0 & 0 & 1 \\ \end{array} \right) , \; \; \; Q_{3} = \left( \begin{array}{rrr} \frac{ 1 }{ 2 } & \frac{ 1 }{ 2 } & - 1 \\ - 1 & 1 & 0 \\ 0 & 0 & 1 \\ \end{array} \right) , \; \; \; D_{3} = \left( \begin{array}{rrr} 2 & 0 & 0 \\ 0 & - \frac{ 1 }{ 2 } & - 2 \\ 0 & - 2 & - 2 \\ \end{array} \right) $$

==============================================

$$ E_{4} = \left( \begin{array}{rrr} 1 & 0 & 0 \\ 0 & 1 & - 4 \\ 0 & 0 & 1 \\ \end{array} \right) $$ $$ P_{4} = \left( \begin{array}{rrr} 1 & - \frac{ 1 }{ 2 } & 3 \\ 1 & \frac{ 1 }{ 2 } & - 1 \\ 0 & 0 & 1 \\ \end{array} \right) , \; \; \; Q_{4} = \left( \begin{array}{rrr} \frac{ 1 }{ 2 } & \frac{ 1 }{ 2 } & - 1 \\ - 1 & 1 & 4 \\ 0 & 0 & 1 \\ \end{array} \right) , \; \; \; D_{4} = \left( \begin{array}{rrr} 2 & 0 & 0 \\ 0 & - \frac{ 1 }{ 2 } & 0 \\ 0 & 0 & 6 \\ \end{array} \right) $$

==============================================

$$ P^T H P = D $$ $$\left( \begin{array}{rrr} 1 & 1 & 0 \\ - \frac{ 1 }{ 2 } & \frac{ 1 }{ 2 } & 0 \\ 3 & - 1 & 1 \\ \end{array} \right) \left( \begin{array}{rrr} 0 & 1 & 1 \\ 1 & 0 & - 3 \\ 1 & - 3 & 0 \\ \end{array} \right) \left( \begin{array}{rrr} 1 & - \frac{ 1 }{ 2 } & 3 \\ 1 & \frac{ 1 }{ 2 } & - 1 \\ 0 & 0 & 1 \\ \end{array} \right) = \left( \begin{array}{rrr} 2 & 0 & 0 \\ 0 & - \frac{ 1 }{ 2 } & 0 \\ 0 & 0 & 6 \\ \end{array} \right) $$ $$ Q^T D Q = H $$ $$\left( \begin{array}{rrr} \frac{ 1 }{ 2 } & - 1 & 0 \\ \frac{ 1 }{ 2 } & 1 & 0 \\ - 1 & 4 & 1 \\ \end{array} \right) \left( \begin{array}{rrr} 2 & 0 & 0 \\ 0 & - \frac{ 1 }{ 2 } & 0 \\ 0 & 0 & 6 \\ \end{array} \right) \left( \begin{array}{rrr} \frac{ 1 }{ 2 } & \frac{ 1 }{ 2 } & - 1 \\ - 1 & 1 & 4 \\ 0 & 0 & 1 \\ \end{array} \right) = \left( \begin{array}{rrr} 0 & 1 & 1 \\ 1 & 0 & - 3 \\ 1 & - 3 & 0 \\ \end{array} \right) $$

    PARI/GP is free software, covered by the GNU General Public License, and comes WITHOUT ANY WARRANTY WHATSOEVER.

    Type ? for help, \q to quit.
    Type ?12 for how to get moral (and possibly technical) support.

    parisize = 4000000, primelimit = 500509
    ? m = [ 0,1,1; 1,0,-3; 1,-3,0]
    %1 = 
    [0 1 1]

    [1 0 -3]

    [1 -3 0]

    ? m - mattranspose(m)
    %2 = 
    [0 0 0]

    [0 0 0]

    [0 0 0]

    ? p1 = [ 1,0,0; 1,1,0; 0,0,1]
    %3 = 
    [1 0 0]

    [1 1 0]

    [0 0 1]

    ? 
    ? m1 = mattranspose(p1) * m * p1
    %4 = 
    [2 1 -2]

    [1 0 -3]

    [-2 -3 0]



    p2 = [ 1, -1/2, 1; 0,1,0; 0,0,1]    


    ? p2 = [ 1, -1/2, 1; 0,1,0; 0,0,1]  
    %5 = 
    [1 -1/2 1]

    [0 1 0]

    [0 0 1]

    ? m2 = mattranspose(p2) * m1 * p2 
    %6 = 
    [2 0 0]

    [0 -1/2 -2]

    [0 -2 -2]

    ? 

    p3 = [1,0,0; 0,1,-4; 0,0,1]
    ? 
    ? p3 = [1,0,0; 0,1,-4; 0,0,1]
    %7 = 
    [1 0 0]

    [0 1 -4]

    [0 0 1]

    ? m3 = mattranspose(p3) * m2 * p3   
    %8 = 
    [2 0 0]

    [0 -1/2 0]

    [0 0 6]

    ? p = p1 * p2 * p3
    %9 = 
    [1 -1/2 3]

    [1 1/2 -1]

    [0 0 1]

    ? 
    ? matdet(p)
    %10 = 1
    ? 
    ? q = matadjoint(p)
    %11 = 
    [1/2 1/2 -1]

    [-1 1 4]

    [0 0 1]

    ? 
    ? m3
    %12 = 
    [2 0 0]

    [0 -1/2 0]

    [0 0 6]

    ? 
    ?  mattranspose(q) * m3 * q   
    %13 = 
    [0 1 1]

    [1 0 -3]

    [1 -3 0]

? m
%14 = 
[0 1 1]

[1 0 -3]

[1 -3 0]

? p
%15 = 
[1 -1/2 3]

[1 1/2 -1]

[0 0 1]

? 
?  mattranspose(p) * m * p    
%16 = 
[2 0 0]

[0 -1/2 0]

[0 0 6]

? 

I collected a bunch of these, in some i answer and typeset as well, easier to read than this one:

reference for linear algebra books that teach reverse Hermite method for symmetric matrices

Bilinear Form Diagonalisation

Given a $4\times 4$ symmetric matrix, is there an efficient way to find its eigenvalues and diagonalize it?

Find the transitional matrix that would transform this form to a diagonal form.

Writing an expression as a sum of squares

Determining matrix $A$ and $B$, rectangular matrix

Will Jagy
  • 139,541