Skip to content

Instantly share code, notes, and snippets.

@stephen-lazaro
Last active July 31, 2018 21:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stephen-lazaro/73c30c866515261c8e73e19e49372bd6 to your computer and use it in GitHub Desktop.
Save stephen-lazaro/73c30c866515261c8e73e19e49372bd6 to your computer and use it in GitHub Desktop.
Automatic differentiation in one dimension using the Dual numbers of the ring of doubles
object differentials {
import spire.implicits._
import spire.math._
import spire.algebra._
implicit val duals = JetDim(1)
def auto_diff (f: Jet [Double] => Jet [Double]) = (x: Double) => f ( Jet (x, 0) )
def df (f: Jet[Double] => Jet[Double]) = (x: Double) => auto_diff (f) (x) ._2 (0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment