An expression like this one
a < x < b
is normally represented as
Less[a, x, b]
while an expression like
a < x <= b
is represented as
Inequality[a, Less, x, LessEqual, b]
(1) What is the reason of the following strange behavior of pattern matching and Inequality
expressions?
MatchQ[Inequality[1, Less, x, LessEqual, 2], _Inequality]
MatchQ[Inequality[1, Less, x, LessEqual, 2], Inequality[___]]
MatchQ[Inequality[1, Less, x, LessEqual, 2],
Inequality[1, Less, x, LessEqual, 2]]
MatchQ[Inequality[1, Less, x, LessEqual, 2],
Inequality[_, Less, _, LessEqual, _]]
MatchQ[Inequality[1, Less, x, LessEqual, 2],
Inequality[1, _, x, LessEqual, 2]]
True False True True False
(2) How to do pattern matching properly with Inequality
?
(3) Elegant way to convert all the Inequality
in an expression to their normal form when possible (because of this problem)?
Inequality[___]
evaluates toTrue
immediately. TryHoldPattern[Inequality[___]]
instead: that one then works. I think the issue is always pre-evaluation of the pattern. Look at whatInequality[1, _, x, LessEqual, 2]
evaluates to. $\endgroup$