Shàngyuán System in Ancient Chinese Astronomical Systems

First draft: July, 2019

Shàngyuán (上元) played a very important role in ancient Chinese astronomical systems. From the first century to 1280, almost all astronomical systems in China were constructed based on the Shàngyuán system. Chén Zūnguī (陳遵媯), a Chinese astronomer who studied the history of ancient Chinese astronomy, once said, "The history of the ancient Chinese astronomical systems was basically the evolution of the computation of Shàngyuán." This article briefly introduces the concept of Shàngyuán, its origin, its computation, how the Shàngyuán system was used to adjust the astronomical constants, and the abolishment of the system. The information is taken from the books Chinese Astronomical Systems and Mathematics[1] and Chinese Mathematical Astronomy[2].


  1. Introduction
    1. Ancient Chinese Astronomical Systems
    2. Superior Epoch
    3. Mystery of the Superior Epoch Computation
  2. Computation of the Superior Epoch
    1. General Description
    2. Congruence Equations
    3. Conditions for the Existence of a Solution
    4. Yǎnjì Algorithm (演 紀 術)
  3. Adjustment of Astronomical Constants
  4. Abolishment of the Superior Epoch

IntroductionAncient Chinese Astronomical Systems

The Chinese term lìfǎ (曆法) or simply (曆) is sometimes translated as calendar, but this translation is inaccurate. From the 7th century, a lìfǎ documented in an official historical record consisted of seven sections and their contents are: 1) mean motions of the Moon and Sun, 2) climate over the year and some astrological stuff, 3) non-uniform motion of the Sun and related issues, 4) lengths of the shadow cast by the Sun of an upright post at solar noons, times of sunrise and sunset, and stars crossing the meridian at dusk and at dawn over the year, 5) non-uniform motion of the Moon and related issues, 6) computation of eclipses, and 7) motions of Mercury, Venus, Mars, Jupiter and Saturn. These are very close to the contents in a modern astronomical almanac. contained a system of mathematical astronomy developed to perform these calculations. Calendar calculation was just one of the calculations in a . Thus, a better translation of is astronomical system or almanac. Hereafter I will use astronomical system and almanac interchangeably.

All Chinese astronomical systems specified a lìyuán (曆元), which was a time origin from which time was measured for almanac calculations. In the literature, lìyuán is sometimes translated as system origin. In modern astronomy, the term epoch has several meanings. One of them is a temporal point of origin from which time is measured. Therefore, 曆元 is used as the Chinese translation for the term epoch used in modern astronomy. Thus, it seems that epoch is a better translation for lìyuán used in ancient Chinese astronomical systems and it will be used here.

Superior Epoch

In modern astronomy, an epoch is just an arbitrary time origin with no astronomical significance. However, this was not the case in ancient Chinese almanacs before 1281. The assumption was that celestial motions were cyclic, and an epoch was chosen to be the beginning of a grand cycle. Epochs in early astronomical systems were chosen to be an instant at which the lunar conjunction and winter solstice were assumed to occur at midnight on a day with a sexagenary day cycle of jiǎ zǐ. The epochs were not determined by examining observation data from the past, but calculated based on the observed positions of the Sun and Moon and the cycles of their motions. Near the end of the western Han dynasty in the first century BC, Liú Xīn (劉歆) used the I Ching or Book of Changes, an ancient Chinese divination text, to explain the astronomical constants appearing in the Tàichū almanac (太初曆) used at that time. He renamed the almanac the Sāntǒng (三統曆) and introduced the concept of tàijí shàngyuán (太極上元) or simply shàngyuán. It was an epoch at midnight on a jiǎ zǐ day in a year with a sexagenary cycle of jiǎ zǐ, and with the following unusual astronomical phenomena: lunar conjunction, winter solstice, the beginning of an eclipse cycle, and five planets aligned in the same direction in the sky. He placed the tàijí shàngyuán 143,127 years before the winter solstice in 105 BCE.

