AFTD Auto-Formalizing Theoretical Domains

bpe_retyping_three_of_numeric_bounds

theoremverified

If the three-merge optimum is at most three initial maximum pair counts, it is at most the two-merge optimum plus one initial maximum, and the two-merge optimum is bounded by the initial maximum plus twice the maximum after any first greedy step, then for every greedy prefix of length i less than three its optimal three-merge utility is at most twice the prefix saving plus three times the maximum pair count at the resulting string.

Statement

theorem bpe_retyping_three_of_numeric_bounds
    (s t : List ℕ) (i : ℕ) (hi : i < 3)
    (hg : bpe_steps bpe_greedy_step i s t)
    (hinit : bpe_optimal_utility s 3 ≤ 3 * bpe_max_pair_count s)
    (hgrowth : bpe_optimal_utility s 3 ≤ bpe_optimal_utility s 2 + bpe_max_pair_count s)
    (htwo : ∀ u, bpe_greedy_step s u →
      bpe_optimal_utility s 2 ≤ bpe_max_pair_count s + 2 * bpe_max_pair_count u) :
    bpe_optimal_utility s 3 ≤ 2 * (s.length - t.length) + 3 * bpe_max_pair_count t
Source
Arithmetic reduction for the budget-three case of OP-1287.
Verified
19 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 7
  • bpe_three_two_step_bound_of_numeric_boundsFor two greedy steps s to u to v, if the optimal three-merge utility is at most the two-merge optimum plus the initial maximum pair count,…
  • bpe_stepsExactly k applications of the specified binary relation connect the input and output strings.
  • bpe_greedy_step_utility_eq_maxA greedy full-merge step decreases the string length by exactly the maximum nonoverlapping adjacent-pair count, including the unchanged…
  • bpe_greedy_step_length_leAny greedy full byte-pair merge step produces an output string of length at most the input string length.
  • bpe_optimal_utilityThe supremum, over strings reachable in k partial-merge steps, of the reduction in length of the input string.
  • 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 proof proceeds by case analysis on the prefix length i < 3, which must be 0, 1, or 2. When i = 0, no steps are taken (t = s) and the claim reduces directly to the initial bound hypothesis hinit. When i = 1, one greedy step is taken, reducing the string length by the initial maximum pair count, and combining the growth assumption with the two-merge bound htwo yields the inequality by linear arithmetic. When i = 2, an auxiliary theorem shows that two greedy steps already bound the three-merge optimum by twice the length reduction alone, from which the result follows immediately.

  1. The prefix length i is either 0, 1, or 2, reducing the theorem to these three cases.

    Since i is a natural number strictly less than 3, it must be 0, 1, or 2. We deduce this disjunction by linear integer arithmetic (omega) and split into the three corresponding cases.

    lines 9–10

      have hc : i = 0 ∨ i = 1 ∨ i = 2 := by omega
      rcases hc with rfl | rfl | rfl
  2. The bound holds when i = 0.

    By definition of bpe_steps, zero steps means t = s. The prefix length reduction is s.length - s.length = 0, so the goal simplifies to bounding the optimal three-merge utility by 3 * bpe_max_pair_count s, which is exactly the hypothesis hinit.

    lines 11–13

    uses bpe_steps

      · simp only [bpe_steps] at hg
        subst t
        simpa using hinit
  3. The bound holds when i = 1.

    Unfolding bpe_steps for i = 1 reveals that s undergoes a single greedy step to an intermediate string u = t. By bpe_greedy_step_utility_eq_max, the length reduction s.length - u.length is bpe_max_pair_count s, and by bpe_greedy_step_length_le, u is no longer than s. The hypothesis htwo gives an upper bound on the two-merge optimum at s in terms of bpe_max_pair_count s and 2 * bpe_max_pair_count u. Adding this to the growth assumption hgrowth gives an upper bound of 2 * bpe_max_pair_count s + 2 * bpe_max_pair_count u, which linear integer arithmetic (omega) matches to 2 * (s.length - u.length) + 3 * bpe_max_pair_count u.

    lines 14–20

    uses bpe_steps, bpe_greedy_step_length_le, bpe_greedy_step_utility_eq_max

      · rcases hg with ⟨u, hu, heq⟩
        simp only [bpe_steps] at heq
        subst t
        have hlen := bpe_greedy_step_length_le s u hu
        have hval := bpe_greedy_step_utility_eq_max s u hu
        have hb := htwo u hu
        omega
  4. The bound holds when i = 2.

    Unfolding bpe_steps for i = 2 decomposes the path into two consecutive greedy steps s to u and u to v, with t = v. Applying the lemma bpe_three_two_step_bound_of_numeric_bounds directly shows that the three-merge optimum is at most 2 * (s.length - v.length). Since 3 * bpe_max_pair_count v is non-negative, the target inequality follows immediately by linear arithmetic (omega).

    lines 21–25

    uses bpe_steps, bpe_three_two_step_bound_of_numeric_bounds

      · rcases hg with ⟨u, hu, v, hv, heq⟩
        simp only [bpe_steps] at heq
        subst t
        have hb := bpe_three_two_step_bound_of_numeric_bounds s u v hu hv hgrowth (htwo u hu)
        omega
bpe_steps
Under a transition relation R, 0 steps from s to t means s = t, and k + 1 steps means there is an intermediate list u such that R s u and k steps connect u to t.
bpe_greedy_step_length_le
A greedy BPE step never increases the length of the list.
bpe_greedy_step_utility_eq_max
The length reduction achieved by a greedy BPE step from s to t equals the maximum pair count in s.
bpe_three_two_step_bound_of_numeric_bounds
If s transitions greedily to u and u transitions greedily to v, the three-merge optimum is bounded by the two-merge optimum plus the initial maximum, and the two-merge optimum is bounded by the initial maximum plus twice the intermediate maximum, then the three-merge optimum is at most twice the length reduction from s to v.

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

theorem bpe_retyping_three_of_numeric_bounds    (s t : List ℕ) (i : ℕ) (hi : i < 3)    (hg : bpe_steps bpe_greedy_step i s t)    (hinit : bpe_optimal_utility s 3 ≤ 3 * bpe_max_pair_count s)    (hgrowth : bpe_optimal_utility s 3 ≤ bpe_optimal_utility s 2 + bpe_max_pair_count s)    (htwo : ∀ u, bpe_greedy_step s u →      bpe_optimal_utility s 2 ≤ bpe_max_pair_count s + 2 * bpe_max_pair_count u) :    bpe_optimal_utility s 3 ≤ 2 * (s.length - t.length) + 3 * bpe_max_pair_count t := by  have hc : i = 0 ∨ i = 1 ∨ i = 2 := by omega  rcases hc with rfl | rfl | rfl  · simp only [bpe_steps] at hg    subst t    simpa using hinit  · rcases hg with ⟨u, hu, heq⟩    simp only [bpe_steps] at heq    subst t    have hlen := bpe_greedy_step_length_le s u hu    have hval := bpe_greedy_step_utility_eq_max s u hu    have hb := htwo u hu    omega  · rcases hg with ⟨u, hu, v, hv, heq⟩    simp only [bpe_steps] at heq    subst t    have hb := bpe_three_two_step_bound_of_numeric_bounds s u v hu hv hgrowth (htwo u hu)    omega
See it in the graphDiscuss this resultChallenge it