5D Library › 玄空飞星置换代数、二十四山罗盘离散化与骨相比例计量 · English

第二章 合十、三般卦与替卦的约定

合十与三般卦

每一宫有三个数:运星、山星、向星。几种传统上受重视的格局可以写成精确的条件。合十:在所有九宫中,运星与向星之和都是 10(向星合十),或运星与山星之和都是 10(山星合十)。父母三般卦:每一宫的三个数都属于同一组 {1, 4, 7}、{2, 5, 8} 或 {3, 6, 9}。连珠三般卦:每一宫的三个数是连续的三个数(9 与 1 相邻)。

代数上,两张盘的和在九宫中保持不变,只有当它们沿相反方向飞行时才可能;此时和为 10,当且仅当两个中宫数之和模 9 余 1。

推导

# Chapter 2. p03: He shi and san ban gua among the 216 charts.
# Same chart rules as p02. In each of the nine palaces a chart shows
# three numbers: period star, mountain star, facing star. Patterns:
#   he shi (sum to ten), facing side: period + facing = 10 everywhere;
#   he shi, mountain side: period + mountain = 10 everywhere;
#   san ban gua (father and mother): in every palace the three numbers
#     form one of the sets {1, 4, 7}, {2, 5, 8}, {3, 6, 9};
#   lian zhu (string of pearls): in every palace the three numbers are
#     consecutive, such as 3, 4, 5 (9 counts as next to 1).
# Algebra: a sum is constant over the palaces only if the two charts
# fly in opposite directions; then it equals 10 exactly when the two
# centre numbers sum to 1 mod 9.
import collections

LOSHU = {"SE": 4, "S": 9, "SW": 2, "E": 3, "C": 5, "W": 7,
         "NE": 8, "N": 1, "NW": 6}
PALACE_OF = {v: k for k, v in LOSHU.items()}
PATH = ["C", "NW", "W", "NE", "S", "N", "SW", "E", "SE"]
OPP = {"N": "S", "S": "N", "E": "W", "W": "E", "NE": "SW", "SW": "NE",
       "NW": "SE", "SE": "NW"}
PAL_ORDER = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"]
MOUNTAINS = ("ren zi gui chou gen yin jia mao yi chen xun si bing wu "
             "ding wei kun shen geng you xin xu qian hai").split()

def norm(x):
    return (x - 1) % 9 + 1

def fly(c, sign):
    return {p: norm(c + sign * k) for k, p in enumerate(PATH)}

def polarity(number, pos):
    cardinal = number in (1, 3, 7, 9)
    return (1, -1, -1)[pos] if cardinal else (-1, 1, 1)[pos]

def side(base, pal, pos):
    n = base[pal]
    ref = LOSHU[pal] if n == 5 else n
    return fly(n, polarity(ref, pos))

