关于「京房八宫与纳甲:异或掩码与闭式」,《纳甲与奇门的组合计算》给出的定量结论是什么?
结论:程序验证了 64 卦恰好每卦属于一宫,乾宫依文王卦序为 1、44、33、12、20、23、35、14(乾、姤、遁、否、观、剥、晋、大有),坤宫为 2、24、19、11、34、43、5、8,与通行的八宫表一致。
数据口径:书中以标注框区分证据、16 段可运行的 Python 程序、原典与假说。
对照数据表
下表数字由本章 Python 程序原样打印,可重新运行复现。 与结论吻合的打印值: 11, 12, 14, 19, 20, 23
King Wen table is a bijection onto 1..64: True every hexagram lies in exactly one palace: True Qian palace (King Wen): 1 44 33 12 20 23 35 14 Kun palace (King Wen): 2 24 19 11 34 43 5 8 generation lines flipped upper XOR lower shi ying pure - 000 6 3 1st 1 100 1 4 2nd 1,2 110 2 5 3rd 1,2,3 111 3 6 4th 1,2,3,4 011 4 1 5th 1,2,3,4,5 001 5 2 wandering 1,2,3,5 101 4 1 returning 5 010 3 6 the eight XOR codes are all different: True; generations 0-5 form a Gray code (one bit changes per step): True Reading: a palace is the pure hexagram XOR a fixed set of eight masks. Which generation a hexagram belongs to, and hence its world line, is read off from upper XOR lower alone; its palace is then the lower trigram XOR the mask's lower half.
核心公式
\[\varnothing,\ \{1\},\ \{1,2\},\ \{1,2,3\},\ \{1,2,3,4\},\ \{1,\dots,5\},\ \{1,2,3,5\},\ \{5\}\]
查看完整验算程序
# Chapter 1. Jing Fang's eight palaces as bit flips on (Z_2)^6.
# A hexagram is six bits, line 1 (bottom) to line 6 (top), yang = 1;
# a trigram is three bits, bottom first. Each palace starts from a pure
# hexagram (the same trigram twice) and flips a fixed set of lines:
# generations 1-5 flip lines 1, 1-2, 1-3, 1-4, 1-5; the "wandering
# soul" flips 1-3 and 5; the "returning soul" flips only line 5.
# The world line (shi) of each generation and the response line (ying,
# three lines away) follow the usual table.
TRIGRAMS = {"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)}
GENERATIONS = (("pure", (), 6), ("1st", (1,), 1), ("2nd", (1, 2), 2),
("3rd", (1, 2, 3), 3), ("4th", (1, 2, 3, 4), 4),
("5th", (1, 2, 3, 4, 5), 5),
("wandering", (1, 2, 3, 5), 4), ("returning", (5,), 3))
# King Wen numbers: KW[upper][lower]
ORDER = ("Qian", "Zhen", "Kan", "Gen", "Kun", "Xun", "Li", "Dui")
KW_ROWS = ((1, 25, 6, 33, 12, 44, 13, 10), (34, 51, 40, 62, 16, 32, 55, 54),
(5, 3, 29, 39, 8, 48, 63, 60), (26, 27, 4, 52, 23, 18, 22, 41),
(11, 24, 7, 15, 2, 46, 36, 19), (9, 42, 59, 53, 20, 57, 37, 61),
(14, 21, 64, 56, 35, 50, 30, 38), (43, 17, 47, 31, 45, 28, 49, 58))
KW = {(ORDER[u], ORDER[l]): KW_ROWS[u][l] for u in range(8) for l in range(8)}
NAME = {bits: n for n, bits in TRIGRAMS.items()}
def flip(hexagram, lines):
return tuple(b ^ (i + 1 in lines) for i, b in enumerate(hexagram))
def palace_members(t):
pure = TRIGRAMS[t] + TRIGRAMS[t]
return [flip(pure, lines) for _, lines, _ in GENERATIONS]
def kw(h):
return KW[NAME[h[3:]], NAME[h[:3]]]
if __name__ == "__main__":
print(" King Wen table is a bijection onto 1..64: {}".format(
sorted(KW.values()) == list(range(1, 65))))
seen = {}
for t in TRIGRAMS:
for g, h in enumerate(palace_members(t)):
seen.setdefault(h, []).append((t, g))
print(" every hexagram lies in exactly one palace: {}".format(
len(seen) == 64 and all(len(v) == 1 for v in seen.values())))
for t in ("Qian", "Kun"):
print(" {:4s} palace (King Wen): ".format(t) + " ".join(
str(kw(h)) for h in palace_members(t)))
print(" generation lines flipped upper XOR lower shi ying")
codes = []
for name, lines, shi in GENERATIONS:
m = flip((0,) * 6, lines)
x = tuple(a ^ b for a, b in zip(m[:3], m[3:]))
codes.append(x)
ying = shi + 3 if shi <= 3 else shi - 3
print(" {:10s} {:13s} {} {} {}".format(
name, ",".join(map(str, lines)) or "-", "".join(map(str, x)),
shi, ying))
gray = all(sum(a != b for a, b in zip(codes[i], codes[i + 1])) == 1
for i in range(5))
print(" the eight XOR codes are all different: {}; generations 0-5"
.format(len(set(codes)) == 8))
print(" form a Gray code (one bit changes per step): {}".format(gray))
print("\nReading: a palace is the pure hexagram XOR a fixed set of eight")
print("masks. Which generation a hexagram belongs to, and hence its")
print("world line, is read off from upper XOR lower alone; its palace")
print("is then the lower trigram XOR the mask's lower half.")唯一数据源与引用
范雅福(Fan, Y.). (2026). 《纳甲装卦与奇门遁甲排盘的组合计算》第 1 章「京房八宫与纳甲:异或掩码与闭式」(版本 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090182
DOI: 10.5281/zenodo.24090182 · 阅读本章所在专著 · 5DL-B-067 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026067,
author = {Fan, Yafu},
title = {Najia Hexagram Encoding and Qimen Dunjia Combinatorial Engines},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
doi = {10.5281/zenodo.24090182},
url = {https://doi.org/10.5281/zenodo.24090182}
}