# Calendars for the Modern Age

— EARLY CALENDARS AND THE LEAP YEAR PROBLEM —

Archaeological records suggest that calendar systems developed around the same time as writing in the ancient empires of Sumeria and Egypt, and from there spread rapidly through the Ancient Near East.

These early calendars came in many forms, and often reflect the culture or religion present in the empire that created or adapted them.  Quite often they reflect long-term weather patterns, like the Egyptian calendar, which features three seasons (flood, emergence, and low water) of 120 days each, followed by 5 intercalary days of civil and religious significance.

Notably, the Egyptian calendar lacks any concept of a leap year, which led the date to slip away from the tropical year, the length of time it takes the Earth to revolve around the sun (if you believe that newfangled heliocentrism nonsense).  For this reason the Romans would sometimes refer to the Egyptian calendar as the annus vagus (wandering year), in what I can only assume was the world’s oldest (re: only) calendrical diss.

The Sumerian/Babylonian calendar resembles the Egyptian calendar in many regards — it again features three seasons, broken into twelve lunar months with an intercalary period. Yet, unlike the Egyptian system, this calendar was a proper lunisolar calendar: it set months according to the lunar cycle and years according to the solar cycle.

Babylon’s emphasis on the lunar cycle led to an interesting resolution of the leap year problem: insert a thirteenth month whenever you feel like it.  At first these insertions were the subject of royal decree, put forth on a case-by-case basis. Later, Babylonian astronomers made the observation that 19 tropical years equaled 235 lunar cycles (accurate to within two hours!) and codified this lunar-solar epicycle into their calendar.

The Babylonian system survives in spirit as precursor to the Hebrew religious calendar, while the Egyptian calendar was supplanted by the Coptic, or Alexandrian calendar to better sync with the newly-minted Julian calendar.  Incremental refinements to the leap year system in the Julian calendar led to the introduction of the Gregorian calendar in 1582, which stands as the dominant calendar of the modern age.

In the Gregorian calendar, leap years are inserted into the calendar according to various divisibility rules.  The following algorithm suggests the historical development of these rules:

• There are no leap years (the Egyptian calendar)
• unless the year is divisible by 4 (the Julian calendar)
• unless the year is divisible by 100 (the Gregorian calendar)
• unless the year is divisible by 400 (the Gregorian calendar)

— HOW LONG IS A DAY? —

The Gregorian system includes 97 additional days every four centuries, and suggests that the length of the average tropical year is

$365 + \frac{97}{400} \approx 365.2425 \text{ days}.$

So, how close does this come to the true year length?

Unfortunately, this is a question without an answer.  While Kepler’s laws suggest absolute periodicity of orbits, the nutation of the Earth and the slight wobble of the Sun (due to gravitational influence of other planets) lead to a mean tropical year that changes (albeit slowly) over time.

To be strangely specific, Laskar’s planetary model (1986) suggests that for years near 2000 (give or take 10,000 years), the length of the mean tropical year has the following third-order Taylor approximation:

$365.2421896698-6.15359 \times 10^{-6} Y - 7.29 \times 10^{-10} Y^2 + 2.64 \times 10^{-10} Y^3,$

in which Y is number of (signed) Gregorian years from the year 2000. In particular, we compute that the length of the expected tropical year in 2017 is 365 days, 5 hours, 48 minutes, and 36.243 seconds. (This is a full 10 seconds shorter than the year 2000.)

— LEAP YEARS AS CONVERGENTS —

But let’s ignore the chaotic instability of the solar system for a moment and suppose that the Earth becomes locked into a perfect orbit with a tropical year of 365.242086145121 days.  What becomes the optimal leap year system to reduce drift from the tropical year?

One solution is to simply intersperse 14614766 leap years into every block of 60370105 years, but this method is a little clunky and doesn’t suggest how to distribute these leaps to reduce local errors.

A second solution uses the theory of continued fractions and convergents.  In continued fraction notation, we have

$\displaystyle 0.242086145121=[0,4,7,1,1,1,5,6,1,77,1,5,1,6,4],$

which we use to produce convergents a/b for the proportion of years that should leap. These convergents are

$\displaystyle \frac{1}{4}, \, \frac{7}{29}, \, \frac{8}{33}, \, \frac{15}{62}, \, \frac{23}{95},\,\frac{130}{537}, \,\frac{803}{3317}, \,\frac{933}{3854},\, \frac{72644}{300075},\, \frac{73577}{303929},\,\ldots,$

in which we recognize the Julian 1/4.

Here, we’ve defined convergents using continued fractions, but their fundamental property is made more clear by an independent definition: a reduced fraction a/b is a convergent to the number $\alpha$ if

$\displaystyle \vert a/b-\alpha \vert < \vert p/q- \alpha \vert$

