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

第一章 洛书、飞星路径与二面体群

洛书与飞星路径

洛书把 1 至 9 排进九宫:南 9、北 1、东 3、西 7、东南 4、西南 2、东北 8、西北 6、中宫 5,每行、每列、每条对角线之和都是 15。玄空飞星的排盘沿一条固定的路径移动数字:中宫、西北、西、东北、南、北、西南、东、东南。这条路径按洛书的数字看,恰好是 5、6、7、8、9、1、2、3、4。

一张飞星盘由中宫的数字 cc 与飞行方向决定。顺飞时第 kk 宫(沿路径计数)的数字是 c+kc + k,逆飞时是 c−kc – k,都按 9 取模并写成 1 至 9。既然第 kk 宫的洛书数是 5+k5 + k,一张盘就是把洛书上的每个数 xx 映射为 c+(x−5)c + (x – 5) 或 c−(x−5)c – (x – 5)。也就是说,所有飞星盘就是九元循环群 ℤ9\mathbb{Z}_9 上的十八个映射 x↦x+tx \mapsto x + t 与 x↦−x+tx \mapsto -x + t,它们构成 18 阶的二面体群 (Dummit and Foote 2004)。

推导

# Chapter 1. p01: The Lo Shu, the flight path and the group D9.
# The Lo Shu places 1 to 9 in the nine palaces (north at the bottom):
#     SE 4   S 9   SW 2
#     E  3   C 5   W  7
#     NE 8   N 1   NW 6
# Flying stars move along the fixed path C, NW, W, NE, S, N, SW, E, SE,
# which visits the palaces in Lo Shu order 5, 6, 7, 8, 9, 1, 2, 3, 4.
# A chart with centre star c, flown forward, puts c + k at the k-th
# palace of the path; flown backward, c - k (numbers taken mod 9 and
# written 1 to 9). Since the k-th palace has Lo Shu number 5 + k, a
# chart is the map x -> c + (x - 5) or x -> c - (x - 5) applied to the
# Lo Shu: the 18 maps x -> +x + t and x -> -x + t on Z9, which form
# the dihedral group of order 18. The program checks this, finds the
# order of each kind of map, counts which charts are magic squares,
# and lists the period charts of the 180-year cycle of nine periods.
LOSHU = {"SE": 4, "S": 9, "SW": 2, "E": 3, "C": 5, "W": 7,
         "NE": 8, "N": 1, "NW": 6}
PATH = ["C", "NW", "W", "NE", "S", "N", "SW", "E", "SE"]
GRID = [["SE", "S", "SW"], ["E", "C", "W"], ["NE", "N", "NW"]]

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

def fly(c, forward=True):
    return {p: norm(c + k if forward else c - k)
            for k, p in enumerate(PATH)}

def is_magic(ch):
    rows = [[ch[p] for p in r] for r in GRID]
    sums = [sum(r) for r in rows] + [sum(c) for c in zip(*rows)]
    sums += [rows[0][0] + rows[1][1] + rows[2][2],
             rows[0][2] + rows[1][1] + rows[2][0]]
    return len(set(sums)) == 1

def order(f):
    x = list(range(1, 10))
    y, n = [f(v) for v in x], 1
    while y != x:
        y, n = [f(v) for v in y], n + 1
    return n

if __name__ == "__main__":
    print("   path visits Lo Shu numbers:", [LOSHU[p] for p in PATH])
    ok = all(fly(c, fw)[p] == norm(c + s * (LOSHU[p] - 5))
             for c in range(1, 10) for fw, s in ((True, 1), (False, -1))
             for p in PATH)
    print("   every chart equals x -> c +/- (x - 5) on the Lo Shu:", ok)
    charts = {tuple(sorted(fly(c, fw).items()))
              for c in range(1, 10) for fw in (True, False)}
    print("   distinct charts: {}".format(len(charts)))
    print("   order of x -> x + 1: {}; of x -> -x + t: {}".format(
        order(lambda v: norm(v + 1)), order(lambda v: norm(-v + 3))))
    magic = [(c, fw) for c in range(1, 10) for fw in (True, False)
             if is_magic(fly(c, fw))]
    print("   magic squares among the 18:", magic)
    print("\n   period  years          chart (SE S SW / E C W / NE N NW)")
    for p in range(1, 10):
        ch = fly(p)
        y0 = 1864 + 20 * (p - 1)
        txt = " / ".join(" ".join(str(ch[q]) for q in r) for r in GRID)
        print("   {:6d}  {} to {}   {}".format(p, y0, y0 + 19, txt))
    print("   nine periods of 20 years: {} years".format(9 * 20))
