5D Library › Modular Numerology, Character-Stroke Hashes and Residue-Class Distributions · 中文

Chapter 6. Phone Numbers: Modulo 80, XOR and Compressed Numbers

Modulo 80 reads only the last four digits

The common method of phone-number numerology takes the last four digits of the number (some books take the last eight, some the whole number), divides by 80, keeps the remainder, counts a remainder of 0 as 80, and looks the result up in the table of eighty-one numbers. The three versions look different and are in fact identical. Because 104=125×8010^4 = 125 \times 80, every digit before the last four is multiplied by a multiple of 80 and contributes nothing to the remainder. The Chinese remainder theorem says more: 80=16×580 = 16 \times 5; the residue modulo 5 is fixed by the last digit alone, the residue modulo 16 by the last four.

Calculation

# 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.

The program checks on a hundred thousand random eleven-digit numbers that the three versions agree every time. The last four digits run from 0000 to 9999, 10,000 possibilities, and each of the 80 remainders occurs exactly 125 times, perfectly evenly; 34 of the 80 reachable numbers are good, so with the last four digits spread evenly the base rate of a “good number” is 0.425. Adding one to the last four digits changes the label in 0.550 of cases: the label is highly unstable under the smallest change of number.

The eight stars are a three-bit XOR

Another popular rule looks at “digit pairs”, two adjacent digits, and sorts the 64 pairs into eight classes called stars: Fu Wei, Sheng Qi, Tian Yi and Yan Nian are good; Jue Ming, Wu Gui, Liu Sha and Huo Hai are bad. The eight names come from the “wandering years” of Eight Mansions feng shui, the relations between two trigrams (Ruoguan Daoren, n.d.). Pairing the Later Heaven trigrams with the Luoshu square, each digit 1 to 9 except 5 stands for a trigram: 1 Kan, 2 Kun, 3 Zhen, 4 Xun, 6 Qian, 7 Dui, 8 Gen, 9 Li. Volume 64 wrote the trigrams as three-bit binary numbers (bottom, middle and top line, yang = 1); the relation between two digits can then be written as the bitwise XOR of their three-bit codes.

Calculation

# 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.

The program checks that in the usual table of the eight stars, the eight digit pairs of each star all have the same XOR, and the eight stars correspond to the eight elements of ℤ23\mathbb{Z}_2^3. Fu Wei is 000 (the same digit), Yan Nian 111 (all three lines changed), Sheng Qi 001, Tian Yi 110. The XOR values of the four good stars form a subgroup: exactly those whose bottom XOR middle is 0. A rule far simpler than the table follows. Split the digits into two groups, 1, 3, 4, 9 (bottom XOR middle is 1: Kan, Li, Zhen, Xun) and 2, 6, 7, 8 (Qian, Kun, Gen, Dui); a digit pair is good exactly when both digits lie in the same group. The two groups are the “East four” and “West four” of the Eight Mansions school.

The XOR of each pair of the eight digits; gold is good. Reordered into the East and West groups, the good pairs are exactly the two diagonal blocks.

So the good-or-bad verdict of the eight stars carries a single bit of information: whether two digits lie in the same group. Which star it is depends on the three-bit XOR, but good or bad looks at only one bit of it.

How many numbers pass

0 and 5 stand for no trigram, and books treat them in two ways: skip them and take the digits on either side as neighbours (“skip”), or count a pair containing 0 or 5 as neither good nor bad (“neutral”). The next program goes through all 10810^8 strings of the last eight digits, digit by digit with the same-group rule, and counts exactly the strings with no bad pair and the mean number of bad pairs (Lind and Marcus 1995).

Calculation

# 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.

Eight-digit endings with no bad pair number 3,358,976 under the skip rule, 0.0336 of all, about one in thirty; under the neutral rule 8,939,776, 0.0894 of all, about one in eleven. Without 0 and 5 at all only 131,072 remain, 0.001311 of all. A random number has on average 2.700 or 2.240 bad pairs.

In terms of information, an unconstrained digit carries 3.322 bits; a number that passes keeps only 2.710 or 2.886 bits of choice per digit (Shannon 1948). “Good numbers” are a strongly compressed subset of all numbers, whose members differ from one another only within that subset; and which numbers belong to it depends on the convention for 0 and 5.

Note

The two rules together. The modulo-80 rule looks only at the remainder of the last four digits; the eight-star rule looks at whether all adjacent digits lie in the same group. They read different properties of a number, and a number can be good under one and bad under the other. Software that uses both should report them separately rather than merge them into one score.

Summary

The modulo-80 rule for phone numbers reads only the last four digits, because 10,000 is a multiple of 80; with those digits spread evenly the base rate of a good number is 0.425, and adding one to the number changes the verdict with probability 0.550. The eight stars are a three-bit XOR, and good or bad is equivalent to whether two digits lie in the same of the East and West groups, a single bit. Eight-digit endings with no bad pair are only 0.0336 to 0.0894 of all, depending on the convention for 0 and 5.

References

Lind, Douglas, and Brian Marcus. 1995. An Introduction to Symbolic Dynamics and Coding. Cambridge University Press.
Ruoguan Daoren. n.d. Bazhai Mingjing [the Bright Mirror of the Eight Mansions]. In Chinese; Qing Dynasty, Author Known by the Sobriquet Ruoguan Daoren.
Shannon, Claude E. 1948. “A Mathematical Theory of Communication.” Bell System Technical Journal 27: 379–423, 623–56.

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).