Skip to content

Commit

Permalink
Merge pull request #4 from msakai/explicit-power
Browse files Browse the repository at this point in the history
Define (**) for AD type explicitly
  • Loading branch information
ocramz authored Jul 3, 2023
2 parents 8898edd + 223b68b commit 04884b9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Numeric/AD/DelCont/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ instance Floating a => Floating (AD s a a) where
exp = op1Num $ \x -> (exp x, (exp x *))
log = op1Num $ \x -> (log x, (/x))
sqrt = op1Num $ \x -> (sqrt x, (/ (2 * sqrt x)))
(**) = op2Num $ \x y -> (x ** y, (* (y * x ** (y - 1))), (* (x ** y * log x)))
logBase = op2Num $ \x y ->
let
dx = - logBase x y / (log x * x)
Expand Down
3 changes: 3 additions & 0 deletions test/Numeric/AD/DelContSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ spec = do
describe "rad1 : Unary functions" $ do
let
x0 = 1.2
x1 = 0.0
it "(** 2)" $ do
let
f x = x ** 2
(_, dfdx) = rad1 f x0
(_, dfdx1) = rad1 f x1
dfdx `shouldBe` 2.4
dfdx1 `shouldBe` 0.0
it "sqrt" $ do
let
(_, dfdx) = rad1 sqrt x0
Expand Down

0 comments on commit 04884b9

Please sign in to comment.