Math Says Don't Slow Down At Red Lights

Generated by FLUX.1-schnell.

The Problem

One day, I was riding my bike to high school as I approached a red light, unsure of when exactly it would turn green, and noticed I was kind of trying to slow down at some steadily decreasing rate. I was trying to simultaneously accomplish two things:

  • Slow down as little as possible, in order to preserve as much speed as possible and spare my lazy legs
  • Slow down enough to make sure that the light will turn green before I reach the intersection and have to come to a complete stop

So I was kind of trying to do an optimization, balancing these two factors. It occurred to me that there must be some optimum solution that I should be able to reach mathematically, given some assumptions. The solution could be obvious to some people, but to me it really wasn’t clear; maybe you should avoid the breaks entirely in order to maintain the maximum possible speed if you get lucky and the light turns green quickly, or maybe you should break significantly in order to delay reaching the intersection and ensure that you can maintain at least some speed if you get unlucky and the light stays red for a long time.

Formalizing this optimization problem:

  • \(v(t)\) is the speed as a function of time. It must be monotonically decreasing, since you want to conserve energy until you’re sure that you can pass the intersection in a green light. This only describes the speed before the light turns green; after that, our optimization puzzle is done, the solution is very clear. The cyclist should not slow down at all, and probably should start speeding up again.
  • \(T\) is the maximum time a light at this intersection can stay red. We assume the cyclist knows this from previous encounters with this intersection.
  • \(t_g\) is the amount of time that passes from the cyclist’s first sight of the red light until it turns green, assumed to be drawn randomly from a uniform distribution between \(0\) and \(T\). The cyclist does not know \(t_g\), and has to find a strategy for the distribution of possibilities.
  • \(D\) is the initial distance to the stoplight.
  • \(V=v(0)\) is the initial speed.

First, we can handle an easy case. If \(V < D/T\), then you’re guaranteed to see a green light before you reach the intersection, and you should not touch your brakes at all. From now on, we will assume this is not the case.

Expected Value Of Speed

So, if we want to preserve as much speed as possible, we might want to maximize the expected value of the final speed when the light turns green. This expected value will be calculated by using an integral to average the final speed over all possibilities for the unknown value \(t_g\):

Expected final speed: \(\frac{1}{T}\int_0^T v(t_g) dt_g\)

However, we now note that this integral is exactly equal to the expression which calculates the total distance traveled at time \(T\)! So, we just need an \(f(t)\) that maximizes distance traveled at time \(T\). Given our assumption \(V > D/T\), we know it is possible to have a \(v(t)\) function that reaches \(D\) at time \(T\) (the function which stays at \(v=V\) until you reach the intersection and then comes to an abrupt halt at \(v=0\)). So, \(\int_0^T v(t_g) dt_g=D\) is possible. And \(\int_0^T v(t_g) dt_g>D\) is forbidden, because that means you plan to enter the intersection even if the light is red. Therefore, we’ve found our optimum!

So, this is our answer. It’s totally inconsequential what you do with your breaks, just make sure you reach the intersection before you’re 100% sure the light will turn green.

What a nice simple answer to a nice practical problem. You can do lots of different braking patterns, and they will all lead to the same tiredness in your legs at the end of the day. Or do they…

On second thought, maximizing the expected value of speed isn’t really the problem we initially set up. I really care about the tiredness in my legs, not the speed of my bike. And the tiredness in my legs is determined by energy consumption, not speed. This would be our solution if going from 10 to 20 mph was exactly as easy as going from 0 to 10 mph.

This is actually the case for rockets, where a certain amount of fuel gives you a certain amount of Delta-v (change in velocity), and kinetic energy doesn’t really matter (kinetic energy isn’t the intuitive quantity to use for rockets in flight because the ejected rocket fuel has different kinetic energy depending on what reference frame you’re considering).

So if our bike was in space, this would be the right answer! But this is not the right answer for any propulsion method where you gain speed by pushing on a surface or fluid, as is the case for a bike, and basically everything else on earth.

This is supposed to depict a rocket-bike coming to a stop near a space-intersection. Generated by FLUX.1-schnell.

Expected Value Of Kinetic Energy

Really, we want to maximize the expected value of our kinetic energy, proportional to the square of our speed. Specifically, we want:

Find \(f(t)\) that maximizes \(\int_0^T \left[v(t)\right]^2 dt\) subject to \(\int_0^T f(t) dt = L\).

This is a harder problem than the one we just solved, and will take more work to reach a proof of an optimal solution.

