Skip to content

Instantly share code, notes, and snippets.

View MBcode's full-sized avatar

mike bobak MBcode

View GitHub Profile
@ttesmer
ttesmer / AD.hs
Last active March 19, 2024 03:04
Automatic Differentiation in 38 lines of Haskell using Operator Overloading and Dual Numbers. Inspired by conal.net/papers/beautiful-differentiation
{-# LANGUAGE TypeSynonymInstances #-}
data Dual d = D Float d deriving Show
type Float' = Float
diff :: (Dual Float' -> Dual Float') -> Float -> Float'
diff f x = y'
where D y y' = f (D x 1)
class VectorSpace v where
zero :: v