egison-5.1.0: sample/math/geometry/riemann-curvature-tensor-of-FLRW-metric.egi
declare symbol w, r, θ, φ, K: MathValue
-- Parameters
def x : Vector MathValue := [| w, r, θ, φ |]
-- Scale factor function a(w)
def a := function (w)
assertEqual "x" x [| w, r, θ, φ |]
-- Spatial curvature factor.
def W (r: MathValue) : MathValue := 1 / `(1 - K * r^2)
assertEqual "W r = 1/(1-Kr^2)"
(W r)
(1 / `(1 - K * r^2))
-- Metric tensor
def g_i_j : Matrix MathValue :=
[| [| -1, 0, 0, 0 |]
, [| 0, a^2 * W r, 0, 0 |]
, [| 0, 0, a^2 * r^2, 0 |]
, [| 0, 0, 0, a^2 * r^2 * (sin θ)^2 |]
|]
def g~i~j := M.inverse g_#_#
-- Christoffel symbols
def Γ_i_j_k := (1 / 2) * (∂/∂ g_i_k x~j + ∂/∂ g_i_j x~k - ∂/∂ g_j_k x~i)
def Γ~i_j_k := withSymbols [m]
g~i~m . Γ_m_j_k
-- Riemann curvature
def R~i_j_k_l := withSymbols [m]
∂/∂ Γ~i_j_l x~k - ∂/∂ Γ~i_j_k x~l + Γ~m_j_l . Γ~i_m_k - Γ~m_j_k . Γ~i_m_l
-- Ricci curvature
def Ric_i_j := withSymbols [m]
sum (contract R~m_i_m_j)
-- Scalar curvature
def scalarCurvature := withSymbols [i, j]
expandAll' (g~i~j . Ric_i_j)
-- Expected scalar curvature of the FLRW metric (in units c=1):
-- R = 6 (a''(w) a + (a'(w))^2 + K) / a^2
-- The full computation is expensive (>5min on this machine); evaluating
-- `scalarCurvature` is left as the file's final value, not asserted, to
-- keep `cabal test` runtime reasonable. To verify the expected form
-- explicitly, run: `cabal run egison -- -t <this-file>` and compare.