Hacker News new | ask | show | jobs
by magicalhippo 1366 days ago
Right, I was confused because for some reason I imagined "sin" coming from the symbolic library, but I'm assuming it's just built-in so AD knows about.
1 comments

The `sin` function comes from this bit at the end of TFA:

    instance VectorSpace d => Floating (Dual d) where
      pi             = D pi zero
      exp   (D u u') = D (exp u)  (scale (exp u) u')
      log   (D u u') = D (log u)  (scale (log u) u')
  --->sin   (D u u') = D (sin u)  (scale (cos u) u')
      cos   (D u u') = D (cos u)  (scale (-sin u) u')
      sinh  (D u u') = D (sinh u) (scale (cosh u) u')
      cosh  (D u u') = D (cosh u) (scale (sinh u) u')
and the `sin` function on the right-hand side comes from `Float`, since `Float` is the type of the argument `u` in `sin u` in `D (sin u) (scale (cos u) u')`.
Not quite. This subthread is about the extremely short, one-line implementation mentioned here https://news.ycombinator.com/item?id=32882825 (which merges two unrelated modules (autodiff and symbolic) and uses autodiff to implement symbolic differentiation). Your comment is true for the original 38-line implemention of autodiff at the very top of the thread, but not in this subthread. The 38-line implementation is similar to the aforementioned autodiff module though.
However, if the symbolic package knows that

cos(a+b) == cos(a)cos(b) - sin(a)sin(b)

then it works.

Something must be known in advance about the relationship between sin and cos for addition, otherwise you cannot go from one to the other (and the basic

cos(a)^2+sin(a)^2=1

is not enough for that.

Yes, indeed, I was referring to TFA, and obviously I was confused.