No Integer Satisfies Both
Every leap rule is a congruence system. So is every settlement calendar. Whether two of them can be jointly satisfied depends on a number nobody computes.
- You are seeing
-
- A scheduling constraint is described as tight or awkward rather than as unsatisfiable
- Two cycles are assumed to align eventually because both are regular
- A date calculation is correct in testing and wrong at a boundary
- Code ported between languages changes behaviour only for negative inputs
- The mechanism
- Two periodic schedules are jointly satisfiable only under a coprimality condition on their periods; where it fails, the system has no solution rather than a hard one, and implementations that do not check return an answer anyway.
- The older apparatus
- Number theory, which states the exact condition and requires it be checked before the construction is applied. Calendar reform argued the same questions in prose for fifteen centuries.
- The false friend
- A schedule that is merely rare rather than impossible. Coprime periods always eventually align; the alignment may just be centuries away, which is a different problem with a different fix.
- The discriminating test
- Compute the gcd of the two periods. If it exceeds one, check whether the two required residues agree modulo that gcd. If they do not, no date satisfies both and no amount of search will find one.
- On your own data
- Model an institution's coupon, settlement, reset and reporting calendars as congruence systems and enumerate which pairs are jointly unsatisfiable versus merely infrequent.
A year is a leap year if it is divisible by four, except if divisible by a hundred, unless it is also divisible by four hundred.
That is not a rule of thumb with exceptions bolted on. It is three congruence conditions, and stating it that way makes the design visible: 97 leap years in every 400, a mean year of 365.2425 days, and a residual drift of about three ten-thousandths of a day a year.
The Revised Julian rule, proposed in 1923, is the same object built more carefully. A century year is a leap year only when its remainder on division by 900 is 200 or 600. That gives 218 leap days per 900 years and a mean year closer to the true one than the Gregorian figure. The two calendars will not visibly disagree until after February 2800.
Choosing a leap rule is choosing a modulus. Everything else — the drift, the exceptions, the centuries until divergence — falls out of that one decision.
The condition nobody states #
Once schedules are congruences, the interesting question stops being how accurate one is and becomes whether two of them can be satisfied at once.
There is an exact answer. The Chinese Remainder Theorem says that a system of congruences with pairwise coprime moduli has a unique solution, and tells you how to construct it. That is the well-known half.
The other half is what happens when the moduli share a factor, and it is not a weaker guarantee. It is the absence of one.
Take x ≡ 1 (mod 4) and x ≡ 0 (mod 6). The greatest common divisor of 4 and 6 is 2. Consistency would require 1 ≡ 0 (mod 2), which is false. No integer satisfies both. Not a large integer, not an inconvenient one — none.
Where a solution does exist under shared factors, it is unique only modulo the least common multiple rather than the product, which is a smaller and less useful guarantee than the one people think they have.
And the construction does not fail gracefully. It does not return a nearest fit or a warning. It simply does not apply, which means any general implementation has to test coprimality before applying the formula, not after, because after is too late to notice.
Where this stops being about calendars #
Everything with a repeating date is a congruence.
Coupon payment dates. Settlement cycles. Rate reset schedules. Margin calls. Reporting periods. Exchange holiday calendars. Fiscal quarters that do not align with calendar quarters. Weekly cycles interacting with monthly ones interacting with a 360-day year that no calendar has ever had.
An institution runs dozens of these simultaneously, each defined by a different desk in a different decade against a different convention. Whether any given pair can be jointly satisfied is a computation on their periods, and it is a computation nobody performs, because the periods are described in prose — “the second business day”, “the fifteenth of each month”, “every third Wednesday” — rather than as moduli.
So a genuinely unsatisfiable pair does not present as unsatisfiable. It presents as an edge case that keeps needing manual intervention, or a reconciliation break that recurs at intervals, or a rule with an exceptions list that grows by one line every few years.
The distinction that matters is between impossible and rare. Coprime periods always align eventually; the alignment may be a century out, which is a scheduling inconvenience with an ordinary fix. Periods sharing a factor with inconsistent residues never align, and no amount of waiting, searching or manual patching will produce the date. Those two failure modes look identical from inside an operations queue and have nothing in common.
The smaller version of the same problem #
There is a version of this that has already cost real money, and it is about a sign.
Mathematical congruence does not distinguish which representative is “the” residue — the relation is symmetric and does not care. The mod operator in code has to pick, and languages picked differently. Python, Ruby, Lua and Haskell use floored division, where the result takes the sign of the divisor. C, Java, JavaScript, Go, Rust, PHP and Swift truncate, where the remainder takes the sign of the dividend.
So −13 mod 3 is 2 in the first group and −1 in the second. Both are correct by their own language’s definition.
They differ only when the operands have opposite signs, which is exactly the case a quick test with two positive numbers cannot reach. The bug class surfaces in date arithmetic and array indexing that goes negative at a boundary the original author never crossed, and it travels with code ported between languages, silently, changing behaviour only in the region nobody tested.
An unchecked gcd and an unchecked sign convention are the same mistake at different scales: a condition that number theory states precisely, that a schedule expressed in prose conceals, and that the system will not raise because from inside it there is nothing wrong.
Gregory’s commission spent years choosing a modulus. The choice held for four centuries.
Most settlement calendars were not chosen at all. They accumulated, in prose, one clause at a time, and nobody has computed a gcd across them.
Questions
Is a leap rule really modular arithmetic?
Exactly that. The Gregorian rule is a year divisible by 4, except one divisible by 100, unless it is also divisible by 400 — three congruence conditions. The Revised Julian rule is sharper: a century year is a leap year only when its remainder on division by 900 is 200 or 600. Choosing a leap rule is choosing a modulus, and the residual drift is a property of that choice.
When do two repeating schedules fail to align at all?
When their periods share a factor and their required positions disagree with respect to it. The Chinese Remainder Theorem guarantees a unique combined solution only for pairwise coprime moduli. Drop that and you may get no solution: x ≡ 1 (mod 4) together with x ≡ 0 (mod 6) is satisfied by no integer, because consistency would require 1 ≡ 0 (mod 2).
What happens if you apply the standard construction anyway?
It does not degrade gracefully. The construction simply does not apply, and gives no fallback answer. Any general-purpose implementation has to test pairwise coprimality, or the weaker consistency condition, before applying the formula rather than after.
Why does the same modulo operation give different answers in different languages?
Because mathematical congruence does not pick a sign convention and code has to. Python, Ruby, Lua and Haskell use floored division, where the result takes the divisor's sign; C, Java, JavaScript, Go, Rust and Swift truncate, so the remainder takes the dividend's sign. −13 mod 3 is 2 in the first group and −1 in the second. They differ only when the operands have opposite signs, which a test with two positive numbers will never reach.