Created
March 17, 2012 06:40
-
-
Save darkf/2055832 to your computer and use it in GitHub Desktop.
calculus assignment bs
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
(* Take a tree of expressions in and output the expression tree of the differentiation of it. (or something like that.) | |
Copyright (c) 2012 darkf | |
MIT license | |
*) | |
(* Assignment: http://pastebin.com/tiRVsxNx | |
Graphs: http://f.imgtmp.com/FOVY7.jpg | |
*) | |
type Node = | |
| Constant of int | |
| Variable of string | |
| Mult of Node * Node | |
| Plus of Node * Node | |
| Minus of Node * Node | |
| Cos of Node | |
| Sin of Node | |
(*let tree = Mult ((Variable "x"), Plus ( | |
(Plus ((Constant 2), (Variable "x"))) | |
, | |
(Cos | |
(Minus ((Variable "x"), (Constant 4))))))*) | |
let tree = Mult (Constant 5, Variable "x") | |
let rec diff x = match x with | |
| Plus(x,y) -> Plus (diff x, diff y) | |
| Minus(x,y) -> Minus (diff x, diff y) | |
| Mult(x,y) -> Plus( | |
Mult (diff x, y), | |
Mult (x, diff y) | |
) | |
//| Cos(x) -> | |
//| Sin(x) -> | |
| Constant(x) -> Constant 0 | |
| Variable(x) -> Constant 1 | |
printfn "%A" (diff tree) | |
System.Console.ReadKey(true) |> ignore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment