roseking's picture
Add lean source and binary files (part 103)
a44267b verified
Raw History Blame Contribute Delete
2.74 kB
21
def roots : {P : Finset (Fin n × Fin n)} → {D : Finset (Fin n)} →
    EliminationChain P D → List (Fin n × Fin n)
body · 2 lines
  | _, _, .done => []
  | _, _, .step a b _ _ _ tail => (a, b) :: tail.roots
26
lemma finalEntries_eq_union_roots (c : EliminationChain P D) :
    c.finalEntries = P ∪ c.roots.toFinset := by
proof · 5 lines
  induction c with
  | done => simp [finalEntries, roots]
  | step a b hab hP hb tail ih =>
      simpa [finalEntries, roots, Finset.union_comm, Finset.union_left_comm,
        Finset.union_assoc] using ih
34
lemma roots_notMem_initial (c : EliminationChain P D)
    (hpos : ∀ p ∈ c.finalEntries, p.1 < p.2) :
    ∀ p ∈ c.roots, p ∉ P := by
proof · 11 lines
  induction c with
  | done => simp [roots]
  | @step P D a b hab hP hb tail ih =>
      intro p hp
      change p ∈ (a, b) :: tail.roots at hp
      rcases List.mem_cons.mp hp with rfl | hp
      · intro hpP
        have haa := hP a hpP
        exact lt_irrefl a (hpos (a, a)
          (tail.entries_subset_final (Finset.mem_insert_of_mem haa)))
      · exact fun hpP => ih hpos p hp (Finset.mem_insert_of_mem hpP)
49
lemma roots_nodup (c : EliminationChain P D)
    (hpos : ∀ p ∈ c.finalEntries, p.1 < p.2) : c.roots.Nodup := by
proof · 6 lines
  induction c with
  | done => exact List.nodup_nil
  | step a b hab hP hb tail ih =>
      apply List.nodup_cons.mpr
      exact ⟨fun hp => tail.roots_notMem_initial hpos (a, b) hp
        (Finset.mem_insert_self _ _), ih hpos⟩
60
lemma completeRootChain_roots_toFinset (n : ℕ) :
    (completeRootChain n).roots.toFinset = allPositiveRoots n := by
proof · 2 lines
  have h := (completeRootChain n).finalEntries_eq_union_roots
  simpa only [completeRootChain_final, Finset.empty_union] using h.symm
65
lemma completeRootChain_roots_nodup (n : ℕ) : (completeRootChain n).roots.Nodup := by
proof · 4 lines
  apply (completeRootChain n).roots_nodup
  intro p hp
  rw [completeRootChain_final] at hp
  exact (Finset.mem_filter.mp hp).2
71
lemma completeRootChain_roots_length (n : ℕ) :
    (completeRootChain n).roots.length = (allPositiveRoots n).card := by
proof · 2 lines
  rw [←completeRootChain_roots_toFinset]
  exact (List.toFinset_card_of_nodup (completeRootChain_roots_nodup n)).symm