egison-5.1.0: sample/math/geometry/exterior-derivative.egi
--
-- Exterior Derivative
--
declare symbol x, y, z : MathValue
def N : Integer := 3
def params : Vector MathValue := [|x, y, z|]
def g : Matrix Integer := [|[|1, 0, 0|], [|0, 1, 0|], [|0, 0, 1|]|]
def d {a} (X: a) : DiffForm a := !(flip ∂/∂) params X
--def f : MathValue := function (x, y, z)
def f := x ^ 2 + y ^ 2 + z ^ 2
-- The exterior derivative of f is the gradient 1-form
assertEqual "d f = grad(x^2+y^2+z^2)"
(d f)
[| 2 * x, 2 * y, 2 * z |]
-- d (d f) before antisymmetrization is the Hessian matrix
assertEqual "d (d f) = Hessian (raw, pre-normalize)"
(d (d f))
[| [| 2, 0, 0 |], [| 0, 2, 0 |], [| 0, 0, 2 |] |]
-- After antisymmetrization (the diff-form normalizer), d^2 = 0
assertEqual "dfNormalize (d (d f)) = 0 (d^2 = 0)"
(dfNormalize (d (d f)))
[| [| 0, 0, 0 |], [| 0, 0, 0 |], [| 0, 0, 0 |] |]