intervals-0.8.1: Interval Arithmetic

Numeric.Interval.Kaucher

Description

"Directed" Interval arithmetic

Synopsis

# Documentation

data Interval a #

Constructors

 I !a !a
Instances
 # Instance detailsDefined in Numeric.Interval.Kaucher Methods(>>=) :: Interval a -> (a -> Interval b) -> Interval b #(>>) :: Interval a -> Interval b -> Interval b #return :: a -> Interval a #fail :: String -> Interval a # # Instance detailsDefined in Numeric.Interval.Kaucher Methodsfmap :: (a -> b) -> Interval a -> Interval b #(<\$) :: a -> Interval b -> Interval a # # Instance detailsDefined in Numeric.Interval.Kaucher Methodspure :: a -> Interval a #(<*>) :: Interval (a -> b) -> Interval a -> Interval b #liftA2 :: (a -> b -> c) -> Interval a -> Interval b -> Interval c #(*>) :: Interval a -> Interval b -> Interval b #(<*) :: Interval a -> Interval b -> Interval a # # Instance detailsDefined in Numeric.Interval.Kaucher Methodsfold :: Monoid m => Interval m -> m #foldMap :: Monoid m => (a -> m) -> Interval a -> m #foldr :: (a -> b -> b) -> b -> Interval a -> b #foldr' :: (a -> b -> b) -> b -> Interval a -> b #foldl :: (b -> a -> b) -> b -> Interval a -> b #foldl' :: (b -> a -> b) -> b -> Interval a -> b #foldr1 :: (a -> a -> a) -> Interval a -> a #foldl1 :: (a -> a -> a) -> Interval a -> a #toList :: Interval a -> [a] #null :: Interval a -> Bool #length :: Interval a -> Int #elem :: Eq a => a -> Interval a -> Bool #maximum :: Ord a => Interval a -> a #minimum :: Ord a => Interval a -> a #sum :: Num a => Interval a -> a #product :: Num a => Interval a -> a # # Instance detailsDefined in Numeric.Interval.Kaucher Methodstraverse :: Applicative f => (a -> f b) -> Interval a -> f (Interval b) #sequenceA :: Applicative f => Interval (f a) -> f (Interval a) #mapM :: Monad m => (a -> m b) -> Interval a -> m (Interval b) #sequence :: Monad m => Interval (m a) -> m (Interval a) # # Instance detailsDefined in Numeric.Interval.Kaucher Methodsdistribute :: Functor f => f (Interval a) -> Interval (f a) #collect :: Functor f => (a -> Interval b) -> f a -> Interval (f b) #distributeM :: Monad m => m (Interval a) -> Interval (m a) #collectM :: Monad m => (a -> Interval b) -> m a -> Interval (m b) # Eq a => Eq (Interval a) # Instance detailsDefined in Numeric.Interval.Kaucher Methods(==) :: Interval a -> Interval a -> Bool #(/=) :: Interval a -> Interval a -> Bool # (RealFloat a, Ord a) => Floating (Interval a) # Instance detailsDefined in Numeric.Interval.Kaucher Methodspi :: Interval a #exp :: Interval a -> Interval a #log :: Interval a -> Interval a #sqrt :: Interval a -> Interval a #(**) :: Interval a -> Interval a -> Interval a #logBase :: Interval a -> Interval a -> Interval a #sin :: Interval a -> Interval a #cos :: Interval a -> Interval a #tan :: Interval a -> Interval a #asin :: Interval a -> Interval a #acos :: Interval a -> Interval a #atan :: Interval a -> Interval a #sinh :: Interval a -> Interval a #cosh :: Interval a -> Interval a #tanh :: Interval a -> Interval a #asinh :: Interval a -> Interval a #acosh :: Interval a -> Interval a #atanh :: Interval a -> Interval a #log1p :: Interval a -> Interval a #expm1 :: Interval a -> Interval a #log1pexp :: Interval a -> Interval a #log1mexp :: Interval a -> Interval a # (Fractional a, Ord a) => Fractional (Interval a) # Instance detailsDefined in Numeric.Interval.Kaucher Methods(/) :: Interval a -> Interval a -> Interval a #recip :: Interval a -> Interval a # Data a => Data (Interval a) # Instance detailsDefined in Numeric.Interval.Kaucher Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Interval a -> c (Interval a) #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Interval a) #toConstr :: Interval a -> Constr #dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Interval a)) #dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Interval a)) #gmapT :: (forall b. Data b => b -> b) -> Interval a -> Interval a #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Interval a -> r #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Interval a -> r #gmapQ :: (forall d. Data d => d -> u) -> Interval a -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> Interval a -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> Interval a -> m (Interval a) #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Interval a -> m (Interval a) #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Interval a -> m (Interval a) # (Num a, Ord a) => Num (Interval a) # Instance detailsDefined in Numeric.Interval.Kaucher Methods(+) :: Interval a -> Interval a -> Interval a #(-) :: Interval a -> Interval a -> Interval a #(*) :: Interval a -> Interval a -> Interval a #negate :: Interval a -> Interval a #abs :: Interval a -> Interval a #signum :: Interval a -> Interval a # Ord a => Ord (Interval a) # Instance detailsDefined in Numeric.Interval.Kaucher Methodscompare :: Interval a -> Interval a -> Ordering #(<) :: Interval a -> Interval a -> Bool #(<=) :: Interval a -> Interval a -> Bool #(>) :: Interval a -> Interval a -> Bool #(>=) :: Interval a -> Interval a -> Bool #max :: Interval a -> Interval a -> Interval a #min :: Interval a -> Interval a -> Interval a # Real a => Real (Interval a) # realToFrac will use the midpoint Instance detailsDefined in Numeric.Interval.Kaucher Methods 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. Instance detailsDefined in Numeric.Interval.Kaucher MethodsfloatDigits :: Interval a -> Int #floatRange :: Interval a -> (Int, Int) #decodeFloat :: Interval a -> (Integer, Int) #exponent :: Interval a -> Int #significand :: Interval a -> Interval a #scaleFloat :: Int -> Interval a -> Interval a #isNaN :: Interval a -> Bool #isInfinite :: Interval a -> Bool #isIEEE :: Interval a -> Bool #atan2 :: Interval a -> Interval a -> Interval a # RealFrac a => RealFrac (Interval a) # Instance detailsDefined in Numeric.Interval.Kaucher MethodsproperFraction :: Integral b => Interval a -> (b, Interval a) #truncate :: Integral b => Interval a -> b #round :: Integral b => Interval a -> b #ceiling :: Integral b => Interval a -> b #floor :: Integral b => Interval a -> b # Show a => Show (Interval a) # Instance detailsDefined in Numeric.Interval.Kaucher MethodsshowsPrec :: Int -> Interval a -> ShowS #show :: Interval a -> String #showList :: [Interval a] -> ShowS # # Instance detailsDefined in Numeric.Interval.Kaucher Associated Typestype Rep (Interval a) :: Type -> Type # Methodsfrom :: Interval a -> Rep (Interval a) x #to :: Rep (Interval a) x -> Interval a # # Instance detailsDefined in Numeric.Interval.Kaucher Associated Typestype Rep1 Interval :: k -> Type # Methodsfrom1 :: Interval a -> Rep1 Interval a #to1 :: Rep1 Interval a -> Interval a # type Rep (Interval a) # Instance detailsDefined in Numeric.Interval.Kaucher type Rep (Interval a) = D1 (MetaData "Interval" "Numeric.Interval.Kaucher" "intervals-0.8.1-37DWOFGOl0SDknPs4iISGx" False) (C1 (MetaCons "I" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 a) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 a))) type Rep1 Interval # Instance detailsDefined in Numeric.Interval.Kaucher type Rep1 Interval = D1 (MetaData "Interval" "Numeric.Interval.Kaucher" "intervals-0.8.1-37DWOFGOl0SDknPs4iISGx" False) (C1 (MetaCons "I" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) Par1 :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) Par1))

