Is it possible to have Mathematica move all terms to one side of an inequality?
Are you looking for Subtract?
eq=x>=y
Subtract@@eq>=0
gives:
x-y>=0
Edit
If one wants a function, which keeps the order sign and adds the 0, one may use:
oneSide=(Head[#][Subtract@@#,0]&)
and call e.g. eq//oneSide
This approach works by using the fact that an inequality or equality can be traversed by Map
in the same way that a regular list can. It can take an arbitrary inequality or equation eqn
, and you don't have to know in advance whether it's >
, <
or anything else. First I define the equation eqn
, and then I use the fact that the second part of eqn
is the right-hand side (eqn[[2]]
) which I want to subtract from both sides:
eqn = (x > y + z)
Map[(# - eqn[[2]]) &, eqn]
-y - z > 0
You could adapt it to bring only part of the right-hand side to the left, e.g. the y
but not z
:
Map[(# - eqn[[2, 1]]) &, eqn]
x - y > z
Edit
By the way, using Map
on an equation is a "natural" choice in this situation, because manipulating equations always involves doing the same thing on both sides. That "thing" can be formulated as applying a function f[...]
to both sides. In this example it's a subtraction operation, but it could also be the operation of squaring both sides, multiplying them by a factor, expanding in a power series, and whatever else you might think of. In Mathematica, Map
is the operation that corresponds to this type of manipulation.
With inequalities, you just have to be more careful than with equalities because doing the same thing on both sides doesn't always leave the relation unchanged (think of multiplying by a negative number). In this question, that problem didn't arise because addition and subtraction don't cause inequalities to break.
Edit 2
One should also realize that inequalities and equations (i.e., Equal
and Greater
etc.) can have two or more arguments, as in
eqn = (x > y > z)
The answers by Peter and Pillsy do not take this into account, whereas the Map
approach works naturally in these cases, too:
Map[(# - Last[eqn]) &, eqn]
x - z > y - z > 0
There has in fact been some discussion long ago if one should make the Equal
function in Mathematica "listable" so that it applies this Map
process automatically when you type eqn - Last[eqn]
, but there are cases when that's not desirable (e.g., when taking the square root on both sides due to multi-valuedness), so we have to do it ourselves when needed.
In the spirit of hiding the Map
code from the user, one can of course define a function like Peter does, i.e., in my case
Clear[oneSide]; oneSide[e_] := Map[(# - Last[e]) &, e]
Since Mathematica 11.3 you can use SubtractSides
, that works for equations and inequalities, for example
eqns = {
x >= y,
x^2 == b c + c,
2 x < x + 1
};
SubtractSides /@ eqns
(* {x - y >= 0, -c - b c + x^2 == 0, -1 + x < 0} *)