It is well known that astronomy and astrology were not separated in the ancient time. What was special about the ancient Chinese astronomy was that it was also closely related to politics. The doctrine of the mandate of heaven was used to justify the legitimacy of a ruler. According to this belief, heaven, which embodies the natural order and will of the universe, bestows the mandate on a just ruler. One way to show the ruler received the mandate was the annual production and distribution of the almanacs, and that almanacs accurately predicted the astronomical phenomena. An inaccurate prediction, like the failure to predict cosmic events such as eclipses, became a sign of moral imperfection, a warning that the emperor's virtue was not adequate to keep him in touch with celestial rhythms. This was the reason why there were frequent modifications of the astronomical systems to improve almanac accuracy. One of the reasons why Liú Xīn deliberately mystified the almanac was to provide evidence that the western Han emperor was about to lose the mandate of heaven and would be replaced by Wáng Mǎng (王莽), who later became the founder of the Xin dynasty. Unfortunately, the pursue of shàngyuán was followed by subsequent almanac makers, and more conditions were added to the epoch. The term shàngyuán may be translated as superior epoch and I will use superior epoch and shàngyuán interchangeably hereafter.

Chinese astronomers discovered the non-uniform motion of the Moon in the first century. We now know that it is caused by the orbital eccentricity of the Moon. The cycle of the non-uniform motion is called the anomalistic month, which is the average time between two successive perigee passages of the Moon. It was also known that the average time between two successive passages of the Moon through the ascending node of its orbit and the ecliptic was different from the anomalistic month and synodic month. This period is now called the draconic month or nodal month. The non-uniform motion of the Moon and its passage through the nodes are important in the eclipse prediction. As a result, two additional conditions were added to the superior epoch: it had to be the instant when the Moon was at perigee (or apogee) and at the ascending (or descending) node of its orbit. The discovery of precession caused the sidereal year as another cycle relevant to the superior epoch. At the superior epoch, the winter solstice point had to be located inside the Emptiness mansion (虛宿), which is in the present-day constellation Aquarius. The non-uniform motion of the Sun was discovered in the 6th century. However, it was assumed that the motion of the Sun was the fastest at winter solstice. This was equivalent to the assumption that the Earth was at perihelion at the winter solstice and so the anomalistic year was the same as the tropical year. This assumption was incorrect, but the observations in the ancient time were not accurate enough to detect the error of the assumption. So the non-uniform motion of the Sun didn't add another condition to the superior epoch. Thus, in the ideal situation, the superior epoch was the instant at which the following astronomical phenomena occurred at midnight on a jiǎ zǐ day in a jiǎ zǐ year: lunar conjunction, winter solstice, the Moon was at perigee (or apogee) and at the ascending (or descending) node, five planets were in the same direction, winter solstice was in the Emptiness mansion.

It is almost impossible for the simultaneous occurrence of these astronomical phenomena, but it can be made possible by appropriately adjusting the observational data, as will be demonstrated in the next two sections. In the ideal situation, the cycles involved in the calculation are: sexagenary year cycle (60 years), sexagenary day cycle (60 days), synodic month, tropical year, anomalistic month, nodal month, sidereal year, and the synodic periods of the five planets. From observation, one can determine at a particular winter solstice the number of days each of the relevant quantity was from the beginning of each cycle. One can then set up a system of 11 congruence equations for N, which is the number of years between this winter solstice and the superior epoch.

Mystery of the Superior Epoch Computation

Chinese mathematicians developed a general algorithm for solving a system of congruence equations no later than the third century. The algorithm was later known as the dà yǎn zǒng shù shù (大衍總術數) in China and the direct construction proof of the Chinese remainder theorem in the West. It was generally believed that this was the algorithm used by the almanac makers to compute the superior epoch. However, there were two major problems with this algorithm. First, the amount of calculation involved is huge. Even with today's computational knowledge, it's still very difficult to carry out the calculation without the assistance of a computer. A more serious problem is that the Chinese remainder theorem requires the divisors to be pairwise coprime in order to guarantee the existence of a solution, but the divisors in the congruence equations for the superior epoch are not pairwise coprime. This means that the equations may not have a solution unless the remainders in the equations satisfy certain conditions, but the Chinese remainder theorem doesn't provide any method to check the existence of a solution. In the case of no solution, there doesn't seem to have an easy way to fix the situation. Another, unrelated, puzzle is that if the number of years from the superior epoch N was computed by solving the 11 congruence equations, it would be a very large number. Upon examining the values of N for all the almanacs that used a superior epoch, it is found that with two exceptions all of them were less than 100 million years, which were too small if they were really the solution of the 11 equations. How, then, did the almanac makers computed the superior epoch?

