bpe_retyping_of_greedy_opt_stability
Assume every greedy step loses at most twice its saving from the k-step optimal partial-merge utility, and assume k-step optimum is at most k times the initial maximum pair count. Then after any number of greedy steps, the original k-step optimum is at most twice the total greedy saving plus k times the maximum pair count in the resulting string.
Statement
theorem bpe_retyping_of_greedy_opt_stability
(hstable : ∀ (s t : List ℕ) (k : ℕ), bpe_greedy_step s t →
bpe_optimal_utility s k ≤ 2 * (s.length - t.length) + bpe_optimal_utility t k)
(hcount : ∀ (s : List ℕ) (k : ℕ),
bpe_optimal_utility s k ≤ k * bpe_max_pair_count s)
(i k : ℕ) (s t : List ℕ) (hg : bpe_steps bpe_greedy_step i s t) :
bpe_optimal_utility s k ≤ 2 * (s.length - t.length) + k * bpe_max_pair_count t- Source
- Telescoping reduction from greedy one-step optimum stability to OP-1287.
- Verified
- 19 Nov 2026
- Axioms
Classical.choiceQuot.soundpropext- Built on 6
- bpe_stepsExactly k applications of the specified binary relation connect the input and output strings.
- bpe_optimal_utilityThe supremum, over strings reachable in k partial-merge steps, of the reduction in length of the input string.
- bpe_greedy_step_length_leAny greedy full byte-pair merge step produces an output string of length at most the input string length.
- bpe_greedy_steps_length_leApplying k greedy full byte-pair merge steps to a string produces an output string of length at most the input string length.
- bpe_max_pair_countThe largest nonoverlapping full-merge pair count among adjacent pairs of the current string, with maximum zero for a string shorter than…
- bpe_greedy_stepA greedy full-merge step selects any most frequent adjacent pair and a fresh symbol; a string without adjacent pairs remains unchanged.
The proof, explained
The theorem is proved by induction on the number of greedy steps i, generalizing over the starting string s. In the base case i = 0, no steps are taken, so s = t and the bound follows directly from the assumption bounding the optimal utility of s by k times its maximum pair count. In the inductive step i + 1, the path splits into a first step s → u and an i-step path u → t. The single-step stability hypothesis and the induction hypothesis bound the utilities of the two segments, and because greedy steps never increase string length, the length reductions telescope so that linear arithmetic completes the proof.
In the base case i = 0, no greedy steps are taken and the inequality holds.
We proceed by induction on the number of greedy steps i, generalizing the initial string s. When i = 0, the definition of bpe_steps implies s = t. The length reduction s.length - t.length vanishes, simplifying the required bound to bpe_optimal_utility s k ≤ k * bpe_max_pair_count s, which is given directly by the assumption hcount.
uses
bpe_stepsinduction i generalizing s with | zero => simp only [bpe_steps] at hg subst t simpa using hcount s k
In the inductive step for i + 1, the execution decomposes into a single greedy step to an intermediate string u followed by i greedy steps to t.
By the inductive definition of bpe_steps, reaching t from s in i + 1 greedy steps means there exists an intermediate string u such that s reaches u in one greedy step (hu) and u reaches t in i greedy steps (hut).
| succ i ih => rcases hg with ⟨u, hu, hut⟩The optimal utility bounds hold for the first step s → u and for the remaining path u → t.
Applying the greedy step stability hypothesis hstable to the first step s → u bounds bpe_optimal_utility s k by 2 * (s.length - u.length) + bpe_optimal_utility u k. Applying the induction hypothesis ih to the i-step path from u to t bounds bpe_optimal_utility u k by 2 * (u.length - t.length) + k * bpe_max_pair_count t.
have h1 := hstable s u k hu have h2 := ih u hut
String lengths are non-increasing along greedy steps, so the length reductions telescope to establish the bound for s.
By bpe_greedy_step_length_le and bpe_greedy_steps_length_le, string lengths satisfy u.length ≤ s.length and t.length ≤ u.length. Consequently, the natural number length differences telescope: (s.length - u.length) + (u.length - t.length) = s.length - t.length. Adding the two utility bounds and simplifying via linear arithmetic (omega) completes the inductive step.
uses
bpe_greedy_step_length_le,bpe_greedy_steps_length_lehave hlen1 := bpe_greedy_step_length_le s u hu have hlen2 := bpe_greedy_steps_length_le i u t hut omega
bpe_steps- The n-step iteration of a binary relation R on lists: 0 steps is equality (s = t), and n + 1 steps means there is an intermediate string u such that R s u holds and u reaches t in n steps.
bpe_greedy_step_length_le- A single greedy BPE step never increases the length of the string.
bpe_greedy_steps_length_le- Any sequence of greedy BPE steps never increases the length of the string.
Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.
Lean source view module on GitHub
Choose a tactic — a marked line — to see the goals Lean had before and after it, as in Lean’s infoview. Step with ← → or j k.
set_option maxRecDepth 8192set_option maxHeartbeats 4000000theorem bpe_retyping_of_greedy_opt_stability (hstable : ∀ (s t : List ℕ) (k : ℕ), bpe_greedy_step s t → bpe_optimal_utility s k ≤ 2 * (s.length - t.length) + bpe_optimal_utility t k) (hcount : ∀ (s : List ℕ) (k : ℕ), bpe_optimal_utility s k ≤ k * bpe_max_pair_count s) (i k : ℕ) (s t : List ℕ) (hg : bpe_steps bpe_greedy_step i s t) : bpe_optimal_utility s k ≤ 2 * (s.length - t.length) + k * bpe_max_pair_count t := by induction i generalizing s with | zero => simp only [bpe_steps] at hg subst t simpa using hcount s k | succ i ih => rcases hg with ⟨u, hu, hut⟩ have h1 := hstable s u k hu have h2 := ih u hut have hlen1 := bpe_greedy_step_length_le s u hu have hlen2 := bpe_greedy_steps_length_le i u t hut omega