2
$\begingroup$

I have 5(x-1)-(y+1)-(z+1)==0. If I use FullSimplify on it it returns 5x==7+x+y. This is not what I want: I want it to return 5x-y-z==7.

$\endgroup$
1

4 Answers 4

3
$\begingroup$

The following works nicely:

Block[{cf = CoefficientArrays[#]}, Last[cf].Variables[Subtract @@ #] == -First[cf]] &[
       5 (x - 1) - (y + 1) - (z + 1) == 0]
$\endgroup$
3
$\begingroup$

Try this:

eq = 5 (x - 1) - (y + 1) - (z + 1) == 0
Map[Plus[7, #] &, Expand[eq]]

(*  5 x - y - z == 7  *)
$\endgroup$
3
$\begingroup$

Another option:

expr = 5 (x - 1) - (y + 1) - (z + 1) == 0;
Expand[expr]//.{a_==b:Except[_?NumericQ]:>a-b==0,a___+b_?NumericQ==c_:>Plus@a==c-b}
$\endgroup$
2
$\begingroup$

One way is

body = 5 (x - 1) - (y + 1) - (z + 1);
(#[[2]].Variables[body] == -1*#[[1]]) &@
Flatten[Normal@CoefficientArrays[{body == 0}, {x, y, z}], 1]

BR

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.