1
$\begingroup$

I wonder that which command can rearrange one side of a equation into 0, e.g. "ax==by" into "ax-by==0".

$\endgroup$
2
  • 2
    $\begingroup$ closely related/possible duplicate Q/A: Arrange equation in normal form $\endgroup$
    – kglr
    Commented Nov 29, 2017 at 3:09
  • 2
    $\begingroup$ # - eqn[[-1]] & /@ eqn $\endgroup$
    – Bob Hanlon
    Commented Nov 29, 2017 at 3:31

5 Answers 5

3
$\begingroup$

Here are a couple of ways:

#1 - #2 == 0 & @@ (a x == b y)

(* a x - b y == 0 *)


#[[1]] - #[[2]] == 0 &@ (a x == b y)

(* a x - b y == 0 *)

As far as I can tell, they're going to work on any equation, with no modification. And it's straightforward to define

lhsequals0 = #[[1]] - #[[2]] == 0 &

so that, for example

lhsequals0[3 x^2 + 2 y - 4 == 6 xy^2 - 4 x^2 + Cos[Sqrt[y]]]

(* -4 + 7 x^2 - 6 xy^2 + 2 y - Cos[Sqrt[y]] == 0 *)

Just to give a sense of how and why this works, look at the FullForm for your equation:

FullForm[a x == b y]

(* Equal[Times[a, x], Times[b, y]] *)

An equation will always have the head Equal, with the first argument (#[[1]] or #1, depending) being the lhs and the second (#[[2]] or #2) being the rhs. So all both of the above functions are doing is subtracting the rhs from the lhs and setting Equal to zero.

Do see @kglr's link in the comments for some more in-depth answers.

$\endgroup$
2
  • $\begingroup$ Thanks aardvark2012! your way seems elegant. $\endgroup$
    – Charles6
    Commented Nov 29, 2017 at 7:00
  • $\begingroup$ @HC6 Realised I was needlessly complicating it. Fixed now. $\endgroup$ Commented Nov 29, 2017 at 7:11
3
$\begingroup$

"ax==by" into "ax+by==0".

I assume you meant a x - b y ==0 in the above.

One way (out of many I am sure) is

ClearAll[x,y,a,b,lhs,rhs];
eq=a x==b y;
lhs=eq/.(lhs_==rhs_)-> lhs;
rhs=eq/.(lhs_==rhs_)-> rhs;
eq=lhs-rhs==0

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ Oh, silly me! I do mean "ax-by==0" $\endgroup$
    – Charles6
    Commented Nov 29, 2017 at 6:47
3
$\begingroup$

You can use Thread on Equal:

eqn = a x == b y;

Thread[eqn - b y, Equal]

a x - b y == 0

$\endgroup$
1
  • $\begingroup$ Thanks for your reply! However, the actual case is a bit more complicated, where both sides is not konwn, and your solution might be not so easy to carry out. $\endgroup$
    – Charles6
    Commented Nov 29, 2017 at 6:53
3
$\begingroup$

Since V 12.3 we have SubtractSides and other related functions.

f = a x == b y;

SubtractSides[f, b y]

a x - b y == 0

$\endgroup$
1
$\begingroup$

A minor rephrasing of the existing answers:

f1 = a x == b y;
f2 = 3 x^2 + 2 y - 4 == 6 xy^2 - 4 x^2 + Cos[Sqrt[y]];

Subtract @@ # == 0 & /@ {f1, f2}

{a x - b y == 0, -4 + 7 x^2 - 6 xy^2 + 2 y - Cos[Sqrt[y]] == 0}

$\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.