def chart(period, i):
    base = fly(period, 1)
    sit = PAL_ORDER[i // 3]
    face = OPP[sit]
    return base, side(base, sit, i % 3), side(base, face, i % 3), sit, face

def category(period, i):
    base, m, f, sit, face = chart(period, i)
    if m[sit] == period and f[face] == period:
        return "wang shan wang xiang"
    if m[face] == period and f[sit] == period:
        return "shang shan xia shui"
    if m[face] == period and f[face] == period:
        return "shuang xing hui xiang"
    return "shuang xing hui zuo"

def palaces(ch):
    base, m, f, sit, face = ch
    return [(base[p], m[p], f[p]) for p in PATH]

def he_shi(trip, k):
    return all(t[0] + t[k] == 10 for t in trip)

def san_ban(trip):
    return all(len({x % 3 for x in t}) == 1 and len(set(t)) == 3
               for t in trip)

def lian_zhu(trip):
    for t in trip:
        s = sorted(t)
        if not any({norm(a), norm(a + 1), norm(a + 2)} == set(s)
                   for a in range(1, 10)):
            return False
    return True

if __name__ == "__main__":
    cnt = collections.Counter()
    by_cat = collections.Counter()
    for p in range(1, 10):
        for i in range(24):
            trip = palaces(chart(p, i))
            for name, ok in (("he shi, facing side", he_shi(trip, 2)),
                             ("he shi, mountain side", he_shi(trip, 1)),
                             ("san ban gua", san_ban(trip)),
                             ("lian zhu", lian_zhu(trip))):
                if ok:
                    cnt[name] += 1
                    by_cat[(name, category(p, i))] += 1
    print("   pattern                  charts   share of 216")
    for name in ("he shi, facing side", "he shi, mountain side",
                 "san ban gua", "lian zhu"):
        print("   {:22s} {:8d} {:14.4f}".format(name, cnt[name],
                                               cnt[name] / 216))
    print("\n   pattern by class (only non-zero cells):")
    for (name, cat), n in sorted(by_cat.items()):
        print("     {:22s} {:22s} {:3d}".format(name, cat, n))
    print("\nReading: each pattern is rare and confined to particular")
    print("classes: he shi needs two charts flying in opposite")
    print("directions with matching centres, and san ban gua and lian")
    print("zhu occur only among the shang shan xia shui charts. These")
    print("are facts about a permutation table, not evidence about")
    print("houses.")
#    pattern                  charts   share of 216
#    he shi, facing side          12         0.0556
#    he shi, mountain side        12         0.0556
#    san ban gua                  16         0.0741
#    lian zhu                     16         0.0741
#
#    pattern by class (only non-zero cells):
#      he shi, facing side    shuang xing hui xiang    8
#      he shi, facing side    wang shan wang xiang     4
#      he shi, mountain side  shuang xing hui zuo      8
#      he shi, mountain side  wang shan wang xiang     4
#      lian zhu               shang shan xia shui     16
#      san ban gua            shang shan xia shui     16
#
# Reading: each pattern is rare and confined to particular
# classes: he shi needs two charts flying in opposite
# directions with matching centres, and san ban gua and lian
# zhu occur only among the shang shan xia shui charts. These
# are facts about a permutation table, not evidence about
# houses.

216 盘中,向星合十与山星合十各 12 个(各占 0.0556),父母三般卦与连珠三般卦各 16 个(各占 0.0741)。它们只出现在特定的类中:向星合十有 8 个在双星会向、4 个在旺山旺向;山星合十有 8 个在双星会坐、4 个在旺山旺向;父母三般卦与连珠三般卦全部出现在上山下水的盘中。这是置换表的事实,不是关于房子的证据。

替卦:两种约定

坐向靠近两山交界时,许多流派改用替卦:把侧盘的中宫数换成相应之山的「替星」。本书采用的替星表为:子、癸、甲、申为 1;坤、壬、乙、卯、未为 2;戌、乾、亥、辰、巽、巳为 6;酉、辛、丑、艮、丙为 7;寅、午、庚、丁为 9。替换之后如何决定飞行方向,各家说法不一。本书比较两种明确写出的约定:约定 A 沿用下卦的飞行方向;约定 B 改用替星本宫的阴阳。

推导

# Chapter 2. p04: Replacement charts (ti gua) under two conventions.
# When a facing lies near the edge of its mountain, the replacement
# method changes the centre number of each side chart: the number n
# is replaced by the replacement star of the mountain in the same
# position within palace n (n = 5: the palace where it stands), from
#   zi gui jia shen -> 1;  kun ren yi mao wei -> 2;
#   xu qian hai chen xun si -> 6;  you xin chou gen bing -> 7;
#   yin wu geng ding -> 9.
# Texts differ on the direction of flight after replacement. Two
# stated conventions: A keeps the direction of the ordinary chart;
# B takes the polarity of the replacement number's own palace. With
# a new centre, the period star may land in neither the sitting nor
# the facing palace: class "other".
import collections

LOSHU = {"SE": 4, "S": 9, "SW": 2, "E": 3, "C": 5, "W": 7,
         "NE": 8, "N": 1, "NW": 6}
PALACE_OF = {v: k for k, v in LOSHU.items()}
PATH = ["C", "NW", "W", "NE", "S", "N", "SW", "E", "SE"]
OPP = {"N": "S", "S": "N", "E": "W", "W": "E", "NE": "SW", "SW": "NE",
       "NW": "SE", "SE": "NW"}
PAL_ORDER = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"]
MOUNTAINS = ("ren zi gui chou gen yin jia mao yi chen xun si bing wu "
             "ding wei kun shen geng you xin xu qian hai").split()

def norm(x):
    return (x - 1) % 9 + 1

def fly(c, sign):
    return {p: norm(c + sign * k) for k, p in enumerate(PATH)}

def polarity(number, pos):
    cardinal = number in (1, 3, 7, 9)
    return (1, -1, -1)[pos] if cardinal else (-1, 1, 1)[pos]

def side(base, pal, pos):
    n = base[pal]
    ref = LOSHU[pal] if n == 5 else n
    return fly(n, polarity(ref, pos))

def chart(period, i):
    base = fly(period, 1)
    sit = PAL_ORDER[i // 3]
    face = OPP[sit]
    return base, side(base, sit, i % 3), side(base, face, i % 3), sit, face

def category(period, i):
    base, m, f, sit, face = chart(period, i)
    if m[sit] == period and f[face] == period:
        return "wang shan wang xiang"
    if m[face] == period and f[sit] == period:
        return "shang shan xia shui"
    if m[face] == period and f[face] == period:
        return "shuang xing hui xiang"
    return "shuang xing hui zuo"

TI = {}
for names, star in (("zi gui jia shen", 1), ("kun ren yi mao wei", 2),
                    ("xu qian hai chen xun si", 6),
                    ("you xin chou gen bing", 7), ("yin wu geng ding", 9)):
    for n in names.split():
        TI[n] = star

def side_ti(base, pal, pos, conv):
    n = base[pal]
    ref = LOSHU[pal] if n == 5 else n
    c = TI[MOUNTAINS[PAL_ORDER.index(PALACE_OF[ref]) * 3 + pos]]
    sign = polarity(ref, pos) if conv == "A" else polarity(c, pos)
    return fly(c, sign)

def chart_ti(period, i, conv):
    base = fly(period, 1)
    sit = PAL_ORDER[i // 3]
    face = OPP[sit]
    return (base, side_ti(base, sit, i % 3, conv),
            side_ti(base, face, i % 3, conv), sit, face)

def classify(ch, period):
    base, m, f, sit, face = ch
    if m[sit] == period and f[face] == period:
        return "wang shan wang xiang"
    if m[face] == period and f[sit] == period:
        return "shang shan xia shui"
    if m[face] == period and f[face] == period:
        return "shuang xing hui xiang"
    if m[sit] == period and f[sit] == period:
        return "shuang xing hui zuo"
    return "other"

if __name__ == "__main__":
    names = ["wang shan wang xiang", "shang shan xia shui",
             "shuang xing hui xiang", "shuang xing hui zuo", "other"]
    res, cnt, changed = {}, {}, {}
    for conv in ("A", "B"):
        cnt[conv], changed[conv] = collections.Counter(), 0
        for p in range(1, 10):
            for i in range(24):
                ch = chart_ti(p, i, conv)
                cnt[conv][classify(ch, p)] += 1
                changed[conv] += ch[1:3] != chart(p, i)[1:3]
                res[(conv, p, i)] = ch[1:3]
    print("   charts that differ from the ordinary chart: A {}, B {}"
          .format(changed["A"], changed["B"]))
    print("\n   class                    ordinary   conv. A   conv. B")
    plain = collections.Counter(category(p, i) for p in range(1, 10)
                                for i in range(24))
    for n in names:
        print("   {:22s} {:10d} {:9d} {:9d}".format(
            n, plain[n], cnt["A"][n], cnt["B"][n]))
    same = sum(1 for p in range(1, 10) for i in range(24)
               if res[("A", p, i)] == res[("B", p, i)])
    print("\n   charts on which A and B agree: {} of 216 ({:.4f})".format(
        same, same / 216))
    print("\nReading: the replacement method changes most charts, and")
    print("the two conventions disagree on half of them. A reading that")
    print("depends on which convention a master follows is a property")
    print("of the convention, which must be stated before any test.")
#    charts that differ from the ordinary chart: A 182, B 182
#
#    class                    ordinary   conv. A   conv. B
#    wang shan wang xiang           48        24        16
#    shang shan xia shui            48         4         2
#    shuang xing hui xiang          60        14        19
#    shuang xing hui zuo            60        14        19
#    other                           0       160       160
#
#    charts on which A and B agree: 108 of 216 (0.5000)
#
# Reading: the replacement method changes most charts, and
# the two conventions disagree on half of them. A reading that
# depends on which convention a master follows is a property
# of the convention, which must be stated before any test.

两种约定都改变了 216 盘中的 182 个。中宫数一旦改变,当运之星可能既不在坐也不在向,形成第五类「其他」,在两种约定下各有 160 个。其余四类的计数也不同:约定 A 下旺山旺向 24 个、上山下水 4 个,约定 B 下分别为 16 个与 2 个。两种约定只在 108 个盘上一致,恰为一半(0.5000)。

假说 · 尚未验证

可检验的推论。 若替卦的某一约定确实对应可观测的差别,那么在预先登记的检验中,按该约定分类的结局差异应显著大于按另一约定分类的差异。什么会证明这一推论错:若两种约定的分类与结局都无关,或彼此没有差别,那么约定之争在经验上没有内容。

小结

合十、三般卦与连珠都是稀少的格局,并且只出现在特定的类中。替卦改变了大多数的盘,而两种约定只在一半的盘上一致:任何依赖替卦的论断,都必须先说明采用的是哪一种约定。

Fan, Y. (2026). Xuankong Flying-Star Permutations, Twenty-Four-Mountain Compass Discretization and Craniofacial Ratio Metrology: Lo-Shu Orbit Cycles, Magnetic Declination Flip Rates and Landmark Measurement Error Propagation [玄空飞星置换代数、二十四山罗盘离散化与骨相比例计量] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090215 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).