bpe_partial_residual_can_exceed_greedy
There are a string, a greedy merge result, and a partial-merge result of the same input for which the partial result has a strictly larger maximum nonoverlapping pair count than the greedy result.
Statement
theorem bpe_partial_residual_can_exceed_greedy :
∃ s g p : List ℕ, bpe_greedy_step s g ∧ bpe_partial_step s p ∧
bpe_max_pair_count g < bpe_max_pair_count p- Source
- Exact counterexample to a residual-count dominance route for OP-1287; experiment 34404.
- Verified
- 19 Nov 2026
- Axioms
Classical.choiceQuot.soundpropext- Built on 6
- 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_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_pair_countThe number of occurrences of the ordered symbol pair replaced by the left-to-right nonoverlapping full merge.
The proof, explained
The theorem is proved by constructing an explicit counterexample: the string s = [0, 0, 1, 0, 0, 0, 1, 0]. A greedy merge on the most frequent pair (0, 0) replaces non-overlapping pairs left-to-right to produce g = [2, 1, 2, 0, 1, 0], in which no pair appears more than once. In contrast, a partial merge that skips the middle zero of the triple 0, 0, 0 produces p = [2, 1, 0, 2, 1, 0], creating two identical blocks [2, 1, 0] whose adjacent pairs occur twice, thereby strictly exceeding the greedy result's maximum pair count.
The candidate lists `s = [0, 0, 1, 0, 0, 0, 1, 0]`, `g = bpe_full_merge 0 0 2 s = [2, 1, 2, 0, 1, 0]`, and `p = [2, 1, 0, 2, 1, 0]` satisfy `bpe_max_pair_count g < bpe_max_pair_count p`. automation
We provide explicit witness lists `s`, `g`, and `p`. In `g`, every adjacent pair appears at most once, giving a maximum pair count of 1. In `p`, the sublist `[2, 1, 0]` appears twice, giving the pairs `(2, 1)` and `(1, 0)` a count of 2. Lean's `decide` tactic evaluates both counts directly and confirms that 1 < 2, leaving the validity of the steps `bpe_greedy_step s g` and `bpe_partial_step s p` to be shown.
refine ⟨[0,0,1,0,0,0,1,0], bpe_full_merge 0 0 2 [0,0,1,0,0,0,1,0], [2,1,0,2,1,0], ?_, ?_, by decide⟩
`g` is a valid greedy merge step from `s` (`bpe_greedy_step s g`). automation
A greedy step consists of either halting when no pair occurs, or greedily merging all non-overlapping occurrences of a most frequent pair with a fresh token. Selecting the merge branch (`right`), we choose the pair `(0, 0)` and fresh token 2. Computation via `decide` verifies that `s` has a strictly positive maximum pair count, that `(0, 0)` achieves this maximum count (which is 2), and that 2 does not appear in `s`. The resulting list `g` is identical to `bpe_full_merge 0 0 2 s` by definition (`rfl`).
· right exact ⟨0,0,2, by decide, by decide, by decide, rfl⟩
`p` is a valid partial merge step from `s` (`bpe_partial_step s p`). automation
A partial step allows merging any subset of occurrences of a pair into a fresh token. Choosing the merge branch (`right`), we instantiate the pair as `(0, 0)` and the token as 2, verifying `2 ∉ s` by `decide`. Simplifying with the inductive definition of `bpe_partial_merge` confirms that `p = [2, 1, 0, 2, 1, 0]` is obtained by merging the first occurrence of `(0, 0)`, skipping the next `0`, and merging the subsequent `(0, 0)`.
uses
bpe_partial_merge· right refine ⟨0,0,2, by decide, ?_⟩ simp [bpe_partial_merge]
bpe_partial_merge- A relation stating that list `t` is obtained from list `s` by replacing zero or more occurrences of the pair `(a, b)` with symbol `z`.
- The maximum pair counts, pair frequencies, token non-membership conditions, and the inductive reachability of the partial merge are all evaluated by Lean's computational automation (`decide` and `simp`) 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 bpe_partial_residual_can_exceed_greedy : ∃ s g p : List ℕ, bpe_greedy_step s g ∧ bpe_partial_step s p ∧ bpe_max_pair_count g < bpe_max_pair_count p := by refine ⟨[0,0,1,0,0,0,1,0], bpe_full_merge 0 0 2 [0,0,1,0,0,0,1,0], [2,1,0,2,1,0], ?_, ?_, by decide⟩ · right exact ⟨0,0,2, by decide, by decide, by decide, rfl⟩ · right refine ⟨0,0,2, by decide, ?_⟩ simp [bpe_partial_merge]