arXiv:2611.05675cs.FLNov 2026

Manuscript Offprint

arXiv:2611.05675

Quadratic reset bounds for finite maximal prefix codes

Samrath Singh Chadha

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Let CC be a finite maximal prefix code of maximum codeword length k≥2k \geq 2. We prove that, whenever the literal decoder of CC is synchronizing, it has a reset word of length at most (k−1)(4k−5)(k-1)(4k-5). The bound is independent of the alphabet and the number of decoder states. Its main ingredient is a short-detection theorem: a linear observation of the decoder, with terminal weight constant on states of depth k−1k-1, is either identically zero or nonzero on a word of length at most 2k−32k-3. The proof uses a first-return decomposition in noncommuting variables and cancellation of a highest-degree coefficient.

For codes whose codeword lengths are k−1k-1 and kk, we prove the sharper bound 2(k−1)2−12(k-1)^2 - 1 and characterize equality. The binary code with the single short word ak−1a^{k-1} attains this bound for every k≥2k \geq 2; an age representation and a potential on circular arcs give the matching lower bound. Both upper bounds yield polynomial-time constructions in the explicit code size. The mathematical results and the algorithms are formalized in Lean, with polynomial work bounds in a specified binary cost model.

1 Introduction

A prefix code can be decoded as soon as a complete codeword has been read. If the starting position is unknown, however, different parsings may persist. A reset word removes this uncertainty: after reading it, every possible state of the decoder is the same. For the code {a,ba,bb}\{a, ba, bb\}, the letter aa is a reset word. The decoder is either at the root or has just read bb, and in both cases aa completes a codeword. For the code {aa,ab,ba,bb}\{aa, ab, ba, bb\}, no word resets the decoder, since the two possible depth parities remain different.

We ask how long a shortest reset word can be when all codewords have length at most kk. This parameter measures the depth of the prefix tree. It can be much smaller than the number of states: a full tree on dd letters can have 1+d+⋯+dk−11 + d + \cdots + d^{k-1} internal vertices. Thus even a polynomial bound in the number of states need not give a polynomial bound in kk.

Throughout, Σ\Sigma is a finite alphabet with at least two letters, and C⊆Σ+C \subseteq \Sigma^+ is a finite nonempty maximal prefix code. Its literal decoder has as states the proper prefixes of the codewords, including ε\varepsilon. A transition extends the current prefix by one letter, except that completing a codeword returns the decoder to ε\varepsilon. Maximality makes every transition defined. Write

k=max⁡c∈C∣c∣,s(C)=min⁡{∣w∣:w resets the literal decoder of C},k = \max_{c \in C} |c|, \qquad s(C) = \min\{|w| : w \text{ resets the literal decoder of } C\},

where the second quantity is used only when a reset word exists.

Theorem 1.1. If k≥2k \geq 2 and the literal decoder of CC is synchronizing, then

s(C)≤(k−1)(4k−5).(1.1)s(C) \leq (k-1)(4k-5). \tag{1.1}

A reset word satisfying this bound can be constructed in time polynomial in the explicitly listed code and alphabet.

The next result treats all full prefix trees with leaves at two consecutive depths. For r≥1r \geq 1 and ∅≠A⊊Σr\varnothing \neq A \subsetneq \Sigma^r, set

C(A)=A∪(Σr+1∖AΣ).(1.2)C(A)=A\cup(\Sigma^{r+1}\setminus A\Sigma). \tag{1.2}

Thus each word at depth r is either a leaf in A or has all its children as leaves at depth r+1r+1.

Theorem 1.2. The code C(A)C(A) is maximal, has height r+1r+1, and is synchronizing. Moreover,

s(C(A))≤2r2−1,(1.3)s(C(A))\leq2r^{2}-1, \tag{1.3}

with equality if and only if A=TrA = T^r for some nonempty proper subalphabet T⊊ΣT \subsetneq \Sigma. A reset word satisfying (1.3) can be constructed in polynomial time in the explicit input size.

The equality cases reduce, by identifying letters, to the following binary family.

Theorem 1.3. For every k≥2k \geq 2, the binary code

Ck={ak−1}∪({a,b}k∖ak−1{a,b})C_{k}=\{a^{k-1}\}\cup(\{a,b\}^{k}\setminus a^{k-1}\{a,b\})

has reset threshold s(Ck)=2(k−1)2−1s(C_{k}) = 2(k-1)^{2} - 1. The word

ak−1(bkak−1)k−2a^{k-1}(b^{k}a^{k-1})^{k-2}

is a shortest reset word. Inverse images under surjective letter maps give the same threshold over every finite alphabet with at least two letters.

Let sd(k)s_{d}(k) denote the largest reset threshold among synchronizing finite maximal prefix codes of height kk on a fixed dd-letter alphabet. There are only finitely many such codes, and Theorem 1.3 ensures that the class is nonempty.

Corollary 1.4. For every d≥2d \geq 2 and k≥2k \geq 2,

2(k−1)2−1≤sd(k)≤(k−1)(4k−5).2(k-1)^{2}-1\leq s_{d}(k)\leq(k-1)(4k-5).

In particular, sd(k)=Θ(k2)s_d(k) = \Theta(k^2).

Earlier work. Synchronization of prefix codes is part of the classical theory of codes; Schützenberger's work [8] studies synchronizing properties of a particular family of prefix codes. The shortest-reset-word problem for finite automata goes back to Černý [4]. Pin [6] develops the approach of bounding the length needed to reduce the image of a subset. The complementary approach enlarges preimages. Rystsov [7] uses this construction with linear algebra and averaging for regular automata; Steinberg [9] gives a general averaging lemma. Our universal bound combines preimage expansion with a word-length estimate specific to prefix trees.

Carpi and D'Alessandro [3] explicitly study synchronization in terms of maximum word length. They relate bounds for synchronizing pairs of complete finite codes to bounds for incompletable words of finite languages. Their result is a conditional route to a quadratic bound in this parameter.

State bounds for prefix-code decoders also follow from results on one-cluster automata: automata in which repeated use of one letter leads every state to the same cycle. Béal, Berlinkov, and Perrin [1] prove a quadratic state bound for this class and apply it to finite prefix codes. Berlinkov, Ferens, Ryzhikov, and Szykula [2] obtain an O(Nlog⁡3N)O(N \log^3 N) reset bound for literal automata of finite prefix codes, where N is the number of states. Theorem 1.1 gives a bound directly in the height of a complete literal decoder.

The distinction between the automata matters. Here a reset word must merge every proper-prefix state, without minimizing the decoder. The related theorem on uncompletable words and matrix mortality [5] concerns incomplete codes. A finite maximal prefix code has no uncompletable word: every input can be extended on the right to a concatenation of codewords. Its reset problem therefore requires a different argument.

The proofs. For the general bound, repeated use of one letter first sends the decoder into a cycle of at most kk states. We then construct a reset word backwards, enlarging the preimage of a chosen state. Cyclic averaging supplies an enlargement as soon as some short word changes a preimage's cardinality. Section 3 carries out this construction using the short-detection theorem proved in Section 4. The latter replaces a bound depending on the dimension of a state space by one depending only on tree depth.

For consecutive depths, the next codeword boundary is a nondecreasing function of the current boundary. Section 5 uses this order to advance the least remaining offset between two parsings. A closure property of the short codewords describes the only obstruction to the simplest advance. Section 6 proves the exact binary lower bound by assigning a potential to sets of possible ages. Section 7 gives the algorithms. Appendix A contains the arc calculations, and Appendix B describes the formal verification.