# How to rearrange both sides of a polynomial equation

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

• closely related/possible duplicate Q/A: Arrange equation in normal form – kglr Nov 29 '17 at 3:09
• # - eqn[[-1]] & /@ eqn – Bob Hanlon Nov 29 '17 at 3:31

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.

• Thanks aardvark2012! your way seems elegant. – HC6 Nov 29 '17 at 7:00
• @HC6 Realised I was needlessly complicating it. Fixed now. – aardvark2012 Nov 29 '17 at 7:11

"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


• Oh, silly me! I do mean "ax-by==0" – HC6 Nov 29 '17 at 6:47

You can use Thread on Equal:

eqn = a x == b y;

Thread[eqn - b y, Equal]


a x - b y == 0

• 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. – HC6 Nov 29 '17 at 6:53