{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Numeric.AD.Internal.Type
( AD(..)
) where
import Data.Number.Erf
import Numeric.AD.Mode
import Data.Typeable
newtype AD s a = AD { forall s a. AD s a -> a
runAD :: a }
deriving (AD s a -> AD s a -> Bool
(AD s a -> AD s a -> Bool)
-> (AD s a -> AD s a -> Bool) -> Eq (AD s a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall s a. Eq a => AD s a -> AD s a -> Bool
$c== :: forall s a. Eq a => AD s a -> AD s a -> Bool
== :: AD s a -> AD s a -> Bool
$c/= :: forall s a. Eq a => AD s a -> AD s a -> Bool
/= :: AD s a -> AD s a -> Bool
Eq,Eq (AD s a)
Eq (AD s a) =>
(AD s a -> AD s a -> Ordering)
-> (AD s a -> AD s a -> Bool)
-> (AD s a -> AD s a -> Bool)
-> (AD s a -> AD s a -> Bool)
-> (AD s a -> AD s a -> Bool)
-> (AD s a -> AD s a -> AD s a)
-> (AD s a -> AD s a -> AD s a)
-> Ord (AD s a)
AD s a -> AD s a -> Bool
AD s a -> AD s a -> Ordering
AD s a -> AD s a -> AD s a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall s a. Ord a => Eq (AD s a)
forall s a. Ord a => AD s a -> AD s a -> Bool
forall s a. Ord a => AD s a -> AD s a -> Ordering
forall s a. Ord a => AD s a -> AD s a -> AD s a
$ccompare :: forall s a. Ord a => AD s a -> AD s a -> Ordering
compare :: AD s a -> AD s a -> Ordering
$c< :: forall s a. Ord a => AD s a -> AD s a -> Bool
< :: AD s a -> AD s a -> Bool
$c<= :: forall s a. Ord a => AD s a -> AD s a -> Bool
<= :: AD s a -> AD s a -> Bool
$c> :: forall s a. Ord a => AD s a -> AD s a -> Bool
> :: AD s a -> AD s a -> Bool
$c>= :: forall s a. Ord a => AD s a -> AD s a -> Bool
>= :: AD s a -> AD s a -> Bool
$cmax :: forall s a. Ord a => AD s a -> AD s a -> AD s a
max :: AD s a -> AD s a -> AD s a
$cmin :: forall s a. Ord a => AD s a -> AD s a -> AD s a
min :: AD s a -> AD s a -> AD s a
Ord,Int -> AD s a -> ShowS
[AD s a] -> ShowS
AD s a -> String
(Int -> AD s a -> ShowS)
-> (AD s a -> String) -> ([AD s a] -> ShowS) -> Show (AD s a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall s a. Show a => Int -> AD s a -> ShowS
forall s a. Show a => [AD s a] -> ShowS
forall s a. Show a => AD s a -> String
$cshowsPrec :: forall s a. Show a => Int -> AD s a -> ShowS
showsPrec :: Int -> AD s a -> ShowS
$cshow :: forall s a. Show a => AD s a -> String
show :: AD s a -> String
$cshowList :: forall s a. Show a => [AD s a] -> ShowS
showList :: [AD s a] -> ShowS
Show,ReadPrec [AD s a]
ReadPrec (AD s a)
Int -> ReadS (AD s a)
ReadS [AD s a]
(Int -> ReadS (AD s a))
-> ReadS [AD s a]
-> ReadPrec (AD s a)
-> ReadPrec [AD s a]
-> Read (AD s a)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall s a. Read a => ReadPrec [AD s a]
forall s a. Read a => ReadPrec (AD s a)
forall s a. Read a => Int -> ReadS (AD s a)
forall s a. Read a => ReadS [AD s a]
$creadsPrec :: forall s a. Read a => Int -> ReadS (AD s a)
readsPrec :: Int -> ReadS (AD s a)
$creadList :: forall s a. Read a => ReadS [AD s a]
readList :: ReadS [AD s a]
$creadPrec :: forall s a. Read a => ReadPrec (AD s a)
readPrec :: ReadPrec (AD s a)
$creadListPrec :: forall s a. Read a => ReadPrec [AD s a]
readListPrec :: ReadPrec [AD s a]
Read,AD s a
AD s a -> AD s a -> Bounded (AD s a)
forall a. a -> a -> Bounded a
forall s a. Bounded a => AD s a
$cminBound :: forall s a. Bounded a => AD s a
minBound :: AD s a
$cmaxBound :: forall s a. Bounded a => AD s a
maxBound :: AD s a
Bounded,Integer -> AD s a
AD s a -> AD s a
AD s a -> AD s a -> AD s a
(AD s a -> AD s a -> AD s a)
-> (AD s a -> AD s a -> AD s a)
-> (AD s a -> AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (Integer -> AD s a)
-> Num (AD s a)
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
forall s a. Num a => Integer -> AD s a
forall s a. Num a => AD s a -> AD s a
forall s a. Num a => AD s a -> AD s a -> AD s a
$c+ :: forall s a. Num a => AD s a -> AD s a -> AD s a
+ :: AD s a -> AD s a -> AD s a
$c- :: forall s a. Num a => AD s a -> AD s a -> AD s a
- :: AD s a -> AD s a -> AD s a
$c* :: forall s a. Num a => AD s a -> AD s a -> AD s a
* :: AD s a -> AD s a -> AD s a
$cnegate :: forall s a. Num a => AD s a -> AD s a
negate :: AD s a -> AD s a
$cabs :: forall s a. Num a => AD s a -> AD s a
abs :: AD s a -> AD s a
$csignum :: forall s a. Num a => AD s a -> AD s a
signum :: AD s a -> AD s a
$cfromInteger :: forall s a. Num a => Integer -> AD s a
fromInteger :: Integer -> AD s a
Num,Num (AD s a)
Ord (AD s a)
(Num (AD s a), Ord (AD s a)) =>
(AD s a -> Rational) -> Real (AD s a)
AD s a -> Rational
forall a. (Num a, Ord a) => (a -> Rational) -> Real a
forall s a. Real a => Num (AD s a)
forall s a. Real a => Ord (AD s a)
forall s a. Real a => AD s a -> Rational
$ctoRational :: forall s a. Real a => AD s a -> Rational
toRational :: AD s a -> Rational
Real,Num (AD s a)
Num (AD s a) =>
(AD s a -> AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (Rational -> AD s a)
-> Fractional (AD s a)
Rational -> AD s a
AD s a -> AD s a
AD s a -> AD s a -> AD s a
forall a.
Num a =>
(a -> a -> a) -> (a -> a) -> (Rational -> a) -> Fractional a
forall s a. Fractional a => Num (AD s a)
forall s a. Fractional a => Rational -> AD s a
forall s a. Fractional a => AD s a -> AD s a
forall s a. Fractional a => AD s a -> AD s a -> AD s a
$c/ :: forall s a. Fractional a => AD s a -> AD s a -> AD s a
/ :: AD s a -> AD s a -> AD s a
$crecip :: forall s a. Fractional a => AD s a -> AD s a
recip :: AD s a -> AD s a
$cfromRational :: forall s a. Fractional a => Rational -> AD s a
fromRational :: Rational -> AD s a
Fractional,Fractional (AD s a)
AD s a
Fractional (AD s a) =>
AD s a
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a -> AD s a)
-> (AD s a -> AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> Floating (AD s a)
AD s a -> AD s a
AD s a -> AD s a -> AD s a
forall a.
Fractional a =>
a
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> Floating a
forall s a. Floating a => Fractional (AD s a)
forall s a. Floating a => AD s a
forall s a. Floating a => AD s a -> AD s a
forall s a. Floating a => AD s a -> AD s a -> AD s a
$cpi :: forall s a. Floating a => AD s a
pi :: AD s a
$cexp :: forall s a. Floating a => AD s a -> AD s a
exp :: AD s a -> AD s a
$clog :: forall s a. Floating a => AD s a -> AD s a
log :: AD s a -> AD s a
$csqrt :: forall s a. Floating a => AD s a -> AD s a
sqrt :: AD s a -> AD s a
$c** :: forall s a. Floating a => AD s a -> AD s a -> AD s a
** :: AD s a -> AD s a -> AD s a
$clogBase :: forall s a. Floating a => AD s a -> AD s a -> AD s a
logBase :: AD s a -> AD s a -> AD s a
$csin :: forall s a. Floating a => AD s a -> AD s a
sin :: AD s a -> AD s a
$ccos :: forall s a. Floating a => AD s a -> AD s a
cos :: AD s a -> AD s a
$ctan :: forall s a. Floating a => AD s a -> AD s a
tan :: AD s a -> AD s a
$casin :: forall s a. Floating a => AD s a -> AD s a
asin :: AD s a -> AD s a
$cacos :: forall s a. Floating a => AD s a -> AD s a
acos :: AD s a -> AD s a
$catan :: forall s a. Floating a => AD s a -> AD s a
atan :: AD s a -> AD s a
$csinh :: forall s a. Floating a => AD s a -> AD s a
sinh :: AD s a -> AD s a
$ccosh :: forall s a. Floating a => AD s a -> AD s a
cosh :: AD s a -> AD s a
$ctanh :: forall s a. Floating a => AD s a -> AD s a
tanh :: AD s a -> AD s a
$casinh :: forall s a. Floating a => AD s a -> AD s a
asinh :: AD s a -> AD s a
$cacosh :: forall s a. Floating a => AD s a -> AD s a
acosh :: AD s a -> AD s a
$catanh :: forall s a. Floating a => AD s a -> AD s a
atanh :: AD s a -> AD s a
$clog1p :: forall s a. Floating a => AD s a -> AD s a
log1p :: AD s a -> AD s a
$cexpm1 :: forall s a. Floating a => AD s a -> AD s a
expm1 :: AD s a -> AD s a
$clog1pexp :: forall s a. Floating a => AD s a -> AD s a
log1pexp :: AD s a -> AD s a
$clog1mexp :: forall s a. Floating a => AD s a -> AD s a
log1mexp :: AD s a -> AD s a
Floating,Int -> AD s a
AD s a -> Int
AD s a -> [AD s a]
AD s a -> AD s a
AD s a -> AD s a -> [AD s a]
AD s a -> AD s a -> AD s a -> [AD s a]
(AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (Int -> AD s a)
-> (AD s a -> Int)
-> (AD s a -> [AD s a])
-> (AD s a -> AD s a -> [AD s a])
-> (AD s a -> AD s a -> [AD s a])
-> (AD s a -> AD s a -> AD s a -> [AD s a])
-> Enum (AD s a)
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
forall s a. Enum a => Int -> AD s a
forall s a. Enum a => AD s a -> Int
forall s a. Enum a => AD s a -> [AD s a]
forall s a. Enum a => AD s a -> AD s a
forall s a. Enum a => AD s a -> AD s a -> [AD s a]
forall s a. Enum a => AD s a -> AD s a -> AD s a -> [AD s a]
$csucc :: forall s a. Enum a => AD s a -> AD s a
succ :: AD s a -> AD s a
$cpred :: forall s a. Enum a => AD s a -> AD s a
pred :: AD s a -> AD s a
$ctoEnum :: forall s a. Enum a => Int -> AD s a
toEnum :: Int -> AD s a
$cfromEnum :: forall s a. Enum a => AD s a -> Int
fromEnum :: AD s a -> Int
$cenumFrom :: forall s a. Enum a => AD s a -> [AD s a]
enumFrom :: AD s a -> [AD s a]
$cenumFromThen :: forall s a. Enum a => AD s a -> AD s a -> [AD s a]
enumFromThen :: AD s a -> AD s a -> [AD s a]
$cenumFromTo :: forall s a. Enum a => AD s a -> AD s a -> [AD s a]
enumFromTo :: AD s a -> AD s a -> [AD s a]
$cenumFromThenTo :: forall s a. Enum a => AD s a -> AD s a -> AD s a -> [AD s a]
enumFromThenTo :: AD s a -> AD s a -> AD s a -> [AD s a]
Enum,Fractional (AD s a)
Real (AD s a)
(Real (AD s a), Fractional (AD s a)) =>
(forall b. Integral b => AD s a -> (b, AD s a))
-> (forall b. Integral b => AD s a -> b)
-> (forall b. Integral b => AD s a -> b)
-> (forall b. Integral b => AD s a -> b)
-> (forall b. Integral b => AD s a -> b)
-> RealFrac (AD s a)
forall b. Integral b => AD s a -> b
forall b. Integral b => AD s a -> (b, AD s a)
forall a.
(Real a, Fractional a) =>
(forall b. Integral b => a -> (b, a))
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> RealFrac a
forall s a. RealFrac a => Fractional (AD s a)
forall s a. RealFrac a => Real (AD s a)
forall s a b. (RealFrac a, Integral b) => AD s a -> b
forall s a b. (RealFrac a, Integral b) => AD s a -> (b, AD s a)
$cproperFraction :: forall s a b. (RealFrac a, Integral b) => AD s a -> (b, AD s a)
properFraction :: forall b. Integral b => AD s a -> (b, AD s a)
$ctruncate :: forall s a b. (RealFrac a, Integral b) => AD s a -> b
truncate :: forall b. Integral b => AD s a -> b
$cround :: forall s a b. (RealFrac a, Integral b) => AD s a -> b
round :: forall b. Integral b => AD s a -> b
$cceiling :: forall s a b. (RealFrac a, Integral b) => AD s a -> b
ceiling :: forall b. Integral b => AD s a -> b
$cfloor :: forall s a b. (RealFrac a, Integral b) => AD s a -> b
floor :: forall b. Integral b => AD s a -> b
RealFrac,Floating (AD s a)
RealFrac (AD s a)
(RealFrac (AD s a), Floating (AD s a)) =>
(AD s a -> Integer)
-> (AD s a -> Int)
-> (AD s a -> (Int, Int))
-> (AD s a -> (Integer, Int))
-> (Integer -> Int -> AD s a)
-> (AD s a -> Int)
-> (AD s a -> AD s a)
-> (Int -> AD s a -> AD s a)
-> (AD s a -> Bool)
-> (AD s a -> Bool)
-> (AD s a -> Bool)
-> (AD s a -> Bool)
-> (AD s a -> Bool)
-> (AD s a -> AD s a -> AD s a)
-> RealFloat (AD s a)
Int -> AD s a -> AD s a
Integer -> Int -> AD s a
AD s a -> Bool
AD s a -> Int
AD s a -> Integer
AD s a -> (Int, Int)
AD s a -> (Integer, Int)
AD s a -> AD s a
AD s a -> AD s a -> AD s a
forall a.
(RealFrac a, Floating a) =>
(a -> Integer)
-> (a -> Int)
-> (a -> (Int, Int))
-> (a -> (Integer, Int))
-> (Integer -> Int -> a)
-> (a -> Int)
-> (a -> a)
-> (Int -> a -> a)
-> (a -> Bool)
-> (a -> Bool)
-> (a -> Bool)
-> (a -> Bool)
-> (a -> Bool)
-> (a -> a -> a)
-> RealFloat a
forall s a. RealFloat a => Floating (AD s a)
forall s a. RealFloat a => RealFrac (AD s a)
forall s a. RealFloat a => Int -> AD s a -> AD s a
forall s a. RealFloat a => Integer -> Int -> AD s a
forall s a. RealFloat a => AD s a -> Bool
forall s a. RealFloat a => AD s a -> Int
forall s a. RealFloat a => AD s a -> Integer
forall s a. RealFloat a => AD s a -> (Int, Int)
forall s a. RealFloat a => AD s a -> (Integer, Int)
forall s a. RealFloat a => AD s a -> AD s a
forall s a. RealFloat a => AD s a -> AD s a -> AD s a
$cfloatRadix :: forall s a. RealFloat a => AD s a -> Integer
floatRadix :: AD s a -> Integer
$cfloatDigits :: forall s a. RealFloat a => AD s a -> Int
floatDigits :: AD s a -> Int
$cfloatRange :: forall s a. RealFloat a => AD s a -> (Int, Int)
floatRange :: AD s a -> (Int, Int)
$cdecodeFloat :: forall s a. RealFloat a => AD s a -> (Integer, Int)
decodeFloat :: AD s a -> (Integer, Int)
$cencodeFloat :: forall s a. RealFloat a => Integer -> Int -> AD s a
encodeFloat :: Integer -> Int -> AD s a
$cexponent :: forall s a. RealFloat a => AD s a -> Int
exponent :: AD s a -> Int
$csignificand :: forall s a. RealFloat a => AD s a -> AD s a
significand :: AD s a -> AD s a
$cscaleFloat :: forall s a. RealFloat a => Int -> AD s a -> AD s a
scaleFloat :: Int -> AD s a -> AD s a
$cisNaN :: forall s a. RealFloat a => AD s a -> Bool
isNaN :: AD s a -> Bool
$cisInfinite :: forall s a. RealFloat a => AD s a -> Bool
isInfinite :: AD s a -> Bool
$cisDenormalized :: forall s a. RealFloat a => AD s a -> Bool
isDenormalized :: AD s a -> Bool
$cisNegativeZero :: forall s a. RealFloat a => AD s a -> Bool
isNegativeZero :: AD s a -> Bool
$cisIEEE :: forall s a. RealFloat a => AD s a -> Bool
isIEEE :: AD s a -> Bool
$catan2 :: forall s a. RealFloat a => AD s a -> AD s a -> AD s a
atan2 :: AD s a -> AD s a -> AD s a
RealFloat,Floating (AD s a)
Floating (AD s a) =>
(AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> (AD s a -> AD s a)
-> Erf (AD s a)
AD s a -> AD s a
forall a.
Floating a =>
(a -> a) -> (a -> a) -> (a -> a) -> (a -> a) -> Erf a
forall s a. Erf a => Floating (AD s a)
forall s a. Erf a => AD s a -> AD s a
$cerf :: forall s a. Erf a => AD s a -> AD s a
erf :: AD s a -> AD s a
$cerfc :: forall s a. Erf a => AD s a -> AD s a
erfc :: AD s a -> AD s a
$cerfcx :: forall s a. Erf a => AD s a -> AD s a
erfcx :: AD s a -> AD s a
$cnormcdf :: forall s a. Erf a => AD s a -> AD s a
normcdf :: AD s a -> AD s a
Erf,Floating (AD s a)
Floating (AD s a) =>
(AD s a -> AD s a)
-> (AD s a -> AD s a) -> (AD s a -> AD s a) -> InvErf (AD s a)
AD s a -> AD s a
forall a.
Floating a =>
(a -> a) -> (a -> a) -> (a -> a) -> InvErf a
forall s a. InvErf a => Floating (AD s a)
forall s a. InvErf a => AD s a -> AD s a
$cinverf :: forall s a. InvErf a => AD s a -> AD s a
inverf :: AD s a -> AD s a
$cinverfc :: forall s a. InvErf a => AD s a -> AD s a
inverfc :: AD s a -> AD s a
$cinvnormcdf :: forall s a. InvErf a => AD s a -> AD s a
invnormcdf :: AD s a -> AD s a
InvErf,Typeable)
instance Mode a => Mode (AD s a) where
type Scalar (AD s a) = Scalar a
isKnownConstant :: AD s a -> Bool
isKnownConstant = a -> Bool
forall t. Mode t => t -> Bool
isKnownConstant (a -> Bool) -> (AD s a -> a) -> AD s a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AD s a -> a
forall s a. AD s a -> a
runAD
asKnownConstant :: AD s a -> Maybe (Scalar (AD s a))
asKnownConstant = a -> Maybe (Scalar a)
forall t. Mode t => t -> Maybe (Scalar t)
asKnownConstant (a -> Maybe (Scalar a))
-> (AD s a -> a) -> AD s a -> Maybe (Scalar a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AD s a -> a
forall s a. AD s a -> a
runAD
isKnownZero :: AD s a -> Bool
isKnownZero = a -> Bool
forall t. Mode t => t -> Bool
isKnownZero (a -> Bool) -> (AD s a -> a) -> AD s a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AD s a -> a
forall s a. AD s a -> a
runAD
zero :: AD s a
zero = a -> AD s a
forall s a. a -> AD s a
AD a
forall t. Mode t => t
zero
auto :: Scalar (AD s a) -> AD s a
auto = a -> AD s a
forall s a. a -> AD s a
AD (a -> AD s a) -> (Scalar a -> a) -> Scalar a -> AD s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Scalar a -> a
forall t. Mode t => Scalar t -> t
auto
AD a
a ^* :: AD s a -> Scalar (AD s a) -> AD s a
^* Scalar (AD s a)
b = a -> AD s a
forall s a. a -> AD s a
AD (a
a a -> Scalar a -> a
forall t. Mode t => t -> Scalar t -> t
^* Scalar a
Scalar (AD s a)
b)
Scalar (AD s a)
a *^ :: Scalar (AD s a) -> AD s a -> AD s a
*^ AD a
b = a -> AD s a
forall s a. a -> AD s a
AD (Scalar a
Scalar (AD s a)
a Scalar a -> a -> a
forall t. Mode t => Scalar t -> t -> t
*^ a
b)
AD a
a ^/ :: Fractional (Scalar (AD s a)) => AD s a -> Scalar (AD s a) -> AD s a
^/ Scalar (AD s a)
b = a -> AD s a
forall s a. a -> AD s a
AD (a
a a -> Scalar a -> a
forall t. (Mode t, Fractional (Scalar t)) => t -> Scalar t -> t
^/ Scalar a
Scalar (AD s a)
b)