Portability | GHC only |
---|---|

Stability | experimental |

Maintainer | ekmett@gmail.com |

Safe Haskell | None |

- class Lifted t => Mode t where
- one :: (Mode t, Num a) => t a
- class (Mode t, Mode (D t)) => Jacobian t where
- type D t :: * -> *
- unary :: Num a => (a -> a) -> D t a -> t a -> t a
- lift1 :: Num a => (a -> a) -> (D t a -> D t a) -> t a -> t a
- lift1_ :: Num a => (a -> a) -> (D t a -> D t a -> D t a) -> t a -> t a
- binary :: Num a => (a -> a -> a) -> D t a -> D t a -> t a -> t a -> t a
- lift2 :: Num a => (a -> a -> a) -> (D t a -> D t a -> (D t a, D t a)) -> t a -> t a -> t a
- lift2_ :: Num a => (a -> a -> a) -> (D t a -> D t a -> D t a -> (D t a, D t a)) -> t a -> t a -> t a

- class Primal t where
- deriveLifted :: ([Q Pred] -> [Q Pred]) -> Q Type -> Q [Dec]
- deriveNumeric :: ([Q Pred] -> [Q Pred]) -> Q Type -> Q [Dec]
- class Lifted t where
- showsPrec1 :: (Num a, Show a) => Int -> t a -> ShowS
- (==!) :: (Num a, Eq a) => t a -> t a -> Bool
- compare1 :: (Num a, Ord a) => t a -> t a -> Ordering
- fromInteger1 :: Num a => Integer -> t a
- (+!), (*!), (-!) :: Num a => t a -> t a -> t a
- negate1, signum1, abs1 :: Num a => t a -> t a
- (/!) :: Fractional a => t a -> t a -> t a
- recip1 :: Fractional a => t a -> t a
- fromRational1 :: Fractional a => Rational -> t a
- toRational1 :: Real a => t a -> Rational
- pi1 :: Floating a => t a
- exp1, sqrt1, log1 :: Floating a => t a -> t a
- (**!), logBase1 :: Floating a => t a -> t a -> t a
- sin1, atan1, acos1, asin1, tan1, cos1 :: Floating a => t a -> t a
- sinh1, atanh1, acosh1, asinh1, tanh1, cosh1 :: Floating a => t a -> t a
- properFraction1 :: (RealFrac a, Integral b) => t a -> (b, t a)
- truncate1, floor1, ceiling1, round1 :: (RealFrac a, Integral b) => t a -> b
- floatRadix1 :: RealFloat a => t a -> Integer
- floatDigits1 :: RealFloat a => t a -> Int
- floatRange1 :: RealFloat a => t a -> (Int, Int)
- decodeFloat1 :: RealFloat a => t a -> (Integer, Int)
- encodeFloat1 :: RealFloat a => Integer -> Int -> t a
- exponent1 :: RealFloat a => t a -> Int
- significand1 :: RealFloat a => t a -> t a
- scaleFloat1 :: RealFloat a => Int -> t a -> t a
- isNaN1, isIEEE1, isNegativeZero1, isDenormalized1, isInfinite1 :: RealFloat a => t a -> Bool
- atan21 :: RealFloat a => t a -> t a -> t a
- succ1, pred1 :: (Num a, Enum a) => t a -> t a
- toEnum1 :: (Num a, Enum a) => Int -> t a
- fromEnum1 :: (Num a, Enum a) => t a -> Int
- enumFrom1 :: (Num a, Enum a) => t a -> [t a]
- enumFromThen1 :: (Num a, Enum a) => t a -> t a -> [t a]
- enumFromTo1 :: (Num a, Enum a) => t a -> t a -> [t a]
- enumFromThenTo1 :: (Num a, Enum a) => t a -> t a -> t a -> [t a]
- minBound1 :: (Num a, Bounded a) => t a
- maxBound1 :: (Num a, Bounded a) => t a

- class Iso a b where

# AD modes

class Lifted t => Mode t whereSource

isKnownConstant :: t a -> BoolSource

allowed to return False for items with a zero derivative, but we'll give more NaNs than strictly necessary

isKnownZero :: Num a => t a -> BoolSource

allowed to return False for zero, but we give more NaN's than strictly necessary then

lift :: Num a => a -> t aSource

Embed a constant

(<+>) :: Num a => t a -> t a -> t aSource

Vector sum

(*^) :: Num a => a -> t a -> t aSource

Scalar-vector multiplication

(^*) :: Num a => t a -> a -> t aSource

Vector-scalar multiplication

(^/) :: Fractional a => t a -> a -> t aSource

Scalar division

(<**>) :: Floating a => t a -> t a -> t aSource

Exponentiation, this should be overloaded if you can figure out anything about what is constant!

'zero' = 'lift' 0

# Automatically Deriving AD

class (Mode t, Mode (D t)) => Jacobian t whereSource

`Jacobian`

is used by `deriveMode`

but is not exposed
via `Mode`

to prevent its abuse by end users
via the `AD`

data type.

unary :: Num a => (a -> a) -> D t a -> t a -> t aSource

