AFTD Auto-Formalizing Theoretical Domains

op2130_setup_replay_shift

theoremverified

A fixed local discrepancy schedule acts identically on a suffix when all its edge indices are shifted by the length of an untouched prefix.

Statement

theorem op2130_setup_replay_shift (p s : List ℤ) (ops : List (ℕ × Bool)) : op2130_setup_replay (p ++ s) (ops.map fun (j,c) => (p.length+j,c)) = p ++ op2130_setup_replay s ops
Source
OP-2130, shifting a local greedy discrepancy schedule
Verified
24 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 2

The proof, explained

The theorem is proved by induction on the list of operations ops. The base case is trivial as an empty schedule leaves p ++ s unchanged on both sides. For the inductive step, an auxiliary lemma (op2130_shift_aux_step) shows that a single discrepancy step on p ++ s at index |p| + j leaves prefix p untouched and modifies only suffix s at index j. Applying the induction hypothesis to the remaining operations on the updated suffix completes the proof.

  1. The element at index |p| + j in the concatenation p ++ s equals the element at index j in s.

    Since |p| ≤ |p| + j, List.getD_append_right shifts the lookup into the suffix s at index (|p| + j) - |p|, which simplifies to j.

    lines 3–5

    uses List.getD_append_right

      have h0 : (p ++ s).getD (p.length+j) 0 = s.getD j 0 := by
        rw [List.getD_append_right _ _ _ _ (by omega)]
        simp
  2. The element at index |p| + j + 1 in p ++ s equals the element at index j + 1 in s.

    Similarly, since |p| ≤ |p| + j + 1, List.getD_append_right shifts the lookup into s at index (|p| + j + 1) - |p|. Linear arithmetic verifies that (|p| + j + 1) - |p| = j + 1, matching the lookup in s at index j + 1.

    lines 6–9

    uses List.getD_append_right

      have h1 : (p ++ s).getD (p.length+j+1) 0 = s.getD (j+1) 0 := by
        rw [List.getD_append_right _ _ _ _ (by omega)]
        have hidx : p.length+j+1-p.length = j+1 := by omega
        rw [hidx]
  3. A single discrepancy step on p ++ s at index |p| + j leaves prefix p untouched and modifies only s at index j.

    Unfolding op2130_mc_step and substituting the two index lookups (h0 and h1), the step's comparison and increment delta depend only on the values at indices j and j + 1 of s. The resulting updates occur at indices |p| + j and |p| + (j + 1); by List.set_append_right and Nat.add_assoc, both updates bypass p and modify s at indices j and j + 1, producing p ++ op2130_mc_step s j c.

    lines 10–11

    uses List.set_append_right, Nat.add_assoc

      simp only [op2130_mc_step, h0, h1]
      simp [List.set_append_right, Nat.add_assoc]
  4. Unfold the definition of replay and establish the base case for an empty schedule ops = [].

    Unfolding op2130_setup_replay expresses the replay process as a left fold (List.foldl). We induct on ops, generalizing the suffix s. In the base case where ops is empty (nil), no steps are performed and both sides reduce definitionally to p ++ s.

    lines 14–16

      unfold op2130_setup_replay
      induction ops generalizing s with
      | nil => rfl
  5. The replay identity holds for any non-empty schedule (j, c) :: qs by the inductive hypothesis.

    Decompose the head operation into its index j and boolean coin c. By List.map_cons and List.foldl_cons, the fold executes the single step op2130_mc_step (p ++ s) (|p| + j) c first. The auxiliary lemma op2130_shift_aux_step rewrites this state to p ++ op2130_mc_step s j c. The inductive hypothesis applied to the updated suffix op2130_mc_step s j c completes the proof.

    lines 17–19

    uses List.map_cons, List.foldl_cons, op2130_shift_aux_step

      | cons q qs ih =>
          rcases q with ⟨j,c⟩
          simp only [List.map_cons, List.foldl_cons, op2130_shift_aux_step, ih]
List.getD_append_right
If an index n is at least the length of list l, looking up index n in the concatenation l ++ l' with default value d equals looking up index n - |l| in l'.
List.set_append_right
If an index i is at least the length of list s, updating index i in the concatenation s ++ t to value x equals concatenating s with list t updated at index i - |s|.
Nat.add_assoc
Addition of natural numbers is associative: (n + m) + k = n + (m + k).
op2130_shift_aux_step
Applying a single discrepancy step at index |p| + j to the concatenation p ++ s leaves prefix p untouched and applies the step to suffix s at index j.
List.map_cons
Mapping a function over a non-empty list a :: l yields f(a) :: map(f, l).
List.foldl_cons
Left-folding a binary operation over a non-empty list a :: l starting from accumulator b equals the left fold over tail l starting from accumulator f(b, 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 op2130_shift_aux_step (p s : List ℤ) (j : ℕ) (c : Bool) :    op2130_mc_step (p ++ s) (p.length+j) c = p ++ op2130_mc_step s j c := by  have h0 : (p ++ s).getD (p.length+j) 0 = s.getD j 0 := by    rw [List.getD_append_right _ _ _ _ (by omega)]    simp  have h1 : (p ++ s).getD (p.length+j+1) 0 = s.getD (j+1) 0 := by    rw [List.getD_append_right _ _ _ _ (by omega)]    have hidx : p.length+j+1-p.length = j+1 := by omega    rw [hidx]  simp only [op2130_mc_step, h0, h1]  simp [List.set_append_right, Nat.add_assoc]theorem op2130_setup_replay_shift (p s : List ℤ) (ops : List (ℕ × Bool)) : op2130_setup_replay (p ++ s) (ops.map fun (j,c) => (p.length+j,c)) = p ++ op2130_setup_replay s ops := by  unfold op2130_setup_replay  induction ops generalizing s with  | nil => rfl  | cons q qs ih =>      rcases q with ⟨j,c⟩      simp only [List.map_cons, List.foldl_cons, op2130_shift_aux_step, ih]
See it in the graphDiscuss this resultChallenge it