{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Numeric.Rounded.Hardware.Interval.NonEmpty
( Interval(..)
, increasing
, maxI
, minI
, powInt
, null
, inf
, sup
, width
, hull
) where
import Control.DeepSeq (NFData (..))
import Control.Monad
import Control.Monad.ST
import qualified Data.Array.Base as A
import Data.Coerce
import Data.Ix
import Data.Primitive
import qualified Data.Vector.Generic as VG
import qualified Data.Vector.Generic.Mutable as VGM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import GHC.Float (log1p, expm1)
import GHC.Generics (Generic)
import Numeric.Rounded.Hardware.Internal
import qualified Numeric.Rounded.Hardware.Interval.Class as C
import qualified Numeric.Rounded.Hardware.Interval.ElementaryFunctions as C
import Prelude hiding (null)
data Interval a
= I !(Rounded 'TowardNegInf a) !(Rounded 'TowardInf a)
deriving (Int -> Interval a -> ShowS
forall a. Show a => Int -> Interval a -> ShowS
forall a. Show a => [Interval a] -> ShowS
forall a. Show a => Interval a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Interval a] -> ShowS
$cshowList :: forall a. Show a => [Interval a] -> ShowS
show :: Interval a -> String
$cshow :: forall a. Show a => Interval a -> String
showsPrec :: Int -> Interval a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Interval a -> ShowS
Show,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)
instance NFData a => NFData (Interval a)
increasing :: (forall r. Rounding r => Rounded r a -> Rounded r a) -> Interval a -> Interval a
increasing :: forall a.
(forall (r :: RoundingMode).
Rounding r =>
Rounded r a -> Rounded r a)
-> Interval a -> Interval a
increasing forall (r :: RoundingMode).
Rounding r =>
Rounded r a -> Rounded r a
f (I Rounded 'TowardNegInf a
a Rounded 'TowardInf a
b) = forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I (forall (r :: RoundingMode).
Rounding r =>
Rounded r a -> Rounded r a
f Rounded 'TowardNegInf a
a) (forall (r :: RoundingMode).
Rounding r =>
Rounded r a -> Rounded r a
f Rounded 'TowardInf a
b)
negateI :: (Num a, RoundedRing a) => Interval a -> Interval a
negateI :: forall a. (Num a, RoundedRing a) => Interval a -> Interval a
negateI (I Rounded 'TowardNegInf a
a Rounded 'TowardInf a
b) = forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I (forall a. Num a => a -> a
negate (coerce :: forall a b. Coercible a b => a -> b
coerce Rounded 'TowardInf a
b)) (forall a. Num a => a -> a
negate (coerce :: forall a b. Coercible a b => a -> b
coerce Rounded 'TowardNegInf a
a))
{-# INLINE [0] negateI #-}
addI, subI, mulI :: (Num a, RoundedRing a) => Interval a -> Interval a -> Interval a
I Rounded 'TowardNegInf a
a Rounded 'TowardInf a
b addI :: forall a.
(Num a, RoundedRing a) =>
Interval a -> Interval a -> Interval a
`addI` I Rounded 'TowardNegInf a
a' Rounded 'TowardInf a
b' = case forall a.
RoundedRing a =>
Rounded 'TowardNegInf a
-> Rounded 'TowardInf a
-> Rounded 'TowardNegInf a
-> Rounded 'TowardInf a
-> (Rounded 'TowardNegInf a, Rounded 'TowardInf a)
intervalAdd Rounded 'TowardNegInf a
a Rounded 'TowardInf a
b Rounded 'TowardNegInf a
a' Rounded 'TowardInf a
b' of
(Rounded 'TowardNegInf a
a'', Rounded 'TowardInf a
b'') -> forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I Rounded 'TowardNegInf a
a'' Rounded 'TowardInf a
b''
I Rounded 'TowardNegInf a
a Rounded 'TowardInf a
b subI :: forall a.
(Num a, RoundedRing a) =>
Interval a -> Interval a -> Interval a
`subI` I Rounded 'TowardNegInf a
a' Rounded 'TowardInf a
b' = case forall a.
RoundedRing a =>
Rounded 'TowardNegInf a
-> Rounded 'TowardInf a
-> Rounded 'TowardNegInf a
-> Rounded 'TowardInf a
-> (Rounded 'TowardNegInf a, Rounded 'TowardInf a)
intervalSub Rounded 'TowardNegInf a
a Rounded 'TowardInf a
b Rounded 'TowardNegInf a
a' Rounded 'TowardInf a
b' of
(Rounded 'TowardNegInf a
a'', Rounded 'TowardInf a
b'') -> forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I Rounded 'TowardNegInf a
a'' Rounded 'TowardInf a
b''
I Rounded 'TowardNegInf a
a Rounded 'TowardInf a
b mulI :: forall a.
(Num a, RoundedRing a) =>
Interval a -> Interval a -> Interval a
`mulI` I Rounded 'TowardNegInf a
a' Rounded 'TowardInf a
b' = case forall a.
RoundedRing a =>
Rounded 'TowardNegInf a
-> Rounded 'TowardInf a
-> Rounded 'TowardNegInf a
-> Rounded 'TowardInf a
-> (Rounded 'TowardNegInf a, Rounded 'TowardInf a)
intervalMul Rounded 'TowardNegInf a
a Rounded 'TowardInf a
b Rounded 'TowardNegInf a
a' Rounded 'TowardInf a
b' of
(Rounded 'TowardNegInf a
a'', Rounded 'TowardInf a
b'') -> forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I Rounded 'TowardNegInf a
a'' Rounded 'TowardInf a
b''
mulAddI :: (Num a, RoundedRing a) => Interval a -> Interval a -> Interval a -> Interval a
mulAddI :: forall a.
(Num a, RoundedRing a) =>
Interval a -> Interval a -> Interval a -> Interval a
mulAddI (I Rounded 'TowardNegInf a
a Rounded 'TowardInf a
b) (I Rounded 'TowardNegInf a
a' Rounded 'TowardInf a
b') (I Rounded 'TowardNegInf a
a'' Rounded 'TowardInf a
b'') = case forall a.
RoundedRing a =>
Rounded 'TowardNegInf a
-> Rounded 'TowardInf a
-> Rounded 'TowardNegInf a
-> Rounded 'TowardInf a
-> Rounded 'TowardNegInf a
-> Rounded 'TowardInf a
-> (Rounded 'TowardNegInf a, Rounded 'TowardInf a)
intervalMulAdd Rounded 'TowardNegInf a
a Rounded 'TowardInf a
b Rounded 'TowardNegInf a
a' Rounded 'TowardInf a
b' Rounded 'TowardNegInf a
a'' Rounded 'TowardInf a
b'' of
(Rounded 'TowardNegInf a
x, Rounded 'TowardInf a
y) -> forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I Rounded 'TowardNegInf a
x Rounded 'TowardInf a
y
normalizeDivisor :: (Ord a, Num a) => Interval a -> Interval a
normalizeDivisor :: forall a. (Ord a, Num a) => Interval a -> Interval a
normalizeDivisor x :: Interval a
x@(I (Rounded a
a) (Rounded a
b))
| a
0 forall a. Ord a => a -> a -> Bool
< a
a Bool -> Bool -> Bool
|| a
b forall a. Ord a => a -> a -> Bool
< a
0 = Interval a
x
| a
a forall a. Eq a => a -> a -> Bool
== a
0 Bool -> Bool -> Bool
&& a
0 forall a. Ord a => a -> a -> Bool
< a
b = forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I (forall (r :: RoundingMode) a. a -> Rounded r a
Rounded a
0) (forall (r :: RoundingMode) a. a -> Rounded r a
Rounded a
b)
| a
a forall a. Ord a => a -> a -> Bool
< a
0 Bool -> Bool -> Bool
&& a
b forall a. Eq a => a -> a -> Bool
== a
0 = forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I (forall (r :: RoundingMode) a. a -> Rounded r a
Rounded a
a) (forall (r :: RoundingMode) a. a -> Rounded r a
Rounded (-a
0))
| Bool
otherwise = forall a. HasCallStack => String -> a
error String
"divide by zero"
divI :: (Num a, RoundedFractional a) => Interval a -> Interval a -> Interval a
I Rounded 'TowardNegInf a
a Rounded 'TowardInf a
b divI :: forall a.
(Num a, RoundedFractional a) =>
Interval a -> Interval a -> Interval a
`divI` Interval a
y = let I Rounded 'TowardNegInf a
a' Rounded 'TowardInf a
b' = forall a. (Ord a, Num a) => Interval a -> Interval a
normalizeDivisor Interval a
y
(Rounded 'TowardNegInf a
z, Rounded 'TowardInf a
z') = forall a.
RoundedFractional a =>
Rounded 'TowardNegInf a
-> Rounded 'TowardInf a
-> Rounded 'TowardNegInf a
-> Rounded 'TowardInf a
-> (Rounded 'TowardNegInf a, Rounded 'TowardInf a)
intervalDiv Rounded 'TowardNegInf a
a Rounded 'TowardInf a
b Rounded 'TowardNegInf a
a' Rounded 'TowardInf a
b'
in forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I Rounded 'TowardNegInf a
z Rounded 'TowardInf a
z'
divAddI :: (Num a, RoundedFractional a) => Interval a -> Interval a -> Interval a -> Interval a
divAddI :: forall a.
(Num a, RoundedFractional a) =>
Interval a -> Interval a -> Interval a -> Interval a
divAddI (I Rounded 'TowardNegInf a
a Rounded 'TowardInf a
b) Interval a
y (I Rounded 'TowardNegInf a
a'' Rounded 'TowardInf a
b'') = let I Rounded 'TowardNegInf a
a' Rounded 'TowardInf a
b' = forall a. (Ord a, Num a) => Interval a -> Interval a
normalizeDivisor Interval a
y
(Rounded 'TowardNegInf a
z, Rounded 'TowardInf a
z') = forall a.
RoundedFractional a =>
Rounded 'TowardNegInf a
-> Rounded 'TowardInf a
-> Rounded 'TowardNegInf a
-> Rounded 'TowardInf a
-> Rounded 'TowardNegInf a
-> Rounded 'TowardInf a
-> (Rounded 'TowardNegInf a, Rounded 'TowardInf a)
intervalDivAdd Rounded 'TowardNegInf a
a Rounded 'TowardInf a
b Rounded 'TowardNegInf a
a' Rounded 'TowardInf a
b' Rounded 'TowardNegInf a
a'' Rounded 'TowardInf a
b''
in forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I Rounded 'TowardNegInf a
z Rounded 'TowardInf a
z'
{-# INLINE [0] addI #-}
{-# INLINE [0] subI #-}
{-# INLINE [0] mulI #-}
{-# INLINE [0] divI #-}
{-# INLINE mulAddI #-}
{-# INLINE divAddI #-}
{-# RULES
"Interval.NonEmpty/x*y+z" forall x y z. addI (mulI x y) z = mulAddI x y z
"Interval.NonEmpty/z+x*y" forall x y z. addI z (mulI x y) = mulAddI x y z
"Interval.NonEmpty/x*y-z" forall x y z. subI (mulI x y) z = mulAddI x y (negateI z)
"Interval.NonEmpty/z-x*y" forall x y z. subI z (mulI x y) = negateI (mulAddI x y (negateI z))
"Interval.NonEmpty/x/y+z" forall x y z. addI (divI x y) z = divAddI x y z
"Interval.NonEmpty/z+x/y" forall x y z. addI z (divI x y) = divAddI x y z
"Interval.NonEmpty/x/y-z" forall x y z. subI (divI x y) z = divAddI x y (negateI z)
"Interval.NonEmpty/z-x/y" forall x y z. subI z (divI x y) = negateI (divAddI x y (negateI z))
"Interval.NonEmpty/negate-negate" forall x. negateI (negateI x) = x
"Interval.NonEmpty/x+(-y)" forall x y. addI x (negateI y) = subI x y
"Interval.NonEmpty/(-y)+x" forall x y. addI (negateI y) x = subI x y
"Interval.NonEmpty/x-(-y)" forall x y. subI x (negateI y) = addI x y
#-}
instance (Num a, RoundedRing a) => Num (Interval a) where
+ :: Interval a -> Interval a -> Interval a
(+) = forall a.
(Num a, RoundedRing a) =>
Interval a -> Interval a -> Interval a
addI
(-) = forall a.
(Num a, RoundedRing a) =>
Interval a -> Interval a -> Interval a
subI
* :: Interval a -> Interval a -> Interval a
(*) = forall a.
(Num a, RoundedRing a) =>
Interval a -> Interval a -> Interval a
mulI
negate :: Interval a -> Interval a
negate = forall a. (Num a, RoundedRing a) => Interval a -> Interval a
negateI
abs :: Interval a -> Interval a
abs x :: Interval a
x@(I Rounded 'TowardNegInf a
a Rounded 'TowardInf a
b)
| Rounded 'TowardNegInf a
a forall a. Ord a => a -> a -> Bool
>= Rounded 'TowardNegInf a
0 = Interval a
x
| Rounded 'TowardInf a
b forall a. Ord a => a -> a -> Bool
<= Rounded 'TowardInf a
0 = forall a. Num a => a -> a
negate Interval a
x
| Bool
otherwise = forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I Rounded 'TowardNegInf a
0 (forall a. Ord a => a -> a -> a
max (forall a. Num a => a -> a
negate (coerce :: forall a b. Coercible a b => a -> b
coerce Rounded 'TowardNegInf a
a)) Rounded 'TowardInf a
b)
signum :: Interval a -> Interval a
signum = forall a.
(forall (r :: RoundingMode).
Rounding r =>
Rounded r a -> Rounded r a)
-> Interval a -> Interval a
increasing forall a. Num a => a -> a
signum
fromInteger :: Integer -> Interval a
fromInteger Integer
x = case forall a.
RoundedRing a =>
Integer -> (Rounded 'TowardNegInf a, Rounded 'TowardInf a)
intervalFromInteger Integer
x of
(Rounded 'TowardNegInf a
y, Rounded 'TowardInf a
y') -> forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I Rounded 'TowardNegInf a
y Rounded 'TowardInf a
y'
{-# INLINE (+) #-}
{-# INLINE (-) #-}
{-# INLINE negate #-}
{-# INLINE (*) #-}
{-# INLINE abs #-}
{-# INLINE signum #-}
{-# INLINE fromInteger #-}
instance (Num a, RoundedFractional a) => Fractional (Interval a) where
recip :: Interval a -> Interval a
recip Interval a
x = let I Rounded 'TowardNegInf a
a Rounded 'TowardInf a
b = forall a. (Ord a, Num a) => Interval a -> Interval a
normalizeDivisor Interval a
x
(Rounded 'TowardNegInf a
y, Rounded 'TowardInf a
y') = forall a.
RoundedFractional a =>
Rounded 'TowardNegInf a
-> Rounded 'TowardInf a
-> (Rounded 'TowardNegInf a, Rounded 'TowardInf a)
intervalRecip Rounded 'TowardNegInf a
a Rounded 'TowardInf a
b
in forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I Rounded 'TowardNegInf a
y Rounded 'TowardInf a
y'
/ :: Interval a -> Interval a -> Interval a
(/) = forall a.
(Num a, RoundedFractional a) =>
Interval a -> Interval a -> Interval a
divI
fromRational :: Rational -> Interval a
fromRational Rational
x = case forall a.
RoundedFractional a =>
Rational -> (Rounded 'TowardNegInf a, Rounded 'TowardInf a)
intervalFromRational Rational
x of
(Rounded 'TowardNegInf a
y, Rounded 'TowardInf a
y') -> forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I Rounded 'TowardNegInf a
y Rounded 'TowardInf a
y'
{-# INLINE recip #-}
{-# INLINE (/) #-}
{-# INLINE fromRational #-}
maxI :: Ord a => Interval a -> Interval a -> Interval a
maxI :: forall a. Ord a => Interval a -> Interval a -> Interval a
maxI (I Rounded 'TowardNegInf a
a Rounded 'TowardInf a
a') (I Rounded 'TowardNegInf a
b Rounded 'TowardInf a
b') = forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I (forall a. Ord a => a -> a -> a
max Rounded 'TowardNegInf a
a Rounded 'TowardNegInf a
b) (forall a. Ord a => a -> a -> a
max Rounded 'TowardInf a
a' Rounded 'TowardInf a
b')
{-# INLINE maxI #-}
minI :: Ord a => Interval a -> Interval a -> Interval a
minI :: forall a. Ord a => Interval a -> Interval a -> Interval a
minI (I Rounded 'TowardNegInf a
a Rounded 'TowardInf a
a') (I Rounded 'TowardNegInf a
b Rounded 'TowardInf a
b') = forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I (forall a. Ord a => a -> a -> a
min Rounded 'TowardNegInf a
a Rounded 'TowardNegInf a
b) (forall a. Ord a => a -> a -> a
min Rounded 'TowardInf a
a' Rounded 'TowardInf a
b')
{-# INLINE minI #-}
powInt :: (Ord a, Num a, RoundedRing a) => Interval a -> Int -> Interval a
powInt :: forall a.
(Ord a, Num a, RoundedRing a) =>
Interval a -> Int -> Interval a
powInt (I Rounded 'TowardNegInf a
a Rounded 'TowardInf a
a') Int
n | forall a. Integral a => a -> Bool
odd Int
n Bool -> Bool -> Bool
|| Rounded 'TowardNegInf a
0 forall a. Ord a => a -> a -> Bool
<= Rounded 'TowardNegInf a
a = forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I (Rounded 'TowardNegInf a
aforall a b. (Num a, Integral b) => a -> b -> a
^Int
n) (Rounded 'TowardInf a
a'forall a b. (Num a, Integral b) => a -> b -> a
^Int
n)
| Rounded 'TowardInf a
a' forall a. Ord a => a -> a -> Bool
<= Rounded 'TowardInf a
0 = forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I ((coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Num a => a -> a
abs Rounded 'TowardInf a
a'))forall a b. (Num a, Integral b) => a -> b -> a
^Int
n) ((coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Num a => a -> a
abs Rounded 'TowardNegInf a
a))forall a b. (Num a, Integral b) => a -> b -> a
^Int
n)
| Bool
otherwise = forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I Rounded 'TowardNegInf a
0 (forall a. Ord a => a -> a -> a
max ((coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Num a => a -> a
abs Rounded 'TowardNegInf a
a))forall a b. (Num a, Integral b) => a -> b -> a
^Int
n) (Rounded 'TowardInf a
a'forall a b. (Num a, Integral b) => a -> b -> a
^Int
n))
{-# SPECIALIZE powInt :: Interval Float -> Int -> Interval Float #-}
{-# SPECIALIZE powInt :: Interval Double -> Int -> Interval Double #-}
null :: Interval a -> Bool
null :: forall a. Interval a -> Bool
null Interval a
_ = Bool
False
inf :: Interval a -> Rounded 'TowardNegInf a
inf :: forall a. Interval a -> Rounded 'TowardNegInf a
inf (I Rounded 'TowardNegInf a
x Rounded 'TowardInf a
_) = Rounded 'TowardNegInf a
x
sup :: Interval a -> Rounded 'TowardInf a
sup :: forall a. Interval a -> Rounded 'TowardInf a
sup (I Rounded 'TowardNegInf a
_ Rounded 'TowardInf a
y) = Rounded 'TowardInf a
y
width :: (Num a, RoundedRing a) => Interval a -> Rounded 'TowardInf a
width :: forall a.
(Num a, RoundedRing a) =>
Interval a -> Rounded 'TowardInf a
width (I Rounded 'TowardNegInf a
x Rounded 'TowardInf a
y) = Rounded 'TowardInf a
y forall a. Num a => a -> a -> a
- coerce :: forall a b. Coercible a b => a -> b
coerce Rounded 'TowardNegInf a
x
hull :: RoundedRing a => Interval a -> Interval a -> Interval a
hull :: forall a. RoundedRing a => Interval a -> Interval a -> Interval a
hull (I Rounded 'TowardNegInf a
x Rounded 'TowardInf a
y) (I Rounded 'TowardNegInf a
x' Rounded 'TowardInf a
y') = forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I (forall a. Ord a => a -> a -> a
min Rounded 'TowardNegInf a
x Rounded 'TowardNegInf a
x') (forall a. Ord a => a -> a -> a
max Rounded 'TowardInf a
y Rounded 'TowardInf a
y')
{-# SPECIALIZE C.expP :: Double -> Interval Double #-}
{-# SPECIALIZE C.expI :: Interval Double -> Interval Double #-}
{-# SPECIALIZE C.expm1P :: Double -> Interval Double #-}
{-# SPECIALIZE C.expm1I :: Interval Double -> Interval Double #-}
{-# SPECIALIZE C.logP :: Double -> Interval Double #-}
{-# SPECIALIZE C.logI :: Interval Double -> Interval Double #-}
{-# SPECIALIZE C.log1pP :: Double -> Interval Double #-}
{-# SPECIALIZE C.log1pI :: Interval Double -> Interval Double #-}
{-# SPECIALIZE C.sin_small :: Interval Double -> Interval Double #-}
{-# SPECIALIZE C.cos_small :: Interval Double -> Interval Double #-}
{-# SPECIALIZE C.sinP :: Interval Double -> Interval Double #-}
{-# SPECIALIZE C.cosP :: Interval Double -> Interval Double #-}
{-# SPECIALIZE C.sinI :: Interval Double -> Interval Double #-}
{-# SPECIALIZE C.cosI :: Interval Double -> Interval Double #-}
{-# SPECIALIZE C.tanI :: Interval Double -> Interval Double #-}
{-# SPECIALIZE C.atan_small :: Interval Double -> Interval Double #-}
{-# SPECIALIZE C.atanP :: Double -> Interval Double #-}
{-# SPECIALIZE C.atanI :: Interval Double -> Interval Double #-}
{-# SPECIALIZE C.asinP :: Double -> Interval Double #-}
{-# SPECIALIZE C.asinI :: Interval Double -> Interval Double #-}
{-# SPECIALIZE C.acosP :: Double -> Interval Double #-}
{-# SPECIALIZE C.acosI :: Interval Double -> Interval Double #-}
{-# SPECIALIZE C.sinhP :: Double -> Interval Double #-}
{-# SPECIALIZE C.sinhI :: Interval Double -> Interval Double #-}
{-# SPECIALIZE C.coshP :: Double -> Interval Double #-}
{-# SPECIALIZE C.coshI :: Interval Double -> Interval Double #-}
{-# SPECIALIZE C.tanhP :: Double -> Interval Double #-}
{-# SPECIALIZE C.tanhI :: Interval Double -> Interval Double #-}
{-# SPECIALIZE C.asinhP :: Double -> Interval Double #-}
{-# SPECIALIZE C.asinhI :: Interval Double -> Interval Double #-}
{-# SPECIALIZE C.acoshP :: Double -> Interval Double #-}
{-# SPECIALIZE C.acoshI :: Interval Double -> Interval Double #-}
{-# SPECIALIZE C.atanhP :: Double -> Interval Double #-}
{-# SPECIALIZE C.atanhI :: Interval Double -> Interval Double #-}
instance (Num a, RoundedFractional a, RoundedSqrt a, Eq a, RealFloat a, RealFloatConstants a) => Floating (Interval a) where
pi :: Interval a
pi = forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I forall a. RealFloatConstants a => Rounded 'TowardNegInf a
pi_down forall a. RealFloatConstants a => Rounded 'TowardInf a
pi_up
exp :: Interval a -> Interval a
exp = forall i.
(IsInterval i, Fractional i, Eq (EndPoint i),
RealFloat (EndPoint i), RealFloatConstants (EndPoint i),
RoundedFractional (EndPoint i)) =>
i -> i
C.expI
log :: Interval a -> Interval a
log = forall i.
(IsInterval i, Fractional i, Eq (EndPoint i),
RealFloat (EndPoint i), RealFloatConstants (EndPoint i)) =>
i -> i
C.logI
sqrt :: Interval a -> Interval a
sqrt = forall i. (IsInterval i, RoundedSqrt (EndPoint i)) => i -> i
C.sqrtI
sin :: Interval a -> Interval a
sin = forall i.
(IsInterval i, Fractional i, Eq (EndPoint i),
RealFloat (EndPoint i), RoundedRing (EndPoint i),
RealFloatConstants (EndPoint i)) =>
i -> i
C.sinI
cos :: Interval a -> Interval a
cos = forall i.
(IsInterval i, Fractional i, Eq (EndPoint i),
RealFloat (EndPoint i), RoundedRing (EndPoint i),
RealFloatConstants (EndPoint i)) =>
i -> i
C.cosI
tan :: Interval a -> Interval a
tan = forall i.
(IsInterval i, Fractional i, Eq (EndPoint i),
RealFloat (EndPoint i), RoundedRing (EndPoint i),
RealFloatConstants (EndPoint i)) =>
i -> i
C.tanI
asin :: Interval a -> Interval a
asin = forall i.
(IsInterval i, Fractional i, Eq (EndPoint i),
RealFloat (EndPoint i), RoundedRing (EndPoint i),
RoundedSqrt (EndPoint i), RealFloatConstants (EndPoint i)) =>
i -> i
C.asinI
acos :: Interval a -> Interval a
acos = forall i.
(IsInterval i, Fractional i, Eq (EndPoint i),
RealFloat (EndPoint i), RoundedRing (EndPoint i),
RoundedSqrt (EndPoint i), RealFloatConstants (EndPoint i)) =>
i -> i
C.acosI
atan :: Interval a -> Interval a
atan = forall i.
(IsInterval i, Fractional i, Eq (EndPoint i),
RealFloat (EndPoint i), RoundedRing (EndPoint i),
RealFloatConstants (EndPoint i)) =>
i -> i
C.atanI
sinh :: Interval a -> Interval a
sinh = forall i.
(IsInterval i, Fractional i, Eq (EndPoint i),
RealFloat (EndPoint i), RealFloatConstants (EndPoint i),
RoundedFractional (EndPoint i)) =>
i -> i
C.sinhI
cosh :: Interval a -> Interval a
cosh = forall i.
(IsInterval i, Fractional i, Eq (EndPoint i),
RealFloat (EndPoint i), RealFloatConstants (EndPoint i),
RoundedFractional (EndPoint i)) =>
i -> i
C.coshI
tanh :: Interval a -> Interval a
tanh = forall i.
(IsInterval i, Fractional i, Eq (EndPoint i),
RealFloat (EndPoint i), RealFloatConstants (EndPoint i),
RoundedFractional (EndPoint i)) =>
i -> i
C.tanhI
asinh :: Interval a -> Interval a
asinh = forall i.
(IsInterval i, Fractional i, Eq (EndPoint i),
RealFloat (EndPoint i), RealFloatConstants (EndPoint i),
RoundedSqrt (EndPoint i)) =>
i -> i
C.asinhI
acosh :: Interval a -> Interval a
acosh = forall i.
(IsInterval i, Fractional i, Eq (EndPoint i),
RealFloat (EndPoint i), RealFloatConstants (EndPoint i),
RoundedSqrt (EndPoint i)) =>
i -> i
C.acoshI
atanh :: Interval a -> Interval a
atanh = forall i.
(IsInterval i, Fractional i, Eq (EndPoint i),
RealFloat (EndPoint i), RealFloatConstants (EndPoint i)) =>
i -> i
C.atanhI
log1p :: Interval a -> Interval a
log1p = forall i.
(IsInterval i, Fractional i, Eq (EndPoint i),
RealFloat (EndPoint i), RealFloatConstants (EndPoint i)) =>
i -> i
C.log1pI
expm1 :: Interval a -> Interval a
expm1 = forall i.
(IsInterval i, Fractional i, Eq (EndPoint i),
RealFloat (EndPoint i), RealFloatConstants (EndPoint i),
RoundedFractional (EndPoint i)) =>
i -> i
C.expm1I
{-# SPECIALIZE instance Floating (Interval Float) #-}
{-# SPECIALIZE instance Floating (Interval Double) #-}
instance (RealFloat a, RoundedRing a) => C.IsInterval (Interval a) where
type EndPoint (Interval a) = a
makeInterval :: Rounded 'TowardNegInf (EndPoint (Interval a))
-> Rounded 'TowardInf (EndPoint (Interval a)) -> Interval a
makeInterval = forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I
width :: Interval a -> Rounded 'TowardInf (EndPoint (Interval a))
width = forall a.
(Num a, RoundedRing a) =>
Interval a -> Rounded 'TowardInf a
width
withEndPoints :: (Rounded 'TowardNegInf (EndPoint (Interval a))
-> Rounded 'TowardInf (EndPoint (Interval a)) -> Interval a)
-> Interval a -> Interval a
withEndPoints Rounded 'TowardNegInf (EndPoint (Interval a))
-> Rounded 'TowardInf (EndPoint (Interval a)) -> Interval a
f (I Rounded 'TowardNegInf a
x Rounded 'TowardInf a
y) = Rounded 'TowardNegInf (EndPoint (Interval a))
-> Rounded 'TowardInf (EndPoint (Interval a)) -> Interval a
f Rounded 'TowardNegInf a
x Rounded 'TowardInf a
y
hull :: Interval a -> Interval a -> Interval a
hull = forall a. RoundedRing a => Interval a -> Interval a -> Interval a
hull
intersection :: Interval a -> Interval a -> Interval a
intersection (I Rounded 'TowardNegInf a
x Rounded 'TowardInf a
y) (I Rounded 'TowardNegInf a
x' Rounded 'TowardInf a
y') | forall (r :: RoundingMode) a. Rounded r a -> a
getRounded Rounded 'TowardNegInf a
x'' forall a. Ord a => a -> a -> Bool
<= forall (r :: RoundingMode) a. Rounded r a -> a
getRounded Rounded 'TowardInf a
y'' = forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I Rounded 'TowardNegInf a
x'' Rounded 'TowardInf a
y''
| Bool
otherwise = forall a. HasCallStack => String -> a
error String
"empty intersection"
where x'' :: Rounded 'TowardNegInf a
x'' = forall a. Ord a => a -> a -> a
max Rounded 'TowardNegInf a
x Rounded 'TowardNegInf a
x'
y'' :: Rounded 'TowardInf a
y'' = forall a. Ord a => a -> a -> a
min Rounded 'TowardInf a
y Rounded 'TowardInf a
y'
maybeIntersection :: Interval a -> Interval a -> Maybe (Interval a)
maybeIntersection (I Rounded 'TowardNegInf a
x Rounded 'TowardInf a
y) (I Rounded 'TowardNegInf a
x' Rounded 'TowardInf a
y') | forall (r :: RoundingMode) a. Rounded r a -> a
getRounded Rounded 'TowardNegInf a
x'' forall a. Ord a => a -> a -> Bool
<= forall (r :: RoundingMode) a. Rounded r a -> a
getRounded Rounded 'TowardInf a
y'' = forall a. a -> Maybe a
Just (forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I Rounded 'TowardNegInf a
x'' Rounded 'TowardInf a
y'')
| Bool
otherwise = forall a. Maybe a
Nothing
where x'' :: Rounded 'TowardNegInf a
x'' = forall a. Ord a => a -> a -> a
max Rounded 'TowardNegInf a
x Rounded 'TowardNegInf a
x'
y'' :: Rounded 'TowardInf a
y'' = forall a. Ord a => a -> a -> a
min Rounded 'TowardInf a
y Rounded 'TowardInf a
y'
equalAsSet :: Interval a -> Interval a -> Bool
equalAsSet (I Rounded 'TowardNegInf a
x Rounded 'TowardInf a
y) (I Rounded 'TowardNegInf a
x' Rounded 'TowardInf a
y') = Rounded 'TowardNegInf a
x forall a. Eq a => a -> a -> Bool
== Rounded 'TowardNegInf a
x' Bool -> Bool -> Bool
&& Rounded 'TowardInf a
y forall a. Eq a => a -> a -> Bool
== Rounded 'TowardInf a
y'
subset :: Interval a -> Interval a -> Bool
subset (I Rounded 'TowardNegInf a
x Rounded 'TowardInf a
y) (I Rounded 'TowardNegInf a
x' Rounded 'TowardInf a
y') = Rounded 'TowardNegInf a
x' forall a. Ord a => a -> a -> Bool
<= Rounded 'TowardNegInf a
x Bool -> Bool -> Bool
&& Rounded 'TowardInf a
y forall a. Ord a => a -> a -> Bool
<= Rounded 'TowardInf a
y'
weaklyLess :: Interval a -> Interval a -> Bool
weaklyLess (I Rounded 'TowardNegInf a
x Rounded 'TowardInf a
y) (I Rounded 'TowardNegInf a
x' Rounded 'TowardInf a
y') = Rounded 'TowardNegInf a
x forall a. Ord a => a -> a -> Bool
<= Rounded 'TowardNegInf a
x' Bool -> Bool -> Bool
&& Rounded 'TowardInf a
y forall a. Ord a => a -> a -> Bool
<= Rounded 'TowardInf a
y'
precedes :: Interval a -> Interval a -> Bool
precedes (I Rounded 'TowardNegInf a
_ Rounded 'TowardInf a
y) (I Rounded 'TowardNegInf a
x' Rounded 'TowardInf a
_) = forall (r :: RoundingMode) a. Rounded r a -> a
getRounded Rounded 'TowardInf a
y forall a. Ord a => a -> a -> Bool
<= forall (r :: RoundingMode) a. Rounded r a -> a
getRounded Rounded 'TowardNegInf a
x'
interior :: Interval a -> Interval a -> Bool
interior (I Rounded 'TowardNegInf a
x Rounded 'TowardInf a
y) (I Rounded 'TowardNegInf a
x' Rounded 'TowardInf a
y') = forall (r :: RoundingMode) a. Rounded r a -> a
getRounded Rounded 'TowardNegInf a
x' forall {a}. RealFloat a => a -> a -> Bool
<# forall (r :: RoundingMode) a. Rounded r a -> a
getRounded Rounded 'TowardNegInf a
x Bool -> Bool -> Bool
&& forall (r :: RoundingMode) a. Rounded r a -> a
getRounded Rounded 'TowardInf a
y forall {a}. RealFloat a => a -> a -> Bool
<# forall (r :: RoundingMode) a. Rounded r a -> a
getRounded Rounded 'TowardInf a
y'
where a
s <# :: a -> a -> Bool
<# a
t = a
s forall a. Ord a => a -> a -> Bool
< a
t Bool -> Bool -> Bool
|| (a
s forall a. Eq a => a -> a -> Bool
== a
t Bool -> Bool -> Bool
&& forall a. RealFloat a => a -> Bool
isInfinite a
s)
strictLess :: Interval a -> Interval a -> Bool
strictLess (I Rounded 'TowardNegInf a
x Rounded 'TowardInf a
y) (I Rounded 'TowardNegInf a
x' Rounded 'TowardInf a
y') = forall (r :: RoundingMode) a. Rounded r a -> a
getRounded Rounded 'TowardNegInf a
x forall {a}. RealFloat a => a -> a -> Bool
<# forall (r :: RoundingMode) a. Rounded r a -> a
getRounded Rounded 'TowardNegInf a
x' Bool -> Bool -> Bool
&& forall (r :: RoundingMode) a. Rounded r a -> a
getRounded Rounded 'TowardInf a
y forall {a}. RealFloat a => a -> a -> Bool
<# forall (r :: RoundingMode) a. Rounded r a -> a
getRounded Rounded 'TowardInf a
y'
where a
s <# :: a -> a -> Bool
<# a
t = a
s forall a. Ord a => a -> a -> Bool
< a
t Bool -> Bool -> Bool
|| (a
s forall a. Eq a => a -> a -> Bool
== a
t Bool -> Bool -> Bool
&& forall a. RealFloat a => a -> Bool
isInfinite a
s)
strictPrecedes :: Interval a -> Interval a -> Bool
strictPrecedes (I Rounded 'TowardNegInf a
_ Rounded 'TowardInf a
y) (I Rounded 'TowardNegInf a
x' Rounded 'TowardInf a
_) = forall (r :: RoundingMode) a. Rounded r a -> a
getRounded Rounded 'TowardInf a
y forall a. Ord a => a -> a -> Bool
< forall (r :: RoundingMode) a. Rounded r a -> a
getRounded Rounded 'TowardNegInf a
x'
disjoint :: Interval a -> Interval a -> Bool
disjoint (I Rounded 'TowardNegInf a
x Rounded 'TowardInf a
y) (I Rounded 'TowardNegInf a
x' Rounded 'TowardInf a
y') = forall (r :: RoundingMode) a. Rounded r a -> a
getRounded Rounded 'TowardInf a
y forall a. Ord a => a -> a -> Bool
< forall (r :: RoundingMode) a. Rounded r a -> a
getRounded Rounded 'TowardNegInf a
x' Bool -> Bool -> Bool
|| forall (r :: RoundingMode) a. Rounded r a -> a
getRounded Rounded 'TowardInf a
y' forall a. Ord a => a -> a -> Bool
< forall (r :: RoundingMode) a. Rounded r a -> a
getRounded Rounded 'TowardNegInf a
x
{-# INLINE makeInterval #-}
{-# INLINE width #-}
{-# INLINE withEndPoints #-}
{-# INLINE hull #-}
{-# INLINE intersection #-}
{-# INLINE maybeIntersection #-}
{-# INLINE equalAsSet #-}
{-# INLINE subset #-}
{-# INLINE weaklyLess #-}
{-# INLINE precedes #-}
{-# INLINE interior #-}
{-# INLINE strictLess #-}
{-# INLINE strictPrecedes #-}
{-# INLINE disjoint #-}
newtype instance VUM.MVector s (Interval a) = MV_Interval (VUM.MVector s (a, a))
newtype instance VU.Vector (Interval a) = V_Interval (VU.Vector (a, a))
intervalToPair :: Fractional a => Interval a -> (a, a)
intervalToPair :: forall a. Fractional a => Interval a -> (a, a)
intervalToPair (I (Rounded a
x) (Rounded a
y)) = (a
x, a
y)
{-# INLINE intervalToPair #-}
pairToInterval :: Ord a => (a, a) -> Interval a
pairToInterval :: forall a. Ord a => (a, a) -> Interval a
pairToInterval (a
x, a
y) = forall a.
Rounded 'TowardNegInf a -> Rounded 'TowardInf a -> Interval a
I (forall (r :: RoundingMode) a. a -> Rounded r a
Rounded a
x) (forall (r :: RoundingMode) a. a -> Rounded r a
Rounded a
y)
{-# INLINE pairToInterval #-}
instance (VU.Unbox a, Ord a, Fractional a) => VGM.MVector VUM.MVector (Interval a) where
basicLength :: forall s. MVector s (Interval a) -> Int
basicLength (MV_Interval MVector s (a, a)
mv) = forall (v :: * -> * -> *) a s. MVector v a => v s a -> Int
VGM.basicLength MVector s (a, a)
mv
basicUnsafeSlice :: forall s.
Int -> Int -> MVector s (Interval a) -> MVector s (Interval a)
basicUnsafeSlice Int
i Int
l (MV_Interval MVector s (a, a)
mv) = forall s a. MVector s (a, a) -> MVector s (Interval a)
MV_Interval (forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> Int -> v s a -> v s a
VGM.basicUnsafeSlice Int
i Int
l MVector s (a, a)
mv)
basicOverlaps :: forall s. MVector s (Interval a) -> MVector s (Interval a) -> Bool
basicOverlaps (MV_Interval MVector s (a, a)
mv) (MV_Interval MVector s (a, a)
mv') = forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> Bool
VGM.basicOverlaps MVector s (a, a)
mv MVector s (a, a)
mv'
basicUnsafeNew :: forall s. Int -> ST s (MVector s (Interval a))
basicUnsafeNew Int
l = forall s a. MVector s (a, a) -> MVector s (Interval a)
MV_Interval forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (v :: * -> * -> *) a s. MVector v a => Int -> ST s (v s a)
VGM.basicUnsafeNew Int
l
basicInitialize :: forall s. MVector s (Interval a) -> ST s ()
basicInitialize (MV_Interval MVector s (a, a)
mv) = forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
VGM.basicInitialize MVector s (a, a)
mv
basicUnsafeReplicate :: forall s. Int -> Interval a -> ST s (MVector s (Interval a))
basicUnsafeReplicate Int
i Interval a
x = forall s a. MVector s (a, a) -> MVector s (Interval a)
MV_Interval forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> a -> ST s (v s a)
VGM.basicUnsafeReplicate Int
i (forall a. Fractional a => Interval a -> (a, a)
intervalToPair Interval a
x)
basicUnsafeRead :: forall s. MVector s (Interval a) -> Int -> ST s (Interval a)
basicUnsafeRead (MV_Interval MVector s (a, a)
mv) Int
i = forall a. Ord a => (a, a) -> Interval a
pairToInterval forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> ST s a
VGM.basicUnsafeRead MVector s (a, a)
mv Int
i
basicUnsafeWrite :: forall s. MVector s (Interval a) -> Int -> Interval a -> ST s ()
basicUnsafeWrite (MV_Interval MVector s (a, a)
mv) Int
i Interval a
x = forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> a -> ST s ()
VGM.basicUnsafeWrite MVector s (a, a)
mv Int
i (forall a. Fractional a => Interval a -> (a, a)
intervalToPair Interval a
x)
basicClear :: forall s. MVector s (Interval a) -> ST s ()
basicClear (MV_Interval MVector s (a, a)
mv) = forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
VGM.basicClear MVector s (a, a)
mv
basicSet :: forall s. MVector s (Interval a) -> Interval a -> ST s ()
basicSet (MV_Interval MVector s (a, a)
mv) Interval a
x = forall (v :: * -> * -> *) a s. MVector v a => v s a -> a -> ST s ()
VGM.basicSet MVector s (a, a)
mv (forall a. Fractional a => Interval a -> (a, a)
intervalToPair Interval a
x)
basicUnsafeCopy :: forall s.
MVector s (Interval a) -> MVector s (Interval a) -> ST s ()
basicUnsafeCopy (MV_Interval MVector s (a, a)
mv) (MV_Interval MVector s (a, a)
mv') = forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> ST s ()
VGM.basicUnsafeCopy MVector s (a, a)
mv MVector s (a, a)
mv'
basicUnsafeMove :: forall s.
MVector s (Interval a) -> MVector s (Interval a) -> ST s ()
basicUnsafeMove (MV_Interval MVector s (a, a)
mv) (MV_Interval MVector s (a, a)
mv') = forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> ST s ()
VGM.basicUnsafeMove MVector s (a, a)
mv MVector s (a, a)
mv'
basicUnsafeGrow :: forall s.
MVector s (Interval a) -> Int -> ST s (MVector s (Interval a))
basicUnsafeGrow (MV_Interval MVector s (a, a)
mv) Int
n = forall s a. MVector s (a, a) -> MVector s (Interval a)
MV_Interval forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> ST s (v s a)
VGM.basicUnsafeGrow MVector s (a, a)
mv Int
n
{-# INLINE basicLength #-}
{-# INLINE basicUnsafeSlice #-}
{-# INLINE basicOverlaps #-}
{-# INLINE basicUnsafeNew #-}
{-# INLINE basicInitialize #-}
{-# INLINE basicUnsafeReplicate #-}
{-# INLINE basicUnsafeRead #-}
{-# INLINE basicUnsafeWrite #-}
{-# INLINE basicClear #-}
{-# INLINE basicSet #-}
{-# INLINE basicUnsafeCopy #-}
{-# INLINE basicUnsafeMove #-}
{-# INLINE basicUnsafeGrow #-}
instance (VU.Unbox a, Ord a, Fractional a) => VG.Vector VU.Vector (Interval a) where
basicUnsafeFreeze :: forall s.
Mutable Vector s (Interval a) -> ST s (Vector (Interval a))
basicUnsafeFreeze (MV_Interval MVector s (a, a)
mv) = forall a. Vector (a, a) -> Vector (Interval a)
V_Interval forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (v :: * -> *) a s. Vector v a => Mutable v s a -> ST s (v a)
VG.basicUnsafeFreeze MVector s (a, a)
mv
basicUnsafeThaw :: forall s.
Vector (Interval a) -> ST s (Mutable Vector s (Interval a))
basicUnsafeThaw (V_Interval Vector (a, a)
v) = forall s a. MVector s (a, a) -> MVector s (Interval a)
MV_Interval forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (v :: * -> *) a s. Vector v a => v a -> ST s (Mutable v s a)
VG.basicUnsafeThaw Vector (a, a)
v
basicLength :: Vector (Interval a) -> Int
basicLength (V_Interval Vector (a, a)
v) = forall (v :: * -> *) a. Vector v a => v a -> Int
VG.basicLength Vector (a, a)
v
basicUnsafeSlice :: Int -> Int -> Vector (Interval a) -> Vector (Interval a)
basicUnsafeSlice Int
i Int
l (V_Interval Vector (a, a)
v) = forall a. Vector (a, a) -> Vector (Interval a)
V_Interval (forall (v :: * -> *) a. Vector v a => Int -> Int -> v a -> v a
VG.basicUnsafeSlice Int
i Int
l Vector (a, a)
v)
basicUnsafeIndexM :: Vector (Interval a) -> Int -> Box (Interval a)
basicUnsafeIndexM (V_Interval Vector (a, a)
v) Int
i = forall a. Ord a => (a, a) -> Interval a
pairToInterval forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (v :: * -> *) a. Vector v a => v a -> Int -> Box a
VG.basicUnsafeIndexM Vector (a, a)
v Int
i
basicUnsafeCopy :: forall s.
Mutable Vector s (Interval a) -> Vector (Interval a) -> ST s ()
basicUnsafeCopy (MV_Interval MVector s (a, a)
mv) (V_Interval Vector (a, a)
v) = forall (v :: * -> *) a s.
Vector v a =>
Mutable v s a -> v a -> ST s ()
VG.basicUnsafeCopy MVector s (a, a)
mv Vector (a, a)
v
elemseq :: forall b. Vector (Interval a) -> Interval a -> b -> b
elemseq (V_Interval Vector (a, a)
_) Interval a
x b
y = Interval a
x seq :: forall a b. a -> b -> b
`seq` b
y
{-# INLINE basicUnsafeFreeze #-}
{-# INLINE basicUnsafeThaw #-}
{-# INLINE basicLength #-}
{-# INLINE basicUnsafeSlice #-}
{-# INLINE basicUnsafeIndexM #-}
{-# INLINE basicUnsafeCopy #-}
{-# INLINE elemseq #-}
instance (VU.Unbox a, Ord a, Fractional a) => VU.Unbox (Interval a)
instance (Prim a, Ord a, Fractional a) => A.MArray (A.STUArray s) (Interval a) (ST s) where
getBounds :: forall i. Ix i => STUArray s i (Interval a) -> ST s (i, i)
getBounds (A.STUArray i
l i
u Int
_ MutableByteArray# s
_) = forall (m :: * -> *) a. Monad m => a -> m a
return (i
l, i
u)
getNumElements :: forall i. Ix i => STUArray s i (Interval a) -> ST s Int
getNumElements (A.STUArray i
_ i
_ Int
n MutableByteArray# s
_) = forall (m :: * -> *) a. Monad m => a -> m a
return Int
n
unsafeNewArray_ :: forall i. Ix i => (i, i) -> ST s (STUArray s i (Interval a))
unsafeNewArray_ = forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
(i, i) -> m (a i e)
A.newArray_
newArray_ :: forall i. Ix i => (i, i) -> ST s (STUArray s i (Interval a))
newArray_ bounds :: (i, i)
bounds@(i
l,i
u) = do
let n :: Int
n = forall a. Ix a => (a, a) -> Int
rangeSize (i, i)
bounds
arr :: MutableByteArray s
arr@(MutableByteArray MutableByteArray# s
arr_) <- forall (m :: * -> *).
PrimMonad m =>
Int -> m (MutableByteArray (PrimState m))
newByteArray (Int
2 forall a. Num a => a -> a -> a
* forall a. Prim a => a -> Int
sizeOf (forall a. HasCallStack => a
undefined :: a) forall a. Num a => a -> a -> a
* Int
n)
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> Int -> a -> m ()
setByteArray MutableByteArray s
arr Int
0 (Int
2 forall a. Num a => a -> a -> a
* Int
n) (a
0 :: a)
forall (m :: * -> *) a. Monad m => a -> m a
return (forall s i e.
i -> i -> Int -> MutableByteArray# s -> STUArray s i e
A.STUArray i
l i
u Int
n MutableByteArray# s
arr_)
unsafeRead :: forall i.
Ix i =>
STUArray s i (Interval a) -> Int -> ST s (Interval a)
unsafeRead (A.STUArray i
_ i
_ Int
_ MutableByteArray# s
byteArr) Int
i = do
a
x <- forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> m a
readByteArray (forall s. MutableByteArray# s -> MutableByteArray s
MutableByteArray MutableByteArray# s
byteArr) (Int
2 forall a. Num a => a -> a -> a
* Int
i)
a
y <- forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> m a
readByteArray (forall s. MutableByteArray# s -> MutableByteArray s
MutableByteArray MutableByteArray# s
byteArr) (Int
2 forall a. Num a => a -> a -> a
* Int
i forall a. Num a => a -> a -> a
+ Int
1)
forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. Ord a => (a, a) -> Interval a
pairToInterval (a
x, a
y))
unsafeWrite :: forall i.
Ix i =>
STUArray s i (Interval a) -> Int -> Interval a -> ST s ()
unsafeWrite (A.STUArray i
_ i
_ Int
_ MutableByteArray# s
byteArr) Int
i Interval a
e = do
let (a
x, a
y) = forall a. Fractional a => Interval a -> (a, a)
intervalToPair Interval a
e
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray (forall s. MutableByteArray# s -> MutableByteArray s
MutableByteArray MutableByteArray# s
byteArr) (Int
2 forall a. Num a => a -> a -> a
* Int
i) a
x
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray (forall s. MutableByteArray# s -> MutableByteArray s
MutableByteArray MutableByteArray# s
byteArr) (Int
2 forall a. Num a => a -> a -> a
* Int
i forall a. Num a => a -> a -> a
+ Int
1) a
y
instance (Prim a, Ord a, Fractional a) => A.IArray A.UArray (Interval a) where
bounds :: forall i. Ix i => UArray i (Interval a) -> (i, i)
bounds (A.UArray i
l i
u Int
_ ByteArray#
_) = (i
l,i
u)
numElements :: forall i. Ix i => UArray i (Interval a) -> Int
numElements (A.UArray i
_ i
_ Int
n ByteArray#
_) = Int
n
unsafeArray :: forall i.
Ix i =>
(i, i) -> [(Int, Interval a)] -> UArray i (Interval a)
unsafeArray (i, i)
bounds [(Int, Interval a)]
el = forall a. (forall s. ST s a) -> a
runST forall a b. (a -> b) -> a -> b
$ do
STUArray s i (Interval a)
marr <- forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
(i, i) -> m (a i e)
A.newArray_ (i, i)
bounds
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [(Int, Interval a)]
el forall a b. (a -> b) -> a -> b
$ \(Int
i,Interval a
e) -> forall (a :: * -> * -> *) e (m :: * -> *) i.
(MArray a e m, Ix i) =>
a i e -> Int -> e -> m ()
A.unsafeWrite STUArray s i (Interval a)
marr Int
i Interval a
e
forall s i e. STUArray s i e -> ST s (UArray i e)
A.unsafeFreezeSTUArray STUArray s i (Interval a)
marr
unsafeAt :: forall i. Ix i => UArray i (Interval a) -> Int -> Interval a
unsafeAt (A.UArray i
_ i
_ Int
_ ByteArray#
byteArr) Int
i =
let x :: a
x = forall a. Prim a => ByteArray -> Int -> a
indexByteArray (ByteArray# -> ByteArray
ByteArray ByteArray#
byteArr) (Int
2 forall a. Num a => a -> a -> a
* Int
i)
y :: a
y = forall a. Prim a => ByteArray -> Int -> a
indexByteArray (ByteArray# -> ByteArray
ByteArray ByteArray#
byteArr) (Int
2 forall a. Num a => a -> a -> a
* Int
i forall a. Num a => a -> a -> a
+ Int
1)
in forall a. Ord a => (a, a) -> Interval a
pairToInterval (a
x, a
y)
#if !MIN_VERSION_base(4, 16, 0)
{-# RULES
"fromIntegral/a->Interval Float"
fromIntegral = \x -> case intervalFromIntegral x of (l, u) -> I l u :: Interval Float
"fromIntegral/a->Interval Double"
fromIntegral = \x -> case intervalFromIntegral x of (l, u) -> I l u :: Interval Double
#-}
#endif