AFTD Auto-Formalizing Theoretical Domains

op_2130_right_moves_are_greedy

theoremverified

If the first endpoint has at least the discrepancy of the second endpoint before every move in the all-false trajectory, greedy with all-false coins chooses false at every request.

Statement

theorem op_2130_right_moves_are_greedy (n : ℕ) (edges : List (Fin n × Fin n)) (h : ∀ k (hk : k < edges.length), let d := (edges.take k).foldl (fun d e => carpool_step n d e false) (fun _ => 0); d (edges[k]).2 ≤ d (edges[k]).1) : carpool_greedy_orientations n edges (List.replicate edges.length false) = List.replicate edges.length false
Source
OP-2130: identify a deterministic legal right-moving trajectory with randomized greedy on an all-false coin tape
Verified
22 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 2
  • carpool_stepIn online carpooling on n vertices, given an edge e joining two distinct vertices and an orientation bit b, the discrepancy vector d…
  • carpool_greedy_orientationsGiven a list of edges and a list of tie-breaking coins, randomized greedy carpooling orients each edge toward the endpoint with smaller…
Used by 2
  • op_2130_path_cascade_witnessFor every D ≥ 1 there is an edge sequence on SimpleGraph.pathGraph (2*D) of length at most D^3 and one coin tape whose greedy run reaches…
  • op_2130_terminal_path_cascade_witnessFor every positive D, there is a fixed sequence of at most D³ requests on the 2D-vertex path and a fixed coin tape for which the terminal…

The proof, explained

Under the assumption that along the all-false trajectory the second endpoint of every requested edge has at most the discrepancy of the first endpoint, the greedy algorithm with all-false coins chooses false at every step. The proof first proves an auxiliary lemma by induction on the edge list for an arbitrary initial discrepancy: at each edge, the discrepancy condition ensures the greedy rule never chooses true, so it selects false (either by strict inequality or tie-breaking) and matches the induction hypothesis on the tail. The main theorem then follows immediately by specializing this auxiliary lemma to the initial all-zero discrepancy vector.

  1. The auxiliary lemma holds when the edge list is empty.

    We proceed by induction on the list of edges es, generalizing over the initial discrepancy state d. In the base case where es is empty, both carpool_greedy_orientations.aux and List.replicate immediately evaluate to the empty list by definition.

    lines 6–7

    uses carpool_greedy_orientations.aux

      induction es generalizing d with
      | nil => simp [carpool_greedy_orientations.aux]
  2. For the first edge e in e :: es, the discrepancy of the second endpoint is at most that of the first: d e.2 ≤ d e.1.

    In the inductive step on e :: es, we instantiate the hypothesis h at index k = 0, which is valid since 0 < (e :: es).length. Taking zero edges leaves the initial discrepancy d unchanged, and the zeroth edge is e, so h directly gives d e.2 ≤ d e.1.

    lines 8–12

      | cons e es ih =>
        have h0 : d e.2 ≤ d e.1 := by
          have hh := h 0 (by simp)
          dsimp at hh
          exact hh
  3. The discrepancy hypothesis is preserved for the tail es starting from the updated discrepancy carpool_step n d e false.

    For any index k < es.length, we instantiate hypothesis h at k + 1, which is strictly less than (e :: es).length by linear arithmetic. Taking k + 1 elements of e :: es equals e followed by taking k elements of es by List.take_succ_cons. Folding the all-false update across this prefix corresponds to starting from carpool_step n d e false and updating along es.take k, while the (k + 1)-th edge of e :: es is es[k]. Thus the required inequality holds for the tail.

    lines 13–18

    uses List.take_succ_cons

        have htail : ∀ k (hk : k < es.length),
          let s := (es.take k).foldl (fun d e => carpool_step n d e false) (carpool_step n d e false)
          s (es[k]).2 ≤ s (es[k]).1 := by
          intro k hk
          have hh := h (k + 1) (by simp; omega)
          simpa [List.take_succ_cons] using hh
  4. The auxiliary lemma holds for e :: es with initial discrepancy d.

    We expand the definition of carpool_greedy_orientations.aux on e :: es. The first tie-breaking coin is false. Since d e.2 ≤ d e.1, we have ¬(d e.1 < d e.2) by not_lt.mpr, so the greedy rule does not choose true. Whether d e.2 < d e.1 holds strictly or there is a tie, it chooses false. The recursive call on the tail es starting from the updated state evaluates to List.replicate es.length false by the induction hypothesis, completing the inductive step.

    lines 19–20

    uses List.length_cons, List.replicate_succ, carpool_greedy_orientations.aux, not_lt.mpr

        simp only [List.length_cons, List.replicate_succ, carpool_greedy_orientations.aux]
        simp [not_lt.mpr h0, ih _ htail]
  5. The greedy algorithm with all-false coins chooses false for every edge starting from the all-zero discrepancy.

    Unfolding carpool_greedy_orientations shows that it calls carpool_greedy_orientations.aux starting with the all-zero discrepancy function (fun _ => 0). Applying the auxiliary lemma op2130_aux_false_greedy directly yields the desired result.

    lines 23–24

    uses op2130_aux_false_greedy

      unfold carpool_greedy_orientations
      exact op2130_aux_false_greedy n edges (fun _ => 0) h
carpool_greedy_orientations.aux
The recursive helper function that computes the list of greedy orientation decisions for a list of edges, given coin flips for tie-breaking and the current discrepancy vector.
List.take_succ_cons
Taking i + 1 elements from a list a :: as yields a followed by taking i elements from as.
List.length_cons
The length of a list a :: as is one more than the length of as.
List.replicate_succ
Replicating an element n + 1 times yields the element prepended to the element replicated n times.
not_lt.mpr
If b ≤ a, then a is not strictly less than b (¬(a < b)).
op2130_aux_false_greedy
If the discrepancy of the second endpoint never exceeds that of the first endpoint along the all-false trajectory, greedy with all-false coins chooses false at every step, starting from any initial discrepancy.

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

private lemma op2130_aux_false_greedy (n : ℕ) (es : List (Fin n × Fin n)) (d : Fin n → ℤ)    (h : ∀ k (hk : k < es.length),      let s := (es.take k).foldl (fun d e => carpool_step n d e false) d      s (es[k]).2 ≤ s (es[k]).1) :    carpool_greedy_orientations.aux n es (List.replicate es.length false) d = List.replicate es.length false := by  induction es generalizing d with  | nil => simp [carpool_greedy_orientations.aux]  | cons e es ih =>    have h0 : d e.2 ≤ d e.1 := by      have hh := h 0 (by simp)      dsimp at hh      exact hh    have htail : ∀ k (hk : k < es.length),      let s := (es.take k).foldl (fun d e => carpool_step n d e false) (carpool_step n d e false)      s (es[k]).2 ≤ s (es[k]).1 := by      intro k hk      have hh := h (k + 1) (by simp; omega)      simpa [List.take_succ_cons] using hh    simp only [List.length_cons, List.replicate_succ, carpool_greedy_orientations.aux]    simp [not_lt.mpr h0, ih _ htail]theorem op_2130_right_moves_are_greedy (n : ℕ) (edges : List (Fin n × Fin n)) (h : ∀ k (hk : k < edges.length), let d := (edges.take k).foldl (fun d e => carpool_step n d e false) (fun _ => 0); d (edges[k]).2 ≤ d (edges[k]).1) : carpool_greedy_orientations n edges (List.replicate edges.length false) = List.replicate edges.length false := by  unfold carpool_greedy_orientations  exact op2130_aux_false_greedy n edges (fun _ => 0) h
See it in the graphDiscuss this resultChallenge it