Description
A real interval is entered as a pair of real numbers to the interval function. It is stored internally as an arbitrary precision interval using the
MPFI library.
i1 : interval(3.1415,3.1416)
o1 = [3.1415,3.1416]
o1 : RRi (of precision 53)
|
The precision is measured in bits, is visible in the ring displayed on the second of each pair of output lines, and can be recovered using
precision.
i2 : precision interval(3.1415,3.1416)
o2 = 53
|
For real intervals, the functions
class and
ring yield different results. That allows numbers of various precisions to be used without creating a new ring for each precision.
i3 : class interval(3.1,3.5)
o3 = RRi
o3 : InexactFieldFamily
|
i4 : ring interval(3.1,3.5)
o4 = RRi
53
o4 : RealIntervalField
|
The precision can be specified on input by specifying the precision of both input
RR numbers.Alternatively, the precision can be specified by including the option
Precision.
i5 : interval(2.5p100,3.2p1000)
o5 = [2.5,3.2]
o5 : RRi (of precision 100)
|
i6 : interval(2.5,3.2,Precision=>200)
o6 = [2.5,3.20000000000000017763568394002504646778106689453125]
o6 : RRi (of precision 200)
|
Intervals can also be created using
span(Sequence) to create the smallest interval containing the inputs.
i7 : span(2,Precision=>100)
o7 = [2,2]
o7 : RRi (of precision 100)
|
i8 : span(2,3,interval(-1.5,-0.5),73)
o8 = [-1.5,73]
o8 : RRi (of precision 53)
|
Operations using intervals are computed as sets so that the resulting intervals contain all possible outputs from pairs of points in input intervals.
i9 : interval(1,3)+interval(2,4)
o9 = [3,7]
o9 : RRi (of precision 53)
|
i10 : interval(-1,1)*interval(2,3)
o10 = [-3,3]
o10 : RRi (of precision 53)
|
i11 : interval(0,1)-interval(0,1)
o11 = [-1,1]
o11 : RRi (of precision 53)
|
i12 : interval(1,2)/interval(1,2)
o12 = [.5,2]
o12 : RRi (of precision 53)
|
The notion of equality tested by
== amounts to checking the equality of the endpoints of intervals.The notion of equality tested by
=== takes into account the precision of the inputs as well.
i13 : interval(1,3) == interval(1,3,Precision=>100)
o13 = true
|
i14 : interval(1,3) === interval(1,3,Precision=>100)
o14 = false
|
i15 : interval(1/3,1,Precision=>100)==interval(1/3,1,Precision=>1000)
o15 = false
|
The notion of inequalities for intervals amounts to testing the inequality for all points in the intervals. In particular,
<= is not the same as
< or
==.
i16 : interval(1,2)<=interval(2,3)
o16 = true
|
i17 : interval(1,2)<=interval(1,2)
o17 = false
|
i18 : interval(1,2)<interval(2,3)
o18 = false
|
i19 : interval(1,2)<interval(3,4)
o19 = true
|
Transcendental functions on intervals produce intervals containing the image of the function on the interval.
i20 : exp(interval(2,4))
o20 = [7.38905609893065,54.5981500331442]
o20 : RRi (of precision 53)
|
i21 : cos(interval(1,1.3))
o21 = [.267498828624587,.54030230586814]
o21 : RRi (of precision 53)
|
i22 : sqrt(interval(2))
o22 = [1.41421356237309,1.4142135623731]
o22 : RRi (of precision 53)
|
Transcendental functions are available to high precision, with
numericInterval.
i23 : numericInterval(100,pi)
o23 = [3.14159265358979323846264338328,3.14159265358979323846264338328]
o23 : RRi (of precision 100)
|
i24 : numericInterval_200 EulerConstant
o24 = [.577215664901532860606512090082402431042159335939923598805767
,.577215664901532860606512090082402431042159335939923598805768]
o24 : RRi (of precision 200)
|