Not quite. In the simplified setting I was working with, you are going for a mix of cottages and farms that makes:
(1) Food surplus = remaining growth
As you grow closer to your desired size, you are actually going back and converting previously built farms to cottages to try and ensure (1).
GS
Yea, I agree that is the most simplified formula

Make sure:
food surplus = population units to grow until you hit the health or happiness caps.
in other words,
food surplus = remained growth
As your city gets closer to the desired size, you will start switching farms to cottages. so for the 15 cottage or 15 farm scenario, at size size 6 with a

surplus of 9 (4 initial + 5 farms), the remaining growth is 9.
Thus, you chould start working a cottage with the 7th citizen. 8 growth remains and your

surplus is 9. Thus, you will turn 1 farm into cottage. You will work 2 cottages and 5 farms and the initial +4

rice.
Next, at size 8, 7 growth remains. Work the initial rice and 3 farms, for a total of 7

surplus and start working the 3rd & 4th cottages.
Next at size 9, 6 growth remains. Work the initial rice and 2 farms, for a total of 6

surplus and start working the 5th & 6th cottages.
Next at size 10, 5 growth remains. Work the initial rice and 1 farm, for a total of 5

surplus and start working the 7th & 8th cottages.
Next at size 11, 4 growth remains. Work only the rice for a total of 4

surplus and the 9th & 10th cottages.
For subsequent population growths 11-14, you will work the remaining cottages 11 through 14, switching farms to cottages if you haven't done earlier.
Here it goes
Remember that a city with only a 4

surplus rice should work farms until population 7. The 7th citizen starts to work the first cottage.
With a 5

surplus corn, work farms until population 6 for a total of 9

surplus. The 6th citizen starts working the first cottage.
With a 6

surplus pig, work farms until population 5 for a total of 10

surplus. The 5th citizen starts working the first cottage.
With a 6

surplus pig and a 4

surplus rice, for a total of 10

surplus through food resources, the 4th citizen starts working the first cottage.
Beautifully optimized!
PS. I would still work 2-3 farms more than in this scenario because of Slavery usage, to support 2 library specialists and 1 spy specialists, and the slight effect of growing getting more difficult with each new population unit. Artichoker's example was a huge exaggeration with 100 turns. In reality on marathon speed, going from size 10->11 with 5

surplus would take 63/5=12 turns, 1/8 of what Artichoker mentioned.