What does Najia and Qimen Combinatorics conclude, in numbers, about “Jing Fang's Eight Palaces and the Najia: XOR Masks and a Closed Form”?
Answer: The program checks that each of the 64 hexagrams belongs to exactly one palace; in King Wen numbers the Qian palace is 1, 44, 33, 12, 20, 23, 35, 14 (Qian, Gou, Dun, Pi, Guan, Bo, Jin, Da You) and the Kun palace 2, 24, 19, 11, 34, 43, 5, 8, as in the usual table of the eight palaces.
Scope of the numbers: Marked boxes separate evidence, 16 runnable Python programs, classical sources and hypotheses.
Data table
The numbers below are printed verbatim by the chapter's Python program and can be reproduced by running it. printed values that match the answer: 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.
Key formula
Show the full program
# 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.")Single source and citation
Fan, Y. (2026). Najia Hexagram Encoding and Qimen Dunjia Combinatorial Engines (Version 1.0.0), Chapter 1: Jing Fang's Eight Palaces and the Najia: XOR Masks and a Closed Form. 5D Library. https://doi.org/10.5281/zenodo.24090182
DOI: 10.5281/zenodo.24090182 · Read the monograph · 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}
}Other chapter answers in this book
- Chapter 2 · Six Relatives, Six Spirits and the Void Branches
- Chapter 3 · The Seventy-Two Bureau Numbers and Two Calendars
- Chapter 4 · Earth Plate and Heaven Plate: a Dihedral Group and a Ring Rotation
- Chapter 5 · The Human and Spirit Plates, and the Group the Plates Generate
- Chapter 6 · How Often the Patterns Occur, How Conventions Disagree, and Neighbouring Hours
- Chapter 7 · The Jing shi yizhuan and the Rhapsody of the Old Fisherman
- Chapter 8 · A Budget of Conventions and a Pre-Registered Matching Test