5D Library › 黄历择吉布尔格、建除十二直同余与卢恩符文组合学 · English
第一章 黄历规则的布尔谓词与消失的纯吉日
每条规则都是日历上的谓词
通书(黄历)为每一天标注值神、黄黑道、星宿与各种神煞,有吉有凶。在数学家看来,每条规则都是定义在一年各天 上的布尔谓词 :真或假,由当天的干支、月建(在十二个「节」交替)与年支(在立春交替)算出。一组规则为每一天确定布尔格 中的一个点,「择日」就是在这个格里搜索。本章使用 2027 年的各天,节气时刻取日本国立天文台公布的数据并换算为北京时间 (国立天文台 暦計算室 2026),规则共七组:建除十二神(按常见口诀,其中六个为凶)、十二黄黑道神、岁破、月三煞、凶宿表(28 宿中 13 宿;这是模型用表,因为各家通书不同),以及与两个人出生年支的相冲。
推导
# Chapter 1. p01: Stacking almanac rules on the days of 2027.
# Each day of 2027 gets its stem-branch, month branch (changing at each
# "jie" solar term, Beijing time) and year branch (changing at Lichun).
# Seven rule sets mark a day bad: R1 the twelve officers (jian, man,
# ping, shou, bi, po bad), R2 the black-road gods, R3 the year breaker,
# R4 the month's three sha, R5 an unlucky lodge (13 of 28, a model list;
# lists differ between almanacs), R6 and R7 a clash with the birth-year
# branch of two people (born in zi and mao years). A "pure" day has no
# bad mark. The share of pure days is compared with the product of the
# single-rule shares, which assumes the rules are independent, and
# extrapolated to almanacs that add many more rules (8% of days each).
import datetime
OFFICERS = ("jian chu man ping ding zhi po wei cheng shou kai bi").split()
# the 12 "jie" of 2027, Beijing time (UTC+8), from NAOJ's 2027 table
JIE = ((1, 5, 22, 10), (2, 4, 9, 46), (3, 6, 3, 40), (4, 5, 8, 17),
(5, 6, 1, 25), (6, 6, 5, 26), (7, 7, 15, 37), (8, 8, 1, 27),
(9, 8, 4, 28), (10, 8, 20, 17), (11, 7, 23, 39), (12, 7, 16, 38))
D0 = datetime.date(2027, 1, 1) # geng-chen day, mansion Gui (22)
def days(offset_h=0):
"""One dict per day of 2027: stem, branch, month and year branch."""
jie = [datetime.datetime(2027, m, d, h, mi) +
datetime.timedelta(hours=offset_h) for m, d, h, mi in JIE]
out = []
for k in range(365):
day = D0 + datetime.timedelta(days=k)
n = sum(1 for j in jie if j.date() <= day) # jie passed
gz = (16 + k) % 60
out.append({"date": day, "gz": gz, "s": gz % 10, "b": gz % 12,
"M": n % 12, "Y": 6 if n < 2 else 7,
"mansion": (22 + k) % 28})
return out
GOOD_OFFICER = {1, 4, 5, 7, 8, 10} # chu ding zhi wei cheng kai
QINGLONG = {2: 0, 8: 0, 3: 2, 9: 2, 4: 4, 10: 4, 5: 6, 11: 6,
0: 8, 6: 8, 1: 10, 7: 10} # month branch -> Azure Dragon day
YELLOW = {0, 1, 4, 5, 7, 10} # the six "yellow road" gods
SANSHA = {8: (5, 6, 7), 0: (5, 6, 7), 4: (5, 6, 7),
2: (11, 0, 1), 6: (11, 0, 1), 10: (11, 0, 1),
5: (2, 3, 4), 9: (2, 3, 4), 1: (2, 3, 4),
11: (8, 9, 10), 3: (8, 9, 10), 7: (8, 9, 10)}
BAD_MANSION = {1, 2, 4, 8, 9, 10, 11, 14, 17, 19, 22, 23, 26} # model
TIANDE = {2: ("s", 3), 3: ("b", 8), 4: ("s", 8), 5: ("s", 7),
6: ("b", 11), 7: ("s", 0), 8: ("s", 9), 9: ("b", 2),
10: ("s", 2), 11: ("s", 1), 0: ("b", 5), 1: ("s", 6)}
YUEDE = {2: 2, 6: 2, 10: 2, 8: 8, 0: 8, 4: 8, 11: 0, 3: 0, 7: 0,
5: 6, 9: 6, 1: 6}
TIANSHE = {2: 14, 3: 14, 4: 14, 5: 30, 6: 30, 7: 30,
8: 44, 9: 44, 10: 44, 11: 0, 0: 0, 1: 0}
def officer(d):
return (d["b"] - d["M"]) % 12
def marks(d, births=(0, 3)):
"""Bad marks (rule sets R1..R7) and good marks of one day."""
bad = {
"R1 officer": officer(d) not in GOOD_OFFICER,
"R2 black road": (d["b"] - QINGLONG[d["M"]]) % 12 not in YELLOW,
"R3 year breaker": d["b"] == (d["Y"] + 6) % 12,
"R4 three sha": d["b"] in SANSHA[d["M"]],
"R5 mansion": d["mansion"] in BAD_MANSION,
"R6 clash A": d["b"] == (births[0] + 6) % 12,
"R7 clash B": d["b"] == (births[1] + 6) % 12,
}
kind, v = TIANDE[d["M"]]
good = {
"tian de": d[kind] == v,
"yue de": d["s"] == YUEDE[d["M"]],
"tian she": d["gz"] == TIANSHE[d["M"]],
}
return bad, good
if __name__ == "__main__":
ds = days()
names = list(marks(ds[0])[0])
alive = list(range(365))
indep = 1.0
print(" rule sets bad share pure days share if independent")
for k, name in enumerate(names, 1):
share = sum(1 for d in ds if marks(d)[0][name]) / 365
indep *= 1 - share
alive = [i for i in alive if not marks(ds[i])[0][name]]
print(" R1..R{} {:8.3f} {:8d} {:6.3f} {:8.3f}".format(
k, share, len(alive), len(alive) / 365, indep))
by_month = [0] * 12
for i in alive:
by_month[ds[i]["date"].month - 1] += 1
print(" pure days by month: {}".format(" ".join(map(str, by_month))))
base = len(alive) / 365
for m in (20, 40, 60):
print(" {} further rules marking 8% each: {:.4f} of days pure,"
" {:.1f} a year".format(m, base * 0.92 ** m,
365 * base * 0.92 ** m))
# rule sets bad share pure days share if independent
# R1..R1 0.488 187 0.512 0.512
# R1..R2 0.501 94 0.258 0.255
# R1..R3 0.082 84 0.230 0.234
# R1..R4 0.247 69 0.189 0.177
# R1..R5 0.466 38 0.104 0.094
# R1..R6 0.085 33 0.090 0.086
# R1..R7 0.082 33 0.090 0.079
# pure days by month: 2 3 2 4 2 0 5 4 2 6 2 1
# 20 further rules marking 8% each: 0.0171 of days pure, 6.2 a year
# 40 further rules marking 8% each: 0.0032 of days pure, 1.2 a year
# 60 further rules marking 8% each: 0.0006 of days pure, 0.2 a year只看建除,剩下 187 天(0.512)。加上黑道,剩下 94 天(0.258);加岁破 84 天,三煞 69 天,凶宿 38 天,两个人的冲日之后剩 33 天(0.090)。每加一组规则,纯吉日的比例大约乘以一减去新规则的比例,就像这些规则相互独立一样:实际比例(0.258、0.230、0.189、0.104)与独立乘积(0.255、0.234、0.177、0.094)相差不大。纯吉日的分布也不均匀:在这个例子中,2027 年 6 月一天也没有。真实的通书还列有几十种神煞。若再加 20 条规则、每条标凶 8% 的日子,只剩 0.0171 的日子是纯吉日,一年约 6.2 天;再加 40 条,一年 1.2 天;再加 60 条,0.2 天:大多数年份一天也没有。衰减随规则数呈指数。
两个流派,两种判定
不同的通书传统给规则不同的权重。下面,流派 A 按建除与黄道判定;流派 B 按星宿与三煞判定,但让「天德」或「月德」压过一切。
推导
# Chapter 1. p02: Two schools, one calendar. School A calls a day good
# when its officer is good and it falls on a yellow-road god. School B
# calls a day good when its lodge is not on the unlucky list and it is
# not a three-sha day, or whenever a tian de or yue de virtue falls on it
# (a virtue overrides). Both use only rules from p01 for 2027. Reported:
# how often they agree, Cohen's kappa (agreement beyond chance), and how
# many days one school calls good and the other bad.
import datetime
OFFICERS = ("jian chu man ping ding zhi po wei cheng shou kai bi").split()
# the 12 "jie" of 2027, Beijing time (UTC+8), from NAOJ's 2027 table
JIE = ((1, 5, 22, 10), (2, 4, 9, 46), (3, 6, 3, 40), (4, 5, 8, 17),
(5, 6, 1, 25), (6, 6, 5, 26), (7, 7, 15, 37), (8, 8, 1, 27),
(9, 8, 4, 28), (10, 8, 20, 17), (11, 7, 23, 39), (12, 7, 16, 38))
D0 = datetime.date(2027, 1, 1) # geng-chen day, mansion Gui (22)
def days(offset_h=0):
"""One dict per day of 2027: stem, branch, month and year branch."""
jie = [datetime.datetime(2027, m, d, h, mi) +
datetime.timedelta(hours=offset_h) for m, d, h, mi in JIE]
out = []
for k in range(365):
day = D0 + datetime.timedelta(days=k)
n = sum(1 for j in jie if j.date() <= day) # jie passed
gz = (16 + k) % 60
out.append({"date": day, "gz": gz, "s": gz % 10, "b": gz % 12,
"M": n % 12, "Y": 6 if n < 2 else 7,
"mansion": (22 + k) % 28})
return out
GOOD_OFFICER = {1, 4, 5, 7, 8, 10} # chu ding zhi wei cheng kai
QINGLONG = {2: 0, 8: 0, 3: 2, 9: 2, 4: 4, 10: 4, 5: 6, 11: 6,
0: 8, 6: 8, 1: 10, 7: 10} # month branch -> Azure Dragon day
YELLOW = {0, 1, 4, 5, 7, 10} # the six "yellow road" gods
SANSHA = {8: (5, 6, 7), 0: (5, 6, 7), 4: (5, 6, 7),
2: (11, 0, 1), 6: (11, 0, 1), 10: (11, 0, 1),
5: (2, 3, 4), 9: (2, 3, 4), 1: (2, 3, 4),
11: (8, 9, 10), 3: (8, 9, 10), 7: (8, 9, 10)}
BAD_MANSION = {1, 2, 4, 8, 9, 10, 11, 14, 17, 19, 22, 23, 26} # model
TIANDE = {2: ("s", 3), 3: ("b", 8), 4: ("s", 8), 5: ("s", 7),
6: ("b", 11), 7: ("s", 0), 8: ("s", 9), 9: ("b", 2),
10: ("s", 2), 11: ("s", 1), 0: ("b", 5), 1: ("s", 6)}
YUEDE = {2: 2, 6: 2, 10: 2, 8: 8, 0: 8, 4: 8, 11: 0, 3: 0, 7: 0,
5: 6, 9: 6, 1: 6}
TIANSHE = {2: 14, 3: 14, 4: 14, 5: 30, 6: 30, 7: 30,
8: 44, 9: 44, 10: 44, 11: 0, 0: 0, 1: 0}
def officer(d):
return (d["b"] - d["M"]) % 12
def marks(d, births=(0, 3)):
"""Bad marks (rule sets R1..R7) and good marks of one day."""
bad = {
"R1 officer": officer(d) not in GOOD_OFFICER,
"R2 black road": (d["b"] - QINGLONG[d["M"]]) % 12 not in YELLOW,
"R3 year breaker": d["b"] == (d["Y"] + 6) % 12,
"R4 three sha": d["b"] in SANSHA[d["M"]],
"R5 mansion": d["mansion"] in BAD_MANSION,
"R6 clash A": d["b"] == (births[0] + 6) % 12,
"R7 clash B": d["b"] == (births[1] + 6) % 12,
}
kind, v = TIANDE[d["M"]]
good = {
"tian de": d[kind] == v,
"yue de": d["s"] == YUEDE[d["M"]],
"tian she": d["gz"] == TIANSHE[d["M"]],
}
return bad, good
def school_a(d):
bad, _ = marks(d)
return not bad["R1 officer"] and not bad["R2 black road"]
def school_b(d):
bad, good = marks(d)
plain = not bad["R5 mansion"] and not bad["R4 three sha"]
return plain or good["tian de"] or good["yue de"]
if __name__ == "__main__":
ds = days()
a = [school_a(d) for d in ds]
b = [school_b(d) for d in ds]
n = len(ds)
agree = sum(1 for x, y in zip(a, b) if x == y) / n
pa, pb = sum(a) / n, sum(b) / n
chance = pa * pb + (1 - pa) * (1 - pb)
kappa = (agree - chance) / (1 - chance)
print(" good days: school A {}, school B {}".format(sum(a), sum(b)))
print(" agreement {:.3f}, chance agreement {:.3f}, kappa {:.3f}"
.format(agree, chance, kappa))
ab = sum(1 for x, y in zip(a, b) if x and not y)
ba = sum(1 for x, y in zip(a, b) if y and not x)
both = sum(1 for x, y in zip(a, b) if x and y)
print(" A good, B bad: {}; B good, A bad: {}; both good: {}".format(
ab, ba, both))
# good days: school A 94, school B 188
# agreement 0.518, chance agreement 0.493, kappa 0.050
# A good, B bad: 41; B good, A bad: 135; both good: 53流派 A 找到 94 个吉日,流派 B 找到 188 个。两者在 0.518 的日子上一致,而两个按同样比例随机挑日子的流派也会有 0.493 的一致;科恩 kappa(超出偶然的一致程度)(Cohen 1960) 只有 0.050。有 135 天 B 说吉而 A 说凶,41 天相反。两本由真实规则成分构成、只是选取的规则不同的通书,可以在将近半年里意见相左,而双方都没有算错。分歧来自规则的取舍与权重,这是任何计算都无法裁决的。
假说 · 尚未验证
作者的诠释(尚未验证): 不同出版者为同一年出版的通书,在「宜嫁娶」日上的一致程度 kappa 低于三分之一。什么会证明它错: 在同一年至少五本通书之间,嫁娶日的两两 kappa 达到三分之一或更高。
小结
每条通书规则都是一年各天上的布尔谓词。七组规则在 2027 年只留下 33 个纯吉日(0.090),纯吉日比例大致按单条规则比例的乘积下降,所以规则越多,比例越趋于零。由相同成分构成的两个流派,一致程度只比偶然略高(kappa 0.050)。
参考文献
Fan, Y. (2026). Almanac Auspicious Boolean Lattices, Jianchu Twelve-Officer Congruences and Runic Combinatorics: Constraint Satisfaction Paradoxes, Solar-Term Phase Jumps and Elder Futhark Inversion Distributions [黄历择吉布尔格、建除十二直同余与卢恩符文组合学] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090239 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).