| Copyright | (c) Edward Kmett 2013-2015 |
|---|---|
| License | BSD3 |
| Maintainer | Edward Kmett <ekmett@gmail.com> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | Trustworthy |
| Language | Haskell2010 |
Numeric.Log
Description
Documentation
Log-domain Float and Double values.
Instances
| Foldable1 Log Source # | |||||
Defined in Numeric.Log Methods fold1 :: Semigroup m => Log m -> m Source # foldMap1 :: Semigroup m => (a -> m) -> Log a -> m Source # foldMap1' :: Semigroup m => (a -> m) -> Log a -> m Source # toNonEmpty :: Log a -> NonEmpty a Source # maximum :: Ord a => Log a -> a Source # minimum :: Ord a => Log a -> a Source # foldrMap1 :: (a -> b) -> (a -> b -> b) -> Log a -> b Source # foldlMap1' :: (a -> b) -> (b -> a -> b) -> Log a -> b Source # foldlMap1 :: (a -> b) -> (b -> a -> b) -> Log a -> b Source # foldrMap1' :: (a -> b) -> (a -> b -> b) -> Log a -> b Source # | |||||
| Eq1 Log Source # | |||||
| Serial1 Log Source # | |||||
Defined in Numeric.Log Methods serializeWith :: MonadPut m => (a -> m ()) -> Log a -> m () Source # deserializeWith :: MonadGet m => m a -> m (Log a) Source # | |||||
| Comonad Log Source # | |||||
| ComonadApply Log Source # | |||||
| Distributive Log Source # | |||||
| Applicative Log Source # | |||||
| Functor Log Source # | |||||
| Monad Log Source # | |||||
| Foldable Log Source # | |||||
Defined in Numeric.Log Methods fold :: Monoid m => Log m -> m Source # foldMap :: Monoid m => (a -> m) -> Log a -> m Source # foldMap' :: Monoid m => (a -> m) -> Log a -> m Source # foldr :: (a -> b -> b) -> b -> Log a -> b Source # foldr' :: (a -> b -> b) -> b -> Log a -> b Source # foldl :: (b -> a -> b) -> b -> Log a -> b Source # foldl' :: (b -> a -> b) -> b -> Log a -> b Source # foldr1 :: (a -> a -> a) -> Log a -> a Source # foldl1 :: (a -> a -> a) -> Log a -> a Source # toList :: Log a -> [a] Source # null :: Log a -> Bool Source # length :: Log a -> Int Source # elem :: Eq a => a -> Log a -> Bool Source # maximum :: Ord a => Log a -> a Source # minimum :: Ord a => Log a -> a Source # | |||||
| Traversable Log Source # | |||||
| Hashable1 Log Source # | |||||
Defined in Numeric.Log | |||||
| Apply Log Source # | |||||
| Bind Log Source # | |||||
| Extend Log Source # | |||||
| Traversable1 Log Source # | |||||
| (RealFloat a, Unbox a) => Vector Vector (Log a) Source # | |||||
Defined in Numeric.Log Methods basicUnsafeFreeze :: Mutable Vector s (Log a) -> ST s (Vector (Log a)) basicUnsafeThaw :: Vector (Log a) -> ST s (Mutable Vector s (Log a)) basicLength :: Vector (Log a) -> Int basicUnsafeSlice :: Int -> Int -> Vector (Log a) -> Vector (Log a) basicUnsafeIndexM :: Vector (Log a) -> Int -> Box (Log a) basicUnsafeCopy :: Mutable Vector s (Log a) -> Vector (Log a) -> ST s () | |||||
| Unbox a => MVector MVector (Log a) Source # | |||||
Defined in Numeric.Log Methods basicLength :: MVector s (Log a) -> Int basicUnsafeSlice :: Int -> Int -> MVector s (Log a) -> MVector s (Log a) basicOverlaps :: MVector s (Log a) -> MVector s (Log a) -> Bool basicUnsafeNew :: Int -> ST s (MVector s (Log a)) basicInitialize :: MVector s (Log a) -> ST s () basicUnsafeReplicate :: Int -> Log a -> ST s (MVector s (Log a)) basicUnsafeRead :: MVector s (Log a) -> Int -> ST s (Log a) basicUnsafeWrite :: MVector s (Log a) -> Int -> Log a -> ST s () basicClear :: MVector s (Log a) -> ST s () basicSet :: MVector s (Log a) -> Log a -> ST s () basicUnsafeCopy :: MVector s (Log a) -> MVector s (Log a) -> ST s () basicUnsafeMove :: MVector s (Log a) -> MVector s (Log a) -> ST s () basicUnsafeGrow :: MVector s (Log a) -> Int -> ST s (MVector s (Log a)) | |||||
| Binary a => Binary (Log a) Source # | |||||
| Serial a => Serial (Log a) Source # | |||||
| Serialize a => Serialize (Log a) Source # | |||||
| NFData a => NFData (Log a) Source # | |||||
Defined in Numeric.Log | |||||
| RealFloat a => Monoid (Log a) Source # | |||||
| RealFloat a => Semigroup (Log a) Source # | |||||
| Data a => Data (Log a) Source # | |||||
Defined in Numeric.Log Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Log a -> c (Log a) Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Log a) Source # toConstr :: Log a -> Constr Source # dataTypeOf :: Log a -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Log a)) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Log a)) Source # gmapT :: (forall b. Data b => b -> b) -> Log a -> Log a Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Log a -> r Source # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Log a -> r Source # gmapQ :: (forall d. Data d => d -> u) -> Log a -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> Log a -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Log a -> m (Log a) Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Log a -> m (Log a) Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Log a -> m (Log a) Source # | |||||
| (RealFloat a, Enum a) => Enum (Log a) Source # | |||||
Defined in Numeric.Log Methods succ :: Log a -> Log a Source # pred :: Log a -> Log a Source # toEnum :: Int -> Log a Source # fromEnum :: Log a -> Int Source # enumFrom :: Log a -> [Log a] Source # enumFromThen :: Log a -> Log a -> [Log a] Source # enumFromTo :: Log a -> Log a -> [Log a] Source # enumFromThenTo :: Log a -> Log a -> Log a -> [Log a] Source # | |||||
| RealFloat a => Floating (Log a) Source # | |||||
Defined in Numeric.Log Methods exp :: Log a -> Log a Source # log :: Log a -> Log a Source # sqrt :: Log a -> Log a Source # (**) :: Log a -> Log a -> Log a Source # logBase :: Log a -> Log a -> Log a Source # sin :: Log a -> Log a Source # cos :: Log a -> Log a Source # tan :: Log a -> Log a Source # asin :: Log a -> Log a Source # acos :: Log a -> Log a Source # atan :: Log a -> Log a Source # sinh :: Log a -> Log a Source # cosh :: Log a -> Log a Source # tanh :: Log a -> Log a Source # asinh :: Log a -> Log a Source # acosh :: Log a -> Log a Source # atanh :: Log a -> Log a Source # log1p :: Log a -> Log a Source # expm1 :: Log a -> Log a Source # | |||||
| Storable a => Storable (Log a) Source # | |||||
Defined in Numeric.Log Methods sizeOf :: Log a -> Int Source # alignment :: Log a -> Int Source # peekElemOff :: Ptr (Log a) -> Int -> IO (Log a) Source # pokeElemOff :: Ptr (Log a) -> Int -> Log a -> IO () Source # peekByteOff :: Ptr b -> Int -> IO (Log a) Source # pokeByteOff :: Ptr b -> Int -> Log a -> IO () Source # | |||||
| Generic (Log a) Source # | |||||
Defined in Numeric.Log Associated Types
| |||||
| RealFloat a => Num (Log a) Source # | |||||
| (Floating a, Read a) => Read (Log a) Source # | |||||
| RealFloat a => Fractional (Log a) Source # | |||||
| (RealFloat a, Ord a) => Real (Log a) Source # | |||||
Defined in Numeric.Log Methods toRational :: Log a -> Rational Source # | |||||
| RealFloat a => RealFrac (Log a) Source # | |||||
| (Floating a, Show a) => Show (Log a) Source # | |||||
| Eq a => Eq (Log a) Source # | |||||
| Ord a => Ord (Log a) Source # | |||||
Defined in Numeric.Log | |||||
| Hashable a => Hashable (Log a) Source # | |||||
| (RealFloat a, Unbox a) => Unbox (Log a) Source # | |||||
Defined in Numeric.Log | |||||
| newtype MVector s (Log a) Source # | |||||
Defined in Numeric.Log | |||||
| type Rep (Log a) Source # | |||||
Defined in Numeric.Log | |||||
| newtype Vector (Log a) Source # | |||||
Defined in Numeric.Log | |||||
sum :: (RealFloat a, Foldable f) => f (Log a) -> Log a Source #
Efficiently and accurately compute the sum of a set of log-domain numbers
While folding with (+) accomplishes the same end, it requires an
additional n-2 logarithms to sum n terms. In addition,
here we introduce fewer opportunities for round-off error.
While for small quantities the naive sum accumulates error,
>>>let xs = Prelude.replicate 40000 (Exp 1e-4) :: [Log Float]>>>Prelude.sum xs ~= 4.00e4True
This sum gives a more accurate result,
>>>Numeric.Log.sum xs ~= 4.00e4True
NB: This does require two passes over the data.