# Units Figure: With appropriate units for length, time, mass and temperature we can put $c = \hbar = k_b = G = 1$ and avoid having to drag these constants around when doing calculations. We can easily restore them in any expression using dimensional analysis when needed.

When doing numerical calculations we have to deal with units. Here are some notes on this including how you could change the units in the numerical project. A slightly more general class to deal with arbitrary units and provide physical constants in these units is also included in the FML C++ cosmology library.

Below we will use the notation $[x]_{\rm SI}$ to denote the numerical value of a physical constant in SI units, e.g. $[c]_{\rm SI} = 3\cdot 10^8$.

When deriving equations then having to keep around physical constants like $c,G,k_b$ can be a drag. The way to avoid this is to put all of these constants to unity! If we want the constants back in the end we just have to do some simple dimensional analysis. Why does this work and why is this allowed? Lets take the speed of light as an example. In our normal SI units we have $c = 3\cdot 10^8 m/s$. But a meter and a second are arbitrary choices made by humans. If we for example used units, lets call it a ${\rm longmeter}$ and a ${\rm shortsecond}$, that are such that $1\,{\rm longmeter} = 10^3 m$ and $1\,{\rm shortsecond} = \frac{1}{3\cdot 10^5} s$ then $1\,{\rm longmeter}$ per ${\rm shortsecond}$ equals $3\cdot 10^8 m/s$, i.e. the speed of light in these units is $1$.

If we do a calculation in these units and find that a quantity, that for example has dimensions of length, equals $\ell = 0.01\,{\rm longmeter}$ then we can convert back to normal meters as follows: $\ell = 0.01\,{\rm longmeter} = 0.01\,\frac{{\rm longmeter}}{m} m = 0.01\cdot 10^3 m = 10m$. Thus all we need is the factor that tells us how many ${\rm longmeter}$'s there are in a normal meter.

To see how we can set more constants to unity lets take Newtons constant $G = 6.7\cdot 10^{-11} \frac{m^3}{s^2kg}$. If we now introduce a new unit for mass, call it $1\,{\rm bigkg} = f$ kg for some $f$, then in our (${\rm longmeter}$, ${\rm shortsecond}$, ${\rm bigkg}$) system we have $$G = 6.7\cdot 10^{-11} \frac{m^3}{s^2kg} = 6.7\cdot 10^{-11} \frac{(10^3 m)}{10^3} \frac{(3\cdot 10^8 m/s)^2}{(3\cdot 10^8)^2} \cdot f$$ If we take $f = \frac{10^3[c]_{\rm SI}^2}{[G]_{\rm SI}} \sim 10^{30}$ (so this unit for mass is basically solar-masses) and use that $3\cdot 10^8 m/s = 1\,{\rm longmeter}/{\rm shortsecond}$ and $10^3 m = 1\,{\rm longmeter}$ then we find $$G = 1 \frac{({\rm longmeter})^3}{({\rm shortsecond})^2({\rm bigkg})}$$ Thus in our new units for length, time and mass the two constants $G$ and $c$ are unity (and we can do the same thing with Boltzmanns constant by defining a new unit of temperature, a HotKelvin, to get $k_b = 1$). Can we go further and set the next constant $\hbar$ to unity? Not in this case. This has units of $kgm^2/s$ and we have already fixed all these units so the value for $\hbar$ will be whatever it turns out to be ($10^{-76}$ or so for this example).

