Display modes

There are several useful output representations for intervals. The display is controlled globally by the setdisplay function, which has the following options:

  • interval output format:

    • :infsup: output of the form [1.09999, 1.30001], rounded to the current number of significant figures.

    • :full: output of the form Interval(1.0999999999999999, 1.3), as in the showfull function.

    • :midpoint: output in the midpoint-radius form, e.g. 1.2 ± 0.100001.

  • sigfigs :: Int keyword argument: number of significant figures to show in standard mode.

  • decorations :: Bool keyword argument: whether to show decorations or not.

julia> using IntervalArithmetic
julia> a = interval(1.1, pi) # default displayInterval{Float64}(1.1, 3.1415926535897936, com)
julia> setdisplay(; sigdigits = 10)Display options: - format: full - decorations: false - significant digits: 10 (ignored)
julia> aInterval{Float64}(1.1, 3.1415926535897936, com)
julia> setdisplay(:full)Display options: - format: full - decorations: false - significant digits: 10 (ignored)
julia> aInterval{Float64}(1.1, 3.1415926535897936, com)
julia> setdisplay(:midpoint)Display options: - format: midpoint - decorations: false - significant digits: 10
julia> a2.120796327 ± 1.020796327
julia> setdisplay(; sigdigits = 4)Display options: - format: midpoint - decorations: false - significant digits: 4
julia> a2.121 ± 1.021
julia> setdisplay(:infsup)Display options: - format: infsup - decorations: false - significant digits: 4
julia> a[1.099, 3.142]

Arithmetic operations

Basic arithmetic operations (+, -, *, /, ^) are defined for pairs of intervals in a standard way: the result is the smallest interval containing the result of operating with each element of each interval. More precisely, for two intervals $X$ and $Y$ and an operation $\bigcirc$, we define the operation on the two intervals by

\[X \bigcirc Y \bydef \{ x \bigcirc y \,:\, x \in X \text{ and } y \in Y \}.\]

For example,

julia> using IntervalArithmetic
julia> setdisplay(:full)Display options: - format: full - decorations: false - significant digits: 4 (ignored)
julia> X = interval(0, 1)Interval{Float64}(0.0, 1.0, com)
julia> Y = interval(1, 2)Interval{Float64}(1.0, 2.0, com)
julia> X + YInterval{Float64}(1.0, 3.0, com)

Due to the above definition, subtraction of two intervals may give poor enclosures:

julia> X - XInterval{Float64}(-1.0, 1.0, com)

Elementary functions

The main elementary functions are implemented. The functions for Interval{Float64} internally use routines from the correctly-rounded CRlibm library where possible, i.e. for the following functions defined in that library:

  • exp, expm1
  • log, log1p, log2, log10
  • sin, cos, tan
  • asin, acos, atan
  • sinh, cosh

Other functions that are implemented for Interval{Float64} internally convert to an Interval{BigFloat}, and then use routines from the MPFR library (BigFloat in Julia):

  • ^
  • exp2, exp10
  • atan, atanh

In particular, in order to obtain correct rounding for the power function (^), intervals are converted to and from BigFloat; this implies a significant slow-down in this case.

For example,

julia> X = interval(1)Interval{Float64}(1.0, 1.0, com)
julia> sin(X)Interval{Float64}(0.8414709848078965, 0.8414709848078966, com)
julia> cos(cosh(X))Interval{Float64}(0.027712143770207736, 0.02771214377020796, com)
julia> setprecision(BigFloat, 53)53
julia> Y = big(X)Interval{BigFloat}(1.0, 1.0, com)
julia> sin(Y)Interval{BigFloat}(0.8414709848078965, 0.84147098480789662, com)
julia> cos(cosh(Y))Interval{BigFloat}(0.027712143770207736, 0.027712143770207961, com)
julia> setprecision(BigFloat, 128)128
julia> sin(Y)Interval{BigFloat}(0.8414709848078965, 0.84147098480789662, com)

Comparisons and set operations

All comparisons and set operations for Real have been purposely disallowed to prevent silent errors.

julia> interval(1) < interval(2)ERROR: ArgumentError: `<` is purposely not supported for intervals. See instead `isstrictless`, `strictprecedes`
julia> precedes(interval(1), interval(2))true
julia> issubset(interval(1, 2), interval(2))ERROR: ArgumentError: `issubset` is purposely not supported for intervals. See instead `issubset_interval`
julia> issubset_interval(interval(1, 2), interval(2))false
julia> intersect(interval(1, 2), interval(2))ERROR: ArgumentError: `union!` is purposely not supported for intervals. See instead `hull`
julia> intersect_interval(interval(1, 2), interval(2))Interval{Float64}(2.0, 2.0, trv)

Custom interval bounds type

A BareInterval{T} or Interval{T} have the restriction T <: Union{Rational,AbstractFloat} which is the parametric type for the bounds of the interval. Supposing one wishes to use their own numeric type MyNumType <: Union{Rational,AbstractFloat}, they must provide their own arithmetic operations (with correct rounding!).