What does Taiyi Congruence Cycles and Game Bounds conclude, in numbers, about “Random-Permutation Tests on a Chronicle of Calamities: Why Fitting after the Fact Almost Always Succeeds”?

Answer: Chapter 6 runs random-permutation tests on a synthetic chronicle: the most "significant" configuration has a family-wise p of 0.501, and once the choice of convention and tolerance is counted, the chance that some path is nominally significant is 0.867.

Scope of the numbers: Its parameters are illustrative; all calculations are generated by its programs; its chronicle of calamities is synthetic data generated with a fixed seed. Chapter 6 runs random-permutation tests on a synthetic chronicle: the most "significant" configuration has a family-wise p of 0.501, and once the choice of convention and tolerance is counted, the chance that some path is nominally significant is 0.867.

中文版

Data table

The numbers below are printed verbatim by the chapter's Python program and can be reproduced by running it. standard-library Python onlyprinted values that match the answer: 0.501

years 1100, calamity years 224, base rate 0.204
conditions searched73
best: 'Taiyi 8'39 of 138 years, rate 0.283
nominal one-sided p0.0165
Bonferroni p1.000
conditions with nominal p < 0.053
permutation family-wise p (1000 relabellings)0.501
Show the full program
# Chapter 6. p61: a random-permutation test of an after-the-fact fit.
# The chronicle is synthetic: each year 1000-2099 is marked as a
# "calamity year" with probability 0.2 (seeded), independent of every
# god. We then search all single-feature conditions (convention C) for
# the one whose years carry the most calamities, and judge that best
# fit against 1000 random relabellings of the same chronicle.
import math
import random

# Ring of sixteen gods, clockwise from zi; ring slots that are palaces
# carry the Taiyi palace number (Jinjing vol. 2 example: from Dayi (hai)
# 1, Dizhu (zi) 8, Hede (gen) 3, Gaocong (mao) 4, total 16 before xun 9).
RING = ("zi", "chou", "gen", "yin", "mao", "chen", "xun", "si",
        "wu", "wei", "kun", "shen", "you", "xu", "qian", "hai")
PAL = {0: 8, 2: 3, 4: 4, 6: 9, 8: 2, 10: 7, 12: 6, 14: 1}
POS = {p: k for k, p in PAL.items()}
TY_ORDER = (1, 2, 3, 4, 6, 7, 8, 9)          # skips the centre 5
# Wenchang starts at Wude (shen) and walks clockwise; qian and kun each
# hold it two years, so one circuit of 16 gods takes 18 years.
WC_SEQ = (11, 12, 13, 14, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10)
BR_POS = (0, 1, 3, 4, 5, 7, 8, 9, 11, 12, 13, 15)   # 12 branches on ring


