Interval Arithmetic

Representations of real intervals.

This represents all numbers between -2 and +5:

Interval[{-2,5}]

The square of any number between -2 and +5 is always between 0 and 25:

Interval[{-2,5}]^2

Taking the reciprocal gives two distinct intervals:

1/Interval[{-2,5}]

(RefLink[Abs, paclet:ref/Abs]) folds the intervals back together again:

Abs[%]

You can use intervals in many kinds of functions:

Solve[3 x+2==Interval[{-2,5}],x]

Some functions automatically generate intervals:

Limit[Sin[1/x],x->0]

Operations on intervals.

This finds the overlap of the two intervals:

IntervalIntersection[Interval[{3,7}],Interval[{-2,5}]]

You can use (RefLink[Max, paclet:ref/Max]) and (RefLink[Min, paclet:ref/Min]) to find the end points of intervals:

Max[%]

This finds out which of a list of intervals contains the point 7:

IntervalMemberQ[Table[Interval[{i,i+1}],{i,1,20,3}],7]

You can use intervals not only with exact quantities but also with approximate numbers. Even with machine-precision numbers, the Wolfram Language always tries to do rounding in such a way as to preserve the validity of results.

This shows explicitly the interval treated by the Wolfram Language as the machine-precision number 0.

Interval[0.]

This shows the corresponding interval around 100., shifted back to zero:

Interval[100.]-100

The same kind of thing works with numbers of any precision:

Interval[N[Pi,60]]-Pi

With ordinary machine-precision arithmetic, this computation gives an incorrect result:

Sin[N[Pi]]

The interval generated here, however, includes the correct value of 0:

Sin[Interval[N[Pi]]]