HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Moduleintervals-0.9.3Haskell2010

Numeric.Interval.Internal

Interval arithmetic

Synopsis
  • Packageintervals-0.9.3
  • Exports50
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceInternal.hs
datadata Interval a
#

Constructors

Instances16Generic1, Eq, Floating, Fractional, Data, Num, …
valuenull :: Interval a -> Bool

Check if an interval is empty

Example1 expression
null (1 ... 5)False
Example1 expression
null (1 ... 1)False
Example1 expression
null emptyTrue
valuemember :: Ord a => a -> Interval a -> Bool

Determine if a point is in the interval.

Example1 expression
member 3.2 (1.0 ... 5.0)True
Example1 expression
member 5 (1.0 ... 5.0)True
Example1 expression
member 1 (1.0 ... 5.0)True
Example1 expression
member 8 (1.0 ... 5.0)False
Example1 expression
member 5 emptyFalse
valuenotMember :: Ord a => a -> Interval a -> Bool

Determine if a point is not included in the interval

Example1 expression
notMember 8 (1.0 ... 5.0)True
Example1 expression
notMember 1.4 (1.0 ... 5.0)False

And of course, nothing is a member of the empty interval.

Example1 expression
notMember 5 emptyTrue
valueelem :: Ord a => a -> Interval a -> Bool

Deprecated. Use member instead.

Determine if a point is in the interval.

Example1 expression
elem 3.2 (1.0 ... 5.0)True
Example1 expression
elem 5 (1.0 ... 5.0)True
Example1 expression
elem 1 (1.0 ... 5.0)True
Example1 expression
elem 8 (1.0 ... 5.0)False
Example1 expression
elem 5 emptyFalse
valuenotElem :: Ord a => a -> Interval a -> Bool

Deprecated. Use notMember instead.

Determine if a point is not included in the interval

Example1 expression
notElem 8 (1.0 ... 5.0)True
Example1 expression
notElem 1.4 (1.0 ... 5.0)False

And of course, nothing is a member of the empty interval.

Example1 expression
notElem 5 emptyTrue
valueinf :: Interval a -> a

The infimum (lower bound) of an interval

Example1 expression
inf (1.0 ... 20.0)1.0
Example1 expression
inf empty*** Exception: empty interval
valuesup :: Interval a -> a

The supremum (upper bound) of an interval

Example1 expression
sup (1.0 ... 20.0)20.0
Example1 expression
sup empty*** Exception: empty interval
valuesingular :: Ord a => Interval a -> Bool

Is the interval a singleton point? N.B. This is fairly fragile and likely will not hold after even a few operations that only involve singletons

Example1 expression
singular (singleton 1)True
Example1 expression
singular (1.0 ... 20.0)False
valuewidth :: Num a => Interval a -> a

Calculate the width of an interval.

Example1 expression
width (1 ... 20)19
Example1 expression
width (singleton 1)0
Example1 expression
width empty0
valuemidpoint :: Fractional a => Interval a -> a

Nearest point to the midpoint of the interval.

Example1 expression
midpoint (10.0 ... 20.0)15.0
Example1 expression
midpoint (singleton 5.0)5.0
Example1 expression
midpoint empty*** Exception: empty interval
valueintersection :: Ord a => Interval a -> Interval a -> Interval a

Calculate the intersection of two intervals.

Example1 expression
intersection (1 ... 10 :: Interval Double) (5 ... 15 :: Interval Double)5.0 ... 10.0
valuehull :: Ord a => Interval a -> Interval a -> Interval a

Calculate the convex hull of two intervals

Example1 expression
hull (0 ... 10 :: Interval Double) (5 ... 15 :: Interval Double)0.0 ... 15.0
Example1 expression
hull (15 ... 85 :: Interval Double) (0 ... 10 :: Interval Double)0.0 ... 85.0
valuebisect :: Fractional a => Interval a -> (Interval a, Interval a)

Bisect an interval at its midpoint.

Example1 expression
bisect (10.0 ... 20.0)(10.0 ... 15.0,15.0 ... 20.0)
Example1 expression
bisect (singleton 5.0)(5.0 ... 5.0,5.0 ... 5.0)
Example1 expression
bisect Empty(Empty,Empty)
valuemagnitude :: (Num a, Ord a) => Interval a -> a

Magnitude

Example1 expression
magnitude (1 ... 20)20
Example1 expression
magnitude (-20 ... 10)20
Example1 expression
magnitude (singleton 5)5

throws EmptyInterval if the interval is empty.

Example1 expression
magnitude empty*** Exception: empty interval
valuemignitude :: (Num a, Ord a) => Interval a -> a

"mignitude"

Example1 expression
mignitude (1 ... 20)1
Example1 expression
mignitude (-20 ... 10)0
Example1 expression
mignitude (singleton 5)5

