packages feed

egison-3.10.0: test/lib/math/tensor.egi

(assert-equal "Tensor product - case 1"
  (. [| [| 1 1 |] [| 0 1 |] |]~i~j [| [| 1 1 |] [| 0 1 |] |]_j_k)
  [| [| 1 2 |] [| 0 1 |] |])

(assert-equal "Tensor product - case 2"
  (. [| [| 1 1 |] [| 0 1 |] |]~i~j [| [| 1 1 |] [| 0 1 |] |]_j~k [| [| 1 1 |] [| 0 1 |] |]_k_l)
  [| [| 1 3 |] [| 0 1 |] |]~i_l)

(assert-equal "Vector *"
  (V.* [| 1 1 0 |] [| 10 5 10 |])
  15)

(assert-equal "Matrix * - case 1"
  (M.* [| [| 1 1 |] [| 0 1 |] |] [| [| 1 1 |] [| 0 1 |] |])
  [| [| 1 2 |] [| 0 1 |] |])

(assert-equal "Matrix * - case 2"
  (M.* [| [| 1 1 |] [| 0 1 |] |] [| [| 1 1 |] [| 0 1 |] |] [| [| 1 1 |] [| 0 1 |] |])
  [| [| 1 3 |] [| 0 1 |] |])

(assert-equal "Tensor '+' - case 1"
  (+ 1 [|1 2 3|])
  [|2 3 4|])

(assert-equal "Tensor '+' - case 2"
  (+ [|1 2 3|] 1)
  [|2 3 4|])

(assert-equal "Tensor '+' - case 3"
  (+ [|[|11 12|]
       [|21 22|]
       [|31 32|]|]_i_j
     [|100 200 300|]_i)
  [| [| 111 112 |] [| 221 222 |] [| 331 332 |] |]_i_j)

(assert-equal "Tensor '+' - case 4"
  (+ [|100 200 300|]_i
     [|[|11 12|]
       [|21 22|]
       [|31 32|]|]_i_j)
  [| [| 111 112 |] [| 221 222 |] [| 331 332 |] |]_i_j)

(assert-equal "Tensor '+' - case 5"
  (+ [|[|1 2 3|]
       [|10 20 30|]|]_i_j
     [|100 200 300|]_j)
  [| [| 101 202 303 |] [| 110 220 330 |] |]_i_j)

(assert-equal "Tensor '+' - case 6"
  (+ [|100 200 300|]_j
     [|[|1 2 3|]
       [|10 20 30|]|]_i_j)
  [| [| 101 110 |] [| 202 220 |] [| 303 330 |] |]_j_i)

;(assert-equal "Tensor ∂/∂ - case 1"
;  (∂/∂ [|(f x) (g x)|] x)
;  [|(f|1 x) (g|1 x)|])

;(assert-equal "Tensor ∂/∂ - case 2"
;  (∂/∂ (f x y z) [|x y z|])
;  [|(f|1 x y z) (f|2 x y z) (f|3 x y z)|])

;(assert-equal "Tensor ∂/∂ - case 3"
;  (apply [|(∂/∂ $ x) (∂/∂ $ y)|] (f x y))
;  [|(f|1 x y) (f|2 x y)|])

(assert-equal "append indices with ..."
  (show (let {[$A (generate-tensor 2#1 {2 2})]
              [$f (lambda [%B] B..._j)]}
          (f A_i)))
  (show [| [| 1 1 |] [| 1 1 |] |]_i_j))

(assert-equal "generate_tensor by using function expr"
  (letrec {[$g__ (generate-tensor
                    (match-lambda [integer integer]
                      {[[$n ,n] (function [x y z])]
                       [[_ _] 0]})
                    {3 3})]}
     (show (with-symbols {i j} (d/d g_i_j x))))
  "[| [| g_1_1|x, 0, 0 |], [| 0, g_2_2|x, 0 |], [| 0, 0, g_3_3|x |] |]")

(assert-equal "define tensor having value of function expr"
  (letrec {[$g__ [| [| (function [x y z]) 0 0 |] [| 0 (function [x y z]) 0 |] [| 0 0 (function [x y z]) |] |]]}
     (show (with-symbols {i j} (d/d g_i_j x))))
  "[| [| g_1_1|x, 0, 0 |], [| 0, g_2_2|x, 0 |], [| 0, 0, g_3_3|x |] |]")