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