Special Relativistic Mechanics

The relativistic domain provides tools for special relativistic dynamics, Lorentz transformations, and four-vector calculations.

Overview

The relativistic module implements:

  • Relativistic particle dynamics with proper Lagrangian/Hamiltonian

  • Four-vectors with Lorentz invariants

  • Lorentz transformations (boosts, velocity addition)

  • Relativistic collisions and invariant mass calculations

The relativistic Lagrangian is:

\[L = -mc^2\sqrt{1 - \frac{v^2}{c^2}} - V(\mathbf{r})\]

Quick Start

from mechanics_dsl.domains.relativistic import RelativisticParticle, gamma

# Create a relativistic particle
particle = RelativisticParticle(mass=1.0)
particle.set_parameter('c', 1.0)  # Natural units

# Calculate Lorentz factor at v = 0.8c
g = particle.lorentz_factor(0.8)  # γ = 5/3 ≈ 1.667

# Relativistic momentum: p = γmv
p = particle.relativistic_momentum(0.8)  # p ≈ 1.333

# Total energy: E = γmc²
E = particle.relativistic_energy(0.8)  # E ≈ 1.667

# Kinetic energy: T = (γ-1)mc²
T = particle.kinetic_energy(0.8)  # T ≈ 0.667

Classes

RelativisticParticle

class mechanics_dsl.domains.relativistic.RelativisticParticle(mass: float = 1.0, name: str = 'relativistic_particle')[source]

Bases: PhysicsDomain

Special relativistic point particle dynamics.

Uses the relativistic Lagrangian:

L = -mc²√(1 - v²/c²) - V(r)

or equivalently minimizes proper time along worldline.

Example

>>> particle = RelativisticParticle(mass=1.0)
>>> particle.set_parameter('c', 1.0)  # Natural units
>>> gamma = particle.lorentz_factor(0.8)  # v = 0.8c
set_potential(V: Expr) None[source]

Set the potential energy function.

lorentz_factor(v: float) float[source]

Calculate Lorentz factor γ = 1/√(1 - v²/c²).

Parameters:

v – Speed (magnitude of velocity)

Returns:

Lorentz factor γ

relativistic_momentum(v: float) float[source]

Calculate relativistic momentum p = γmv.

Parameters:

v – Speed

Returns:

Relativistic momentum

relativistic_energy(v: float) float[source]

Calculate total relativistic energy E = γmc².

Parameters:

v – Speed

Returns:

Total energy

kinetic_energy(v: float) float[source]

Calculate relativistic kinetic energy T = (γ-1)mc².

Parameters:

v – Speed

Returns:

Kinetic energy

rest_energy() float[source]

Calculate rest energy E₀ = mc².

define_lagrangian() Expr[source]

Relativistic Lagrangian: L = -mc²√(1 - v²/c²) - V(r)

In the low-velocity limit, this reduces to (1/2)mv² - V plus a constant.

define_hamiltonian() Expr[source]

Relativistic Hamiltonian: H = √(p²c² + m²c⁴) + V(r)

where p is the relativistic momentum.

derive_equations_of_motion() Dict[str, Expr][source]

Derive relativistic equations of motion.

dp/dt = F = -∇V

Returns:

Dictionary with momentum rate equations

get_state_variables() List[str][source]

State variables: positions and momenta.

get_required_parameters() List[str][source]

Get list of required parameters for this domain.

Override in subclasses to specify required parameters.

Returns:

List of required parameter names

get_conserved_quantities() Dict[str, Expr][source]

Total energy and momentum (if no external forces).

Example: Relativistic dynamics with external field

import sympy as sp
from mechanics_dsl.domains.relativistic import RelativisticParticle

particle = RelativisticParticle(mass=1.0)

# Add a potential V(x) = kx²/2
x = sp.Symbol('x')
particle.set_potential(0.5 * x**2)

# Get Lagrangian and Hamiltonian
L = particle.define_lagrangian()
H = particle.define_hamiltonian()

FourVector

class mechanics_dsl.domains.relativistic.FourVector(ct: float | Expr, x: float | Expr, y: float | Expr, z: float | Expr)[source]

Represents a four-vector in special relativity.

Components: (ct, x, y, z) with metric signature (+,-,-,-).

invariant() float | Expr[source]

Calculate Lorentz invariant (squared interval).

s² = (ct)² - x² - y² - z²

magnitude() float | Expr[source]

Magnitude √|s²|.

is_timelike() bool[source]

Check if interval is timelike (s² > 0).

is_spacelike() bool[source]

