The combination of Reduce
and ReplaceAll
may help:
Reduce[a == b + c + d - e /. c -> aa - d, aa] /. aa -> c + d
(* c + d == a - b + e *)
There's a defection in the solution above: it won't work correctly if the original equation contains the variable aa
, of course in most cases we can avoid the duplication of name manually without much effort, but here I'd like to add a safer one:
Reduce[a == b + c + d - e /. c -> # - d, #] /. # -> c + d &@Unique["a"]
(* c + d == a - b + e *)
Unique
is used to create a symbol that has never been used. This solution will work even if a
has got an value:
a = 1;
Reduce[a == b + c + d - e /. c -> # - d, #] /. # -> c + d &@Unique["a"]
(* c + d == 1 - b + e *)
Let's make it into a funtion:
newReduce[x_Equal, y_Plus]y_] := Reduce[x /. First@ySolve[y ->== #, Cases[x, _Symbol, {-1}, Rest@y1]], #] /. # -> y &@Unique["a"]
The first argument of newReduce
is the equation, and the second one is the "multiple variables", for example:
a = 2;
newReduce[x + r y + z == d a + 2 u - op/3, x + y + z]
(* x + y + z == 1/3 (6 d - op + 6 u + 3 y - 3 r y) *)
newReduce[x + r /y + z == d /a + 2 u - op/3, x y + y z]
(* x y + y z == 1/6 (-6 r + 3 d y - 2 op y + 12 u y) && y != 0 *)
newReduce[x + r /y + z == d a + 2 u - op/3, x y z]
(* x y z == -(1/3) z (3 r - 6 d y + op y - 6 u y + 3 y z) && y z != 0 *)
As you see, now it works not only for the "multiple variables" with the head Plus
.