(...) :: a -> a -> Interval a infix 3 #

Create a directed interval.

interval :: Ord a => a -> a -> Maybe (Interval a) #

Try to create a non-empty interval.

whole :: Fractional a => Interval a #

The whole real number line

>>> whole
-Infinity ... Infinity


empty :: Fractional a => Interval a #

An empty interval

>>> empty
NaN ... NaN


null :: Ord a => Interval a -> Bool #

negation handles NaN properly

>>> null (1 ... 5)
False

>>> null (1 ... 1)
False

>>> null empty
True


singleton :: a -> Interval a #

A singleton point

>>> singleton 1
1 ... 1


member :: Ord a => a -> Interval a -> Bool #

Determine if a point is in the interval.

>>> member 3.2 (1.0 ... 5.0)
True

>>> member 5 (1.0 ... 5.0)
True

>>> member 1 (1.0 ... 5.0)
True

>>> member 8 (1.0 ... 5.0)
False

>>> member 5 empty
False


notMember :: Ord a => a -> Interval a -> Bool #

Determine if a point is not included in the interval

>>> notMember 8 (1.0 ... 5.0)
True

>>> notMember 1.4 (1.0 ... 5.0)
False


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

>>> notMember 5 empty
True


elem :: Ord a => a -> Interval a -> Bool #

Deprecated: Use member instead.

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 -> Bool #

Deprecated: Use notMember instead.

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


inf :: Interval a -> a #

The infinumum (lower bound) of an interval

>>> inf (1 ... 20)
1


sup :: Interval a -> a #

The supremum (upper bound) of an interval

>>> sup (1 ... 20)
20


