5D Library › Almanac Auspicious Boolean Lattices, Jianchu Twelve-Officer Congruences and Runic Combinatorics · 中文
Chapter 4. Satisfiability: When No Day Is Acceptable, and When Every Day Is Both
A request as a satisfiability problem
A person asking for “a good day for the wedding within the next month” poses a constraint satisfaction problem: find a day in a window such that no bad predicate holds. As rule sets are added, the problem can become unsatisfiable. The question is how often, for windows of a month and of a week.
Calculation
# Chapter 4. p07: Is there any acceptable day in the next 30 days?
# For every 30-day window starting on a day of 2027 (336 windows that
# end inside the year), count the days free of all bad marks of rule
# sets R1..Rk of p01, for k = 1 to 7, and the share of windows with no
# such day: the request "a pure day this month" is then unsatisfiable.
# The same with a 7-day window (a wedding someone wants next week).
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])
flags = [marks(d)[0] for d in ds]
print(" rules 30-day window: mean free days, none free "
"7-day: none free")
for k in range(1, 8):
ok = [not any(f[n] for n in names[:k]) for f in flags]
res = []
for w in (30, 7):
wins = [sum(ok[s:s + w]) for s in range(365 - w + 1)]
res.append((sum(wins) / len(wins),
sum(1 for x in wins if x == 0) / len(wins)))
print(" R1..R{} {:6.2f} {:.3f} {:.3f}"
.format(k, res[0][0], res[0][1], res[1][1]))
# rules 30-day window: mean free days, none free 7-day: none free
# R1..R1 15.23 0.000 0.000
# R1..R2 7.77 0.000 0.084
# R1..R3 6.98 0.021 0.164
# R1..R4 5.71 0.021 0.206
# R1..R5 3.29 0.033 0.440
# R1..R6 2.86 0.057 0.496
# R1..R7 2.86 0.057 0.496With the twelve officers alone, a 30-day window has 15.23 acceptable days on average and never none. With all seven rule sets, 2.86 on average, and 0.057 of 30-day windows contain no acceptable day at all. For a 7-day window, the situation is much worse: with the officers and the black-road gods, 0.084 of weeks have no acceptable day; with the lodges added, 0.440; with the two personal clashes, 0.496. A couple who want “a good day next week” under seven rule sets face even odds of an impossible request, and the almanac will have to relax a rule, which is a choice, not a calculation.
Days that are good and bad at once
The opposite problem is as common. Most days carry at least one favourable and at least one unfavourable mark, and the verdict depends on which mark is allowed to win.
Calculation
# Chapter 4. p08: Every day carries a good mark and a bad mark.
# Good marks: tian de, yue de, tian she, a good officer, a yellow-road
# god. Bad marks: rule sets R1..R5 of p01 (no personal clashes). A day
# whose marks point both ways can be called good or bad depending on
# which mark the reader lets win. Counted for 2027: days with only good
# marks, only bad marks, both, and neither.
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()
rows = {"only good": 0, "only bad": 0, "both": 0, "neither": 0}
virtue_bad = 0
for d in ds:
bad, good = marks(d)
g = any(good.values()) or not bad["R1 officer"] or \
not bad["R2 black road"]
b = any(v for k, v in bad.items() if k[:2] in
("R1", "R2", "R3", "R4", "R5"))
key = "both" if g and b else "only good" if g else \
"only bad" if b else "neither"
rows[key] += 1
if any(good.values()) and (bad["R3 year breaker"] or
bad["R4 three sha"]):
virtue_bad += 1
for k, v in rows.items():
print(" {:9s}: {:3d} days ({:.3f})".format(k, v, v / 365))
print(" a virtue (tian de, yue de, tian she) on a year-breaker or")
print(" three-sha day: {} days".format(virtue_bad))
# only good: 38 days (0.104)
# only bad : 75 days (0.205)
# both : 252 days (0.690)
# neither : 0 days (0.000)
# a virtue (tian de, yue de, tian she) on a year-breaker or
# three-sha day: 25 daysIn 2027, counting five good marks (heavenly virtue, monthly virtue, the day of heavenly pardon, a good officer, a yellow-road god) and five bad ones, only 38 days (0.104) carry good marks alone and 75 (0.205) bad marks alone; 252 days (0.690) carry both, and no day carries neither. On 25 days a virtue falls on a year-breaker or three-sha day, the classic case where schools differ on whether the virtue cancels the spirit. Seven tenths of the year are thus decided by the ranking of the rules, which Chapter 7 examines.
Hypothesis · not established
The author’s interpretation (not yet tested): professional day-choosers, given the same couple and the same week, choose different days in most cases when the week contains no day free of all their bad marks, and agree in most cases when it contains exactly one. What would show it wrong: agreement among professionals does not fall when the week contains no fully free day.
Summary
With seven rule sets, 0.057 of 30-day windows and 0.496 of 7-day windows contain no acceptable day. At the same time 0.690 of the year carries both good and bad marks. An almanac verdict is therefore mostly a decision about which rule wins, not a fact read off the calendar.
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).