This integral doesn’t directly work out to a nice physical quantity like in the previous case. So we are going to need to try to use calculus of variations, the field of math that tries to find optimal functions to solve some problem.

Let us phrase our problem in the typical language of the Calculus of variations, with an action functional \(s[v]\) and a Lagrangian \(L\):

\[s[v] = \int_0^T L(t, v, \dot{v}) dt\] \[L(t, v, \dot{v}) = v^2\]

Now, let’s apply the Euler-Lagrange equation, guaranteed to give us the local extrema of \(s[f]\).

\[\frac{\partial L}{\partial v} - \frac{d}{dt}\frac{\partial L}{\partial \dot{v}} = 0\] \[2 v - 0 = 0\] \[v = 0\]

Well, I guess \(v(t)=0\) and \(S[v]=0\) is a true minimum, and therefore a local extremum, so this did work. However, we failed to include our boundary condition \(v(0)=V\), so this is useless for our problem. There’s a trick we can apply here: make our Lagrangian more general, and therefore get more general solutions for the extrema, and then enforce our boundary condition on those. Let’s do this via a Lagrange multiplier \(\lambda(t)\).

\[L(t, v, \dot{v}) = v^2 + \lambda \dot{v}\]

This of course changes our problem, but the Lagrangian will be the same if we ensure that at each time \(t\), either \(\lambda(t)=0\) or \(\dot{v}(t)=0\). We’ll keep this in mind for the future.

Now let’s apply the Euler-Lagrange equation again:

\[\frac{\partial L}{\partial v} - \frac{d}{dt}\frac{\partial L}{\partial \dot{v}} = 0\] \[2v - \frac{d}{dt}\lambda = 0\] \[\dot{\lambda} = 2v\] \[\lambda = 2x + C\]

So, integrating to solve for \(\lambda\), we now have an expression in terms of \(x(t)\), the distance traveled at time \(t\), and \(C\), a free integration constant. We can plug this back into our Lagrangian:

\[L = v^2 + \lambda \dot{v}\] \[L = v^2 + (2x + C) \dot{v}\] \[L = \dot{x}^2 + C \ddot{x} + 2 x \ddot{x}\]

Now we have phrased things in terms of the position and its derivatives, rather than the velocity and its derivatives. But now that we have a double derivative, our usual Euler-Lagrange equation doesn’t work anymore. But lucky for us, smart people have encountered this before, and there exists a Generalized Euler-Lagrange Equation for us to use here! It just adds one more term to the equation. Let’s try it out:

\[\frac{\partial L}{\partial x} - \frac{d}{dt}\frac{\partial L}{\partial \dot{x}} + \frac{d^2}{dt^2}\frac{\partial L}{\partial \ddot{x}} = 0\] \[2\ddot{x} - \frac{d}{dt}(2\dot{x}) + \frac{d^2}{dt^2}(C + 2x) = 0\] \[2\ddot{x} - 2\ddot{x} + 2\ddot{x} = 0\] \[\ddot{x} = 0\]

So our Euler-Lagrange equation told us that there should be no acceleration. Matching our boundary condition \(v(0)=V\), this gives us exactly one solution:

\[v(t) = V\]

Checking back to our Lagrange multiplier constraint, we needed \(\lambda(t)=0\) or \(\dot{v}(t)=0\), and here we have \(\dot{v}(t)=0\) at all times \(t\), so this checks out.

So, apparently you’re not supposed to slow down at a stoplight! You should keep off the brakes as much as possible, hoping to zoom through the intersection at full speed with a green light, but ready to slam on the brakes as hard as you can at the last second if you’re unlucky and the light stays red too long. Good to know!

Should I Really Not Slow Down At Red Lights?

Keep in mind that I’m not telling you you shouldn’t brake, I’m just telling you that math is telling you you shouldn’t brake. Probably you should consider safety and whatnot and slow down. This math tells you that you’ll save some energy, but at the same time, other math will tell you that this method will increase wear on your brakes and tires, will likely make you come to a complete stop where balancing or stepping off your pedals can be annoying, and is relatively likely to cause injury or death to yourself or others.

You need to decide for yourself how you’ll balance this tradeoff between energy efficiency and human life. And you have to choose somewhere in the middle; the extreme ends of this spectrum correspond to either being a monster or never leaving your bedroom.

For myself, I’ll probably brake a little bit harder than I would have before knowing this, but nothing too crazy. Human intuition about how you should behave is actually pretty great at taking all of these factors into account, so I probably wasn’t really far off from the true optimum at the start.