5D Library › 多模态历法张量融合、模九十谐波拨盘与跨系统共振诊断 · English

第三章 飞宫四化:有向图与三层叠忌

从命盘到有向图

紫微斗数把十四颗主星与若干辅星排入十二宫。本章用通行的排法构造全部命盘:命宫由农历月与时辰定;十二宫的宫干由生年天干按「五虎遁」定;五行局由命宫干支的纳音定;紫微星由农历日与局数定,其余主星按固定的间隔排列;文昌、文曲按时辰,左辅、右弼按月份 (Anonymous, n.d.)。

四化把十个天干各映射到四颗星:化禄、化权、化科、化忌。程序采用通行的四化表;各派对庚、壬等干的取法不尽相同,第 p06 段以庚干为例计算这种差别的影响。

飞宫化忌:每一宫以自己的宫干化出一颗忌星,从这一宫向那颗星所在的宫画一条有向边;边若指向自己,就是「自化忌」。十二宫、十二条边,构成一个十二个顶点的函数图。程序枚举 10 种年干、12 个月、30 天、12 个时辰的全部 43,200 种组合。

推导

# Chapter 3. [p05] Zi Wei charts and the directed graph of flying ji.
# Branches zi = 0 .. hai = 11. Ming palace: (2 + month - 1 - hour) mod 12.
# Palace stems by the "five tigers" rule from the year stem. Bureau from
# the nayin element of the ming palace (shui 2, mu 3, jin 4, tu 5,
# huo 6). Ziwei from lunar day and bureau; the other 13 main stars by
# fixed offsets; wenchang, wenqu by hour, zuofu, youbi by month. Each
# palace's stem turns one star into ji; an edge runs from the palace to
# where that star sits (a self-loop is "self ji"). All 10 x 12 x 30 x 12
# = 43,200 combinations of year stem, month, day and hour.
NAYIN = ("jin", "huo", "mu", "tu", "jin", "huo", "shui", "tu", "jin",
         "mu", "shui", "tu", "huo", "mu", "shui", "jin", "huo", "mu", "tu",
         "jin", "huo", "shui", "tu", "jin", "mu", "shui", "tu", "huo", "mu",
         "shui")
BUREAU = {"shui": 2, "mu": 3, "jin": 4, "tu": 5, "huo": 6}
# lu, quan, ke, ji for stems jia .. gui
SIHUA = (("lianzhen", "pojun", "wuqu", "taiyang"),
         ("tianji", "tianliang", "ziwei", "taiyin"),
         ("tiantong", "tianji", "wenchang", "lianzhen"),
         ("taiyin", "tiantong", "tianji", "jumen"),
         ("tanlang", "taiyin", "youbi", "tianji"),
         ("wuqu", "tanlang", "tianliang", "wenqu"),
         ("taiyang", "wuqu", "taiyin", "tiantong"),
         ("jumen", "taiyang", "wenqu", "wenchang"),
         ("tianliang", "ziwei", "zuofu", "wuqu"),
         ("pojun", "jumen", "taiyin", "tanlang"))

def palace_stem(ys, b):
    return (2 * (ys % 5) + 2 + (b - 2) % 12) % 10

def sexagenary(s, b):
    return next(i for i in range(60) if i % 10 == s and i % 12 == b)

