5D Library › Six-Dimensional Hypercube Walks, Hexagram Mutation Markov Chains and Modular Star-Palace Lattices · 中文
Chapter 4. Which Text Is Read: the Rules for Moving Lines and a Good-or-Bad Function
Zhu Xi’s rules for moving lines
Once a hexagram is cast, which text is read? In the section “Examining the changes” of his Introduction to the Study of the Changes, Zhu Xi gave rules by the number of moving lines, usually summarised as follows (Zhu Xi 2002): no moving line, read the judgement of the cast hexagram; one, read the text of that moving line; two, read the texts of both moving lines, the upper as main; three, read the judgements of the cast and changed hexagrams, the cast as main; four, read the two unmoving lines of the changed hexagram, the lower as main; five, read the one unmoving line of the changed hexagram; all six, read “use nine” for Qian and “use six” for Kun, and otherwise the judgement of the changed hexagram.
These rules map every cast onto one “main text”: sixty-four judgements, three hundred and eighty-four line texts, plus “use nine” and “use six”, 450 texts in all. The eighth program enumerates all 4,096 combinations of line values and computes the chance that each text is read under the two methods.
Calculation
# Chapter 4. Which text is read: Zhu Xi's rules for moving lines.
# Zhu Xi's "Examining the changes" (as usually summarised) picks the text
# to read from the number of moving lines:
# 0 the judgement of the cast hexagram (ben gua)
# 1 that moving line of the cast hexagram
# 2 the upper of the two moving lines, cast hexagram
# 3 the judgement of the cast hexagram (with the changed one beside it)
# 4 the lower of the two unmoving lines of the changed hexagram
# 5 the one unmoving line of the changed hexagram
# 6 Qian: "use nine"; Kun: "use six"; otherwise the changed judgement
# The program enumerates all 4^6 = 4,096 casts of line values with their
# probabilities under each method and reports the chance of each rule,
# the number of different texts that can be the main text (of the 64
# judgements, 384 line texts and 2 special texts), the entropy of the
# main text in bits, and the total-variation distance between methods.
import math
from itertools import product
METHODS = {"yarrow": {6: 1 / 16, 7: 5 / 16, 8: 7 / 16, 9: 3 / 16},
"coins": {6: 1 / 8, 7: 3 / 8, 8: 3 / 8, 9: 1 / 8}}
def main_text(cast):
ben = tuple(1 if v in (7, 9) else 0 for v in cast)
moving = [i for i, v in enumerate(cast) if v in (6, 9)]
zhi = tuple(1 - b if i in moving else b for i, b in enumerate(ben))
still = [i for i in range(6) if i not in moving]
k = len(moving)
if k == 0 or k == 3:
return k, ("judgement", ben)
if k in (1, 2):
return k, ("line", ben, max(moving))
if k in (4, 5):
return k, ("line", zhi, min(still))
if ben == (1,) * 6:
return k, ("use nine",)
if ben == (0,) * 6:
return k, ("use six",)
return k, ("judgement", zhi)
if __name__ == "__main__":
dists, rules = {}, {}
for name, pv in METHODS.items():
texts, rule = {}, [0.0] * 7
for cast in product((6, 7, 8, 9), repeat=6):
p = math.prod(pv[v] for v in cast)
k, t = main_text(cast)
rule[k] += p
texts[t] = texts.get(t, 0.0) + p
dists[name], rules[name] = texts, rule
print(" moving lines: " + " ".join("{:>4}".format(k)
for k in range(7)))
for name in METHODS:
print(" rule share {:6s} ".format(name) + " ".join(
"{:.3f}".format(x)[1:] for x in rules[name]))
keys = set(dists["yarrow"]) | set(dists["coins"])
for name, d in dists.items():
h = -sum(p * math.log2(p) for p in d.values() if p > 0)
print(" {:6s}: {} possible main texts, entropy {:.3f} bits,"
" most likely {:.4f}".format(name, len(d), h,
max(d.values())))
print(" 'use nine' {:.2e}, 'use six' {:.2e}".format(
d.get(("use nine",), 0), d.get(("use six",), 0)))
tvd = sum(abs(dists["yarrow"].get(k, 0) - dists["coins"].get(k, 0))
for k in keys) / 2
print(" distance between the two methods' main-text distributions:"
" {:.3f}".format(tvd))
print("\nReading: the rule used has the same chance under both methods,")
print("and every one of the 450 texts can come up. But which text comes")
print("up differs: the methods disagree on about a fifth of the")
print("probability, and 'use nine' is 729 times as likely as 'use six'")
print("with yarrow, while coins make them equal.")
# moving lines: 0 1 2 3 4 5 6
# rule share yarrow .178 .356 .297 .132 .033 .004 .000
# rule share coins .178 .356 .297 .132 .033 .004 .000
# yarrow: 450 possible main texts, entropy 8.481 bits, most likely 0.0074
# 'use nine' 4.35e-05, 'use six' 5.96e-08
# coins : 450 possible main texts, entropy 8.642 bits, most likely 0.0048
# 'use nine' 3.81e-06, 'use six' 3.81e-06
# distance between the two methods' main-text distributions: 0.178
#
# Reading: the rule used has the same chance under both methods,
# and every one of the 450 texts can come up. But which text comes
# up differs: the methods disagree on about a fifth of the
# probability, and 'use nine' is 729 times as likely as 'use six'
# with yarrow, while coins make them equal.Each rule is used with the same probability under both methods (the binomial distribution of p05 in Chapter 2: no moving line 0.1780, one 0.3560, and so on), and all 450 texts can be read. But which text is read differs: the total-variation distance between the two methods’ main-text distributions is 0.178, so about a fifth of the probability mass is assigned differently. Most striking are the two special texts: with yarrow “use nine” comes up with probability 4.35e-05 and “use six” only 5.96e-08, a factor of 729; with coins both are 3.81e-06. The entropy of the main text is 8.481 bits with yarrow and 8.642 bits with coins — the yarrow results are slightly more concentrated.
Note
The two methods are not two implementations of one oracle. If software claims to “replace” the yarrow method with coins, what it changes is not the number of moving lines but the probability of reading each text: about a fifth of the probability mass is redistributed. Software should say which method it simulates.
A good-or-bad judgement is a function on the cube
Traditionally a hexagram’s fortune is often judged from line positions: a yang line in an odd place or a yin line in an even place is “in its correct place”; lines one and four, two and five, three and six of opposite kind “resonate”. Adding the number of lines in their correct places (0 to 6) to the number of resonating pairs (0 to 3) gives a score from 0 to 9. It is only an illustrative convention, but it shows a general fact: every such judgement is a function on the cube and can be decomposed in the Walsh-Fourier basis (O’Donnell 2014).
Calculation
The degree of a score and the noise operator. Writing yin and yang as , the count of correct places is linear in the (degree one), and the count of resonances contains (degree two). Under the coin method, the changed hexagram acts on the cast hexagram as the noise operator of Boolean function analysis: a component of degree is multiplied by . So “the expected score of the changed hexagram given the cast” — a conditional good-or-bad function — keeps half the first-degree component and a quarter of the second, and the correlation between the cast and changed scores follows directly from the Fourier weights.
Calculation
# Chapter 4. A "good or bad" score as a function on the cube.
# Two classical criteria of a hexagram's lines, counted as a score:
# correct place a yang line in an odd place (1, 3, 5) or a yin line in
# an even place (2, 4, 6) 0 .. 6
# resonance the pairs of places (1,4), (2,5), (3,6) holding lines
# of opposite kind 0 .. 3
# score f = correct places + resonances (0 .. 9). Written with s_i = +1
# for yang and -1 for yin, the first count has degree 1 and the second
# degree 2: f's Walsh-Fourier weight sits on levels 1 and 2 only.
# A changed hexagram damps a level-k component by (1 - a - b)^k = (1/2)^k
# under coins, so a "conditional score" E[f(changed) | cast] keeps level 1
# at half and level 2 at a quarter. The program computes the spectrum and,
# for both methods, the mean score of the changed hexagram and the
# correlation between the cast's score and the changed one's.
from itertools import product
STATES = [tuple((n >> i) & 1 for i in range(6)) for n in range(64)]
def score(x):
correct = sum(1 for i, b in enumerate(x) if b == (1 if i % 2 == 0 else 0))
resonance = sum(1 for i in range(3) if x[i] != x[i + 3])
return correct + resonance
def walsh(f):
weights = [0.0] * 7
for mask in range(64):
c = sum(f(x) * (-1) ** sum(x[i] for i in range(6) if mask >> i & 1)
for x in STATES) / 64
weights[bin(mask).count("1")] += c * c
return weights
def change_stats(pv):
yang, yin = pv[7] + pv[9], pv[6] + pv[8]
a, b = pv[9] / yang, pv[6] / yin
def step(u, v):
if u == 1:
return a if v == 0 else 1 - a
return b if v == 1 else 1 - b
mx = my = sxx = syy = sxy = 0.0
for x in STATES:
fx = score(x)
for y in STATES:
p = 1 / 64
for u, v in zip(x, y):
p *= step(u, v)
fy = score(y)
mx += p * fx
my += p * fy
sxx += p * fx * fx
syy += p * fy * fy
sxy += p * fx * fy
cov = sxy - mx * my
corr = cov / ((sxx - mx * mx) * (syy - my * my)) ** 0.5
return mx, my, corr
if __name__ == "__main__":
w = walsh(score)
print(" Fourier weight by level: " + " ".join(
"{}: {:.3f}".format(k, v) for k, v in enumerate(w) if v > 1e-12))
var = sum(w[1:])
rho = (w[1] * 0.5 + w[2] * 0.25) / var
print(" predicted correlation under coins: {:.4f}".format(rho))
for name, pv in (("yarrow", {6: 1 / 16, 7: 5 / 16, 8: 7 / 16,
9: 3 / 16}),
("coins", {6: 1 / 8, 7: 3 / 8, 8: 3 / 8, 9: 1 / 8})):
mx, my, corr = change_stats(pv)
print(" {:6s}: mean score cast {:.3f}, changed {:.3f};"
" correlation {:.4f}".format(name, mx, my, corr))
print("\nReading: the score is a low-degree function on the cube, so a")
print("changed hexagram keeps a predictable part of it: under coins the")
print("correlation is exactly the Fourier prediction. Yarrow keeps a")
print("similar correlation but lowers the changed hexagram's mean a")
print("little, because it pushes lines towards yin.")
# Fourier weight by level: 0: 20.250 1: 1.500 2: 0.750
# predicted correlation under coins: 0.4167
# yarrow: mean score cast 4.500, changed 4.406; correlation 0.4259
# coins : mean score cast 4.500, changed 4.500; correlation 0.4167
#
# Reading: the score is a low-degree function on the cube, so a
# changed hexagram keeps a predictable part of it: under coins the
# correlation is exactly the Fourier prediction. Yarrow keeps a
# similar correlation but lowers the changed hexagram's mean a
# little, because it pushes lines towards yin.The score’s Fourier weight falls only on degree one (1.500) and degree two (0.750). The noise operator predicts a correlation of 0.4167 between the cast and changed scores under coins, and the enumeration gives exactly that. With yarrow the correlation is similar (0.4259), but the changed hexagram’s mean score falls slightly, from 4.500 to 4.406, because yarrow pushes lines towards yin.
Hypothesis · not established
The author’s hypothesis (not established): the correlation between any good-or-bad score based on line positions, fixed in advance, and outcomes reported afterwards by the person who asked is indistinguishable from zero. What would show it to be wrong: in a pre-registered study with blind scoring, a correlation between score and outcome significantly above zero in two independent samples.
Summary
Zhu Xi’s rules map every cast onto one of 450 texts. Each rule is used equally often under the two casting methods, but which text is read differs: the two distributions are 0.178 apart, and with yarrow “use nine” is 729 times as likely as “use six”. A good-or-bad score built on line positions is a low-degree function on the cube; changing lines acts on it as the noise operator, keeping half of the first-degree component and a quarter of the second, so the correlation between cast and changed scores is exactly 0.4167 (coins).
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).