# Simulating Time¶

Read time: 23 minutes (5914 words)

Remember our “dance” simulation? In that simulation, we all took turns getting “happy”. Silly, but kind of fun.

What we were doing was simulating the flow of electrons through a material. That simulation was pretty weak, but I hope it got its point across. The side effects of each simulated atom’s mad desire to get “happy” produced a “flow” of electrons through the system. No one electron traveled very far, but when we looked at the system as a whole, there was a change in the number of electrons at any given point as the simulation proceeded.

What we were really doing was setting up a way to measure the value of an electric charge (related to the number of electrons present) at specific points in our system. That value changed over time as the electrons moved around.

What does that term “move” even mean?

We establish the position of something in our three-dimensional” world. You should be comfortable in that 3D world. You have a height, a width, and a depth, terms we use to speek of the position of things in an X-Y-Z coordinate system. Write down any three numbers, and you have nailed down one position in space. Figure out the position of the top of your head, the position of the bottom of your feet, do a little math, and you can calculate your height!

To “move” is to change those three variables some amount. Simple! If your “grow”, your height probably changes, and you get taller. The top of your head “moved” up, but the rate at which it did this was incredibly slow (it seems!)

Our electrons “moved” from atom to atom in our simulation. But did that happen all at once, or was there some moment in time when they were somewhere in between?

How would I know, and how should I study that? Do I even need to study that if I want my simulation to be good? Apparently, time has something to do with all of this!

## Time is Important¶

Imagine a world in which time did not exist. Scary thought.

That entire world would just sit there. Nothing would “happen”, since we use that term to describe changes over time. But we have no time.

Note

Sounds like another research problem for George Boole. He is done with a world where there are no numbers, other than one and zero!

Let’s consider a simple object, like a car.

When it is parked, it just sits there. There are no changes in the car over a period of time. However if we set the car on motion, there are changes in something about that car over time.

### State¶

We can set up a bunch of variables to record different aspects of the car’s makeup. We might measure its weight, color, and position on the planet, for example. There probably would be many more variables to record to do a really good job of describing each car we might want to study. Collectively, we call the current set of values in all of these variables the state of the car.

#### State Variables¶

Just to be certain we are talking about something associated with a car that might change over time, each variable we record is called a state variable. That distinguished these variables from others we might use to calculate something about the car. You might not care about the position of your feet and your head, but you do care about your height!

#### State Changes¶

That state can change from moment to moment as time marches on! That parked car probably experiences no changes in any of those state variables over a period of time. It just sits there. However, if we set the car in motion, each of those variables (well maybe not the color, unless it was going really fast) might change over time.

The weight is going to change (why has to do with gas consumption - wait, the amount of gas in the car is probably another state variable we need to track!)

The current position on the planet is certainly going to change. Know what, the rate of change of that position in some direction might be something to track as well. We call that the velocity of the car, measured in some direction. The absolute velocity of the car (its velocity measured in the direction it is moving), is called its speed!

The color is not likely to change. Or is it? Over a long enough period of time, far longer than the time we might need to study to gas consumption, the color might fade (especially in Texas). We could track that if we like!

It looks like the passing of time is pretty important to our study of cars!

## Modeling Time¶

As far as we know, time marches smoothly from right now forward to some other time in the future. So far, we have been unable to get time to move in any other “direction”, but that might change as time marches on.

We should be able to see that we can use a loop to “simulate” the passing of time:

for(time = NOW, time <= FUTURE, time+= DELTA_TIME)
// do something at each moment in time


In this loop, we assign some initial value to the time variable, and watch that variable change as the loop runs. Actually, we are not watching everything as time proceeds. Instead, we are sleeping as time marches on, then waking up after some small amount of time has passed (measured by DELTA_TIME) and looking around at our system. In essence, we are watching our system by examining snapshots of the state of the system at discrete moments in time between NOW and FUTURE.

In doing that, we are turning the real world into a sequence of snapshots of the state of that world. We have “discretized” the problem.

Fsr us, studying a computer, this is a good thing, because we really do not want to watch as everything changes in our simulation!

Here is an example.

When a real digital circuit changes from a zero to a one, it exhibits something called “ringing”. That simple emans that the circuit cannot just instantaneously make that change. It goes through a complex incremental change from that “zero” to the final “one”.

In our work, we will look at the signals in this system as specific points in time, and claim the system is a zero if the voltage is below some value, and one it is above some other vlue. In between? Well, we are going to ignore that! We will set up our simulation so when we wake up and look at it, it it is in one of these two states.