Elm Exactly

Theoremcomponents_valid

StandardElmMech/Src/GroupingProof.lean:318, The canonical grouping is valid · tactic proof

Statement

theorem components_valid (n : Nat) (r : Nat → Nat → Bool) : ValidNumbering n r (components n r)

Proof

by
  have hinv : Inv n r ([] ++ classes n r) := by simpa using classes_inv
  have hcov : Cover n ([] ++ classes n r) := fun x hx => by simpa using classes_cover (r := r) hx
  obtain ⟨cs, hcs, hp, hrl⟩ := place_spec (n := n) (r := r) (n + 1) [] (classes n r) hinv hcov
    (Nat.le_trans classes_length (Nat.le_succ n))
  have heq : components n r = cs := by unfold components; simpa using hcs
  rw [heq]
  have hcls : ∀ c ∈ cs, ∃ a, a < n ∧ c = cls n r a := fun c hc => classes_inv.1 c (hp.mem_iff.mp hc)
  have hdisj : cs.Pairwise Disj := (hp.pairwise_iff (fun {_ _} => disj_symm)).mpr classes_inv.2
  refine ⟨?_, ?_, ?_, ?_⟩
  · -- the classes partition range n
    apply (List.perm_ext_iff_of_nodup _ List.nodup_range).mpr
    · intro x
      rw [List.mem_range, List.mem_flatten]
      constructor
      · rintro ⟨c, hc, hx⟩
        obtain ⟨a, ha, rfl⟩ := hcls c hc
        exact cls_lt ha hx
      · intro hx
        obtain ⟨c, hc, hxc⟩ := classes_cover (r := r) hx
        exact ⟨c, hp.mem_iff.mpr hc, hxc⟩
    · apply flatten_nodup cs _ hdisj
      intro c hc
      obtain ⟨a, _, rfl⟩ := hcls c hc
      exact (cls_sorted a).imp (fun h => Nat.ne_of_lt h)
  · intro c hc
    obtain ⟨a, ha, rfl⟩ := hcls c hc
    refine ⟨cls_sorted a, fun he => ?_⟩
    have := self_mem_cls (r := r) ha
    rw [he] at this; simp at this
  · intro c hc i hi j hj
    obtain ⟨a, ha, rfl⟩ := hcls c hc
    have hai := ((mem_cls ha).mp hi).2
    rw [mem_cls ha]
    constructor
    · intro h; exact ⟨hj, mr_trans hai h⟩
    · intro h; exact mr_trans (mr_symm hai) h.2
  · intro a b ha hb hab ⟨i, hi, j, hj, hr⟩
    obtain ⟨a', ha', hca⟩ := hcls cs[a] (List.getElem_mem ha)
    obtain ⟨b', hb', hcb⟩ := hcls cs[b] (List.getElem_mem hb)
    have hjn : j < n := by rw [hcb] at hj; exact cls_lt hb' hj
    have hrd := readyList_get [] cs hrl a ha
    simp only [List.nil_append] at hrd
    unfold ready at hrd
    have h1 := (List.all_eq_true.mp hrd) i hi
    have h2 := (List.all_eq_true.mp h1) j (List.mem_range.mpr hjn)
    simp only [hr, Bool.not_true, Bool.false_or, Bool.or_eq_true, List.contains_iff_mem,
      List.any_eq_true] at h2
    have hpw := List.pairwise_iff_getElem.mp hdisj
    rcases h2 with hja | ⟨p, hp', hjp⟩
    · exfalso
      rcases Nat.lt_or_gt_of_ne hab with h | h
      · exact hpw a b ha hb h j hja hj
      · exact hpw b a hb ha h j hj hja
    · obtain ⟨k, hk, rfl⟩ := List.mem_take_iff_getElem.mp hp'
      have hkb : k = b := by
        apply Classical.byContradiction
        intro hne
        have hk' : k < cs.length := (Nat.lt_min.mp hk).2
        rcases Nat.lt_or_gt_of_ne hne with h | h
        · exact hpw k b hk' hb h j hjp hj
        · exact hpw b k hb hk' h j hj hjp
      subst hkb
      exact (Nat.lt_min.mp hk).1

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.