Feb 8 22:25 2015 derivative.ex Page 1 # Derivative Function with Function Return # Functional Programming Example -- Higher Order # H. Conrad Cunningham, Professor # Computer and Information Science # University of Mississippi # Developed for CSci 556, Multiparadigm Programming, Spring 2015 # 34567890123456789012345678901234567890123456789012345678901234567890 # 2015-02-08: Developed from 2013 Lua version defmodule Derivative do @moduledoc """ This higher-order differentiation function is adapted from a Lua version, which itself is adapted from a Scheme version in section 1.3.4 of Abelson and Sussman's Structure and Interpretation of Computer Programs (SICP) textbook. """ @doc """ Function "deriv" takes a single-argument function "f" and a small delta "dx" and returns a single-argument function (closure) that computes an approximation of the value of the derivative at the value of its argument. Definition of derivative: lim(dx->0) (f(x+dx) - f(x)) / dx """ def deriv(f,dx) when is_function(f) and is_number(dx) do (fn x -> (f.(x+dx) - f.(x)) / dx end) end end