Skip to content

Instantly share code, notes, and snippets.

@egisatoshi
Created May 17, 2016 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egisatoshi/6241d73568af00bfd5bbd00949645fe9 to your computer and use it in GitHub Desktop.
Save egisatoshi/6241d73568af00bfd5bbd00949645fe9 to your computer and use it in GitHub Desktop.
Multi variate Taylor Expansion
(define $∇
(lambda [$f $xs]
(generate-tensor
1#(∂/∂ f (nth %1 xs))
{(length xs)})))
(define $nabla ∇)
(define $taylor-expansion2
(lambda [$f $xs $as]
(map2 *
(map 1#(/ 1 (fact %1)) nats0)
; (map (substitute (zip xs as) $)
(iterate (Op.* (∇ $ xs) (V.* (generate-tensor 1#h_%1 {(length xs)}) $)) f))))
(define $taylor-expansion3
(lambda [$f $xs $as]
(iterate (Op.* (∇ $ xs) (V.* (generate-tensor 1#h_%1 {(length xs)}) $)) f)))
(define $Op.* compose)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment