Elm Exactly

TheoremcopyLoop_succ

StandardElmMech/Stat/CopyLoop.lean:135, One round · tactic proof

A round: stop when nothing is to be translated, else translate and recur.

Statement

theorem copyLoop_succ (gid : Nat) (tr : Assignment → Except SpecError (Spec (List D.Def))) (fuel : Nat)
    (pending : List Assignment) (made : List (Assignment × List D.Def)) (out : List Req) :
    copyLoop gid tr (fuel + 1) pending made out =
      if todoOf pending made = [] then .ok (made, out)
      else match translateAll tr (todoOf pending made) with
        | .error e => .error e
        | .ok rs =>
          copyLoop gid tr fuel (((rs.flatMap (·.2.reqs)).filter (·.1 == gid)).map (·.2))
            (addMade made rs) (out ++ (rs.flatMap (·.2.reqs)).filter (·.1 != gid))

Proof

by
  rw [copyLoop]
  unfold todoOf
  cases h : dedupFirst (pending.filter fun a => !(made.any (·.1 == a))) with
  | nil => rfl
  | cons a l =>
    simp only [List.cons_ne_nil, ↓reduceIte]
    simp only [bind, Except.bind, addMade]
    cases translateAll tr (a :: l) <;> rfl

Proved with tactics, which Lean expands into a proof term that its kernel checks.

Used by

In StandardElmMech/Stat/CopyLoop.lean: The copy loop terminates within 2^k + 1 rounds, makes the least set of copies closed under requests, at most 2^k (copyLoop_fuel, copyLoop_least, copies_le_pow).

A Standard Definition of Elm? (Draft version 0.4) © Rupert Smith. The text is licensed under CC BY 4.0: share and adapt it freely, with credit and a link to the licence.