5D Library › Four-Pillar Calendrical Computation and Formal Rule Engines · 中文
Chapter 4. The Ten Gods Are Z5 × Z2, the Hidden Stems Weight Vectors
Two coordinates of a stem
The ten stems pair off by element and polarity: jia and yi wood, bing and ding fire, wu and ji earth, geng and xin metal, ren and gui water, the first of each pair yang and the second yin. With jia as 0, the -th stem has element and polarity . “Generates” is adding 1 in (wood generates fire, fire earth, … water wood), and “controls” is adding 2 (wood controls earth, earth water, … metal wood).
The ten gods describe every other stem from the point of view of the day stem, the “self”. The element difference gives five relations: same as self, generated by self, controlled by self, controlling self, generating self; matching or opposite polarity splits each in two. Same element with the same polarity, for example, is the companion, with opposite polarity the rob wealth; controlling self with the same polarity is the seven killings, with opposite polarity the direct officer. The ten gods are thus exactly the ten elements of .
Calculation
# Chapter 4. The ten gods as the group Z_5 x Z_2.
# Stem i (0 = jia ... 9 = gui) has element e = i // 2 (wood, fire, earth,
# metal, water) and polarity p = i % 2 (0 yang, 1 yin). In the cycle
# wood -> fire -> earth -> metal -> water -> wood, "generates" is +1 and
# "controls" is +2 (mod 5). The ten god of stem j seen from the day
# stem i depends on (e_j - e_i) mod 5 and on whether p_j = p_i:
# 0 same : BJ companion / JC rob wealth
# 1 i makes : SS eating god / SG hurting officer
# 2 i rules : PC indirect wealth / ZC direct wealth
# 3 rules i : QS seven killings / ZG direct officer
# 4 makes i : PY indirect resource/ ZY direct resource
# (first code: same polarity; second: opposite polarity).
STEMS = ("jia", "yi", "bing", "ding", "wu", "ji", "geng", "xin", "ren",
"gui")
CODES = (("BJ", "JC"), ("SS", "SG"), ("PC", "ZC"), ("QS", "ZG"),
("PY", "ZY"))
def god(i, j):
de = (j // 2 - i // 2) % 5
return CODES[de][0 if i % 2 == j % 2 else 1]
if __name__ == "__main__":
print(" day stem " + " ".join("{:>4s}".format(s) for s in STEMS))
for i in range(10):
print(" {:9s} ".format(STEMS[i]) + " ".join(
"{:>4s}".format(god(i, j)) for j in range(10)))
rows = all(len({god(i, j) for j in range(10)}) == 10 for i in range(10))
cols = all(len({god(i, j) for i in range(10)}) == 10 for j in range(10))
print(" every row and column holds all ten gods (Latin square): {}"
.format(rows and cols))
inv = all(god(i, j) == god((i + 2 * a) % 10 ^ b, (j + 2 * a) % 10 ^ b)
for i in range(10) for j in range(10) for a in range(5)
for b in (0, 1))
print(" unchanged when both stems shift element or flip polarity: {}"
.format(inv))
by_step = {}
for i in range(10):
for j in range(10):
by_step.setdefault((j - i) % 10, set()).add(god(i, j))
mixed = sum(len(v) > 1 for v in by_step.values())
print(" stem-order steps (j - i mod 10) that give more than one god:"
" {} of 10".format(mixed))
print("\nReading: the ten gods are the ten elements of Z_5 x Z_2, the")
print("element step and the polarity match. They are a function of")
print("that pair, not of the distance in the order jia ... gui: only")
print("steps of an even number of stems give a single god.")
# day stem jia yi bing ding wu ji geng xin ren gui
# jia BJ JC SS SG PC ZC QS ZG PY ZY
# yi JC BJ SG SS ZC PC ZG QS ZY PY
# bing PY ZY BJ JC SS SG PC ZC QS ZG
# ding ZY PY JC BJ SG SS ZC PC ZG QS
# wu QS ZG PY ZY BJ JC SS SG PC ZC
# ji ZG QS ZY PY JC BJ SG SS ZC PC
# geng PC ZC QS ZG PY ZY BJ JC SS SG
# xin ZC PC ZG QS ZY PY JC BJ SG SS
# ren SS SG PC ZC QS ZG PY ZY BJ JC
# gui SG SS ZC PC ZG QS ZY PY JC BJ
# every row and column holds all ten gods (Latin square): True
# unchanged when both stems shift element or flip polarity: True
# stem-order steps (j - i mod 10) that give more than one god: 5 of 10
#
# Reading: the ten gods are the ten elements of Z_5 x Z_2, the
# element step and the polarity match. They are a function of
# that pair, not of the distance in the order jia ... gui: only
# steps of an even number of stems give a single god.The program prints the whole table of ten gods (in two-letter codes: BJ companion, JC rob wealth, SS eating god, SG hurting officer, PC indirect wealth, ZC direct wealth, QS seven killings, ZG direct officer, PY indirect resource, ZY direct resource). It is a Latin square: every row and every column contains each of the ten gods exactly once. Moving both stems to another element, or flipping both polarities, leaves the god unchanged; this is the invariance of a group action.
A counterexample is worth noting: the ten gods are not a function of distance along the order of the stems. Two pairs one step apart in the order jia, yi, bing, ding … behave differently: yi seen from jia is rob wealth, but bing seen from yi is hurting officer; five of the ten “order distances” correspond to more than one god. Only an even number of steps fixes both the element difference and the polarity match, and with it the god. The ten gods are built on the product of element and polarity, not on the ten stems arranged in a circle.
Summary
The ten gods are the ten elements of , and their table is a Latin square invariant under shifts of element and flips of polarity; it is not a function of distance along the order of the stems. Hidden stems can be written as weight vectors over the elements; three common weightings agree on the main element and differ by up to 0.93 on the others, and the proportions 0.6, 0.3, 0.1 share their origin with the 18, 9 and 3 days of the days-in-command table.
Fan, Y. (2026). Four-Pillar Calendrical Computation and Formal Rule Engines: Julian-Day Sexagenary Cycles, Midnight-Boundary Disagreements, Birth-Time Sensitivity Bounds and Weighted-Graph Strength Scoring [四柱排盘的历法计算与规则引擎] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090180 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).