FLRW Cosmology Model

In this post, I would like to introduce the basic assumption of modern cosmology, i.e. the FLRW model, also as an application of Einstein field equation.

The idea is simple, given a FLRW metric, plug into the field equation, then we deduce how the space scale \(a\) (which is a parameter of the metric) changes along with the \(t\) coordinates. Here I express the computation in a Python program.


import sympy as sp
from sympy.diffgeom import Manifold, Patch, CoordSystem, TensorProduct
from sympy.diffgeom.diffgeom import metric_to_Ricci_components, metric_to_Christoffel_2nd
from sympy import Symbol, Function, sin, simplify, Matrix

# Define spacetime dimensions
dim = 4

# Define manifold and coordinate system (using spherical coordinates)
M = Manifold('M', dim)
patch = Patch('P', M)
coords = CoordSystem('coords', patch, [
    Symbol('t', real=True),
    Symbol('r', real=True, positive=True),
    Symbol('theta', real=True, positive=True),
    Symbol('phi', real=True)
])

# Get coordinate functions and basic one-forms
t, r, theta, phi = coords.coord_functions()
dt, dr, dtheta, dphi = coords.base_oneforms()

# Define scale factor and curvature parameter (using natural units c=1)
a = Function('a')(t)  # Scale factor as a function of time
k = Symbol('k')       # Spatial curvature parameter

# Construct FLRW metric
# ds² = -dt² + a(t)²[dr²/(1-kr²) + r²(dθ² + sin²θ dφ²)]
g = -TensorProduct(dt, dt) + \
    a**2 * (TensorProduct(dr, dr)/(1-k*r**2) + \
            r**2 * TensorProduct(dtheta, dtheta) + \
            r**2 * sin(theta)**2 * TensorProduct(dphi, dphi))

# Matrix form of the metric (for Einstein tensor calculation)
g_matrix = Matrix([
    [-1, 0, 0, 0],
    [0, a**2/(1-k*r**2), 0, 0],
    [0, 0, a**2*r**2, 0],
    [0, 0, 0, a**2*r**2*sin(theta)**2]
])

# Calculate Christoffel symbols
Christoffel = metric_to_Christoffel_2nd(g)

# Calculate Ricci tensor
Ricci_tensor = metric_to_Ricci_components(g)

# Define coordinate index names
coord_names = ['t', 'r', 'θ', 'φ']

# Calculate inverse metric tensor
g_inverse = Matrix([
    [-1, 0, 0, 0],
    [0, (1-k*r**2)/a**2, 0, 0],
    [0, 0, 1/(a**2*r**2), 0],
    [0, 0, 0, 1/(a**2*r**2*sin(theta)**2)]
])

# Calculate Ricci scalar R = g^{μν} * R_{μν}
Ricci_scalar = 0
for i in range(dim):
    for j in range(dim):
        Ricci_scalar += g_inverse[i, j] * Ricci_tensor[i, j]
Ricci_scalar = simplify(Ricci_scalar)

# Calculate Einstein tensor G_μν = R_μν - (1/2) * g_μν * R
Einstein_tensor = Matrix([[0 for _ in range(dim)] for _ in range(dim)])
for i in range(dim):
    for j in range(dim):
        Einstein_tensor[i, j] = Ricci_tensor[i, j] - (1/2) * g_matrix[i, j] * Ricci_scalar
        Einstein_tensor[i, j] = simplify(Einstein_tensor[i, j])

# Print Christoffel symbols
print("Christoffel symbols of FLRW metric (Γ^μ_νρ):")
for i in range(dim):
    for j in range(dim):
        for k in range(dim):
            if Christoffel[i, j, k] != 0:
                print(f"Γ^{coord_names[i]}_{coord_names[j]}{coord_names[k]} = {simplify(Christoffel[i, j, k])}")

# Print Ricci tensor
print("\nRicci tensor of FLRW metric (R_μν):")
for i in range(dim):
    for j in range(dim):
        if Ricci_tensor[i, j] != 0:
            print(f"R_{coord_names[i]}{coord_names[j]} = {simplify(Ricci_tensor[i, j])}")

# Print Ricci scalar
print("\nRicci scalar of FLRW metric (R):")
print(f"R = {Ricci_scalar}")

# Print Einstein tensor
print("\nEinstein tensor of FLRW metric (G_μν):")
for i in range(dim):
    for j in range(dim):
        if Einstein_tensor[i, j] != 0:
            print(f"G_{coord_names[i]}{coord_names[j]} = {Einstein_tensor[i, j]}")