Unfortunately, the ancient computation method was gradually forgotten after the abolishment of the shàngyuán system in 1280. As mentioned above, issuing an accurate almanac was one way to demonstrate that the emperor received the mandate of heaven. Therefore, the production and distribution of annual almanacs were monopolized by the government in Imperial China. The technical details of the almanac construction were kept secret, and private study of astronomy was outlawed. Knowledge of almanac making was transmitted within and shared by a small number of specialists. Official historical records have sections on the astronomical systems used at the time, but they only provide formulae that performed various almanac calculations. The theory behind the formulae and how they were derived were kept secret. In the Ming dynasty (1368-1644), the officials in the Imperial Astronomical Bureau (欽天監) were hereditary. The Ming dynasty kept using the almanac developed in 1280, which abandoned the superior epoch, without trying to improve it. In the late 15th century, the almanac failed to predict a number of eclipses. The astronomers in the imperial court who inherited the position didn't study their craft well and were unable to improve the almanac. The imperial court had to ask the Jesuits for help to construct a new almanac.

There were scholars attempting to uncover the mathematical principle behind the ancient almanacs since the 17th century and made a number of discoveries, but the ancient method of computing the superior epoch remained an unsolved problem until about three decades ago when the mathematician Qū Ānjīng (曲安京) solved the mystery. According to his study, only the sexagenary year and day cycle, synodic month and tropical year were involved in the computation of the superior epoch. The observational values of the other astronomical constants such as the anomalistic month, sidereal years and so on were used as a reference and they were adjusted to match the superior epoch. The detail will be explained in the following two sections.

Computation of the Superior EpochGeneral Description

According to Qū Ānjīng, the ancient method of computing the superior epoch can be divided into a few steps. First, choose an integer A to represent the denominator of the synodic month PL. That is, write PL = U/A days, where U is another integer. The tropical year Ps (in days) is also expressed as a fraction, as will be explained below. Both the tropical year and synodic month were determined by observations, but they could be expressed as fractions in various ways that were consistent with observations within measurement errors. Use the chosen values of PL, Ps and other observation data to set up a system of three congruence equations for N, the number of years between the superior epoch and a particular winter solstice. The system of equations are examined to determine if a solution exists, if a solution doesn't exist or if N is greater than 100 million years, the equations are abandoned. Choose another set of U, A and other parameters and set up the equations for N again. The procedure is repeated until an acceptable solution for N is found.

Congruence Equations

Chinese almanacs usually took the winter solstice as the beginning of a year, even though most of the time the beginning of a calendar year was about one or two months after the winter solstice. Take a particular winter solstice as a reference time. Let N be the number of years between this winter solstice and the superior epoch, R0 be the number of years between the reference year and the previous jiǎ zǐ year, r1 be the number of days between this winter solstice and midnight on the previous jiǎ zǐ day, and r2 be the number of days between this winter solstice and the previous lunar conjunction (i.e. the age of the Moon of this winter solstice). The equations for N can be written as

N ≡ R0 (mod 60),    PsN ≡ r1 (mod 60),   Ps N≡ r2 (mod PL).   (1)

Here Ps is the tropical year in days, PL is the synodic month in days, and ≡ denotes congruence. The first equation means that N-R0 is an integer multiples of 60. The second equation means that PsN - r1 is an integer multiples of 60. The last equation means that PsN - r2 is an integer multiples of PL. Note that R0 is an integer, but r1 and r2 are not.

To convert the equations in (1) into equations involving only integers, write the synodic month PL=U/A, where both U and A are integers. The tropical year Ps also needs to be expressed in a fraction. There are two ways to do this. The first method was used before the 7th century, in which a zhāng cycle was specified. A zhāng cycle is simply the least common multiple of PL and Ps. Suppose a zhāng cycle contains p synodic months and q tropical years. Then we have Ps = pU/(qA). In the early almanacs, p=235 and q=19 were chosen, so that 235 synodic months were equal to 19 tropical years. Since 235=19×12+7, 7 leap months had to be inserted in 19 years and the pattern of leap months repeated every 19 years. This particular zhāng cycle was known as the Metonic cycle in ancient Greece. Other values of p and q were used since the 5th century. For example, p=7421 and q=600 were used in the Xuánshǐ almanac (玄始曆) (221 leap months in 600 years), p=6246 and q=505 in the Zhèngguāng almanac (正光曆) (186 leap months in 505 years), p=4836 and q=391 in the Dàmíng almanac (大明曆) created by Zǔ Chōngzhī (144 leap months in 391 years), p=5306 and q=429 in the Kāihuáng almanac (開皇曆) (158 leap months in 429 years), and so on. In this method, the congruence equations in (1) can be written as

