Search arXivSearch

arXiv · 2607.16088

Variable-length Gray codes for the Natural Numbers

Abstract

The modular $b$-ary Gray code arranges fixed-length $b$-ary representations of intervals of natural numbers so that consecutive numbers differ in a single digit. Its usefulness, however, is tied to a fixed word length. We introduce, for every integer base $b\ge 2$, a \emph{variable-length Gray code} $V_{b}$: a bijection from the natural numbers onto the set of all finite strings over the $b$-symbol alphabet $\{0,1,\dots,b-1\}$. The construction orders the natural numbers by codeword length into blocks and lists each block along the modular $b$-ary Gray code of the within-block offset, with its leading digit incremented modulo $b$. We prove four properties for arbitrary $b$. First, $V_{b}$ is a bijection, a complete code that assigns exactly one codeword to every finite string over the alphabet, including the empty string. Second, the Levenshtein (edit) distance between the codewords of two consecutive integers is always one. Third, codeword length is monotone non-decreasing in the encoded number. Fourth, the transition to codewords of length $k$ occurs exactly at $n=N_{k}=\sum_{i=0}^{k-1}b^{i}$, where $V_{b}(n)=1\,0^{k-1}$. The presented code, therefore, realizes a Hamiltonian enumeration under unit edit steps while retaining a near-optimal, self-adapting length profile. These properties suggest a use in machine learning: large language models routinely emit natural numbers as symbol strings, yet the positional notations they rely on are neither complete -- strings with leading zeros are invalid or redundant -- nor locally stable, since incrementing a number may rewrite many symbols at once. Because $V_{b}$ is a complete code and moves by a single edit between consecutive integers, it removes both obstacles and is a natural candidate representation for numeric tokens; we develop this argument and discuss the code's compression behavior relative to fixed-length Gray codes.

Explore related subjects

Keep this discovery

Explore connections, maps & timelines

BibTeXRIS

Ezequiel López-Rubio. 2026-07-21. Variable-length Gray codes for the Natural Numbers. https://arxiv.org/abs/2607.16088

Cite the original work for its findings. Save a collection to share your selection of sources.

KEEP EXPLORING

Related papers

Radiance-Field Guided Pretraining: Scaling Localization Models with Unlabeled Wireless Signals

Radio frequency (RF)-based indoor localization offers significant promise for applications such as indoor navigation, augmented reality, and pervasive computing. While deep learning has greatly enhanced localization accuracy and robustness, existing localization models still face major challenges in cross-scene generalization due to their reliance on scene-specific labeled data. To address this, we introduce Radiance-Field Reinforced Pretraining (RFRP). This novel self-supervised pretraining framework couples a large localization model (LM) with a neural radio-frequency radiance field (RF-NeRF) in an asymmetrical autoencoder architecture. In this design, the LM encodes received RF spectra into latent, position-relevant representations, while the RF-NeRF decodes them to reconstruct the original spectra. This alignment between input and output enables effective representation learning using large-scale, unlabeled RF data, which can be collected continuously with minimal effort. To this end, we collected RF samples at 7,327,321 positions across 100 diverse scenes using four common wireless technologies--RFID, BLE, WiFi, and IIoT. Data from 75 scenes were used for training, and the remaining 25 for evaluation. Experimental results show that the RFRP-pretrained LM reduces localization error by over 40% compared to non-pretrained models and by 21% compared to those pretrained using supervised learning.

cs.IT

Uniform Recovery of Structured Signals from Nonlinear Observations: Improved Error Rates

Consider the recovery of structured signals from nonlinear observations. Under Gaussian matrix and a large class of unknown nonlinear link functions, Plan and Vershynin (2016) showed that generalized Lasso achieves accurate nonuniform recovery of a fixed signal. More recently, Genzel and Stollenwerk (2023) showed that generalized Lasso is indeed capable of accurately recovering all structured signals. However, in some canonical settings with discontinuous link functions, their uniform recovery error rate is essentially slower than the nonuniform one. Specifically, in the recovery of $n$-dimensional $k$-sparse vectors from $m$ measurements, generalized Lasso with a perfectly tuned $\ell_1$ constraint achieves nonuniform error rate $ O(\sqrt{k\log(en/k)/m})$, while the uniform error rate of Genzel and Stollenwerk is no faster than $O((k\log(en/k)/m)^{1/4})$. In this paper, we narrow this gap by establishing improved uniform recovery guarantees under piecewise Lipschitz link functions with well-separated jump discontinuities. We analyze a projected gradient descent (PGD) algorithm whose projection can be onto a convex set or a cone, and our results for the PGD with a convex set are also valid for the generalized Lasso. In sparse recovery, the improved uniform error rates match the nonuniform rate $O(\sqrt{k\log(en/k)/m})$ up to logarithmic factors. Under the sign link function, we further show that iterative hard thresholding (a specific instance of the PGD) achieves uniform recovery error rate $O(\sqrt{k\log(en/k)/m})$, matching the nonuniform rate up to a universal constant. Technically, the uniform guarantees for the PGD are obtained by showing that the gradient maps satisfy the restricted approximate invertibility condition uniformly over all signals. We demonstrate that this is a general approach to uniform recovery under nonlinear observations.

cs.IT

Recursive overlap Bernoulli distributions and an entropy concavity conjecture

We introduce a family of recursively generated finite probability distributions obtained from left and right embeddings with overlaps. The construction interpolates between the classical binomial distribution and the non-overlapping Bernoulli product distribution. We derive explicit formulas for the expectation, variance, and the generating function of higher moments, and formulate a conjecture asserting that the Shannon entropy is concave. The conjecture is proved in the two extremal cases and supported by symbolic computations for numerous overlap sequences.

cs.IT