5D Library › Najia Hexagram Encoding and Qimen Dunjia Combinatorial Engines · 中文

Chapter 3. The Seventy-Two Bureau Numbers and Two Calendars

The verse of bureau numbers and its closed form

Time-family Qimen uses yang dun after the Winter Solstice and yin dun after the Summer Solstice; each of the twenty-four solar terms has an upper, middle and lower yuan, each with a bureau number from one to nine (Ho 2003). The usual verse encodes these 72 numbers: “Winter Solstice and Awakening of Insects one-seven-four, Lesser Cold two-eight-five …”. Volume 62 discussed the Luoshu and the turning plates; here we look first at the 72 numbers themselves.

Calculation

# Chapter 3. The 72 bureau numbers of the solar terms, in closed form.
# Time-family Qimen uses yang dun from the Winter Solstice and yin dun
# from the Summer Solstice; each of the 24 terms has an upper, middle
# and lower "yuan" with its own bureau number 1-9. The verse table is
# copied below as usually printed. Closed form: the terms come in eight
# groups of three, one per trigram palace p of the Later Heaven square
# (yang: Kan 1, Gen 8, Zhen 3, Xun 4; yin: Li 9, Kun 2, Dui 7, Qian 6).
# The k-th term of a group (k = 0, 1, 2) has upper yuan p + k (yang) or
# p - k (yin); middle and lower add 6 and 12 (yang) or 3 and 6 (yin),
# all modulo 9 with 0 written as 9.
TERMS = ("Dong Zhi", "Xiao Han", "Da Han", "Li Chun", "Yu Shui",
         "Jing Zhe", "Chun Fen", "Qing Ming", "Gu Yu", "Li Xia",
         "Xiao Man", "Mang Zhong", "Xia Zhi", "Xiao Shu", "Da Shu",
         "Li Qiu", "Chu Shu", "Bai Lu", "Qiu Fen", "Han Lu", "Shuang Jiang",
         "Li Dong", "Xiao Xue", "Da Xue")
VERSE = ("174 285 396 852 963 174 396 417 528 417 528 639 "
         "936 825 714 258 147 936 714 693 582 693 582 471").split()
PALACES = (1, 8, 3, 4, 9, 2, 7, 6)

def nine(x):
    return (x - 1) % 9 + 1

def closed(i):
    group, k = divmod(i, 3)
    p = PALACES[group]
    if i < 12:
        up = nine(p + k)
        return up, nine(up + 6), nine(up + 12)
    up = nine(p - k)
    return up, nine(up + 3), nine(up + 6)

if __name__ == "__main__":
    ok = all("".join(map(str, closed(i))) == VERSE[i] for i in range(24))
    print("   verse table = closed form for all 24 terms x 3 yuan: {}".format(
        ok))
    for i in (0, 3, 12, 21):
        print("   {:12s} upper/middle/lower: {} {} {}".format(
            TERMS[i], *closed(i)))
    used = {}
    for i in range(24):
        for b in closed(i):
            used[(i < 12, b)] = used.get((i < 12, b), 0) + 1
    print("   each bureau number serves 4 term-yuan pairs per dun: {}".format(
        set(used.values()) == {4}))
    print("   bureaus: 9 numbers x 2 duns = {};  x 60 double-hours = {:,d}"
          .format(9 * 2, 9 * 2 * 60))
    print("   term-yuan pairs: 24 x 3 = {}".format(24 * 3))
    print("\nReading: the 72 numbers of the verse are generated by eight")
    print("starting palaces and two step rules: +1 per term and +6 per yuan")
    print("in yang dun, -1 and +3 in yin dun. Each of the 18 bureaus is used")
    print("by exactly four term-yuan pairs.")
#    verse table = closed form for all 24 terms x 3 yuan: True
#    Dong Zhi     upper/middle/lower: 1 7 4
#    Li Chun      upper/middle/lower: 8 5 2
#    Xia Zhi      upper/middle/lower: 9 3 6
#    Li Dong      upper/middle/lower: 6 9 3
#    each bureau number serves 4 term-yuan pairs per dun: True
#    bureaus: 9 numbers x 2 duns = 18;  x 60 double-hours = 1,080
#    term-yuan pairs: 24 x 3 = 72
#
# Reading: the 72 numbers of the verse are generated by eight
# starting palaces and two step rules: +1 per term and +6 per yuan
# in yang dun, -1 and +3 in yin dun. Each of the 18 bureaus is used
# by exactly four term-yuan pairs.

