5D Library › 姓名笔画、生命灵数与手机号码的同余映射和分布论 · English
第六章 手机号码:模 80、异或与被压缩的号码
模 80 只读后四位
手机号码数理的通行做法是:取号码的后四位(有的书取后八位,有的取整个号码)除以 80,取余数,余数为 0 时记作 80,再查八十一数理表。三种做法看起来不同,其实完全相同。因为 ,号码中后四位以前的每一位都乘以 80 的倍数,对余数没有贡献。用中国剩余定理还可以说得更细:,号码模 5 的余数只由最后一位决定,模 16 的余数由后四位决定。
推导
# Chapter 6. Phone numbers modulo 80.
# The rule: divide the number (or its last four, or last eight, digits)
# by 80, take the remainder r (r = 0 counts as 80), and look r up in the
# 81-number list. Because 10 000 = 125 x 80, a number's remainder modulo
# 80 is decided by its last four digits alone, so all three versions of
# the rule agree. By the Chinese remainder theorem, 80 = 16 x 5: the last
# digit fixes the residue mod 5, the last four fix it mod 16.
import random
GOOD = {1, 3, 5, 6, 7, 8, 11, 13, 15, 16, 17, 18, 21, 23, 24, 25, 29,
31, 32, 33, 35, 37, 39, 41, 45, 47, 48, 52, 57, 61, 63, 65, 67,
68, 81}
def number80(n):
r = n % 80
return 80 if r == 0 else r
if __name__ == "__main__":
print(" 10 000 mod 80 = {}; 10^8 mod 80 = {}".format(10000 % 80,
10 ** 8 % 80))
rng = random.Random(80)
agree = 0
for _ in range(100000):
n = rng.randrange(10 ** 10, 2 * 10 ** 10)
a, b, c = number80(n), number80(n % 10 ** 4), number80(n % 10 ** 8)
agree += a == b == c
print(" 100,000 random 11-digit numbers: whole number, last 8 and last"
" 4")
print(" digits give the same number every time: {}".format(
agree == 100000))
hits = {}
for t in range(10000):
k = number80(t)
hits[k] = hits.get(k, 0) + 1
print(" last four digits 0000-9999: each of the 80 numbers occurs {}"
" times".format(set(hits.values())))
good = sum(1 for k in range(1, 81) if k in GOOD)
print(" good numbers reachable: {} of 80, so the base rate of a 'good'"
.format(good))
print(" number among evenly spread numbers is {:.3f}".format(good / 80))
moved = sum((number80(t) in GOOD) != (number80(t + 1) in GOOD)
for t in range(9999))
print(" adding one to the last four digits flips the label in {:.3f}"
" of cases".format(moved / 9999))
print("\nReading: the rule reads only the last four digits; with those")
print("evenly spread, a 'good' number is drawn with probability 0.425,")
print("and moving to the next number changes the verdict about half the")
print("time.")
# 10 000 mod 80 = 0; 10^8 mod 80 = 0
# 100,000 random 11-digit numbers: whole number, last 8 and last 4
# digits give the same number every time: True
# last four digits 0000-9999: each of the 80 numbers occurs {125} times
# good numbers reachable: 34 of 80, so the base rate of a 'good'
# number among evenly spread numbers is 0.425
# adding one to the last four digits flips the label in 0.550 of cases
#
# Reading: the rule reads only the last four digits; with those
# evenly spread, a 'good' number is drawn with probability 0.425,
# and moving to the next number changes the verdict about half the
# time.程序在十万个随机的十一位号码上验证了三种做法完全一致。后四位从 0000 到 9999 共 10,000 种,80 个余数各出现 125 次,恰好均匀;可达的 80 个数中吉数 34 个,所以在后四位均匀分布时,「吉号」的基率是 0.425。把后四位加一,吉凶标签在 0.550 的情形下改变:标签对号码的微小变化极不稳定。
八星就是三位二进制的异或
另一种流行的规则看相邻两位数字组成的「数字对」,把 64 种数字对分成八类,称为八星:伏位、生气、天医、延年为吉,绝命、五鬼、六煞、祸害为凶。这八个名称来自八宅风水的「游年」,即两个卦之间的关系 (Ruoguan Daoren, n.d.)。按后天八卦配洛书,数字 1 到 9(除 5)各对应一卦:1 坎、2 坤、3 震、4 巽、6 乾、7 兑、8 艮、9 离。第 64 本把卦写成三位二进制(初爻、中爻、上爻,阳为 1);于是两个数字之间的关系可以写成它们对应三位码的逐位异或。
推导
# Chapter 6. The "eight stars" of digit pairs are XOR on trigrams.
# Each digit except 5 (and 0) stands for a trigram by the Later Heaven
# Luoshu square: 1 Kan, 2 Kun, 3 Zhen, 4 Xun, 6 Qian, 7 Dui, 8 Gen,
# 9 Li. A trigram is three bits (bottom, middle, top; yang = 1). The
# table of the eight stars below is the one usually printed. We check
# that each star is exactly one value of (trigram a) XOR (trigram b).
TRIGRAM = {1: (0, 1, 0), 2: (0, 0, 0), 3: (1, 0, 0), 4: (0, 1, 1),
6: (1, 1, 1), 7: (1, 1, 0), 8: (0, 0, 1), 9: (1, 0, 1)}
STARS = {
"Fu Wei (good)": "11 22 33 44 66 77 88 99",
"Sheng Qi (good)": "14 41 67 76 39 93 28 82",
"Tian Yi (good)": "13 31 68 86 49 94 27 72",
"Yan Nian (good)": "19 91 78 87 34 43 26 62",
"Jue Ming (bad)": "12 21 69 96 48 84 37 73",
"Wu Gui (bad)": "18 81 79 97 36 63 24 42",
"Liu Sha (bad)": "16 61 47 74 38 83 29 92",
"Huo Hai (bad)": "17 71 89 98 46 64 23 32",
}
def xor(a, b):
return tuple(x ^ y for x, y in zip(TRIGRAM[a], TRIGRAM[b]))
def bits(t):
return "".join(map(str, t))
if __name__ == "__main__":
seen = set()
for star, pairs in STARS.items():
masks = {xor(int(p[0]), int(p[1])) for p in pairs.split()}
seen |= {p for p in pairs.split()}
print(" {:17s} XOR = {}".format(star, " ".join(bits(m)
for m in sorted(masks))))
digits = sorted(TRIGRAM)
print(" ordered pairs covered: {} of {}".format(
len(seen), len(digits) ** 2))
good = {xor(int(p[0]), int(p[1])) for s, ps in STARS.items()
if "good" in s for p in ps.split()}
closed = all(tuple(x ^ y for x, y in zip(a, b)) in good
for a in good for b in good)
print(" the four good masks form a subgroup of (Z_2)^3: {}".format(
closed))
parity = {d: TRIGRAM[d][0] ^ TRIGRAM[d][1] for d in digits}
east = [d for d in digits if parity[d] == 1]
west = [d for d in digits if parity[d] == 0]
print(" bottom XOR middle = 1 for digits {}; = 0 for {}".format(
east, west))
ok = all((parity[int(p[0])] == parity[int(p[1])]) == ("good" in s)
for s, ps in STARS.items() for p in ps.split())
print(" a pair is good exactly when both digits are in the same"
" group: {}".format(ok))
print("\nReading: each star is one of the eight elements of (Z_2)^3; the")
print("four good stars are the subgroup on which bottom XOR middle is 0.")
print("So good or bad is a single bit: whether two digits lie in the")
print("same group of four, the East group 1 3 4 9 or the West 2 6 7 8.")
# Fu Wei (good) XOR = 000
# Sheng Qi (good) XOR = 001
# Tian Yi (good) XOR = 110
# Yan Nian (good) XOR = 111
# Jue Ming (bad) XOR = 010
# Wu Gui (bad) XOR = 011
# Liu Sha (bad) XOR = 101
# Huo Hai (bad) XOR = 100
# ordered pairs covered: 64 of 64
# the four good masks form a subgroup of (Z_2)^3: True
# bottom XOR middle = 1 for digits [1, 3, 4, 9]; = 0 for [2, 6, 7, 8]
# a pair is good exactly when both digits are in the same group: True
#
# Reading: each star is one of the eight elements of (Z_2)^3; the
# four good stars are the subgroup on which bottom XOR middle is 0.
# So good or bad is a single bit: whether two digits lie in the
# same group of four, the East group 1 3 4 9 or the West 2 6 7 8.程序验证了:通行的八星表中,每一颗星的八个数字对恰好对应同一个异或值,八颗星对应 的八个元素。伏位是 000(同一个数字),延年是 111(三爻全变),生气是 001,天医是 110。四个吉星的异或值构成一个子群,正是「初爻与中爻异或为 0」的那些。由此推出一个比八星表简单得多的规则:把数字分成两组,1、3、4、9 一组(初爻与中爻异或为 1:坎、离、震、巽),2、6、7、8 一组(乾、坤、艮、兑);一个数字对为吉,当且仅当两个数字属于同一组。 这两组正是八宅中的「东四」与「西四」。
所以八星表的吉凶只携带一位信息:两个数字是否同组。具体是哪一颗星,由三位异或决定,但吉凶只看其中一位。
有多少号码通过
0 与 5 不对应任何卦,书中有两种处理:跳过它们、把两侧的数字当作相邻(「跳过」),或者含 0、5 的数字对不计吉凶(「中性」)。下面的程序对后八位的全部 种字符串,按上一节的「同组」规则逐位递推,精确计算没有凶对的字符串数与平均凶对数 (Lind and Marcus 1995)。
推导
# Chapter 6. How many digit strings pass, and how much choice is left.
# By p13 a pair of digits is good iff both lie in the East group
# {1,3,4,9} or both in the West group {2,6,7,8}. Two printed conventions
# for 0 and 5: (I) "skip" - drop them and judge the digits on either
# side as neighbours; (II) "neutral" - a pair containing 0 or 5 is
# neither good nor bad. For the last eight digits drawn evenly from 10^8
# strings we count exactly, by dynamic programming over the group of the
# last digit, the strings with no bad pair and the mean number of bad
# pairs, and we compare the choice left with log2(10) bits per digit.
import math
EAST, WEST, ZERO_FIVE = set("1349"), set("2678"), set("05")
def group(d):
return "E" if d in EAST else "W" if d in WEST else "N"
def count(length, rule):
# state: (group that the next digit must agree with, bad pairs so far)
states = {("-", 0): 1}
for _ in range(length):
new = {}
for (last, bad), c in states.items():
for d in "0123456789":
g = group(d)
if g == "N":
nxt = last if rule == "skip" else "-"
b = bad
else:
b = bad + (last in "EW" and last != g)
nxt = g
new[nxt, b] = new.get((nxt, b), 0) + c
states = new
return states
if __name__ == "__main__":
L = 8
total = 10 ** L
print(" last {} digits, {:,d} strings".format(L, total))
for rule in ("skip", "neutral"):
st = count(L, rule)
clean = sum(c for (g, b), c in st.items() if b == 0)
mean_bad = sum(b * c for (g, b), c in st.items()) / total
print(" rule {:7s}: no bad pair {:,d} strings = {:.4f}".format(
rule, clean, clean / total))
print(" mean bad pairs {:.3f}; choice left {:.3f}"
" bits per digit".format(mean_bad, math.log2(clean) / L))
print(" an unconstrained digit carries {:.3f} bits".format(
math.log2(10)))
strict = 2 * 4 ** L
print(" with no 0 or 5 at all: {:,d} strings = {:.6f} of all".format(
strict, strict / total))
print("\nReading: without 0s and 5s as buffers almost no string passes;")
print("with them, one string in thirty passes under the skip rule and")
print("one in eleven under the neutral rule. A passing number keeps")
print("under three bits of choice per digit instead of 3.32, and which")
print("numbers pass depends on the rule chosen for 0 and 5.")
# last 8 digits, 100,000,000 strings
# rule skip : no bad pair 3,358,976 strings = 0.0336
# mean bad pairs 2.700; choice left 2.710 bits per digit
# rule neutral: no bad pair 8,939,776 strings = 0.0894
# mean bad pairs 2.240; choice left 2.886 bits per digit
# an unconstrained digit carries 3.322 bits
# with no 0 or 5 at all: 131,072 strings = 0.001311 of all
#
# Reading: without 0s and 5s as buffers almost no string passes;
# with them, one string in thirty passes under the skip rule and
# one in eleven under the neutral rule. A passing number keeps
# under three bits of choice per digit instead of 3.32, and which
# numbers pass depends on the rule chosen for 0 and 5.没有任何凶对的八位尾号,在「跳过」规则下有 3,358,976 个,占 0.0336,约三十分之一;在「中性」规则下有 8,939,776 个,占 0.0894,约十一分之一。若不用 0 与 5,只剩 131,072 个,占 0.001311。随机号码平均有 2.700 或 2.240 个凶对。
从信息的角度看,一位不受限制的数字携带 3.322 比特;满足条件的号码每位只剩 2.710 或 2.886 比特的选择 (Shannon 1948)。「吉号」是全部号码中一个被强烈压缩的子集,它的成员之间的差别只在这个子集之内;而哪些号码属于这个子集,取决于对 0 与 5 的约定。
注
两种规则合在一起。 模 80 规则只看后四位的余数,八星规则看全部相邻数字是否同组。两者读的是号码的不同性质,一个号码可以在一种规则下为吉、在另一种下为凶。软件若同时使用两者,应当分别报告,而不是合成一个分数。
小结
模 80 的手机号码规则只读后四位,因为 10,000 是 80 的倍数;后四位均匀时,吉数的基率为 0.425,号码加一就有 0.550 的机会改变吉凶。八星是三位二进制的异或,吉凶等价于两个数字是否同属东四或西四,只携带一位信息。没有凶对的八位尾号只占 0.0336 到 0.0894,取决于对 0 与 5 的约定。
参考文献
Fan, Y. (2026). Modular Numerology, Character-Stroke Hashes and Residue-Class Distributions: Digital-Root Arithmetic, Kangxi Radical Restorations, Modulo-80 Grid Mappings and Empirical Base-Rate Concentration [姓名笔画、生命灵数与手机号码的同余映射和分布论] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090178 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).