Say I have a product of two polynomials and I need to rewrite it into as many squares as possible using similar sums and differences. Is there a way to achieve this in Mathematica ?
E.g.
a(a-b) = 0.5(a^2 - b^2 + (a-b)^2)
a(a+b) = 0.5(a^2 + b^2 + (a-b)^2)
a(3a-4b+c) = 0.5(a^2 - b^2 + (2a-b)^2 - (2b-c)^2 + (a-2b+c)^2)
Note that each subtracted square is of a similar form to the square it is subtracted from, while there may be extra added squares.
I am trying to do such a rewrite for a more complicated expression, such as:
(3a - 4b + c)(9a - 24b + 22c - 8d + e)
To me it seems similar to Writing an expression as sum of squares of expressions (I am no longer sure it is similar)
Any hints please? I need this for a smaller part of a Numerical Analysis / PDEs problem.
UPDATE
Thanks to reading up on @Daniel Lichtblau's suggestion about diagonalization, I just realized this is a type of Lagrange reduction, but with some constraints (on the coefficients used in the linear combinations), such that the terms will sum up from 1 to N in the way described below. I hope this helps? https://www.encyclopediaofmath.org/index.php/Lagrange_method
UPDATE (BRUTE FORCE)
I think maybe this might be brute-forced as follows: We need a linear combination of squares of a linear combination, where the inner linear combination might have zero coefficients.
e.g. a(a-b) = 0.5*[(1a+0b)^2 - (0a+1b)^2 + (1a-1b)^2]
and
a(3a-4b+c) = 0.5[(1a+0b+0c)^2 - (0a+1b+0c)^2 + (2a-1b+0c)^2 - (0a+2b-1c)^2 + (1a-2b+1c)^2] = 0.5(a^2 - b^2 + (2a-b)^2 - (2b-c)^2 + (a-2b+c)^2)
Here is what I am thinking:
- Given product P = (a + b + ...)(a + b + c + d +...)
- List all the terms $a,b,c,d,$ etc that are available in the product P
- Create squares of random linear combinations of the terms e.g. $(2a + 0b + 1c - d)^2$ where the coefficients can be any integer.
- Create random linear combinations of the above using coefficients $1$ and $-1$ (the kicker here is that I don't know how many terms from step 3 above, to linearly combine)
- Compare result to the product P. If it is equivalent upon expansion of P, end. If not, continue.
Old Update:
Here is a simplified explanation of what I am trying to do:
The terms a, b, c, etc are some variables $x,x_{n-1},x_{n-2}$ etc. This rearrangement is to help me obtain a telescoping sum when the product is summed from n=1 to a final value N. The final result must be positive sum, an initial expression at zero and a final expression at N.
e.g. $\displaystyle\sum_{n=1}^N(x_n - x_{n-1})x_n = 0.5\displaystyle\sum_{n=1}^N(x_n^2 -x_{n-1}^2 + (x_n-x_{n-1})^2)$ $=0.5x_N^2 - 0.5x_0^2 + 0.5\displaystyle\sum_{n=1}^N(x_n-x_{n-1})^2$
And we see that, thanks to the fact that the subtractions are deducted from an expression of similar form, the final answer will have an initial form, a final form and a sum that is definitely positive.
Similarly, using the rewriting above, I would be able to have
$\displaystyle\sum_{n=1}^N(3x_n - 4x_{n-1}+x_{n-2})x_n$
$=0.5x_N^2 - 0.5x_0^2 + 0.5(2x_N-x_{N-1})^2 - 0.5(2x_1-x_0)^2 + 0.5\displaystyle\sum_{n=1}^N(x_n-2x_{n-1}+x_{n-2})^2$
I think @march's graceful attempt in the answer below might be modified to include this constraint (?) on the subtracted forms, but I am not sure how to do this.
(3a - 4b + c)(9a - 24b + 22c - 8d + e)
can be rewritten as a positive plus a negative square:-4.79720198444 (1. a - 0.283636811685 b - 1.32868615928 c + 0.699797681099 d - 0.0874747101373 e)^2 + 31.7972019844 (1. a - 1.74105454634 b + 0.978891920593 c - 0.271814142004 d + 0.0339767677505 e)^2
$\endgroup$(2a+3b)^2 - (2b+3c)^2 + c^2
would be fine because the only subtracted term(2b+3c)
is from a similar term(2a+3b)
$\endgroup$