N ≡ R0 (mod 60),    pUN ≡ R1 (mod 60qA),    pN ≡ R2 (mod q),   (2)

where R1=qAr1 and R2=qr2.

The second method was adopted since the middle of 7th century, in which the tropical year was simply written as Ps=T/A, where T was another integer. The equations in (1) can be written as

N ≡ R0 (mod 60),  TN≡R1 (mod 60A),  TN≡R2 (mod U),   (3)

where R1=Ar1 and R2=Ar2. Although the zhāng cycle is not specified, it can still be calculated by finding the least common multiple of T/A and U/A. However, the computation of lunar conjunctions used for calendars took into account the non-uniform motion of the Moon since the 7th century, whereas only the mean motion of the Moon was taken into account for calendars before. So the zhāng cycle no longer corresponded to the cycle of leap months. As will be explained below, the values of U, T and A may need to be adjusted in order for the congruence equations to have a solution. When a zhāng cycle is pre-specified, only U and A can be adjusted. Whereas in the second method U, T and A can be adjusted freely. This is the difference between the two methods in the computation of the superior epoch.

Conditions for the Existence of a Solution

As mentioned above, it is not guaranteed that the system of congruence equations will have a solution. It's not difficult to derive the necessary and sufficient conditions for the existence of a solution. I will use the equations in (3) as an example. From the first equation we can write N=R0+60m, where m is an arbitrary integer. Substituting this expression into the middle equation in (3) gives


where n is an integer. This equation can be written as

60g1(mt-na)=R1-TR0,   (4)

where g1=gcd(T,A) is the greatest common divisor of T and A, t=T/g1 and a=A/g1. It follows that t and a are relatively prime. Since mt-na is an integer, the equation has a solution iff 60g1 | (R1-TR0), i.e. 60g1 divides (R1-TR0). So far only the first two equations in (3) are examined. There are two more conditions when we add the last equation into the mix. Substituting the general solution N=R0+60m into the last equation in (3) and following the same argument, we find the second necessary and sufficient condition: g2|(R2-R0T), where g2=gcd(60T,U). The last condition can be derived by substituting the general solution of the middle equation in (3) to the last equation. The result is g3|(R1-R2), where g3=gcd(60A,U). To sum up, the system of congruence equations in (3) has a solution iff

60g1|(R1-TR0),  g2|(R2-R0T),  g3|(R1-R2),
g1=gcd(T,A),  g2=gcd(60T,U)  g3=gcd(60A,U).

If these conditions are not satisfied, the remainders R1=Ar1 and R2=Ar2 will need to be adjusted. However, values of r1 and r2 are obtained from observations and they have little rooms for adjustment. The general principle was that values of r1 and r2 cannot deviate from observations by more than 0.01 days. If it is impossible to find R1 and R2 within the acceptable range, another set of U, T and A has to be chosen so that U/A and T/A can approximate PL and Ps within measurement errors. Another set of congruence equations are set up based on these new parameters. The remainders R1 and R2 are then tuned to satisfy the conditions. If this fails again, the procedure of choosing a new set of T, U, A, R1 and R2 has to be repeated until a suitable set of parameters is found.

However, the procedure described above was probably not the method used by the ancient almanac makers to adjust the parameters. The adjustments were probably carried out while solving the equations using the yǎnjì algorithm described below.

Yǎnjì Algorithm (演 紀 術)

The ancient Chinese used the yǎnjì algorithm (演紀術) to solve the system of congruence equations. The algorithm is very simple. Here I again use the system of equations in (3) as an example. The algorithm takes one equation at a time. Let's start with the first equation in (3). We have found that the general solution is N=R0+60m. The next step is to substitute this general solution into the second equation. This has also been done above and the result is equation (4). The condition 60g1|(R1-TR0) has to be satisfied in order to have a solution. The parameter R1 is tuned to satisfy the condition. If it's impossible to find an R1 in the acceptable range. Another set of parameters A, U and T have to be chosen. Suppose an acceptable R1 is found. Equation (4) can be written as

