# Why doesn't Rationalize work for 0. in Interval?

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}

• You might want to adjust the second argument of Rationalize[] if seen fit. Aug 5, 2015 at 20:30
• Map[Rationalize[#, 0] &, Interval[{0., 1.}], {2}] Aug 5, 2015 at 20:32
• @belisarius, try this: Interval[{0., 1.}] // Map[Rationalize[#, 0.0000000000000001] &, #, {2}] & Aug 5, 2015 at 20:33
• @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. Aug 5, 2015 at 20:34
• Interesting also is Interval[{0., 1.}]/2 // Rationalize for demonstrating how bad my floating-point intuition is. Aug 5, 2015 at 20:36

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.

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