bpe_refund_pair_slot_obstruction
For the displayed string, a greedy self-pair merge and a two-step partial comparator exist; after the greedy step the two displayed pair types each occur once while the maximum count is one, and the weighted sum of one full occurrence and one half occurrence exceeds that maximum. The partial comparator contains two copies of the retyped pair.
Statement
theorem bpe_refund_pair_slot_obstruction : let s : List ℕ := [0,0,1,2,0,0,0,1,3] let g := bpe_full_merge 0 0 4 s let p : List ℕ := [4,1,2,0,4,1,3] bpe_greedy_step s g ∧ bpe_steps bpe_partial_step 2 s [5,2,0,5,3] ∧ bpe_pair_count 0 1 g = 1 ∧ bpe_pair_count 4 1 g = 1 ∧ bpe_max_pair_count g = 1 ∧ bpe_pair_count 4 1 p = 2 ∧ 2 * bpe_max_pair_count g < 2 * bpe_pair_count 0 1 g + bpe_pair_count 4 1 g
- Source
- Exact pair-count witness against a naive independent refund-slot bound for OP-1287; experiment 34410.
- Verified
- 19 Nov 2026
- Axioms
Classical.choiceQuot.soundpropext- Built on 8
- bpe_full_mergeThe string obtained by scanning left to right and replacing every available nonoverlapping occurrence of the selected pair with the given…
- 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.
- bpe_partial_stepA partial merge replaces an arbitrary nonoverlapping subset of one pair by a fresh symbol, with an unchanged step allowed.
- bpe_partial_mergeThe relation between input and output strings obtained by replacing an arbitrary subset of pairwise nonoverlapping occurrences of the…
- bpe_stepsExactly k applications of the specified binary relation connect the input and output strings.
- bpe_pair_countThe number of occurrences of the ordered symbol pair replaced by the left-to-right nonoverlapping full merge.
- bpe_worst_case_ratio_three_upper_boundThe worst-case ratio of greedy Byte-Pair Encoding to optimal partial-merge utility for three merges is at most 7/12.
The proof, explained
The theorem exhibits an explicit counterexample string $s = [0,0,1,2,0,0,0,1,3]$ where greedy Byte Pair Encoding (BPE) creates an obstruction for potential-function-based pair-slot bounds. While a greedy merge on the most frequent pair $(0,0)$ resolves the triple $[0,0,0]$ from the left into $[4,0]$—yielding a string $g$ where $(4,1)$ and $(0,1)$ each occur once and the maximum pair count drops to $1$—an alternative partial merge resolves the triple into $[0,4]$, producing a string $p$ where $(4,1)$ occurs twice. The proof establishes the validity of both the greedy step and the two-step partial derivation by constructing explicit witnesses, with all numerical counts and inequalities verified by direct computation (`decide`).
The five numerical count equalities and the weighted inequality hold for $g$ and $p$, reducing the theorem to establishing the greedy step and the two-step partial merge derivation.
After simplifying the let-bindings defining the initial string $s$, the greedy result $g$, and the intermediate string $p$, the proof decomposes the conjunction of seven assertions. The last five subgoals—that the pair counts $\mathrm{count}((0,1), g) = 1$, $\mathrm{count}((4,1), g) = 1$, $\mathrm{max\_count}(g) = 1$, $\mathrm{count}((4,1), p) = 2$, and the arithmetic inequality $2 \cdot 1 < 2 \cdot 1 + 1$—are verified directly by computational evaluation (`decide`).
dsimp only refine ⟨?_, ?_, by decide, by decide, by decide, by decide, by decide⟩
The transition from $s$ to $g$ is a valid greedy BPE step.
A greedy step allows either a no-op if the maximum pair count is zero, or a full merge of any pair attaining the maximum positive count using a fresh symbol. Selecting the second alternative via `right`, we provide the pair $(0, 0)$ and fresh symbol $4$. Direct evaluation (`decide`) verifies that the maximum count in $s$ is positive, that $(0, 0)$ attains this maximum, and that $4 \notin s$. The equality $g = \mathrm{bpe\_full\_merge}(0,0,4,s)$ holds by definition of $g$ (`rfl`).
· right exact ⟨0,0,4, by decide, by decide, by decide, rfl⟩
The list $p = [4, 1, 2, 0, 4, 1, 3]$ is a valid partial merge of $(0, 0)$ into $4$ starting from $s$.
We record an auxiliary hypothesis `hfirst` stating that $p$ is a partial merge of $(0, 0)$ into $4$ applied to $s$. Unlike the full greedy merge which merges the first two zeros of the run $[0,0,0]$ to produce $[4, 0]$, this partial merge leaves the first zero unchanged and merges the subsequent pair of zeros into $4$, yielding $[0, 4]$. The recursive definition of `bpe_partial_merge` is verified by `simp`.
· have hfirst : bpe_partial_merge 0 0 4 [0,0,1,2,0,0,0,1,3] [4,1,2,0,4,1,3] := by simp [bpe_partial_merge]
The string $[5, 2, 0, 5, 3]$ is reachable from $s$ in two partial merge steps.
We exhibit the two-step sequence using intermediate string $p = [4, 1, 2, 0, 4, 1, 3]$. The first step is the partial merge from $s$ to $p$ justified by `hfirst` with fresh symbol $4$ (verified $4 \notin s$ by `decide`). The second step fully merges $(4, 1)$ into $5$ (verified $5 \notin p$ by `decide`), which is a valid partial merge by `bpe3ub_partial_of_full`. The resulting list is $[5, 2, 0, 5, 3]$, which matches the target string in zero further steps (`rfl`).
uses
Or.inr,bpe3ub_partial_of_fullrefine ⟨[4,1,2,0,4,1,3], Or.inr ⟨0,0,4, by decide, hfirst⟩, _, Or.inr ⟨4,1,5, by decide, bpe3ub_partial_of_full 4 1 5 _⟩, ?_⟩ rfl
Or.inr- Given a proof of $B$, constructs a proof of the disjunction $A \lor B$.
bpe3ub_partial_of_full- A full merge of all non-overlapping occurrences of pair $(a, b)$ into fresh symbol $z$ in a string $s$ is a valid partial merge.
- The pair counts, maximum pair count, and list non-membership conditions on concrete lists of natural numbers are decidable and checked automatically by Lean's kernel evaluator via `decide`.
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_refund_pair_slot_obstruction : let s : List ℕ := [0,0,1,2,0,0,0,1,3] let g := bpe_full_merge 0 0 4 s let p : List ℕ := [4,1,2,0,4,1,3] bpe_greedy_step s g ∧ bpe_steps bpe_partial_step 2 s [5,2,0,5,3] ∧ bpe_pair_count 0 1 g = 1 ∧ bpe_pair_count 4 1 g = 1 ∧ bpe_max_pair_count g = 1 ∧ bpe_pair_count 4 1 p = 2 ∧ 2 * bpe_max_pair_count g < 2 * bpe_pair_count 0 1 g + bpe_pair_count 4 1 g := by dsimp only refine ⟨?_, ?_, by decide, by decide, by decide, by decide, by decide⟩ · right exact ⟨0,0,4, by decide, by decide, by decide, rfl⟩ · have hfirst : bpe_partial_merge 0 0 4 [0,0,1,2,0,0,0,1,3] [4,1,2,0,4,1,3] := by simp [bpe_partial_merge] refine ⟨[4,1,2,0,4,1,3], Or.inr ⟨0,0,4, by decide, hfirst⟩, _, Or.inr ⟨4,1,5, by decide, bpe3ub_partial_of_full 4 1 5 _⟩, ?_⟩ rfl