← All papers
First page of Optimal single-track Gray codes from Gray-ordered necklaces

Optimal single-track Gray codes from Gray-ordered necklaces

Chris Dzoba

math.CO Oct 17, 2026 · v1 cs.DM cs.IT
Formalizes in Lean 4 with Mathlib that the Degni–Drisko property at a prime n yields an optimal single-track Gray code; n=3 and n=5 cases checked by computation.
A single-track Gray code of length $n$ is a cyclic Gray code of $n$-bit words in which every column is a cyclic shift of the first. For prime $n$ the longest possible period is $2^n-2$. Whether it is attained for every prime has been open since Hiltgen, Paterson and Brandestini introduced these codes in 1996, and optimal codes were known for primes $n\le 19$. We show that a conjecture of Degni and Drisko (2007) on the reflected Gray code order of necklaces implies optimal single-track Gray codes for every prime. Their list of necklaces, conjecturally a Gray path for prime $n$, closes into a Hamilton cycle of the necklace graph after $(n-3)/2$ explicit Pósa rotations, and such a cycle lifts to an optimal code. This implication is formalized in Lean 4. Together with computation it gives optimal single-track Gray codes for every odd prime $n\le 47$: for $n\le 37$ explicit codes checked word by word by a program independent of the generator, and for $n=41$, $43$ and $47$ codes obtained from the implication after the Degni-Drisko property was verified at these lengths by two independently written programs.

Whether optimal single-track Gray codes, with period 2^n-2, exist for every prime n has been open since 1996. Optimal codes were known only for primes n ≤ 19.

The problem reduces to Hamiltonicity of the necklace graph Q_n. The Degni–Drisko list of necklaces, ordered by first occurrence in the binary reflected Gray code, is conjectured to be a Gray path for prime n. It is closed into a Hamilton cycle by (n-3)/2 explicit Pósa rotations, and the cycle is lifted to an optimal code (Theorem A). Theorem A is formalized in Lean 4 with Mathlib as the theorem stgc_of_DD, and further codes were found by computer search and checked by independent verifiers.

The Degni–Drisko conjecture implies optimal single-track Gray codes for every prime. Optimal codes are obtained for every odd prime n ≤ 47: explicit codes checked word by word for n ≤ 37, and codes via Theorem A for n = 41, 43 and 47 after the hypothesis was verified by two independent programs.

nperiod 2^n-2methodverification
36explicitLean (decide)
238,388,606searchword by word, ≥3 checkers
312,147,483,646searchword by word, ≥3 checkers
37137,438,953,470Theorem Aword by word, 1 checker
47140,737,488,355,326Theorem AConjecture 1 at n=47, 2 programs
Optimal codes by length (selected rows)