What does The Algebra of Check Digits conclude, in numbers, about “Luhn's Doubling: Why Mod 10 Misses 09 and 90”?
Answer: Chapter 2 opens up Luhn's doubling: it misses 09 and 90, but jump transpositions make up 0.696 of its misses.
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: 0.696, 09, 90
| digit d | 0 1 2 3 4 5 6 7 8 9 |
| dbl(d) | 0 2 4 6 8 1 3 5 7 9 |
| h = d-dbl(d) | 0 9 8 7 6 4 3 2 1 0 |
| g = d+dbl(d) | 0 3 6 9 2 6 9 2 5 8 |
| adjacent swaps unseen | 09>90 (2 of 90 ordered) |
| twin errors unseen | 22>55, 33>66, 44>77 (6 of 90 ordered) |
| test payload 1234509 | 12345096 ; slip 1234590 -> 12345906 ; same: True |
| test payload 7000022 | 70000229 ; slip 7000055 -> 70000559 ; same: True |
| jump swap 12345674 > 12543674 passes Luhn: True | |
| expected Luhn misses among 12112 errors | 142.2 |
| adjacent swap | 27.5 share 0.193 |
| twin | 4.5 share 0.031 |
| phonetic | 7.4 share 0.052 |
| jump swap | 99.0 share 0.696 |
| jump twin | 3.9 share 0.027 |
Show the full program
# Chapter 2. p21: why Luhn's doubling misses 09/90 and three twin pairs.
# Luhn (US patent 2,950,048): from the right, the check digit and every
# second digit count as they are; the others are doubled and, if the
# result exceeds 9, reduced by 9. The total must be 0 mod 10.
# An adjacent pair (a, b) is read as a + dbl(b) or dbl(a) + b; swapping
# it goes unseen when h(a) = h(b) with h(d) = d - dbl(d) mod 10.
# A twin aa > bb goes unseen when g(a) = g(b), g(d) = d + dbl(d) mod 10.
# The last block splits Luhn's expected misses among Verhoeff's 12,112
# errors (p11 counts) by class, on 10-digit codewords.
import math
def dbl(d):
return 2 * d if d < 5 else 2 * d - 9
def luhn_digit(payload):
# 校验位:右起第一位载荷数字加倍
s = 0
for i, ch in enumerate(reversed(payload)):
d = int(ch)
s += dbl(d) if i % 2 == 0 else d # step
return (10 - s % 10) % 10
def luhn_ok(code):
s = 0
for i, ch in enumerate(reversed(code)):
d = int(ch)
s += dbl(d) if i % 2 else d # step
return s % 10 == 0
R = range(10)
print("digit d " + " ".join("%d" % d for d in R))
print("dbl(d) " + " ".join("%d" % dbl(d) for d in R))
print("h = d-dbl(d) " + " ".join("%d" % ((d - dbl(d)) % 10) for d in R))
print("g = d+dbl(d) " + " ".join("%d" % ((d + dbl(d)) % 10) for d in R))
adj = ["%d%d>%d%d" % (a, b, b, a) for a in R for b in R
if a < b and (a - dbl(a)) % 10 == (b - dbl(b)) % 10]
twin = ["%d%d>%d%d" % (a, a, b, b) for a in R for b in R
if a < b and (a + dbl(a)) % 10 == (b + dbl(b)) % 10]
print("adjacent swaps unseen: %s (2 of 90 ordered)" % ", ".join(adj))
print("twin errors unseen: %s (6 of 90 ordered)" % ", ".join(twin))
# 测试号:明显的示意载荷,非任何真实卡号或账号
for p, q in (("1234509", "1234590"), ("7000022", "7000055")):
cp, cq = luhn_digit(p), luhn_digit(q)
print("test payload %s -> %s%d ; slip %s -> %s%d ; same: %s"
% (p, p, cp, q, q, cq, cp == cq))
code = "1234567" + str(luhn_digit("1234567"))
jump = code[:2] + code[4] + code[3] + code[2] + code[5:]
print("jump swap %s > %s passes Luhn: %s" % (code, jump, luhn_ok(jump)))
# 按类别拆分 Luhn 的漏检(十位码字,穷举位置)
PAT = {
"adjacent swap": (1237, [((a, b), (b, a)) for a in R for b in R
if a != b]),
"twin": (67, [((a, a), (b, b)) for a in R for b in R if a != b]),
"phonetic": (59, [((a, 0), (1, a)) for a in range(2, 10)]
+ [((1, a), (a, 0)) for a in range(2, 10)]),
"jump swap": (99, [((a, c, b), (b, c, a)) for a in R for c in R
for b in R if a != b]),
"jump twin": (35, [((a, c, a), (b, c, b)) for a in R for c in R
for b in R if a != b]),
}
def val(k0, digs):
n = len(digs)
t = [dbl(d) if (k0 + n - 1 - i) % 2 else d for i, d in enumerate(digs)]
return int(math.fsum(t)) % 10
lost = {}
for name, (cnt, pairs) in PAT.items():
n = len(pairs[0][0])
tot = miss = 0
for k0 in range(10 - n + 1):
for o, e in pairs:
tot += 1
miss += val(k0, o) == val(k0, e) # step
lost[name] = cnt * miss / tot
allmiss = math.fsum(lost.values())
print("expected Luhn misses among 12112 errors: %.1f" % allmiss)
for name, v in lost.items():
print(" %-14s %5.1f share %.3f" % (name, v, v / allmiss))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 2: Luhn's Doubling: Why Mod 10 Misses 09 and 90. 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 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 5 · Verhoeff's Algorithm Dissected: Positions, Twins, Jumps and the Errors with No Name
- 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