So if \(K\) were always 0.6% or 0.7% (or any other value), it would be easy. Make a guess about the life expectancy and read the best retirement age in the graph. Given that in the CPP \(K\) changes at 65, what happens at the transition? When the best retirement age is above 65, we are in the 0.7% rule. When it is below, we are in the 0.6% rule. Lets take a look at just those data points
There is still an overlap around a life expectancy of 78 years. If \(T\) were not required to be an integer, the difference in the best retiment age between two values for K would be $$\Delta T = \frac{D - \frac{1}{K_1} - 1 + 12*65}{2} - \frac{D - \frac{1}{K_2} - 1 + 12*65}{2} = \frac{1}{2K_2} - \frac{1}{2K_1}$$ For 0.6% and 0.7%, that is about 11.9 months. What we want to find is when is it worth to transition from $$T_1 = \frac{D - \frac{1}{K_1} - 1 + 12*65}{2}$$ to $$T_2 = \frac{D - \frac{1}{K_2} - 1 + 12*65}{2}$$ The logic is the same that we used for retiring from \(T\) to \(T+1\): the extra amount earned on the months that are left has to be larger than the lost payments $$(D - T_2)((65*12 - T_1)K_1 + (T_2 - 65*12)K_2) > (T_2 - T_1)(1 - K_1(65*12 - T_1))$$ Doing the substitutions (I used GiNaC ) we get $$\frac{D^2}{4000} - \frac{39D}{100} + \frac{12276379}{84000} > 0$$ Which has a solution of a life expectancy just over 77 years and 10 months. For the discrete case we can just test the 0.6% and 0.7% solutions and pick the best. The combined result is on the last graph:
And indeed, with a life expectancy of 77 years and 10 months one should retire at 64 years and 6 months. But with a life expectancy just a month longer, the best retirement age is 65 years and 6 months. When I first got curious about this I was lazy and just wrote a python script to try all the possible retirement ages. I was surprised to see the discontinuity in the graph and decided to do the math to see what was going on. The program is available on sr.ht in case anyone wants to try it.