Last active
February 25, 2017 22:09
-
-
Save jdh30/91af8fe2120d957a7ba8b0faf8a54072 to your computer and use it in GitHub Desktop.
A symbolic derivative written in OCaml using pattern matching over code quotations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let d x = function | |
| <:expr< $y$ >> when x=y -> <:expr< 1 >> | |
| <:expr< $f$ + $g$ >> -> <:expr< $d f x$ + $d g x$ >> | |
| <:expr< $f$ * $g$ >> -> <:expr< $f$ * $d g x$ + $g$ * $d f x$ >> | |
| _ -> <:expr< 0 >> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment