Beautiful differentiation
Lately I’ve been playing again with parametric surfaces in Haskell. Surface rendering requires normals, which can be constructed from partial derivatives, which brings up automatic differentiation (AD). Playing with some refactoring, I’ve stumbled across a terser, lovelier formulation for the derivative rules than I’ve seen before.
Edits:
- 2008-05-08: Added source files: NumInstances.hs and Dif.hs.
- 2008-05-20: Changed some variable names for clarity and consistency. For instance,
x@(D x0 x')
instead ofp@(D x x')
. - 2008-05-20: Removed extraneous
Fractional
constraint in theFloating
instance ofDif
.