3 ms·
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
by cryptonector 4y ago
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')`.
- krastanov 4y agoNot quite. This subthread is about the extremely short, one-line implementation mentioned here https://news.ycombinator.com/item?id=32882825 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.
- cryptonector 4y agoYes, indeed, I was referring to TFA, and obviously I was confused.
- pfortuny 4y agoHowever, 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.