5
$\begingroup$

If I evaluate

Reduce[#, x] & /@ {{4 x > 1, 2 x < 5}, {5 x > 1, x < 5}, {4 x > 1, x < 5}}

the result is

{1/4 < x < 5/2, 1/5 < x < 5, 1/4 < x < 5}

If I select the result and copy-paste it on a new line (that is, I am not typing by hand the inequalities) to compare it with SameQ

(Reduce[#, x] & /@ {{4 x > 1, 2 x < 5}, {5 x > 1, x < 5}, {4 x > 1, 
     x < 5}}) === {1/4 < x < 5/2, 1/5 < x < 5, 1/4 < x < 5}

I get False

Why is that so?

In particular, I found that out when using Length on the expressions

{Length /@ (Reduce[#, x] & /@ {{4 x > 1, 2 x < 5}, {5 x > 1, 
      x < 5}, {4 x > 1, x < 5}}), 
 Length /@ {1/4 < x < 5/2, 1/5 < x < 5, 1/4 < x < 5}}

which, surprisingly to me, leads to different results

{{5, 5, 5}, {3, 3, 3}}
$\endgroup$

1 Answer 1

6
$\begingroup$

Reduce is returning Inequality objects, which let's you mix inequalities like a < x <= b.

Typing a < x < b gives a Less object.

FullForm[Reduce[#, x] & /@ {{4 x > 1, 2 x < 5}, {5 x > 1, x < 5}, {4 x > 1, x < 5}}]
List[Inequality[Rational[1,4],Less,x,Less,Rational[5,2]],Inequality[Rational[1,5],Less,x,Less,5],Inequality[Rational[1,4],Less,x,Less,5]]
FullForm[{1/4 < x < 5/2, 1/5 < x < 5, 1/4 < x < 5}]
List[Less[Rational[1,4],x,Rational[5,2]],Less[Rational[1,5],x,5],Less[Rational[1,4],x,5]]

A simple example to see where Inequality comes in handy:

FullForm[a < x <= b]
Inequality[a, Less, x, LessEqual, b]

But using only < is interpreted as Less. I imagine Reduce always returns Inequality objects for consistency.

FullForm[a < x < b]
Less[a, x, b]
$\endgroup$
5
  • $\begingroup$ But I am not typing it. I literally copy-paste the output. Why is its form not preserved? Is that a common feature of Mathematica? $\endgroup$ Apr 20, 2021 at 14:25
  • $\begingroup$ When you copy it's copying the plain text, not the underlying FullForm. $\endgroup$
    – Greg Hurst
    Apr 20, 2021 at 14:26
  • $\begingroup$ This is not common in Mathematica, it's a corner case I think. $\endgroup$
    – Greg Hurst
    Apr 20, 2021 at 14:27
  • 3
    $\begingroup$ I don't quite grok Chip's last comment, but the lack of a canonical representation of inequalities is one of the mildly irritating design choices of the language (at least for me). $\endgroup$
    – Michael E2
    Apr 20, 2021 at 14:31
  • $\begingroup$ I agree, I'd prefer if Reduce returned Less, etc when possible. Or even have Inequality auto evaluate where possible. $\endgroup$
    – Greg Hurst
    Apr 20, 2021 at 14:32

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.