HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleintervals-0.9.2Haskell2010

Numeric.Interval.NonEmpty.Internal

Interval arithmetic

  • 1 type
  • 47 values
  • Packageintervals-0.9.2
  • Exports48
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceInternal.hs
datadata Interval a
#

Constructors

  • I !a !a
Instances15Generic1, Eq, Floating, Fractional, Data, Num, …
  • Generic1 IntervalDefined in intervals-0.9.2 · Numeric.Interval.NonEmpty.Internal
  • Eq a => Eq (Interval a)Defined in intervals-0.9.2 · Numeric.Interval.NonEmpty.Internal
  • (RealFloat a, Ord a) => Floating (Interval a)Defined in intervals-0.9.2 · Numeric.Interval.NonEmpty.Internal

    Transcendental functions for intervals.

    Property
    conservative (exp :: Double -> Double) exp
    Property
    conservativeExceptNaN (log :: Double -> Double) log
    Property
    conservative (sin :: Double -> Double) sin
    Property
    conservative (cos :: Double -> Double) cos
    Property
    conservative (tan :: Double -> Double) tan
    Property
    conservativeExceptNaN (asin :: Double -> Double) asin
    Property
    conservativeExceptNaN (acos :: Double -> Double) acos
    Property
    conservative (atan :: Double -> Double) atan
    Property
    conservative (sinh :: Double -> Double) sinh
    Property
    conservative (cosh :: Double -> Double) cosh
    Property
    conservative (tanh :: Double -> Double) tanh
    Property
    conservativeExceptNaN (asinh :: Double -> Double) asinh
    Property
    conservativeExceptNaN (acosh :: Double -> Double) acosh
    Property
    conservativeExceptNaN (atanh :: Double -> Double) atanh
    Example1 expression
    cos (0 ... (pi + 0.1))-1.0 ... 1.0
  • (Fractional a, Ord a) => Fractional (Interval a)Defined in intervals-0.9.2 · Numeric.Interval.NonEmpty.Internal

    Fractional instance for intervals.

    Property
    ys /= singleton 0 ==> conservative2 ((/) :: Double -> Double -> Double) (/) xs ys
    Property
    xs /= singleton 0 ==> conservative (recip :: Double -> Double) recip xs
  • Data a => Data (Interval a)Defined in intervals-0.9.2 · Numeric.Interval.NonEmpty.Internal
  • (Num a, Ord a) => Num (Interval a)Defined in intervals-0.9.2 · Numeric.Interval.NonEmpty.Internal

    Num instance for intervals.

    Property
    conservative2 ((+) :: Double -> Double -> Double) (+)
    Property
    conservative2 ((-) :: Double -> Double -> Double) (-)
    Property
    conservative2 ((*) :: Double -> Double -> Double) (*)
    Property
    conservative (abs :: Double -> Double) abs
  • Ord a => Ord (Interval a)Defined in intervals-0.9.2 · Numeric.Interval.NonEmpty.Internal
  • Real a => Real (Interval a)Defined in intervals-0.9.2 · Numeric.Interval.NonEmpty.Internal

    realToFrac will use the midpoint

  • RealFloat a => RealFloat (Interval a)Defined in intervals-0.9.2 · Numeric.Interval.NonEmpty.Internal

    We have to play some semantic games to make these methods make sense. Most compute with the midpoint of the interval.

  • RealFrac a => RealFrac (Interval a)Defined in intervals-0.9.2 · Numeric.Interval.NonEmpty.Internal
  • Show a => Show (Interval a)Defined in intervals-0.9.2 · Numeric.Interval.NonEmpty.Internal
  • Generic (Interval a)Defined in intervals-0.9.2 · Numeric.Interval.NonEmpty.Internal
  • Ord a => Semigroup (Interval a)Defined in intervals-0.9.2 · Numeric.Interval.NonEmpty.Internal

    <> is hull

  • type Rep (Interval a) = D1 ('MetaData "Interval" "Numeric.Interval.NonEmpty.Internal" "intervals-0.9.2-GszllUVeoea4WIEuxTLFCE" 'False) (C1 ('MetaCons "I" 'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a)))Defined in intervals-0.9.2 · Numeric.Interval.NonEmpty.Internal
  • type Rep1 Interval = D1 ('MetaData "Interval" "Numeric.Interval.NonEmpty.Internal" "intervals-0.9.2-GszllUVeoea4WIEuxTLFCE" 'False) (C1 ('MetaCons "I" 'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) Par1 :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) Par1))Defined in intervals-0.9.2 · Numeric.Interval.NonEmpty.Internal
value(...) :: Ord a => a -> a -> Interval a
#

Create a non-empty interval, turning it around if necessary

valuewhole :: Fractional a => Interval a
#

The whole real number line

Example1 expression
whole-Infinity ... Infinity
Property
(x :: Double) `elem` whole
valuesingleton :: a -> Interval a
#

A singleton point

Example1 expression
singleton 11 ... 1
Property
x `elem` (singleton x)
Property
x /= y ==> y `notElem` (singleton x)
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
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
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
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
valueinf :: Interval a -> a
#

The infinumum (lower bound) of an interval

Example1 expression
inf (1 ... 20)1
Property
min x y == inf (x ... y)
Property
inf x <= sup x
valuesup :: Interval a -> a
#

The supremum (upper bound) of an interval

Example1 expression
sup (1 ... 20)20
Property
sup x `elem` x
Property
max x y == sup (x ... y)
Property
inf x <= sup x
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
Property
0 <= width x
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
Property
midpoint x `elem` (x :: Interval Double)
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
Property
commutative (distance :: Interval Double -> Interval Double -> Double)
Property
0 <= distance x y
valueintersection :: Ord a => Interval a -> Interval a -> Maybe (Interval a)
#

Calculate the intersection of two intervals.

Example1 expression
intersection (1 ... 10 :: Interval Double) (5 ... 15 :: Interval Double)Just (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
Property
conservative2 const hull
Property
conservative2 (flip const) hull
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)
Property
let (a, b) = bisect (x :: Interval Double) in sup a == inf b
Property
let (a, b) = bisect (x :: Interval Double) in inf a == inf x
Property
let (a, b) = bisect (x :: Interval Double) in sup b == sup x
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
Property
0 <= magnitude x
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
Property
0 <= mignitude x
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
valueclamp :: Ord a => Interval a -> a -> a
#

The nearest value to that supplied which is contained in the interval.

Property
(clamp xs y) `elem` xs
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
Property
inflate x i `contains` i
valuedeflate :: (Fractional a, Ord a) => a -> Interval a -> Interval a
#

Deflate an interval by shrinking it from both ends. Note that in cases that would result in an empty interval, the result is a singleton interval at the midpoint.

Example1 expression
deflate 3.0 (-4.0 ... 10.0)-1.0 ... 7.0
Example1 expression
deflate 2.0 (-1.0 ... 1.0)0.0 ... 0.0
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)-2.0 ... 2.0
Property
abs x >= 1 ==> (scale (x :: Double) i) `contains` i
Property
forAll (choose (0,1)) $ \x -> abs x <= 1 ==> i `contains` (scale (x :: Double) i)
valuesymmetric :: (Num a, Ord a) => a -> Interval a
#

Construct a symmetric interval.

Example1 expression
symmetric 3-3 ... 3
Example1 expression
symmetric (-2)-2 ... 2
Property
x `elem` symmetric x
Property
0 `elem` symmetric x

id function. Useful for type specification

Example1 expression
:t ifloat (1 ... 3)ifloat (1 ... 3) :: Interval Float