Take the equation $f(x,y,z) = x y^2 + (1-x)(y-z)^2$. I want to rewrite this in the form $(y+a(x,z))^2 + b(x,z)$. This can easily be solved by hand, with $a(x,z) = - z(1-x)$ and $b(x,z) = x(1-x)z^2$. The actual problem I want to solve is more complicated than this and can't as easily be done by hand, but the essence of the problem should be the same - I want Mathematica to solve the equation
$$x y^2 + (1-x)(y-z)^2 = (y+a)^2 + b$$
for $a$ and $b$, with the constraint that $a$ and $b$ can only be functions of $x$ and $z$. Is there any way of imposing this condition? Simply plugging in the equation into Solve
,
Solve[x*y^2 + (1 - x) ((y + z)^2) == (y + a)^2 + b, {a, b}]
obviously does not work, since the equation by itself is not sufficiently constrained. I tried replacing a
with a[x,z]
and likewise for b
, but Mathematica didn't know what to do with that and just treated a[x,z]
as a variable.