Christoffel symbols of FLRW metric (Γ^μ_νρ):
Γ^t_rr = -a(t)*Subs(Derivative(a(_xi), _xi), _xi, t)/(k*r**2 - 1)
Γ^t_θθ = a(t)*r**2*Subs(Derivative(a(_xi), _xi), _xi, t)
Γ^t_φφ = a(t)*sin(theta)**2*r**2*Subs(Derivative(a(_xi), _xi), _xi, t)
Γ^r_tr = Subs(Derivative(a(_xi), _xi), _xi, t)/a(t)
Γ^r_rt = Subs(Derivative(a(_xi), _xi), _xi, t)/a(t)
Γ^r_rr = -k*r/(k*r**2 - 1)
Γ^r_θθ = k*r**3 - r
Γ^r_φφ = (k*r**2 - 1)*sin(theta)**2*r
Γ^θ_tθ = Subs(Derivative(a(_xi), _xi), _xi, t)/a(t)
Γ^θ_rθ = 1/r
Γ^θ_θt = Subs(Derivative(a(_xi), _xi), _xi, t)/a(t)
Γ^θ_θr = 1/r
Γ^θ_φφ = -sin(2*theta)/2
Γ^φ_tφ = Subs(Derivative(a(_xi), _xi), _xi, t)/a(t)
Γ^φ_rφ = 1/r
Γ^φ_θφ = 1/tan(theta)
Γ^φ_φt = Subs(Derivative(a(_xi), _xi), _xi, t)/a(t)
Γ^φ_φr = 1/r
Γ^φ_φθ = 1/tan(theta)

Ricci tensor of FLRW metric (R_μν):
R_tt = -3*Subs(Derivative(a(_xi), (_xi, 2)), _xi, t)/a(t)
R_rr = (-2*k - a(t)*Subs(Derivative(a(_xi), (_xi, 2)), _xi, t) - 2*Subs(Derivative(a(_xi), _xi), _xi, t)**2)/(k*r**2 - 1)
R_θθ = (2*k + a(t)*Subs(Derivative(a(_xi), (_xi, 2)), _xi, t) + 2*Subs(Derivative(a(_xi), _xi), _xi, t)**2)*r**2
R_φφ = (2*k + a(t)*Subs(Derivative(a(_xi), (_xi, 2)), _xi, t) + 2*Subs(Derivative(a(_xi), _xi), _xi, t)**2)*sin(theta)**2*r**2

Ricci scalar of FLRW metric (R):
R = 6*(k + a(t)*Subs(Derivative(a(_xi), (_xi, 2)), _xi, t) + Subs(Derivative(a(_xi), _xi), _xi, t)**2)/a(t)**2

Einstein tensor of FLRW metric (G_μν):
G_tt = 3.0*(k + Subs(Derivative(a(_xi), _xi), _xi, t)**2)/a(t)**2
G_rr = (1.0*k + 2.0*a(t)*Subs(Derivative(a(_xi), (_xi, 2)), _xi, t) + 1.0*Subs(Derivative(a(_xi), _xi), _xi, t)**2)/(k*r**2 - 1)
G_θθ = (-1.0*k - 2.0*a(t)*Subs(Derivative(a(_xi), (_xi, 2)), _xi, t) - 1.0*Subs(Derivative(a(_xi), _xi), _xi, t)**2)*r**2
G_φφ = (-1.0*k - 2.0*a(t)*Subs(Derivative(a(_xi), (_xi, 2)), _xi, t) - 1.0*Subs(Derivative(a(_xi), _xi), _xi, t)**2)*sin(theta)**2*r**2

Plug in the final Einstein tensor into the Einstein equation. Let’s take \( G_{tt} \) as an example:

2025-04-13    
Einstein Field Equation

To derive the Einstein field equation, we start from physical considerations involving energy and momentum, and geometry considerations from the curvature of spacetime.


The Einstein field equation relies on three fundamental assumptions:

  1. Energy conservation
  2. Momentum conservation
  3. Newtonian gravity equation

For assumptions 1 and 2, the conservation law for the stress-energy tensor holds:

\[ \nabla_\mu T^{\mu \nu} = 0 \]

The stress-energy tensor \(T^{\mu \nu}\) encapsulates crucial physical quantities and is expressed as:

2025-03-07    
Some Basics of Differential Geometry 3

In this post, I would like to study some basic knowledge of the \( \nabla \) symbol, as well as an important formula related with riemann tensor.

I. Connection

Definition: A connection \( \nabla \) on a smooth manifold \( (M, \mathcal{O}) \) is a map that takes a pair consisting of a vector field \( X \) and a \( (p, q) \)-tensor field \( T \) and sends them to a \( (p, q) \)-tensor field \( \nabla_X T \), satisfying:

2025-02-07    
Some Basics of Differential Geometry 2

