{-# LANGUAGE Rank2Types #-}
-----------------------------------------------------------------------------
-- |
-- Copyright   : (c) Edward Kmett 2010-2021
-- License     : BSD3
-- Maintainer  : ekmett@gmail.com
-- Stability   : experimental
-- Portability : GHC only
--
-- Higher order derivatives via a \"dual number tower\".
--
-----------------------------------------------------------------------------
module Numeric.AD.Mode.Tower.Double
  ( AD
  , TowerDouble
  , auto
  -- * Taylor Series
  , taylor
  , taylor0
  -- * Maclaurin Series
  , maclaurin
  , maclaurin0
  -- * Derivatives
  , diff    -- first derivative of (Double -> a)
  , diff'   -- answer and first derivative of (Double -> a)
  , diffs   -- answer and all derivatives of (Double -> a)
  , diffs0  -- zero padded derivatives of (Double -> a)
  , diffsF  -- answer and all derivatives of (Double -> f a)
  , diffs0F -- zero padded derivatives of (Double -> f a)
  -- * Directional Derivatives
  , du      -- directional derivative of (Double -> a)
  , du'     -- answer and directional derivative of (Double -> a)
  , dus     -- answer and all directional derivatives of (Double -> a)
  , dus0    -- answer and all zero padded directional derivatives of (Double -> a)
  , duF     -- directional derivative of (Double -> f a)
  , duF'    -- answer and directional derivative of (Double -> f a)
  , dusF    -- answer and all directional derivatives of (Double -> f a)
  , dus0F   -- answer and all zero padded directional derivatives of (Double -> a)
  ) where

import qualified Numeric.AD.Rank1.Tower.Double as Rank1
import Numeric.AD.Internal.Tower.Double (TowerDouble)
import Numeric.AD.Internal.Type (AD(..))
import Numeric.AD.Mode

diffs :: (forall s. AD s TowerDouble -> AD s TowerDouble) -> Double -> [Double]
diffs :: (forall s. AD s TowerDouble -> AD s TowerDouble)
-> Double -> [Double]
diffs forall s. AD s TowerDouble -> AD s TowerDouble
f = (TowerDouble -> TowerDouble) -> Double -> [Double]
Rank1.diffs (forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. AD s TowerDouble -> AD s TowerDouble
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. a -> AD s a
AD)
{-# INLINE diffs #-}

diffs0 :: (forall s. AD s TowerDouble -> AD s TowerDouble) -> Double -> [Double]
diffs0 :: (forall s. AD s TowerDouble -> AD s TowerDouble)
-> Double -> [Double]
diffs0 forall s. AD s TowerDouble -> AD s TowerDouble
f = (TowerDouble -> TowerDouble) -> Double -> [Double]
Rank1.diffs0 (forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. AD s TowerDouble -> AD s TowerDouble
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. a -> AD s a
AD)
{-# INLINE diffs0 #-}

diffsF :: Functor f => (forall s. AD s TowerDouble -> f (AD s TowerDouble)) -> Double -> f [Double]
diffsF :: forall (f :: * -> *).
Functor f =>
(forall s. AD s TowerDouble -> f (AD s TowerDouble))
-> Double -> f [Double]
diffsF forall s. AD s TowerDouble -> f (AD s TowerDouble)
f = forall (f :: * -> *).
Functor f =>
(TowerDouble -> f TowerDouble) -> Double -> f [Double]
Rank1.diffsF (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. AD s TowerDouble -> f (AD s TowerDouble)
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. a -> AD s a
AD)
{-# INLINE diffsF #-}

diffs0F :: Functor f => (forall s. AD s TowerDouble -> f (AD s TowerDouble)) -> Double -> f [Double]
diffs0F :: forall (f :: * -> *).
Functor f =>
(forall s. AD s TowerDouble -> f (AD s TowerDouble))
-> Double -> f [Double]
diffs0F forall s. AD s TowerDouble -> f (AD s TowerDouble)
f = forall (f :: * -> *).
Functor f =>
(TowerDouble -> f TowerDouble) -> Double -> f [Double]
Rank1.diffs0F (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. AD s TowerDouble -> f (AD s TowerDouble)
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. a -> AD s a
AD)
{-# INLINE diffs0F #-}

taylor :: (forall s. AD s TowerDouble -> AD s TowerDouble) -> Double -> Double -> [Double]
taylor :: (forall s. AD s TowerDouble -> AD s TowerDouble)
-> Double -> Double -> [Double]
taylor forall s. AD s TowerDouble -> AD s TowerDouble
f = (TowerDouble -> TowerDouble) -> Double -> Double -> [Double]
Rank1.taylor (forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. AD s TowerDouble -> AD s TowerDouble
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. a -> AD s a
AD)

taylor0 :: (forall s. AD s TowerDouble -> AD s TowerDouble) -> Double -> Double -> [Double]
taylor0 :: (forall s. AD s TowerDouble -> AD s TowerDouble)
-> Double -> Double -> [Double]
taylor0 forall s. AD s TowerDouble -> AD s TowerDouble
f = (TowerDouble -> TowerDouble) -> Double -> Double -> [Double]
Rank1.taylor0 (forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. AD s TowerDouble -> AD s TowerDouble
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. a -> AD s a
AD)
{-# INLINE taylor0 #-}

maclaurin :: (forall s. AD s TowerDouble -> AD s TowerDouble) -> Double -> [Double]
maclaurin :: (forall s. AD s TowerDouble -> AD s TowerDouble)
-> Double -> [Double]
maclaurin forall s. AD s TowerDouble -> AD s TowerDouble
f = (TowerDouble -> TowerDouble) -> Double -> [Double]
Rank1.maclaurin (forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. AD s TowerDouble -> AD s TowerDouble
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. a -> AD s a
AD)
{-# INLINE maclaurin #-}

maclaurin0 :: (forall s. AD s TowerDouble -> AD s TowerDouble) -> Double -> [Double]
maclaurin0 :: (forall s. AD s TowerDouble -> AD s TowerDouble)
-> Double -> [Double]
maclaurin0 forall s. AD s TowerDouble -> AD s TowerDouble
f = (TowerDouble -> TowerDouble) -> Double -> [Double]
Rank1.maclaurin0 (forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. AD s TowerDouble -> AD s TowerDouble
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. a -> AD s a
AD)
{-# INLINE maclaurin0 #-}

diff :: (forall s. AD s TowerDouble -> AD s TowerDouble) -> Double -> Double
diff :: (forall s. AD s TowerDouble -> AD s TowerDouble)
-> Double -> Double
diff forall s. AD s TowerDouble -> AD s TowerDouble
f = (TowerDouble -> TowerDouble) -> Double -> Double
Rank1.diff (forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. AD s TowerDouble -> AD s TowerDouble
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. a -> AD s a
AD)
{-# INLINE diff #-}

diff' :: (forall s. AD s TowerDouble -> AD s TowerDouble) -> Double -> (Double, Double)
diff' :: (forall s. AD s TowerDouble -> AD s TowerDouble)
-> Double -> (Double, Double)
diff' forall s. AD s TowerDouble -> AD s TowerDouble
f = (TowerDouble -> TowerDouble) -> Double -> (Double, Double)
Rank1.diff' (forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. AD s TowerDouble -> AD s TowerDouble
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. a -> AD s a
AD)
{-# INLINE diff' #-}

du :: Functor f => (forall s. f (AD s TowerDouble) -> AD s TowerDouble) -> f (Double, Double) -> Double
du :: forall (f :: * -> *).
Functor f =>
(forall s. f (AD s TowerDouble) -> AD s TowerDouble)
-> f (Double, Double) -> Double
du forall s. f (AD s TowerDouble) -> AD s TowerDouble
f = forall (f :: * -> *).
Functor f =>
(f TowerDouble -> TowerDouble) -> f (Double, Double) -> Double
Rank1.du (forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s TowerDouble) -> AD s TowerDouble
fforall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE du #-}

du' :: Functor f => (forall s. f (AD s TowerDouble) -> AD s TowerDouble) -> f (Double, Double) -> (Double, Double)
du' :: forall (f :: * -> *).
Functor f =>
(forall s. f (AD s TowerDouble) -> AD s TowerDouble)
-> f (Double, Double) -> (Double, Double)
du' forall s. f (AD s TowerDouble) -> AD s TowerDouble
f = forall (f :: * -> *).
Functor f =>
(f TowerDouble -> TowerDouble)
-> f (Double, Double) -> (Double, Double)
Rank1.du' (forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s TowerDouble) -> AD s TowerDouble
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE du' #-}

duF :: (Functor f, Functor g) => (forall s. f (AD s TowerDouble) -> g (AD s TowerDouble)) -> f (Double, Double) -> g Double
duF :: forall (f :: * -> *) (g :: * -> *).
(Functor f, Functor g) =>
(forall s. f (AD s TowerDouble) -> g (AD s TowerDouble))
-> f (Double, Double) -> g Double
duF forall s. f (AD s TowerDouble) -> g (AD s TowerDouble)
f = forall (f :: * -> *) (g :: * -> *).
(Functor f, Functor g) =>
(f TowerDouble -> g TowerDouble) -> f (Double, Double) -> g Double
Rank1.duF (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s TowerDouble) -> g (AD s TowerDouble)
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE duF #-}

duF' :: (Functor f, Functor g) => (forall s. f (AD s TowerDouble) -> g (AD s TowerDouble)) -> f (Double, Double) -> g (Double, Double)
duF' :: forall (f :: * -> *) (g :: * -> *).
(Functor f, Functor g) =>
(forall s. f (AD s TowerDouble) -> g (AD s TowerDouble))
-> f (Double, Double) -> g (Double, Double)
duF' forall s. f (AD s TowerDouble) -> g (AD s TowerDouble)
f = forall (f :: * -> *) (g :: * -> *).
(Functor f, Functor g) =>
(f TowerDouble -> g TowerDouble)
-> f (Double, Double) -> g (Double, Double)
Rank1.duF' (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s TowerDouble) -> g (AD s TowerDouble)
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE duF' #-}

dus :: Functor f => (forall s. f (AD s TowerDouble) -> AD s TowerDouble) -> f [Double] -> [Double]
dus :: forall (f :: * -> *).
Functor f =>
(forall s. f (AD s TowerDouble) -> AD s TowerDouble)
-> f [Double] -> [Double]
dus forall s. f (AD s TowerDouble) -> AD s TowerDouble
f = forall (f :: * -> *).
Functor f =>
(f TowerDouble -> TowerDouble) -> f [Double] -> [Double]
Rank1.dus (forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s TowerDouble) -> AD s TowerDouble
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE dus #-}

dus0 :: Functor f => (forall s. f (AD s TowerDouble) -> AD s TowerDouble) -> f [Double] -> [Double]
dus0 :: forall (f :: * -> *).
Functor f =>
(forall s. f (AD s TowerDouble) -> AD s TowerDouble)
-> f [Double] -> [Double]
dus0 forall s. f (AD s TowerDouble) -> AD s TowerDouble
f = forall (f :: * -> *).
Functor f =>
(f TowerDouble -> TowerDouble) -> f [Double] -> [Double]
Rank1.dus0 (forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s TowerDouble) -> AD s TowerDouble
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE dus0 #-}

dusF :: (Functor f, Functor g) => (forall s. f (AD s TowerDouble) -> g (AD s TowerDouble)) -> f [Double] -> g [Double]
dusF :: forall (f :: * -> *) (g :: * -> *).
(Functor f, Functor g) =>
(forall s. f (AD s TowerDouble) -> g (AD s TowerDouble))
-> f [Double] -> g [Double]
dusF forall s. f (AD s TowerDouble) -> g (AD s TowerDouble)
f = forall (f :: * -> *) (g :: * -> *).
(Functor f, Functor g) =>
(f TowerDouble -> g TowerDouble) -> f [Double] -> g [Double]
Rank1.dusF (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s TowerDouble) -> g (AD s TowerDouble)
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE dusF #-}

dus0F :: (Functor f, Functor g) => (forall s. f (AD s TowerDouble) -> g (AD s TowerDouble)) -> f [Double] -> g [Double]
dus0F :: forall (f :: * -> *) (g :: * -> *).
(Functor f, Functor g) =>
(forall s. f (AD s TowerDouble) -> g (AD s TowerDouble))
-> f [Double] -> g [Double]
dus0F forall s. f (AD s TowerDouble) -> g (AD s TowerDouble)
f = forall (f :: * -> *) (g :: * -> *).
(Functor f, Functor g) =>
(f TowerDouble -> g TowerDouble) -> f [Double] -> g [Double]
Rank1.dus0F (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s TowerDouble) -> g (AD s TowerDouble)
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE dus0F #-}