#    path visits Lo Shu numbers: [5, 6, 7, 8, 9, 1, 2, 3, 4]
#    every chart equals x -> c +/- (x - 5) on the Lo Shu: True
#    distinct charts: 18
#    order of x -> x + 1: 9; of x -> -x + t: 2
#    magic squares among the 18: [(5, True), (5, False)]
#
#    period  years          chart (SE S SW / E C W / NE N NW)
#         1  1864 to 1883   9 5 7 / 8 1 3 / 4 6 2
#         2  1884 to 1903   1 6 8 / 9 2 4 / 5 7 3
#         3  1904 to 1923   2 7 9 / 1 3 5 / 6 8 4
#         4  1924 to 1943   3 8 1 / 2 4 6 / 7 9 5
#         5  1944 to 1963   4 9 2 / 3 5 7 / 8 1 6
#         6  1964 to 1983   5 1 3 / 4 6 8 / 9 2 7
#         7  1984 to 2003   6 2 4 / 5 7 9 / 1 3 8
#         8  2004 to 2023   7 3 5 / 6 8 1 / 2 4 9
#         9  2024 to 2043   8 4 6 / 7 9 2 / 3 5 1
#    nine periods of 20 years: 180 years

程序核对了这一等式,确认恰有 18 张不同的盘;平移 x↦x+1x \mapsto x + 1 的阶为 9,反射 x↦−x+tx \mapsto -x + t 的阶为 2。18 张盘中只有中宫为 5 的顺飞(洛书本身)与逆飞两张是幻方;其余的盘因为取模而失去「纵横十五」的性质。按三元九运,每运 20 年,九运共 180 年;第九运为 2024 年至 2043 年,其运盘中宫为 9。

216 个下卦盘与四类格局

一座房子的盘有三层:运盘(当运之数入中顺飞);山星盘,以运盘落在坐山宫位的数入中;向星盘,以运盘落在向首宫位的数入中。山星与向星各自顺飞还是逆飞,由该数所代表之宫中与坐山(或向首)同一元龙(地元、天元、人元)之山的阴阳决定;该数为 5 时,以 5 所在宫位的洛书数代之。本书采用的阴阳约定是:四正宫(1、3、7、9)的地、天、人三山为阳、阴、阴,四隅宫(2、4、6、8)为阴、阳、阳。

格局按当运之星落在哪里分为四类:旺山旺向(山星当运之星在坐,向星当运之星在向)、上山下水(反之)、双星会向(两者都在向)、双星会坐(两者都在坐)。

推导

# Chapter 1. p02: All 216 charts and their four classes.
# A house chart for period P and sitting mountain m has three layers:
# the period chart (P in the centre, flown forward); the mountain-star
# chart, whose centre is the period-chart number n found in the
# sitting palace; and the facing-star chart, whose centre is the
# number found in the facing palace. Each side chart flies forward or
# backward by the polarity of the mountain in the same position
# (earth, heaven or man) within the palace whose Lo Shu number is n;
# when n = 5, the palace where the 5 stands is used instead. The
# twenty-four mountains are listed from ren clockwise in pinyin; the
# facing mountain is the one opposite, in the same position.
# Classes, by where the period star P falls in the two side charts:
#   wang shan wang xiang: mountain star P sits, facing star P faces;
#   shang shan xia shui: the reverse of that;
#   shuang xing hui xiang / hui zuo: both P at the facing / sitting.
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"

