Skip to content

Instantly share code, notes, and snippets.

import math
def sin(dual):
return Dual(math.sin(dual.value), dual.derivative * math.cos(dual.value))
def __add__(self, other):
if isinstance(other, self.__class__):
return Dual(self.value + other.value, self.derivative + other.derivative)
else:
return self + Dual(other)
class Dual:
def __init__(self, value=0., derivative=0.):
self.value = value
self.derivative = derivative
def __add__(self, other):
return Dual(self.value + other.value, self.derivative + other.derivative)
def __mul__(self, other):
return Dual(self.value * other.value, self.value*other.derivative + self.derivative * other.value)
def super_complicated_function(x):
return x * sin(x+6.)**2. / 2. - 2. / 2.**x

Keybase proof

I hereby claim:

  • I am tswedish on github.
  • I am tswedish (https://keybase.io/tswedish) on keybase.
  • I have a public key ASBmF9szOq6XhfbyhBf4NY1dTFdefEIf91vI5vstfqE7Ugo

To claim this, I am signing this object: