Portability | DeriveDataTypeable |
---|---|
Stability | experimental |
Maintainer | ekmett@gmail.com |
Safe Haskell | Safe-Inferred |
Interval arithmetic
- data Interval a = I !a !a
- (...) :: a -> a -> Interval a
- whole :: Fractional a => Interval a
- empty :: Fractional a => Interval a
- null :: Ord a => Interval a -> Bool
- singleton :: a -> Interval a
- elem :: Ord a => a -> Interval a -> Bool
- notElem :: Ord a => a -> Interval a -> Bool
- inf :: Interval a -> a
- sup :: Interval a -> a
- singular :: Ord a => Interval a -> Bool
- width :: Num a => Interval a -> a
- midpoint :: Fractional a => Interval a -> a
- intersection :: (Fractional a, Ord a) => Interval a -> Interval a -> Interval a
- hull :: Ord a => Interval a -> Interval a -> Interval a
- bisection :: Fractional a => Interval a -> (Interval a, Interval a)
- magnitude :: (Num a, Ord a) => Interval a -> a
- mignitude :: (Num a, Ord a) => Interval a -> a
- contains :: Ord a => Interval a -> Interval a -> Bool
- isSubsetOf :: Ord a => Interval a -> Interval a -> Bool
- certainly :: Ord a => (forall b. Ord b => b -> b -> Bool) -> Interval a -> Interval a -> Bool
- (<!) :: Ord a => Interval a -> Interval a -> Bool
- (<=!) :: Ord a => Interval a -> Interval a -> Bool
- (==!) :: Eq a => Interval a -> Interval a -> Bool
- (>=!) :: Ord a => Interval a -> Interval a -> Bool
- (>!) :: Ord a => Interval a -> Interval a -> Bool
- possibly :: Ord a => (forall b. Ord b => b -> b -> Bool) -> Interval a -> Interval a -> Bool
- (<?) :: Ord a => Interval a -> Interval a -> Bool
- (<=?) :: Ord a => Interval a -> Interval a -> Bool
- (==?) :: Ord a => Interval a -> Interval a -> Bool
- (>=?) :: Ord a => Interval a -> Interval a -> Bool
- (>?) :: Ord a => Interval a -> Interval a -> Bool
- clamp :: Ord a => Interval a -> a -> a
- idouble :: Interval Double -> Interval Double
- ifloat :: Interval Float -> Interval Float
Documentation
I !a !a |
Monad Interval | |
Functor Interval | |
Typeable1 Interval | |
Applicative Interval | |
Foldable Interval | |
Traversable Interval | |
Distributive Interval | |
Eq a => Eq (Interval a) | |
(RealFloat a, Ord a) => Floating (Interval a) | |
(Fractional a, Ord a) => Fractional (Interval a) | |
Data a => Data (Interval a) | |
(Num a, Ord a) => Num (Interval a) | |
Ord a => Ord (Interval a) | |
Real a => Real (Interval a) |
|
RealFloat a => RealFloat (Interval a) | 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) | |
Show a => Show (Interval a) |
(...) :: a -> a -> Interval aSource
The rule of thumb is you should only use this to construct using values that you took out of the interval. Otherwise, use I, to force rounding
whole :: Fractional a => Interval aSource
The whole real number line
>>>
whole
-Infinity ... Infinity
empty :: Fractional a => Interval aSource
An empty interval
>>>
empty
NaN ... NaN
null :: Ord a => Interval a -> BoolSource
negation handles NaN properly
>>>
null (1 ... 5)
False
>>>
null (1 ... 1)
False
>>>
null empty
True
elem :: Ord a => a -> Interval a -> BoolSource
Determine if a point is in the interval.
>>>
elem 3.2 (1.0 ... 5.0)
True
>>>
elem 5 (1.0 ... 5.0)
True
>>>
elem 1 (1.0 ... 5.0)
True
>>>
elem 8 (1.0 ... 5.0)
False
>>>
elem 5 empty
False
notElem :: Ord a => a -> Interval a -> BoolSource
Determine if a point is not included in the interval
>>>
notElem 8 (1.0 ... 5.0)
True
>>>
notElem 1.4 (1.0 ... 5.0)
False
And of course, nothing is a member of the empty interval.
>>>
notElem 5 empty
True
singular :: Ord a => Interval a -> BoolSource
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
>>>
singular (singleton 1)
True
>>>
singular (1.0 ... 20.0)
False
width :: Num a => Interval a -> aSource
Calculate the width of an interval.
>>>
width (1 ... 20)
19
>>>
width (singleton 1)
0
>>>
width empty
NaN
midpoint :: Fractional a => Interval a -> aSource
Nearest point to the midpoint of the interval.
>>>
midpoint (10.0 ... 20.0)
15.0
>>>
midpoint (singleton 5.0)
5.0
>>>
midpoint empty
NaN
intersection :: (Fractional a, Ord a) => Interval a -> Interval a -> Interval aSource
Calculate the intersection of two intervals.
>>>
intersection (1 ... 10 :: Interval Double) (5 ... 15 :: Interval Double)
5.0 ... 10.0
hull :: Ord a => Interval a -> Interval a -> Interval aSource
Calculate the convex hull of two intervals
>>>
hull (0 ... 10 :: Interval Double) (5 ... 15 :: Interval Double)
0.0 ... 15.0
>>>
hull (15 ... 85 :: Interval Double) (0 ... 10 :: Interval Double)
0.0 ... 85.0
bisection :: Fractional a => Interval a -> (Interval a, Interval a)Source
Bisect an interval at its midpoint.
>>>
bisection (10.0 ... 20.0)
(10.0 ... 15.0,15.0 ... 20.0)
>>>
bisection (singleton 5.0)
(5.0 ... 5.0,5.0 ... 5.0)
>>>
bisection empty
(NaN ... NaN,NaN ... NaN)
magnitude :: (Num a, Ord a) => Interval a -> aSource
Magnitude
>>>
magnitude (1 ... 20)
20
>>>
magnitude (-20 ... 10)
20
>>>
magnitude (singleton 5)
5
mignitude :: (Num a, Ord a) => Interval a -> aSource
"mignitude"
>>>
mignitude (1 ... 20)
1
>>>
mignitude (-20 ... 10)
10
>>>
mignitude (singleton 5)
5
contains :: Ord a => Interval a -> Interval a -> BoolSource
Check if interval X
totally contains interval Y
>>>
(20 ... 40 :: Interval Double) `contains` (25 ... 35 :: Interval Double)
True
>>>
(20 ... 40 :: Interval Double) `contains` (15 ... 35 :: Interval Double)
False
isSubsetOf :: Ord a => Interval a -> Interval a -> BoolSource
Flipped version of contains
. Check if interval X
a subset of interval Y
>>>
(25 ... 35 :: Interval Double) `isSubsetOf` (20 ... 40 :: Interval Double)
True
>>>
(20 ... 40 :: Interval Double) `isSubsetOf` (15 ... 35 :: Interval Double)
False
certainly :: Ord a => (forall b. Ord b => b -> b -> Bool) -> Interval a -> Interval a -> BoolSource
For all x
in X
, y
in Y
. x
op
y
(<!) :: Ord a => Interval a -> Interval a -> BoolSource
For all x
in X
, y
in Y
. x
<
y
>>>
(5 ... 10 :: Interval Double) <! (20 ... 30 :: Interval Double)
True
>>>
(5 ... 10 :: Interval Double) <! (10 ... 30 :: Interval Double)
False
>>>
(20 ... 30 :: Interval Double) <! (5 ... 10 :: Interval Double)
False
(<=!) :: Ord a => Interval a -> Interval a -> BoolSource
For all x
in X
, y
in Y
. x
<=
y
>>>
(5 ... 10 :: Interval Double) <=! (20 ... 30 :: Interval Double)
True
>>>
(5 ... 10 :: Interval Double) <=! (10 ... 30 :: Interval Double)
True
>>>
(20 ... 30 :: Interval Double) <=! (5 ... 10 :: Interval Double)
False
(==!) :: Eq a => Interval a -> Interval a -> BoolSource
For all x
in X
, y
in Y
. x
==
y
Only singleton intervals return true
>>>
(singleton 5 :: Interval Double) ==! (singleton 5 :: Interval Double)
True
>>>
(5 ... 10 :: Interval Double) ==! (5 ... 10 :: Interval Double)
False
(>=!) :: Ord a => Interval a -> Interval a -> BoolSource
For all x
in X
, y
in Y
. x
>=
y
>>>
(20 ... 40 :: Interval Double) >=! (10 ... 20 :: Interval Double)
True
>>>
(5 ... 20 :: Interval Double) >=! (15 ... 40 :: Interval Double)
False
(>!) :: Ord a => Interval a -> Interval a -> BoolSource
For all x
in X
, y
in Y
. x
>
y
>>>
(20 ... 40 :: Interval Double) >! (10 ... 19 :: Interval Double)
True
>>>
(5 ... 20 :: Interval Double) >! (15 ... 40 :: Interval Double)
False
possibly :: Ord a => (forall b. Ord b => b -> b -> Bool) -> Interval a -> Interval a -> BoolSource
Does there exist an x
in X
, y
in Y
such that x
?
op
y
(<?) :: Ord a => Interval a -> Interval a -> BoolSource
Does there exist an x
in X
, y
in Y
such that x
?
<
y
(<=?) :: Ord a => Interval a -> Interval a -> BoolSource
Does there exist an x
in X
, y
in Y
such that x
?
<=
y
(==?) :: Ord a => Interval a -> Interval a -> BoolSource
Does there exist an x
in X
, y
in Y
such that x
?
==
y
(>=?) :: Ord a => Interval a -> Interval a -> BoolSource
Does there exist an x
in X
, y
in Y
such that x
?
>=
y
(>?) :: Ord a => Interval a -> Interval a -> BoolSource
Does there exist an x
in X
, y
in Y
such that x
?
>
y
clamp :: Ord a => Interval a -> a -> aSource
The nearest value to that supplied which is contained in the interval.