
29 Nov
2007
29 Nov
'07
3:24 p.m.
On Nov 28, 2007 9:20 PM, Chris Smith
I intend to naively treat each function as being from the reals to the reals, and then take advantage of the fact (which is proven by the type system in the code I posted) that when the derivative is evaluated at integer inputs for functions defined using only ring operations, the result is an integer (and similarly for rationals and field operations).
I must be missing the point of something. What's wrong with
diff f x = let AD y dy = f (AD x 1) in dy
? In ghci we get *Main> :t diff (\x -> 2*x) (2::Int) diff (\x -> 2*x) (2::Int) :: Int *Main> :t diff (\x -> 2*x) (2::Float) diff (\x -> 2*x) (2::Float) :: Float I've used almost exactly that line of code myself a few times. -- Dan