To round up this series about the date of Easter, I’d like to look at this part of Gauss’s algorithm, which I’ve rewritten with improved variable names:
metonic_year = year mod 19
century = [year / 100]
quadricentennial = [century / 4]
p = [(13 + 8 × century) / 25]
M = (15 - p + century - quadricentennial) mod 30
ndays_equinox_to_full_moon = ((30 - 11) × metonic_year + M) mod 30
How can we improve the names for p and M? Things are becoming difficult here. M is a correction that applies to the century, and p is so hard that Gauss got it wrong. He initially thought it was [century / 3], which gave wrong Easter dates from the year 4200 onwards. Gauss found about the error soon and made several failed attempts at fixing it, until a student of his finally found the correct expression about 15 years after the original paper.
The second observation is the number 11 in the last expression. The original algorithm doesn’t say 30 - 11, it says 19. Good luck explaining to someone that this is not the length of the Metonic cycle. Initially I had DIFF_BETWEEN_12_MOONS_AND_A_YEAR in place of 11, but this made the expression too long. Besides, I’d need to also use constant names for 30 (presumably the length of the lunar cycle), 19 (the length of the Metonic cycle) and more. It would make it harder to read.
One problem I’d try to correct is that the result isn’t actually the days from equinox to full moon—it’s actually the days from the day after the equinox to the day after the full moon. I might try to keep the name ndays_equinox_to_full_moon and instead change the algorithm so that the name is accurate. In fact, trying to improve the name of a variable often leads to entirely refactoring the code.
If I wanted to write a paper on this I’d continue these improvements, but I think I’ve said enough and I’ll stop here.