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

Chapter 2. Six Relatives, Six Spirits and the Void Branches

The six relatives are differences in Z5

The next step in dressing a hexagram is the six relatives: taking the palace’s element as “self”, each line is read by how its branch’s element relates to self. Same as self is brothers, generated by self offspring, controlled by self wife-wealth, controlling self officer-ghost, generating self parents (Wang, n.d.). In the notation of Volume 66 this is a difference in ℤ5\mathbb{Z}_5: with wood 0, fire 1, earth 2, metal 3 and water 4, the line’s element minus the palace’s element modulo 5, 0 to 4, gives brothers, offspring, wife-wealth, officer-ghost and parents in turn.

Calculation

# Chapter 2. Six relatives: the palace element against each line.
# Palaces and najia branches as in p01 and p02 (repeated here, since the
# programs do not import one another). The relative of a line is the
# relation of its branch's element to the palace's element in Z_5
# (wood 0, fire 1, earth 2, metal 3, water 4; "generates" is +1):
#   0 brothers (XD), +1 offspring (ZS), +2 wife-wealth (QC),
#   +3 officer-ghost (GG), +4 parents (FM).
# A hexagram that lacks a relative must borrow it as a "hidden spirit"
# (fu shen) from the pure hexagram of its palace.
TRIGRAMS = {"Qian": (1, 1, 1), "Dui": (1, 1, 0), "Li": (1, 0, 1),
            "Zhen": (1, 0, 0), "Xun": (0, 1, 1), "Kan": (0, 1, 0),
            "Gen": (0, 0, 1), "Kun": (0, 0, 0)}
ELEMENT = {"Qian": 3, "Dui": 3, "Li": 1, "Zhen": 0, "Xun": 0, "Kan": 4,
           "Gen": 2, "Kun": 2}
MASKS = ((), (1,), (1, 2), (1, 2, 3), (1, 2, 3, 4), (1, 2, 3, 4, 5),
         (1, 2, 3, 5), (5,))
SHI = (6, 1, 2, 3, 4, 5, 4, 3)
START = {"Qian": 0, "Zhen": 0, "Kan": 2, "Gen": 4,
         "Kun": 7, "Xun": 1, "Li": 3, "Dui": 5}
YANG = {"Qian", "Zhen", "Kan", "Gen"}
BRANCH_ELEMENT = (4, 2, 0, 0, 2, 1, 1, 2, 3, 3, 2, 4)
CODES = ("XD", "ZS", "QC", "GG", "FM")
NAME = {v: k for k, v in TRIGRAMS.items()}

def branches(lower, upper):
    def run(t, base):
        step = 2 if t in YANG else -2
        return [(base + step * k) % 12 for k in range(3)]
    return run(lower, START[lower]) + run(upper, START[upper] + 6)

def all_hexagrams():
    for t, bits in TRIGRAMS.items():
        for g, m in enumerate(MASKS):
            h = tuple(b ^ (i + 1 in m) for i, b in enumerate(bits + bits))
            yield h, t, g

def relatives(h, palace):
    bs = branches(NAME[h[:3]], NAME[h[3:]])
    return [CODES[(BRANCH_ELEMENT[b] - ELEMENT[palace]) % 5] for b in bs]

