Re: Sum of Squares
- To: mathgroup at smc.vnet.net
- Subject: [mg26615] Re: [mg26587] Sum of Squares
- From: BobHanlon at aol.com
- Date: Thu, 11 Jan 2001 10:39:22 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Here is an approach var = {x, y, z}; expr1 = 5 x^2 + 8 x y + 5 y^2 + 2 x z - 2 y z + 2 z^2; expr2 = Plus @@ ((Partition[coef = Table[Unique[s], {2*Length[var]}], Length[var]].var)^2); cl1 = Flatten[CoefficientList[expr1, var]]; cl2 = Flatten[CoefficientList[expr2, var]]; soln = Solve[Complement[Thread[cl1 == cl2],{True}], coef]; There are multiple solutions ans = expr2 /. soln /. coef[[3]] -> 1 {(-2*x - y - z)^2 + (-x - 2*y + z)^2, (-x - 2*y + z)^2 + (2*x + y + z)^2, (x + 2*y - z)^2 + (2*x + y + z)^2, (-x - 2*y + z)^2 + (2*x + y + z)^2} And @@ ((expr1 == Expand[#])& /@ ans) True Bob Hanlon In a message dated 2001/1/9 2:28:14 AM, wself at msubillings.edu writes: >Is there, or could there be, a "sum of squares" function for >multivariate polynomials, which would rewrite an expression as a sum of >squares, when possible? > >It might work like this: > >SumOfSquares[5 x^2 + 8 x y + 5 y^2 + 2 x z - 2 y z + 2 z^2] > >---> > >(x + 2y - z)^2 + (2x + y + z)^2 >