Check if interval is spacelike (s² < 0).

is_lightlike() bool[source]

Check if interval is lightlike/null (s² = 0).

to_array() ndarray[source]

Convert to numpy array.

Example: Spacetime intervals

from mechanics_dsl.domains.relativistic import FourVector

# Event at (ct=5, x=3, y=0, z=0)
event = FourVector(ct=5.0, x=3.0, y=0.0, z=0.0)

# Lorentz invariant: s² = (ct)² - x² - y² - z²
s2 = event.invariant()  # 25 - 9 = 16 (timelike)

print(event.is_timelike())   # True (s² > 0)
print(event.is_spacelike())  # False
print(event.is_lightlike())  # False

# Light ray from origin
light = FourVector(ct=5.0, x=3.0, y=4.0, z=0.0)
print(light.invariant())     # 0 (null/lightlike)
print(light.is_lightlike())  # True

LorentzTransform

class mechanics_dsl.domains.relativistic.LorentzTransform[source]

Lorentz transformation tools.

Transforms four-vectors between inertial reference frames.

static boost_x(four_vector: FourVector, v: float, c: float = 299792458.0) FourVector[source]

Apply Lorentz boost along x-axis.

Parameters:
  • four_vector – Input four-vector

  • v – Relative velocity of new frame

  • c – Speed of light

Returns:

Transformed four-vector

static boost_matrix(v: float, direction: ndarray, c: float = 299792458.0) ndarray[source]

Construct 4x4 Lorentz boost matrix for arbitrary direction.

Parameters:
  • v – Speed of new frame

  • direction – Unit vector for boost direction

  • c – Speed of light

Returns:

4x4 boost matrix

static velocity_addition(v1: float, v2: float, c: float = 299792458.0) float[source]

Relativistic velocity addition formula.

u = (v1 + v2) / (1 + v1*v2/c²)

Parameters:
  • v1 – First velocity

  • v2 – Second velocity

  • c – Speed of light

Returns:

Combined velocity

static time_dilation(proper_time: float, v: float, c: float = 299792458.0) float[source]

Calculate dilated time interval.

Δt = γΔτ

Parameters:
  • proper_time – Proper time interval Δτ

  • v – Relative velocity

  • c – Speed of light

Returns:

Dilated time interval

static length_contraction(proper_length: float, v: float, c: float = 299792458.0) float[source]

Calculate contracted length.

L = L₀/γ

Parameters:
  • proper_length – Proper length L₀

  • v – Relative velocity

  • c – Speed of light

Returns:

Contracted length

Example: Lorentz boost

from mechanics_dsl.domains.relativistic import FourVector, LorentzTransform

# Event in lab frame
event = FourVector(ct=10.0, x=5.0, y=0.0, z=0.0)

# Boost to frame moving at v = 0.6c in x-direction
boosted = LorentzTransform.boost_x(event, v=0.6, c=1.0)
print(f"ct' = {boosted.ct:.3f}, x' = {boosted.x:.3f}")

# Invariant is preserved!
assert abs(event.invariant() - boosted.invariant()) < 1e-10

Example: Relativistic velocity addition

from mechanics_dsl.domains.relativistic import LorentzTransform

# Spaceship at 0.5c fires missile at 0.5c
v_combined = LorentzTransform.velocity_addition(0.5, 0.5, c=1.0)
print(f"Combined velocity: {v_combined}c")  # 0.8c, not 1.0c!

# Even 0.9c + 0.9c gives less than c
v = LorentzTransform.velocity_addition(0.9, 0.9, c=1.0)
print(f"0.9c + 0.9c = {v:.4f}c")  # 0.9945c

Key Formulas

Lorentz Factor

\[\gamma = \frac{1}{\sqrt{1 - v^2/c^2}}\]

Energy-Momentum Relation

\[E^2 = (pc)^2 + (mc^2)^2\]

Velocity Addition

\[u = \frac{v_1 + v_2}{1 + v_1 v_2 / c^2}\]

Time Dilation

\[\Delta t = \gamma \Delta \tau\]

Length Contraction

\[L = L_0 / \gamma\]

Convenience Functions

from mechanics_dsl.domains.relativistic import gamma, beta, rapidity

# Quick Lorentz factor
g = gamma(0.8, c=1.0)  # 5/3

# β = v/c
b = beta(0.6, c=1.0)  # 0.6

# Rapidity η = arctanh(v/c)
# Rapidities add linearly: η₁₂ = η₁ + η₂
eta = rapidity(0.6, c=1.0)

See Also