On very large scales, the matter and energy in the universe is essentially uniformly distributed. This is the *cosmological principle*, which is justified by observations on scales greater than ~100Mpc. This is extremely convenient for our ability to model the universe, because it greatly simplifies the mathematics. If we apply General Relativity to a universe with a uniform distribution of matter and energy, we obtain the Friedmann equations, which describe how the expansion rate of the universe changes over time. These equations may seem complicated and mysterious. How can we be sure that they are accurate? Well, for one thing they are exact solutions to GR, and for another, they are very well tested against observations. Also, I think it is actually not that difficult to understand them, at least in a Newtonian context, by drawing an analogy to orbits. If we launch something from a planet with too slow of a speed, then it will slow down and come back. This is analogous to a "closed" universe, with too much gravitation such that its expansion slows down and then it collapses on itself in a finite amount of time. An "open" universe, with too little gravitating matter, will continue to expand forever. This is analogous to launching something from a planet on a hyperbolic orbit -- fast enough that it slows down, but never stops, and never comes back. Finally there is a perfectly balanced "flat" universe, which has exactly the right amount of gravitation so that the expansion rate slows to zero, but after infinite time. This is like a parabolic orbit, where the object was launched at exactly the escape speed.

(Aside: "Flat" in the cosmological sense does not mean "like a pancake", but rather that the spatial geometry is 3D-Euclidean, the type of geometry we are all intimately familiar with. It means two straight and initially parallel lines remain parallel, and the sum of angles in any triangle is 180 degrees. A closed universe on the other hand will have those straight, parallel lines converge on each other, and the sum of angles is greater than 180°. The 2D analogy is the surface of a sphere, where lines of longitude are straight, and parallel at the equator, yet converge at the poles. This is also called "positive curvature". An open universe will instead spread apart parallel lines, and the sum of angles in a triangle is less than 180 degrees. That is "negative curvature", and a good 2D analogy is the region around a saddle point.)

The Friedmann equations are the general relativistic version of this same logic. In fact, if we use the Newtonian laws of gravity, apply it to an expanding, uniform sphere of particles that interact only by gravity, then we will come up with equations that look almost identical to the properly general relativistic Friedmann equations (save for a few numerical factors and constants, like the speed of light.) Someday I might show the Newtonian derivation, which is quite a fun bit of physics, but for now let's take the equations as given. How do we use them to simulate a universe?

We'll start with the First Friedmann equation, written in a slightly different and more suggestive form:

Here "a" represents the size or "scale factor" of the universe. It is set equal to 1 at the present time by convention. If a grows to 2, then that means the distances between galaxies has doubled. The moment of the Big Bang corresponds to a=0.

"a" with a dot over it (which I'll write in text as a') represents the rate at which the scale factor is changing with time (like an expansion velocity). In calculus terms, the dot stands for a time derivative. Dividing a' by a means "expansion velocity per distance", which is the definition of the Hubble constant. The Hubble constant today in the real universe is roughly 68km/s/Mpc. This means a galaxy 1Mpc away is receding at 68km/s due to the expansion of space in between here and there. A galaxy 2Mpc away recedes twice as fast (136km/s), because there is twice as much space in between. For a wide range of cosmological distances, this linear relationship between distance and recession velocity holds, and this is known as Hubble's Law.

On the right hand side of the equation is H

_{0}, which is the value of the Hubble constant at the present time, and then a bunch of funny symbols Ω (omega). Each omega represents a density (for example Ω

_{m} is the density of matter), but as a fraction of the "critical density". The critical density is the exact density which would make the universe flat and slow down to zero expansion rate after infinite time. As an example, if the matter density was exactly the critical density of the universe, then Ω

_{m} would equal 1.

So, this first Friedmann equation says that the size of the universe changes at a rate which is governed by the densities of matter (Ω

_{m}), radiation (Ω

_{r}), and dark energy (Ω

_{Λ}). And there is an Ω

_{k}, which is 1 minus the sum of the others. That is, if the sum of the matter, radiation, and dark energy densities is exactly the critical density, then Ω

_{k}=0. The meaning of k is the spatial curvature. Ω

_{k}=0 is a flat universe, while Ω

_{k}>0 is open (negatively curved), and Ω

_{k}<0 is closed (positively curved).

One last thing to notice is how each Ω term is scaled by some power of a. This has a very deep physical meaning. Ω

_{m} is divided by a

^{3}, because the density of matter decreases with the volume of the universe, or the size of the universe cubed. Ω

_{r} gets divided by a

^{4} because radiation is not only dilluted just like matter, but each photon is also redshifted by expansion, which decreases its energy, and tacks on another factor of a. So the energy density of radiation drops off as a

^{4}. This is a weird way in which cosmological expansion appears to violate energy conservation -- the energy of radiation is

*not* conserved in an expanding universe!

Ω

_{Λ} is an interesting one. It is divided by the scale factor with a weird exponent, containing another parameter, "w". "w" is a knob which describes how the density of dark energy changes with expansion (in more precise terms it describes its equation of state). The simplest model, and the one that best agrees with observations, is w=-1, which means dark energy does not dillute at all. The interpretation is that dark energy is a property of space itself, rather than some substance like particles of matter. The more the universe expands, the more space there is, and thus there more dark energy there is. This is yet another example of how cosmic expansion seems to violate energy conservation. (It doesn't really -- energy conservation just does not apply in the usual way to an expanding space-time!)

Now to turn this equation into something we can use -- implementing it into a computer code which evolves model universes. To do so, we will convert it into an equation for acceleration. This is a good calculus exercise, and I'll explain briefly the steps and then show the final result.

First, multiply both sides of the equation by a

^{2} to get a' by itself on the left side. Then, take the time derivative of both sides. Using the chain rule, this means the time derivative of a'

^{2} is 2a'a''. Finally, isolate a'' (the acceleration) by dividing both sides by 2a'. The final result is:

This is a form of the 2nd Friedmann equation, also called the acceleration equation. As you might guess it describes how the universe's expansion speeds up or slows down. Notice that matter and radiation both act to slow it down (their coefficients are negative), while dark energy acts to speed it up. This isn't immediately obvious since there is a minus sign in front of the dark energy term too, but remember that w=-1.

At last, this acceleration equation can be implemented directly on the computer. We begin by setting the values of the cosmological parameters at the present time (all the Ω's and Hubble constant), calculate the acceleration a'', and then iterate again for the expansion velocity a' and the change in scale factor a:

Those are the fundamental equations programmed into the model, and we will explore their consequences below.

(Aside: The Friedmann equations may also (and often are) expressed and solved in *integral form*. Here I have instead opted to work with them in *differential form*, solving for the evolution of the model universe by successive iteration through small steps of time from some starting condition. In my case, starting at the present time with a value of H_{0}, and iterating both backwards and forwards.)