[Paper Review] On the Hamming Distance between base-n representations of whole numbers
This paper derives a closed-form formula for the sum of Hamming distances between consecutive integers from 1 to m in base-n representation. It proves that the Hamming distance between m and m−1 equals l+1, where l is the exponent of the highest power of n dividing m, and uses this to derive S(m) = Σ⌈m/n^j⌉, which enables efficient computation of the total Hamming distance across all consecutive pairs.
We first introduce the Hamming distance between two strings. Then, we apply this concept to the representations of whole numbers in base n for all positive integers n > 2. We claim that a simple formula exists for the sum of all Hamming distances between pairs of consec- utive integers from 1 to m, which we will derive. We also state and prove other interesting results concerning the aforementioned topic.
Motivation & Objective
- To establish a mathematical formula for the sum of Hamming distances between consecutive integers in base-n representations.
- To analyze the Hamming distance between m and m−1 in base n, particularly how it relates to the highest power of n dividing m.
- To provide an efficient algorithmic implementation for computing the total Hamming distance sum up to a given m.
- To generalize the Hamming distance behavior across different bases n ≥ 2 and whole numbers.
- To validate the derived formula with a working Python implementation for practical use.
Proposed method
- Define the Hamming distance H(S1, S2) as the number of differing digit positions between two equal-length strings S1 and S2.
- Introduce zero-padding to align variable-length base-n representations of consecutive integers.
- Prove via case analysis that H(m, m−1) = l + 1, where l is the exponent of the highest power of n dividing m.
- Express the total sum S(m) as the sum over i from 1 to m of (P_i + 1), where P_i is the highest power of n dividing i.
- Reformulate the sum using Iverson brackets and interchange summation order to obtain S(m) = Σ⌈m/n^j⌉ over j ≥ 0.
- Implement the formula efficiently in Python by iterating over powers of n up to log_n(m), avoiding brute-force string comparisons.
Experimental results
Research questions
- RQ1What is the Hamming distance between consecutive integers m and m−1 in base-n representation, and how does it depend on the prime power structure of m?
- RQ2Can a closed-form expression be derived for the cumulative sum of Hamming distances between all consecutive pairs of integers from 1 to m in base n?
- RQ3How does the Hamming distance vary based on whether n divides m, and what role does the highest power of n dividing m play?
- RQ4Is there an efficient algorithm to compute the total Hamming distance sum without explicitly comparing each pair of consecutive numbers?
- RQ5What is the computational complexity of computing the sum using the derived formula compared to naive string comparison?
Key findings
- The Hamming distance between m and m−1 in base n is H(m, m−1) = l + 1, where l is the exponent of the highest power of n dividing m.
- The sum of Hamming distances from 1 to m in base n is given by S(m) = Σ⌈m/n^j⌉ for j from 0 to ⌈log_n m⌉.
- The formula S(m) = Σ⌈m/n^j⌉ is derived by expressing the sum as a double summation over divisibility conditions and interchanging the order of summation.
- The derivation relies on Iverson brackets to encode divisibility, allowing exact transformation into a sum over powers of n.
- The formula enables O(log_n m) time computation of the total Hamming distance, vastly improving over O(m) naive comparison.
- A Python implementation confirms the correctness of the formula and demonstrates its efficiency for large values of m and n.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.