The program shows that a simple closed form generates all 72 numbers of the verse. The twenty-four terms fall into groups of three by the Later Heaven trigrams: in yang dun the Winter Solstice group starts at Kan 1, the Beginning of Spring group at Gen 8, the Spring Equinox group at Zhen 3, the Beginning of Summer group at Xun 4; in yin dun the Summer Solstice group starts at Li 9, the Beginning of Autumn group at Kun 2, the Autumn Equinox group at Dui 7, the Beginning of Winter group at Qian 6. The upper yuan of the kk-th term of a group is the starting palace plus kk in yang dun and minus kk in yin dun; the middle and lower yuan add 6 per yuan in yang dun and 3 in yin dun (all modulo 9, with 9 for 0). Winter Solstice, for example, is one-seven-four: 11, 1+6=71 + 6 = 7, 7+6=13→47 + 6 = 13 \to 4. The program compares all three yuan of the 24 terms and finds every one in agreement. Nine bureau numbers times two duns make 18 bureaus, each used by exactly four term-yuan pairs; 18 bureaus times the 60 double-hours of a bureau make 1,080.

Split-supplement and intercalation

The bureau is fixed by “which term, which yuan”, and those two questions have two answers.

Split-supplement (chai bu) takes the term strictly from the astronomical moment of the term, and the yuan from the “fu tou”: the latest jia or ji day, whose branch zi, wu, mao or you gives the upper yuan, yin, shen, si or hai the middle, and chen, xu, chou or wei the lower.

Intercalation (zhi run) lets each upper-yuan fu tou (jia-zi, ji-mao, jia-wu, ji-you, fifteen days apart) open the three yuan of one term, the terms following in order. Fifteen days is a little shorter than the mean length of a term, so the fu tou gradually runs ahead of the term (“chao shen”); when it runs more than nine days ahead before Mang Zhong or Da Xue, that term’s three yuan are repeated (the “intercalation”) to bring the two back together.

The two methods can give the same double-hour different bureaus. The next program computes the moments of the solar terms from 1990 to 2030 with Meeus’s low-accuracy solar theory (Meeus 1998) (about ten minutes of error; see Volume 66), finds the fu tou from the day pillars, and compares the two bureaus double-hour by double-hour from 2000 to 2029.

Calculation

# Chapter 3. Split-supplement against intercalation: how often do they
# give a different bureau?
# Terms: the Sun's apparent longitude reaches 270 + 15 i degrees (low-
# accuracy solar theory of Meeus ch. 25, Delta T 69 s, UTC+8; about ten
# minutes of error, see Volume 66). Day pillars from the Julian day.
# Split-supplement (chai bu): the term is the last term before the
# moment; the yuan is set by the "fu tou", the latest jia or ji day:
# zi/wu/mao/you -> upper, yin/shen/si/hai -> middle, others -> lower.
# Intercalation (zhi run): every upper-yuan fu tou (jia-zi, ji-mao,
# jia-wu, ji-you; 15 days apart) opens three yuan of one term, terms in
# order; when the fu tou runs nine days or more ahead of Mang Zhong or
# Da Xue, that term is repeated (the intercalary bureau).
# Each double-hour from 2000 to 2029 is compared at its midpoint.
import math

def sun_longitude(jde):
    t = (jde - 2451545.0) / 36525
    l0 = 280.46646 + 36000.76983 * t + 0.0003032 * t * t
    m = math.radians(357.52911 + 35999.05029 * t - 0.0001537 * t * t)
    c = ((1.914602 - 0.004817 * t - 0.000014 * t * t) * math.sin(m)
         + (0.019993 - 0.000101 * t) * math.sin(2 * m)
         + 0.000289 * math.sin(3 * m))
    om = math.radians(125.04 - 1934.136 * t)
    return (l0 + c - 0.00569 - 0.00478 * math.sin(om)) % 360

def crossing(target, guess):
    jd = guess
    for _ in range(50):
        diff = (target - sun_longitude(jd) + 180) % 360 - 180
        jd += diff / 0.9856
        if abs(diff) < 1e-7:
            break
    return jd - 69 / 86400 + 8 / 24             # local (UTC+8) Julian date

def nine(x):
    return (x - 1) % 9 + 1

def bureau(i, yuan):                          # p05's closed form
    group, k = divmod(i, 3)
    p = (1, 8, 3, 4, 9, 2, 7, 6)[group]
    up = nine(p + k) if i < 12 else nine(p - k)
    step = 6 if i < 12 else 3
    return (i < 12, nine(up + step * yuan))

def term_times(jd0, jd1):
    out, i, jd = [], 0, jd0 - 20
    while jd < jd1 + 20:
        jd = crossing((270 + 15 * i) % 360, jd0 - 10 + 15.22 * i)
        out.append((jd, i % 24))
        i += 1
    return out

