log-domain-0.13.2: Log-domain arithmetic
Copyright(c) Edward Kmett 2013-2015
LicenseBSD3
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellTrustworthy
LanguageHaskell2010

Numeric.Log

Description

 
Synopsis

Documentation

newtype Log a Source #

Log-domain Float and Double values.

Constructors

Exp 

Fields

Instances

Instances details
Foldable Log Source # 
Instance details

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 #

sum :: Num a => Log a -> a Source #

product :: Num a => Log a -> a Source #

Foldable1 Log Source # 
Instance details

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 #

head :: Log a -> a Source #

last :: 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 # 
Instance details

Defined in Numeric.Log

Methods

liftEq :: (a -> b -> Bool) -> Log a -> Log b -> Bool Source #

Traversable Log Source # 
Instance details

Defined in Numeric.Log

Methods

traverse :: Applicative f => (a -> f b) -> Log a -> f (Log b) Source #

sequenceA :: Applicative f => Log (f a) -> f (Log a) Source #

mapM :: Monad m => (a -> m b) -> Log a -> m (Log b) Source #

sequence :: Monad m => Log (m a) -> m (Log a) Source #

Applicative Log Source # 
Instance details

Defined in Numeric.Log

Methods

pure :: a -> Log a Source #

(<*>) :: Log (a -> b) -> Log a -> Log b Source #

liftA2 :: (a -> b -> c) -> Log a -> Log b -> Log c Source #

(*>) :: Log a -> Log b -> Log b Source #

(<*) :: Log a -> Log b -> Log a Source #

Functor Log Source # 
Instance details

Defined in Numeric.Log

Methods

fmap :: (a -> b) -> Log a -> Log b Source #

(<$) :: a -> Log b -> Log a Source #

Monad Log Source # 
Instance details

Defined in Numeric.Log

Methods

(>>=) :: Log a -> (a -> Log b) -> Log b Source #

(>>) :: Log a -> Log b -> Log b Source #

return :: a -> Log a Source #

Serial1 Log Source # 
Instance details

Defined in Numeric.Log

Methods

serializeWith :: MonadPut m => (a -> m ()) -> Log a -> m ()

deserializeWith :: MonadGet m => m a -> m (Log a)

Comonad Log Source # 
Instance details

Defined in Numeric.Log

Methods

extract :: Log a -> a Source #

duplicate :: Log a -> Log (Log a) Source #

extend :: (Log a -> b) -> Log a -> Log b Source #

ComonadApply Log Source # 
Instance details

Defined in Numeric.Log

Methods

(<@>) :: Log (a -> b) -> Log a -> Log b Source #

(@>) :: Log a -> Log b -> Log b Source #

(<@) :: Log a -> Log b -> Log a Source #

Distributive Log Source # 
Instance details

Defined in Numeric.Log

Methods

distribute :: Functor f => f (Log a) -> Log (f a) Source #

collect :: Functor f => (a -> Log b) -> f a -> Log (f b) Source #

distributeM :: Monad m => m (Log a) -> Log (m a) Source #

collectM :: Monad m => (a -> Log b) -> m a -> Log (m b) Source #

Hashable1 Log Source # 
Instance details

Defined in Numeric.Log

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> Log a -> Int Source #

Apply Log Source # 
Instance details

Defined in Numeric.Log

Methods

(<.>) :: Log (a -> b) -> Log a -> Log b Source #

(.>) :: Log a -> Log b -> Log b Source #

(<.) :: Log a -> Log b -> Log a Source #

liftF2 :: (a -> b -> c) -> Log a -> Log b -> Log c Source #

Bind Log Source # 
Instance details

Defined in Numeric.Log

Methods

(>>-) :: Log a -> (a -> Log b) -> Log b Source #

join :: Log (Log a) -> Log a Source #

Extend Log Source # 
Instance details

Defined in Numeric.Log

Methods

duplicated :: Log a -> Log (Log a) Source #

extended :: (Log a -> b) -> Log a -> Log b Source #

Traversable1 Log Source # 
Instance details

Defined in Numeric.Log

Methods

traverse1 :: Apply f => (a -> f b) -> Log a -> f (Log b) Source #

sequence1 :: Apply f => Log (f b) -> f (Log b) Source #

(RealFloat a, Unbox a) => Vector Vector (Log a) Source # 
Instance details

Defined in Numeric.Log

Unbox a => MVector MVector (Log a) Source # 
Instance details

Defined in Numeric.Log

Methods

basicLength :: MVector s (Log a) -> Int Source #

basicUnsafeSlice :: Int -> Int -> MVector s (Log a) -> MVector s (Log a) Source #

basicOverlaps :: MVector s (Log a) -> MVector s (Log a) -> Bool Source #

basicUnsafeNew :: Int -> ST s (MVector s (Log a)) Source #

basicInitialize :: MVector s (Log a) -> ST s () Source #

basicUnsafeReplicate :: Int -> Log a -> ST s (MVector s (Log a)) Source #

basicUnsafeRead :: MVector s (Log a) -> Int -> ST s (Log a) Source #

basicUnsafeWrite :: MVector s (Log a) -> Int -> Log a -> ST s () Source #

basicClear :: MVector s (Log a) -> ST s () Source #

basicSet :: MVector s (Log a) -> Log a -> ST s () Source #

basicUnsafeCopy :: MVector s (Log a) -> MVector s (Log a) -> ST s () Source #

basicUnsafeMove :: MVector s (Log a) -> MVector s (Log a) -> ST s () Source #

