2

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.

acl
  • 19,834
  • 3
  • 66
  • 91
Chris D
  • 21
  • 1

4 Answers4

3

Try this:

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

(*  5 x - y - z == 7  *)
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Alexei Boulbitch
  • 39,397
  • 2
  • 47
  • 96
3

The following works nicely:

Block[{cf = CoefficientArrays[#]}, Last[cf].Variables[Subtract @@ #] == -First[cf]] &[
       5 (x - 1) - (y + 1) - (z + 1) == 0]
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
3

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}
Simon Woods
  • 84,945
  • 8
  • 175
  • 324
2

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

PlatoManiac
  • 14,723
  • 2
  • 42
  • 74