Theoremplace_spec
Statement
theorem place_spec : ∀ (k : Nat) (placed todo : List (List Nat)), Inv n r (placed ++ todo) →
Cover n (placed ++ todo) → todo.length ≤ k →
∃ out, place n r k placed todo = placed ++ out ∧ out.Perm todo ∧ ReadyList n r placed out
| 0, placed, todo, _, _, hk => by
have : todo = []Proof
List.eq_nil_of_length_eq_zero (by omega)
subst this
exact ⟨[], by simp [place], List.Perm.refl _, trivial⟩
| k + 1, placed, todo, hinv, hcov, hk => by
by_cases hne : todo = []
· subst hne
exact ⟨[], by simp [place], List.Perm.refl _, trivial⟩
obtain ⟨c, hc, hrd⟩ := exists_ready hinv hcov hne
cases hf : todo.find? (ready n r placed) with
| none => exact absurd hrd (List.find?_eq_none.mp hf c hc)
| some cmp =>
have hcmp := List.mem_of_find?_eq_some hf
have hready := List.find?_some hf
have hnd : todo.Nodup := (List.nodup_append.mp (inv_nodup hinv)).2.1
have hperm : todo.Perm (cmp :: todo.filter (· != cmp)) := by
rw [← hnd.erase_eq_filter]; exact List.perm_cons_erase hcmp
have hperm2 : (placed ++ todo).Perm ((placed ++ [cmp]) ++ todo.filter (· != cmp)) := by
rw [List.append_assoc]; exact List.Perm.append_left _ hperm
have hlen : (todo.filter (· != cmp)).length ≤ k := by
have := hperm.length_eq; simp at this; omega
obtain ⟨out, hout, hp, hrl⟩ := place_spec k (placed ++ [cmp]) (todo.filter (· != cmp))
(inv_perm hperm2 hinv) (cover_perm hperm2 hcov) hlen
refine ⟨cmp :: out, ?_, ?_, ⟨hready, hrl⟩⟩
· simp only [place, hf]; rw [hout]; simp
· exact (hp.cons cmp).trans hperm.symmProved by a term, which Lean's kernel checks directly.
Theorems it uses
Used by
In StandardElmMech/Src/GroupingProof.lean: components_valid: the canonical grouping is one the book allows (ValidNumbering).
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.