5D Library › Six-Dimensional Hypercube Walks, Hexagram Mutation Markov Chains and Modular Star-Palace Lattices · 中文
Chapter 1. The Sixty-Four Hexagrams Are a Six-Dimensional Cube
A hexagram is a binary string
A hexagram has six lines read from the bottom up, each yin or yang. Write yang as 1 and yin as 0, and a hexagram is a six-digit binary string ; the sixty-four hexagrams are exactly the elements of , the sixty-four vertices of the six-dimensional cube. The number of lines in which two hexagrams differ is the Hamming distance between two vertices; changing lines from the cast to the changed hexagram is a walk of steps on the cube. Functions on the cube can be expanded in the Walsh-Fourier basis, the basic tool of the analysis of Boolean functions (O’Donnell 2014), which Chapter 4 will use.
Calculation
Three symmetries. The complementary hexagram (cuo) exchanges yin and yang in every line, an exclusive-or with : . The reversed hexagram (zong) turns the figure upside down, reversing the order of the digits: . The two commute; with “both” (cuo-zong) and the identity they form a group of four (the Klein four-group) acting on the sixty-four hexagrams. Burnside’s lemma says the number of orbits equals the average number of hexagrams fixed by the elements of the group.
The first program computes the distribution of distances, how many hexagrams each of the four symmetries fixes, and how the received order of the hexagrams is paired.
Calculation
# Chapter 1. The sixty-four hexagrams as the six-dimensional cube Z2^6.
# A hexagram is six bits read from the bottom line up (1 = yang, 0 = yin).
# Changing k lines moves k steps on the cube: the Hamming distance.
# cuo (complement) flip every line: x XOR 111111
# zong (reversal) turn the figure over: bits in reverse order
# Together with the identity and cuo-zong they form a group of four
# (the Klein four-group). Burnside's lemma counts its orbits as the
# average number of hexagrams each element fixes. The program also checks
# the received King Wen order: hexagrams 2k-1 and 2k are reversals of each
# other, except where a hexagram equals its own reversal, in which case
# the pair are complements.
from collections import Counter
TRI = {"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)} # bottom line first
KING_WEN = [ # upper, lower for 1..64
"qian qian", "kun kun", "kan zhen", "gen kan",
"kan qian", "qian kan", "kun kan", "kan kun",
"xun qian", "qian dui", "kun qian", "qian kun",
"qian li", "li qian", "kun gen", "zhen kun",
"dui zhen", "gen xun", "kun dui", "xun kun",
"li zhen", "gen li", "gen kun", "kun zhen",
"qian zhen", "gen qian", "gen zhen", "dui xun",
"kan kan", "li li", "dui gen", "zhen xun",
"qian gen", "zhen qian", "li kun", "kun li",
"xun li", "li dui", "kan gen", "zhen kan",
"gen dui", "xun zhen", "dui qian", "qian xun",
"dui kun", "kun xun", "dui kan", "kan xun",
"dui li", "li xun", "zhen zhen", "gen gen",
"xun gen", "zhen dui", "zhen li", "li gen",
"xun xun", "dui dui", "xun kan", "kan dui",
"xun dui", "zhen gen", "kan li", "li kan",
]
def hexagram(upper, lower):
return TRI[lower] + TRI[upper]
KW = [hexagram(*pair.split()) for pair in KING_WEN]
ALL = [tuple((n >> i) & 1 for i in range(6)) for n in range(64)]
def cuo(h):
return tuple(1 - b for b in h)
def zong(h):
return tuple(reversed(h))
if __name__ == "__main__":
print(" King Wen list holds 64 distinct hexagrams: {}".format(
len(set(KW)) == 64))
dist = Counter(sum(a != b for a, b in zip(x, y))
for x in ALL for y in ALL)
print(" distance k between two hexagrams: share of pairs"
" (= C(6,k) / 64)")
print(" " + " ".join("{}:{:.4f}".format(k, dist[k] / 4096)
for k in range(7)))
group = {"identity": lambda h: h, "cuo": cuo, "zong": zong,
"cuo-zong": lambda h: cuo(zong(h))}
fixed = {name: sum(g(h) == h for h in ALL) for name, g in group.items()}
print(" hexagrams fixed:", ", ".join("{} {}".format(k, v)
for k, v in fixed.items()))
print(" orbits (Burnside): {} / 4 = {}".format(
sum(fixed.values()), sum(fixed.values()) // 4))
by_zong = by_cuo = bad = 0
for i in range(0, 64, 2):
a, b = KW[i], KW[i + 1]
if zong(a) != a and b == zong(a):
by_zong += 1
elif zong(a) == a and b == cuo(a):
by_cuo += 1
else:
bad += 1
print(" King Wen pairs: {} by reversal, {} by complement, {} other"
.format(by_zong, by_cuo, bad))
print("\nReading: two hexagrams differ in k lines with probability")
print("C(6, k)/64. Complement, reversal and both together split the 64")
print("into 20 orbits. The received order pairs every hexagram with its")
print("reversal, and the 8 that read the same upside down with their")
print("complement - 28 + 4 = 32 pairs, without exception.")
# King Wen list holds 64 distinct hexagrams: True
# distance k between two hexagrams: share of pairs (= C(6,k) / 64)
# 0:0.0156 1:0.0938 2:0.2344 3:0.3125 4:0.2344 5:0.0938 6:0.0156
# hexagrams fixed: identity 64, cuo 0, zong 8, cuo-zong 8
# orbits (Burnside): 80 / 4 = 20
# King Wen pairs: 28 by reversal, 4 by complement, 0 other
#
# Reading: two hexagrams differ in k lines with probability
# C(6, k)/64. Complement, reversal and both together split the 64
# into 20 orbits. The received order pairs every hexagram with its
# reversal, and the 8 that read the same upside down with their
# complement - 28 + 4 = 32 pairs, without exception.Two hexagrams differ in lines with probability : a difference of 3 lines is commonest (0.3125), while being identical or exactly opposite has only 0.0156. The complement fixes no hexagram — none is its own opposite in every line; reversal fixes 8, the “symmetric” hexagrams that read the same upside down; complement-and-reversal also fixes 8. By Burnside’s lemma the four symmetries divide the sixty-four hexagrams into orbits.
The received order (the King Wen order) shows exactly this structure: hexagrams and form pairs, 28 of them pairs of reversals, and the remaining 4 formed by the 8 hexagrams that read the same upside down, paired as complements — 32 pairs in all, without exception.
The nuclear hexagram shrinks to four within two steps
The nuclear hexagram takes lines two, three and four of a hexagram as its lower trigram and lines three, four and five as its upper. On the string it is a sliding window:
The result depends only on the middle four digits, so the nuclear map sends 64 hexagrams to 16, each image with exactly 4 preimages — it is not onto. Applied again it gives : only two digits remain, 4 hexagrams.
Calculation
# Chapter 1. The nuclear hexagram (hu gua) folds 64 into 16, then 4.
# The nuclear hexagram takes lines 2-3-4 as its lower trigram and lines
# 3-4-5 as its upper: from (b1 .. b6) it makes (b2, b3, b4, b3, b4, b5).
# Its result depends only on the four middle bits b2..b5, so the map is
# 64 -> 16, each image reached from exactly 4 hexagrams. Applied twice it
# gives (b3, b4, b3, b4, b3, b4): only two bits survive, 4 hexagrams. On
# those 4 the map acts as follows (names from the trigram pair):
# Qian -> Qian, Kun -> Kun (fixed points),
# Ji Ji <-> Wei Ji (a 2-cycle: each is the other's nuclear hexagram).
from collections import Counter
TRI = {(1, 1, 1): "Qian", (0, 0, 0): "Kun", (1, 0, 0): "Zhen",
(0, 1, 0): "Kan", (0, 0, 1): "Gen", (0, 1, 1): "Xun",
(1, 0, 1): "Li", (1, 1, 0): "Dui"}
NAMES = {("Qian", "Qian"): "Qian (1)", ("Kun", "Kun"): "Kun (2)",
("Kan", "Li"): "Ji Ji (63)", ("Li", "Kan"): "Wei Ji (64)"}
def hu(h):
return (h[1], h[2], h[3], h[2], h[3], h[4])
def name(h):
up, lo = TRI[h[3:]], TRI[h[:3]]
return NAMES.get((up, lo), "{} over {}".format(up, lo))
if __name__ == "__main__":
allh = [tuple((n >> i) & 1 for i in range(6)) for n in range(64)]
once = Counter(hu(h) for h in allh)
twice = Counter(hu(hu(h)) for h in allh)
thrice = {hu(hu(hu(h))) for h in allh}
print(" distinct after one step: {} (each reached by {} hexagrams)"
.format(len(once), sorted(set(once.values()))))
print(" distinct after two steps: {}".format(len(twice)))
for h, n in sorted(twice.items()):
print(" {:12s} reached by {:2d}; its nuclear hexagram is {}"
.format(name(h), n, name(hu(h))))
print(" after three steps the same 4: {}".format(
thrice == set(twice)))
print("\nReading: the nuclear map is a sliding window over the middle")
print("lines. It forgets two lines at each step until only the")
print("alternation of lines 3 and 4 remains: two fixed points (Qian,")
print("Kun) and one 2-cycle (Ji Ji and Wei Ji), not four fixed points.")
# distinct after one step: 16 (each reached by [4] hexagrams)
# distinct after two steps: 4
# Kun (2) reached by 16; its nuclear hexagram is Kun (2)
# Wei Ji (64) reached by 16; its nuclear hexagram is Ji Ji (63)
# Ji Ji (63) reached by 16; its nuclear hexagram is Wei Ji (64)
# Qian (1) reached by 16; its nuclear hexagram is Qian (1)
# after three steps the same 4: True
#
# Reading: the nuclear map is a sliding window over the middle
# lines. It forgets two lines at each step until only the
# alternation of lines 3 and 4 remains: two fixed points (Qian,
# Kun) and one 2-cycle (Ji Ji and Wei Ji), not four fixed points.After two nuclear steps the 64 hexagrams land on Qian, Kun, Ji Ji and Wei Ji, each with 16 preimages. But the four are not alike: the nuclear hexagram of Qian is Qian and that of Kun is Kun, fixed points; the nuclear hexagram of Ji Ji (Li below, Kan above) is Wei Ji, and that of Wei Ji is Ji Ji again — a 2-cycle. So “the nuclear hexagram converges to four attractors” is not accurate: it converges to two fixed points and one 2-cycle. On the string this is exactly the alternation of lines three and four: equal digits give Qian or Kun, unequal digits swing between Ji Ji and Wei Ji.
Note
What this means for claims such as “the nuclear hexagram shows the process”. Each nuclear step discards the information in two lines, so it is a lossy projection, and the cast hexagram cannot be recovered from its nuclear hexagram. After two steps only the relation of lines three and four remains; any judgement that relies on the second nuclear hexagram in fact uses only those two lines.
Summary
The sixty-four hexagrams are the six-dimensional cube , and the number of changing lines is the Hamming distance. Complement and reversal generate a group of four that divides the hexagrams into 20 orbits; the received order pairs hexagrams by reversal, and the symmetric ones by complement, 32 pairs without exception. The nuclear hexagram is a sliding window on the middle four lines: once it folds 64 hexagrams onto 16, twice onto 4, of which Qian and Kun are fixed points and Ji Ji and Wei Ji a 2-cycle.
References
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).