package interval

  1. Overview
  2. Docs

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

val zero : t

Neutral element for addition.

val one : t

Neutral element for multiplication.

val pi : t

π with bounds properly rounded.

val two_pi : t

2π with bounds properly rounded.

val e : t

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

val v : float -> float -> t

v a b returns {low=a; high=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 of_int : int -> t

Returns the interval containing the float conversion of an integer.

val to_string : ?fmt:(float -> '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".

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 : (float -> 'b, 'a, 'b) format -> (t -> 'c, 'd, 'e, 'c) format4

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

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

val compare_f : t -> float -> int

compare_f a x returns

  • 1 if a.high < x,
  • 0 if a.lowxa.high, i.e., if xa, and
  • -1 if x < a.low.
val size : t -> t

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

val size_high : t -> float

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

val size_low : t -> float

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

val sgn : t -> t

sgn a returns the sign of each bound, i.e., {low=float (compare a.low 0.); high=float (compare a.high 0.)}.

val truncate : t -> t

truncate a returns the integer interval containing a, that is {low=floor a.low; high=ceil a.high}.

val abs : t -> t

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

  • a if a.low0.,
  • ~- a if a.high0., and
  • {low=0.; high=max (-a.low) a.high} otherwise.
val hull : t -> t -> t

hull a b returns the smallest interval containing a and b, that is {low=min a.low b.low; high=max a.high b.high}.

val max : t -> t -> t

max a b returns the "maximum" of the intervals a and b, that is {low=max a.low b.low; high=max a.high b.high}.

val min : t -> t -> t

min a b returns the "minimum" of the intervals a and b, that is {low=min a.low b.low;high=min a.high b.high}.

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

a + b returns {low=a.low +. b.low; high=a.high +. b.high} properly rounded.

val (+.) : t -> float -> t

a +. x returns {low = a.low +. x; high = a.high +. x} properly rounded.

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

x +: a returns {low = a.low +. x; high = a.high +. x} properly rounded.

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

a - b returns {low = a.low -. b.high; high = a.high -. b.low} properly rounded.

val (-.) : t -> float -> t

a -. x returns {low = a.low -. x; high = a.high -. x} properly rounded.

val (-:) : float -> t -> t

x -: a returns {low = x -. a.high; high = x -. a.low} properly rounded.

val (~-) : t -> t

~- a is the unary negation, it returns {low=-a.high; high=-a.low}.

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 (*.) : float -> 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 -> float -> 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 -> float -> 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 (/:) : float -> 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. Raise Interval.Division_by_zero if a=zero.

val mod_f : t -> float -> t

mod_f a f returns a mod f according to interval arithmetic and OCaml mod_float definition. Raise Interval.Division_by_zero if f=0.0.

val sqrt : t -> t

sqrt x returns

  • {low=sqrt x.low; high=sqrt x.high} (properly rounded) if x.low0.,
  • {low=0.; high=sqrt x.high} if x.low < 0 ≤ x.high.
val (**) : t -> int -> t

pow_i a n returns interval a raised to nth power according to interval arithmetic. If n=0 then one is returned. Computed with exp-log in base2.

val (**.) : t -> float -> t

a **. f returns interval a raised to f power according to interval arithmetic. If f=0. then one is returned. Computed with exp-log in base2.

  • raises Domain_error

    if f <= 0. and a=zero or if f is not an integer value and a.high < 0..

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

x **: a returns float x raised to interval a power according to interval arithmetic, considering the restiction of x to x >= 0.

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

a *** b returns interval a raised to b power according to interval arithmetic, considering the restriction of "x power y" to x >= 0.

  • raises Domain_error

    if a.high < 0 or (a.high = 0. and b.high <= 0.).

Logarithmic and exponential functions

val log : t -> t

log a returns, properly rounded,

  • {low=log a.low; high=log a.high} if a.low>0., and
  • {low=neg_infinity; high=log a.high} if a.low<0<=a.high.

Raise Domain_error if a.high ≤ 0.

val exp : t -> t

exp a returns {low=exp a.high; high=exp b.high}, properly rounded.

Trigonometric functions

val cos : t -> t

cos a returns the proper extension of cos to interval arithmetic. Returns [-1,1] if one of the bounds is greater or lower than ±2⁵³.

val sin : t -> t

sin a returns the proper extension of sin to interval arithmetic. Returns [-1,1] if one of the bounds is greater or lower than ±2⁵³.

val tan : t -> t

tan a returns the proper extension of tan to interval arithmetic. Returns [-∞,∞] if one of the bounds is greater or lower than ±2⁵³.

val acos : t -> t

acos a returns {low=(if a.high<1. then acos a.high else 0); high=(if a.low>-1. then acos a.low else pi)}. All values are in [0,π].

val asin : t -> t

asin a returns {low=(if a.low > -1. then asin a.low else -pi/2); high=(if a.low < 1. then asin a.high else pi/2)}. All values are in [-π/2,π/2].

val atan : t -> t

atan a returns {low=atan a.low; high=atan a.high} properly rounded.

val atan2mod : t -> t -> t

atan2mod y x returns the proper extension of interval arithmetic to atan2 but with values in [-π, 2π] instead of [-π, π]. This can happen when y.low < 0 and y.high > 0 and x.high < 0: then the returned interval is {low=atan2 y.high x.high; high=(atan2 y.low x.high)+2 pi}. This preserves the best inclusion function possible but is not compatible with the standard definition of atan2.

val atan2 : t -> t -> t

Same function as above but when y.low < 0 and y.high > 0 and x.high < 0 the returned interval is [-π, π]. This does not preserve the best inclusion function but is compatible with the atan2 regular definition.

val cosh : t -> t

cosh is the proper extension of cosh to interval arithmetic.

val sinh : t -> t

sinh is the proper extension of sinh to interval arithmetic.

val tanh : t -> t

tanh is the proper extension of tanh to interval arithmetic.

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.

Arrays of intervals

module Arr : sig ... end

Operations on arrays of intervals.