Quadratic forms into sums of squares of linear forms

93 Views Asked by At

I would like to know whether there exists software or online calculators that turn quadratic forms directly into sums/differences of squares of linear forms? For instance:

For $q(x,y,z) = 2x^2 - 2y^2 - 6z^2 + 3xy - 4xz + 7yz$

Returns $q(x,y,z) = 2(x + \frac{3}{4}y - z)^2 - 8(z - \frac{5}{8}y)^2$

I know how to compute it using the Gauß reduction method, but I wish I could get it swifter...

Thanks — I'm a French student, sorry if I made any language mistakes.

1

There are 1 best solutions below

1
On

With MATHEMATICA you can proceed with

Clear[SquareIt]
SquareIt[expr_, vars_List] := Module[{n = Length[vars], rels, coefs, sol, varsint, obj},
  obj = Sum[a[i] Sum[b[i, j] vars[[j]], {j, 1, n}]^2, {i, 1, n}];
  rels = CoefficientRules[expr - obj, vars];
  coefs = Map[Last, rels];
  varsint = Variables[coefs];
  sol = FindInstance[coefs == 0, varsint][[1]];
  Return[obj /. sol]
]

SquareIt[2 x^2 - 2 y^2 - 6 z^2 + 3 x y - 4 x z + 7 y z, {x, y, z}]

$$ \frac{25}{8} \left(x+\frac{z}{5}\right)^2-\frac{9}{8} \left(x-\frac{4 y}{3}+\frac{7 z}{3}\right)^2 $$

NOTE

Regarding

$$ 2 a x^2-6 a z^2-2 b y^2+3 c x y-4 x z+7 y z $$

Manually first we separate the squares as

$$ 2 a x^2-6 a z^2-2 b y^2 $$

and then we use the identity

$$ x_i x_j = \frac 14\left((x_i+x_j)^2-(x_i-x_j)^2)\right) $$

obtaining

$$ 2 a x^2-6 a z^2-2 b y^2+\frac{3}{4} c \left((x+y)^2-(y-x)^2\right)+(z-x)^2-(x+z)^2+\frac{7}{4} \left((y+z)^2-(z-y)^2\right) $$

Gauss method.