knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

R-CMD-check Rdoc Codecov test coverage

Overview

knitr::include_graphics(system.file("help/figures/lorentz.png", package = "lorentz"))

The lorentz package furnishes some R-centric functionality for special relativity. Lorentz transformations of four-vectors are handled and some functionality for the stress energy tensor is given. The package deals with four-momentum and has facilities for dealing with photons and mirrors in relativistic situations. A detailed vignette is provided in the package.

The original motivation for the package was the investigation of the (nonassociative) gyrogroup structure of relativistic three-velocities under Einsteinian velocity composition. Natural R idiom may be used to manipulate vectors of three-velocities, although one must be careful with brackets.

Installation

To install the most recent stable version on CRAN, use install.packages() at the R prompt:

R> install.packages("lorentz")

To install the current development version use devtools:

R> devtools::install_github("RobinHankin/lorentz")

And then to load the package use library():

library("lorentz")

The lorentz package in use

The package furnishes natural R idiom for working with three-velocities, four-velocities, and Lorentz transformations as four-by-four matrices. Although natural units in which $c=1$ are used by default, this can be changed.

 u <- as.3vel(c(0.6,0,0))  # define a three-velocity, 0.6c to the right
 u

as.4vel(u)    # convert to a four-velocity:
gam(u)  # calculate the gamma term

B <- boost(u) # give the Lorentz transformation
B

The boost matrix can be used to transform arbitrary four-vectors:

B %*% (1:4)  # Lorentz transform of an arbitrary four-vector

But it can also be used to transform four-velocities:

v <- as.4vel(c(0,0.7,-0.2))
B %*% t(v)

The classical parallelogram law for addition of velocities is incorrect when relativistic effects are included. To combine $u$ and $v$ in terms of successive boosts we would simply multiply the boost matrices:

boost(u) %*% boost(v)

and note that the result depends on the order:

boost(v) %*% boost(u)

Vectorization

The package is fully vectorized and can deal with vectors whose entries are three-velocities or four-velocities:

 set.seed(0)
 options(digits=3)
 # generate 5 random three-velocities:
 (u <- r3vel(5))
 # calculate the gamma correction term:
 gam(u)

 # add a velocity of 0.9c in the x-direction:
 v <- as.3vel(c(0.9,0,0))
 v+u


 # convert u to a four-velocity:
 as.4vel(u)

 # use four-velocities to effect the same transformation:
 w <- as.4vel(u) %*% boost(-v)
 as.3vel(w)

Three-velocities

Three-velocities behave in interesting and counter-intuitive ways.

 u <- as.3vel(c(0.2,0.4,0.1))   # single three-velocity
 v <- r3vel(4,0.9)              # 4 random three-velocities with speed 0.9
 w <- as.3vel(c(-0.5,0.1,0.3))  # single three-velocity

The three-velocity addition law is given by Ungar.

Then we can see that velocity addition is not commutative:

 u+v
 v+u
 (u+v)-(v+u)

Observe that the difference between u+v and v+u is not "small" in any sense. Commutativity is replaced with gyrocommutatitivity:

# Compare two different ways of calculating the same thing:
 (u+v) - gyr(u,v,v+u)  

# The other way round:
 (v+u) - gyr(v,u,u+v)

(that is, zero to numerical accuracy)

Nonassociativity of three-velocities

It would be reasonable to expect that u+(v+w)==(u+v)+w. However, this is not the case:

 ((u+v)+w) - (u+(v+w))

(that is, significant departure from associativity). Associativity is replaced with gyroassociativity:

 (u+(v+w)) - ((u+v)+gyr(u,v,w))
 ((u+v)+w) - (u+(v+gyr(v,u,w)))

(zero to numerical accuracy).

References

The most concise reference is

Further information

For more detail, see the package vignette

vignette("lorentz")


RobinHankin/gyrogroup documentation built on April 24, 2024, 9:36 a.m.