Function Repository Resource:

ComovingDistance

Source Notebook

Compute the comoving distance as a closed-form function of redshift using a parabolic expansion model

Contributed by: Donald Airey

ResourceFunction["ComovingDistance"][z]

gives the comoving distance corresponding to the redshift z using a parabolic expansion model.

Details

The redshift z is a nonnegative, dimensionless number.
The computation uses a closed-form expression derived from a parabolic expansion model with constant acceleration.
The returned value is a pure number representing distance in meters.
ComovingDistance applies a numerical formula and uses no integration or iterative approximation, making it faster that UniverseModelData.

Examples

Basic Examples (2) 

Compute a comoving distance from a redshift:

In[1]:=
ResourceFunction["ComovingDistance"][0.1]
Out[1]=

Compute the comoving distance to the surface of last scattering (in Gpc):

In[2]:=
UnitConvert[ResourceFunction["ComovingDistance"][1000], "Gigaparsecs"]
Out[2]=

Scope (1) 

Predict the distance moduli of SN 1997ff (redshift equal to 1.755):

In[3]:=
\[Mu][z_] := 5 Log10[QuantityMagnitude[
    UnitConvert[ (1 + z) ResourceFunction["ComovingDistance"][
        z]/(10*Quantity[1, "Parsecs"]), "DimensionlessUnit"]]]
\[Mu][1.755]
Out[4]=

Applications (2) 

Define a helper function for computing an object's distance modulus μ as a function of redshift z:

In[5]:=

\[Mu][z_?NumericQ] := Module[
  {luminousDistance},
  luminousDistance = (1 + z) ResourceFunction["ComovingDistance"][z];
  5 Log10[
    QuantityMagnitude[
     UnitConvert[ luminousDistance/(10*Quantity[1, "Parsecs"]), "DimensionlessUnit"]]]
  ]
Out[6]=

Create a Hubble diagram of observed distance moduli against the function predictions:

In[7]:=
dataUrl = "https://github.com/PantheonPlusSH0ES/DataRelease/raw/refs/heads/main/Pantheon+_Data/4_DISTANCES_AND_COVAR/Pantheon+SH0ES.dat";
pantheonData = Import[dataUrl, "Table", HeaderLines -> 1];
pantheonRedshifts = pantheonData[[All, 3]];
pantheonDistanceModuli = pantheonData[[All, 11]];
observedPlot = ListPlot[Transpose[{pantheonRedshifts, pantheonDistanceModuli}], PlotStyle -> {Gray}, PlotMarkers -> {"\[FilledCircle]", Medium}, PlotRange -> All];
predictionLine = ListLinePlot[
   Transpose[{pantheonRedshifts, \[Mu] /@ pantheonRedshifts}], PlotStyle -> {Red, Thick}, PlotRange -> All];
Show[{observedPlot, predictionLine}, PlotRange -> {All, All}, Frame -> True, Axes -> False, FrameLabel -> {"Redshift z", "Distance Modulus \[Mu]"}, LabelStyle -> Directive[14]]
Out[8]=

Properties and Relations (1) 

ComovingDistance is an approximate inverse for the "Redshift" function in UniverseModelData:

In[9]:=
ResourceFunction["ComovingDistance"][
 UniverseModelData[Quantity[10^24, "Meters"], "Redshift"]]
Out[9]=

Publisher

Donald Airey

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.0.0 – 16 January 2026

Related Resources

Author Notes

This function implements a closed-form cosmological distance calculation derived analytically (i.e., without numerical integration) and intended for exploratory and comparative studies. Because the result is obtained in a single, non-iterative evaluation, it achieves machine-precision accuracy while avoiding the execution-time and error tradeoffs associated with integration-based distance calculations. When applied to Type Ia supernova redshift data, the resulting distance moduli more closely track observed magnitudes and exhibit reduced systematic residuals relative to standard FLRW-based calculations, as demonstrated in the companion notebook linked above.

License Information