2
$\begingroup$

Consider

Clear[x];
x = 2;
x < 2.9 || x > 3.1

This yields

True

So, everything is o. k. (interesting) But when you replace || by or, the result becomes really interesting:

Clear[x];
x = 2;
x < 2.9 or x > 3.1

yields

2 < 5.8 or && 5.8 or > 3.1

What the heck is going on? I presume that the following is happening:

  1. or is different from OR (that is, from ||), since Mathematica is case-sensitive.
  2. Thus, or is an other operator, perhaps a bitwise or or something like this???

I am interested in how exactly the strange value is generated. That is, if or is a bitwise operation, how do the left and right sides look "in bits" and how does or work on these bits? Any help is greatly appreciated.

$\endgroup$
2
  • 1
    $\begingroup$ The command is Or; your or is an undefined variable, as so humorously pointed out below. $\endgroup$
    – Nicholas G
    Aug 11 at 13:00
  • 1
    $\begingroup$ Either Or[x < 2.9, x > 3.1] or (x < 2.9) ~Or~ (x > 3.1) $\endgroup$
    – Bob Hanlon
    Aug 11 at 14:09

1 Answer 1

6
$\begingroup$

Since or is an as yet undefined symbol, the input

2.9 or x

is interpreted as the product of these three things, and evaluates to

5.8*or

in your case since you set x=2 before.

Accordingly, if you input

x < 2.9 or x > 3.1

this evaluates to

2 < 5.8*or > 3.1

But a chain of inequalities such as a < b > c is always rewritten as And[a<b,b>c], therefore you get

And[2 < 5.8*or, 5.8*or > 3.1]

respectively the equivalent short form using &&.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.