Suppose you are racing in on dimension, trying to get from 0 to 1 as quickly as possible. You start with a speed of 1. However at any time you choose, you may press a button that will instantly teleport you back to the origin, and multiply your speed by (1+2r), where r is the location at which you pressed the button.
If you can press this button as many times as you like, how fast can you finish the race, and when are the optimal times to press this? And how do things change if the multiplier is instead (1+kr)?
This question came up while thinking about traditional idle video games in which you can spend resources and purchase upgrades to increase your resource gathering rate, however these can generally only be activated by pressing restart and sacrificing all your resources.
The first question that needs answering is whether it is worth pressing the button at all? To work this out, we can consider a simplified model where we plan to press the button exactly once at point r. In this case the total time taken to complete the race is
The time taken to travel a distance r while travelling at a speed of 1: speeddistance=1r.
The time taken to travel from the origin to 1 while travelling at (1+2r): speeddistance=(1+2r)1.
Adding these together gives the total time: [eqTimeOnePress]: T=r+1+2r1.
We can find the optimal r by solving for when the derivative is zero: drdT=1−(1+2r)22=0.
This happens when 0=(1+2r)2−2,=4r2+4r−1,
which has solution given by the quadratic formula: r=2−1±2.
One of these solutions is negative, so not relevant to our problem. The positive solution is r≈0.2071.
Substituting this into [eqTimeOnePress] then gives a time of T=2−1+2+1+2(2−1+2)1≈0.9142.
This is less than 1, so it clearly does pay to press the button at least once. Now the question gets more complicated. How many times should we press the button, and when should we do so?
Now let's consider multiple presses. For reasons that will make sense later, I'm going to number the presses counter intuitively. The location of the last press will be denoted r1, the one immediately before that will be r2, and so on and so forth. The total time taken when using n presses will be denoted by Tn.
To start with, we'll assume two presses while we build some intuition for the problem. The total time to complete the race becomes:
The time to travel until the first press at r2 with speed 1: speeddistance=1r2.
The time taken to travel until the second press at r1 with speed (1+2r1): speeddistance=(1+2r2)r1.
The time taken to travel from 0 to 1 with speed (1+2r2)(1+2r1): speeddistance=(1+2r2)(1+2r1)1.
Adding these together gives the total time for two presses: [eqTimeTwoPresses]: T2=r2+(1+2r2)r1+(1+2r2)(1+2r1)1.
Now optimising this using derivatives is a multivariate calculus problem that would be a pain to do by hand. But you can fire up Python or Mathematica to get a numerical solution (see the appendix for code): r1r2≈0.2071≈0.1761.
The last press, r1, is at the same place as when we were only using one press! This is quite surprising. Let's try again with three presses and see if the pattern continues. In this case the total time is [eqTimeThreePresses]: T3=r3+(1+2r3)r2+(1+2r3)(1+2r2)r1+(1+2r3)(1+2r2)(1+2r1)1,
and the optimal times are r1r2r3≈0.2071≈0.1761≈0.1528.
Clearly this pattern is continuing. Why? Surely it would make sense that optimising across multiple presses would require adjusting all of them, not just the newest one.
Well let's take a look at equations for the times T1,T2,T3. In the case of a single press, what would happen if we started at a different speed, say s? Well then [eqTimeOnePress] becomes: T1=s1(r1+1+2r11).
This however is only a scaling factor. Scaling factors don't change the location of the optimal point, meaning the location of the press does not depend on the incoming speed.
Now let's re-examine [eqTimeTwoPresses] by cleverly factorising it: T2=r2+(1+2r2)r1+(1+2r2)(1+2r1)1,=r2+(1+2r2)1(r1+(1+2r1)1),=r2+(1+2r2)1T1.
Remember that r2 is the first press, and r1 the second. Due to the scaling argument we made above, the optimal location for the second press r1 is completely independent of the first press r2. However from this formula, r2 is determined by r1 due to the T1 in the equation above.
Similarly for [eqTimeTwoPresses]: T3=r3+(1+2r3)r2+(1+2r3)(1+2r2)r1+(1+2r3)(1+2r2)(1+2r1)1,=r3+(1+2r3)1(r2+(1+2r2)1(r1+(1+2r1)1)),=r3+(1+2r3)1(r2+(1+2r2)1T1),=r3+(1+2r3)1T2.
This confirms the observations that seemed strange before. It turns out that the optimal press value can be calculated purely based on the optimal press values that come after it, and not those before it. Hopefully now you can see why we chose that indexing system.
Generalising the analysis in the previous section, we have the result: [eqGeneralisedSequence]: Tn=rn+1+2rn1Tn−1.
Solving for the optimal point when the derivative is zero, and once-again exluding a non-physical solution, gives [eqGeneralisedRestarts]: rn=22Tn−1−1.
At this point, it's reasonable to investigate how the speed multiplier affects the results, rather than just looking at k=2. For this we can use the generalised form of [eqGeneralisedSequence]: : Tn=rn+1+krn1Tn−1.
Once again solving for optimal point at zero derivative gives: rn=kkTn−1−1.
Combining these gives us Tn=kkTn−1−1+1+k(kkTn−1−1)1Tn−1,
which simplifies to [eqGeneralisedCombined]: Tn=k−1+2kTn−1.
In the figure below we plot T1000 for values of k ranging from 1 to 10 (including decimals). See the appendix for Python and Mathematica code to generate this.