5D Library › Six-Dimensional Hypercube Walks, Hexagram Mutation Markov Chains and Modular Star-Palace Lattices · 中文

Chapter 5. The Placement Rules of Zi Wei Dou Shu Are Maps Modulo 12

The twelve palaces and the Life palace

Zi Wei Dou Shu draws a person’s chart on twelve palaces, each belonging to an earthly branch. Numbering Zi, Chou, Yin … Hai as 0 to 11, the twelve palaces are ℤ12\mathbb{Z}_{12}. The first step of laying out a chart finds the Life palace and the Body palace from the lunar birth month mm (1 to 12) and the birth hour hh (0 for the Zi hour, 11 for Hai): starting from the Yin palace as the first month, count forward to the birth month, then backward to the birth hour for the Life palace, or forward to it for the Body palace (Anonymous 1607).

Calculation

Life palace, Body palace and the twelve palaces. L=(2+(m−1)−h)mod⁡12,B=(2+(m−1)+h)mod⁡12.L = (2 + (m-1) – h) \bmod 12, \qquad B = (2 + (m-1) + h) \bmod 12 . The twelve palaces run backward from the Life palace: Life LL, Siblings L−1L-1, Spouse L−2L-2, Children L−3L-3, Wealth L−4L-4, Health L−5L-5, Travel L−6L-6, Friends L−7L-7, Career L−8L-8, Property L−9L-9, Fortune L−10L-10, Parents L−11L-11. So Travel is the opposite palace L+6L + 6, and Wealth and Career are L+8L + 8 and L+4L + 4 — the Life, Wealth and Career palaces form exactly an inscribed equilateral triangle in ℤ12\mathbb{Z}_{12}, a translate of {0,4,8}\{0, 4, 8\}.

The palace stems come from the year stem by the “five tigers” rule, which gives the stem of the Yin palace, and then run on in order; Book 37 showed that the five-tigers rule is a two-to-one affine map. The stem and branch of the Life palace fix its na yin element, and the na yin element fixes the “element bureau”: water two, wood three, metal four, earth five, fire six. The tenth program computes these maps.

Calculation

# Chapter 5. Zi Wei Dou Shu: the Life Palace and the "element bureau".
# Branches are numbered 0..11 (Zi, Chou, Yin, ... Hai); stems 0..9 (Jia ..
# Gui). Birth month m (1..12, lunar) and birth hour h (0 = Zi .. 11 = Hai).
#   Life palace   start at Yin (2) as month 1, count forward to month m,
#                 then backward to hour h:   L = (2 + (m - 1) - h) mod 12
#   Body palace   forward instead:           (2 + (m - 1) + h) mod 12
#   12 palaces    Life, Siblings, Spouse, Children, Wealth, Health,
#                 Travel, Friends, Career, Property, Fortune, Parents at
#                 L, L - 1, ..., L - 11 (counted backward)
#   palace stems  the stem on Yin is 2 (year stem mod 5) + 2 (mod 10) - the
#                 "five tigers" rule of Book 37 - and stems run on from Yin
#   bureau        the na yin element of the Life palace's stem-branch pair
#                 gives the bureau: water 2, wood 3, metal 4, earth 5, fire 6
BRANCH = "Zi Chou Yin Mao Chen Si Wu Wei Shen You Xu Hai".split()
PALACES = ("Life Siblings Spouse Children Wealth Health Travel Friends "
           "Career Property Fortune Parents").split()
NAYIN = "metal fire wood earth metal fire water earth metal wood " \
        "water earth fire wood water".split() * 2   # 30 pairs of the 60
BUREAU = {"water": 2, "wood": 3, "metal": 4, "earth": 5, "fire": 6}

def life(m, h):
    return (2 + (m - 1) - h) % 12

def body(m, h):
    return (2 + (m - 1) + h) % 12

def stem_of(branch, year_stem):
    yin_stem = (2 * (year_stem % 5) + 2) % 10
    return (yin_stem + (branch - 2) % 12) % 10

