Skip to content

Instantly share code, notes, and snippets.

@cls cls/derivative.sml
Created May 12, 2018

Embed
What would you like to do?
Derivative of a function in Standard ML, using Real.nextAfter
fun derivative (f : real -> real) (x : real) : real =
let val pos = Real.nextAfter (x, Real.posInf)
val neg = Real.nextAfter (x, Real.negInf)
in
(f pos - f neg) / (pos - neg)
end
@cls

This comment has been minimized.

Copy link
Owner Author

commented May 12, 2018

I'm unsure if Standard ML guarantees that pos - neg here be non-zero.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.