Legend:
Library
Module
Module type
Parameter
Class
Class type

Interval operations. Locally open this module — using e.g. `I.(...)` — to redefine classical arithmetic operators for interval arithmetic.

`include T with type number = float and type t = t`
`type number = float`

Numbers type on which intervals are defined.

`type t = t`

The type of intervals.

`val zero : t`

`val one : t`

Neutral element for multiplication.

`val pi : t`

π with bounds properly rounded.

`val two_pi : t`

2π with bounds properly rounded.

`val half_pi : t`

π/2 with bounds properly rounded.

`val e : t`

`e` (Euler's constant) with bounds properly rounded.

`val entire : t`

The entire set of `number`s.

• since 1.5
`val v : number -> number -> t`

`v a b` returns the interval [`a`, `b`]. BEWARE that, unless you take care, if you use `v a b` with literal values for `a` and/or `b`, the resulting interval may not contain these values because the compiler will round them to binary numbers before passing them to `v`.

• raises Invalid_argument

if the interval [`a`, `b`] is equal to [-∞,-∞] or [+∞,+∞] or one of the bounds is NaN.

`val low : t -> number`

`low t` returns the lower bound of the interval.

`val high : t -> number`

`high t` returns the higher bound of the interval.

`val of_int : int -> t`

Returns the interval containing the conversion of an integer to the number type.

`val to_string : ?fmt:(number -> 'b, 'a, 'b) format -> t -> string`

`to_string i` return a string representation of the interval `i`.

• parameter fmt

is the format used to print the two bounds of `i`. Default: `"%g"` for float `number`s.

`val pr : out_channel -> t -> unit`

Print the interval to the channel. To be used with `Printf` format "%a".

`val pp : Format.formatter -> t -> unit`

Print the interval to the formatter. To be used with `Format` format "%a".

`val fmt : (number -> 'b, 'a, 'b) format -> (t -> 'c, 'd, 'e, 'c) format4`

`fmt number_fmt` returns a format to print intervals where each component is printed with `number_fmt`.

Example: `Printf.printf ("%s = " ^^ fmt "%.10f" ^^ "\n") name i`.

### Boolean functions

`val compare_f : t -> number -> int`

`compare_f a x` returns

• `1` if `high(a) < x`,
• `0` if `low(a)``x``high(a)`, i.e., if `x``a`, and
• `-1` if `x < low(a)`.
`val is_bounded : t -> bool`

`is_bounded x` says whether the interval is bounded, i.e., -∞ < `low(x)` and `high(x)` < ∞.

• since 1.5
`val is_entire : t -> bool`

`is_entire x` says whether `x` is the `entire` interval.

• since 1.5
`val equal : t -> t -> bool`

`equal a b` says whether the two intervals are the same.

• since 1.5
`val (=) : t -> t -> bool`

Synonym for `equal`.

• since 1.5
`val subset : t -> t -> bool`

`subset x y` returns true iff `x``y`.

• since 1.5
`val (<=) : t -> t -> bool`

`x <= y` says whether `x` is weakly less than `y` i.e., ∀ξ ∈ `x`, ∃η ∈ `y`, ξ ≤ η and ∀η ∈ `y`, ∃ξ ∈ `x`, ξ ≤ η.

• since 1.5
`val (>=) : t -> t -> bool`

`x >= y` says whether `x` is weakly greater than `y` i.e., ∀ξ ∈ `x`, ∃η ∈ `y`, ξ ≥ η and ∀η ∈ `y`, ∃ξ ∈ `x`, ξ ≥ η.

• since 1.5
`val precedes : t -> t -> bool`

`precedes x y` returns true iff `x` is to the left but may touch `y`.

• since 1.5
`val interior : t -> t -> bool`

`interior x y` returns true if `x` is interior to `y` in the topological sense. For example `interior entire entire` is `true`.

• since 1.5
`val (<) : t -> t -> bool`

`x < y` says whether `x` is strictly weakly less than `y` i.e., ∀ξ ∈ `x`, ∃η ∈ `y`, ξ < η and ∀η ∈ `y`, ∃ξ ∈ `x`, ξ < η.

• since 1.5
`val (>) : t -> t -> bool`

`x > y` iff `y < x`.

• since 1.5
`val strict_precedes : t -> t -> bool`

`strict_precedes x y` returns true iff `x` is to the left and does not touch `y`.

• since 1.5
`val disjoint : t -> t -> bool`

`disjoint x y` returns true iff `x``y` = ∅.

• since 1.5

### Operations

`val width : t -> t`

`size a` returns an interval containing the true width of the interval `high a - low a`.

`val width_high : t -> number`

`size_high a` returns the width of the interval `high a - low a` rounded up.

`val width_low : t -> number`

`size_low a` returns the width of the interval `high a - low a` rounded down.

`val mag : t -> number`

`mag x` returns the magnitude of `x`, that is sup{ |x| : x ∈ `x` }.

`val mig : t -> number`

`mig x` returns the mignitude of `x`, that is inf{ |x| : x ∈ `x` }.

`val sgn : t -> t`

`sgn a` returns the sign of each bound, e.g., for floats [`float (compare (low a) 0.)`, `float (compare (high a) 0.)`].

`val truncate : t -> t`

`truncate a` returns the integer interval containing `a`, that is [`floor(low a)`, `ceil(high a)`].

`val abs : t -> t`

`abs a` returns the absolute value of the interval, that is

• `a` if `low a``0.`,
• `~- a` if `high a``0.`, and
• [0, `max (- low a) (high a)`] otherwise.
`val hull : t -> t -> t`

`hull a b` returns the smallest interval containing `a` and `b`, that is [`min (low a) (low b)`, `max (high a) (high b)`].

`val inter_exn : t -> t -> t`

`inter_exn x y` returns the intersection of `x` and `y`.

• raises Domain_error

if the intersection is empty.

• since 1.5
`val inter : t -> t -> t option`

`inter_exn x y` returns `Some z` where `z` is the intersection of `x` and `y` if it is not empty and `None` if the intersection is empty.

• since 1.5
`val max : t -> t -> t`

`max a b` returns the "maximum" of the intervals `a` and `b`, that is [`max (low a) (low b)`, `max (high a) (high b)`].

`val min : t -> t -> t`

`min a b` returns the "minimum" of the intervals `a` and `b`, that is [`min (low a) (low b)`, `min (high a) (high b)`].

`val (+) : t -> t -> t`

`a + b` returns [`low a +. low b`, `high a +. high b`] properly rounded.

`val (+.) : t -> number -> t`

`a +. x` returns [`low a +. x`, `high a +. x`] properly rounded.

`val (+:) : number -> t -> t`

`x +: a` returns [`a +. low a`, `x +. high a`] properly rounded.

`val (-) : t -> t -> t`

`a - b` returns [`low a -. high b`, `high a -. low b`] properly rounded.

`val (-.) : t -> number -> t`

`a -. x` returns [`low a -. x`, `high a -. x`] properly rounded.

`val (-:) : number -> t -> t`

`x -: a` returns [`x -. high a`, `x -. low a`] properly rounded.

`val (~-) : t -> t`

`~- a` is the unary negation, it returns [`-high a`, `-low a`].

`val (*) : t -> t -> t`

`a * b` multiplies `a` by `b` according to interval arithmetic and returns the proper result. If `a=zero` or `b=zero` then `zero` is returned.

`val (*.) : number -> t -> t`

`x *. a` multiplies `a` by `x` according to interval arithmetic and returns the proper result. If `x=0.` then `zero` is returned.

`val (*:) : t -> number -> t`

`a *. x` multiplies `a` by `x` according to interval arithmetic and returns the proper result. If `x=0.` then `zero` is returned.

`val (/) : t -> t -> t`

`a / b` divides the first interval by the second according to interval arithmetic and returns the proper result. Raise `Interval.Division_by_zero` if `b=``zero`.

`val (/.) : t -> number -> t`

`a /. x` divides `a` by `x` according to interval arithmetic and returns the proper result. Raise `Interval.Division_by_zero` if `x=0.0`.

`val (/:) : number -> t -> t`

`x /: a` divides `x` by `a` according to interval arithmetic and returns the result. Raise `Interval.Division_by_zero` if `a=``zero`.

`val inv : t -> t`

`inv a` returns `1. /: a` but is more efficient. Raise `Interval.Division_by_zero` if `a=``zero`.

`type 'a one_or_two = `
1. `| One of 'a`
2. `| Two of 'a * 'a`
`val invx : t -> t one_or_two`

`invx a` is the extended division. When 0 ∉ `a`, the result is `One(inv a)`. If 0 ∈ `a`, then the two natural intervals (properly rounded) `Two`([-∞, 1/(low a)], [1/(high a), +∞]) are returned. Raise `Interval.Division_by_zero` if `a=``zero`.

`val cancelminus : t -> t -> t`

`cancelminus x y` returns the tightest interval `z` such that `x``z` + `y`. If no such `z` exists, it returns `entire`.

• since 1.5
`val cancelplus : t -> t -> t`

`cancelplus x y` returns the tightest interval `z` such that `x``z` - `y`. If no such `z` exists, it returns `entire`.

• since 1.5
`val (**) : t -> int -> t`

`a**n` returns interval `a` raised to `n`th power according to interval arithmetic. If `n=0` then `one` is returned.

`val size : t -> t`
• deprecated Use I.width
`val size_high : t -> number`
• deprecated Use I.width_high
`val size_low : t -> number`
• deprecated Use I.width_low

### Usual arithmetic operators

`module U : sig ... end`

Module undoing the redeclaration of usual infix operators `+`, `+.`, etc. in case it is needed locally, while this module is open.