brush-strokes-0.1.0.0: src/lib/Math/Interval/Internal/RoundedHW.hs
module Math.Interval.Internal.RoundedHW
( π(π, inf, sup)
, scaleInterval
)
where
-- base
import Prelude hiding ( Num(..), Fractional(..), Floating(..) )
import qualified Prelude
-- brush-strokes
import Math.Ring
-- deepseq
import Control.DeepSeq
( NFData(..) )
-- rounded-hw
import Numeric.Rounded.Hardware
( Rounded(..) )
import qualified Numeric.Rounded.Hardware.Interval.NonEmpty as Interval
( Interval(..), powInt )
--------------------------------------------------------------------------------
-- | A non-empty interval of real numbers (possibly unbounded).
newtype π = MkI { ival :: Interval.Interval Double }
deriving newtype ( Prelude.Num, Prelude.Fractional, Prelude.Floating )
deriving newtype NFData
{-# COMPLETE π #-}
pattern π :: Double -> Double -> π
pattern π { inf, sup } = MkI ( Interval.I ( Rounded inf ) ( Rounded sup ) )
instance Ring π where
MkI i1 * MkI i2 = MkI $ i1 Prelude.* i2
MkI x ^ n = MkI { ival = Interval.powInt x ( Prelude.fromIntegral n ) }
-- This is very important, as x^2 is not the same as x * x
-- in interval arithmetic. This ensures we don't
-- accidentally use (^) from Prelude.
deriving via ViaPrelude π
instance AbelianGroup π
deriving via ViaPrelude π
instance Field π
deriving via ViaPrelude π
instance Floating π
deriving via ViaPrelude π
instance Transcendental π
scaleInterval :: Double -> π -> π
scaleInterval s iv = π s s * iv -- TODO: could be better