basicUnsafeGrow :: MVector s (Log a) -> Int -> ST s (MVector s (Log a)) Source #

Data a => Data (Log a) Source # 
Instance details

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 #

Storable a => Storable (Log a) Source # 
Instance details

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 #

peek :: Ptr (Log a) -> IO (Log a) Source #

poke :: Ptr (Log a) -> Log a -> IO () Source #

RealFloat a => Monoid (Log a) Source # 
Instance details

Defined in Numeric.Log

Methods

mempty :: Log a Source #

mappend :: Log a -> Log a -> Log a Source #

mconcat :: [Log a] -> Log a Source #

RealFloat a => Semigroup (Log a) Source # 
Instance details

Defined in Numeric.Log

Methods

(<>) :: Log a -> Log a -> Log a Source #

sconcat :: NonEmpty (Log a) -> Log a Source #

stimes :: Integral b => b -> Log a -> Log a Source #

(RealFloat a, Enum a) => Enum (Log a) Source # 
Instance details

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 # 
Instance details

Defined in Numeric.Log

Methods

pi :: Log a Source #

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 #

log1pexp :: Log a -> Log a Source #

log1mexp :: Log a -> Log a Source #

Generic (Log a) Source # 
Instance details

Defined in Numeric.Log

Associated Types

type Rep (Log a) :: Type -> Type Source #

Methods

from :: Log a -> Rep (Log a) x Source #

to :: Rep (Log a) x -> Log a Source #

RealFloat a => Num (Log a) Source # 
Instance details

Defined in Numeric.Log

Methods

(+) :: Log a -> Log a -> Log a Source #

(-) :: Log a -> Log a -> Log a Source #

(*) :: Log a -> Log a -> Log a Source #

negate :: Log a -> Log a Source #

abs :: Log a -> Log a Source #

signum :: Log a -> Log a Source #

fromInteger :: Integer -> Log a Source #

(Floating a, Read a) => Read (Log a) Source # 
Instance details

Defined in Numeric.Log

RealFloat a => Fractional (Log a) Source # 
Instance details

Defined in Numeric.Log

Methods

(/) :: Log a -> Log a -> Log a Source #

recip :: Log a -> Log a Source #

fromRational :: Rational -> Log a Source #

(RealFloat a, Ord a) => Real (Log a) Source # 
Instance details

Defined in Numeric.Log

Methods

toRational :: Log a -> Rational Source #

RealFloat a => RealFrac (Log a) Source # 
Instance details

Defined in Numeric.Log

Methods

properFraction :: Integral b => Log a -> (b, Log a) Source #

truncate :: Integral b => Log a -> b Source #

round :: Integral b => Log a -> b Source #

ceiling :: Integral b => Log a -> b Source #

floor :: Integral b => Log a -> b Source #

(Floating a, Show a) => Show (Log a) Source # 
Instance details

Defined in Numeric.Log

Methods

showsPrec :: Int -> Log a -> ShowS Source #

show :: Log a -> String Source #

showList :: [Log a] -> ShowS Source #

Binary a => Binary (Log a) Source # 
Instance details

Defined in Numeric.Log

Methods

put :: Log a -> Put Source #

get :: Get (Log a) Source #

putList :: [Log a] -> Put Source #

Serial a => Serial (Log a) Source # 
Instance details

Defined in Numeric.Log

Methods

serialize :: MonadPut m => Log a -> m ()

deserialize :: MonadGet m => m (Log a)

Serialize a => Serialize (Log a) Source # 
Instance details

Defined in Numeric.Log

Methods

put :: Putter (Log a) Source #

get :: Get (Log a) Source #

NFData a => NFData (Log a) Source # 
Instance details

Defined in Numeric.Log

Methods

rnf :: Log a -> () Source #

Eq a => Eq (Log a) Source # 
Instance details

Defined in Numeric.Log

Methods

(==) :: Log a -> Log a -> Bool Source #

(/=) :: Log a -> Log a -> Bool Source #

Ord a => Ord (Log a) Source # 
Instance details

Defined in Numeric.Log

Methods

compare :: Log a -> Log a -> Ordering Source #

(<) :: Log a -> Log a -> Bool Source #

(<=) :: Log a -> Log a -> Bool Source #

(>) :: Log a -> Log a -> Bool Source #

(>=) :: Log a -> Log a -> Bool Source #

max :: Log a -> Log a -> Log a Source #

min :: Log a -> Log a -> Log a Source #

Hashable a => Hashable (Log a) Source # 
Instance details

Defined in Numeric.Log

Methods

hashWithSalt :: Int -> Log a -> Int Source #

hash :: Log a -> Int Source #

(RealFloat a, Unbox a) => Unbox (Log a) Source # 
Instance details

Defined in Numeric.Log

newtype MVector s (Log a) Source # 
Instance details

Defined in Numeric.Log

newtype MVector s (Log a) = MV_Log (MVector s a)
type Rep (Log a) Source # 
Instance details

Defined in Numeric.Log

type Rep (Log a) = D1 ('MetaData "Log" "Numeric.Log" "log-domain-0.13.2-9Ch0NQj5AVL3fEvVVOfXTo" 'True) (C1 ('MetaCons "Exp" 'PrefixI 'True) (S1 ('MetaSel ('Just "ln") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))
newtype Vector (Log a) Source # 
Instance details

Defined in Numeric.Log

newtype Vector (Log a) = V_Log (Vector a)

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.00e4
True

This sum gives a more accurate result,

>>> Numeric.Log.sum xs ~= 4.00e4
True

NB: This does require two passes over the data.