5D Library › Almanac Auspicious Boolean Lattices, Jianchu Twelve-Officer Congruences and Runic Combinatorics · 中文

Chapter 1. Almanac Rules as Boolean Predicates, and the Vanishing Pure Day

Each rule is a predicate on the calendar

A Chinese almanac (tongshu, huangli) marks each day with officers, gods, lodges and spirits, some favourable and some not. To a mathematician each rule is a Boolean predicate Pi(t)P_i(t) on the days tt of a year: true or false, computed from the day’s stem and branch, the month branch (which changes at each of the twelve “jie” solar terms) and the year branch (which changes at Lichun). A set of rules defines a point in the Boolean lattice {0,1}m\{0,1\}^m for every day, and “choosing a day” is a search in that lattice. This chapter uses the days of 2027, with the solar terms as published by the National Astronomical Observatory of Japan converted to Beijing time (国立天文台 暦計算室 2026), and seven rule sets: the twelve officers (six of them unfavourable, following the common rhyme), the twelve yellow-road and black-road gods, the year breaker, the month’s three sha, an unfavourable list of lodges (13 of 28; a model list, since almanacs differ), and clashes with the birth-year branches of two people.

Calculation

# 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

The twelve officers alone leave 187 days (0.512). Adding the black-road gods leaves 94 (0.258), the year breaker 84, the three sha 69, the lodges 38, and the two personal clashes 33 days (0.090). Each step multiplies the pure share by roughly one minus the new rule’s share, as if the rules were independent: the actual shares (0.258, 0.230, 0.189, 0.104) stay close to the independent product (0.255, 0.234, 0.177, 0.094). Pure days are also uneven: in this example June 2027 has none. Real almanacs list dozens of further spirits. If 20 more rules each marked 8% of days, 0.0171 of days would remain pure, about 6.2 a year; with 40 more, 1.2 a year; with 60 more, 0.2: in most years, none. The decay is exponential in the number of rules.

Share of 2027 that stays free of every bad mark as rule sets are added, with the independent product (p01).

Two schools, two verdicts

Different almanac traditions weight the rules differently. Below, school A judges a day by its officer and its yellow-road god; school B by its lodge and the three sha, but lets a “heavenly virtue” or “monthly virtue” override everything.

Calculation

# 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

School A finds 94 good days, school B 188. They agree on 0.518 of days, while two schools choosing at random with the same shares would agree on 0.493; Cohen’s kappa, agreement beyond chance (Cohen 1960), is 0.050. On 135 days B says good and A says bad, on 41 the reverse. Two almanacs built from real rule components but different choices of which rules to count can disagree on almost half the year without either making an error of calculation. The disagreement comes from the selection and weighting of rules, which no calculation settles.

Hypothesis · not established

The author’s interpretation (not yet tested): published almanacs from different publishers for the same year agree on “good for weddings” days at a kappa below one third. What would show it wrong: across at least five almanacs for one year, pairwise kappa for wedding days is one third or higher.

Summary

Each almanac rule is a Boolean predicate on the days of the year. Seven rule sets leave 33 pure days in 2027 (0.090), and the pure share falls roughly as the product of the single-rule shares, so adding rules drives it towards zero. Two schools built from the same components agree only slightly beyond chance (kappa 0.050).

References

Cohen, Jacob. 1960. “A Coefficient of Agreement for Nominal Scales.” Educational and Psychological Measurement 20 (1): 37 to 46.
国立天文台 暦計算室. 2026. 令和 9 年(2027)暦要項:二十四節気および雑節. National Astronomical Observatory of Japan. https://eco.mtk.nao.ac.jp/koyomi/yoko/2027/rekiyou272.html.

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).