if __name__ == "__main__":
    jd_start = 2447892.5                          # 1 January 1990
    jd_a, jd_b = 2451544.5, 2462502.5             # 2000-01-01, 2030-01-01
    terms = term_times(jd_start, jd_b)
    day0 = int(jd_start + 0.5)
    # upper-yuan fu tou days: sexagenary index in {0, 15, 30, 45}
    first = next(d for d in range(day0, day0 + 60) if (d + 49) % 60 == 0)
    uppers = list(range(first, int(jd_b) + 30, 15))
    # intercalation: start with the term nearest the first fu tou
    j0 = min(range(len(terms)), key=lambda j: abs(terms[j][0] - uppers[0]))
    assign, j, leaps = [], j0, []
    for u in uppers:
        assign.append((u, j))
        lead = terms[j][0] - u                    # days the fu tou is early
        if terms[j][1] in (11, 23) and lead >= 9 and len(assign) > 1 \
                and assign[-2][1] != j:
            leaps.append(u)
            continue                              # repeat this term
        j += 1
    zr = {}
    for u, jj in assign:
        for d in range(15):
            zr[u + d] = bureau(terms[jj][1], d // 5)
    yuan_of = {0: 0, 6: 0, 3: 0, 9: 0, 2: 1, 8: 1, 5: 1, 11: 1}
    total = differ = dun_differ = 0
    k = 0
    for slot in range(int((jd_b - jd_a) * 12)):
        t = jd_a + slot / 12                      # midpoint of the slot
        day = int(t + 0.5)
        while terms[k + 1][0] <= t:
            k += 1
        fu = day - next(s for s in range(10)
                        if (day - s + 49) % 10 in (0, 5))
        cb = bureau(terms[k][1], yuan_of.get((fu + 49) % 12, 2))
        total += 1
        differ += cb != zr[day]
        dun_differ += cb[0] != zr[day][0]
    n_leap = sum(jd_a <= u < jd_b for u in leaps)
    leads = [terms[jj][0] - u for u, jj in assign if jd_a <= u < jd_b]
    print("   double-hours compared, 2000-2029: {:,d}".format(total))
    print("   intercalary bureaus inserted in these 30 years: {}".format(
        n_leap))
    print("   fu tou ahead of (+) or behind (-) its term: {:+.1f} to {:+.1f}"
          " days".format(max(leads), min(leads)))
    print("   different bureau number or dun: {:.4f}".format(differ / total))
    print("   different dun (yin against yang): {:.4f}".format(
        dun_differ / total))
    print("\nReading: the two calendars of Qimen agree on the bureau for")
    print("about seven double-hours in ten; for the other three the chart")
    print("differs depending only on which calendar the software follows,")
    print("and for about one in fifty even the dun (yin or yang) differs.")
#    double-hours compared, 2000-2029: 131,496
#    intercalary bureaus inserted in these 30 years: 10
#    fu tou ahead of (+) or behind (-) its term: +13.1 to -7.3 days
#    different bureau number or dun: 0.3067
#    different dun (yin against yang): 0.0219
#
# Reading: the two calendars of Qimen agree on the bureau for
# about seven double-hours in ten; for the other three the chart
# differs depending only on which calendar the software follows,
# and for about one in fifty even the dun (yin or yang) differs.
The bureau each method gives at noon on each day of 2026 (yang dun positive, yin dun negative). Solid line: split-supplement; dashed: intercalation.

Over the 131,496 double-hours of these thirty years, the intercalation rule used by the program intercalates 10 times, about once in three years; the fu tou runs at most 13.1 days ahead of its term and at most 7.3 days behind. The two methods give different bureaus (or different duns) for 0.3067 of double-hours, about three in ten; even the dun differs for 0.0219, about one in fifty, clustered round the solstices.

Note

Versions of the intercalation rule. Books state the limit of “chao shen” and the timing of intercalation differently: some say the fu tou may not run more than nine days ahead, some ten; some intercalate only at Mang Zhong and Da Xue, some add rules for “jie qi” when it falls behind. The program of this chapter uses one simple statement of the rule, so the fu tou can run more than nine days ahead. Another statement would change the share of disagreement somewhat, but not the conclusion that the two calendars give different bureaus for a sizeable share of double-hours. Another statement of the rule can be used by replacing it in the program and recomputing.

Summary

The 72 bureau numbers of Qimen are generated entirely by eight starting palaces and two step rules, and 1,080 is 18 bureaus times 60 double-hours. Split-supplement and intercalation give different bureaus for 0.3067 of the double-hours from 2000 to 2029, and different duns for 0.0219. Which calendar a Qimen program follows decides the chart for about three double-hours in ten.

References

Ho, Peng Yoke. 2003. Chinese Mathematical Astrology: Reaching out to the Stars. RoutledgeCurzon.
Meeus, Jean. 1998. Astronomical Algorithms. 2nd ed. Willmann-Bell.

Fan, Y. (2026). Najia Hexagram Encoding and Qimen Dunjia Combinatorial Engines: Eight-Palace Group Actions, Sexagenary Void Cosets, Split-Supplement versus Intercalation Divergences and Nine-Palace Rotor Permutations [纳甲装卦与奇门遁甲排盘的组合计算] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090182 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).