throws EmptyInterval if the interval is empty.

Example1 expression
mignitude empty*** Exception: empty interval
valuedistance :: (Num a, Ord a) => Interval a -> Interval a -> a

Hausdorff distance between intervals.

Example1 expression
distance (1 ... 7) (6 ... 10)0
Example1 expression
distance (1 ... 7) (15 ... 24)8
Example1 expression
distance (1 ... 7) (-10 ... -2)3
Example1 expression
distance Empty (1 ... 1)*** Exception: empty interval
valueinflate :: (Num a, Ord a) => a -> Interval a -> Interval a

Inflate an interval by enlarging it at both ends.

Example1 expression
inflate 3 (-1 ... 7)-4 ... 10
Example1 expression
inflate (-2) (0 ... 4)-2 ... 6
Example1 expression
inflate 1 emptyEmpty
valuedeflate :: (Num a, Ord a) => a -> Interval a -> Interval a

Deflate an interval by shrinking it from both ends.

Example1 expression
deflate 3.0 (-4.0 ... 10.0)-1.0 ... 7.0
Example1 expression
deflate 2.0 (-1.0 ... 1.0)Empty
Example1 expression
deflate 1.0 emptyEmpty
valuescale :: (Fractional a, Ord a) => a -> Interval a -> Interval a

Scale an interval about its midpoint.

Example1 expression
scale 1.1 (-6.0 ... 4.0)-6.5 ... 4.5
Example1 expression
scale (-2.0) (-1.0 ... 1.0)Empty
Example1 expression
scale 3.0 emptyEmpty
valuesymmetric :: (Num a, Ord a) => a -> Interval a

Construct a symmetric interval.

Example1 expression
symmetric 3-3 ... 3
Example1 expression
symmetric (-2)-2 ... 2
valuecontains :: Ord a => Interval a -> Interval a -> Bool

Check if interval X totally contains interval Y

Example1 expression
(20 ... 40 :: Interval Double) `contains` (25 ... 35 :: Interval Double)True
Example1 expression
(20 ... 40 :: Interval Double) `contains` (15 ... 35 :: Interval Double)False
valueisSubsetOf :: Ord a => Interval a -> Interval a -> Bool

Flipped version of contains. Check if interval X a subset of interval Y

Example1 expression
(25 ... 35 :: Interval Double) `isSubsetOf` (20 ... 40 :: Interval Double)True
Example1 expression
(20 ... 40 :: Interval Double) `isSubsetOf` (15 ... 35 :: Interval Double)False
value(<!) :: Ord a => Interval a -> Interval a -> Bool

For all x in X, y in Y. x < y

Example1 expression
(5 ... 10 :: Interval Double) <! (20 ... 30 :: Interval Double)True
Example1 expression
(5 ... 10 :: Interval Double) <! (10 ... 30 :: Interval Double)False
Example1 expression
(20 ... 30 :: Interval Double) <! (5 ... 10 :: Interval Double)False
value(<=!) :: Ord a => Interval a -> Interval a -> Bool

For all x in X, y in Y. x <= y

Example1 expression
(5 ... 10 :: Interval Double) <=! (20 ... 30 :: Interval Double)True
Example1 expression
(5 ... 10 :: Interval Double) <=! (10 ... 30 :: Interval Double)True
Example1 expression
(20 ... 30 :: Interval Double) <=! (5 ... 10 :: Interval Double)False
value(==!) :: Eq a => Interval a -> Interval a -> Bool

For all x in X, y in Y. x == y

Only singleton intervals or empty intervals can return true

Example1 expression
(singleton 5 :: Interval Double) ==! (singleton 5 :: Interval Double)True
Example1 expression
(5 ... 10 :: Interval Double) ==! (5 ... 10 :: Interval Double)False
value(/=!) :: Ord a => Interval a -> Interval a -> Bool

For all x in X, y in Y. x /= y

Example1 expression
(5 ... 15 :: Interval Double) /=! (20 ... 40 :: Interval Double)True
Example1 expression
(5 ... 15 :: Interval Double) /=! (15 ... 40 :: Interval Double)False
value(>=!) :: Ord a => Interval a -> Interval a -> Bool

For all x in X, y in Y. x >= y

Example1 expression
(20 ... 40 :: Interval Double) >=! (10 ... 20 :: Interval Double)True
Example1 expression
(5 ... 20 :: Interval Double) >=! (15 ... 40 :: Interval Double)False
value(>!) :: Ord a => Interval a -> Interval a -> Bool

For all x in X, y in Y. x > y

Example1 expression
(20 ... 40 :: Interval Double) >! (10 ... 19 :: Interval Double)True
Example1 expression
(5 ... 20 :: Interval Double) >! (15 ... 40 :: Interval Double)False