Skip to content

Instantly share code, notes, and snippets.

@unhammer
Created August 26, 2019 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unhammer/761e9a098d095f2cf307a12271b86c69 to your computer and use it in GitHub Desktop.
Save unhammer/761e9a098d095f2cf307a12271b86c69 to your computer and use it in GitHub Desktop.
how to get the derivative in Haskell
-- From https://twitter.com/GabrielG439/status/647601518871359489
:set -package ad
:set -package numbers
:m Numeric.AD Data.Number.Symbolic
diff (\x -> sqrt x) (var "a")
-- 1.0/(2.0*sqrt a)
diff (\x -> x^2 + sqrt x) (var "a")
-- a+a+1.0/(2.0*sqrt a)
diff (\x -> x^2 + sqrt x) 1
-- 2.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment