5D Library › 六维超立方体游走、卦变马尔可夫链与模运算星宫晶格 · English

第一章 六十四卦是六维立方体

卦即二进制串

一个六画卦自下而上有六爻,每爻非阴即阳。记阳为 1、阴为 0,一个卦就是一个六位二进制串 x=(x1,…,x6)x = (x_1, \dots, x_6),六十四卦恰好是集合 ℤ26\mathbb{Z}_2^6 的全部元素,也就是六维立方体的六十四个顶点。两个卦之间相差的爻数,就是两个顶点之间的汉明距离 dHd_H;从本卦到之卦变了几爻,就在立方体上走了几步。立方体上的函数可以用沃尔什—傅里叶基展开,这是布尔函数分析的基本工具 (O’Donnell 2014),第四章会用到它。

推导

三种对称。 错卦(旁通)把每一爻阴阳互换,即与 1111112111111_2 做异或:x↦x⊕1111112x \mapsto x \oplus 111111_2。综卦(反对)把卦上下颠倒,即把位序反转:(x1,…,x6)↦(x6,…,x1)(x_1, \dots, x_6) \mapsto (x_6, \dots, x_1)。两者可交换,再加上「错综」(两者都做)与恒等,构成一个四元群(克莱因四元群)作用在六十四卦上。伯恩赛德引理说,轨道的个数等于群中每个元素固定的卦数的平均值。

第一段程序计算距离的分布、四种对称各固定多少卦,并检查通行本卦序的配对方式。

推导

# 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.

两卦相差 kk 爻的概率是 (6k)/64\binom{6}{k}/64:相差 3 爻最常见(0.3125),完全相同或完全相反都只有 0.0156。错卦不固定任何卦——没有一个卦与自己阴阳全反;综卦固定 8 个卦,即上下颠倒后不变的「对称卦」;错综也固定 8 个。按伯恩赛德引理,四种对称把六十四卦分成 80/4=2080/4 = 20 个轨道。

通行本的卦序(文王序)恰好体现了这一结构:第 2k−12k-1 与第 2k2k 卦两两成对,28 对互为综卦,其余 4 对由颠倒后不变的 8 个卦组成,互为错卦,合计 32 对,没有例外。

互卦:两步之内收缩到四个卦

互卦取本卦的二、三、四爻为下卦,三、四、五爻为上卦。在位串上它是一个滑动窗口:

(x1,x2,x3,x4,x5,x6)↦(x2,x3,x4,x3,x4,x5).(x_1, x_2, x_3, x_4, x_5, x_6) \mapsto (x_2, x_3, x_4, x_3, x_4, x_5).

结果只依赖于中间四位,所以互卦把 64 卦映到 16 卦,每个像恰有 4 个原像,不是满射。再做一次,得到 (x3,x4,x3,x4,x3,x4)(x_3, x_4, x_3, x_4, x_3, x_4),只剩两位,即 4 个卦。

推导

# 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.

两次互卦之后,64 卦落到乾、坤、既济、未济这 4 个卦上,各有 16 个原像。但这 4 个卦的地位并不相同:乾的互卦是乾,坤的互卦是坤,它们是不动点;既济(离下坎上)的互卦是未济,未济的互卦又是既济,两者构成一个二周期。所以说互卦「收敛到四个吸引子」不准确:它收敛到两个不动点与一个二周期。在位串上看,这正是三、四两爻的交替:两位相同时得到乾或坤,两位不同时在既济与未济之间来回。

注

这对「互卦看过程」一类说法意味着什么。 互卦每做一次就丢掉两爻的信息,所以它是一个有损的投影,不能从互卦还原本卦。两次之后只剩三、四两爻的关系,任何依赖二次互卦的判断,实际上只用到了这两爻。

小结

六十四卦就是六维立方体 ℤ26\mathbb{Z}_2^6,变爻的个数是汉明距离。错卦与综卦生成一个四元群,把六十四卦分成 20 个轨道;通行本的卦序按综卦配对,对称卦则按错卦配对,32 对没有例外。互卦是中间四爻上的滑动窗口:一次把 64 卦折叠为 16 卦,二次折叠为 4 卦,其中乾、坤为不动点,既济与未济为二周期。

参考文献

O’Donnell, Ryan. 2014. Analysis of Boolean Functions. Cambridge University Press.

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).