for all fractions p/q with denominator $q < b$.  In other words, a/b is the best approximation to $\alpha$ with small’ denominator.

It should be clear how to use the first convergent, 1/4, to distribute leap years. For the second, 7/29, we begin with a leap year every 4 years, then notice that we’ve been over-counting by 1/4-7/29 and correct by subtracting 1/116. This creates the following rule: include leap days in years divisible by 4, unless that year is divisible by 116′. Note that even at this early stage we appear to differ from the Gregorian system.

Continuing in this way produces the alternating series of refinements

$\displaystyle \frac{1}{4}-\frac{1}{116}+ \frac{1}{957}-\frac{1}{2046}+\frac{1}{5890}-\frac{1}{51015}+\frac{1}{1781229}-\frac{1}{12783718}+\ldots,$

which not only suggests an incredibly convoluted scheme but also requires a huge number of epicycles to resolve itself!

Such is the issue with convergents — by looking only at improvements that can be implemented in the shortest periods possible, we end up with a greater number of terms in the long run.  For example, had we jumped from 1/4 to 15/62 in a single refinement, we arrive at the leap year rule divisible by 4 unless divisible by 124′, which drifts from the tropical year no faster than the system of corrections involving 4, 116, 957, and 2046 year cycles.

It’s safe to say that refinements via convergents are not the answer, but before we throw them under the bus I would like to remark on one of their nicer properties — the approximations they provide can always be written as a sequence of unit fractions, fractions with numerator one.

— ALTERNATING EGYPTIAN FRACTIONS —

It’s unclear where and when rational numbers originated.  They were widely accepted at least in ancient Egypt, with the small caveat that these Egyptian fractions were always written as a sum of unit fractions, ie.

$\displaystyle\frac{5}{6} = \frac{1}{2} + \frac{1}{3}\qquad \text{or} \qquad \frac{4}{5} = \frac{1}{2}+\frac{1}{5}+\frac{1}{10}$

(with the sole exception of 2/3, which was for some reason allowed).  Allowing for repetition, it becomes clear that every rational number can be written as an Egyptian fraction.  This works even if we force the denominators in our fraction to be distinct, a fact better left to the exercises.

Following the example of Egyptian fractions, I define an alternating Egyptian fraction (AEF) as a rational number written as an alternating sum of unit fractions with strictly increasing denominators.  (Following the remarks at the end of the last section, we see that every proper fraction can be written as an AEF via refinement of convergents.)

To fix notation, we write these as increasing sequences $\{a_1,\ldots, a_k\}$, and say that an AEF $\{a_1,\ldots, a_k\}$ is an approximation to $\alpha$ if

$\{a_1\} \geq \alpha,\quad \{a_1,a_2\} \leq \alpha,\quad \{a_1,a_2,a_3\} \geq \alpha, \quad\{a_1, a_2,a_3,a_4\} \leq \alpha,$

and so forth. Since each AEF can be used to create a leap year rule, we are led to consider the following questions:

1.  Given a $k$-term AEF approximation to $\alpha$, which unit fraction $1/a_{k+1}$ should I add or subtract to minimize error in a $(k+1)$-term AEF approximation to $\alpha$? (The algorithm to produce approximations by iterating this approach would be considered a greedy algorithm.)
2. In general, what is the optimal k-term AEF approximation to $\alpha$?

The first question is easy to answer, since at each step we’ve either over- or under-estimated (depending on whether our last term was positive or negative (resp.)), and the next unit fraction we include should be the smallest unit fraction (ie. with the largest denominator) that, when included, under- or over-counts in the opposite direction.

In our particular case we get the sequence of AEF convergents’

$\displaystyle\frac{1}{4}, \quad \frac{1}{4} - \frac{1}{126},\quad \frac{1}{4}-\frac{1}{126}+\frac{1}{44144},\quad \frac{1}{4}-\frac{1}{126}+\frac{1}{44144}-\frac{1}{12872315314},\ldots$

This algorithm converges quadratically to our limiting value, in that the number of digits of accuracy roughly doubles at each iteration.  In fact, the three-term approximation above lies within a millisecond of our stated correct’ value.  (It’s a bit of an understatement to say that this converges quadratically, since this algorithm actually terminates after 8 steps with an exact answer.  For comparison, the continued fraction-based algorithm terminates after 14 iterations.)

Question (2) above is a lot harder to answer, and I know no way to solve it beyond brute-force searching through fractions of bounded denominator. (I’ll make these bounds clearer in a second.)

The best 1-term approximation is clearly still 1/4.  For two-term approximations $1/a_1 -1/a_2$, we may assume that $a_1 \leq 4$ (else $\{a_1\} < \alpha$).  For each choice of $a_1$ we produce a bound on $a_2$ using the condition $\{a_1,a_2\} \leq \alpha$.  Taking the worst of these bounds shows that $a_2 \leq 126$ in general, and searching this space reveals that

