API

IntervalArithmetic.BareIntervalType
BareInterval{T<:NumTypes}

Interval type for guaranteed computation with interval arithmetic according to the IEEE Standard 1788-2015. Unlike Interval, this bare interval does not have decorations, is not a subtype of Real and errors on operations mixing BareInterval and Number.

Fields:

  • lo :: T
  • hi :: T

Constructor compliant with the IEEE Standard 1788-2015: bareinterval.

See also: Interval.

source
IntervalArithmetic.ExactRealType
ExactReal{T<:Real} <: Real

Real numbers with the assurance that they precisely correspond to the number described by their binary form. The purpose is to guarantee that a non interval number is exact, so that ExactReal can be used with Interval without producing the "NG" flag.

Danger

By using ExactReal, users acknowledge the responsibility of ensuring that the number they input corresponds to their intended value. For example, ExactReal(0.1) implies that the user knows that $0.1$ can not be represented exactly as a binary number, and that they are using a slightly different number than $0.1$. To help identify the binary number, ExactReal is displayed without any rounding.

julia> ExactReal(0.1)
ExactReal{Float64}(0.1000000000000000055511151231257827021181583404541015625)

In case of doubt, has_exact_display can be use to check if the string representation of a Real is equal to its binary value.

Examples

julia> setdisplay(:full);

julia> 0.5 * interval(1)
Interval{Float64}(0.5, 0.5, com, NG)

julia> ExactReal(0.5) * interval(1)
Interval{Float64}(0.5, 0.5, com)

julia> [1, interval(2)]
2-element Vector{Interval{Float64}}:
 Interval{Float64}(1.0, 1.0, com, NG)
 Interval{Float64}(2.0, 2.0, com)

julia> [ExactReal(1), interval(2)]
2-element Vector{Interval{Float64}}:
 Interval{Float64}(1.0, 1.0, com)
 Interval{Float64}(2.0, 2.0, com)

See also: @exact.

source
IntervalArithmetic.IntervalType
Interval{T<:NumTypes} <: Real

Interval type for guaranteed computation with interval arithmetic according to the IEEE Standard 1788-2015. This structure combines a BareInterval together with a Decoration.

Fields:

  • bareinterval :: BareInterval{T}
  • decoration :: Decoration
  • isguaranteed :: Bool

Constructors compliant with the IEEE Standard 1788-2015:

See also: ±, .. and @I_str.

source
IntervalArithmetic.bareintervalMethod
bareinterval(T, a, b)

Create the bare interval $[a, b]$ according to the IEEE Standard 1788-2015. The validity of the interval is checked by is_valid_interval: if true then a BareInterval{T} is constructed, otherwise an empty interval is returned.

Danger

Nothing is done to compensate for the fact that floating point literals are rounded to the nearest when parsed (e.g. 0.1). In such cases, parse the string containing the desired value to ensure its tight enclosure.

See also: interval, ±, .. and @I_str.

Examples

julia> setdisplay(:full);

