Toggle navigation
Egison
Documentations
Try It Out
Online Tools
Online Egison Interpreter
Online Egison Tutorial
Online Demonstrations
Poker Hands
Mahjong
Prime Numbers
Trees
Graph (Bellman-Ford Algorithm)
Randomized 3-SAT
Time-Series Data
Math
Blog
Community
Vector Analysis
Nov 2 2017
-- -- Tensor Arithmetics -- 1 + [| 1, 2, 3 |] -- [|2, 3, 4|] [| 1, 2, 3 |] + 1 -- [|2, 3, 4|] [| 1, 2, 3 |]_i + [| 1, 2, 3 |]_i -- [|2, 4, 6|]_i [| 10, 20, 30 |] + [| 1, 2, 3 |] -- [| [| 11, 12, 13 |], [| 21, 22, 23 |], [| 31, 32, 33 |] |] [| 100, 200, 300 |]_i + [|[| 1, 2, 3 |], [| 10, 20, 30 |]|]_j_i -- [| [| 101, 110 |], [| 202, 220 |], [| 303, 330 |] |]_i_j [|[| 11, 12 |], [| 21, 22 |], [| 31, 32 |]|]_i_j + [| 100, 200, 300 |]_i -- [| [| 111, 112 |], [| 221, 222 |], [| 331, 332 |] |]_i_j [| 100, 200, 300 |]_i + [|[| 11, 12 |], [| 21, 22 |], [| 31, 32 |]|]_i_j -- [| [| 111, 112 |], [| 221, 222 |], [| 331, 332 |] |]_i_j -- -- Derivative -- ∂/∂ (f x y z) x -- (f_1 x y z) ∂/∂ [| (f x), (g x) |] x -- [| (f_1 x), (g_1 x) |] ∂/∂ (f x y z) [| x y z |] -- [| (f_1 x y z), (f_2 x y z), (f_3 x y z) |] [| (∂/∂ $ x), (∂/∂ $ y) |] (f x y) -- [| (f_1 x y) (f_2 x y) |] [| (∂/∂ $ x), (∂/∂ $ y) |] [| (f x y), (g x y) |] -- [| [| (f_1 x y) (g_1 x y) |] [| (f_2 x y) (g_2 x y) |] |] -- -- Nabla -- def ∇ := ∂/∂ ∇ (f x y) [| x, y |] -- [| (f_1 x y), (f_2 x y) |] ∇ [| (f x y), (g x y) |] [| x, y |] -- [| [| (f_1 x y), (f_2 x y) |], [| (g_1 x y), (g_2 x y) |] |] -- -- Contraction -- contract ([|1, 2, 3|]~i * [|10, 20, 30|]_i) -- [10, 40, 90] def trace %t := withSymbols [i] sum (contract t~i_i) trace [|[|10, 20, 30|], [|20, 40, 60|], [|30, 60, 90|]|] -- 140 -- -- Divergence -- def div %t %x := trace (!(∇ t x)) div [| (f x y z), (g x y z), (h x y z) |] [| x, y, z |] -- f|1 x y z + g|2 x y z + h|3 x y z -- -- Taylor Expansion -- def multivariateTaylorExpansion $f %xs %ys := withSymbols [h] let hs := generateTensor (\[x] -> h_x) (tensorShape xs) in map2 (*) (map (1)#(1 / fact %1) nats0) (map (compose (1)#(V.substitute xs ys %1) (1)#(V.substitute hs (withSymbols [i] xs_i - ys_i) %1)) (iterate (compose (1)#(∇ %1 xs) (1)#(V.* hs %1)) f)) def taylorExpansion $f $x $a := multivariateTaylorExpansion f [|x|] [|a|] take 3 (taylorExpansion (f x) x 0) -- [f 0, x * (f|1 0), x^2 * (f|1|1 0) / 2] take 3 (multivariateTaylorExpansion (f x y) [| x, y |] [| 0, 0 |]) -- [f 0 0, x * f|1 0 0 + y * f|2 0 0, (x^2 * f|1|1 0 0 + x * y * f|2|1 0 0 + y * x * f|1|2 0 0 + y^2 * f|2|2 0 0) / 2]
Links
Back to the Table of Contents
This website in other langauge:
English
,
日本語