|
2001-09-27
Get TEXTDonald E. Knuth, The Art of Computer Programming, 1.3.2 Exercise 14-15.
[Commentary by Knuth, Forth by Wil Baden. This is not well-suited for Forth, but there's no advantage in purifying it.]
The following algorithm, due to the Neapolitan astronomer Aloysius Lilius and the German Jesuit mathematician Christopher Clavius in the late 16th century, is used by most Western churches to determine the date of Easter Sunday for any year after 1582.
Y
G
C
X
Z
D
E
N
VARIABLE Y \ Year VARIABLE G \ Golden number VARIABLE C \ Century VARIABLE X \ Century leap year adjustment VARIABLE Z \ Moon's orbit adjustment VARIABLE D \ Sunday date VARIABLE E \ Epact VARIABLE N \ Day of month
EASTER ( yyyyy -- dd mm yyyyy )
: EASTER ( yyyyy -- dd mm yyyyy )
Y ! ( )
G is the so-called "golden number" of the year in the 19-year Metonic cycle.
Y @ 19 MOD 1+ G !
When Y is not a multiple of 100, C is the century number; for example, 1984 is in the twentieth century.
Y @ 100 / 1+ C !
Here X is the number of years, such as 1900, in which leap year was dropped in order to keep in step with the sun; Z is a special correction designed to synchronize Easter with the moon's orbit.
C @ 3 4 */ 12 - X !
C @ 8 * 5 + 25 / 5 - Z !
March ((-D) mod 7) actually will be a Sunday.
Y @ 5 4 */ X @ - 10 - D !
This number E is the epact, which specifies when a full moon occurs.
G @ 11 * 20 + Z @ + X @ - 30 MOD
dup 0< IF 30 + THEN
E !
E @ 25 = ANDIF G @ 11 > THEN
ORIF E @ 24 = THEN
IF 1 E +! THEN
Easter is supposedly the first Sunday following the first full moon that occurs on or after March 21. Actually perturbations in the moon's orbit do not make this strictly true, but we are concerned here with the "calendar moon" rather than the actual moon. The N'th of March is a calendar full moon.
44 E @ - N !
N @ 21 < IF 30 N +! THEN
N @ 7 +
D @ N @ + 7 MOD -
N !
N @ 31 > IF
N @ 31 - 4 Y @
ELSE
N @ 3 Y @
THEN ;
.EASTER ( yyyyy -- )
: .EASTER ( yyyyy -- )
EASTER . 4 = IF ." April" ELSE ." March" THEN 3 .R ;
</PLAINTEXT>