AFTD Auto-Formalizing Theoretical Domains

bpe_optimal_utility_le_iff

theoremverified

The optimal utility of k partial merge steps is at most B exactly when every string reachable in k such steps has length reduction at most B.

Statement

theorem bpe_optimal_utility_le_iff (s : List ℕ) (k B : ℕ) :
    bpe_optimal_utility s k ≤ B ↔
      ∀ t : List ℕ, bpe_steps bpe_partial_step k s t → s.length - t.length ≤ B
Source
Helper for OP-1287: bounded natural supremum characterizes the comparator optimum.
Verified
20 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 4
  • bpe_optimal_utilityThe supremum, over strings reachable in k partial-merge steps, of the reduction in length of the input string.
  • bpe_stepsExactly k applications of the specified binary relation connect the input and output strings.
  • 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…

The proof, explained

The optimal utility is defined as the supremum of the set of length reductions |s| - |t| over all strings t reachable from s in k partial merge steps. The proof first verifies that this set is nonempty (s reaches itself with reduction 0) and bounded above by |s| (since |s| - |t| ≤ |s|). The equivalence then reduces to the standard supremum property in a conditionally complete lattice: the supremum of a nonempty set is at most B if and only if every element in the set is at most B.

  1. The set of length reductions achievable in k partial merge steps is bounded above by the length of s.

    Unfolding the definition of `bpe_optimal_utility`, optimal utility is the supremum (sSup) of the set U of reductions s.length - t.length for all strings t reachable from s in k partial merge steps. To use order-theoretic lemmas on this supremum, we first show that U is bounded above, taking s.length as an upper bound since s.length - t.length ≤ s.length by `Nat.sub_le`.

    lines 8–10

    uses Nat.sub_le

      unfold bpe_optimal_utility
      have hbdd : BddAbove {u : ℕ | ∃ t, bpe_steps bpe_partial_step k s t ∧ u = s.length - t.length} :=
        ⟨s.length, by rintro u ⟨t, -, rfl⟩; exact Nat.sub_le _ _⟩
  2. The set of achievable length reductions is nonempty.

    By reflexivity of partial merge reachability (`bpe_ou_steps_refl`), s reaches itself in k steps with length reduction s.length - s.length = 0, so 0 ∈ U.

    lines 11–12

    uses bpe_ou_steps_refl

      have hne : ({u : ℕ | ∃ t, bpe_steps bpe_partial_step k s t ∧ u = s.length - t.length}).Nonempty :=
        ⟨s.length - s.length, s, bpe_ou_steps_refl k s, rfl⟩
  3. If the optimal utility is at most B, then every string reachable in k steps has length reduction at most B.

    We split the equivalence into both directions. For the forward direction, assume sSup U ≤ B. For any string t reachable from s in k steps, the reduction s.length - t.length is in U. Because U is bounded above (`hbdd`), s.length - t.length ≤ sSup U by `le_csSup`. Combining this with sSup U ≤ B via transitivity (`le_trans`) gives s.length - t.length ≤ B.

    lines 13–15

    uses le_csSup, le_trans

      constructor
      · intro h t ht
        exact le_trans (le_csSup hbdd ⟨t, ht, rfl⟩) h
  4. If every string reachable in k steps has length reduction at most B, then the optimal utility is at most B.

    For the converse, assume that every string t reachable in k steps satisfies s.length - t.length ≤ B. Since U is nonempty (`hne`), `csSup_le` states that sSup U ≤ B provided every element u ∈ U satisfies u ≤ B. Any such u is the length reduction of some reachable string t, so the assumption directly implies u ≤ B.

    lines 16–19

    uses csSup_le

      · intro h
        apply csSup_le hne
        rintro u ⟨t, ht, rfl⟩
        exact h t ht
Nat.sub_le
For any natural numbers n and m, n - m ≤ n.
bpe_ou_steps_refl
Any string s can reach itself in k partial merge steps.
le_csSup
If a set s is bounded above and an element a belongs to s, then a ≤ sSup s.
le_trans
Inequality is transitive: if a ≤ b and b ≤ c, then a ≤ c.
csSup_le
If a set s is nonempty and every element b ∈ s satisfies b ≤ a, then sSup s ≤ a.

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_ou_steps_refl : ∀ (k : ℕ) (s : List ℕ), bpe_steps bpe_partial_step k s s  | 0, _ => rfl  | k+1, s => ⟨s, Or.inl rfl, bpe_ou_steps_refl k s⟩theorem bpe_optimal_utility_le_iff (s : List ℕ) (k B : ℕ) :    bpe_optimal_utility s k ≤ B ↔      ∀ t : List ℕ, bpe_steps bpe_partial_step k s t → s.length - t.length ≤ B := by  unfold bpe_optimal_utility  have hbdd : BddAbove {u : ℕ | ∃ t, bpe_steps bpe_partial_step k s t ∧ u = s.length - t.length} :=    ⟨s.length, by rintro u ⟨t, -, rfl⟩; exact Nat.sub_le _ _⟩  have hne : ({u : ℕ | ∃ t, bpe_steps bpe_partial_step k s t ∧ u = s.length - t.length}).Nonempty :=    ⟨s.length - s.length, s, bpe_ou_steps_refl k s, rfl⟩  constructor  · intro h t ht    exact le_trans (le_csSup hbdd ⟨t, ht, rfl⟩) h  · intro h    apply csSup_le hne    rintro u ⟨t, ht, rfl⟩    exact h t ht
See it in the graphDiscuss this resultChallenge it