if __name__ == "__main__":
    base, m, f, sit, face = chart(8, 1)
    print("   check, period 8, zi sitting: mountain star {} and facing star"
          .format(m["S"]))
    print("   {} at the facing palace S -> {}".format(
        f["S"], category(8, 1)))
    names = ["wang shan wang xiang", "shang shan xia shui",
             "shuang xing hui xiang", "shuang xing hui zuo"]
    print("\n   period   wang-wang   shang-xia   hui xiang   hui zuo")
    tot = collections.Counter()
    for p in range(1, 10):
        c = collections.Counter(category(p, i) for i in range(24))
        tot.update(c)
        print("   {:6d} {:11d} {:11d} {:11d} {:9d}".format(
            p, *[c[n] for n in names]))
    print("   {:>6s} {:11d} {:11d} {:11d} {:9d}".format(
        "all", *[tot[n] for n in names]))
    print("\n   shares of 216: " + ", ".join(
        "{:.4f}".format(tot[n] / 216) for n in names))
    for p in (8, 9):
        ws = [MOUNTAINS[i] for i in range(24) if category(p, i) == names[0]]
        print("   period {}, wang shan wang xiang sitting mountains:"
              .format(p))
        print("     " + (" ".join(ws) if ws else "none"))
    print("\nReading: the four classes exhaust all 216 charts, because")
    print("a side chart flown forward always carries P to the palace")
    print("opposite its start, and flown backward keeps it there. The")
    print("class of a chart is fixed by two polarities and nothing else.")
#    check, period 8, zi sitting: mountain star 8 and facing star
#    8 at the facing palace S -> shuang xing hui xiang
#
#    period   wang-wang   shang-xia   hui xiang   hui zuo
#         1           0           0          12        12
#         2           6           6           6         6
#         3           6           6           6         6
#         4           6           6           6         6
#         5          12          12           0         0
#         6           6           6           6         6
#         7           6           6           6         6
#         8           6           6           6         6
#         9           0           0          12        12
#       all          48          48          60        60
#
#    shares of 216: 0.2222, 0.2222, 0.2778, 0.2778
#    period 8, wang shan wang xiang sitting mountains:
#      chou xun si wei qian hai
#    period 9, wang shan wang xiang sitting mountains:
#      none
#
# Reading: the four classes exhaust all 216 charts, because
# a side chart flown forward always carries P to the palace
# opposite its start, and flown backward keeps it there. The
# class of a chart is fixed by two polarities and nothing else.

程序先核对一个熟知的例子:八运子山午向,向首离宫的山星与向星都是 8,为双星会向。216 个下卦盘中,旺山旺向与上山下水各 48 个(各占 0.2222),双星会向与双星会坐各 60 个(各占 0.2778)。八运的旺山旺向坐山为丑、巽、巳、未、乾、亥;一运与九运都没有旺山旺向或上山下水的下卦盘,五运则只有这两类。

四类恰好穷尽所有的盘,原因是一条简单的代数事实:一张侧盘若顺飞,当运之星必落在起点宫位的对宫;若逆飞,则留在起点宫位。山星盘的起点是坐山宫的运盘数,所以山星当运之星「在坐还是在向」只取决于山星盘的飞行方向;向星同理。于是每个盘的格局由两个阴阳完全决定,与其他任何因素无关。

九运子山午向的飞星盘。大字为运盘,左上为山星,右上为向星;坐山与向首宫位以底色标出。
九个元运中四类格局的盘数(每运 24 盘)。

注

这是什么,不是什么。 以上计数是置换表的性质,与房子的吉凶无关。它们说明的是:一旦约定了路径、阴阳与入中规则,格局就是确定的算术结果;不同的约定会给出不同的表。

小结

飞星排盘是九元循环群上的仿射置换,十八种盘构成二面体群。216 个下卦盘按当运之星的落点分为四类,每类所占的比例与每一运的分布都可以精确算出;格局只取决于山星与向星的飞行方向。

参考文献

Dummit, David S., and Richard M. Foote. 2004. Abstract Algebra. 3rd ed. John Wiley; Sons.

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