egison-5.1.0: sample/math/geometry/yang-mills-equation-of-U1-gauge-theory.egi
--
-- Yang-Mills equation of U(1) gauge theory (Electromagnetism)
--
declare symbol t, x, y, z
def N := 4
def g := [|[|-1, 0, 0, 0|], [|0, 1, 0, 0|], [|0, 0, 1, 0|], [|0, 0, 0, 1|]|]
def d (X : Tensor MathValue) : Tensor MathValue :=
!(flip ∂/∂) [| t, x, y, z |] X
def hodge (A : DiffForm MathValue) : DiffForm 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 :=
let r := dfOrder A
in (-1) ^ (N * r + 1) * hodge (d (hodge A))
def Δ A :=
match dfOrder A as integer with
| #0 -> δ (d A)
| #4 -> d (δ A)
| _ -> d (δ A) + δ (d A)
def normalize2 A := withSymbols [t1, t2] A_t1_t2 - A_t2_t1
-- *(dt∧dx) = -dy∧dz
assertEqual "Hodge star of dt ∧ dx"
(hodge (wedge [|1, 0, 0, 0|] [|0, 1, 0, 0|]))
[| [| 0, 0, 0, 0 |], [| 0, 0, 0, 0 |], [| 0, 0, 0, -1 |], [| 0, 0, 0, 0 |] |]
-- *(dy∧dz) = dt∧dx
assertEqual "Hodge star of dy ∧ dz"
(hodge (wedge [|0, 0, 1, 0|] [|0, 0, 0, 1|]))
[| [| 0, 1, 0, 0 |], [| 0, 0, 0, 0 |], [| 0, 0, 0, 0 |], [| 0, 0, 0, 0 |] |]
-- Symbolic functions of (t, x, y, z)
def φ := function (t, x, y, z)
def Ax := function (t, x, y, z)
def Ay := function (t, x, y, z)
def Az := function (t, x, y, z)
-- Exterior derivative of potential 1-form
-- Expected: antisymmetric 2-form with components like (Ax|1 - φ|2) / 2
dfNormalize (d [|φ, Ax, Ay, Az|])
-- Field components as symbolic functions
def Ex := function (t, x, y, z)
def Ey := function (t, x, y, z)
def Ez := function (t, x, y, z)
def Bx := function (t, x, y, z)
def By := function (t, x, y, z)
def Bz := function (t, x, y, z)
-- Electromagnetic field tensor
def F :=
[|[|0, Ex, Ey, Ez|]
, [|- Ex, 0, Bz, - By|]
, [|- Ey, - Bz, 0, Bx|]
, [|- Ez, By, - Bx, 0|]|]
-- Bianchi identity: hodge(dF)
-- (∇·B = 0, rot E = -∂tB)
-- Expected: [| -2*Bz|4 - 2*By|3 - 2*Bx|2, ... |]
hodge (d F)
-- Source equation: δF = J
-- (∇·E = 0, rot B = ∂tE)
-- Expected: [| -4*Ez|4 - 4*Ey|3 - 4*Ex|2, ... |]
δ F