Elm Exactly

Theoremexists_ready

StandardElmMech/Src/GroupingProof.lean:181, Among the unplaced classes one is ready · tactic proof

Statement

theorem exists_ready {placed todo : List (List Nat)} (hinv : Inv n r (placed ++ todo))
    (hcov : Cover n (placed ++ todo)) (hne : todo ≠ []) : ∃ c ∈ todo, ready n r placed c = true

Proof

by
  have hcls : ∀ c ∈ todo, ∃ a, a < n ∧ c = cls n r a := fun c hc => hinv.1 c (List.mem_append_right _ hc)
  obtain ⟨c1, rest, htodo⟩ : ∃ c rest, todo = c :: rest := by
    cases todo with
    | nil => exact absurd rfl hne
    | cons c rest => exact ⟨c, rest, rfl⟩
  have hc1mem : c1 ∈ todo := by rw [htodo]; exact List.mem_cons_self
  obtain ⟨a1, ha1, hc1⟩ := hcls c1 hc1mem
  have hTne : todo.flatten ≠ [] := by
    intro h
    have : a1 ∈ todo.flatten := List.mem_flatten.mpr ⟨c1, hc1mem, by rw [hc1]; exact self_mem_cls ha1⟩
    rw [h] at this; simp at this
  obtain ⟨x0, hx0, hmin⟩ := exists_min (cnt n r todo.flatten) todo.flatten hTne
  obtain ⟨c0, hc0, hx0c⟩ := List.mem_flatten.mp hx0
  obtain ⟨a0, ha0, rfl⟩ := hcls c0 hc0
  refine ⟨cls n r a0, hc0, ?_⟩
  unfold ready
  apply List.all_eq_true.mpr
  intro a ha
  apply List.all_eq_true.mpr
  intro b hb
  have hbn : b < n := List.mem_range.mp hb
  simp only [Bool.or_eq_true, Bool.not_eq_true', List.any_eq_true, List.contains_iff_mem]
  cases hr : r a b
  · exact .inl (.inl rfl)
  by_cases hbc : b ∈ cls n r a0
  · exact .inl (.inr hbc)
  by_cases hbp : ∃ p ∈ placed, b ∈ p
  · exact .inr hbp
  exfalso
  obtain ⟨c, hc, hbc'⟩ := hcov b hbn
  have hcT : c ∈ todo := by
    rcases List.mem_append.mp hc with hc | hc
    · exact absurd ⟨c, hc, hbc'⟩ hbp
    · exact hc
  have hbT : b ∈ todo.flatten := List.mem_flatten.mpr ⟨c, hcT, hbc'⟩
  have hx := (mem_cls ha0).mp hx0c
  have haa := (mem_cls ha0).mp ha
  have hxb : Reach n r x0 b := reach_trans (mr_trans (mr_symm hx.2) haa.2).1 (reach_step haa.1 hbn hr)
  have hnb : ¬ Reach n r b x0 := fun h => hbc ((mem_cls ha0).mpr ⟨hbn, mr_trans hx.2 ⟨hxb, h⟩⟩)
  have hmono : ∀ y ∈ List.range n, (decide (y ∈ todo.flatten) && reachB n r b y) = true →
      (decide (y ∈ todo.flatten) && reachB n r x0 y) = true := by
    intro y _ hy
    simp only [Bool.and_eq_true, decide_eq_true_eq, reachB_iff] at hy ⊢
    exact ⟨hy.1, reach_trans hxb hy.2⟩
  have hle := len_filter_mono hmono
  have hne' : cnt n r todo.flatten b ≠ cnt n r todo.flatten x0 := by
    intro heq
    have := len_filter_eq hmono heq x0 (List.mem_range.mpr hx.1)
      (by simp only [Bool.and_eq_true, decide_eq_true_eq, reachB_iff]; exact ⟨hx0, reach_refl x0⟩)
    simp only [Bool.and_eq_true, decide_eq_true_eq, reachB_iff] at this
    exact hnb this.2
  have := hmin b hbT
  unfold cnt at hle hne' this
  omega

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

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.