5D Library › 纳甲装卦与奇门遁甲排盘的组合计算 · English

第三章 七十二个局数与两种定局历法

局数的歌诀与闭式

时家奇门以冬至后为阳遁、夏至后为阴遁;二十四节气各分上、中、下三元,每元配一个一到九的局数 (Ho 2003)。通行的歌诀把这 72 个数编成「冬至惊蛰一七四,小寒二八五……」。第 62 本已经讨论过洛书与转盘;这里先看这 72 个数本身。

推导

# 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.

程序证明歌诀的 72 个数由一个简单的闭式完全生成。二十四节气按后天八卦每三个一组:阳遁的冬至组起坎一、立春组起艮八、春分组起震三、立夏组起巽四;阴遁的夏至组起离九、立秋组起坤二、秋分组起兑七、立冬组起乾六。组内第 kk 个节气的上元,阳遁为起宫加 kk,阴遁为起宫减 kk;中元与下元,阳遁每元再加 6,阴遁每元加 3(都模 9,以 9 代 0)。例如冬至一七四:11,1+6=71 + 6 = 7,7+6=13→47 + 6 = 13 \to 4。程序逐条比较 24 个节气的三元,全部相符。九个局数乘以阴阳二遁共 18 局,每局恰好被四个「节气—元」用到;18 局乘以每局的 60 个时辰,就是 1,080。

拆补法与置闰法

局数由「哪个节气、哪一元」决定,但这两个问题有两种答法。

拆补法严格按天文的交节时刻定节气,元则按「符头」定:最近的甲日或己日,其地支为子午卯酉则为上元,寅申巳亥为中元,辰戌丑未为下元。

置闰法让每个上元符头(甲子、己卯、甲午、己酉,相隔十五天)开启一个节气的三元,节气按顺序排下去。由于十五天比一个节气的平均长度略短,符头会逐渐跑到节气前面(「超神」);当符头在芒种或大雪之前超过九天时,重复一次该节气的三元(「置闰」),把两者拉回来。

两种方法对同一个时辰可能给出不同的局。下面的程序用 Meeus 的低精度太阳理论算出 1990 年到 2030 年的节气时刻 (Meeus 1998)(约十分钟的误差,见第 66 本),按日柱定符头,再逐时辰比较 2000 年到 2029 年的两种局数。

推导

# 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.
2026 年每天正午两种方法给出的局数(阳遁为正,阴遁为负)。实线为拆补法,虚线为置闰法。

在这三十年的 131,496 个时辰中,按程序所用的置闰规则共置闰 10 次,约三年一次;符头领先节气最多 13.1 天,落后最多 7.3 天。两种方法给出不同局数(或不同阴阳遁)的时辰占 0.3067,约三成;连阴阳遁都不同的占 0.0219,约五十分之一,集中在冬至与夏至前后。

注

置闰规则的版本。 各书对「超神」的上限与置闰的时机说法不一:有的说超神不过九日,有的以十日为限,有的只在芒种、大雪置闰,有的另有接气的规则。本章的程序采用其中一种简单的写法,所以符头领先可以超过九天。换用其他写法,分歧比例会有所变化,但两种历法在相当比例的时辰上给出不同的局,这一结论不会变。若采用其他写法,只需替换程序中的置闰规则即可复算。

小结

奇门的 72 个局数由八个起宫与两条步长规则完全生成,1,080 是 18 局乘 60 时辰。拆补法与置闰法在 2000 年到 2029 年的时辰中有 0.3067 给出不同的局,0.0219 连阴阳遁都不同。一个奇门软件用的是哪一种历法,决定了约三成时辰的排盘。

参考文献

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).