Personal tools

Functional differentiation

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
(explanation of Functional differentiation)
m (Code)
 
(7 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
== Introduction ==
 
== Introduction ==
   
Functional differentiation means computing or approximating the deriviative of a function.
+
Functional differentiation means computing or approximating the derivative of a function.
 
There are several ways to do this:
 
There are several ways to do this:
 
* Approximate the derivative <math>f'(x)</math> by <math>\frac{f(x+h)-f(x)}{h}</math> where <math>h</math> is close to zero. (or at best the square root of the machine precision <math>\varepsilon</math>.
 
* Approximate the derivative <math>f'(x)</math> by <math>\frac{f(x+h)-f(x)}{h}</math> where <math>h</math> is close to zero. (or at best the square root of the machine precision <math>\varepsilon</math>.
* Compute the derivative of <math>f</math> symbolically. This approach is particularly interesting for Haskell.
+
* Compute the derivative of <math>f</math> [[Typeful_symbolic_differentiation|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
  +
: <math> D f (x) = \lim_{h\to 0} \frac{f(x+h)-f(x)}{h}</math>
  +
and the Haskell programmer writes
  +
<haskell>
  +
derive :: (Fractional a) => a -> (a -> a) -> (a -> a)
  +
derive h f x = (f (x+h) - f x) / h .
  +
</haskell>
  +
Haskell's <hask>derive h</hask> approximates the mathematician's <math> D </math>.
  +
In functional analysis <math> D </math> is called a (linear) function operator, because it maps functions to functions.
  +
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>.
   
 
== Blog Posts ==
 
== Blog Posts ==
Line 13: Line 13:
 
* [http://vandreev.wordpress.com/2006/12/04/non-standard-analysis-and-automatic-differentiation/ Non-standard analysis, automatic differentiation, Haskell, and other stories.]
 
* [http://vandreev.wordpress.com/2006/12/04/non-standard-analysis-and-automatic-differentiation/ Non-standard analysis, automatic differentiation, Haskell, and other stories.]
 
* [http://sigfpe.blogspot.com/2005/07/automatic-differentiation.html Automatic Differentiation]
 
* [http://sigfpe.blogspot.com/2005/07/automatic-differentiation.html Automatic Differentiation]
  +
* [http://cdsmith.wordpress.com/2007/11/29/some-playing-with-derivatives/ Some Playing with Derivatives]
  +
* [http://conal.net/blog/posts/paper-beautiful-differentiation/ Beautiful differentiation by Conal Elliott.] The paper itself and link to video of ICFP talk on the subject are available from his [http://conal.net/papers/beautiful-differentiation/ site].
  +
  +
== Code ==
  +
  +
* [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

Contents

[edit] 1 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 \frac{f(x+h)-f(x)}{h} where h is close to zero. (or at best the square root of the machine precision \varepsilon.
  • Compute the derivative of f symbolically. This approach is particularly interesting for Haskell.

[edit] 2 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

 D f (x) = \lim_{h\to 0} \frac{f(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).

[edit] 3 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.

[edit] 4 Code