{-# LANGUAGE CPP #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE DeriveDataTypeable #-}
#if __GLASGOW_HASKELL__ >= 704
{-# LANGUAGE DeriveGeneric #-}
#endif
{-# OPTIONS_HADDOCK not-home #-}
module Numeric.Interval.Internal
( Interval(..)
, (...)
, (+/-)
, interval
, whole
, empty
, null
, singleton
, member
, notMember
, elem
, notElem
, inf
, sup
, singular
, width
, midpoint
, intersection
, hull
, bisect
, bisectIntegral
, magnitude
, mignitude
, distance
, inflate, deflate
, scale, symmetric
, contains
, isSubsetOf
, certainly, (<!), (<=!), (==!), (/=!), (>=!), (>!)
, possibly, (<?), (<=?), (==?), (/=?), (>=?), (>?)
, idouble
, ifloat
, iquot
, irem
, idiv
, imod
) where
import Control.Exception as Exception
import Data.Data
import Data.Function (on)
#if __GLASGOW_HASKELL__ >= 704
import GHC.Generics
#endif
import Numeric.Interval.Exception
import Prelude hiding (null, elem, notElem)
import qualified Data.Semigroup
import qualified Data.Monoid
data Interval a = I !a !a | Empty deriving
( Interval a -> Interval a -> Bool
(Interval a -> Interval a -> Bool)
-> (Interval a -> Interval a -> Bool) -> Eq (Interval a)
forall a. Eq a => Interval a -> Interval a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Interval a -> Interval a -> Bool
$c/= :: forall a. Eq a => Interval a -> Interval a -> Bool
== :: Interval a -> Interval a -> Bool
$c== :: forall a. Eq a => Interval a -> Interval a -> Bool
Eq, Eq (Interval a)
Eq (Interval a)
-> (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)
-> (Interval a -> Interval a -> Interval a)
-> (Interval a -> Interval a -> Interval a)
-> Ord (Interval a)
Interval a -> Interval a -> Bool
Interval a -> Interval a -> Ordering
Interval a -> Interval a -> Interval a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (Interval a)
forall a. Ord a => Interval a -> Interval a -> Bool
forall a. Ord a => Interval a -> Interval a -> Ordering
forall a. Ord a => Interval a -> Interval a -> Interval a
min :: Interval a -> Interval a -> Interval a
$cmin :: forall a. Ord a => Interval a -> Interval a -> Interval a
max :: Interval a -> Interval a -> Interval a
$cmax :: forall a. Ord a => Interval a -> Interval a -> Interval a
>= :: Interval a -> Interval a -> Bool
$c>= :: forall a. Ord a => Interval a -> Interval a -> Bool
> :: Interval a -> Interval a -> Bool
$c> :: forall a. Ord a => Interval a -> Interval a -> Bool
<= :: Interval a -> Interval a -> Bool
$c<= :: forall a. Ord a => Interval a -> Interval a -> Bool
< :: Interval a -> Interval a -> Bool
$c< :: forall a. Ord a => Interval a -> Interval a -> Bool
compare :: Interval a -> Interval a -> Ordering
$ccompare :: forall a. Ord a => Interval a -> Interval a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (Interval a)
Ord
, Typeable (Interval a)
DataType
Constr
Typeable (Interval a)
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Interval a -> c (Interval a))
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Interval a))
-> (Interval a -> Constr)
-> (Interval a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Interval a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Interval a)))
-> ((forall b. Data b => b -> b) -> Interval a -> Interval a)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Interval a -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Interval a -> r)
-> (forall u. (forall d. Data d => d -> u) -> Interval a -> [u])
-> (forall u.
Int -> (forall d. Data d => d -> u) -> Interval a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Interval a -> m (Interval a))
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Interval a -> m (Interval a))
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Interval a -> m (Interval a))
-> Data (Interval a)
Interval a -> DataType
Interval a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (Interval a))
(forall b. Data b => b -> b) -> Interval a -> Interval a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Interval a -> c (Interval a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Interval a)
forall a. Data a => Typeable (Interval a)
forall a. Data a => Interval a -> DataType
forall a. Data a => Interval a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> Interval a -> Interval a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Interval a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> Interval a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Interval a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Interval a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Interval a -> m (Interval a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Interval a -> m (Interval a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Interval a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Interval a -> c (Interval a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Interval a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Interval a))
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Interval a -> u
forall u. (forall d. Data d => d -> u) -> Interval a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Interval a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Interval a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Interval a -> m (Interval a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Interval a -> m (Interval a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Interval a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Interval a -> c (Interval a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Interval a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Interval a))
$cEmpty :: Constr
$cI :: Constr
$tInterval :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Interval a -> m (Interval a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Interval a -> m (Interval a)
gmapMp :: (forall d. Data d => d -> m d) -> Interval a -> m (Interval a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Interval a -> m (Interval a)
gmapM :: (forall d. Data d => d -> m d) -> Interval a -> m (Interval a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Interval a -> m (Interval a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> Interval a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Interval a -> u
gmapQ :: (forall d. Data d => d -> u) -> Interval a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> Interval a -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Interval a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Interval a -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Interval a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Interval a -> r
gmapT :: (forall b. Data b => b -> b) -> Interval a -> Interval a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> Interval a -> Interval a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Interval a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Interval a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (Interval a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Interval a))
dataTypeOf :: Interval a -> DataType
$cdataTypeOf :: forall a. Data a => Interval a -> DataType
toConstr :: Interval a -> Constr
$ctoConstr :: forall a. Data a => Interval a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Interval a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Interval a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Interval a -> c (Interval a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Interval a -> c (Interval a)
$cp1Data :: forall a. Data a => Typeable (Interval a)
Data
, Typeable
#if __GLASGOW_HASKELL__ >= 704
, (forall x. Interval a -> Rep (Interval a) x)
-> (forall x. Rep (Interval a) x -> Interval a)
-> Generic (Interval a)
forall x. Rep (Interval a) x -> Interval a
forall x. Interval a -> Rep (Interval a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Interval a) x -> Interval a
forall a x. Interval a -> Rep (Interval a) x
$cto :: forall a x. Rep (Interval a) x -> Interval a
$cfrom :: forall a x. Interval a -> Rep (Interval a) x
Generic
#if __GLASGOW_HASKELL__ >= 706
, (forall a. Interval a -> Rep1 Interval a)
-> (forall a. Rep1 Interval a -> Interval a) -> Generic1 Interval
forall a. Rep1 Interval a -> Interval a
forall a. Interval a -> Rep1 Interval a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cto1 :: forall a. Rep1 Interval a -> Interval a
$cfrom1 :: forall a. Interval a -> Rep1 Interval a
Generic1
#endif
#endif
)
instance Ord a => Data.Semigroup.Semigroup (Interval a) where
<> :: Interval a -> Interval a -> Interval a
(<>) = Interval a -> Interval a -> Interval a
forall a. Ord a => Interval a -> Interval a -> Interval a
hull
instance Ord a => Data.Monoid.Monoid (Interval a) where
mempty :: Interval a
mempty = Interval a
forall a. Interval a
empty
mappend :: Interval a -> Interval a -> Interval a
mappend = Interval a -> Interval a -> Interval a
forall a. Semigroup a => a -> a -> a
(Data.Semigroup.<>)
infix 3 ...
infixl 6 +/-
(+/-) :: (Num a, Ord a) => a -> a -> Interval a
a
a +/- :: a -> a -> Interval a
+/- a
b = a
a a -> a -> a
forall a. Num a => a -> a -> a
- a
b a -> a -> Interval a
forall a. Ord a => a -> a -> Interval a
... a
a a -> a -> a
forall a. Num a => a -> a -> a
+ a
b
negInfinity :: Fractional a => a
negInfinity :: a
negInfinity = (-a
1)a -> a -> a
forall a. Fractional a => a -> a -> a
/a
0
{-# INLINE negInfinity #-}
posInfinity :: Fractional a => a
posInfinity :: a
posInfinity = a
1a -> a -> a
forall a. Fractional a => a -> a -> a
/a
0
{-# INLINE posInfinity #-}
interval :: Ord a => a -> a -> Maybe (Interval a)
interval :: a -> a -> Maybe (Interval a)
interval a
a a
b
| a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
b = Interval a -> Maybe (Interval a)
forall a. a -> Maybe a
Just (Interval a -> Maybe (Interval a))
-> Interval a -> Maybe (Interval a)
forall a b. (a -> b) -> a -> b
$ a -> a -> Interval a
forall a. a -> a -> Interval a
I a
a a
b
| Bool
otherwise = Maybe (Interval a)
forall a. Maybe a
Nothing
{-# INLINE interval #-}
fmod :: RealFrac a => a -> a -> a
fmod :: a -> a -> a
fmod a
a a
b = a
a a -> a -> a
forall a. Num a => a -> a -> a
- a
qa -> a -> a
forall a. Num a => a -> a -> a
*a
b where
q :: a
q = Integer -> a
forall a b. (Real a, Fractional b) => a -> b
realToFrac (a -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
truncate (a -> Integer) -> a -> Integer
forall a b. (a -> b) -> a -> b
$ a
a a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
b :: Integer)
{-# INLINE fmod #-}
(...) :: Ord a => a -> a -> Interval a
a
a ... :: a -> a -> Interval a
... a
b
| a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
b = a -> a -> Interval a
forall a. a -> a -> Interval a
I a
a a
b
| Bool
otherwise = Interval a
forall a. Interval a
Empty
{-# INLINE (...) #-}
whole :: Fractional a => Interval a
whole :: Interval a
whole = a -> a -> Interval a
forall a. a -> a -> Interval a
I a
forall a. Fractional a => a
negInfinity a
forall a. Fractional a => a
posInfinity
{-# INLINE whole #-}
empty :: Interval a
empty :: Interval a
empty = Interval a
forall a. Interval a
Empty
{-# INLINE empty #-}
null :: Interval a -> Bool
null :: Interval a -> Bool
null Interval a
Empty = Bool
True
null Interval a
_ = Bool
False
{-# INLINE null #-}
singleton :: a -> Interval a
singleton :: a -> Interval a
singleton a
a = a -> a -> Interval a
forall a. a -> a -> Interval a
I a
a a
a
{-# INLINE singleton #-}
inf :: Interval a -> a
inf :: Interval a -> a
inf (I a
a a
_) = a
a
inf Interval a
Empty = EmptyInterval -> a
forall a e. Exception e => e -> a
Exception.throw EmptyInterval
EmptyInterval
{-# INLINE inf #-}
sup :: Interval a -> a
sup :: Interval a -> a
sup (I a
_ a
b) = a
b
sup Interval a
Empty = EmptyInterval -> a
forall a e. Exception e => e -> a
Exception.throw EmptyInterval
EmptyInterval
{-# INLINE sup #-}
singular :: Ord a => Interval a -> Bool
singular :: Interval a -> Bool
singular Interval a
Empty = Bool
False
singular (I a
a a
b) = a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
b
{-# INLINE singular #-}
instance Show a => Show (Interval a) where
showsPrec :: Int -> Interval a -> ShowS
showsPrec Int
_ Interval a
Empty = String -> ShowS
showString String
"Empty"
showsPrec Int
n (I a
a a
b) =
Bool -> ShowS -> ShowS
showParen (Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
3) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$
Int -> a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
3 a
a ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
String -> ShowS
showString String
" ... " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Int -> a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
3 a
b
width :: Num a => Interval a -> a
width :: Interval a -> a
width (I a
a a
b) = a
b a -> a -> a
forall a. Num a => a -> a -> a
- a
a
width Interval a
Empty = a
0
{-# INLINE width #-}
magnitude :: (Num a, Ord a) => Interval a -> a
magnitude :: Interval a -> a
magnitude = Interval a -> a
forall a. Interval a -> a
sup (Interval a -> a) -> (Interval a -> Interval a) -> Interval a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Interval a -> Interval a
forall a. Num a => a -> a
abs
{-# INLINE magnitude #-}
mignitude :: (Num a, Ord a) => Interval a -> a
mignitude :: Interval a -> a
mignitude = Interval a -> a
forall a. Interval a -> a
inf (Interval a -> a) -> (Interval a -> Interval a) -> Interval a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Interval a -> Interval a
forall a. Num a => a -> a
abs
{-# INLINE mignitude #-}
distance :: (Num a, Ord a) => Interval a -> Interval a -> a
distance :: Interval a -> Interval a -> a
distance Interval a
i1 Interval a
i2 = Interval a -> a
forall a. (Num a, Ord a) => Interval a -> a
mignitude (Interval a
i1 Interval a -> Interval a -> Interval a
forall a. Num a => a -> a -> a
- Interval a
i2)
inflate :: (Num a, Ord a) => a -> Interval a -> Interval a
inflate :: a -> Interval a -> Interval a
inflate a
x Interval a
y = a -> Interval a
forall a. (Num a, Ord a) => a -> Interval a
symmetric a
x Interval a -> Interval a -> Interval a
forall a. Num a => a -> a -> a
+ Interval a
y
deflate :: (Num a, Ord a) => a -> Interval a -> Interval a
deflate :: a -> Interval a -> Interval a
deflate a
_ Interval a
Empty = Interval a
forall a. Interval a
Empty
deflate a
x (I a
a a
b) | a
a' a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
b' = a -> a -> Interval a
forall a. a -> a -> Interval a
I a
a' a
b'
| Bool
otherwise = Interval a
forall a. Interval a
Empty
where
a' :: a
a' = a
a a -> a -> a
forall a. Num a => a -> a -> a
+ a
x
b' :: a
b' = a
b a -> a -> a
forall a. Num a => a -> a -> a
- a
x
scale :: (Fractional a, Ord a) => a -> Interval a -> Interval a
scale :: a -> Interval a -> Interval a
scale a
_ Interval a
Empty = Interval a
forall a. Interval a
Empty
scale a
x Interval a
i = a
a a -> a -> Interval a
forall a. Ord a => a -> a -> Interval a
... a
b where
h :: a
h = a
x a -> a -> a
forall a. Num a => a -> a -> a
* Interval a -> a
forall a. Num a => Interval a -> a
width Interval a
i a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
2
mid :: a
mid = Interval a -> a
forall a. Fractional a => Interval a -> a
midpoint Interval a
i
a :: a
a = a
mid a -> a -> a
forall a. Num a => a -> a -> a
- a
h
b :: a
b = a
mid a -> a -> a
forall a. Num a => a -> a -> a
+ a
h
symmetric :: (Num a, Ord a) => a -> Interval a
symmetric :: a -> Interval a
symmetric a
x | a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
b = a -> a -> Interval a
forall a. a -> a -> Interval a
I a
a a
b
| Bool
otherwise = a -> a -> Interval a
forall a. a -> a -> Interval a
I a
b a
a
where
a :: a
a = a -> a
forall a. Num a => a -> a
negate a
x
b :: a
b = a
x
instance (Num a, Ord a) => Num (Interval a) where
I a
a a
b + :: Interval a -> Interval a -> Interval a
+ I a
a' a
b' = (a
a a -> a -> a
forall a. Num a => a -> a -> a
+ a
a') a -> a -> Interval a
forall a. Ord a => a -> a -> Interval a
... (a
b a -> a -> a
forall a. Num a => a -> a -> a
+ a
b')
Interval a
_ + Interval a
_ = Interval a
forall a. Interval a
Empty
{-# INLINE (+) #-}
I a
a a
b - :: Interval a -> Interval a -> Interval a
- I a
a' a
b' = (a
a a -> a -> a
forall a. Num a => a -> a -> a
- a
b') a -> a -> Interval a
forall a. Ord a => a -> a -> Interval a
... (a
b a -> a -> a
forall a. Num a => a -> a -> a
- a
a')
Interval a
_ - Interval a
_ = Interval a
forall a. Interval a
Empty
{-# INLINE (-) #-}
I a
a a
b * :: Interval a -> Interval a -> Interval a
* I a
a' a
b' =
[a] -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [a
a a -> a -> a
forall a. Num a => a -> a -> a
* a
a', a
a a -> a -> a
forall a. Num a => a -> a -> a
* a
b', a
b a -> a -> a
forall a. Num a => a -> a -> a
* a
a', a
b a -> a -> a
forall a. Num a => a -> a -> a
* a
b']
a -> a -> Interval a
forall a. Ord a => a -> a -> Interval a
...
[a] -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum [a
a a -> a -> a
forall a. Num a => a -> a -> a
* a
a', a
a a -> a -> a
forall a. Num a => a -> a -> a
* a
b', a
b a -> a -> a
forall a. Num a => a -> a -> a
* a
a', a
b a -> a -> a
forall a. Num a => a -> a -> a
* a
b']
Interval a
_ * Interval a
_ = Interval a
forall a. Interval a
Empty
{-# INLINE (*) #-}
abs :: Interval a -> Interval a
abs x :: Interval a
x@(I a
a a
b)
| a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
0 = Interval a
x
| a
b a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
0 = Interval a -> Interval a
forall a. Num a => a -> a
negate Interval a
x
| Bool
otherwise = a
0 a -> a -> Interval a
forall a. Ord a => a -> a -> Interval a
... a -> a -> a
forall a. Ord a => a -> a -> a
max (- a
a) a
b
abs Interval a
Empty = Interval a
forall a. Interval a
Empty
{-# INLINE abs #-}
signum :: Interval a -> Interval a
signum = (a -> a) -> Interval a -> Interval a
forall a b. (a -> b) -> Interval a -> Interval b
increasing a -> a
forall a. Num a => a -> a
signum
{-# INLINE signum #-}
fromInteger :: Integer -> Interval a
fromInteger Integer
i = a -> Interval a
forall a. a -> Interval a
singleton (Integer -> a
forall a. Num a => Integer -> a
fromInteger Integer
i)
{-# INLINE fromInteger #-}
bisect :: Fractional a => Interval a -> (Interval a, Interval a)
bisect :: Interval a -> (Interval a, Interval a)
bisect Interval a
Empty = (Interval a
forall a. Interval a
Empty,Interval a
forall a. Interval a
Empty)
bisect (I a
a a
b) = (a -> a -> Interval a
forall a. a -> a -> Interval a
I a
a a
m, a -> a -> Interval a
forall a. a -> a -> Interval a
I a
m a
b) where m :: a
m = a
a a -> a -> a
forall a. Num a => a -> a -> a
+ (a
b a -> a -> a
forall a. Num a => a -> a -> a
- a
a) a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
2
{-# INLINE bisect #-}
bisectIntegral :: Integral a => Interval a -> (Interval a, Interval a)
bisectIntegral :: Interval a -> (Interval a, Interval a)
bisectIntegral Interval a
Empty = (Interval a
forall a. Interval a
Empty, Interval a
forall a. Interval a
Empty)
bisectIntegral (I a
a a
b)
| a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
m Bool -> Bool -> Bool
|| a
b a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
m = (a -> a -> Interval a
forall a. a -> a -> Interval a
I a
a a
a, a -> a -> Interval a
forall a. a -> a -> Interval a
I a
b a
b)
| Bool
otherwise = (a -> a -> Interval a
forall a. a -> a -> Interval a
I a
a a
m, a -> a -> Interval a
forall a. a -> a -> Interval a
I a
m a
b)
where m :: a
m = a
a a -> a -> a
forall a. Num a => a -> a -> a
+ (a
b a -> a -> a
forall a. Num a => a -> a -> a
- a
a) a -> a -> a
forall a. Integral a => a -> a -> a
`div` a
2
midpoint :: Fractional a => Interval a -> a
midpoint :: Interval a -> a
midpoint (I a
a a
b) = a
a a -> a -> a
forall a. Num a => a -> a -> a
+ (a
b a -> a -> a
forall a. Num a => a -> a -> a
- a
a) a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
2
midpoint Interval a
Empty = EmptyInterval -> a
forall a e. Exception e => e -> a
Exception.throw EmptyInterval
EmptyInterval
{-# INLINE midpoint #-}
member :: Ord a => a -> Interval a -> Bool
member :: a -> Interval a -> Bool
member a
x (I a
a a
b) = a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
a Bool -> Bool -> Bool
&& a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
b
member a
_ Interval a
Empty = Bool
False
{-# INLINE member #-}
notMember :: Ord a => a -> Interval a -> Bool
notMember :: a -> Interval a -> Bool
notMember a
x Interval a
xs = Bool -> Bool
not (a -> Interval a -> Bool
forall a. Ord a => a -> Interval a -> Bool
member a
x Interval a
xs)
{-# INLINE notMember #-}
elem :: Ord a => a -> Interval a -> Bool
elem :: a -> Interval a -> Bool
elem = a -> Interval a -> Bool
forall a. Ord a => a -> Interval a -> Bool
member
{-# INLINE elem #-}
{-# DEPRECATED elem "Use `member` instead." #-}
notElem :: Ord a => a -> Interval a -> Bool
notElem :: a -> Interval a -> Bool
notElem = a -> Interval a -> Bool
forall a. Ord a => a -> Interval a -> Bool
notMember
{-# INLINE notElem #-}
{-# DEPRECATED notElem "Use `notMember` instead." #-}
instance Real a => Real (Interval a) where
toRational :: Interval a -> Rational
toRational Interval a
Empty = EmptyInterval -> Rational
forall a e. Exception e => e -> a
Exception.throw EmptyInterval
EmptyInterval
toRational (I a
ra a
rb) = Rational
a Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
+ (Rational
b Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
- Rational
a) Rational -> Rational -> Rational
forall a. Fractional a => a -> a -> a
/ Rational
2 where
a :: Rational
a = a -> Rational
forall a. Real a => a -> Rational
toRational a
ra
b :: Rational
b = a -> Rational
forall a. Real a => a -> Rational
toRational a
rb
{-# INLINE toRational #-}
divNonZero :: (Fractional a, Ord a) => Interval a -> Interval a -> Interval a
divNonZero :: Interval a -> Interval a -> Interval a
divNonZero (I a
a a
b) (I a
a' a
b') =
[a] -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [a
a a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
a', a
a a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
b', a
b a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
a', a
b a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
b']
a -> a -> Interval a
forall a. Ord a => a -> a -> Interval a
...
[a] -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum [a
a a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
a', a
a a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
b', a
b a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
a', a
b a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
b']
divNonZero Interval a
_ Interval a
_ = Interval a
forall a. Interval a
Empty
divPositive :: (Fractional a, Ord a) => Interval a -> a -> Interval a
divPositive :: Interval a -> a -> Interval a
divPositive Interval a
Empty a
_ = Interval a
forall a. Interval a
Empty
divPositive x :: Interval a
x@(I a
a a
b) a
y
| a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
0 Bool -> Bool -> Bool
&& a
b a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
0 = Interval a
x
| a
b a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
0 = a
forall a. Fractional a => a
negInfinity a -> a -> Interval a
forall a. Ord a => a -> a -> Interval a
... (a
b a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
y)
| a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
0 = Interval a
forall a. Fractional a => Interval a
whole
| Bool
otherwise = (a
a a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
y) a -> a -> Interval a
forall a. Ord a => a -> a -> Interval a
... a
forall a. Fractional a => a
posInfinity
{-# INLINE divPositive #-}
divNegative :: (Fractional a, Ord a) => Interval a -> a -> Interval a
divNegative :: Interval a -> a -> Interval a
divNegative Interval a
Empty a
_ = Interval a
forall a. Interval a
Empty
divNegative x :: Interval a
x@(I a
a a
b) a
y
| a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
0 Bool -> Bool -> Bool
&& a
b a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
0 = - Interval a
x
| a
b a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
0 = (a
b a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
y) a -> a -> Interval a
forall a. Ord a => a -> a -> Interval a
... a
forall a. Fractional a => a
posInfinity
| a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
0 = Interval a
forall a. Fractional a => Interval a
whole
| Bool
otherwise = a
forall a. Fractional a => a
negInfinity a -> a -> Interval a
forall a. Ord a => a -> a -> Interval a
... (a
a a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
y)
{-# INLINE divNegative #-}
divZero :: (Fractional a, Ord a) => Interval a -> Interval a
divZero :: Interval a -> Interval a
divZero x :: Interval a
x@(I a
a a
b)
| a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
0 Bool -> Bool -> Bool
&& a
b a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
0 = Interval a
x
| Bool
otherwise = Interval a
forall a. Fractional a => Interval a
whole
divZero Interval a
Empty = Interval a
forall a. Interval a
Empty
{-# INLINE divZero #-}
instance (Fractional a, Ord a) => Fractional (Interval a) where
Interval a
_ / :: Interval a -> Interval a -> Interval a
/ Interval a
Empty = Interval a
forall a. Interval a
Empty
Interval a
x / y :: Interval a
y@(I a
a a
b)
| a
0 a -> Interval a -> Bool
forall a. Ord a => a -> Interval a -> Bool
`notElem` Interval a
y = Interval a -> Interval a -> Interval a
forall a.
(Fractional a, Ord a) =>
Interval a -> Interval a -> Interval a
divNonZero Interval a
x Interval a
y
| Bool
iz Bool -> Bool -> Bool
&& Bool
sz = ArithException -> Interval a
forall a e. Exception e => e -> a
Exception.throw ArithException
DivideByZero
| Bool
iz = Interval a -> a -> Interval a
forall a. (Fractional a, Ord a) => Interval a -> a -> Interval a
divPositive Interval a
x a
a
| Bool
sz = Interval a -> a -> Interval a
forall a. (Fractional a, Ord a) => Interval a -> a -> Interval a
divNegative Interval a
x a
b
| Bool
otherwise = Interval a -> Interval a
forall a. (Fractional a, Ord a) => Interval a -> Interval a
divZero Interval a
x
where
iz :: Bool
iz = a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
0
sz :: Bool
sz = a
b a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
0
recip :: Interval a -> Interval a
recip Interval a
Empty = Interval a
forall a. Interval a
Empty
recip (I a
a a
b) = (a -> a -> a) -> (a -> a) -> a -> a -> a
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on a -> a -> a
forall a. Ord a => a -> a -> a
min a -> a
forall a. Fractional a => a -> a
recip a
a a
b a -> a -> Interval a
forall a. Ord a => a -> a -> Interval a
... (a -> a -> a) -> (a -> a) -> a -> a -> a
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on a -> a -> a
forall a. Ord a => a -> a -> a
max a -> a
forall a. Fractional a => a -> a
recip a
a a
b
{-# INLINE recip #-}
fromRational :: Rational -> Interval a
fromRational Rational
r = let r' :: a
r' = Rational -> a
forall a. Fractional a => Rational -> a
fromRational Rational
r in a -> a -> Interval a
forall a. a -> a -> Interval a
I a
r' a
r'
{-# INLINE fromRational #-}
instance RealFrac a => RealFrac (Interval a) where
properFraction :: Interval a -> (b, Interval a)
properFraction Interval a
x = (b
b, Interval a
x Interval a -> Interval a -> Interval a
forall a. Num a => a -> a -> a
- b -> Interval a
forall a b. (Integral a, Num b) => a -> b
fromIntegral b
b)
where
b :: b
b = a -> b
forall a b. (RealFrac a, Integral b) => a -> b
truncate (Interval a -> a
forall a. Fractional a => Interval a -> a
midpoint Interval a
x)
{-# INLINE properFraction #-}
ceiling :: Interval a -> b
ceiling Interval a
x = a -> b
forall a b. (RealFrac a, Integral b) => a -> b
ceiling (Interval a -> a
forall a. Interval a -> a
sup Interval a
x)
{-# INLINE ceiling #-}
floor :: Interval a -> b
floor Interval a
x = a -> b
forall a b. (RealFrac a, Integral b) => a -> b
floor (Interval a -> a
forall a. Interval a -> a
inf Interval a
x)
{-# INLINE floor #-}
round :: Interval a -> b
round Interval a
x = a -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (Interval a -> a
forall a. Fractional a => Interval a -> a
midpoint Interval a
x)
{-# INLINE round #-}
truncate :: Interval a -> b
truncate Interval a
x = a -> b
forall a b. (RealFrac a, Integral b) => a -> b
truncate (Interval a -> a
forall a. Fractional a => Interval a -> a
midpoint Interval a
x)
{-# INLINE truncate #-}
instance (RealFloat a, Ord a) => Floating (Interval a) where
pi :: Interval a
pi = a -> Interval a
forall a. a -> Interval a
singleton a
forall a. Floating a => a
pi
{-# INLINE pi #-}
exp :: Interval a -> Interval a
exp = (a -> a) -> Interval a -> Interval a
forall a b. (a -> b) -> Interval a -> Interval b
increasing a -> a
forall a. Floating a => a -> a
exp
{-# INLINE exp #-}
log :: Interval a -> Interval a
log (I a
a a
b) = (if a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
0 then a -> a
forall a. Floating a => a -> a
log a
a else a
forall a. Fractional a => a
negInfinity) a -> a -> Interval a
forall a. Ord a => a -> a -> Interval a
... a -> a
forall a. Floating a => a -> a
log a
b
log Interval a
Empty = Interval a
forall a. Interval a
Empty
{-# INLINE log #-}
cos :: Interval a -> Interval a
cos Interval a
Empty = Interval a
forall a. Interval a
Empty
cos Interval a
x
| Interval a -> a
forall a. Num a => Interval a -> a
width Interval a
t a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
forall a. Floating a => a
pi = (-a
1) a -> a -> Interval a
forall a. Ord a => a -> a -> Interval a
... a
1
| Interval a -> a
forall a. Interval a -> a
inf Interval a
t a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
forall a. Floating a => a
pi = - Interval a -> Interval a
forall a. Floating a => a -> a
cos (Interval a
t Interval a -> Interval a -> Interval a
forall a. Num a => a -> a -> a
- Interval a
forall a. Floating a => a
pi)
| Interval a -> a
forall a. Interval a -> a
sup Interval a
t a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
forall a. Floating a => a
pi = (a -> a) -> Interval a -> Interval a
forall a b. (a -> b) -> Interval a -> Interval b
decreasing a -> a
forall a. Floating a => a -> a
cos Interval a
t
| Interval a -> a
forall a. Interval a -> a
sup Interval a
t a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
2 a -> a -> a
forall a. Num a => a -> a -> a
* a
forall a. Floating a => a
pi = (-a
1) a -> a -> Interval a
forall a. Ord a => a -> a -> Interval a
... a -> a
forall a. Floating a => a -> a
cos ((a
forall a. Floating a => a
pi a -> a -> a
forall a. Num a => a -> a -> a
* a
2 a -> a -> a
forall a. Num a => a -> a -> a
- Interval a -> a
forall a. Interval a -> a
sup Interval a
t) a -> a -> a
forall a. Ord a => a -> a -> a
`min` Interval a -> a
forall a. Interval a -> a
inf Interval a
t)
| Bool
otherwise = (-a
1) a -> a -> Interval a
forall a. Ord a => a -> a -> Interval a
... a
1
where
t :: Interval a
t = Interval a -> Interval a -> Interval a
forall a. RealFrac a => a -> a -> a
fmod Interval a
x (Interval a
forall a. Floating a => a
pi Interval a -> Interval a -> Interval a
forall a. Num a => a -> a -> a
* Interval a
2)
{-# INLINE cos #-}
sin :: Interval a -> Interval a
sin Interval a
Empty = Interval a
forall a. Interval a
Empty
sin Interval a
x = Interval a -> Interval a
forall a. Floating a => a -> a
cos (Interval a
x Interval a -> Interval a -> Interval a
forall a. Num a => a -> a -> a
- Interval a
forall a. Floating a => a
pi Interval a -> Interval a -> Interval a
forall a. Fractional a => a -> a -> a
/ Interval a
2)
{-# INLINE sin #-}
tan :: Interval a -> Interval a
tan Interval a
Empty = Interval a
forall a. Interval a
Empty
tan Interval a
x
| Interval a -> a
forall a. Interval a -> a
inf Interval a
t' a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= - a
forall a. Floating a => a
pi a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
2 Bool -> Bool -> Bool
|| Interval a -> a
forall a. Interval a -> a
sup Interval a
t' a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
forall a. Floating a => a
pi a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
2 = Interval a
forall a. Fractional a => Interval a
whole
| Bool
otherwise = (a -> a) -> Interval a -> Interval a
forall a b. (a -> b) -> Interval a -> Interval b
increasing a -> a
forall a. Floating a => a -> a
tan Interval a
x
where
t :: Interval a
t = Interval a
x Interval a -> Interval a -> Interval a
forall a. RealFrac a => a -> a -> a
`fmod` Interval a
forall a. Floating a => a
pi
t' :: Interval a
t' | Interval a
t Interval a -> Interval a -> Bool
forall a. Ord a => a -> a -> Bool
>= Interval a
forall a. Floating a => a
pi Interval a -> Interval a -> Interval a
forall a. Fractional a => a -> a -> a
/ Interval a
2 = Interval a
t Interval a -> Interval a -> Interval a
forall a. Num a => a -> a -> a
- Interval a
forall a. Floating a => a
pi
| Bool
otherwise = Interval a
t
{-# INLINE tan #-}
asin :: Interval a -> Interval a
asin Interval a
Empty = Interval a
forall a. Interval a
Empty
asin (I a
a a
b)
| a
b a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< -a
1 Bool -> Bool -> Bool
|| a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
1 = Interval a
forall a. Interval a
Empty
| Bool
otherwise =
(if a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= -a
1 then -a
halfPi else a -> a
forall a. Floating a => a -> a
asin a
a)
a -> a -> Interval a
forall a. Ord a => a -> a -> Interval a
...
(if a
b a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
1 then a
halfPi else a -> a
forall a. Floating a => a -> a
asin a
b)
where
halfPi :: a
halfPi = a
forall a. Floating a => a
pi a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
2
{-# INLINE asin #-}
acos :: Interval a -> Interval a
acos Interval a
Empty = Interval a
forall a. Interval a
Empty
acos (I a
a a
b)
| a
b a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< -a
1 Bool -> Bool -> Bool
|| a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
1 = Interval a
forall a. Interval a
Empty
| Bool
otherwise =
(if a
b a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
1 then a
0 else a -> a
forall a. Floating a => a -> a
acos a
b)
a -> a -> Interval a
forall a. Ord a => a -> a -> Interval a
...
(if a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< -a
1 then a
forall a. Floating a => a
pi else a -> a
forall a. Floating a => a -> a
acos a
a)
{-# INLINE acos #-}
atan :: Interval a -> Interval a
atan = (a -> a) -> Interval a -> Interval a
forall a b. (a -> b) -> Interval a -> Interval b
increasing a -> a
forall a. Floating a => a -> a
atan
{-# INLINE atan #-}
sinh :: Interval a -> Interval a
sinh = (a -> a) -> Interval a -> Interval a
forall a b. (a -> b) -> Interval a -> Interval b
increasing a -> a
forall a. Floating a => a -> a
sinh
{-# INLINE sinh #-}
cosh :: Interval a -> Interval a
cosh Interval a
Empty = Interval a
forall a. Interval a
Empty
cosh x :: Interval a
x@(I a
a a
b)
| a
b a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
0 = (a -> a) -> Interval a -> Interval a
forall a b. (a -> b) -> Interval a -> Interval b
decreasing a -> a
forall a. Floating a => a -> a
cosh Interval a
x
| a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
0 = (a -> a) -> Interval a -> Interval a
forall a b. (a -> b) -> Interval a -> Interval b
increasing a -> a
forall a. Floating a => a -> a
cosh Interval a
x
| Bool
otherwise = a -> a -> Interval a
forall a. a -> a -> Interval a
I a
0 (a -> Interval a) -> a -> Interval a
forall a b. (a -> b) -> a -> b
$ a -> a
forall a. Floating a => a -> a
cosh (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$ if - a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
b
then a
a
else a
b
{-# INLINE cosh #-}
tanh :: Interval a -> Interval a
tanh = (a -> a) -> Interval a -> Interval a
forall a b. (a -> b) -> Interval a -> Interval b
increasing a -> a
forall a. Floating a => a -> a
tanh
{-# INLINE tanh #-}
asinh :: Interval a -> Interval a
asinh = (a -> a) -> Interval a -> Interval a
forall a b. (a -> b) -> Interval a -> Interval b
increasing a -> a
forall a. Floating a => a -> a
asinh
{-# INLINE asinh #-}
acosh :: Interval a -> Interval a
acosh Interval a
Empty = Interval a
forall a. Interval a
Empty
acosh (I a
a a
b)
| a
b a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
1 = Interval a
forall a. Interval a
Empty
| Bool
otherwise = a -> a -> Interval a
forall a. a -> a -> Interval a
I a
lo (a -> Interval a) -> a -> Interval a
forall a b. (a -> b) -> a -> b
$ a -> a
forall a. Floating a => a -> a
acosh a
b
where lo :: a
lo | a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
1 = a
0
| Bool
otherwise = a -> a
forall a. Floating a => a -> a
acosh a
a
{-# INLINE acosh #-}
atanh :: Interval a -> Interval a
atanh Interval a
Empty = Interval a
forall a. Interval a
Empty
atanh (I a
a a
b)
| a
b a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< -a
1 Bool -> Bool -> Bool
|| a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
1 = Interval a
forall a. Interval a
Empty
| Bool
otherwise =
(if a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= - a
1 then a
forall a. Fractional a => a
negInfinity else a -> a
forall a. Floating a => a -> a
atanh a
a)
a -> a -> Interval a
forall a. Ord a => a -> a -> Interval a
...
(if a
b a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
1 then a
forall a. Fractional a => a
posInfinity else a -> a
forall a. Floating a => a -> a
atanh a
b)
{-# INLINE atanh #-}
increasing :: (a -> b) -> Interval a -> Interval b
increasing :: (a -> b) -> Interval a -> Interval b
increasing a -> b
f (I a
a a
b) = b -> b -> Interval b
forall a. a -> a -> Interval a
I (a -> b
f a
a) (a -> b
f a
b)
increasing a -> b
_ Interval a
Empty = Interval b
forall a. Interval a
Empty
decreasing :: (a -> b) -> Interval a -> Interval b
decreasing :: (a -> b) -> Interval a -> Interval b
decreasing a -> b
f (I a
a a
b) = b -> b -> Interval b
forall a. a -> a -> Interval a
I (a -> b
f a
b) (a -> b
f a
a)
decreasing a -> b
_ Interval a
Empty = Interval b
forall a. Interval a
Empty
instance RealFloat a => RealFloat (Interval a) where
floatRadix :: Interval a -> Integer
floatRadix = a -> Integer
forall a. RealFloat a => a -> Integer
floatRadix (a -> Integer) -> (Interval a -> a) -> Interval a -> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Interval a -> a
forall a. Fractional a => Interval a -> a
midpoint
floatDigits :: Interval a -> Int
floatDigits = a -> Int
forall a. RealFloat a => a -> Int
floatDigits (a -> Int) -> (Interval a -> a) -> Interval a -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Interval a -> a
forall a. Fractional a => Interval a -> a
midpoint
floatRange :: Interval a -> (Int, Int)
floatRange = a -> (Int, Int)
forall a. RealFloat a => a -> (Int, Int)
floatRange (a -> (Int, Int)) -> (Interval a -> a) -> Interval a -> (Int, Int)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Interval a -> a
forall a. Fractional a => Interval a -> a
midpoint
decodeFloat :: Interval a -> (Integer, Int)
decodeFloat = a -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat (a -> (Integer, Int))
-> (Interval a -> a) -> Interval a -> (Integer, Int)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Interval a -> a
forall a. Fractional a => Interval a -> a
midpoint
encodeFloat :: Integer -> Int -> Interval a
encodeFloat Integer
m Int
e = a -> Interval a
forall a. a -> Interval a
singleton (Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
m Int
e)
exponent :: Interval a -> Int
exponent = a -> Int
forall a. RealFloat a => a -> Int
exponent (a -> Int) -> (Interval a -> a) -> Interval a -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Interval a -> a
forall a. Fractional a => Interval a -> a
midpoint
significand :: Interval a -> Interval a
significand Interval a
x = a -> a -> a
forall a. Ord a => a -> a -> a
min a
a a
b a -> a -> Interval a
forall a. Ord a => a -> a -> Interval a
... a -> a -> a
forall a. Ord a => a -> a -> a
max a
a a
b
where
(Integer
_ ,Int
em) = a -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat (Interval a -> a
forall a. Fractional a => Interval a -> a
midpoint Interval a
x)
(Integer
mi,Int
ei) = a -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat (Interval a -> a
forall a. Interval a -> a
inf Interval a
x)
(Integer
ms,Int
es) = a -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat (Interval a -> a
forall a. Interval a -> a
sup Interval a
x)
a :: a
a = Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
mi (Int
ei Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
em Int -> Int -> Int
forall a. Num a => a -> a -> a
- Interval a -> Int
forall a. RealFloat a => a -> Int
floatDigits Interval a
x)
b :: a
b = Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
ms (Int
es Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
em Int -> Int -> Int
forall a. Num a => a -> a -> a
- Interval a -> Int
forall a. RealFloat a => a -> Int
floatDigits Interval a
x)
scaleFloat :: Int -> Interval a -> Interval a
scaleFloat Int
_ Interval a
Empty = Interval a
forall a. Interval a
Empty
scaleFloat Int
n (I a
a a
b) = a -> a -> Interval a
forall a. a -> a -> Interval a
I (Int -> a -> a
forall a. RealFloat a => Int -> a -> a
scaleFloat Int
n a
a) (Int -> a -> a
forall a. RealFloat a => Int -> a -> a
scaleFloat Int
n a
b)
isNaN :: Interval a -> Bool
isNaN (I a
a a
b) = a -> Bool
forall a. RealFloat a => a -> Bool
isNaN a
a Bool -> Bool -> Bool
|| a -> Bool
forall a. RealFloat a => a -> Bool
isNaN a
b
isNaN Interval a
Empty = Bool
True
isInfinite :: Interval a -> Bool
isInfinite (I a
a a
b) = a -> Bool
forall a. RealFloat a => a -> Bool
isInfinite a
a Bool -> Bool -> Bool
|| a -> Bool
forall a. RealFloat a => a -> Bool
isInfinite a
b
isInfinite Interval a
Empty = Bool
False
isDenormalized :: Interval a -> Bool
isDenormalized (I a
a a
b) = a -> Bool
forall a. RealFloat a => a -> Bool
isDenormalized a
a Bool -> Bool -> Bool
|| a -> Bool
forall a. RealFloat a => a -> Bool
isDenormalized a
b
isDenormalized Interval a
Empty = Bool
False
isNegativeZero :: Interval a -> Bool
isNegativeZero (I a
a a
b) = Bool -> Bool
not (a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
0)
Bool -> Bool -> Bool
&& Bool -> Bool
not (a
b a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
0)
Bool -> Bool -> Bool
&& ( (a
b a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
0 Bool -> Bool -> Bool
&& (a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
0 Bool -> Bool -> Bool
|| a -> Bool
forall a. RealFloat a => a -> Bool
isNegativeZero a
a))
Bool -> Bool -> Bool
|| (a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
0 Bool -> Bool -> Bool
&& a -> Bool
forall a. RealFloat a => a -> Bool
isNegativeZero a
a)
Bool -> Bool -> Bool
|| (a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
0 Bool -> Bool -> Bool
&& a
b a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
0))
isNegativeZero Interval a
Empty = Bool
False
isIEEE :: Interval a -> Bool
isIEEE Interval a
_ = Bool
False
atan2 :: Interval a -> Interval a -> Interval a
atan2 = String -> Interval a -> Interval a -> Interval a
forall a. HasCallStack => String -> a
error String
"unimplemented"
intersection :: Ord a => Interval a -> Interval a -> Interval a
intersection :: Interval a -> Interval a -> Interval a
intersection x :: Interval a
x@(I a
a a
b) y :: Interval a
y@(I a
a' a
b')
| Interval a
x Interval a -> Interval a -> Bool
forall a. Ord a => Interval a -> Interval a -> Bool
/=! Interval a
y = Interval a
forall a. Interval a
Empty
| Bool
otherwise = a -> a -> Interval a
forall a. a -> a -> Interval a
I (a -> a -> a
forall a. Ord a => a -> a -> a
max a
a a
a') (a -> a -> a
forall a. Ord a => a -> a -> a
min a
b a
b')
intersection Interval a
_ Interval a
_ = Interval a
forall a. Interval a
Empty
{-# INLINE intersection #-}
hull :: Ord a => Interval a -> Interval a -> Interval a
hull :: Interval a -> Interval a -> Interval a
hull (I a
a a
b) (I a
a' a
b') = a -> a -> Interval a
forall a. a -> a -> Interval a
I (a -> a -> a
forall a. Ord a => a -> a -> a
min a
a a
a') (a -> a -> a
forall a. Ord a => a -> a -> a
max a
b a
b')
hull Interval a
Empty Interval a
x = Interval a
x
hull Interval a
x Interval a
Empty = Interval a
x
{-# INLINE hull #-}
(<!) :: Ord a => Interval a -> Interval a -> Bool
Interval a
Empty <! :: Interval a -> Interval a -> Bool
<! Interval a
_ = Bool
True
Interval a
_ <! Interval a
Empty = Bool
True
I a
_ a
bx <! I a
ay a
_ = a
bx a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
ay
{-# INLINE (<!) #-}
(<=!) :: Ord a => Interval a -> Interval a -> Bool
Interval a
Empty <=! :: Interval a -> Interval a -> Bool
<=! Interval a
_ = Bool
True
Interval a
_ <=! Interval a
Empty = Bool
True
I a
_ a
bx <=! I a
ay a
_ = a
bx a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
ay
{-# INLINE (<=!) #-}
(==!) :: Eq a => Interval a -> Interval a -> Bool
Interval a
Empty ==! :: Interval a -> Interval a -> Bool
==! Interval a
_ = Bool
True
Interval a
_ ==! Interval a
Empty = Bool
True
I a
ax a
bx ==! I a
ay a
by = a
bx a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
ay Bool -> Bool -> Bool
&& a
ax a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
by
{-# INLINE (==!) #-}
(/=!) :: Ord a => Interval a -> Interval a -> Bool
Interval a
Empty /=! :: Interval a -> Interval a -> Bool
/=! Interval a
_ = Bool
True
Interval a
_ /=! Interval a
Empty = Bool
True
I a
ax a
bx /=! I a
ay a
by = a
bx a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
ay Bool -> Bool -> Bool
|| a
ax a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
by
{-# INLINE (/=!) #-}
(>!) :: Ord a => Interval a -> Interval a -> Bool
Interval a
Empty >! :: Interval a -> Interval a -> Bool
>! Interval a
_ = Bool
True
Interval a
_ >! Interval a
Empty = Bool
True
I a
ax a
_ >! I a
_ a
by = a
ax a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
by
{-# INLINE (>!) #-}
(>=!) :: Ord a => Interval a -> Interval a -> Bool
Interval a
Empty >=! :: Interval a -> Interval a -> Bool
>=! Interval a
_ = Bool
True
Interval a
_ >=! Interval a
Empty = Bool
True
I a
ax a
_ >=! I a
_ a
by = a
ax a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
by
{-# INLINE (>=!) #-}
certainly :: Ord a => (forall b. Ord b => b -> b -> Bool) -> Interval a -> Interval a -> Bool
certainly :: (forall a. Ord a => a -> a -> Bool)
-> Interval a -> Interval a -> Bool
certainly forall a. Ord a => a -> a -> Bool
cmp Interval a
l Interval a
r
| Bool
lt Bool -> Bool -> Bool
&& Bool
eq Bool -> Bool -> Bool
&& Bool
gt = Bool
True
| Bool
lt Bool -> Bool -> Bool
&& Bool
eq = Interval a
l Interval a -> Interval a -> Bool
forall a. Ord a => Interval a -> Interval a -> Bool
<=! Interval a
r
| Bool
lt Bool -> Bool -> Bool
&& Bool
gt = Interval a
l Interval a -> Interval a -> Bool
forall a. Ord a => Interval a -> Interval a -> Bool
/=! Interval a
r
| Bool
lt = Interval a
l Interval a -> Interval a -> Bool
forall a. Ord a => Interval a -> Interval a -> Bool
<! Interval a
r
| Bool
eq Bool -> Bool -> Bool
&& Bool
gt = Interval a
l Interval a -> Interval a -> Bool
forall a. Ord a => Interval a -> Interval a -> Bool
>=! Interval a
r
| Bool
eq = Interval a
l Interval a -> Interval a -> Bool
forall a. Eq a => Interval a -> Interval a -> Bool
==! Interval a
r
| Bool
gt = Interval a
l Interval a -> Interval a -> Bool
forall a. Ord a => Interval a -> Interval a -> Bool
>! Interval a
r
| Bool
otherwise = Bool
False
where
lt :: Bool
lt = Bool -> Bool -> Bool
forall a. Ord a => a -> a -> Bool
cmp Bool
False Bool
True
eq :: Bool
eq = Bool -> Bool -> Bool
forall a. Ord a => a -> a -> Bool
cmp Bool
True Bool
True
gt :: Bool
gt = Bool -> Bool -> Bool
forall a. Ord a => a -> a -> Bool
cmp Bool
True Bool
False
{-# INLINE certainly #-}
contains :: Ord a => Interval a -> Interval a -> Bool
contains :: Interval a -> Interval a -> Bool
contains Interval a
_ Interval a
Empty = Bool
True
contains (I a
ax a
bx) (I a
ay a
by) = a
ax a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
ay Bool -> Bool -> Bool
&& a
by a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
bx
contains Interval a
Empty I{} = Bool
False
{-# INLINE contains #-}
isSubsetOf :: Ord a => Interval a -> Interval a -> Bool
isSubsetOf :: Interval a -> Interval a -> Bool
isSubsetOf = (Interval a -> Interval a -> Bool)
-> Interval a -> Interval a -> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip Interval a -> Interval a -> Bool
forall a. Ord a => Interval a -> Interval a -> Bool
contains
{-# INLINE isSubsetOf #-}
(<?) :: Ord a => Interval a -> Interval a -> Bool
Interval a
Empty <? :: Interval a -> Interval a -> Bool
<? Interval a
_ = Bool
False
Interval a
_ <? Interval a
Empty = Bool
False
I a
ax a
_ <? I a
_ a
by = a
ax a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
by
{-# INLINE (<?) #-}
(<=?) :: Ord a => Interval a -> Interval a -> Bool
Interval a
Empty <=? :: Interval a -> Interval a -> Bool
<=? Interval a
_ = Bool
False
Interval a
_ <=? Interval a
Empty = Bool
False
I a
ax a
_ <=? I a
_ a
by = a
ax a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
by
{-# INLINE (<=?) #-}
(==?) :: Ord a => Interval a -> Interval a -> Bool
I a
ax a
bx ==? :: Interval a -> Interval a -> Bool
==? I a
ay a
by = a
ax a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
by Bool -> Bool -> Bool
&& a
bx a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
ay
Interval a
_ ==? Interval a
_ = Bool
False
{-# INLINE (==?) #-}
(/=?) :: Eq a => Interval a -> Interval a -> Bool
I a
ax a
bx /=? :: Interval a -> Interval a -> Bool
/=? I a
ay a
by = a
ax a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
by Bool -> Bool -> Bool
|| a
bx a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
ay
Interval a
_ /=? Interval a
_ = Bool
False
{-# INLINE (/=?) #-}
(>?) :: Ord a => Interval a -> Interval a -> Bool
I a
_ a
bx >? :: Interval a -> Interval a -> Bool
>? I a
ay a
_ = a
bx a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
ay
Interval a
_ >? Interval a
_ = Bool
False
{-# INLINE (>?) #-}
(>=?) :: Ord a => Interval a -> Interval a -> Bool
I a
_ a
bx >=? :: Interval a -> Interval a -> Bool
>=? I a
ay a
_ = a
bx a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
ay
Interval a
_ >=? Interval a
_ = Bool
False
{-# INLINE (>=?) #-}
possibly :: Ord a => (forall b. Ord b => b -> b -> Bool) -> Interval a -> Interval a -> Bool
possibly :: (forall a. Ord a => a -> a -> Bool)
-> Interval a -> Interval a -> Bool
possibly forall a. Ord a => a -> a -> Bool
cmp Interval a
l Interval a
r
| Bool
lt Bool -> Bool -> Bool
&& Bool
eq Bool -> Bool -> Bool
&& Bool
gt = Bool
True
| Bool
lt Bool -> Bool -> Bool
&& Bool
eq = Interval a
l Interval a -> Interval a -> Bool
forall a. Ord a => Interval a -> Interval a -> Bool
<=? Interval a
r
| Bool
lt Bool -> Bool -> Bool
&& Bool
gt = Interval a
l Interval a -> Interval a -> Bool
forall a. Eq a => Interval a -> Interval a -> Bool
/=? Interval a
r
| Bool
lt = Interval a
l Interval a -> Interval a -> Bool
forall a. Ord a => Interval a -> Interval a -> Bool
<? Interval a
r
| Bool
eq Bool -> Bool -> Bool
&& Bool
gt = Interval a
l Interval a -> Interval a -> Bool
forall a. Ord a => Interval a -> Interval a -> Bool
>=? Interval a
r
| Bool
eq = Interval a
l Interval a -> Interval a -> Bool
forall a. Ord a => Interval a -> Interval a -> Bool
==? Interval a
r
| Bool
gt = Interval a
l Interval a -> Interval a -> Bool
forall a. Ord a => Interval a -> Interval a -> Bool
>? Interval a
r
| Bool
otherwise = Bool
False
where
lt :: Bool
lt = Ordering -> Ordering -> Bool
forall a. Ord a => a -> a -> Bool
cmp Ordering
LT Ordering
EQ
eq :: Bool
eq = Ordering -> Ordering -> Bool
forall a. Ord a => a -> a -> Bool
cmp Ordering
EQ Ordering
EQ
gt :: Bool
gt = Ordering -> Ordering -> Bool
forall a. Ord a => a -> a -> Bool
cmp Ordering
GT Ordering
EQ
{-# INLINE possibly #-}
idouble :: Interval Double -> Interval Double
idouble :: Interval Double -> Interval Double
idouble = Interval Double -> Interval Double
forall a. a -> a
id
ifloat :: Interval Float -> Interval Float
ifloat :: Interval Float -> Interval Float
ifloat = Interval Float -> Interval Float
forall a. a -> a
id
default (Integer,Double)
iquot :: Integral a => Interval a -> Interval a -> Interval a
iquot :: Interval a -> Interval a -> Interval a
iquot Interval a
i Interval a
j = case (Interval a
i,Interval a
j) of
(Interval a
Empty,Interval a
_) -> Interval a
forall a. Interval a
Empty
(Interval a
_,Interval a
Empty) -> Interval a
forall a. Interval a
Empty
(I a
l a
u , I a
l' a
u') ->
if a
l' a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
0 Bool -> Bool -> Bool
&& a
0 a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
u' then ArithException -> Interval a
forall a e. Exception e => e -> a
throw ArithException
DivideByZero else a -> a -> Interval a
forall a. a -> a -> Interval a
I
([a] -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [a
a a -> a -> a
forall a. Integral a => a -> a -> a
`quot` a
b | a
a <- [a
l,a
u], a
b <- [a
l',a
u']])
([a] -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum [a
a a -> a -> a
forall a. Integral a => a -> a -> a
`quot` a
b | a
a <- [a
l,a
u], a
b <- [a
l',a
u']])
irem :: Integral a => Interval a -> Interval a -> Interval a
irem :: Interval a -> Interval a -> Interval a
irem Interval a
i Interval a
j = case (Interval a
i,Interval a
j) of
(Interval a
Empty,Interval a
_) -> Interval a
forall a. Interval a
Empty
(Interval a
_,Interval a
Empty) -> Interval a
forall a. Interval a
Empty
(I a
l a
u , I a
l' a
u') ->
if a
l' a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
0 Bool -> Bool -> Bool
&& a
0 a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
u' then ArithException -> Interval a
forall a e. Exception e => e -> a
throw ArithException
DivideByZero else a -> a -> Interval a
forall a. a -> a -> Interval a
I
([a] -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [a
0, a -> a
forall a. Num a => a -> a
signum a
l a -> a -> a
forall a. Num a => a -> a -> a
* (a -> a
forall a. Num a => a -> a
abs a
u' a -> a -> a
forall a. Num a => a -> a -> a
- a
1), a -> a
forall a. Num a => a -> a
signum a
l a -> a -> a
forall a. Num a => a -> a -> a
* (a -> a
forall a. Num a => a -> a
abs a
l' a -> a -> a
forall a. Num a => a -> a -> a
- a
1)])
([a] -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum [a
0, a -> a
forall a. Num a => a -> a
signum a
u a -> a -> a
forall a. Num a => a -> a -> a
* (a -> a
forall a. Num a => a -> a
abs a
u' a -> a -> a
forall a. Num a => a -> a -> a
- a
1), a -> a
forall a. Num a => a -> a
signum a
u a -> a -> a
forall a. Num a => a -> a -> a
* (a -> a
forall a. Num a => a -> a
abs a
l' a -> a -> a
forall a. Num a => a -> a -> a
- a
1)])
idiv :: Integral a => Interval a -> Interval a -> Interval a
idiv :: Interval a -> Interval a -> Interval a
idiv Interval a
i Interval a
j = case (Interval a
i,Interval a
j) of
(Interval a
Empty,Interval a
_) -> Interval a
forall a. Interval a
Empty
(Interval a
_,Interval a
Empty) -> Interval a
forall a. Interval a
Empty
(I a
l a
u , I a
l' a
u') ->
if a
l' a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
0 Bool -> Bool -> Bool
&& a
0 a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
u' then ArithException -> Interval a
forall a e. Exception e => e -> a
throw ArithException
DivideByZero else a -> a -> Interval a
forall a. a -> a -> Interval a
I
(a -> a -> a
forall a. Ord a => a -> a -> a
min (a
l a -> a -> a
forall a. Integral a => a -> a -> a
`Prelude.div` a -> a -> a
forall a. Ord a => a -> a -> a
max a
1 a
l') (a
u a -> a -> a
forall a. Integral a => a -> a -> a
`Prelude.div` a -> a -> a
forall a. Ord a => a -> a -> a
min (-a
1) a
u'))
(a -> a -> a
forall a. Ord a => a -> a -> a
max (a
u a -> a -> a
forall a. Integral a => a -> a -> a
`Prelude.div` a -> a -> a
forall a. Ord a => a -> a -> a
max a
1 a
l') (a
l a -> a -> a
forall a. Integral a => a -> a -> a
`Prelude.div` a -> a -> a
forall a. Ord a => a -> a -> a
min (-a
1) a
u'))
imod :: Integral a => Interval a -> Interval a -> Interval a
imod :: Interval a -> Interval a -> Interval a
imod Interval a
i Interval a
j = case (Interval a
i,Interval a
j) of
(Interval a
Empty,Interval a
_) -> Interval a
forall a. Interval a
Empty
(Interval a
_,Interval a
Empty) -> Interval a
forall a. Interval a
Empty
(Interval a
_ , I a
l' a
u') ->
if a
l' a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
0 Bool -> Bool -> Bool
&& a
0 a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
u' then ArithException -> Interval a
forall a e. Exception e => e -> a
throw ArithException
DivideByZero else
a -> a -> Interval a
forall a. a -> a -> Interval a
I (a -> a -> a
forall a. Ord a => a -> a -> a
min (a
l'a -> a -> a
forall a. Num a => a -> a -> a
+a
1) a
0) (a -> a -> a
forall a. Ord a => a -> a -> a
max a
0 (a
u'a -> a -> a
forall a. Num a => a -> a -> a
-a
1))