if __name__ == "__main__":
    lines, missing, at_shi, n_kinds = {}, {}, {}, {}
    lacking = 0
    for h, palace, g in all_hexagrams():
        rel = relatives(h, palace)
        for r in rel:
            lines[r] = lines.get(r, 0) + 1
        absent = [c for c in CODES if c not in rel]
        lacking += bool(absent)
        for c in absent:
            missing[c] = missing.get(c, 0) + 1
        n_kinds[5 - len(absent)] = n_kinds.get(5 - len(absent), 0) + 1
        r = rel[SHI[g] - 1]
        at_shi[r] = at_shi.get(r, 0) + 1
    print("   {:24s}".format("relative") + "".join("{:>5s}".format(c)
                                               for c in CODES))
    for label, d in (("on all 384 lines", lines),
                     ("on the 64 world lines", at_shi),
                     ("hexagrams lacking it", missing)):
        print("   {:24s}".format(label) + "".join(
            "{:5d}".format(d.get(c, 0)) for c in CODES))
    print("   hexagrams with all five relatives: {} of 64".format(
        n_kinds.get(5, 0)))
    print("   lacking one or more: {}".format(lacking))
    print("   number of distinct relatives per hexagram: " + ", ".join(
        "{}: {}".format(k, v) for k, v in sorted(n_kinds.items())))
    print("\nReading: the 384 lines are not shared evenly among the five")
    print("relatives (offspring 58, brothers 92), and 44 of the 64")
    print("hexagrams lack at least one, so the hidden-spirit rule is not")
    print("an exception but the usual case.")
#    relative                   XD   ZS   QC   GG   FM
#    on all 384 lines           92   58   74   78   82
#    on the 64 world lines      14   12   15   13   10
#    hexagrams lacking it        6   16   16    8   10
#    hexagrams with all five relatives: 20 of 64
#    lacking one or more: 44
#    number of distinct relatives per hexagram: 3: 12, 4: 32, 5: 20
#
# Reading: the 384 lines are not shared evenly among the five
# relatives (offspring 58, brothers 92), and 44 of the 64
# hexagrams lack at least one, so the hidden-spirit rule is not
# an exception but the usual case.
Number of lines among the 384 for each of the five relatives; the dashed line is an even share among the five.

The 384 lines are not shared evenly among the five relatives: brothers 92 lines, parents 82, officer-ghost 78, wife-wealth 74, and offspring only 58. More important, only 20 of the 64 hexagrams contain all five relatives, and 44 lack at least one (12 have only three kinds, 32 have four). A missing relative must be borrowed as a “hidden spirit” from the pure hexagram of the palace. Hidden spirits are thus not an occasional repair but a routine step needed for most hexagrams.

Six spirits: by element, not modulo 6

The six spirits run from line 1 upward: on jia and yi days from Qing Long, on bing and ding days from Zhu Que, on wu days from Gou Chen, on ji days from Teng She, on geng and xin days from Bai Hu, on ren and gui days from Xuan Wu. Ten day stems map onto six starting points.

Calculation

# Chapter 2. Six spirits and the void branches as residues.
# Six spirits, from line 1 upward, start by the day stem: jia, yi with
# Qing Long; bing, ding Zhu Que; wu Gou Chen; ji Teng She; geng, xin
# Bai Hu; ren, gui Xuan Wu; then in the order QL ZQ GC TS BH XW.
# Void (kong wang): the sixty days fall into six decades (xun) of ten;
# each decade pairs its ten stems with ten of the twelve branches, and
# the two branches left over are void for that decade.
STEMS = ("jia", "yi", "bing", "ding", "wu", "ji", "geng", "xin", "ren",
         "gui")
BRANCHES = ("zi", "chou", "yin", "mao", "chen", "si", "wu", "wei", "shen",
            "you", "xu", "hai")
SPIRITS = ("QL", "ZQ", "GC", "TS", "BH", "XW")
START = (0, 0, 1, 1, 2, 3, 4, 4, 5, 5)          # by day stem

def void(k):
    """The two void branches for sexagenary day k (0 = jia-zi)."""
    first = (k % 12 - k % 10 + 10) % 12
    return first, (first + 1) % 12

