bpe_partial_old_pair_count_le
If neither queried symbol is the fresh output symbol, the nonoverlapping count of that ordered pair cannot increase under a partial merge.
Statement
theorem bpe_partial_old_pair_count_le
(a b z : ℕ) (s t : List ℕ) (hz : z ∉ s)
(h : bpe_partial_merge a b z s t) (x y : ℕ) (hx : x ≠ z) (hy : y ≠ z) :
bpe_pair_count x y t ≤ bpe_pair_count x y s- Source
- Helper for arXiv:2611.08671v1, Lemma 17, and OP-1287: compare one pair count across a partial merge.
- Verified
- 20 Nov 2026
- Axioms
Classical.choiceQuot.soundpropext- Built on 2
- bpe_partial_mergeThe relation between input and output strings obtained by replacing an arbitrary subset of pairwise nonoverlapping occurrences of the…
- bpe_pair_countThe number of occurrences of the ordered symbol pair replaced by the left-to-right nonoverlapping full merge.
The proof, explained
The proof shows that partial merges cannot increase the count of pairs (x, y) when neither x nor y is the newly created symbol z. It proceeds by strong induction on the length of the input list s. In each step, prepending a symbol never decreases pair counts, and because x ≠ z, the merged symbol z cannot create any new occurrences of (x, y), while any occurrence in the output must already correspond to an occurrence in the input.
For any list L of length at most 0, prepending w changes the pair count by at most 1 and does not decrease it. automation
Since L has length at most 0, it must be empty. The pair count of an empty list is 0, and the pair count of a single-element list [w] is also 0, so the bounds 0 ≤ 0 ≤ 1 hold trivially.
uses
List.length_eq_zero_iff.mp,Nat.le_zero.mp| 0, w, L, hL => by rw [List.length_eq_zero_iff.mp (Nat.le_zero.mp hL)] simp [bpe_pair_count]
If L is empty, prepending w preserves or increases the pair count by at most 1. automation
When L is empty, count([]) = 0 and count([w]) = 0, so the bounds 0 ≤ 0 ≤ 1 hold immediately.
| n+1, w, L, hL => by match L, hL with | [], _ => simp [bpe_pair_count]
If L = u :: L' and (w, u) = (a, b), prepending w changes the pair count by at most 1 and does not decrease it.
Since (w, u) matches the target pair (a, b), the pair count of w :: u :: L' is 1 + count(L'). By induction hypothesis on L', count(L') ≤ count(u :: L') ≤ count(L') + 1. The lower bound count(u :: L') ≤ 1 + count(L') follows by linear arithmetic. The upper bound 1 + count(L') ≤ count(u :: L') + 1 reduces to count(L') ≤ count(u :: L'), which holds by the induction hypothesis on L'.
uses
List.length_cons,bpe_pocl_count_cons_bounds| u :: L', hL' => simp only [List.length_cons] at hL' by_cases hwu : w = a ∧ u = b · have hc : bpe_pair_count a b (w :: u :: L') = 1 + bpe_pair_count a b L' := by simp [bpe_pair_count, hwu] have ih := bpe_pocl_count_cons_bounds a b n u L' (by omega) rw [hc] constructor · omega · match L', hL' with | [], _ => simp [bpe_pair_count] | v :: L'', hL'' => have ih2 := bpe_pocl_count_cons_bounds a b n v L'' (by simp at hL'' ⊢; omega) omegaIf L = u :: L' and (w, u) ≠ (a, b), prepending w preserves the pair count. automation
Since (w, u) does not match (a, b), the pair count of w :: u :: L' is simply count(u :: L'). The bounds count(u :: L') ≤ count(u :: L') ≤ count(u :: L') + 1 then hold trivially.
· have hc : bpe_pair_count a b (w :: u :: L') = bpe_pair_count a b (u :: L') := by simp [bpe_pair_count, hwu] rw [hc]; omega
For a list s of length at most 0, any partial merge preserves or decreases the pair count of (x, y). automation
Since s has length at most 0, s is the empty list. By definition of partial merge, the output t must also be empty. Both counts are 0, so the inequality holds by reflexivity.
uses
List.length_eq_zero_iff.mp,Nat.le_zero.mp,le_rfl| 0, s, t, hs, h => by rw [List.length_eq_zero_iff.mp (Nat.le_zero.mp hs)] at h ⊢ simp [bpe_partial_merge] at h subst h; exact le_rfl
If s is empty, any partial merge preserves or decreases the pair count of (x, y). automation
When s is empty, the partial merge relation forces t to be empty, and the inequality holds by reflexivity.
uses
le_rfl| n+1, [], t, _, h => by simp [bpe_partial_merge] at h; subst h; exact le_rfl
If s has length 1, any partial merge preserves or decreases the pair count of (x, y). automation
When s = [x0], a partial merge cannot merge any pair, so t = [x0], and the claim holds by reflexivity.
uses
le_rfl| n+1, [x0], t, _, h => by simp [bpe_partial_merge] at h; subst h; exact le_rfl
If the first symbol x0 is kept and the merged tail is empty, the pair count does not increase. automation
When x0 is kept and out is empty, the output is [x0], which has pair count 0, so the inequality holds trivially.
uses
List.length_cons,bpe_pocl_main| n+1, x0 :: y0 :: xs, t, hs, h => by simp only [List.length_cons] at hs rcases h with ⟨out, rfl, hout⟩ | ⟨hxa, hyb, out, rfl, hout⟩ · -- keep x0 have ih := bpe_pocl_main a b z x y hx hy n (y0 :: xs) out (by simp; omega) hout match out, hout, ih with | [], _, _ => simp [bpe_pair_count] | o1 :: out', hout', ih' =>
If x0 is kept and out = o1 :: out' with (x0, o1) = (x, y), the pair count does not increase.
Since (x0, o1) = (x, y), count(t) = 1 + count(out'). Because y ≠ z, the first step on y0 :: xs could not have created z, so o1 must be y0, giving y0 = y. If xs is empty, both lists are [x, y]. If xs = x1 :: xs', the input list also starts with (x, y), so count(s) = 1 + count(x1 :: xs'). By induction hypothesis on the remaining merge, count(out') ≤ count(x1 :: xs'), which completes the inequality.
uses
bpe_pocl_main,List.cons.injEqby_cases hxo : x0 = x ∧ o1 = y · -- o1 is an old symbol, so it is y0 and the rest is a merge of xs have hc1 : bpe_pair_count x y (x0 :: o1 :: out') = 1 + bpe_pair_count x y out' := by simp [bpe_pair_count, hxo] match xs, hout', hs with | [], hout'', _ => simp [bpe_partial_merge] at hout'' obtain ⟨rfl, rfl⟩ := hout'' simp [bpe_pair_count, hxo] | x1 :: xs', hout'', hs' => rcases hout'' with ⟨out2, hout2, hpm⟩ | ⟨-, -, out2, hout2, hpm⟩ · simp only [List.cons.injEq] at hout2 obtain ⟨ho1, hoe⟩ := hout2 have hy0 : y0 = y := ho1.symm.trans hxo.2 have hc2 : bpe_pair_count x y (x0 :: y0 :: x1 :: xs') = 1 + bpe_pair_count x y (x1 :: xs') := by simp [bpe_pair_count, hxo.1, hy0] have ih2 := bpe_pocl_main a b z x y hx hy n (x1 :: xs') out2 (by simp at hs' ⊢; omega) hpm rw [hc1, hc2, hoe]; omega · simp only [List.cons.injEq] at hout2 exact absurd (hxo.2.symm.trans hout2.1) hy
If x0 is kept and out = o1 :: out' with (x0, o1) ≠ (x, y), the pair count does not increase.
Since the first two output symbols do not form the pair (x, y), count(t) = count(o1 :: out'). By induction hypothesis, count(o1 :: out') ≤ count(y0 :: xs). Since prepending x0 cannot decrease the count (bpe_pocl_cons_le), transitivity yields the result.
uses
le_trans,bpe_pocl_cons_le· have hc1 : bpe_pair_count x y (x0 :: o1 :: out') = bpe_pair_count x y (o1 :: out') := by simp [bpe_pair_count, hxo] rw [hc1] exact le_trans ih' (bpe_pocl_cons_le x y x0 (y0 :: xs))
If (x0, y0) is merged into z, the pair count does not increase.
Here t = z :: out where out is a partial merge of xs. By induction hypothesis, count(out) ≤ count(xs). Since x ≠ z, the symbol z cannot form an (x, y) pair with the next symbol, so count(z :: out) ≤ count(out). Monotonicity of prepending y0 and x0 (bpe_pocl_cons_le) shows count(xs) ≤ count(x0 :: y0 :: xs), completing the bound by transitivity.
uses
bpe_pocl_main,le_trans,bpe_pocl_cons_le· -- merge a b into z have ih := bpe_pocl_main a b z x y hx hy n xs out (by omega) hout have hz : bpe_pair_count x y (z :: out) ≤ bpe_pair_count x y out := by match out with | [] => simp [bpe_pair_count] | o :: out' => have : ¬ (z = x ∧ o = y) := fun h => hx h.1.symm simp [bpe_pair_count, this] exact le_trans hz (le_trans ih (le_trans (bpe_pocl_cons_le x y y0 xs) (bpe_pocl_cons_le x y x0 (y0 :: xs))))
The pair count of (x, y) in t is at most that in s under any partial merge, provided x ≠ z and y ≠ z.
Specialising the helper theorem bpe_pocl_main to the length of s immediately yields the result.
uses
bpe_pocl_main,le_rfltheorem bpe_partial_old_pair_count_le (a b z : ℕ) (s t : List ℕ) (hz : z ∉ s) (h : bpe_partial_merge a b z s t) (x y : ℕ) (hx : x ≠ z) (hy : y ≠ z) : bpe_pair_count x y t ≤ bpe_pair_count x y s := by exact bpe_pocl_main a b z x y hx hy s.length s t le_rfl h
List.length_eq_zero_iff.mp- A list has length 0 if and only if it is the empty list.
Nat.le_zero.mp- If a natural number is at most 0, it is equal to 0.
List.length_cons- The length of a list with an element prepended is one more than the length of the tail.
bpe_pocl_count_cons_bounds- Prepending an element to a list either preserves the pair count or increases it by 1.
bpe_pocl_cons_le- Prepending an element to a list does not decrease its pair count.
bpe_pocl_main- Under a partial merge, the count of any pair of symbols distinct from the merged symbol does not increase.
List.cons.injEq- Two non-empty lists are equal if and only if their heads are equal and their tails are equal.
le_trans- Inequality on numbers is transitive: if a ≤ b and b ≤ c, then a ≤ c.
le_rfl- Inequality on numbers is reflexive: a ≤ a.
- The hypothesis hz (that z ∉ s) in the main theorem bpe_partial_old_pair_count_le is unused in the formal proof; only the conditions x ≠ z and y ≠ z are needed.
- The helper lemma bpe_pocl_count_cons_bounds proves both lower and upper bounds on the pair count after consing an element, but only the lower bound (bpe_pocl_cons_le) is needed in the rest of the proof.
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.
theorem bpe_pocl_count_cons_bounds (a b : ℕ) : ∀ (n : ℕ) (w : ℕ) (L : List ℕ), L.length ≤ n → bpe_pair_count a b L ≤ bpe_pair_count a b (w :: L) ∧ bpe_pair_count a b (w :: L) ≤ bpe_pair_count a b L + 1 | 0, w, L, hL => by rw [List.length_eq_zero_iff.mp (Nat.le_zero.mp hL)] simp [bpe_pair_count] | n+1, w, L, hL => by match L, hL with | [], _ => simp [bpe_pair_count] | u :: L', hL' => simp only [List.length_cons] at hL' by_cases hwu : w = a ∧ u = b · have hc : bpe_pair_count a b (w :: u :: L') = 1 + bpe_pair_count a b L' := by simp [bpe_pair_count, hwu] have ih := bpe_pocl_count_cons_bounds a b n u L' (by omega) rw [hc] constructor · omega · match L', hL' with | [], _ => simp [bpe_pair_count] | v :: L'', hL'' => have ih2 := bpe_pocl_count_cons_bounds a b n v L'' (by simp at hL'' ⊢; omega) omega · have hc : bpe_pair_count a b (w :: u :: L') = bpe_pair_count a b (u :: L') := by simp [bpe_pair_count, hwu] rw [hc]; omegatheorem bpe_pocl_cons_le (a b w : ℕ) (L : List ℕ) : bpe_pair_count a b L ≤ bpe_pair_count a b (w :: L) := (bpe_pocl_count_cons_bounds a b L.length w L le_rfl).1theorem bpe_pocl_main (a b z x y : ℕ) (hx : x ≠ z) (hy : y ≠ z) : ∀ (n : ℕ) (s t : List ℕ), s.length ≤ n → bpe_partial_merge a b z s t → bpe_pair_count x y t ≤ bpe_pair_count x y s | 0, s, t, hs, h => by rw [List.length_eq_zero_iff.mp (Nat.le_zero.mp hs)] at h ⊢ simp [bpe_partial_merge] at h subst h; exact le_rfl | n+1, [], t, _, h => by simp [bpe_partial_merge] at h; subst h; exact le_rfl | n+1, [x0], t, _, h => by simp [bpe_partial_merge] at h; subst h; exact le_rfl | n+1, x0 :: y0 :: xs, t, hs, h => by simp only [List.length_cons] at hs rcases h with ⟨out, rfl, hout⟩ | ⟨hxa, hyb, out, rfl, hout⟩ · -- keep x0 have ih := bpe_pocl_main a b z x y hx hy n (y0 :: xs) out (by simp; omega) hout match out, hout, ih with | [], _, _ => simp [bpe_pair_count] | o1 :: out', hout', ih' => by_cases hxo : x0 = x ∧ o1 = y · -- o1 is an old symbol, so it is y0 and the rest is a merge of xs have hc1 : bpe_pair_count x y (x0 :: o1 :: out') = 1 + bpe_pair_count x y out' := by simp [bpe_pair_count, hxo] match xs, hout', hs with | [], hout'', _ => simp [bpe_partial_merge] at hout'' obtain ⟨rfl, rfl⟩ := hout'' simp [bpe_pair_count, hxo] | x1 :: xs', hout'', hs' => rcases hout'' with ⟨out2, hout2, hpm⟩ | ⟨-, -, out2, hout2, hpm⟩ · simp only [List.cons.injEq] at hout2 obtain ⟨ho1, hoe⟩ := hout2 have hy0 : y0 = y := ho1.symm.trans hxo.2 have hc2 : bpe_pair_count x y (x0 :: y0 :: x1 :: xs') = 1 + bpe_pair_count x y (x1 :: xs') := by simp [bpe_pair_count, hxo.1, hy0] have ih2 := bpe_pocl_main a b z x y hx hy n (x1 :: xs') out2 (by simp at hs' ⊢; omega) hpm rw [hc1, hc2, hoe]; omega · simp only [List.cons.injEq] at hout2 exact absurd (hxo.2.symm.trans hout2.1) hy · have hc1 : bpe_pair_count x y (x0 :: o1 :: out') = bpe_pair_count x y (o1 :: out') := by simp [bpe_pair_count, hxo] rw [hc1] exact le_trans ih' (bpe_pocl_cons_le x y x0 (y0 :: xs)) · -- merge a b into z have ih := bpe_pocl_main a b z x y hx hy n xs out (by omega) hout have hz : bpe_pair_count x y (z :: out) ≤ bpe_pair_count x y out := by match out with | [] => simp [bpe_pair_count] | o :: out' => have : ¬ (z = x ∧ o = y) := fun h => hx h.1.symm simp [bpe_pair_count, this] exact le_trans hz (le_trans ih (le_trans (bpe_pocl_cons_le x y y0 xs) (bpe_pocl_cons_le x y x0 (y0 :: xs))))theorem bpe_partial_old_pair_count_le (a b z : ℕ) (s t : List ℕ) (hz : z ∉ s) (h : bpe_partial_merge a b z s t) (x y : ℕ) (hx : x ≠ z) (hy : y ≠ z) : bpe_pair_count x y t ≤ bpe_pair_count x y s := by exact bpe_pocl_main a b z x y hx hy s.length s t le_rfl h