mt - na = S1,  where S1 = (R1 - TR0)/(60g1),
⇒  mt ≡ S1 (mod a).

This equation can be solved by first considering the equation μt ≡ 1 (mod a). Here μ is known as the modular multiplicative inverse of t. The modular multiplicative inverse can be calculated using the dà yǎn qiú yī shù (大衍求一術), which is equivalent to the extended Euclidean algorithm. After μ is solved, m is obtained by multiplying μ by S1. Note that m is not unique. Adding m to any multiples of a is also a solution. Let M be the smallest positive solution. Then the general solution is m=M+ka, where k is any integer. The number N0=R0+60M is the number of years between the particular winter solstice and the previous winter solstice that occurred at midnight on a jiǎ zǐ day in a jiǎ zǐ year, but this was not a lunar conjunction. So the integer k needs to be determined in order for the epoch to coincide with the lunar conjunction. Substituting the general solution N=R0+60(M+ka) into the last equation in (3) yields

TR0 + 60T(M + ka) = R2 + Ub,  where b is an integer,
⇒  60Tak - Ub = R2 - TR0 - 60TM.

The equation has a solution iff gcd(60Ta,U)|(R2-TR0-60TM). We need to adjust the parameter R2 to satisfy the condition. If it's impossible to find R2 in the acceptable range, we will have to choose another set of parameters A, T and U and start over the calculation. Suppose an acceptable R2 is found.

Let g = gcd(60Ta,U), v = 60Ta/g, u = U/g, S3 = (R2 - TR0 - 60TM)/g,then
vk - ub = S3 ⇒ vk ≡ S3 (mod u).

To find k, we can find the modular multiplicative inverse of v using the extended Euclidean algorithm and then multiply the result by S3. We then add an appropriate multiple of u to obtain the smallest positive solution K. The final solution is N=R0+60(M+Ka). However, there is another stupulation: if N is greater than 100 million years, the solution is rejected. In that case, we need to choose another set of parameters A, U, T, R1 and R2 and start over. The procedure may need to be repeated a few times until an acceptable N is obtained.

By tackling one equation at a time, the amount of computation involved in the yǎnjì algorithm is much less than the Chinese remainder theorem, which involves the multiplication of large numbers. Since the numbers T, U, and A tend to be large, the amount of computation saved is tremendous.

When an acceptable value of N is obtained, the next step is to adjust the other astronomical constants to match the superior epoch.

Adjustment of Astronomical Constants

As seen above, the computation of superior epoch only involves the sexagenary year and day cycle, tropical year and synodic month. The superior epoch is also supposed to be the time origin of the other cycles, but those cycles are not involved in the calculation. So there are mismatches between the observation data and the computed superior epoch. To remove the discrepancies, we need to adjust the astronomical constants. Here I take the anomalistic month as an example to demonstrate how this can be done.

Let floor(x) denote the greatest integer smaller than or equal to x, and
mod(X,Y) = X - Y·floor(X/Y)
be the remainder of X divided by Y.

Suppose in a hypothetical almanac the superior epoch is calculated to be 10,000 years from a particular winter solstice and the tropical year is taken to be (365 + 97/400) days = 365.2425 days. Suppose it was determined from observations that the Moon was 12.3457 days past the perigee at that winter solstice and the anomalistic month was measured to be 27.5546 days. Are these observation data consistent with the superior epoch? The number of days between the superior epoch and the winter solstice was 3652425 days. If we assume the Moon was at perigee at the superior epoch and the anomalistic month was 27.5546 days, it would be mod(3652425, 27.5546) = 7.6608 days past the perigee at the winter solstice, which is clearly inconsistent with the observation data. To remove the discrepancy, we will need to adjust the value of the anomalistic month to Pa so that mod(3652425,Pa) = 12.3457. It follows that 3652425-12.3457 is an integer multiple of Pa, or Pa = 3652412.6543/n, where n is a positive integer. It is desirable to choose Pa to be as close to the measured value as possible. If Pa = 27.5546, n would be 3652412.6543/27.5546 = 1332551.83, which is not an integer. We can take the nearest integer and set Pa = 3652412.6543/132552 = 27.55456465613495 days, which is only 3 seconds less than the measurement value. We can safely assume that the measurement error in the ancient time was much greater, so no accuracy would be lost by adjusting the anomalistic month to this value. The problem is that this particular Pa is not a simple fraction and is inconvenient for almanac calculations. So the almanac makers would prefer to choose another value that could both be close to the observation value within measurement error and could be expressed as a simpler fraction. The larger N is, the easier it is to find a simpler fraction to approximate the measurement value and to match the superior epoch.

