Elm Exactly

TheoremaliasOrderAux_spec

StandardElmMech/Src/AliasOrderProof.lean:150 · term proof

Statement

theorem aliasOrderAux_spec (hnd : (all.map (·.1)).Nodup)
    (hacyc : ∀ i < all.length, ¬ Plus all.length (mentionsIdx all) i i) :
    ∀ (k : Nat) (placed rest : List AliasD), (placed ++ rest).Perm all → rest.length ≤ k →
      ∃ out, aliasOrderAux all k placed rest = placed ++ out ∧ out.Perm rest ∧ AReadyList all placed out
  | 0, placed, rest, _, hk => by
    have : rest = []

Proof

List.eq_nil_of_length_eq_zero (by omega)
    subst this
    exact ⟨[], by simp [aliasOrderAux], List.Perm.refl _, trivial⟩
  | k + 1, placed, rest, hp, hk => by
    by_cases hne : rest = []
    · subst hne
      exact ⟨[], by simp [aliasOrderAux], List.Perm.refl _, trivial⟩
    obtain ⟨c, hc, hrd⟩ := exists_aReady hp hnd hacyc hne
    rw [aliasOrderAux_eq]
    cases hf : rest.find? (aReady all placed) with
    | none => exact absurd hrd (List.find?_eq_none.mp hf c hc)
    | some a =>
      simp only
      have ha := List.mem_of_find?_eq_some hf
      have hready := List.find?_some hf
      have hndr : (rest.map (·.1)).Nodup := by
        have := (hp.map (·.1)).nodup_iff.mpr hnd
        simp only [List.map_append] at this
        exact (List.nodup_append.mp this).2.1
      have hperm := perm_filter_name hndr ha
      have hperm2 : ((placed ++ [a]) ++ rest.filter (·.1 != a.1)).Perm all := by
        rw [List.append_assoc]; exact (List.Perm.append_left _ hperm.symm).trans hp
      have hlen : (rest.filter (·.1 != a.1)).length ≤ k := by
        have := hperm.length_eq; simp at this; omega
      obtain ⟨out, hout, hpo, hrl⟩ := aliasOrderAux_spec hnd hacyc k (placed ++ [a]) _ hperm2 hlen
      refine ⟨a :: out, ?_, (hpo.cons a).trans hperm.symm, ⟨hready, hrl⟩⟩
      rw [hout]; simp

Proved by a term, which Lean's kernel checks directly.

Theorems it uses

Used by

In StandardElmMech/Src/AliasOrderProof.lean: aliasOrder_valid: the canonical order of aliases is one the book allows.

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.