# Modeling Expansion

Goal: model an expanding universe.
Scenario: a single photon that passes a series of targets placed 200 million light years apart

## Basics

``````var simple = {
photon: {d: 0},
next: function () {
this.photon.d += c
}
}
``````

This JavaScript code defines an object, called `simple` that contains two things, a `photon` and a `next()` function. The `photon` has a distance `d` which starts at zero. Every time `next()` is called, `d` increases by `c`.

The operator `+=` means "add this to myself", so this line of code:

``````        this.photon.d += c
``````

is shorthand for this line of code:

``````        this.photon.d = this.photon.d + c
``````

Now we need to do a few things:

• Define the model's units
• Define c
• Call the `next()` function in a loop
• Record when the photon passes a target

That's what the following code does:

``````// time units:          1 million years
// distance units:      1 million light years

// the speed of light   1 million light years / million years
const c = 1

function run(model) {

// create targets at distance (d) 200 million light years apart
model.targets = []
for (var i = 200; i <= 30000; i+=200)
model.targets.push({d: i, start: i})

var t = 0
var nextTarget = 0

// start the loop
while (model.targets[nextTarget]) {

//advance the model 1 million years
t += 1
model.next()

// if we hit a target record the time
if (model.photon.d >= model.targets[nextTarget].d) {

console.log("Target reached", t)
model.targets[nextTarget].hit = t

nextTarget += 1
}
}
}
``````

The `run()` function creates an array of targets, and then calls `next()` in a loop, which moves the photon. The time `t` is recorded whenever the photon passes a target.

## Expansion

Hubble's law is `v = HD`, where `v` is the velocity of the target, `H` is Hubble's Constant, and `D` is the distance of the target. How hard could that be?

### Attempt 1

It seemed all I would have to do to model the expansion of space is calculate the velocity of a target based on its distance, like this:

``````var expanding1 = {
photon: {d: 0},
next: function () {
this.photon.d += c

// targets move at H × D
for (var target of this.targets)
target.d += H * target.d
}
}
``````

While `simple.next()` just moves the photon, `expanding.next()` moves the photon and the targets.

The important new line in this model is `target.d += H * target.start`, and it contains a new constant `H`, which is Hubble's constant, which was recently measured to be 74 km/sec/Mpc.

To use this value in the model, it must be converted to the proper units.

• Step 1: convert (km/s / Megaparsec) to (km/s / Million light years)
• Step 2: convert (km/s) to (light years / year)
Which gives:
```    74 km/s/Mpc = 22.6880185 km/s/Mly = 7.56790836e-5 ly/y/Mly = 0.0000756
```

Here is attempt 1:

(note these are zoomed way out so you can see more of what happens)

This sends the targets flying away too fast. It's not even close to what the standard model should predict. Something isn't right.

### Attempt 2

In Hubble's Law, the `D` supposedly stands for co-moving distance, and not good ol' proper distance.

"Comoving distance factors out the expansion of the universe, giving a distance that does not change in time due to the expansion of space"

Ok, then. If Hubble's Law calls for co-moving distance, and co-moving distance doesn't change with the expansion of the universe, then the model should be changed to calculate the target's velocity based on its `start` distance, which will always be the same.

``````var expanding2 = {
photon: {d: 0},
next: function () {
this.photon.d += c

// targets move at H × D
for (var target of this.targets)
target.d += H * target.start
}
}
``````

This seemed to be a bit more manageable. And for some reason, this actually produces the right z's one would expect in an expanding universe, but only plotted against distance, not time.

### Attempt 3

It turns out, this doesn't really capture expansion very well. According to expansion, the target doesn't simply move away from the photon. The target and the photon are both part of the Hubble flow. Space expands in front of and behind the photon, giving it a speed boost along the way.

Here's a good discussion on this: Does a photon travel more than 1 billion light years in 1 billion years due to the expansion of space?

So not only should the targets be moving according to Hubble's Law, so should the photon. Not only that, but the targets should be updating their velocity as they go, so we have to also revert the change made in attempt 2.

``````var expanding3 = {
photon: {d: 0},
next: function () {

// photon and targets move at H × D

this.photon.d += c + H * this.photon.d

for (var target of this.targets)
target.d += H * target.d
}
}
``````

By gaining some speed in the Hubble flow, we can interpret the photon's change in speed as stretching in wavelength to easily calculate the redshifts:

``````    this.photon.v = c + this.photon.d * H
this.photon.d += this.photon.v
this.photon.w = (this.photon.v * 299792458 / this.photon.f)
``````

And this worked great. They were just as expected. I would thank the internet people here by name, but they didn't seem interested in getting credited.

### Attempt 4

Attempt 3 was originally going to be Attempt 2 with a wavelength stretching photon. I copy-and-pasted Attempt 1 by mistake, and that worked. It took me hours to recreate the results, because I didn't realize I copy-and-pasted the wrong (but actually right) Attempt 1 code to begin Attempt 3.

For completeness, this is what Attempt 3 would have been, which I'll call Attempt 4:

``````var expanding4 = {
photon: {d: 0},
next: function () {

// photon and targets move at H × D

this.photon.d += c + H * this.photon.d

for (var target of this.targets)
target.d += H * target.start
}
}
``````

Way off!

My intuition at the beginning was that the decelerating photon hypothesis and the expanding universe were analogs, insofar as they should predict the same time delays in light signals from galaxy to galaxy.

When I arrived at Attempt 2, I just accepted that my intuition was wrong, and my hypothesis is not identical to the expanding universe the way I thought it was.

Of course, through feedback on the internet, and sheer dumb luck, I got Attempt 3. which matches the decelerating photon hypothesis exactly.

``````hypothesis1 = {
photon: {d: 0},
next: function () {
this.photon.d += c - H * this.photon.d
}
}
``````

Go back to Hubble's Law as Photon Velocity

Or check out the Testing Page