5D Library › 六维超立方体游走、卦变马尔可夫链与模运算星宫晶格 · English
第六章 三方四正是十二宫环上的卷积
把「三方四正」写成卷积
判断一个宫位时,紫微斗数看的不只是本宫,还有它的对宫与两个三合宫——合称「三方四正」。若宫位 上星曜的数值记为 ,对本宫、对宫、三合宫分别赋予权重 ,则宫位 的综合分数是
这正是 上的循环卷积。循环卷积被离散傅里叶变换对角化:第 个谐波被乘以 。凡是 的谐波,其中的信息在综合分数里完全看不见。
推导
等权三合的零点。 若只取本宫与两个三合宫、权重相等,则 ,当 不是 3 的倍数时为零。也就是说,三合正三角形在 中是 3 阶子群 ,对它求和只能看见周期为 4 的模式。
推导
# 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.第一种权重(本宫 1、对宫 0.8、三合各 0.5)的谱在所有谐波上都不为零,没有丢失信息。等权的本宫加三合只保留 三个谐波,12 个谐波中丢失 8 个——宫位上三分之二的变化模式,在综合分数里根本看不见。等权的本宫加对宫丢失 6 个。只要对宫的权重与三合不同,全部谐波就都恢复了。
程序的最后一行检查流月的规则。一种常见的起流月方法(「斗君」)是:以流年地支 所在宫为流年命宫,从此逆数到生月、再顺数到生时为正月,此后顺排。这样正月在 ,第 月再顺数 宫,流月命宫为 ,与本命命宫 合起来满足 ——流月命宫是本命命宫的反射()再加上年与月的平移。各家起流月的方法不尽相同;本书采用上面这一种,程序验证的也是这一种。
一个按事项评分的算法
一个「求财、问婚、涉讼、出行」的定量评分算法,可以写成:确定流月命宫,找到事项对应的宫位(求财看财帛),在它的三方四正上把星曜的数值按卷积加起来。算法本身是精确的;不精确的是输入——每颗星的数值。第十三段程序比较两套都说得通的赋值:A 是一般的吉凶尺度,B 是偏重财务的尺度(提高武曲、贪狼,放宽七杀、破军,降低天同)。
推导
# 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.在 12 种主星排布与 12 个流月命宫组成的 144 种情形中,两套赋值的排序秩相关只有 0.606;0.264 的情形对被两套赋值排成相反的顺序;各自的「最佳十个月」只有 6 个重合。两套赋值都有理由,却对「哪个月求财最好」给出相当不同的答案。
注
对「流月流日定量评分」的含义。 卷积与谐波分析说明了评分算法的结构,但分数的意义完全来自星曜赋值与汇总权重这两组约定。一个评分系统应当公开它的赋值与权重,并说明换一套合理的约定后结果会变多少;否则分数的精确只是表面的。第八章的检验要求在看到任何结果之前固定这些约定。
小结
三方四正的汇总是 上的循环卷积,由离散傅里叶变换对角化。等权的三合正三角形是 3 阶子群上的求和,丢失 12 个谐波中的 8 个;加上权重不同的对宫后信息全部保留。流月命宫是本命命宫的反射加平移。一个按事项评分的算法在结构上是精确的,但它的结果取决于星曜赋值:两套都说得通的赋值,排序秩相关只有 0.606,最佳月份只有 6 个重合。
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).