关于「抄错的谱:一万二千条错误里的两大类」,《校验码代数与韦尔霍夫算法》给出的定量结论是什么?

结论:第一章摆出错误谱与七种方案的穷举总账:按错误谱加权,有名字的错误每万条 Luhn 漏 117.4 条,韦尔霍夫漏 18.3 条。

数据口径:书中录入量、出错率与成本均为示意参数;全部计算由书中程序生成;本书是非个人化经营建议。 书中以标注框区分已发表的证据、可运行的 Python 计算(19 段程序)、原典与作者的假说。

English version

对照数据表

下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 117.4, 18.3

detection rate by class (10-digit codewords, exhaustive)
scheme single adj twin phon jump jtwin miss
plain sum mod 101.000 0.000 0.889 1.000 0.000 0.889 1112.4
Luhn mod 101.000 0.978 0.933 0.875 0.000 0.889 117.4
EAN-13 weights 1,31.000 0.889 0.889 1.000 0.000 0.889 204.6
ISBN-10 mod 111.000 1.000 0.889 0.889 1.000 1.000 11.6
Verhoeff D51.000 1.000 0.956 0.806 0.942 0.942 18.3
Damm quasigroup1.000 1.000 0.915 0.989 0.896 0.886 17.0
MOD 97-10, 2 digits1.000 1.000 1.000 1.000 1.000 1.000 0.0
miss = undetected per 10,000 recorded errors, six classes only
查看完整验算程序
# Chapter 1. p12: exhaustive detection rates of seven schemes, six classes.
# Codewords have 10 digits including the check digit(s). For every class
# of error, every position where it fits and every digit pattern, the
# program asks whether the scheme's state after the damaged block still
# equals the state after the intact block (equal state = undetected).
# Linear and group schemes cancel the rest of the codeword; for Damm's
# quasigroup the incoming interim digit is averaged over 0 to 9 (it is
# 0 when the block starts at the left end).
# "miss" weights the misses by Verhoeff's counts of the six classes and
# reports undetected errors per 10,000 recorded errors (all 12,112).
import math

L = 10
COUNTS = {"single": 9574, "adj": 1237, "twin": 67, "phon": 59,
          "jump": 99, "jtwin": 35}
TOTAL = 12112
DAMM = ["0317598642", "7092154863", "4206871359", "1750983426",
        "6123045978", "3674209581", "5869720134", "8945362017",
        "9438617205", "2581436790"]
T = [[int(ch) for ch in row] for row in DAMM]
SIGMA = [1, 5, 7, 6, 2, 8, 3, 0, 9, 4]


def d5(i, j):
    # 二面体群 D5:0-4 为旋转,5-9 为翻转
    if i < 5 and j < 5:
        return (i + j) % 5
    if i < 5:
        return 5 + (i + j) % 5
    if j < 5:
        return 5 + (i - j) % 5
    return (i - j) % 5


P = [list(range(10))]
for _ in range(7):
    P.append([SIGMA[x] for x in P[-1]])


def dbl(d):
    return 2 * d if d < 5 else 2 * d - 9


def linear(m, g):
    return (lambda s, k, d: (s + g(k, d)) % m), [0], "R"


SCHEMES = [
    ("plain sum mod 10", linear(10, lambda k, d: d)),
    ("Luhn mod 10", linear(10, lambda k, d: dbl(d) if k % 2 else d)),
    ("EAN-13 weights 1,3", linear(10, lambda k, d: d * (3 if k % 2
                                                         else 1))),
    ("ISBN-10 mod 11", linear(11, lambda k, d: d * (k + 1))),
    ("Verhoeff D5", ((lambda s, k, d: d5(s, P[k % 8][d])), [0], "R")),
    ("Damm quasigroup", ((lambda s, k, d: T[s][d]), list(range(10)),
                         "L")),
    ("MOD 97-10, 2 digits", linear(97, lambda k, d: d * pow(10, k, 97))),
]


def classes():
    r = range(10)
    return [
        ("single", [((a,), (b,)) for a in r for b in r if a != b]),
        ("adj", [((a, b), (b, a)) for a in r for b in r if a != b]),
        ("twin", [((a, a), (b, b)) for a in r for b in r if a != b]),
        ("phon", [((a, 0), (1, a)) for a in range(2, 10)]
         + [((1, a), (a, 0)) for a in range(2, 10)]),
        ("jump", [((a, c, b), (b, c, a)) for a in r for c in r
                  for b in r if a != b]),
        ("jtwin", [((a, c, a), (b, c, b)) for a in r for c in r
                   for b in r if a != b]),
    ]


def run(step, order, s, k0, digs):
    n = len(digs)
    seq = [(k0 + n - 1 - t, digs[t]) for t in range(n)]
    if order == "R":
        seq.reverse()
    for k, d in seq:
        s = step(s, k, d)
    return s


def rate(scheme, pairs):
    step, inits, order = scheme
    hit = tot = 0
    n = len(pairs[0][0])
    for k0 in range(L - n + 1):
        for o, e in pairs:
            starts = inits
            if order == "L" and k0 == L - n:
                starts = [0] * len(inits)
            for s in starts:
                tot += 1
                if run(step, order, s, k0, o) != run(step, order, s,
                                                     k0, e):
                    hit += 1
    return hit / tot


CL = classes()
print("detection rate by class (10-digit codewords, exhaustive)")
print("scheme               single  adj   twin  phon  jump jtwin miss")
for name, sc in SCHEMES:
    rs = [rate(sc, pairs) for _, pairs in CL]
    miss = math.fsum(COUNTS[c] * (1.0 - r)
                     for (c, _), r in zip(CL, rs)) / TOTAL * 10000
    print("%-20s " % name + " ".join("%5.3f" % r for r in rs)
          + " %5.1f" % miss)
print("miss = undetected per 10,000 recorded errors, six classes only")

唯一数据源与引用

范雅福(Fan, Y.). (2026). 《校验码代数与二面体群韦尔霍夫算法、订单号汇款码书号单字误抄与相邻换位检出率母典》第 1 章「抄错的谱:一万二千条错误里的两大类」(版本 1.0.0). 5D Library. DOI 待发布

DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 5DL-B-297 · v1.0.0 · CC-BY-NC-ND-4.0

BibTeX
@book{fan2026297,
  author    = {Fan, Yafu},
  title     = {The Algebra of Check Digits and Verhoeff's Dihedral-Group Code: Detection Rates for Single-Digit Slips and Adjacent Transpositions in Order, Remittance and Book Numbers},
  year      = {2026},
  publisher = {5D Library},
  edition   = {1.0.0},
  note      = {DOI pending}
}

本书其他章节结论