Doesn't this shortchange the food in the city? You'd have to start with a food bin that's nearly full, to grow to P-1 right away. But then it would end up just half hull, from growing to P on the final turn. So if you wanted to repeat this cycle, you'd have to spend some extra turns refilling at size P, and it's no longer a 10 turn cycle. Which is OK, but I'm not sure it's optimal.
At least one of us doesn't understand the question. Try again?
It might be that you are missing the food overflow that occurs on both ends.
Initial condition: 9 + P + X / ( 20 + 2P )
After whip: 9 + P + X / ( 16 + 2P )
Surplus required on first turn of cycle: 7 + P - X
Foodbin after first turn: ( 8 + P ) / (18+2P)
Surplus required during next nine turns: 9 + P
Foodbin after tenth turn: ( 17 + 2P )
Surplus reuqired on last turn of cycle: 1 + X
Final Condition: 9 + P + X / (20 + 2P)
So roughly speaking, a harvest at the beginning and the end, with 9 turns in the middle where you are net positive food per turn, but not very much.
And then the rest of the exercise is just demonstrating that the arrangement that requires the lowest peak surplus is not to start with the granary nearly full (because that requires a lot of food on the last turn), but rather with the granary just short of 34 full.
With numbers, at size six.
If you start with the granary almost full (28/32), you don't need any food surplus on the first turn (28/28), but you need 14 surplus on the last turn (from 29/30 to 28/32).
If you start with the granary at 15/32 (the result of an exact growth), then you only need 1 surplus on the last turn (29/30 to 15/32), but you need 13 surplus on the first turn (15/28 to 14/30).
But if you start with the granary at 21/32, the whip brings you to 21/28, you need 7 surplus to grow on the first turn, and then you need 7 surplus to grow from 29/30 to 21/32.
A Ha! Found an error. In earlier posts, I had talked about needing a different equation for odds and evens, but I misunderstood the result - I got confused by a piece that was an artifact of my model. So the ideal point is 3/4 bin - 3 when P is even and... something else when P is odd, because 3/4 bin is not an integer in that case.
In other words - as long as you hit the right end points for the middle turns (growing exactly to P-1 on the first turn, exactly one food short of growing on the last), any initial condition that doesn't require starving to set it up will need the same food surplus on the first and last turn combined.
You need the minimum (at the 3/4 point) to show you what's possible -- so that you can abandon a plan that can't possible work, and so that you don't put yourself in a position where you are "forced" into working lower yield tiles than is optimal.
Here's an extreme illustration of the problem: suppose you start the cycle at 31/32. you whip (31/28), and arrange a 3 food deficit on the initial turn. Over the next 9 turns you slowly grow to 29/30. Now on the final turn, you need a 17 food surplus.
That's possible - the city is +2, so if each pop is on a 5F tile, you produce 27 food and consume 10. Perfect. But, umm - what tiles were you working when you weren't growing at 17 food / turn? How on earth did you manage a -3 deficit when a single tile and the city would provide 7 of the 8 food you needed? etc.