singular :: 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

>>> singular (singleton 1)
True

>>> singular (1.0 ... 20.0)
False


width :: Num a => Interval a -> a #

Calculate the width of an interval.

>>> width (1 ... 20)
19

>>> width (singleton 1)
0

>>> width empty
NaN


midpoint :: Fractional a => Interval a -> a #

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 a #

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 a #

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


bisect :: Fractional a => Interval a -> (Interval a, Interval a) #

Bisect an interval at its midpoint.

>>> bisect (10.0 ... 20.0)
(10.0 ... 15.0,15.0 ... 20.0)

>>> bisect (singleton 5.0)
(5.0 ... 5.0,5.0 ... 5.0)

>>> bisect empty
(NaN ... NaN,NaN ... NaN)


magnitude :: (Num a, Ord a) => Interval a -> a #

Magnitude

>>> magnitude (1 ... 20)
20

>>> magnitude (-20 ... 10)
20

>>> magnitude (singleton 5)
5


mignitude :: (Num a, Ord a) => Interval a -> a #

"mignitude"

>>> mignitude (1 ... 20)
1

>>> mignitude (-20 ... 10)
0

>>> mignitude (singleton 5)
5

>>> mignitude empty
NaN


distance :: (Num a, Ord a) => Interval a -> Interval a -> a #

Hausdorff distance between non-empty intervals.

>>> distance (1 ... 7) (6 ... 10)
0

>>> distance (1 ... 7) (15 ... 24)
8

>>> distance (1 ... 7) (-10 ... -2)
3

>>> distance empty (1 ... 1)
NaN


inflate :: (Num a, Ord a) => a -> Interval a -> Interval a #

Inflate an interval by enlarging it at both ends.

>>> inflate 3 (-1 ... 7)
-4 ... 10

>>> inflate (-2) (0 ... 4)
2 ... 2


deflate :: Fractional a => a -> Interval a -> Interval a #

Deflate an interval by shrinking it from both ends.

>>> deflate 3.0 (-4.0 ... 10.0)
-1.0 ... 7.0

>>> deflate 2.0 (-1.0 ... 1.0)
1.0 ... -1.0


scale :: Fractional a => a -> Interval a -> Interval a #

Scale an interval about its midpoint.

>>> scale 1.1 (-6.0 ... 4.0)
-6.5 ... 4.5

>>> scale (-2.0) (-1.0 ... 1.0)
2.0 ... -2.0


symmetric :: Num a => a -> Interval a #

Construct a symmetric interval.

>>> symmetric 3
-3 ... 3

>>> symmetric (-2)
2 ... -2


contains :: Ord a => Interval a -> Interval a -> Bool #

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 -> Bool #

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 -> Bool #

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

(<!) :: Ord a => Interval a -> Interval a -> Bool #

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 -> Bool #

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 -> Bool #

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 -> Bool #

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 -> Bool #

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 -> Bool #

Does there exist an x in X, y in Y such that x op y?

(<?) :: Ord a => Interval a -> Interval a -> Bool #

Does there exist an x in X, y in Y such that x < y?

(<=?) :: Ord a => Interval a -> Interval a -> Bool #

Does there exist an x in X, y in Y such that x <= y?

(==?) :: Ord a => Interval a -> Interval a -> Bool #

Does there exist an x in X, y in Y such that x == y?

(>=?) :: Ord a => Interval a -> Interval a -> Bool #

Does there exist an x in X, y in Y such that x >= y?

(>?) :: Ord a => Interval a -> Interval a -> Bool #

Does there exist an x in X, y in Y such that x > y?

clamp :: Ord a => Interval a -> a -> a #

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

id function. Useful for type specification

>>> :t idouble (1 ... 3)
idouble (1 ... 3) :: Interval Double


id function. Useful for type specification

>>> :t ifloat (1 ... 3)
ifloat (1 ... 3) :: Interval Float


iquot :: Integral a => Interval a -> Interval a -> Interval a #

an interval containing all x quot y >>> (5 quot 3) member ((4...6) iquot (2...4)) True >>> (1...10) iquot ((-5)...4) *** Exception: divide by zero

irem :: Integral a => Interval a -> Interval a -> Interval a #

an interval containing all x rem y >>> (5 rem 3) member ((4...6) irem (2...4)) True >>> (1...10) irem ((-5)...4) *** Exception: divide by zero

idiv :: Integral a => Interval a -> Interval a -> Interval a #

an interval containing all x div y >>> (5 div 3) member ((4...6) idiv (2...4)) True >>> (1...10) idiv ((-5)...4) *** Exception: divide by zero

imod :: Integral a => Interval a -> Interval a -> Interval a #

an interval containing all x mod y >>> (5 mod 3) member ((4...6) imod (2...4)) True >>> (1...10) imod ((-5)...4) *** Exception: divide by zero