6
$\begingroup$

Same motivation as this q. Why doesn't Rationalize work for 0.?

Interval[{0., 1.}] // Map[Rationalize, #, {2}] &

Interval[{-4.45015*10^-308,1}]

There's nothing wrong with 0. by itself:

{0., 1.} // Map[Rationalize]

{0, 1}

$\endgroup$
7
  • $\begingroup$ You might want to adjust the second argument of Rationalize[] if seen fit. $\endgroup$ Aug 5, 2015 at 20:30
  • $\begingroup$ Map[Rationalize[#, 0] &, Interval[{0., 1.}], {2}] $\endgroup$ Aug 5, 2015 at 20:32
  • $\begingroup$ @belisarius, try this: Interval[{0., 1.}] // Map[Rationalize[#, 0.0000000000000001] &, #, {2}] & $\endgroup$ Aug 5, 2015 at 20:33
  • $\begingroup$ @Guesswhoitis., most positive values of 2nd parameters seem to work, though note above counterexample. But I want to know why this issue is Interval specific. $\endgroup$ Aug 5, 2015 at 20:34
  • $\begingroup$ Interesting also is Interval[{0., 1.}]/2 // Rationalize for demonstrating how bad my floating-point intuition is. $\endgroup$ Aug 5, 2015 at 20:36

1 Answer 1

5
$\begingroup$

I believe this has to do with the fact that intervals "grow" just a bit on evaluation with machine numbers to ensure that values at the endpoint will be included in the interval.

NestList[Interval @@ # &, Interval[{0., 1.}], 5] // InputForm

(*
{Interval[{-2.2250738585072014*^-308, 1.0000000000000002}], 
 Interval[{-4.450147717014403*^-308, 1.0000000000000004}], 
 Interval[{-6.675221575521604*^-308, 1.0000000000000007}], 
 Interval[{-8.900295434028806*^-308, 1.0000000000000009}], 
 Interval[{-1.1125369292536007*^-307, 1.000000000000001}], 
 Interval[{-1.3350443151043208*^-307, 1.0000000000000013}]}
*)

I'm only guessing at why it is designed this way. The docs give a pretty vague description.

"For approximate machine- or arbitrary-precision numbers x, Interval[x] yields an interval reflecting the uncertainty in x."

Edit:

Just to make it a little more interesting, this is what it appears to be doing to the endpoints.

NestList[# + {$MinMachineNumber, $MachineEpsilon} &, {0., 1.}, 5] // InputForm

(*
{{0., 1.}, 
 {2.2250738585072014*^-308, 1.0000000000000002}, 
 {4.450147717014403*^-308, 1.0000000000000004}, 
 {6.675221575521604*^-308, 1.0000000000000007}, 
 {8.900295434028806*^-308, 1.0000000000000009}, 
 {1.1125369292536007*^-307, 1.000000000000001}}
*)

I suspect that in general the step is $MachineEpsilon but zero is a special case as it often is in Mathematica.

$\endgroup$
2
  • 2
    $\begingroup$ What's the transitive closure? This is a disaster waiting to happen in temporal queries or real time systems. $\endgroup$ Aug 5, 2015 at 21:20
  • $\begingroup$ Yes, I have been bitten by this a time or two. $\endgroup$
    – Andy Ross
    Aug 5, 2015 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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