lift1 :: Num a => (a -> a) -> (D t a -> D t a) -> t a -> t aSource

lift1_ :: Num a => (a -> a) -> (D t a -> D t a -> D t a) -> t a -> t aSource

binary :: Num a => (a -> a -> a) -> D t a -> D t a -> t a -> t a -> t aSource

lift2 :: Num a => (a -> a -> a) -> (D t a -> D t a -> (D t a, D t a)) -> t a -> t a -> t aSource

lift2_ :: Num a => (a -> a -> a) -> (D t a -> D t a -> D t a -> (D t a, D t a)) -> t a -> t a -> t aSource

`Primal`

is used by `deriveMode`

but is not exposed
via the `Mode`

class to prevent its abuse by end users
via the AD data type.

It provides direct access to the result, stripped of its derivative information, but this is unsafe in general as (lift . primal) would discard derivative information. The end user is protected from accidentally using this function by the universal quantification on the various combinators we expose.

deriveLifted :: ([Q Pred] -> [Q Pred]) -> Q Type -> Q [Dec]Source

provides
`deriveLifted`

t

instance Lifted $t

given supplied instances for

instance Lifted $t => Primal $t where ... instance Lifted $t => Jacobian $t where ...

The seemingly redundant

constraints are caused by Template Haskell staging restrictions.
`Lifted`

$t

deriveNumeric :: ([Q Pred] -> [Q Pred]) -> Q Type -> Q [Dec]Source

provides the following instances:
`deriveNumeric`

f g

instance ('Lifted' $f, 'Num' a, 'Enum' a) => 'Enum' ($g a) instance ('Lifted' $f, 'Num' a, 'Eq' a) => 'Eq' ($g a) instance ('Lifted' $f, 'Num' a, 'Ord' a) => 'Ord' ($g a) instance ('Lifted' $f, 'Num' a, 'Bounded' a) => 'Bounded' ($g a)

instance ('Lifted' $f, 'Show' a) => 'Show' ($g a) instance ('Lifted' $f, 'Num' a) => 'Num' ($g a) instance ('Lifted' $f, 'Fractional' a) => 'Fractional' ($g a) instance ('Lifted' $f, 'Floating' a) => 'Floating' ($g a) instance ('Lifted' $f, 'RealFloat' a) => 'RealFloat' ($g a) instance ('Lifted' $f, 'RealFrac' a) => 'RealFrac' ($g a) instance ('Lifted' $f, 'Real' a) => 'Real' ($g a)

showsPrec1 :: (Num a, Show a) => Int -> t a -> ShowSSource

(==!) :: (Num a, Eq a) => t a -> t a -> BoolSource

compare1 :: (Num a, Ord a) => t a -> t a -> OrderingSource

fromInteger1 :: Num a => Integer -> t aSource

(+!), (*!), (-!) :: Num a => t a -> t a -> t aSource

negate1, signum1, abs1 :: Num a => t a -> t aSource

(/!) :: Fractional a => t a -> t a -> t aSource

recip1 :: Fractional a => t a -> t aSource

fromRational1 :: Fractional a => Rational -> t aSource

toRational1 :: Real a => t a -> RationalSource

pi1 :: Floating a => t aSource

exp1, sqrt1, log1 :: Floating a => t a -> t aSource

(**!), logBase1 :: Floating a => t a -> t a -> t aSource

sin1, atan1, acos1, asin1, tan1, cos1 :: Floating a => t a -> t aSource

sinh1, atanh1, acosh1, asinh1, tanh1, cosh1 :: Floating a => t a -> t aSource

properFraction1 :: (RealFrac a, Integral b) => t a -> (b, t a)Source

truncate1, floor1, ceiling1, round1 :: (RealFrac a, Integral b) => t a -> bSource

floatRadix1 :: RealFloat a => t a -> IntegerSource

floatDigits1 :: RealFloat a => t a -> IntSource

floatRange1 :: RealFloat a => t a -> (Int, Int)Source

decodeFloat1 :: RealFloat a => t a -> (Integer, Int)Source

encodeFloat1 :: RealFloat a => Integer -> Int -> t aSource

exponent1 :: RealFloat a => t a -> IntSource

significand1 :: RealFloat a => t a -> t aSource

scaleFloat1 :: RealFloat a => Int -> t a -> t aSource

isNaN1, isIEEE1, isNegativeZero1, isDenormalized1, isInfinite1 :: RealFloat a => t a -> BoolSource

atan21 :: RealFloat a => t a -> t a -> t aSource

succ1, pred1 :: (Num a, Enum a) => t a -> t aSource

toEnum1 :: (Num a, Enum a) => Int -> t aSource

fromEnum1 :: (Num a, Enum a) => t a -> IntSource

enumFrom1 :: (Num a, Enum a) => t a -> [t a]Source

enumFromThen1 :: (Num a, Enum a) => t a -> t a -> [t a]Source

enumFromTo1 :: (Num a, Enum a) => t a -> t a -> [t a]Source

enumFromThenTo1 :: (Num a, Enum a) => t a -> t a -> t a -> [t a]Source