5D Library › Six-Dimensional Hypercube Walks, Hexagram Mutation Markov Chains and Modular Star-Palace Lattices · 中文
Chapter 6. “Three Sides and Four Squares” Is a Convolution on the Ring of Twelve Palaces
Writing “three sides and four squares” as a convolution
To judge a palace, Zi Wei Dou Shu looks not only at the palace itself but at its opposite palace and its two trine palaces — together, “three sides and four squares”. If the stars in palace have value and the palace, its opposite and its trines are weighted , the combined score of palace is
exactly a circular convolution on . A circular convolution is diagonalised by the discrete Fourier transform: harmonic is multiplied by . Wherever , the information in that harmonic is invisible in the combined score.
Calculation
The zeros of equal trines. Taking only the palace and its two trines with equal weights gives , which is zero whenever is not a multiple of 3. That is, the trine triangle is the subgroup of order 3 in , and summing over it can see only patterns of period 4.
Calculation
# Chapter 6. "Three sides and four squares" as a convolution on Z12.
# To judge a palace i the reading combines the palace itself, its
# opposite i + 6 and its two trines i + 4 and i + 8 - the triangle
# {0, 4, 8} is the subgroup of order 3 in Z12. Any weighting of these
# four places is a circular convolution s = w * v of the star values v
# with a kernel w on Z12, and is diagonalised by the discrete Fourier
# transform: harmonic k is multiplied by W(k) = sum_j w_j exp(-2 pi i jk/12).
# Where W(k) = 0 the information in harmonic k is lost.
# Part 2: the flowing month. With year branch Y, birth month m, birth hour
# h, one common rule puts the first month's palace ("dou jun") at
# Y - (m - 1) + h and month k a further k - 1 palaces on, so the month-k
# palace is [Y - (m - 1) + h] + (k - 1) = Y - m + h + k (mod 12).
# With the natal Life palace L = 1 + m - h (p10)
# this gives month palace + L = Y + k + 1 (mod 12), checked for all
# 12^4 combinations.
import cmath
def spectrum(w):
out = []
for k in range(7):
z = sum(w.get(j, 0.0) * cmath.exp(-2j * cmath.pi * j * k / 12)
for j in range(12))
out.append(abs(z))
return out
if __name__ == "__main__":
kernels = {"self 1, opposite 0.8, trines 0.5": {0: 1, 6: 0.8, 4: 0.5,
8: 0.5},
"self and trines only, equal": {0: 1, 4: 1, 8: 1},
"self and opposite only, equal": {0: 1, 6: 1}}
print(" kernel |W(k)| for k = 0 .. 6")
for name, w in kernels.items():
sp = spectrum(w)
lost = sum((1 if k in (0, 6) else 2) for k, v in enumerate(sp)
if v < 1e-9)
print(" {:34s} ".format(name) + " ".join("{:4.2f}".format(v)
for v in sp))
print(" {:34s} harmonics lost: {} of 12".format("", lost))
ok = all((y - m + h + k) % 12 == (y + k + 1 - (1 + m - h)) % 12
for y in range(12) for m in range(1, 13)
for h in range(12) for k in range(1, 13))
print("\n month palace + natal Life palace = Y + k + 1 (mod 12) in"
" all cases: {}".format(ok))
print("\nReading: weighting the triangle equally keeps only the")
print("harmonics that are multiples of 3 - two thirds of the pattern")
print("around the circle cannot be seen at all. Adding the opposite")
print("palace with a different weight restores every harmonic. The")
print("flowing-month palace is the natal Life palace reflected (L to")
print("-L) and shifted by the year and the month.")
# kernel |W(k)| for k = 0 .. 6
# self 1, opposite 0.8, trines 0.5 2.80 0.30 1.30 1.20 1.30 0.30 2.80
# harmonics lost: 0 of 12
# self and trines only, equal 3.00 0.00 0.00 3.00 0.00 0.00 3.00
# harmonics lost: 8 of 12
# self and opposite only, equal 2.00 0.00 2.00 0.00 2.00 0.00 2.00
# harmonics lost: 6 of 12
#
# month palace + natal Life palace = Y + k + 1 (mod 12) in all cases: True
#
# Reading: weighting the triangle equally keeps only the
# harmonics that are multiples of 3 - two thirds of the pattern
# around the circle cannot be seen at all. Adding the opposite
# palace with a different weight restores every harmonic. The
# flowing-month palace is the natal Life palace reflected (L to
# -L) and shifted by the year and the month.The spectrum of the first weighting (palace 1, opposite 0.8, trines 0.5 each) is nonzero at every harmonic: nothing is lost. The palace and trines with equal weights keep only the harmonics and lose 8 of the 12 — two thirds of the patterns of variation around the palaces are simply invisible in the combined score. The palace and its opposite with equal weights lose 6. As soon as the opposite palace is weighted differently from the trines, every harmonic returns.
The last line of the program checks the rule for flowing months. One common way of starting the flowing months (the “dou jun”) is: take the palace of the flowing year’s branch as the year’s Life palace, count backward from it to the birth month and then forward to the birth hour to find the first month, and continue forward from there. The first month then sits at and month a further palaces on, so the flowing-month Life palace of month is , and together with the natal Life palace it satisfies — the month palace is the natal Life palace reflected () and shifted by year and month. Schools differ in how they start the flowing months; this book uses the rule above, and the program verifies it.
A matter-by-matter scoring algorithm
A quantitative scoring algorithm for “seeking wealth, asking about marriage, going to law, travelling” can be written: find the flowing-month Life palace, find the palace belonging to the matter (Wealth for seeking wealth), and add the star values over its three sides and four squares by the convolution. The algorithm itself is exact; what is not exact is its input — the value of each star. The thirteenth program compares two defensible sets of values: A, a general good-and-bad scale, and B, a scale weighted towards money (Wu Qu and Tan Lang raised, Qi Sha and Po Jun softened, Tian Tong lowered).
Calculation
# Chapter 6. A numerical score for "seeking wealth this month" - and how
# much it depends on the conventions put into it.
# The score of a matter is a weighted sum of star values over the "three
# sides and four squares" of the matter's palace (kernel of p12: self 1,
# opposite 0.8, trines 0.5). For wealth the matter's palace is the Wealth
# palace, four places back from the flowing-month Life palace. Star
# values are a convention. Two plausible conventions are compared:
# A a general good/bad scale
# B a wealth-specific scale (Wu Qu and Tan Lang raised, Qi Sha and
# Po Jun softened, Tian Tong lowered)
# Over all 12 main-star layouts (p11) x 12 flowing-month Life palaces,
# the program scores the 144 cases under each convention and reports
# their Spearman rank correlation, the share of pairs of cases the two
# conventions order differently, and the overlap of their top 10 cases.
import math
from itertools import combinations
ZI = {"Zi Wei": 0, "Tian Ji": -1, "Tai Yang": -3, "Wu Qu": -4,
"Tian Tong": -5, "Lian Zhen": -8}
FU = {"Tian Fu": 0, "Tai Yin": 1, "Tan Lang": 2, "Ju Men": 3,
"Tian Xiang": 4, "Tian Liang": 5, "Qi Sha": 6, "Po Jun": 10}
A = {"Zi Wei": 2, "Tian Fu": 2, "Tai Yang": 1, "Tai Yin": 1,
"Tian Tong": 1, "Tian Liang": 1, "Tian Xiang": 1, "Wu Qu": 1,
"Tian Ji": 0.5, "Tan Lang": 0, "Lian Zhen": -0.5, "Ju Men": -1,
"Qi Sha": -1, "Po Jun": -1}
B = dict(A, **{"Wu Qu": 2, "Tan Lang": 1, "Qi Sha": 0, "Po Jun": -0.5,
"Tian Tong": 0})
KERNEL = {0: 1.0, 6: 0.8, 4: 0.5, 8: 0.5}
def layout(z):
f = (4 - z) % 12
out = {s: (z + o) % 12 for s, o in ZI.items()}
out.update({s: (f + o) % 12 for s, o in FU.items()})
return out
def score(z, life, values):
stars = layout(z)
wealth = (life - 4) % 12
# rounded, so that equal scores compare equal whatever the order of
# the terms
terms = [KERNEL[off] * values[s] for s, pos in stars.items()
for off in KERNEL if pos == (wealth + off) % 12]
return round(math.fsum(terms), 9)
def ranks(xs):
order = sorted(range(len(xs)), key=lambda i: xs[i])
r = [0.0] * len(xs)
i = 0
while i < len(order):
j = i
while j + 1 < len(order) and xs[order[j + 1]] == xs[order[i]]:
j += 1
for k in range(i, j + 1):
r[order[k]] = (i + j) / 2 + 1
i = j + 1
return r
def pearson(x, y):
n = len(x)
mx, my = math.fsum(x) / n, math.fsum(y) / n
sxy = math.fsum((a - mx) * (b - my) for a, b in zip(x, y))
sxx = math.fsum((a - mx) ** 2 for a in x)
syy = math.fsum((b - my) ** 2 for b in y)
return sxy / (sxx * syy) ** 0.5
if __name__ == "__main__":
cases = [(z, life) for z in range(12) for life in range(12)]
sa = [score(z, l, A) for z, l in cases]
sb = [score(z, l, B) for z, l in cases]
rho = pearson(ranks(sa), ranks(sb))
disagree = sum(1 for i, j in combinations(range(len(cases)), 2)
if (sa[i] - sa[j]) * (sb[i] - sb[j]) < 0)
pairs = len(cases) * (len(cases) - 1) // 2
top_a = set(sorted(range(len(cases)), key=lambda i: -sa[i])[:10])
top_b = set(sorted(range(len(cases)), key=lambda i: -sb[i])[:10])
print(" cases scored: {}; distinct scores A {}, B {}".format(
len(cases), len(set(sa)), len(set(sb))))
print(" Spearman rank correlation A vs B: {:.3f}".format(rho))
print(" pairs of cases ordered oppositely: {:.3f}".format(
disagree / pairs))
print(" top-10 cases shared: {} of 10".format(len(top_a & top_b)))
print("\nReading: two conventions that a practitioner could defend")
print("agree broadly but not in detail: they order a sizeable share of")
print("pairs of months oppositely and share only part of their 'best")
print("months'. A score is exactly as definite as its conventions.")
# cases scored: 144; distinct scores A 43, B 41
# Spearman rank correlation A vs B: 0.606
# pairs of cases ordered oppositely: 0.264
# top-10 cases shared: 6 of 10
#
# Reading: two conventions that a practitioner could defend
# agree broadly but not in detail: they order a sizeable share of
# pairs of months oppositely and share only part of their 'best
# months'. A score is exactly as definite as its conventions.Across the 144 cases formed by the 12 main-star layouts and 12 flowing-month Life palaces, the two sets of values rank the cases with a rank correlation of only 0.606; 0.264 of the pairs of cases are put in opposite order by the two; and their “ten best months” share only 6. Both sets of values have reasons behind them, yet they give quite different answers to “which month is best for seeking wealth”.
Note
What this means for “quantitative scores by flowing month and day”. Convolution and harmonic analysis explain the structure of a scoring algorithm, but the meaning of the score comes entirely from two sets of conventions: the star values and the aggregation weights. A scoring system should publish its values and weights and say how much its results change under another reasonable set; otherwise the precision of its scores is only on the surface. The test in Chapter 8 requires these conventions to be fixed before any result is seen.
Summary
Aggregating “three sides and four squares” is a circular convolution on , diagonalised by the discrete Fourier transform. The equal-weighted trine triangle is a sum over the subgroup of order 3 and loses 8 of the 12 harmonics; adding the opposite palace with a different weight keeps all the information. The flowing-month Life palace is the natal Life palace reflected and shifted. A matter-by-matter scoring algorithm is exact in structure, but its results depend on the star values: two defensible sets rank the cases with a rank correlation of only 0.606 and share only 6 of their best months.
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).