julia> bareinterval(1//1, π)
BareInterval{Rational{Int64}}(1//1, 85563208//27235615)

julia> bareinterval(Rational{Int32}, 1//1, π)
BareInterval{Rational{Int32}}(1//1, 85563208//27235615)

julia> bareinterval(1, π)
BareInterval{Float64}(1.0, 3.1415926535897936)

julia> bareinterval(BigFloat, 1, π)
BareInterval{BigFloat}(1.0, 3.141592653589793238462643383279502884197169399375105820974944592307816406286233)
source
IntervalArithmetic.bisectMethod
bisect(x, α=0.5)
bisect(x, i, α=0.5)

Split an interval x at a relative position α, where α = 0.5 corresponds to the midpoint.

Split the i-th component of a vector x at a relative position α, where α = 0.5 corresponds to the midpoint.

source
IntervalArithmetic.cancelminusMethod
cancelminus(x, y)

Compute the unique interval z such that y + z == x.

The result is decorated by at most trv (Section 11.7.1).

Implement the cancelMinus function of the IEEE Standard 1788-2015 (Section 9.2).

source
IntervalArithmetic.cancelplusMethod
cancelplus(x, y)

Compute the unique interval z such that y - z == x; this is semantically equivalent to cancelminus(x, -y).

The result is decorated by at most trv (Section 11.7.1).

Implement the cancelPlus function of the IEEE Standard 1788-2015 (Section 9.2).

source
IntervalArithmetic.emptyintervalMethod
emptyinterval(T=default_numtype())

Create an empty interval. This interval is an exception to the fact that the lower bound is larger than the upper one.

Implement the empty function of the IEEE Standard 1788-2015 (Section 10.5.2).

source
IntervalArithmetic.entireintervalMethod
entireinterval(T=default_numtype())

Create an interval representing the entire real line, or the entire complex plane if T is complex.

Note

Depending on the flavor, infinity may or may not be considered part of the interval.

Implement the entire function of the IEEE Standard 1788-2015 (Section 10.5.2).

source
IntervalArithmetic.has_exact_displayMethod
has_exact_display(x::Real)

Determine if the display of x up to 2000 decimals is equal to the bitwise value of x. This is famously not true for the float displayed as 0.1.

source
IntervalArithmetic.hullMethod
hull(x, y)

Return the interval hull of the intervals x and y, considered as (extended) sets of real numbers, i.e. the smallest interval that contains all of x and y.

The result is decorated by at most trv (Section 11.7.1).

Implement the convexHull function of the IEEE Standard 1788-2015 (Section 9.3).

source
IntervalArithmetic.intersect_intervalMethod
intersect_interval(x, y)

Returns the intersection of the intervals x and y, considered as (extended) sets of real numbers. That is, the set that contains the points common in x and y.

The result is decorated by at most trv (Section 11.7.1).

Implement the intersection function of the IEEE Standard 1788-2015 (Section 9.3).

source
IntervalArithmetic.intervalMethod
interval(T, a, b, d = com)

Create the interval $[a, b]$ according to the IEEE Standard 1788-2015. The validity of the interval is checked by is_valid_interval: if true then an Interval{T} is constructed, otherwise an NaI (Not an Interval) is returned.

Danger

Nothing is done to compensate for the fact that floating point literals are rounded to the nearest when parsed (e.g. 0.1). In such cases, parse the string containing the desired value to ensure its tight enclosure.

See also: ±, .. and @I_str.

Examples

julia> setdisplay(:full);

julia> interval(1//1, π)
Interval{Rational{Int64}}(1//1, 85563208//27235615, com)

julia> interval(Rational{Int32}, 1//1, π)
Interval{Rational{Int32}}(1//1, 85563208//27235615, com)

julia> interval(1, π)
Interval{Float64}(1.0, 3.1415926535897936, com)

julia> interval(BigFloat, 1, π)
Interval{BigFloat}(1.0, 3.141592653589793238462643383279502884197169399375105820974944592307816406286233, com)
source
IntervalArithmetic.isatomicMethod
isatomic(x)

Test whether x is unable to be split. This occurs if the interval is empty, or if its lower and upper bounds are equal, or if the bounds are consecutive floating-point numbers.

source
IntervalArithmetic.iscommonMethod
iscommon(x)

Test whether x is not empty and bounded.

Note

This is does not take into consideration the decoration of the interval.

source
IntervalArithmetic.isguaranteedMethod
isguaranteed(x::BareInterval)
isguaranteed(x::Interval)
isguaranteed(x::Complex{<:Interval})

Test whether the interval is not guaranteed to encompass all possible numerical errors. This happens whenever an Interval is constructed using convert(::Type{<:Interval}, ::Real), which may occur implicitly when mixing intervals and Real types.

Since conversion between BareInterval and Number is prohibited, this implies that isguaranteed(::BareInterval) == true.

In the case of a complex interval x, this is semantically equivalent to isguaranteed(real(x)) & isguaranteed(imag(x)).

Examples

julia> isguaranteed(bareinterval(1))
true

julia> isguaranteed(interval(1))
true

julia> isguaranteed(convert(Interval{Float64}, 1))
false

julia> isguaranteed(interval(1) + 0)
false
source
IntervalArithmetic.isinteriorMethod
isinterior(x, y)

Test whether x is in the interior of y. If x and y are intervals, this is semantically equivalent to isstrictsubset(x, y).

Implement the interior function of the IEEE Standard 1788-2015 (Table 9.3).

See also: isstrictsubset.

source
IntervalArithmetic.isstrictlessMethod
isstrictless(x, y)

Test whether inf(x) < inf(y) and sup(x) < sup(y), where < is replaced by for infinite values.

Implement the strictLess function of the IEEE Standard 1788-2015 (Table 10.3).

source
IntervalArithmetic.isstrictsubsetMethod
isstrictsubset(x, y)

Test whether x is a strict subset of y. If x and y are intervals, this is semantically equivalent to isinterior(x, y). If x and y are vectors, x must be a subset of y with at least one of their component being a strict subset.

See also: isinterior.

source
IntervalArithmetic.isthinMethod
isthin(x)

Test whether x contains only a real.

Implement the isSingleton function of the IEEE Standard 1788-2015 (Table 9.3).

source
IntervalArithmetic.isweaklessMethod
isweakless(x, y)

Test whether inf(x) ≤ inf(y) and sup(x) ≤ sup(y), where < is replaced by for infinite values.

Implement the less function of the IEEE Standard 1788-2015 (Table 10.3).

source
IntervalArithmetic.midMethod
mid(x, α = 0.5)

Relative midpoint of x, for α between 0 and 1 such that mid(x, 0) is the lower bound of the interval, mid(x, 1) its upper bound, and mid(x, 0.5) its midpoint.

Implement the mid function of the IEEE Standard 1788-2015 (Table 9.2).

See also: inf, sup, bounds, diam, radius and midradius.

source
IntervalArithmetic.minceMethod
mince(x, n)

Split an interval x in n intervals of the same diameter.

Split the i-th component of a vector x in n[i] intervals of the same diameter; n can be a tuple of integers, or a single integer in which case the same n is used for all the components of x.

source
IntervalArithmetic.overlapMethod
overlap(x::BareInterval, y::BareInterval)
overlap(x::Interval, y::Interval)

Implement the overlap function of the IEEE Standard 1788-2015 (Table 10.7).

source
IntervalArithmetic.powMethod
pow(x, y)

Compute the power of the positive real part of x by y. In particular, even if y is a thin integer, this is not equivalent to pown(x, sup(y)).

Implement the pow function of the IEEE Standard 1788-2015 (Table 9.1).

See also: pown.

Examples

julia> setdisplay(:full);

julia> pow(bareinterval(2, 3), bareinterval(2))
BareInterval{Float64}(4.0, 9.0)

julia> pow(interval(-1, 1), interval(3))
Interval{Float64}(0.0, 1.0, trv)

julia> pow(interval(-1, 1), interval(-3))
Interval{Float64}(1.0, Inf, trv)
source
IntervalArithmetic.pownMethod
pown(x, n)

Implement the pown function of the IEEE Standard 1788-2015 (Table 9.1).

Examples

julia> setdisplay(:full);

julia> pown(bareinterval(2, 3), 2)
BareInterval{Float64}(4.0, 9.0)

julia> pown(interval(-1, 1), 3)
Interval{Float64}(-1.0, 1.0, com)

julia> pown(interval(-1, 1), -3)
Interval{Float64}(-Inf, Inf, trv)
source
IntervalArithmetic.precedesMethod
precedes(x, y)

Test whether any element of x is lesser or equal to every elements of y.

Implement the precedes function of the IEEE Standard 1788-2015 (Table 10.3).

source
IntervalArithmetic.radiusMethod
radius(x)

Radius of x, such that issubset_interval(x, mid(x) ± radius(x)). If x is complex, then the radius is the maximum radius between its real and imaginary parts.

Implement the rad function of the IEEE Standard 1788-2015 (Table 9.2).

See also: inf, sup, bounds, mid, diam and midradius.

source
IntervalArithmetic.rootnMethod
rootn(x::BareInterval, n::Integer)

Compute the real n-th root of x.

Implement the rootn function of the IEEE Standard 1788-2015 (Table 9.1).

source
IntervalArithmetic.setdisplayFunction
setdisplay(format::Symbol; decorations::Bool, sigdigits::Int)

Change the format used by show to display intervals.

Possible options:

  • format can be:
    • :infsup: display intervals as [a, b].
    • :midpoint: display intervals as m ± r.
    • :full: display interval bounds entirely, ignoring sigdigits.
  • decorations: display the decorations or not.
  • sigdigits: number (greater or equal to 1) of significant digits to display.

Initially, the display options are set to setdisplay(:infsup; decorations = false, sigdigits = 6). If any of the three argument format, decorations and sigdigits is omitted, then their value is left unchanged.

Examples

julia> setdisplay(:infsup; decorations = true, sigdigits = 6) # default display options
Display options:
  - format: infsup
  - decorations: true
  - significant digits: 6

julia> x = interval(0.1, 0.3)
[0.0999999, 0.300001]_com

julia> setdisplay(:full)
Display options:
  - format: full
  - decorations: true
  - significant digits: 6 (ignored)

julia> x
Interval{Float64}(0.1, 0.3, com)

julia> setdisplay(:infsup; sigdigits = 3)
Display options:
  - format: infsup
  - decorations: true
  - significant digits: 3

julia> x
[0.0999, 0.301]_com

julia> setdisplay(; decorations = false)
Display options:
  - format: infsup
  - decorations: false
  - significant digits: 3

julia> x
[0.0999, 0.301]
source
IntervalArithmetic.strictprecedesMethod
strictprecedes(x, y)

Test whether any element of x is strictly lesser than every elements of y.

Implement the strictPrecedes function of the IEEE Standard 1788-2015 (Table 10.3).

source
IntervalArithmetic.@I_strMacro
I"str"

Create an interval by parsing the string "str"; this is semantically equivalent to parse(Interval{default_numtype()}, "str").

Examples

julia> setdisplay(:full);

julia> I"[3, 4]"
Interval{Float64}(3.0, 4.0, com)

julia> I"0.1"
Interval{Float64}(0.09999999999999999, 0.1, com)

julia> in_interval(1//10, I"0.1")
true
source
IntervalArithmetic.@exactMacro
@exact

Wrap every literal numbers of the expression in an ExactReal. This macro allows defining generic functions, seamlessly accepting both Number and Interval arguments, without producing the "NG" flag.

Danger

By using ExactReal, users acknowledge the responsibility of ensuring that the number they input corresponds to their intended value. For example, ExactReal(0.1) implies that the user knows that $0.1$ can not be represented exactly as a binary number, and that they are using a slightly different number than $0.1$. To help identify the binary number, ExactReal is displayed without any rounding.

julia> ExactReal(0.1)
ExactReal{Float64}(0.1000000000000000055511151231257827021181583404541015625)

In case of doubt, has_exact_display can be use to check if the string representation of a Real is equal to its binary value.

Examples

julia> setdisplay(:full);

julia> f(x) = 1.2*x + 0.1
f (generic function with 1 method)

julia> f(interval(1, 2))
Interval{Float64}(1.2999999999999998, 2.5, com, NG)

julia> @exact g(x) = 1.2*x + 0.1
g (generic function with 1 method)

julia> g(interval(1, 2))
Interval{Float64}(1.2999999999999998, 2.5, com)

julia> g(1.4)
1.78

See also: ExactReal.

source
IntervalArithmetic.@intervalMacro
@interval(expr)
@interval(T, expr)
@interval(T, expr1, expr2)

Walk through an expression and wrap each argument of functions with the internal constructor atomic.

Examples

julia> setdisplay(:full);

julia> @macroexpand @interval sin(1) # Float64 is the default bound type
:(sin(IntervalArithmetic.atomic(Float64, 1)))

julia> @macroexpand @interval Float32 sin(1)
:(sin(IntervalArithmetic.atomic(Float32, 1)))

julia> @interval Float64 sin(1) exp(1)
Interval{Float64}(0.8414709848078965, 2.7182818284590455, com)
source