5D Library › Multimodal Calendrical Tensor Fusion, Modulo-90 Harmonic Dials and Cross-System Resonance Diagnostics · 中文

Chapter 3. Flying Four Transformations: a Directed Graph and Three-Layer Stacked Ji

From chart to directed graph

Zi Wei Dou Shu places fourteen main stars and several auxiliary stars in twelve palaces. This chapter builds every chart by the common rules: the ming palace from the lunar month and the double-hour; the stems of the twelve palaces from the year stem by the “five tigers” rule; the bureau from the nayin element of the ming palace’s stem-branch; Ziwei from the lunar day and the bureau, the other main stars at fixed intervals; Wenchang and Wenqu by hour, Zuofu and Youbi by month (Anonymous, n.d.).

The four transformations map each of the ten stems to four stars: lu, quan, ke and ji. The program uses the common table; schools differ for some stems such as geng and ren, and p06 takes the geng stem as an example to measure what such a difference does.

Flying ji: each palace’s own stem turns one star into ji, and a directed edge runs from the palace to the palace where that star sits; an edge pointing back to its own palace is a “self ji”. Twelve palaces and twelve edges make a functional graph on twelve vertices. The program enumerates all 43,200 combinations of 10 year stems, 12 months, 30 days and 12 double-hours.

Calculation

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

Single edges look almost random: a chart has on average 1.0078 self-ji palaces (twelve random edges would give exactly 1), and 0.7223 of charts have at least one; the birth-year ji falls in the ming palace in 0.0867 of charts, close to 1/12; the ming palace’s ji lands on each of the twelve roles in between 0.0822 and 0.0850 of charts. The whole graph, however, is not random: the zi and chou palaces repeat the stems of yin and mao, so the ji of these two pairs always fly together, and the twelve ji edges reach only 7.458 distinct palaces on average, fewer than the 7.776 of a random functional graph.

Three-layer stacked ji

The “three-layer stacked ji score” of the author’s outline adds up three kinds of ji: the palace of the birth-year ji, the palace where the ji flown from the ming palace lands, and the palaces of self ji, one point per layer.

Calculation

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

Charts in which some palace scores two make up 0.4137, and three, 0.0340. “Double stacked ji” is thus the normal state, not a rare ill omen. More important is how fragile it is: taking the geng stem’s ji star as Taiyin instead of Tiantong changes the stacked palaces in 0.0934 of charts; a lunar day off by one (a birth near midnight, or a calendar conversion error) changes them in 0.4735.

Hypothesis · not established

The author’s interpretation (not yet tested): the “causal chains” of flying transformations are, mathematically, a functional graph generated by a few rules; its local statistics are close to random, and its structure comes from repeated palace stems and fixed star intervals. Where stacked ji falls is very sensitive to conventions and inputs, and any conclusion resting on it should report whether it survives changes in both. What would show this wrong: if, under another common table of transformations and set of placement rules, a lunar day off by one changes the stacked palaces in less than one chart in ten, this chapter’s conclusion about fragility holds only for this book’s rules.

Summary

Written as a directed graph, flying ji has single edges that are close to random, and its overall structure comes from the zi and chou palaces repeating the stems of yin and mao. More than four charts in ten show double stacked ji, and where it falls changes with one school convention or with a lunar day off by one.

References

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