Functional differentiation: Difference between revisions

From HaskellWiki
 
(2 intermediate revisions by 2 users not shown)
Line 13: Line 13:
and the Haskell programmer writes
and the Haskell programmer writes
<haskell>
<haskell>
derive :: a -> (a -> a) -> (a -> a)
derive :: (Fractional a) => a -> (a -> a) -> (a -> a)
derive h f x = (f (x+h) - f x) / h    .
derive h f x = (f (x+h) - f x) / h    .
</haskell>
</haskell>
Line 20: Line 20:
In Haskell <hask>derive h</hask> is called a higher order function for the same reason.
In Haskell <hask>derive h</hask> is called a higher order function for the same reason.
<math> D </math> is in curried form. If it would be uncurried, you would write <math> D(f,x) </math>.
<math> D </math> is in curried form. If it would be uncurried, you would write <math> D(f,x) </math>.


== Blog Posts ==
== Blog Posts ==
Line 35: Line 34:


* [http://hackage.haskell.org/package/fad Forward accumulation mode Automatic Differentiation] Hackage package
* [http://hackage.haskell.org/package/fad Forward accumulation mode Automatic Differentiation] Hackage package
* [http://hackage.haskell.org/package/vector-space Vector-space package], including derivatives as linear transformations satisfying chain rule.


[[Category:Mathematics]]
[[Category:Mathematics]]

Latest revision as of 08:32, 19 December 2010

Introduction

Functional differentiation means computing or approximating the derivative of a function. There are several ways to do this:

  • Approximate the derivative f(x) by f(x+h)f(x)h where h is close to zero. (or at best the square root of the machine precision ε.
  • Compute the derivative of f symbolically. This approach is particularly interesting for Haskell.

Functional analysis

If you want to explain the terms Higher order function and Currying to mathematicians, this is certainly a good example. The mathematician writes

Df(x)=limh0f(x+h)f(x)h

and the Haskell programmer writes

derive :: (Fractional a) => a -> (a -> a) -> (a -> a)
derive h f x = (f (x+h) - f x) / h    .

Haskell's derive h approximates the mathematician's D. In functional analysis D is called a (linear) function operator, because it maps functions to functions. In Haskell derive h is called a higher order function for the same reason. D is in curried form. If it would be uncurried, you would write D(f,x).

Blog Posts

There have been several blog posts on this recently. I think we should gather the information together and make a nice wiki article on it here. For now, here are links to articles on the topic.

Code