$\displaystyle\frac{1}{4}-\frac{1}{126}$

is the best 2-term AEF approximant to $\alpha$. To find optimal 3-term AEF approximant to $\alpha$, we bound $a_3 \leq 44144$ in a similar fashion, and find (unsurprisingly?) that the familiar expression

$\displaystyle\frac{1}{4}-\frac{1}{126}+\frac{1}{44144}$

is in fact optimal among 3-term AEF approximations to $\alpha$.

At this point it seems reasonable to conjecture that the greedy algorithm always finds the optimal k-term AEF approximation to $\alpha \in (0,1]$. Yet after a bit of experimentation we conclude that this conjecture is false (at least for $k>1$); one simple counter-example can be seen by taking $\alpha =5/28$ and $k=2$. Here, the greedy algorithm gives the inexact approximation

$\displaystyle\frac{5}{28} \approx \frac{1}{5} - \frac{1}{46},$

while $5/28 = \{4,-14\}$ shows that an exact estimate is possible.

— LACK YEARS —

The approximations in the last section seem to suggest leap year rules beginning with the phrase hold a leap year if the year is divisible by 4, unless the year is divisible by 126′.

But here we’d be mistaken, as what our approximations really do is give algorithms for adjusting the number of days in a given year:  add a day if the year is a multiple of 4, subtract a day if the year is a multiple of 126, etc.  One quirk of this system is that the year 126 now has only 364 days — one might call it a lack year.

But lack years are silly, so we look to a solution already visible in the Gregorian calendar — choose an AEF approximation in which $a_k \mid a_{k+1}$ for all k. Under this additional restriction, we expect our AEF approximations to worsen, but how much? What are the new optimal AEF approximations to the mean tropical year?

Here, a modified greedy algorithm gives the sequence of approximations

$\displaystyle\frac{1}{4},\quad \frac{1}{4}-\frac{1}{124}, \quad \frac{1}{4}-\frac{1}{124} + \frac{1}{6572}, \quad \frac{1}{4}-\frac{1}{124} + \frac{1}{6572} - \frac{1}{663772},\ldots$

which converges linearly (ie. the number of correct digits increases like a linear function in the number of terms).

Since the Gregorian calendar uses a 3-term approximation it’s reasonable to make a comparison between the accuracy of that system and the third approximation above. Here, we find that our new system is 276 times more accurate.  (On the other hand, our improvement’ is still almost 20,000 times less accurate than the $\{1,126,44144\}$ system from the previous section.)

Ignoring our greedy algorithm and performing a brute force search gives the following sequence of optimal approximations:

$\displaystyle\frac{1}{4},\quad \frac{1}{4} - \frac{1}{124}, \quad \frac{1}{4}-\frac{1}{124} + \frac{1}{6572}, \quad \frac{1}{4} - \frac{1}{124} + \frac{1}{6448} - \frac{1}{225680}$,

which gives another counter-example to the greed is good’ mantra but doesn’t offer improvements at the 3-term correction scale.

— CONCLUSIONS? —

So, which of these systems would I recommend?  Ultimately, I’d have to say it doesn’t really matter. Given the erratic nature of the Earth’s orbit, no system of this form will remain accurate for a timescale long enough to let these theoretical mean discrepancies compound in an meaningful way.

Thus, in the end, simplicity is key.  The rule leap year if divisible by 4 unless divisible by 124′ gives greater accuracy (for our current tropical year) while using one less clause than the Gregorian system.

Or, if you think that the nice use of centuries in the Gregorian system puts it over the top, consider the following modified Gregorian’ rule: `leap year if divisible by 4 unless by 100 unless by 500′, which captures the simplicity of the 1582 classic while measuring our current orbit with twice the accuracy.

— EXERCISES —

Exercise 1: According to the cubic fit of Laskar’s planetary model, the Gregorian calendar gives an accurate length for the mean tropical year three times near the year 2000.  In which years did this occur?

Exercise 2: Prove that every rational number can be written as an Egyptian fraction with distinct denominators.  (This problem has been described as the first calculus.)

Exercise 3: Prove that every infinite alternating Egyptian fraction converges to a real number in $(0,1]$, and prove that every real number in $(0,1]$ may be written as a limit of alternating Egyptian fractions.

Exercise 4: Formalize the algorithm for constructing greedy AEFs and prove that the approximations constructed in this way converge quadratically.

Exercise 5: Find the best 4-term AEF approximation to the mean tropical year.  Is it the approximation you get using the greedy algorithm? Hint: Please don’t try to do this by hand.

Exercise 6: Prove that there is an open set of $\alpha \in (0,1]$ for which the greedy algorithm fails to produce the optimal k-term AEF approximation for some k.