def sexagenary(stem, branch):
    for k in range(60):
        if k % 10 == stem and k % 12 == branch:
            return k
    raise ValueError("stem and branch of different parity")

def bureau(year_stem, life_branch):
    k = sexagenary(stem_of(life_branch, year_stem), life_branch)
    return BUREAU[NAYIN[k // 2]]

if __name__ == "__main__":
    counts = [0] * 12
    for m in range(1, 13):
        for h in range(12):
            counts[life(m, h)] += 1
    print("   Life palace over 144 month-hour pairs: each branch {} times"
          .format(sorted(set(counts))))
    m, h = 3, 4
    L = life(m, h)
    print("   example month 3, hour Chen: Life in {}, Body in {}".format(
        BRANCH[L], BRANCH[body(m, h)]))
    print("   " + ", ".join("{} {}".format(PALACES[i], BRANCH[(L - i) % 12])
                          for i in range(0, 12, 2)))
    print("   opposite (Travel) = L + 6; Wealth = L - 4 = L + 8;"
          " Career = L - 8 = L + 4")
    tally = {}
    print("\n   bureau by year stem (Jia/Ji .. Wu/Gui) and Life branch:")
    for ys in range(5):
        row = [bureau(ys, b) for b in range(12)]
        for v in row:
            tally[v] = tally.get(v, 0) + 1
        print("   stem {}  ".format(ys) + " ".join(str(v) for v in row))
    print("   bureau counts over the 60 cells: " + ", ".join(
        "{}: {}".format(k, tally[k]) for k in sorted(tally)))
    print("\nReading: the Life and Body palaces are affine maps mod 12 of")
    print("month and hour, each branch equally often. The bureau is a table")
    print("look-up (the na yin cycle of the sixty stem-branch pairs); each")
    print("year stem gives its own pattern, and over the 60 cells each of")
    print("the five bureaus occurs exactly 12 times.")
#    Life palace over 144 month-hour pairs: each branch [12] times
#    example month 3, hour Chen: Life in Zi, Body in Shen
#    Life Zi, Spouse Xu, Wealth Shen, Travel Wu, Career Chen, Fortune Yin
#    opposite (Travel) = L + 6; Wealth = L - 4 = L + 8; Career = L - 8 = L + 4
#
#    bureau by year stem (Jia/Ji .. Wu/Gui) and Life branch:
#    stem 0  2 2 6 6 3 3 5 5 4 4 6 6
#    stem 1  6 6 5 5 4 4 3 3 2 2 5 5
#    stem 2  5 5 3 3 2 2 4 4 6 6 3 3
#    stem 3  3 3 4 4 6 6 2 2 5 5 4 4
#    stem 4  4 4 2 2 5 5 6 6 3 3 2 2
#    bureau counts over the 60 cells: 2: 12, 3: 12, 4: 12, 5: 12, 6: 12
#
# Reading: the Life and Body palaces are affine maps mod 12 of
# month and hour, each branch equally often. The bureau is a table
# look-up (the na yin cycle of the sixty stem-branch pairs); each
# year stem gives its own pattern, and over the 60 cells each of
# the five bureaus occurs exactly 12 times.

The Life and Body palaces are affine maps of birth month and hour, and among the 144 combinations each branch occurs exactly 12 times. The element bureau is a table look-up: each class of year stem has its own row — in a Jia or Ji year, for instance, a Life palace in Zi or Chou gives water two, in Yin or Mao fire six — and across all 60 cells each of the five bureaus occurs 12 times.

Placing the Zi Wei star: a quotient and a parity correction

The verse for placing the Zi Wei star is usually worked as follows: divide the birth day (first to thirtieth) by the bureau number; if it does not divide, “borrow” the smallest xx that makes it divide, giving the quotient qq; count qq palaces from Yin (Yin itself being the first); if the borrowed xx is odd, step back xx palaces, and if it is even (including nothing borrowed), step forward xx.

Calculation

A piecewise affine map. With x=(−d)mod⁡nx = (-d) \bmod n and q=(d+x)/nq = (d + x)/n, Z(d,n)=(2+q−1+(−1)xx)mod⁡12.Z(d, n) = \big(2 + q – 1 + (-1)^{x}\, x\big) \bmod 12 . The Tian Fu star is the reflection of Zi Wei across the Yin-Shen axis: F=(4−Z)mod⁡12F = (4 – Z) \bmod 12. In the Zi Wei group, Tian Ji, Tai Yang, Wu Qu, Tian Tong and Lian Zhen stand at Z−1,Z−3,Z−4,Z−5,Z−8Z – 1, Z – 3, Z – 4, Z – 5, Z – 8; in the Tian Fu group, Tai Yin, Tan Lang, Ju Men, Tian Xiang, Tian Liang, Qi Sha and Po Jun at F+1,F+2,F+3,F+4,F+5,F+6,F+10F + 1, F + 2, F + 3, F + 4, F + 5, F + 6, F + 10.

Calculation

# Chapter 5. Placing the Zi Wei star: a piecewise affine map mod 12.
# For lunar day d (1..30) and bureau n (2..6): find the smallest x >= 0
# with (d + x) divisible by n, and q = (d + x) / n. Count q palaces from
# Yin (Yin itself is 1): position Yin + q - 1. If the borrowed amount x is
# odd, step back x palaces; if x is even (including 0), step forward x.
# The Tian Fu star mirrors Zi Wei across the Yin-Shen axis: F = 4 - Z.
# The other twelve main stars sit at fixed offsets: Tian Ji Z-1, Tai Yang
# Z-3, Wu Qu Z-4, Tian Tong Z-5, Lian Zhen Z-8; Tai Yin F+1, Tan Lang F+2,
# Ju Men F+3, Tian Xiang F+4, Tian Liang F+5, Qi Sha F+6, Po Jun F+10.
BRANCH = "Zi Chou Yin Mao Chen Si Wu Wei Shen You Xu Hai".split()
ZI_GROUP = {"Zi Wei": 0, "Tian Ji": -1, "Tai Yang": -3, "Wu Qu": -4,
            "Tian Tong": -5, "Lian Zhen": -8}
FU_GROUP = {"Tian Fu": 0, "Tai Yin": 1, "Tan Lang": 2, "Ju Men": 3,
            "Tian Xiang": 4, "Tian Liang": 5, "Qi Sha": 6, "Po Jun": 10}

def ziwei(day, bureau):
    x = (-day) % bureau
    q = (day + x) // bureau
    pos = 2 + q - 1
    pos += -x if x % 2 else x
    return pos % 12

def tianfu(z):
    return (4 - z) % 12

def chart(z):
    f = tianfu(z)
    out = {s: (z + o) % 12 for s, o in ZI_GROUP.items()}
    out.update({s: (f + o) % 12 for s, o in FU_GROUP.items()})
    return out

if __name__ == "__main__":
    print("   day 1 in each bureau: " + ", ".join(
        "{} -> {}".format(n, BRANCH[ziwei(1, n)]) for n in range(2, 7)))
    print("   (tables: water 2 Chou, wood 3 Chen, metal 4 Hai,"
          " earth 5 Wu, fire 6 You)")
    print("\n   Zi Wei position counts over days 1-30:")
    print("   bureau  " + " ".join("{:>4}".format(b) for b in BRANCH))
    for n in range(2, 7):
        c = [0] * 12
        for d in range(1, 31):
            c[ziwei(d, n)] += 1
        print("     {}     ".format(n) + " ".join("{:4d}".format(v)
                                                 for v in c))
    mirror = all(tianfu(tianfu(z)) == z for z in range(12))
    fixed = [BRANCH[z] for z in range(12) if tianfu(z) == z]
    charts = {tuple(sorted(chart(z).items())) for z in range(12)}
    print("\n   Tian Fu map is an involution: {}; fixed on {}".format(
        mirror, " and ".join(fixed)))
    print("   distinct layouts of the 14 main stars: {}".format(len(charts)))
    print("\nReading: the rule is a piecewise affine map: a quotient by the")
    print("bureau plus a parity-dependent correction. Its positions are not")
    print("uniform within a bureau. Every main star follows from Zi Wei by")
    print("a rotation or by the reflection across Yin-Shen, so there are")
    print("only 12 possible layouts of the fourteen main stars.")
#    day 1 in each bureau: 2 -> Chou, 3 -> Chen, 4 -> Hai, 5 -> Wu, 6 -> You
#    (tables: water 2 Chou, wood 3 Chen, metal 4 Hai, earth 5 Wu, fire 6 You)
#
#    Zi Wei position counts over days 1-30:
#    bureau    Zi Chou  Yin  Mao Chen   Si   Wu  Wei Shen  You   Xu  Hai
#      2        2    3    4    4    3    2    2    2    2    2    2    2
#      3        1    2    2    2    3    3    3    3    3    3    3    2
#      4        1    2    3    3    4    4    4    3    2    1    1    2
#      5        1    2    3    3    4    3    4    3    2    2    1    2
#      6        2    3    3    3    3    3    3    2    2    2    2    2
#
#    Tian Fu map is an involution: True; fixed on Yin and Shen
#    distinct layouts of the 14 main stars: 12
#
# Reading: the rule is a piecewise affine map: a quotient by the
# bureau plus a parity-dependent correction. Its positions are not
# uniform within a bureau. Every main star follows from Zi Wei by
# a rotation or by the reflection across Yin-Shen, so there are
# only 12 possible layouts of the fourteen main stars.

The program first checks the formula against five known values from the usual placement tables: on the first day of the month Zi Wei stands in Chou, Chen, Hai, Wu and You for the five bureaus, all matching. Within one bureau, Zi Wei’s position is not uniform: in the water-two bureau, for example, Zi Wei falls in Yin or Mao on twice as many days as in Zi; in the metal-four bureau it falls in Chen, Si or Wu on four times as many days as in Zi, You or Xu.

More important are the last two lines. The Tian Fu map is an involution (applied twice it returns to the start), fixed only on Yin and Shen — a reflection across one axis of symmetry of the twelve-gon. Every other main star is a fixed translation of Zi Wei or Tian Fu, so the fourteen main stars have only 12 layouts: once Zi Wei’s palace is known, every main star’s position follows. In group terms, a main-star chart is the image of one fixed template under the dihedral group D12D_{12} (12 rotations and 12 reflections), of which only the 12 rotations and one fixed reflection axis are actually used.

The twelve palaces on \mathbb{Z}_{12} (Life palace placed at Zi). The gold triangle joins the Life, Wealth and Career palaces (a translate of \{0, 4, 8\}); the blue dashed line joins the Life palace to its opposite, Travel.

Note

What this means for “exact charts from birth data”. There are only 12 main-star charts, so with the fourteen main stars alone, all differences between charts come from which palace Zi Wei falls in and which palace is the Life palace — 12 times 12 combinations. Minor stars, the four transformations and the flowing years and months add many more combinations, but the information in the main-star structure itself is finite and can be counted exactly.

Summary

The Life and Body palaces are affine maps modulo 12 of birth month and hour; the element bureau is a table look-up of the Life palace’s na yin, each of the five bureaus taking 12 of the 60 cells. The Zi Wei placement verse is a piecewise affine map: a quotient by the bureau number, corrected forward or backward by the parity of the amount borrowed; Tian Fu is the reflection of Zi Wei across the Yin-Shen axis and every other main star a fixed translation. So the fourteen main stars have only 12 layouts, one orbit under the dihedral group.

References

Anonymous. 1607. Ziwei Doushu [Zi Wei Dou Shu], 3 Juan, in the Wanli Supplement to the Daoist Canon (Wanli Xu Daozang). In Chinese; Author Unknown, Traditionally Attributed to Chen Tuan.

Fan, Y. (2026). Six-Dimensional Hypercube Walks, Hexagram Mutation Markov Chains and Modular Star-Palace Lattices: Boolean Cube Spectral Gaps, Yarrow-versus-Coin Probability Biases and Twelve-Palace Dihedral Projections [六维超立方体游走、卦变马尔可夫链与模运算星宫晶格] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090176 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).