For something I am doing in Mathematica, it would be very helpful to have a function f[] which, when applied to an atomic Boolean expression, returns True if the Boolean expression is an inequality, and returns false if the Boolean expression is not an inequality.
For example:
f[0 == 1] ought to be False, since 0 == 1 is not an inequality.
f[0 != 1] ought to be True, since 0 != 1 is an inequality.
What is the best to define such a function f[] in Mathematica? I had hoped it would already exist, with a name like InequalityQ[], but I have not been able to find such a function already defined in Mathematica.
Thanks for your help.
!=
in it? The problem is that Mathematica immediately evaluates1 != 0
toTrue
. So your expression will not actually have!=
left in it (this assumes ofcourse that the values are all numerical). For symbols, you can check if the Head isUnequal
, i.e.Head[x != y] == Unequal
givesTrue
$\endgroup$ClearAll[f]; SetAttributes[f, HoldFirst]; f[exp_] := MemberQ[Head[Unevaluated[exp]]]@{Unequal, Less, Greater}
? $\endgroup$