5D Library › 六维超立方体游走、卦变马尔可夫链与模运算星宫晶格 · English
第二章 蓍草与铜钱:两种起卦法的精确概率
两种方法
六爻的每一爻取 6、7、8、9 四个值之一:6 为老阴、9 为老阳(动爻),7 为少阳、8 为少阴(静爻)。传统上有两种主要的起卦法 (Wilhelm 1967; Smith 2008)。
大衍筮法(蓍草法)。 依《系辞》与朱熹《筮仪》:取五十根蓍草,去一不用,以四十九根分为两堆,从右堆取一根挂于指间,两堆各以四根一数(揲之以四),余数(1 至 4,整除时为 4)置于一旁。第一变去掉的根数(挂一加两个余数)为 5 或 9,第二、三变为 4 或 8。三变之后剩下 36、32、28 或 24 根,除以 4 得 9、8、7、6。
三钱法(文王课)。 掷三枚铜钱,字为 3、背为 2(或相反),三者之和即为 6、7、8 或 9。
推导
蓍草法的通常分析。 假设每堆的根数除以 4 的余数等可能。第一变两堆共 48 根,两个余数之和为 4 或 8;和为 8 要求两堆都被 4 整除,概率 1/4,所以去 9 根的概率为 1/4、去 5 根为 3/4。第二、三变的根数都是 4 的倍数加 3,余数之和为 3 或 7,各占 1/2。把三变的组合加起来即得各爻值的概率。
推导
# Chapter 2. Yarrow stalks against three coins: the line probabilities.
# Yarrow (Zhu Xi's procedure): of 50 stalks one is set aside; the 49 are
# split in two, one stalk is hung between the fingers, each heap is
# counted off by fours and the remainder (1-4, a remainder of 0 counting
# as 4) is set aside. First change: 1 + remainders = 5 or 9; second and
# third changes: 4 or 8. What is left after three changes is 36, 32, 28
# or 24 stalks = 4 x (9, 8, 7, 6).
# The usual analysis assumes each heap's count mod 4 is equally likely.
# In the first change the two remainders must add to 4 or 8 (48 stalks);
# 8 needs both heaps divisible by 4: probability 1/4. In the later
# changes (39 or 43 stalks, = 3 mod 4) the sum is 3 or 7: 1/2 each.
# Three coins: heads = 3, tails = 2; the sum of three is 6, 7, 8 or 9.
from fractions import Fraction as F
from itertools import product
def yarrow():
first = {5: F(3, 4), 9: F(1, 4)}
later = {4: F(1, 2), 8: F(1, 2)}
out = {}
for a, b, c in product(first, later, later):
v = (49 - a - b - c) // 4
out[v] = out.get(v, 0) + first[a] * later[b] * later[c]
return out
def coins():
out = {}
for faces in product((2, 3), repeat=3):
out[sum(faces)] = out.get(sum(faces), 0) + F(1, 8)
return out
if __name__ == "__main__":
y, c = yarrow(), coins()
names = {6: "old yin (6, moving)", 7: "young yang (7)",
8: "young yin (8)", 9: "old yang (9, moving)"}
print(" line yarrow coins")
for v in (6, 7, 8, 9):
print(" {:22s} {:>5} = {:.4f} {:>5} = {:.4f}".format(
names[v], str(y[v]), float(y[v]), str(c[v]), float(c[v])))
for label, d in (("yarrow", y), ("coins", c)):
yang = d[7] + d[9]
moving = d[6] + d[9]
after = d[7] + d[6] # yang once moving lines flip
print(" {:6s}: P(yang) = {}, P(moving) = {}, P(yang after change)"
" = {}".format(label, yang, moving, after))
print(" yarrow: old yang / old yin = {}".format(y[9] / y[6]))
print("\nReading: both methods give yang and yin equally often and the")
print("same chance (1/4) that a line moves. They differ in which lines")
print("move: with coins old yang and old yin are equally likely; with")
print("yarrow old yang is three times as likely, so a yang line moves")
print("more often than a yin line and the changed hexagram leans yin.")
# line yarrow coins
# old yin (6, moving) 1/16 = 0.0625 1/8 = 0.1250
# young yang (7) 5/16 = 0.3125 3/8 = 0.3750
# young yin (8) 7/16 = 0.4375 3/8 = 0.3750
# old yang (9, moving) 3/16 = 0.1875 1/8 = 0.1250
# yarrow: P(yang) = 1/2, P(moving) = 1/4, P(yang after change) = 3/8
# coins : P(yang) = 1/2, P(moving) = 1/4, P(yang after change) = 1/2
# yarrow: old yang / old yin = 3
#
# Reading: both methods give yang and yin equally often and the
# same chance (1/4) that a line moves. They differ in which lines
# move: with coins old yang and old yin are equally likely; with
# yarrow old yang is three times as likely, so a yang line moves
# more often than a yin line and the changed hexagram leans yin.两种方法在三件事上完全一样:一爻为阳的概率都是 1/2,一爻为动爻的概率都是 1/4。不同之处在于哪一种爻在动。铜钱法下老阴与老阳各占 1/8,完全对称;蓍草法下老阳 3/16 = 0.1875,老阴 1/16 = 0.0625,恰为三倍。由此推出一个不常被提到的后果:蓍草法下阳爻比阴爻更容易变,所以之卦偏阴——之卦的一爻为阳的概率只有 3/8,而铜钱法下仍是 1/2。
「三倍」依赖于怎样分蓍
「余数等可能」是一个假设。分蓍是人手做的,第四段程序用三种分法精确地重算三变:分蓍位置在所有可能处均匀分布;每根蓍草独立地以 1/2 落在左边(二项分布);分得接近对半(以对半为中心、标准差 3 根的正态权重)。
推导
# Chapter 2. The yarrow odds without the "equally likely remainder" step.
# p03 assumed that a heap's count is equally likely to be 1, 2, 3 or 0
# mod 4. Real hands split the stalks in a particular way. Here the split
# of n stalks into a left heap L and a right heap n - L (L >= 1, right
# heap >= 2 so that one stalk can be hung from it) follows one of three
# models, and the four line values are computed exactly by running all
# three changes:
# uniform every L from 1 to n - 2 equally likely
# binomial each stalk falls left or right with probability 1/2
# near-even L close to n / 2: weights exp(-(L - n/2)^2 / (2 x 3^2))
import math
def rem(x):
return x % 4 or 4
def weights(n, model):
out = {}
for left in range(1, n - 1):
if model == "uniform":
w = 1.0
elif model == "binomial":
w = math.comb(n, left)
else:
w = math.exp(-(left - n / 2) ** 2 / 18)
out[left] = w
z = sum(out.values())
return {k: v / z for k, v in out.items()}
def change(n, model):
dist = {}
for left, w in weights(n, model).items():
removed = 1 + rem(left) + rem(n - left - 1)
dist[n - removed] = dist.get(n - removed, 0.0) + w
return dist
def line_values(model):
states = {49: 1.0}
for _ in range(3):
nxt = {}
for n, p in states.items():
for m, q in change(n, model).items():
nxt[m] = nxt.get(m, 0.0) + p * q
states = nxt
return {n // 4: p for n, p in states.items()}
if __name__ == "__main__":
print(" split old yin 6 young yang 7 young yin 8"
" old yang 9 9 / 6")
print(" ideal (p03) 0.0625 0.3125 0.4375"
" 0.1875 3.000")
for model in ("uniform", "binomial", "near-even"):
v = line_values(model)
print(" {:10s} {:6.4f} {:6.4f} {:6.4f}"
" {:6.4f} {:5.3f}".format(
model, v[6], v[7], v[8], v[9], v[9] / v[6]))
print("\nReading: when the hand splits the stalks roughly evenly")
print("(binomial or near-even) the ideal fractions hold to four decimal")
print("places and old yang is three times as likely as old yin. A split")
print("spread evenly over every possible position - not how hands")
print("divide a bundle - shifts the odds and raises the ratio to about")
print("4. The 3:1 bias comes from the counting rule, given a natural")
print("split.")
# split old yin 6 young yang 7 young yin 8 old yang 9 9 / 6
# ideal (p03) 0.0625 0.3125 0.4375 0.1875 3.000
# uniform 0.0517 0.2887 0.4484 0.2112 4.082
# binomial 0.0625 0.3125 0.4375 0.1875 3.000
# near-even 0.0625 0.3125 0.4375 0.1875 3.000
#
# Reading: when the hand splits the stalks roughly evenly
# (binomial or near-even) the ideal fractions hold to four decimal
# places and old yang is three times as likely as old yin. A split
# spread evenly over every possible position - not how hands
# divide a bundle - shifts the odds and raises the ratio to about
# 4. The 3:1 bias comes from the counting rule, given a natural
# split.按二项分布或接近对半的方式分蓍时,四个概率在四位小数内与理想值相同,老阳与老阴之比为 3.000。若分蓍位置在所有可能处均匀分布,老阴降为 0.0517、老阳升为 0.2112,比例变为 4.082。均匀分布不像人手分一把蓍草的方式,所以「三倍」在自然的分法下成立;但它来自计数规则与分法的结合,不是一个与分法无关的常数。
两种方法相同之处与距离
推导
# Chapter 2. What the two methods share and how far apart they are.
# Number of moving lines in a six-line cast: each line moves with
# probability 1/4 under both methods (p03), independently, so the count
# is Binomial(6, 1/4) for both. The methods differ only in WHICH lines
# move. Their distance is measured by the Kullback-Leibler divergence of
# the line values (6, 7, 8, 9), and by how many casts, on average, a
# likelihood-ratio comparison needs before the evidence reaches 100 : 1
# for the method actually used.
import math
from fractions import Fraction as F
Y = {6: F(1, 16), 7: F(5, 16), 8: F(7, 16), 9: F(3, 16)}
C = {6: F(1, 8), 7: F(3, 8), 8: F(3, 8), 9: F(1, 8)}
def kl(p, q):
return sum(float(p[v]) * math.log(float(p[v]) / float(q[v]))
for v in p)
if __name__ == "__main__":
print(" moving lines probability (both methods)")
for k in range(7):
pk = math.comb(6, k) * F(1, 4) ** k * F(3, 4) ** (6 - k)
print(" {} {:>9} = {:.4f}".format(k, str(pk),
float(pk)))
print(" at least one moving line: {:.4f}".format(
1 - float(F(3, 4) ** 6)))
for a, b, p, q in (("yarrow", "coins", Y, C), ("coins", "yarrow", C, Y)):
d = kl(p, q)
casts = math.log(100) / (6 * d)
print(" KL({} || {}) = {:.4f} nats per line; about {:.1f}"
" casts".format(a, b, d, casts))
print("\nReading: the number of moving lines - and with it the reading")
print("rule of Chapter 4 - has the same distribution under both")
print("methods. The line values differ by about 0.04 nats per line, so")
print("telling from the casts alone which method produced them takes")
print("some 17 six-line casts on average.")
# moving lines probability (both methods)
# 0 729/4096 = 0.1780
# 1 729/2048 = 0.3560
# 2 1215/4096 = 0.2966
# 3 135/1024 = 0.1318
# 4 135/4096 = 0.0330
# 5 9/2048 = 0.0044
# 6 1/4096 = 0.0002
# at least one moving line: 0.8220
# KL(yarrow || coins) = 0.0432 nats per line; about 17.8 casts
# KL(coins || yarrow) = 0.0465 nats per line; about 16.5 casts
#
# Reading: the number of moving lines - and with it the reading
# rule of Chapter 4 - has the same distribution under both
# methods. The line values differ by about 0.04 nats per line, so
# telling from the casts alone which method produced them takes
# some 17 six-line casts on average.动爻的个数在两种方法下都服从二项分布 :没有动爻的概率为 0.1780,一个动爻 0.3560,六爻全动只有 0.0002;至少有一个动爻的概率为 0.8220。第四章的变占规则按动爻数分类,所以每条规则被用到的概率在两种方法下相同。
两种方法的爻值分布之间的库尔贝克—莱布勒散度约为每爻 0.0432 奈特。换句话说,如果只看起卦记录、想判断它出自哪种方法,平均需要约 17.8 次六爻起卦,证据才达到 100 比 1。
小结
蓍草法与三钱法在阴阳与动静的比例上完全相同,区别只在于动的是哪一种爻:铜钱法下老阴老阳各 1/8,蓍草法下老阳 3/16 是老阴 1/16 的三倍,因而之卦偏阴(阳爻比例 3/8)。「三倍」在二项分布或接近对半的自然分蓍下精确到四位小数,在均匀分布的分蓍下变为 4.082。两种方法的动爻数分布相同,要从记录中区分它们平均需要约 18 次起卦。
参考文献
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).