7
$\begingroup$

Is there a way, or if not, how could one define a function which takes an equation in any form (for example as given by FullSimplify):

$$(A+X_0) x+By=3x$$

and rearranges it in the more compact and tidy form:

$$(A+X_0-3) x+By=0$$

$\endgroup$
0

1 Answer 1

14
$\begingroup$
ClearAll[a, b, c, d, x, y]
expr = a x + b y + c x == d x;

You can use any of

Collect[(expr /. Equal -> Subtract) == 0, x]
Collect[Subtract @@ expr == 0, x]
FullSimplify[(expr /. Equal -> Subtract) ] == 0 
FullSimplify[Subtract @@ expr] == 0

to get

(* (a + c - d) x + b y == 0 *)

Alternatively, use a custom ComplexityFunction that makes non-zero expressions on the right-hand-side of == more expensive:

cf[e_] := 100 Count[e, Equal[_, Except[0, _]], {0, Infinity}] + LeafCount[e]
FullSimplify[expr, ComplexityFunction -> cf]
(* (a + c - d) x + b y == 0 *)

Update: In versions 11.3+, you can use the function SubtractSides:

FullSimplify /@ SubtractSides[expr]
 (a + c - d) x + b y == 0
$\endgroup$
4
  • $\begingroup$ A very nice solution, that is with the complexity function. $\endgroup$ Mar 3, 2015 at 13:40
  • $\begingroup$ @kglr Hi! In v11.3 and wolframcloud, FullSimplify / @ SubtractSides[expr] can not run. Syntax: "FullSimplify cannotbe followedby@SubtractSide $\{$ expr']. $\endgroup$
    – lotus2019
    Mar 24, 2022 at 1:25
  • $\begingroup$ Thank you @lotus2019; the typo is fixed. $\endgroup$
    – kglr
    Mar 24, 2022 at 2:17
  • $\begingroup$ @kglr My pleasure. $\endgroup$
    – lotus2019
    Mar 24, 2022 at 2:25

Your Answer

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

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