packages feed

egison-5.1.0: sample/math/geometry/hodge-laplacian-polar.egi

declare symbol r, θ: MathValue

-- Parameters and metrics

def N : Integer := 2

def x : Vector MathValue := [|r, θ|]

def g_i_j : Matrix MathValue := [| [| 1, 0 |], [| 0, r^2 |] |]_i_j
def g~i~j : Matrix MathValue := [| [| 1, 0 |], [| 0, 1 / r^2 |] |]~i~j

-- Hodge Laplacian

def d (A: Tensor MathValue) : Tensor MathValue := !(flip ∂/∂) x A

def hodge (A: Tensor MathValue) : Tensor MathValue :=
  let k := dfOrder A
   in withSymbols [i, j]
        sqrt (abs (M.det g_#_#)) *
        foldl
          (.)
          ((ε' N k)_(i_1)..._(i_N) . A..._(j_1)..._(j_k))
          (map (\n -> g~(i_n)~(j_n)) [1..k])


def δ (A: Tensor MathValue) : Tensor MathValue :=
  let k := dfOrder A in
    -1^(N * (k + 1) + 1) * (hodge (d (hodge A)))

def Δ (A: Tensor MathValue) : Tensor MathValue :=
  match (dfOrder A) as integer with
  | #0 -> δ (d A)
  | #N -> d (δ A)
  | _  -> d (δ A) + δ (d A)

def f : MathValue := function (r, θ)

assertEqual "Laplacian" (Δ f) ((-1 / r^2) * ((∂/∂ (∂/∂ f θ) θ) + r * (∂/∂ f r) + (r^2 * (∂/∂ (∂/∂ f r) r))))