关于「东西方原典考辨:《礼记·王制》的九年之蓄与贝拉迪的最优替换」,《缓存命中率与车氏近似》给出的定量结论是什么?

结论:第七章考辨《礼记·王制》「国无九年之蓄曰不足」与贝拉迪 1966 年的最优替换,用储粮模型显示损耗率决定九年之蓄能否达到,并以穷举证实最优替换。

数据口径:本书用标准库程序推翻这条直觉:在齐普夫请求下,最近最少使用(LRU)缓存的命中率随容量增长得很慢,示意参数下容量放大一百二十八倍,命中率只放大 6.80 倍;而车氏近似只凭请求概率与容量,就能事先算出 LRU 命中率,与逐条模拟的最大差距为 0.0013。 书中参数为示意;全部计算由书中程序生成;本书给出只读的容量建议,不访问任何服务器、不写任何配置;「排盘」仅作一种计算结果的名称,不做任何命理推断;属于非个人化经营建议。

English version

对照数据表

下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库

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
查看完整验算程序
# 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))

唯一数据源与引用

范雅福(Fan, Y.). (2026). 《缓存命中率与车氏近似、排盘结果缓存容量的最优边界母典》第 7 章「东西方原典考辨:《礼记·王制》的九年之蓄与贝拉迪的最优替换」(版本 1.0.0). 5D Library. DOI 待发布

DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 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}
}

本书其他章节结论