However we can fix $\hbar = 1$ if we go back and redefine our units, i.e. we can go back and change the particular choices $10^3$ for length and $\frac{1}{3\cdot 10^5}$ for time and $f$ for mass and let these be free numbers. Now demanding that $G=c=\hbar=1$ this will give us a system of equations for our length, time and mass units that can be solved (and has a unique solution since we have $3$ units and $3$ equations). This is what we call natual (or Planck) units (and there is also the unit for charge we can set to put Coloumbs constant $k_e$ to unity, but we won't need that). In general we are free to fix as many fundamental constants as we have units. How do we do this in general?

Instead of $m,s,kg,K$ we use units $\tilde{m}, \tilde{s}, \tilde{kg},\tilde{K}$ and define $$L = \frac{\tilde{m}}{m}$$ $$T = \frac{\tilde{s}}{s}$$ $$M = \frac{\tilde{kg}}{kg}$$ $$P = \frac{\tilde{K}}{K}$$ These are the conversion constants we can use to go from our units to SI units and vice versa and they can be choosen any way you want (as long as they are non-zero positive numbers). Expressing the fundamental constants in these general units we find: $$c = [c]_{\rm SI} \frac{m}{s} = \frac{[c]_{\rm SI}T}{L} \frac{\tilde{m}}{\tilde{s}}$$ $$G = [G]_{\rm SI} \frac{m^3}{s^2kg} = \frac{[G]_{\rm SI}T^2M}{L^3} \frac{\tilde{m}^3}{\tilde{s}^2\tilde{kg}}$$ $$\hbar = [\hbar]_{\rm SI} \frac{kgm^2}{s} = \frac{[\hbar]_{\rm SI}T}{ML^2} \frac{\tilde{kg}\tilde{m}^2}{\tilde{s}}$$ $$k_b = [k_b]_{\rm SI} \frac{J}{K} = \frac{[k_b]_{\rm SI}PT^2}{L^2M} \frac{\tilde{J}}{\tilde{K}}$$ From this its easy to compute what these constants are in any given set of units and its easy for us to pick units for which they have a particular value.

For example if we want Planck units then that means we have to demand $$\frac{[c]_{\rm SI}T}{L} = 1$$ $$\frac{[G]_{\rm SI}T^2M}{L^3} = 1$$ $$\frac{[\hbar]_{\rm SI}T}{ML^2} = 1$$ $$\frac{[k_b]_{\rm SI}PT^2}{L^2M} = 1$$ which you can solve (and then plug in the SI values for the physical constants) to find (e.g. Wolfram Alpha , , , ) $$M = \sqrt{\frac{[\hbar]_{\rm SI} [c]_{\rm SI}}{[G]_{\rm SI}}} = 2.176435\cdot 10^{-8}$$ $$T = \frac{[G]_{\rm SI}M}{[c]_{\rm SI}^3} = 5.391247\cdot 10^{-44}$$ $$L = [c]_{\rm SI}T = 1.616255\cdot 10^{-35}$$ $$P = \frac{L^2M}{[k_b]_{\rm SI}T^2} = 1.416785\cdot 10^{32}$$ This tells us that $1 \tilde{m} \approx 10^{-35} m$ (pretty pretty short) and $1\tilde{K} \approx 10^{32}K$ (pretty pretty hot).

If you only fix $3$ of the constants to unity (or whatever value you want for that matter) then we will have one free parameter left above. In these cases you can pick any unit (fundamental or derived) you want, say meter or Joules or whatever and put this to unity. Every quantity can then be expressed as some powers of this unit (see below for an example). If we only fix $2$ we will have two free choices and so on.

If you implement your equations and units correctly in your code then in a perfect world it would not matter at all what units you choose to use - the results will be the same. However in real life there are issues that can happen if a constant gets too small or large as to over/underflow in calculations (e.g. if $\hbar = 10^{-100}$ and $k_b = 10^{200}$ in some units and you need to calculate $k_b^2\hbar^4$ - which should be $1$ here - the first term will overflow to Inf and the second will underflow to $0$ and the product will be NaN) and there can also be issues related to speed and accuracy (e.g. denormal numbers are usually much slower to do math on). That's why we usually pick units such that our quantities are $O(1)$ (which is why Mpc is a length good unit for the CMB - the modes we need to look at are in the range $10^{-4}/$Mpc to $1/$Mpc). Planck units has the advantage that it shouldn't matter at all if you get the constants correct in your equations - these constants are just unity anyway!

In the lectures and in Dodelson we will use a slightly different form of the natural units presented above where we set $c = \hbar = k_b = 1$ (i.e. we don't set $G$ to unity). In these units a length, time, temperature and energy can all be expressed in terms of one single unit. A common choice in particle physics is to use electronvolts (eV; another choice is to use the mass of the electron as the base unit, but we'll stick with eV) so that a length and time is an inverse eV, an energy a temperature and a mass is eV (energy and mass is related via $E=mc^2$ and with $c=1$ a mass is the same as an energy), a length and time is $eV^{-1},$ a density is $eV/eV^{-3} = eV^4$ and so on. It's a good exercise, to try to see if you understand how to work between different units, to compute what $G$ is in these units (you should find something like $G \approx 10^{-57} eV^{-2}$). In these units its very easy to see if two sides of an equation has compatible units (i.e. to check if you have made some big mistake in a calculation): you simply count the energy-dimension of each side. For example in $E = \frac{GM^2}{R}$ we have $E$ has dimension $1$ (its unit is $eV^1$) and on the right hand side we get $-2$ (from $G$), $+2$ (from $M^2$) and $-(-1) = +1$ (from $1/R$ since $R = eV^{-1}$) so the total is $-2+2+1=1$ which agrees with the left hand side.

In cosmology other choices of units than SI or natural units can be more appropriate. For example it is often more handy to use use a distance scale that is $\sim Mpc$ (the typical length scales associated with the CMB ranges from O(1000) Mpc down to O(1) Mpc). We generally want to use units for which the numbers we deal with have sensible values if possible (i.e. not crazy small or large). In a numerical code we want to deal with physical units as little as possible. If possible they should only enter the code when taking input or giving output (for which we convert to or from our code-units).

One final note on converting back and forth: if you have a quantity, let's say a length, in some special set of units and you want to convert back to meters then you must divide by $L$ (recall the definition of $L$). Likewise if you want to go from SI units to your units you must multiply by $L$.

Example - units where $c=1$: In SI units $H_0^{-1}$ is a time. If we work in units where $c=1$ the Hubble constant can also represent a distance: $$\frac{1}{H_0} = \frac{c}{H_0} = 2997.92 \frac{{\rm Mpc}}{h}$$ Thus if you encounter a dimensionless product like $rH_0$ where $r$ is a distance then in SI units the expression with units restored has to be $rH_0/c$. Einsteins relation between mass and energy becomes even simpler in these units: $E=m$. This is quite useful in particle physics calculations: we can express energies and masses in the same unit (which typically is eV). For example we can say that the electron mass is $0.5$ MeV (which means $0.5$ MeV$/c^2$ in SI units). If we also have $k_b = 1$ then we can express temperatures as an energy ($k_bT$ is an energy), i.e. we can talk about the time in the Universe when the temperature was the same as the electron mass. And this is super useful to understand the early Universe (interesting things usuallly happen when the temperature is comparable to the mass of the particle we are considering).

Examples of equations in Planck units: Take for example the Schwarzschild radius of a black hole which is given by $R = \frac{2GM}{c^2}$. In natural units this simplifies to $R=\frac{M}{2}$, i.e. the diameter equals the mass! Another example is the entropy of a black hole $S = \frac{k_bAc^3}{4G\hbar}$ which simplifies to $S = \frac{A}{4}$ so simply entropy = area! This might look a bit weird at first, but it makes long calculations much easier to write once you get used to it. And as I said in the beginning we can always recover the equation in SI units. How do we do this? With training you can often "see" it directy, but there is also an algorithm you can use. This is called dimensional analysis which is the subject of the next section.

### Planck Units

In Planck units (also this) we enforce $c=\hbar=k_b=G=1$. This leads to $$M = \sqrt{\frac{[\hbar]_{\rm SI} [c]_{\rm SI}}{[G]_{\rm SI}}} = 2.176435\cdot 10^{-8}$$ $$T = \sqrt{\frac{[\hbar]_{\rm SI} [c]_{\rm SI} [G]_{\rm SI}}{[c]_{\rm SI}^5}} = 5.391247\cdot 10^{-44}$$ $$L = \sqrt{\frac{[\hbar]_{\rm SI} [c]_{\rm SI} [G]_{\rm SI}}{[c]_{\rm SI}^3}} = 1.616255\cdot 10^{-35}$$ $$P = \sqrt{\frac{[\hbar]_{\rm SI} [c]_{\rm SI}^5}{[k_b]_{\rm SI}^2[G]_{\rm SI}}} = 1.416785\cdot 10^{32}$$ In the C++ code template you can get Planck units by taking:

// File src/Utils.h
extern struct ConstantsAndUnits {
const double m           = 1./1.616255e-35;     // Length unit (How many of those in a meter)
const double s           = 1./5.391247e-44;     // Time unit (How many of those in a second)
const double kg          = 1./2.176435e-8;      // Mass unit (How many of those in a kg)
const double K           = 1./1.416785e32;      // Temperature unit (How many of those in a Kelvin)
...
} Constants;

// Testing this
std::cout << Constants.c    << "\n";  // Outputs 1
std::cout << Constants.hbar << "\n";  // Outputs 1
std::cout << Constants.k_b  << "\n";  // Outputs 1
std::cout << Constants.G    << "\n";  // Outputs 1


There is also a variant of this that where we set the Planck mass to unity so $8\pi G = 1$. For this you have to multiply $L$ and $T$ by $\sqrt{8\pi}$ and divide $M$ and $P$ by $\sqrt{8\pi}$.

### Particle Physics Units

We fix $c=\hbar=k_b=1$ and fix the remaining unit by enforcing $1eV/c^2 = 1\tilde{kg}$ (a unit energy is one electronvolt) giving us: $$M = \frac{[c]_{\rm SI}^2}{[eV]_{\rm SI}} = 1.7826615 \cdot 10^{-36}$$ $$L = \frac{[eV]_{\rm SI}[\hbar]_{\rm SI}}{[c]_{\rm SI}^3} = 1.973266 \cdot 10^{-7}$$ $$T = [c]_{\rm SI}L = 6.5821085 \cdot 10^{-16}$$ $$P = \frac{T^2}{L^2M[k_b]_{\rm SI}} = 1.160452 \cdot 10^{4}$$ and Newtons constant becomes $G = 6.7088\cdot 10^{-57}$. In the C++ code template you can get these units by taking:

// File src/Utils.h
extern struct ConstantsAndUnits {
const double m           = 1./1.973266e-7;      // Length unit (How many of those in a meter)
const double s           = 1./6.5821085e-16;    // Time unit (How many of those in a second)
const double kg          = 1./1.7826615e-36;    // Mass unit (How many of those in a kg)
const double K           = 1./1.160452e4;       // Temperature unit (How many of those in a Kelvin)
...
} Constants;

// Testing this
std::cout << Constants.c    << "\n";  // Outputs 1
std::cout << Constants.hbar << "\n";  // Outputs 1
std::cout << Constants.k_b  << "\n";  // Outputs 1
std::cout << Constants.G    << "\n";  // Outputs 6.70885e-57
std::cout << Constants.eV   << "\n";  // Outputs 1


There is also a variant of this which is more commonly used where we instead require $m_e=1$ (the mass of the electron which is $\sim 0.5$ MeV).

# Dimensional analysis

In this course we often use (one form of) natural units for which $c = \hbar = k_b = 1$. When we need to solve our equations numerically we need to recover these equations in normal SI units, i.e. we need to "restore" the $c,\hbar,k_b$ we have put to unity. The procedure to do this is called dimensional analysis. Here is how you can do this.

Below we will use the notation $[x]$ to denote the units of $x$. We know that $[c] = m / s$, $[\hbar] = Js = kg\cdot m^2/s$ and $[k_b] = J / K$. If you have an equation like $$\frac{d\tau}{dx} = -\frac{n_e \sigma_T}{H}$$ and you want to introduce the missing constants then since $\tau$ and $x$ is dimensionless the right hand side must be dimensionless. $[\sigma_T] = m^2$, $[n_e] = 1/m^3$ and $[H] = 1/s$ so the right hand side currently has units of $m^{-3} \cdot m^2 \cdot s = s/m$ so there is some physical constants missing. How do you find the combination of constants needed? You can do this mechanically by putting up the equation $$1 = [\hbar]^A [c]^B [k_b]^C \cdot [n_e \sigma_T / H] = (kg m^2 s^{-1})^A (m s^{-1})^B (kg m^2 s^{-2} K^{-1})^C \cdot \frac{s}{m}$$ And then solving the linear system that arises when requiring each of the units to match up. In this example $$0 = 2A + B + 2C-1 \,\,\,(\text{the power of 'm' on the RHS})$$ $$0 = -A - B - 2C+1 \,\,\,(\text{the power of 's' on the RHS})$$ $$0 = A + C \,\,\,(\text{the power of 'kg' on the RHS})$$ $$0 = -C \,\,\,(\text{the power of 'K' on the RHS})$$ The solution is $A=0$, $B=1$ and $C=0$ so the equation with the constants reintroduced is simply $\tau' = -\frac{cn_e\sigma_T}{H}$. This is very tedious, but it will always work if you do it correctly. However in this simple example its quite easy to see directly that we need to multiply it with $c$ as this automatically cancels the $s/m$ unit we already have.

There are some simplifications one can do. For example temperature only enters through the Boltzmann constant $k_b$ (Joules per Kelvin) so whenever you have a $T$ in an expression you know you have to add $k_b$ in front, i.e. make the replacement $T\to k_bT$.

Note that we cannot apply a (non-linear) function to something with units (why?) so whenever you have something like $e^{-\frac{\epsilon}{T}}$ you know that the argument of the exponential must be dimensionless so $[\epsilon/T] = 1$ and since $\epsilon$ is an energy (and so is $k_bT)$ the expression with units introduced is simply $e^{-\frac{\epsilon}{k_bT}}$.