if __name__ == "__main__":
    cells = ["{}:{}".format(s, SPIRITS[START[i]])
             for i, s in enumerate(STEMS)]
    print("   day stem -> spirit on line 1:")
    print("     " + " ".join(cells[:5]))
    print("     " + " ".join(cells[5:]))
    print("   the start is stem mod 6: {};  it follows the element, with"
          .format(all(START[i] == i % 6 for i in range(10))))
    print("   earth split into wu and ji: {}".format(
        all(START[i] == START[i ^ 1] for i in (0, 2, 6, 8))
        and START[4] != START[5]))
    found = {}
    for k in range(60):
        cover = {(k - k % 10 + j) % 12 for j in range(10)}
        left = tuple(b for b in range(12) if b not in cover)
        assert left == tuple(sorted(void(k)))
        found.setdefault(k // 10, set()).add(left)
    for x in range(6):
        (pair,) = found[x]
        print("   decade from {}-{:5s}: void {} {}".format(
            STEMS[0], BRANCHES[(10 * x) % 12], BRANCHES[pair[0]],
            BRANCHES[pair[1]]))
    pairs = [p for x in range(6) for p in found[x]]
    print("   the six void pairs partition the twelve branches: {}".format(
        sorted(b for p in pairs for b in p) == list(range(12))))
    print("   void pair = (branch - stem + 10, +11) mod 12, constant within")
    print("   each decade: checked for all 60 days")
    print("\nReading: the spirits follow the day stem's element, not the")
    print("stem modulo 6; the void branches are the two residues a decade")
    print("of the sixty-cycle misses, and the six decades miss disjoint")
    print("pairs, so every branch is void on exactly ten days in sixty.")
#    day stem -> spirit on line 1:
#      jia:QL yi:QL bing:ZQ ding:ZQ wu:GC
#      ji:TS geng:BH xin:BH ren:XW gui:XW
#    the start is stem mod 6: False;  it follows the element, with
#    earth split into wu and ji: True
#    decade from jia-zi   : void xu hai
#    decade from jia-xu   : void shen you
#    decade from jia-shen : void wu wei
#    decade from jia-wu   : void chen si
#    decade from jia-chen : void yin mao
#    decade from jia-yin  : void zi chou
#    the six void pairs partition the twelve branches: True
#    void pair = (branch - stem + 10, +11) mod 12, constant within
#    each decade: checked for all 60 days
#
# Reading: the spirits follow the day stem's element, not the
# stem modulo 6; the void branches are the two residues a decade
# of the sixty-cycle misses, and the six decades miss disjoint
# pairs, so every branch is void on exactly ten days in sixty.

The program first shows that this map is not “the day stem modulo 6”: by element, wood, fire, metal and water each share one starting point between two stems, and only earth’s wu and ji are split, between Gou Chen and Teng She, to make six. It is a map by element, split on earth.

The void: the complement of a coset

The sixty-day cycle falls into six decades of ten days. The ten stems of a decade take ten consecutive branches; two of the twelve are left over, and these are the decade’s void branches. The program checks that for day kk (jia-zi = 0) the first void branch is (kmod⁡12−kmod⁡10+10)mod⁡12(k \bmod 12 – k \bmod 10 + 10) \bmod 12 and the second the one after it, constant within a decade. The six decades’ void pairs are xu-hai, shen-you, wu-wei, chen-si, yin-mao and zi-chou, which share out the twelve branches without overlap. Each branch is therefore void on exactly ten days in sixty, one sixth.

Note

What this means structurally. The void is part of the structure of the sixty-day cycle, not an extra rule: a decade is ten consecutive elements of ℤ60\mathbb{Z}_{60}, its branches ten consecutive residues of ℤ12\mathbb{Z}_{12}, and the void the two residues left over.

Summary

The six relatives are the difference in ℤ5\mathbb{Z}_5 between a line’s branch element and the palace element. Offspring are rarest among the 384 lines and brothers commonest; 44 of the 64 hexagrams lack at least one relative, so hidden spirits are routine. The six spirits start by the day stem’s element, with earth split between wu and ji, and are not a residue modulo 6. The void branches are the two residues outside a decade’s ten consecutive branches, and the six decades’ void pairs share out all twelve branches.

References

Wang, Hongxu. n.d. Bushi Zhengzong [the Orthodox Lineage of Divination]. In Chinese; Qing Dynasty.

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