In our current system, astronomical constants are classified as the defining constants, primary constants and derived constants. An example of a defining constant is the speed of light, which is defined as 299792458 m/s. Primary constants are determined by observations. An example is Earth's equatorial radius. Derived constants are obtained by combining the primary constants or defining constants or both. An example is the mass ratio of the Sun and Earth. In this sense, the astronomical constants determined by matching the superior epoch, such as the anomalistic month, sidereal year and so on, were derived constants. This seems weird because one would think that these should be constants determined from observations. However, in the ancient shàngyuán system, the measurement values were taken for reference only, the actual values used in the almanacs were determined by adjusting the measurement values to match the calculated superior epoch. Of course, in order for an almanac to be accurate, the adjusted values cannot deviate too much from the measurement values.

Even in the ancient time, not everyone thought that adjusting the astronomical constants to match the superior epoch was a good idea. For example, in the 4th century, a scholar named Dù Yù (杜預) quoted the ancient texts saying that one should make predictions based on observations, instead of altering the measurement values to make predictions and hoping the results would match the observations. In 237, the Jǐngchū almanac (景初曆) was constructed, in which the anomalistic month was not tied to the superior epoch. As a result, the adopted anomalistic month was much closer to the measurement value than the previous almanac. In 443, astronomer Hé Chéngtiān (何承天) created the Yuánjiā almanac (元嘉曆), in which the synodic periods of the five planets were based on observations and had their own epochs separate from the superior epoch. The adopted synodic periods were much more accurate than the previous almanacs. Hé agreed with Dù Yù that astronomical constants should be determined by observations only. However, Hé's approach received criticisms and subsequent almanac makers didn't follow his approach.

From the example above, we see that as long as the number of years N from the superior epoch is large, it's easier to approximate the measurement values to match the superior epoch without sacrificing almanac accuracy. However, large N made almanac calculations inconvenient. So there was a tradeoff between computational convenience and accuracy. The upper bound for N was chosen to be 100 million years. As observation accuracy continued to improve, the restriction on N became the limiting factor for the almanac accuracy, eventually leading to the abolishment of the superior epoch.

Abolishment of the Superior Epoch

The major issue with the superior epoch was its tedious computation. It not only didn't help with the almanac making but also became an obstacle to the further improvement of almanacs.

As the measurement precision continued to improve, values of the tropical year and synodic month had to be approximated by more complicated fractions. That is, values of T, U and A became large, resulting in large values of N. A large value of N was inconvenient for almanac calculation, so people tried to limit N to be less than 100 million years. The restriction limited the improvement of the almanac accuracy. There were 19 almanacs used between 960 and 1279, which means that on average a new almanac was created every 17 years. This shows, on one hand, the improvement in measurement precision and that errors in almanacs were easy to detect. On the other hand, it shows that there was little improvement in the accuracy of the almanacs over these 319 years. The main reason was probably because the almanacs were restricted by the limitation imposed by the superior epoch.

In 1280, the Shòushí almanac (授時曆) was created and the superior epoch was abandoned. This almanac was used from 1281 to 1368. When the Ming dynasty was established in 1368, it was renamed as the Dàtǒng almanac (大統曆), but Dàtǒng almanac was the same as the Shòushí almanac with only a small modification. It was used until 1644. So the Shòushí almanac was used for more than 360 years. There are several reasons why the Shòushí almanac was the most accurate ancient almanacs. Apart from the abolishment of the superior epoch, the improvement in observation devices greatly reduced the measurement errors. The almanac also took advantage of the mathematical techniques developed over the past centuries.