op1287_bpe_six_block_unit_comparator
For the displayed six-block string with distinct separators, merging 1,2 is a greedy first step of utility 2, the next maximum pair count is 1, and the displayed five partial steps achieve utility 9, equal to twice the first greedy utility plus five times the next maximum count.
Statement
theorem op1287_bpe_six_block_unit_comparator : let s : List ℕ := [0,1,2,3,6, 0,1,7, 2,3,8, 4,1,2,5,9, 4,1,10, 2,5,11] let g := bpe_full_merge 1 2 12 s let u := bpe_full_merge 2 5 16 (bpe_full_merge 4 1 15 (bpe_full_merge 12 13 14 (bpe_full_merge 2 3 13 (bpe_full_merge 0 1 12 s)))) bpe_max_pair_count s = 2 ∧ bpe_greedy_step s g ∧ bpe_max_pair_count g = 1 ∧ bpe_steps bpe_partial_step 5 s u ∧ s.length - u.length = 9 ∧ 2 * (s.length - g.length) + 5 * bpe_max_pair_count g = 9
- Source
- OP-1287 tight comparator illustration, the unit case of arXiv:2611.08671v1, Section 3; experiment 31921. This asserts a comparator lower bound and equality with the proposed right side, not an upper bound on the optimum.
- 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_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.
- bpe_pair_countThe number of occurrences of the ordered symbol pair replaced by the left-to-right nonoverlapping full merge.
The proof, explained
The theorem verifies the greedy behavior and comparator bound for Byte Pair Encoding (BPE) on a six-block string s with distinct block separators. Merging the most frequent pair (1, 2) into token 12 constitutes a valid greedy first step that drops the maximum pair frequency from 2 to 1 and achieves utility 2. An alternative 5-step partial merge sequence reduces the string length by 9, exactly matching the upper-bound comparator value 2 * 2 + 5 * 1 = 9. The proof decomposes the properties into concrete list computations verified by `decide` and an explicit 5-step witness sequence where each full merge is certified as a partial merge using `bpe3ub_partial_of_full`.
The string s has maximum pair frequency 2, the greedily merged string g has maximum pair frequency 1, the string u achieves a length reduction of 9, and the comparator identity 2 * (s.length - g.length) + 5 * bpe_max_pair_count g = 9 holds. automation
After simplifying the local let-definitions with `dsimp only`, the theorem's six-part conjunction is split into subgoals. Four of these—the maximum pair count of the concrete string s being 2, the maximum pair count of the post-greedy string g being 1, the length reduction s.length - u.length = 9, and the arithmetic evaluation 2 * (23 - 21) + 5 * 1 = 9—are evaluated directly by Lean's decision procedure `decide` on the explicit lists.
dsimp only refine ⟨by decide, ?_, by decide, ?_, by decide, by decide⟩
Merging the pair (1, 2) into the fresh token 12 is a valid greedy BPE step from s to g. automation
A greedy step is valid if either the maximum pair count is 0 and the string is unchanged, or a pair with maximal frequency is replaced by a fresh token. Selecting the second alternative (`right`), we provide (1, 2) and token 12 as witnesses. The requirements that the maximum pair count is strictly positive, that (1, 2) attains this maximum count of 2, and that 12 does not appear in s are confirmed by computational evaluation (`decide`), while g coincides with the full merge by definition (`rfl`).
· right exact ⟨1, 2, 12, by decide, by decide, by decide, rfl⟩
The string u is reachable from s via a sequence of 5 valid partial merge steps.
To establish the 5-step transition `bpe_steps bpe_partial_step 5 s u`, we supply the intermediate strings formed by five sequential full merges: (0, 1) into 12, (2, 3) into 13, (12, 13) into 14, (4, 1) into 15, and (2, 5) into 16. Each step is shown to be a valid partial step by applying `bpe3ub_partial_of_full`, which proves that any full merge is a valid partial merge, together with computational verification (`decide`) that each new token is fresh at that stage. The final string matches u by definition (`rfl`).
uses
Or.inr,bpe3ub_partial_of_full· refine ⟨_, Or.inr ⟨0, 1, 12, by decide, bpe3ub_partial_of_full 0 1 12 _⟩, _, Or.inr ⟨2, 3, 13, by decide, bpe3ub_partial_of_full 2 3 13 _⟩, _, Or.inr ⟨12, 13, 14, by decide, bpe3ub_partial_of_full 12 13 14 _⟩, _, Or.inr ⟨4, 1, 15, by decide, bpe3ub_partial_of_full 4 1 15 _⟩, _, Or.inr ⟨2, 5, 16, by decide, bpe3ub_partial_of_full 2 5 16 _⟩, rfl⟩
Or.inr- If proposition b holds, then the disjunction a ∨ b holds.
bpe3ub_partial_of_full- A full merge replacing all adjacent occurrences of pair (a, b) with token z in string s is a valid partial merge.
- Several subgoals—evaluating maximum pair counts, computing string lengths, verifying token freshness (non-membership in lists), and linear arithmetic identities—are discharged by Lean's `decide` tactic via kernel reduction on concrete finite lists.
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 op1287_bpe_six_block_unit_comparator : let s : List ℕ := [0,1,2,3,6, 0,1,7, 2,3,8, 4,1,2,5,9, 4,1,10, 2,5,11] let g := bpe_full_merge 1 2 12 s let u := bpe_full_merge 2 5 16 (bpe_full_merge 4 1 15 (bpe_full_merge 12 13 14 (bpe_full_merge 2 3 13 (bpe_full_merge 0 1 12 s)))) bpe_max_pair_count s = 2 ∧ bpe_greedy_step s g ∧ bpe_max_pair_count g = 1 ∧ bpe_steps bpe_partial_step 5 s u ∧ s.length - u.length = 9 ∧ 2 * (s.length - g.length) + 5 * bpe_max_pair_count g = 9 := by dsimp only refine ⟨by decide, ?_, by decide, ?_, by decide, by decide⟩ · right exact ⟨1, 2, 12, by decide, by decide, by decide, rfl⟩ · refine ⟨_, Or.inr ⟨0, 1, 12, by decide, bpe3ub_partial_of_full 0 1 12 _⟩, _, Or.inr ⟨2, 3, 13, by decide, bpe3ub_partial_of_full 2 3 13 _⟩, _, Or.inr ⟨12, 13, 14, by decide, bpe3ub_partial_of_full 12 13 14 _⟩, _, Or.inr ⟨4, 1, 15, by decide, bpe3ub_partial_of_full 4 1 15 _⟩, _, Or.inr ⟨2, 5, 16, by decide, bpe3ub_partial_of_full 2 5 16 _⟩, rfl⟩