def taiyi(j):
    r = j % 360 % 72 % 24 or 24
    return TY_ORDER[(r - 1) // 3]


def wenchang(j):
    r = j % 360 % 72 % 18 or 18
    return WC_SEQ[r - 1]


def jishen(j):
    r = j % 60 or 60                     # from yin, counter-clockwise
    return BR_POS[(2 - (r - 1)) % 12]


def shiji(j):
    # Jishen laid on Hede (gen, slot 2); read where Wenchang falls
    return (wenchang(j) + 2 - jishen(j)) % 16


def count(start, ty):
    stop = POS[ty]
    k, tot = start, PAL.get(start, 1)
    if k == stop:
        return tot
    k = (k + 1) % 16
    while k != stop:
        tot += PAL.get(k, 0)
        k = (k + 1) % 16
    return tot


def host(j):
    return count(wenchang(j), taiyi(j))


def guest(j):
    return count(shiji(j), taiyi(j))


def general(s):
    # counts reduce by their units: 24 sets 4; 10 sets 1 (vol. 2)
    r = s % 10
    return r if r else (s // 10) % 10 or 1


def patterns(j):
    t = POS[taiyi(j)]
    w, g = wenchang(j), shiji(j)
    hg, gg = general(host(j)), general(guest(j))

    def near(a):
        return min((a - t) % 16, (t - a) % 16) in (1, 2)
    return {"yan": g == t, "po": near(w), "ji": near(g),
            "qiu": taiyi(j) in (hg, gg), "guan": hg == gg,
            "ge": gg + taiyi(j) == 10}


WUFU = (1, 3, 9, 7, 5)
DAYOU = (7, 8, 9, 1, 2, 3, 4, 6)
YEARS = list(range(1000, 2100))


def conditions(off):
    # every single-feature condition as a bitmask over YEARS
    masks = {}

    def put(name, i):
        masks[name] = masks.get(name, 0) | (1 << i)
    for i, y in enumerate(YEARS):
        j = y + off
        put("Taiyi {}".format(taiyi(j)), i)
        put("Wenchang {}".format(RING[wenchang(j)]), i)
        put("Shiji {}".format(RING[shiji(j)]), i)
        put("Jishen {}".format(RING[jishen(j)]), i)
        put("Wufu {}".format(WUFU[j % 225 // 45]), i)
        put("Dayou {}".format(DAYOU[j % 288 // 36]), i)
        for k, v in sorted(patterns(j).items()):
            if v:
                put("pattern " + k, i)
        if host(j) > guest(j):
            put("host longer", i)
        if host(j) >= 10:
            put("host >= 10", i)
    return masks


def tail(n, k, p):
    # P(X >= k) for Binomial(n, p)
    return math.fsum(math.comb(n, i) * p ** i * (1 - p) ** (n - i)
                     for i in range(k, n + 1))


def best(lab, masks, tabs):
    out = (2.0, "")
    for name in sorted(masks):
        m = masks[name]
        pv = tabs[name][(lab & m).bit_count()]
        if pv < out[0]:
            out = (pv, name)
    return out


if __name__ == "__main__":
    rng = random.Random(20261112)
    n = len(YEARS)
    flags = [rng.random() < 0.2 for _ in YEARS]
    lab = 0
    for i, f in enumerate(flags):
        lab |= f << i
    k_all = lab.bit_count()
    p0 = k_all / n
    masks = conditions(10153917)
    tabs = {}
    for name, m in masks.items():
        c = m.bit_count()
        tabs[name] = [tail(c, k, p0) for k in range(c + 1)]
    pv, name = best(lab, masks, tabs)
    m = masks[name]
    print(" years {}, calamity years {}, base rate {:.3f}".format(
        n, k_all, p0))
    print(" conditions searched: {}".format(len(masks)))
    print(" best: '{}': {} of {} years, rate {:.3f}".format(
        name, (lab & m).bit_count(), m.bit_count(),
        (lab & m).bit_count() / m.bit_count()))
    print(" nominal one-sided p = {:.4f}".format(pv))
    print(" Bonferroni p = {:.3f}".format(min(1.0, pv * len(masks))))
    nom = len([x for x in masks if tabs[x][(lab & masks[x]).bit_count()]
               < 0.05])
    print(" conditions with nominal p < 0.05: {}".format(nom))
    ge = 0
    idx = list(range(n))
    for _ in range(1000):
        rng.shuffle(idx)
        perm = 0
        for i in range(n):
            if flags[idx[i]]:
                perm |= 1 << i
        if best(perm, masks, tabs)[0] <= pv:
            ge += 1
    print(" permutation family-wise p (1000 relabellings) = {:.3f}"
          .format(ge / 1000))

Single source and citation

Fan, Y. (2026). Taiyi Shenshu: Sixteen-Palace Walks, Accumulated-Year Congruence Cycles and the Game Bounds of Host and Guest Counting Rods (Version 1.0.0), Chapter 6: Random-Permutation Tests on a Chronicle of Calamities: Why Fitting after the Fact Almost Always Succeeds. 5D Library. DOI pending

DOI pending · monograph page goes live after publication · 5DL-B-154 · v1.0.0 · CC-BY-NC-ND-4.0

BibTeX
@book{fan2026154,
  author    = {Fan, Yafu},
  title     = {Taiyi Shenshu: Sixteen-Palace Walks, Accumulated-Year Congruence Cycles and the Game Bounds of Host and Guest Counting Rods},
  year      = {2026},
  publisher = {5D Library},
  edition   = {1.0.0},
  note      = {DOI pending}
}

Other chapter answers in this book