What does The Algebra of Check Digits conclude, in numbers, about “Verhoeff's Algorithm Dissected: Positions, Twins, Jumps and the Errors with No Name”?
Answer: Chapter 5 adds the nameless errors: moving from Luhn to Verhoeff lowers whole-spectrum misses from 207.2 to 107.1, roughly half, and two MOD 97-10 characters reach 6.8.
Scope of the numbers: Entry volumes, error rates and costs are illustrative; all calculations are generated by the book's programs; the book is not individual business advice. Marked boxes separate published evidence, runnable Python calculations (19 programs), classical sources and the author's hypotheses.
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: -10, 107.1, 207.2, 6.8, 97
| scheme named other total (misses per 10,000 errors) | |||
| Luhn | 117.4 | 89.8 | 207.2 |
| EAN 1,3 | 204.6 | 89.7 | 294.3 |
| ISBN-10 mod 11 | 11.6 | 79.3 | 90.8 |
| Verhoeff | 18.3 | 88.8 | 107.1 |
| Damm | 17.0 | 89.0 | 106.0 |
| MOD 97-10 | 0.0 | 6.8 | 6.8 |
| a single check digit lets about 1 in 10 random changes through; | |||
| two MOD 97-10 digits let about 1 in 97 through | |||
Show the full program
# Chapter 5. p52: the whole spectrum, including the errors with no name.
# The six named classes are scored exactly (as in p12). The other 1,041
# of Verhoeff's 12,112 errors (other adjacent, other jump, other two-
# digit, three to six digits) have no fixed pattern, so they are drawn
# at random: a random 10-digit string, the stated number of positions
# (inside a window of six, as in a six-digit number) each replaced by a
# different random digit; draws that fall into a named class are thrown
# back. A damaged string passes iff its final state equals the intact
# one, so validity of the random string does not matter. Fixed seed;
# 6,000 draws per class and scheme. Output: misses per 10,000 errors.
import math
import random
rng = random.Random(20261113)
L = 10
NAMED = {"single": 9574, "adj": 1237, "twin": 67, "phon": 59,
"jump": 99, "jtwin": 35}
OTHER = [("other adjacent", 232, "adj2"), ("other jump", 43, "jmp2"),
("other two-digit", 98, "far2"), ("three digits", 169, 3),
("four digits", 118, 4), ("five digits", 219, 5),
("six digits", 162, 6)]
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]
P = [list(range(10))]
for _ in range(7):
P.append([SIGMA[x] for x in P[-1]])
def d5(i, j):
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
def dbl(d):
return 2 * d if d < 5 else 2 * d - 9
def st_lin(m, g):
def f(digs):
s = 0
for k, d in enumerate(reversed(digs)):
s = (s + g(k, d)) % m
return s
return f
def st_ver(digs):
c = 0
for k, d in enumerate(reversed(digs)):
c = d5(c, P[k % 8][d])
return c
def st_damm(digs):
c = 0
for d in digs:
c = T[c][d]
return c
SCHEMES = [
("Luhn", st_lin(10, lambda k, d: dbl(d) if k % 2 else d)),
("EAN 1,3", st_lin(10, lambda k, d: d * (3 if k % 2 else 1))),
("ISBN-10 mod 11", st_lin(11, lambda k, d: d * (k + 1))),
("Verhoeff", st_ver),
("Damm", st_damm),
("MOD 97-10", st_lin(97, lambda k, d: d * pow(10, k, 97))),
]
def named_pattern(o, e):
# 两位改动是否落入已命名的类(换位、孪生、读音)
(a, b), (c, d) = o, e
if (c, d) == (b, a) or (a == b and c == d):
return True
return (a, b, c, d) in PHON
PHON = {(a, 0, 1, a) for a in range(2, 10)}
PHON |= {(1, a, a, 0) for a in range(2, 10)}
def damage(body, kind):
b = body[:]
w = rng.randrange(L - 5)
if kind == "adj2":
pos = [w, w + 1]
elif kind == "jmp2":
pos = [w, w + 2]
elif kind == "far2":
i = rng.randrange(3)
pos = [w + i, w + i + rng.randrange(3, 6 - i)]
else:
pos = rng.sample(range(w, w + 6), kind)
for p in pos:
b[p] = (b[p] + rng.randrange(1, 10)) % 10
if kind in ("adj2", "jmp2"):
o = (body[pos[0]], body[pos[1]])
e = (b[pos[0]], b[pos[1]])
if named_pattern(o, e) and not (kind == "jmp2" and o + e in PHON):
return None
return b
def exact(state):
r = range(10)
pats = {"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]}
out = []
for name, pairs in pats.items():
n = len(pairs[0][0])
miss = tot = 0
for k0 in range(L - n + 1):
for pre in range(10):
for o, e in pairs:
tot += 1
head = [0] * (L - n - k0 - 1) + [pre]
if k0 == L - n:
head = []
x = head + list(o) + [0] * k0
y = head + list(e) + [0] * k0
if state(x) == state(y):
miss += 1
out.append(NAMED[name] * miss / tot)
return math.fsum(out)
print("scheme named other total (misses per 10,000 errors)")
for name, state in SCHEMES:
named = exact(state)
other = []
for _, cnt, kind in OTHER:
miss = tot = 0
while tot < 6000:
body = [rng.randrange(10) for _ in range(L)]
bad = damage(body, kind)
if bad is None:
continue
tot += 1
if state(bad) == state(body):
miss += 1
other.append(cnt * miss / tot)
o = math.fsum(other)
print("%-15s %6.1f %6.1f %6.1f" % (name, named / TOTAL * 1e4,
o / TOTAL * 1e4,
(named + o) / TOTAL * 1e4))
print("a single check digit lets about 1 in 10 random changes through;")
print("two MOD 97-10 digits let about 1 in 97 through")Single source and citation
Fan, Y. (2026). 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 (Version 1.0.0), Chapter 5: Verhoeff's Algorithm Dissected: Positions, Twins, Jumps and the Errors with No Name. 5D Library. DOI pending
DOI pending · monograph page goes live after publication · 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}
}Other chapter answers in this book
- Chapter 1 · The Spectrum of Slips: Two Classes in Twelve Thousand Errors
- Chapter 2 · Luhn's Doubling: Why Mod 10 Misses 09 and 90
- Chapter 3 · Prime Moduli and Weights: The X of ISBN-10 and the Blind Spot of EAN-13
- Chapter 4 · The Symmetries of a Pentagon: The Dihedral Group D5 and Anti-Symmetric Permutations
- Chapter 6 · Order Numbers, Remittance References and Internal Book Numbers: A Month's Accounts
- Chapter 7 · Classics East and West: Ritual Bronzes, Red Tablets and Gauss's Congruences
- Chapter 8 · Closing the Loop: An Order Desk Procedure, the Order Check-Digit Generator and a Pre-Registered Test