def chart(ys, m, d, h):
    ming = (2 + m - 1 - h) % 12
    n = BUREAU[NAYIN[sexagenary(palace_stem(ys, ming), ming) // 2]]
    k = next(k for k in range(n) if (d + k) % n == 0)
    q = (d + k) // n
    z = (2 + q - 1 + (-k if k % 2 else k)) % 12
    f = (4 - z) % 12
    pos = {"ziwei": z, "tianji": z - 1, "taiyang": z - 3, "wuqu": z - 4,
           "tiantong": z - 5, "lianzhen": z - 8, "tianfu": f,
           "taiyin": f + 1, "tanlang": f + 2, "jumen": f + 3,
           "tianxiang": f + 4, "tianliang": f + 5, "qisha": f + 6,
           "pojun": f + 10, "wenchang": 10 - h, "wenqu": 4 + h,
           "zuofu": 4 + m - 1, "youbi": 10 - (m - 1)}
    return ming, {s: p % 12 for s, p in pos.items()}

def ji_edges(ys, pos, table=SIHUA):
    return [pos[table[palace_stem(ys, b)][3]] for b in range(12)]

def all_charts():
    for ys in range(10):
        for m in range(1, 13):
            for d in range(1, 31):
                for h in range(12):
                    yield ys, m, d, h

if __name__ == "__main__":
    n = selfs = any_self = birth_in_ming = distinct = 0
    role = [0] * 12
    for ys, m, d, h in all_charts():
        ming, pos = chart(ys, m, d, h)
        e = ji_edges(ys, pos)
        n += 1
        k = sum(e[b] == b for b in range(12))
        selfs += k
        any_self += k > 0
        birth_in_ming += pos[SIHUA[ys][3]] == ming
        role[(ming - e[ming]) % 12] += 1
        distinct += len(set(e))
    rand_distinct = 12 * (1 - (11 / 12) ** 12)
    print("   charts: {:,d}".format(n))
    print("   self-ji palaces per chart {:.4f}; charts with one or more"
          " {:.4f}".format(selfs / n, any_self / n))
    print("   birth-year ji in the ming palace: {:.4f} (1/12 = {:.4f})"
          .format(birth_in_ming / n, 1 / 12))
    print("   ming palace's ji by role: min {:.4f}, max {:.4f}".format(
        min(role) / n, max(role) / n))
    print("   distinct palaces hit by the 12 ji edges: {:.3f}".format(
        distinct / n))
    print("   (a random map of 12 palaces would hit {:.3f})".format(
        rand_distinct))
    print("\nReading: one by one, the edges look random: about one self-ji")
    print("per chart and every role about equally likely. Together they")
    print("are not: zi and chou repeat the stems of yin and mao, so their")
    print("ji always fly together and the twelve edges reach fewer palaces.")
#    charts: 43,200
#    self-ji palaces per chart 1.0078; charts with one or more 0.7223
#    birth-year ji in the ming palace: 0.0867 (1/12 = 0.0833)
#    ming palace's ji by role: min 0.0822, max 0.0850
#    distinct palaces hit by the 12 ji edges: 7.458
#    (a random map of 12 palaces would hit 7.776)
#
# Reading: one by one, the edges look random: about one self-ji
# per chart and every role about equally likely. Together they
# are not: zi and chou repeat the stems of yin and mao, so their
# ji always fly together and the twelve edges reach fewer palaces.

单条边看起来几乎是随机的:每盘平均有 1.0078 个自化忌宫(十二条随机边的期望恰好是 1),0.7223 的命盘至少有一个;生年忌落在命宫的比例是 0.0867,接近 1/12;命宫之忌落在十二个宫位的比例都在 0.0822 与 0.0850 之间。可是整张图并不随机:子、丑两宫的宫干重复寅、卯两宫的宫干,这两对宫位的忌永远一起飞;十二条忌边平均只到达 7.458 个不同的宫,少于随机函数图的 7.776 个。

三层叠忌

作者提纲中的「三层叠忌计分」把三种忌叠加:生年忌所在之宫、命宫飞出之忌所在之宫,以及自化忌之宫,每层一分。

推导

# Chapter 3. [p06] Three-layer stacked ji, and how fragile the score is.
# Chart model of p05. A palace scores one point for each layer that
# lands on it: (1) the birth-year ji star; (2) the ji flown from the
# ming palace; (3) a self ji (the palace's own stem turns a star in it
# into ji). Reported: share of charts in which some palace scores 2 or
# 3. Then two perturbations: (a) a convention: geng stem's ji star
# taken as taiyin instead of tiantong (one example of a school
# difference); (b) a lunar day off by one (birth near midnight or a
# calendar slip). Share of charts whose stacked palaces change.
NAYIN = ("jin", "huo", "mu", "tu", "jin", "huo", "shui", "tu", "jin",
         "mu", "shui", "tu", "huo", "mu", "shui", "jin", "huo", "mu", "tu",
         "jin", "huo", "shui", "tu", "jin", "mu", "shui", "tu", "huo", "mu",
         "shui")
BUREAU = {"shui": 2, "mu": 3, "jin": 4, "tu": 5, "huo": 6}
JI = ["taiyang", "taiyin", "lianzhen", "jumen", "tianji", "wenqu",
      "tiantong", "wenchang", "wuqu", "tanlang"]

def palace_stem(ys, b):
    return (2 * (ys % 5) + 2 + (b - 2) % 12) % 10

def chart(ys, m, d, h):
    ming = (2 + m - 1 - h) % 12
    s = palace_stem(ys, ming)
    idx = next(i for i in range(60) if i % 10 == s and i % 12 == ming)
    n = BUREAU[NAYIN[idx // 2]]
    k = next(k for k in range(n) if (d + k) % n == 0)
    z = (2 + (d + k) // n - 1 + (-k if k % 2 else k)) % 12
    f = (4 - z) % 12
    pos = {"taiyang": z - 3, "wuqu": z - 4, "tiantong": z - 5,
           "lianzhen": z - 8, "tianji": z - 1, "taiyin": f + 1,
           "tanlang": f + 2, "jumen": f + 3, "wenchang": 10 - h,
           "wenqu": 4 + h}
    return ming, {k: v % 12 for k, v in pos.items()}

def stacked(ys, m, d, h, ji):
    ming, pos = chart(ys, m, d, h)
    score = [0] * 12
    score[pos[ji[ys]]] += 1
    score[pos[ji[palace_stem(ys, ming)]]] += 1
    for b in range(12):
        if pos[ji[palace_stem(ys, b)]] == b:
            score[b] += 1
    return tuple(b for b in range(12) if score[b] >= 2), max(score)

if __name__ == "__main__":
    alt = JI[:]
    alt[6] = "taiyin"
    n = two = three = conv = dayoff = 0
    for ys in range(10):
        for m in range(1, 13):
            for d in range(1, 31):
                for h in range(12):
                    st, top = stacked(ys, m, d, h, JI)
                    n += 1
                    two += top >= 2
                    three += top >= 3
                    conv += stacked(ys, m, d, h, alt)[0] != st
                    d2 = d + 1 if d < 30 else d - 1
                    dayoff += stacked(ys, m, d2, h, JI)[0] != st
    print("   charts {:,d}".format(n))
    print("   some palace scores >= 2: {:.4f};  scores 3: {:.4f}".format(
        two / n, three / n))
    print("   stacked palaces change with the geng convention: {:.4f}"
          .format(conv / n))
    print("   stacked palaces change with the lunar day off by one: {:.4f}"
          .format(dayoff / n))
    print("\nReading: a double layer of ji is common, not rare; and which")
    print("palace carries it depends on a convention and on the day.")
#    charts 43,200
#    some palace scores >= 2: 0.4137;  scores 3: 0.0340
#    stacked palaces change with the geng convention: 0.0934
#    stacked palaces change with the lunar day off by one: 0.4735
#
# Reading: a double layer of ji is common, not rare; and which
# palace carries it depends on a convention and on the day.

至少有一个宫得到两分的命盘占 0.4137,三分的占 0.0340。「双重叠忌」因此是常态,而不是罕见的凶象。更重要的是它的脆弱:把庚干的忌星从天同改为太阴,0.0934 的命盘改变叠忌宫位;农历日差一天(例如出生在子夜前后,或历法换算出错),0.4735 的命盘改变叠忌宫位。

假说 · 尚未验证

作者的诠释(尚未验证): 飞宫四化的「因果链」在数学上是一个由少数规则生成的函数图,它的局部统计接近随机,结构来自宫干的重复与星曜的固定间隔。叠忌的位置对约定与输入都很敏感,任何依赖叠忌的结论都应当同时报告它在约定与输入变化下是否稳定。什么会证明这一判断错:若采用另一套通行的四化表与排盘规则,叠忌宫位对农历日差一天的变化比例低于一成,本章关于脆弱性的结论只适用于本书的规则。

小结

把飞宫化忌写成有向图后,单条边接近随机,整体结构来自子丑与寅卯宫干的重复。三层叠忌中出现双重叠忌的命盘占四成以上;叠忌的位置会因一项流派约定或农历日差一天而改变。

参考文献

Anonymous. n.d. Ziwei Doushu Quanshu [Complete Book of Zi Wei Dou Shu]. In Chinese; Received Text, Attributed to Chen Tuan.

Fan, Y. (2026). Multimodal Calendrical Tensor Fusion, Modulo-90 Harmonic Dials and Cross-System Resonance Diagnostics: Climate-Balance Vectors, Flying-Transformation Matrices and Solar-Arc Midpoint Trees [多模态历法张量融合、模九十谐波拨盘与跨系统共振诊断] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090189 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).