In this post, we will delve deeper into the concepts of differential geometry, mainly focusing on the notion of riemann tensor, ricci tensor, and ricci scalar.

I. The Riemann Tensor

A. Definition

We start with a \(d\)-dimensional manifold \(M\) endowed with a (pseudo-)Riemannian metric \(g_{\mu\nu}\). The connection compatible with the metric is the Levi-Civita connection \(\nabla\). The Riemann curvature tensor (often called simply the Riemann tensor) \(R^\rho_{\ \sigma\mu\nu}\) is defined by the commutator of covariant derivatives acting on a vector field \(V^\rho\):

2025-01-28    
Some Basics of Differential Geometry

In this post, I would like to build some basics of differential geometry for understanding the Einstein Field Equations.

1. Riemann Tensor and Its Properties

Definition of the Riemann Tensor:

The Riemann curvature tensor \( R^i_{jkl} \) is a fundamental object in differential geometry, representing the intrinsic curvature of a manifold. It is defined as:

\[ R^i_{jkl} = \partial_k \Gamma^i_{jl} - \partial_l \Gamma^i_{jk} + \Gamma^i_{km} \Gamma^m_{jl} - \Gamma^i_{lm} \Gamma^m_{jk} \]

where \( \Gamma^i_{jk} \) are the Christoffel symbols.

2025-01-21    
Understanding Treasury Bonds

I would like to learn some basic information about treasury bonds. The following questions are of interest to me:

  1. How the coupon rate is determined?
  2. How the yield is determined?
  3. What’s the relationship between yield and price?
  4. The relationship between yield and interest rate?
  5. From a macroeconomic perspective, what’s the status of the treasury bond market of USA, China, and Japan?

We refer to these lectures.


Treasury Bonds are debt securities issued by the government to finance its operations. They are known for their stability and are key instruments in the financial markets. Below is a structured explanation of the key concepts related to Treasury Bonds.

2025-01-20    
Stress-Energy Tensor

In this post, I would like to build some fundational knowledge about the Einstein Field Equations. First, I will pose several questions based on the last post about cosmology:

  1. What are the einstein tensor and the stress-energy tensor?
  2. How is Einstein Field Equations derived?
  3. In the context of cosmology, what is the perfect fluid approximation?
  4. How can we derive the Friedmann Equation and Acceleration Equation from the Einstein Field Equations?

We refer to this course.

2025-01-04    
Understanding Income Statements and Cash Flow Statements

I’m trying to learn financial investment, so I will first attempt to read financial reports to understand the business activities happening in the world.

Here are some fundamentals to get know about a company:

  • Income Statement (Profit & Loss): Shows the company’s revenues, expenses, and profits over a specific period. Key metrics to focus on: revenue, gross profit, operating profit, net income. It’s kind of a video shows the activity of the company in a past period.
  • Balance Sheet: Provides a snapshot of the company’s assets, liabilities, and equity at a specific point in time. It gives insight into the company’s financial health and how it’s funded. It’s like a snapshot.
  • Cash Flow Statement: Highlights the company’s cash inflows and outflows over a period. It focuses on operating, investing, and financing activities. A key metric here is free cash flow, which indicates the amount of cash a company has left after capital expenditures.
  • Statement of Shareholders’ Equity: Explains changes in equity from the previous period.

Difference of Income Statement and Cash Flow Statement

1. Income Statement (Profit & Loss Statement)

What it focuses on:
The Income Statement shows a company’s revenues and expenses over a specific period (e.g., a quarter or a year), and ultimately calculates the net income (profit or loss). It focuses on accrual accounting, which means it records revenues when earned and expenses when incurred, regardless of when the actual cash is received or paid.

2024-12-24    
Inflation Cosmology: Is our universe part of a multiuniverse?

I want to learn about cosmology, maybe start with the book “An Introduction to Modern Cosmology” by Andrew Liddle and the lecture “The Early Universe” by MIT OpenCourseWare.

The standard Big Bang

It does not tell the cause of the Bang, but the aftermath of the Bang. It assumes all the matter already existed before the Bang.

Cosmic Inflation

A prequal to the Big Bang.

  • gravity can be repulsive when pressure is negative. (Find out more about the relationship between gravity and pressure in the next part.)
    There is a patch of repulsive gravity material in the early universe, which is the cause of the Big Bang.
    The (mass/energy) density of the repulsive material is not lowered as it expands.The resolution is to introduce negative energy.

Complementarity: The relationship between gravity and pressure

Below is a high-level introduction to these ideas, followed by some of the key formulas in cosmology and general relativity that show why negative pressure can produce a repulsive gravitational effect.

2024-12-23