What does Cache Hit Ratios and the Che Approximation conclude, in numbers, about “Eastern and Western Classics: the Nine-Year Reserve of the Royal Regulations and Belady's Optimal Replacement”?

Answer: Chapter 7 examines "a state without a reserve of nine years is said to be short" from the Royal Regulations of the Book of Rites alongside Belady's optimal replacement of 1966, uses a granary model to show that spoilage decides whether a nine-year reserve is reachable, and confirms optimal replacement by exhaustive search.

Scope of the numbers: Under Zipf requests the hit ratio of a least-recently-used (LRU) cache grows slowly with capacity: with illustrative parameters, a hundred-and-twenty-eight-fold increase in capacity raises the hit ratio only 6.80 times. Chapter 4 derives the optimal capacity from slope and cost, 4187 slots or 0.2094 of the catalogue under illustrative parameters, with a flat cost curve around the optimum.

中文版

Data table

The numbers below are printed verbatim by the chapter's Python program and can be reproduced by running it. standard-library Python only

Reserve cap S (years of need) vs shortage, 30-year horizon
spoilSP(any shortage)shortage yrsspoilage/yr
0.0200.99294.5020.0000
0.0210.66901.4470.0154
0.0230.08910.1570.0498
0.0260.00880.0170.1003
0.0290.00690.0140.1265
0.0500.99294.5020.0000
0.0510.75241.7330.0379
0.0530.15930.2910.1131
0.0560.08270.1510.1621
0.0590.08270.1510.1622
ceiling surplus / spoilage at s = 0.02: 16.67 years
ceiling surplus / spoilage at s = 0.05: 6.67 years
Show the full program
# Chapter 7. p71: the Wangzhi reserve rule as a testable stock model.
# Model: a state eats 1 unit of grain a year. A normal harvest yields
# 4/3 (the text's "three years of farming leave one year of food"), a
# bad year (probability 0.15) yields 1/5. Stored grain loses a share s
# each year to spoilage, and the granary holds at most S years. After
# 60 unscored years that let the stock settle, a 30-year horizon (the
# text's "thirty-year average") is scored: we count years in which
# stock plus harvest cannot cover need. 20000 seeded histories per
# cell. Yields, bad-year odds and spoilage are illustrative.
import math
import random

GOOD, BAD, PBAD, BURN, YEARS, TRIALS = 4 / 3, 1 / 5, 0.15, 60, 30, 20000


def history(rng, cap, spoil):
    stock, short, lost = 0.0, 0, []
    for y in range(BURN + YEARS):
        crop = BAD if rng.random() < PBAD else GOOD
        if y >= BURN:
            lost.append(stock * spoil)
        stock = stock * (1 - spoil) + crop - 1.0
        if stock < 0:
            if y >= BURN:
                short += 1
            stock = 0.0
        stock = min(stock, cap)
    return short, math.fsum(lost) / YEARS


if __name__ == "__main__":
    print("Reserve cap S (years of need) vs shortage, 30-year horizon")
    print("  spoil    S   P(any shortage)   shortage yrs   spoilage/yr")
    for spoil in (0.02, 0.05):
        for cap in (0, 1, 3, 6, 9):
            rng = random.Random(20261113)
            any_s, yrs, loss = 0, [], []
            for _ in range(TRIALS):
                s, l = history(rng, cap, spoil)
                if s:
                    any_s += 1
                yrs.append(s)
                loss.append(l)
            print("  {:.2f}   {:2d}       {:.4f}          {:.3f}"
                  "          {:.4f}".format(
                      spoil, cap, any_s / TRIALS,
                      math.fsum(yrs) / TRIALS, math.fsum(loss) / TRIALS))
    for spoil in (0.02, 0.05):
        print("ceiling surplus / spoilage at s = {:.2f}: {:.2f} years"
              .format(spoil, (GOOD - 1) / spoil))

Single source and citation

Fan, Y. (2026). Cache Hit Ratios and the Che Approximation: Optimal Capacity for Caching Computed Charts (Version 1.0.0), Chapter 7: Eastern and Western Classics: the Nine-Year Reserve of the Royal Regulations and Belady's Optimal Replacement. 5D Library. DOI pending

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

BibTeX
@book{fan2026327,
  author    = {Fan, Yafu},
  title     = {Cache Hit Ratios and the Che Approximation: Optimal Capacity for Caching Computed Charts},
  year      = {2026},
  publisher = {5D Library},
  edition   = {1.0.0},
  note      = {DOI pending}
}

Other chapter answers in this book