Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell98 |
Simple forward automatic differentiation. The main reason for supplying this module rather than using one of several similar alternatives available on Hackage is that they all seem to use the following implementation of differentiation of products (in our notation):
x * y = mkDif (val x * val y) (df 1 x * y + x * df 1 y)
This is elegant but exponential in the order of differentiation, and hence unsuitable for much of validated numerics, which often uses moderately high order derivatives.
In our implementation, high order derivatives are still slow, but not as bad.
Derivatives of order several hundred can be handled, but in type Double
this is often
useless; rounding errors dominate the result. In type IReal
, results are reliable, but the
deep nesting of the resulting expressions may lead to excessive precision requirements. Often
Rounded
is preferrable from an efficiency point of view.
No attempt is made to handle functions of several variables
- newtype Dif a = D [a]
- con :: Num a => a -> Dif a
- var :: Num a => a -> Dif a
- mkDif :: a -> Dif a -> Dif a
- val :: Num a => Dif a -> a
- fromDif :: Num a => Dif a -> [a]
- unDif :: (Num a, Num b) => (Dif a -> Dif b) -> a -> b
- df :: Int -> Dif a -> Dif a
- deriv :: (Num a, Num b) => Int -> (Dif a -> Dif b) -> a -> b
- derivs :: (Num a, Num b) => (Dif a -> Dif b) -> a -> [b]
- chain :: Num a => (a -> a) -> (Dif a -> Dif a) -> Dif a -> Dif a
- rchain :: Num a => (a -> a) -> (Dif a -> Dif a) -> Dif a -> Dif a
- r2chain :: Num a => (a -> a) -> (a -> a) -> (Dif a -> Dif a) -> (Dif a -> Dif a) -> Dif a -> Dif a
- convs :: Num t => [t] -> [t] -> [t]
Documentation
A Dif
value is an infinite list consisting of the values of an infinitely differentiable
function and all its derivatives, all evaluated at a common point. Polynomials are represented
by finite lists, omitting zero derivatives.
D [a] |
(Num a, Eq a) => Eq (Dif a) | |
(Floating a, Powers a) => Floating (Dif a) | |
(Fractional a, Powers a) => Fractional (Dif a) | |
Num a => Num (Dif a) | |
(Num a, Ord a) => Ord (Dif a) | |
Real a => Real (Dif a) | |
(Powers a, RealFloat a) => RealFloat (Dif a) | |
(Powers a, RealFrac a) => RealFrac (Dif a) | |
Show a => Show (Dif a) | |
(Num a, Powers a) => Powers (Dif a) | |
VarPrec a => VarPrec (Dif a) |
deriv :: (Num a, Num b) => Int -> (Dif a -> Dif b) -> a -> b Source
deriv n f is the n'th derivative of f (with derivative information omitted)
derivs :: (Num a, Num b) => (Dif a -> Dif b) -> a -> [b] Source
derivs f a is the list of allderivatives of f, evaluated at a.