Great questions! If you don’t mind, I may use them as FAQs for future versions of the package.
Will Interval(pi) and Interval(e) give me intervals that are guaranteed to contain the number pi and the number e? Or do I have to type in something explicit such as 3.141592…3.141593 to get an interval containing pi?
Since pi
and e
are floating-point numbers, just using Interval
again gives you thin intervals:
julia 0.6> Interval(pi)
Interval(3.141592653589793, 3.141592653589793)
You can do
julia 0.6> pi..pi
Interval(3.1415926535897927, 3.1415926535897936)
or
julia 0.6> @interval(pi)
Interval(3.141592653589793, 3.1415926535897936)
If I multiply an interval by a float or add a float to an interval, for example 2.1*x or x + 2.1, where x is an interval, do I get intervals that are guaranteed to contain the correct results? I know that this is not true for more complicated expressions, and in those cases I can use the macro @intervals( ).
Yes, you do get correct results: the 2.1
is automatically converted. This is also true for more complicated expressions, provided there is an interval that forces the conversion.
For example,
julia 0.6> (2.1..2.1)*3.1 + (4.1..4.1)*5.1
Interval(27.419999999999984, 27.420000000000012)
julia 0.6> @interval(2.1*3.1 + 4.1*5.1)
Interval(27.419999999999984, 27.420000000000012)
julia 0.6> 2.1*3.1 + (4.1..4.1)*5.1
Interval(27.419999999999984, 27.42000000000001)
The first two are correct. In the last one, the multiplication 2.1*3.1
is done without any guarantees, since that is evaluated using standard floating-point arithmetic before the intervals come into the story.