5D Library › 六维超立方体游走、卦变马尔可夫链与模运算星宫晶格 · English
第四章 读哪一段文字:变占规则与吉凶判别函数
朱熹的变占规则
起出一卦之后,读哪一段文字?朱熹在《易学启蒙·考变占》中按动爻的个数给出了一套规则,通常概括如下 (Zhu Xi 2002):无动爻,读本卦卦辞;一爻动,读本卦该动爻的爻辞;二爻动,读本卦两动爻之辞,以上爻为主;三爻动,读本卦与之卦的卦辞,以本卦为主;四爻动,读之卦两不动爻之辞,以下爻为主;五爻动,读之卦不动之爻;六爻全动,乾读「用九」、坤读「用六」,其余读之卦卦辞。
这套规则把每一次起卦映到一段「主读文字」上:六十四段卦辞、三百八十四段爻辞,加上「用九」「用六」,共 450 段。第八段程序枚举全部 4,096 种爻值组合,计算两种起卦法下每段文字被读到的概率。
推导
# 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.每条规则被用到的概率在两种方法下相同(第二章 p05 的二项分布:无动爻 0.1780,一爻动 0.3560,依此类推),450 段文字都可能被读到。但读到哪一段并不相同:两种方法的主读文字分布之间的总变差距离为 0.178,也就是说大约有五分之一的概率质量分配得不一样。最突出的是两段特殊文字:蓍草法下「用九」出现的概率为 4.35e-05,「用六」只有 5.96e-08,相差 729 倍;铜钱法下两者都是 3.81e-06。蓍草法下主读文字的熵为 8.481 比特,铜钱法为 8.642 比特——蓍草法的结果略为集中。
注
两种方法不是同一个占法的两种实现。 如果一个软件声称以铜钱法「代替」蓍草法,它改变的不是动爻的数目,而是读到哪段文字的概率:大约五分之一的概率质量被重新分配。软件应当说明它模拟的是哪一种方法。
吉凶判别是立方体上的函数
传统上判断一卦的吉凶常看爻位:阳爻居奇位、阴爻居偶位为「当位」;初与四、二与五、三与上阴阳相反为「相应」。把当位的个数(0 到 6)与相应的对数(0 到 3)相加,得到一个 0 到 9 的分数 。这只是一个示意的约定,但它说明了一个普遍的事实:任何这类判别都是立方体上的函数,可以用沃尔什—傅里叶基分解 (O’Donnell 2014)。
推导
分数的阶与噪声算子。 以 表示阴阳,当位计数是 的线性函数(一阶),相应计数含有 (二阶)。在铜钱法下,之卦对本卦的作用是布尔函数分析中的噪声算子: 阶的成分乘以 。于是「给定本卦时之卦分数的期望」——一个条件吉凶判别函数——保留一阶成分的一半、二阶成分的四分之一,本卦与之卦分数的相关系数可以直接由傅里叶权重算出。
推导
# 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.分数的傅里叶权重只落在一阶(1.500)与二阶(0.750)上。按噪声算子预言,铜钱法下本卦与之卦分数的相关系数为 0.4167,枚举的结果正好相同。蓍草法下相关系数相近(0.4259),但之卦的平均分数从 4.500 略降到 4.406,因为蓍草法把爻推向阴。
假说 · 尚未验证
作者的假说(尚未验证): 任何以爻位为基础、事先写定的吉凶判别分数,与问卦者事后报告的结果之间的相关,与零没有可区分的差别。什么结果会证明它错:在预先登记、盲法评分的研究中,分数与结果的相关在两个独立样本中都显著为正。
小结
朱熹的变占规则把每次起卦映到 450 段文字之一。每条规则被用到的概率在两种起卦法下相同,但读到哪段文字不同:两个分布相差 0.178,「用九」在蓍草法下是「用六」的 729 倍。以爻位为基础的吉凶分数是立方体上的低阶函数;变卦对它的作用是噪声算子,一阶成分保留一半、二阶保留四分之一,所以本卦与之卦分数的相关系数恰为 0.4167(铜钱法)。
参考文献
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).