l3lab/ntp-mathlib huggingface dataset:
@[aesop unsafe 30% (rule_sets [Matroid])]
theorem Indep.subset_ground (hI : M.Indep I) : I ⊆ M.E := by
  

Proof state:
α : Type u_1
M : Matroid α
I : Set α
hI : M.Indep I
⊢ I ⊆ M.E

Next tactic:
obtain ⟨B, hB, hIB⟩ := hI
@[aesop unsafe 30% (rule_sets [Matroid])]
theorem Indep.subset_ground (hI : M.Indep I) : I ⊆ M.E := by
  obtain ⟨B, hB, hIB⟩ := hI
  

Proof state:
case intro.intro
α : Type u_1
M : Matroid α
I B : Set α
hB : M.Base B
hIB : I ⊆ B
⊢ I ⊆ M.E

Next tactic:
exact hIB.trans hB.subset_ground
theorem indep_or_dep (hX : X ⊆ M.E := by aesop_mat) : M.Indep X ∨ M.Dep X := by
  

Proof state:
α : Type u_1
M : Matroid α
X : Set α
hX : autoParam (X ⊆ M.E) _auto✝
⊢ M.Indep X ∨ M.Dep X

Next tactic:
rw [Dep, and_iff_left hX]
theorem indep_or_dep (hX : X ⊆ M.E := by aesop_mat) : M.Indep X ∨ M.Dep X := by
  rw [Dep, and_iff_left hX]
  

Proof state:
α : Type u_1
M : Matroid α
X : Set α
hX : autoParam (X ⊆ M.E) _auto✝
⊢ M.Indep X ∨ ¬M.Indep X

Next tactic:
apply em
@[simp] theorem not_dep_iff (hX : X ⊆ M.E := by aesop_mat) : ¬ M.Dep X ↔ M.Indep X := by
  

Proof state:
α : Type u_1
M : Matroid α
X : Set α
hX : autoParam (X ⊆ M.E) _auto✝
⊢ ¬M.Dep X ↔ M.Indep X

Next tactic:
rw [Dep, and_iff_left hX, not_not]
@[simp] theorem not_indep_iff (hX : X ⊆ M.E := by aesop_mat) : ¬ M.Indep X ↔ M.Dep X := by
  

Proof state:
α : Type u_1
M : Matroid α
X : Set α
hX : autoParam (X ⊆ M.E) _auto✝
⊢ ¬M.Indep X ↔ M.Dep X

Next tactic:
rw [Dep, and_iff_left hX]
theorem indep_iff_not_dep : M.Indep I ↔ ¬M.Dep I ∧ I ⊆ M.E := by
  

Proof state:
α : Type u_1
M : Matroid α
I : Set α
⊢ M.Indep I ↔ ¬M.Dep I ∧ I ⊆ M.E

Next tactic:
rw [dep_iff, not_and, not_imp_not]
theorem indep_iff_not_dep : M.Indep I ↔ ¬M.Dep I ∧ I ⊆ M.E := by
  rw [dep_iff, not_and, not_imp_not]
  

Proof state:
α : Type u_1
M : Matroid α
I : Set α
⊢ M.Indep I ↔ (I ⊆ M.E → M.Indep I) ∧ I ⊆ M.E

Next tactic:
exact ⟨fun h ↦ ⟨fun _ ↦ h, h.subset_ground⟩, fun h ↦ h.1 h.2⟩
theorem Dep.nonempty (hD : M.Dep D) : D.Nonempty := by
  

Proof state:
α : Type u_1
M : Matroid α
D : Set α
hD : M.Dep D
⊢ Set.Nonempty D

Next tactic:
rw [nonempty_iff_ne_empty]
theorem Dep.nonempty (hD : M.Dep D) : D.Nonempty := by
  rw [nonempty_iff_ne_empty]; 

Proof state:
α : Type u_1
M : Matroid α
D : Set α
hD : M.Dep D
⊢ D ≠ ∅

Next tactic:
rintro rfl
theorem Dep.nonempty (hD : M.Dep D) : D.Nonempty := by
  rw [nonempty_iff_ne_empty]; rintro rfl; 

Proof state:
α : Type u_1
M : Matroid α
hD : M.Dep ∅
⊢ False

Next tactic:
exact hD.not_indep M.empty_indep
theorem Indep.rkPos_of_nonempty (hI : M.Indep I) (hne : I.Nonempty) : M.RkPos := by
  

Proof state:
α : Type u_1
M : Matroid α
I : Set α
hI : M.Indep I
hne : Set.Nonempty I
⊢ RkPos M

Next tactic:
obtain ⟨B, hB, hIB⟩ := hI.exists_base_superset
theorem Indep.rkPos_of_nonempty (hI : M.Indep I) (hne : I.Nonempty) : M.RkPos := by
  obtain ⟨B, hB, hIB⟩ := hI.exists_base_superset
  

Proof state:
case intro.intro
α : Type u_1
M : Matroid α
I : Set α
hI : M.Indep I
hne : Set.Nonempty I
B : Set α
hB : M.Base B
hIB : I ⊆ B
⊢ RkPos M

Next tactic:
exact hB.rkPos_of_nonempty (hne.mono hIB)
theorem Base.eq_of_subset_indep (hB : M.Base B) (hI : M.Indep I) (hBI : B ⊆ I) : B = I :=
  let ⟨B', hB', hB'I⟩ := hI
  hBI.antisymm (by 

Proof state:
α : Type u_1
M : Matroid α
B I : Set α
hB : M.Base B
hI : M.Indep I
hBI : B ⊆ I
B' : Set α
hB' : M.Base B'
hB'I : I ⊆ B'
⊢ I ⊆ B

Next tactic:
rwa [hB.eq_of_subset_base hB' (hBI.trans hB'I)]
theorem base_iff_maximal_indep : M.Base B ↔ M.Indep B ∧ ∀ I, M.Indep I → B ⊆ I → B = I := by
  

Proof state:
α : Type u_1
M : Matroid α
B : Set α
⊢ M.Base B ↔ M.Indep B ∧ ∀ (I : Set α), M.Indep I → B ⊆ I → B = I

Next tactic:
refine' ⟨fun h ↦ ⟨h.indep, fun _ ↦ h.eq_of_subset_indep ⟩, fun h ↦ _⟩
theorem base_iff_maximal_indep : M.Base B ↔ M.Indep B ∧ ∀ I, M.Indep I → B ⊆ I → B = I := by
  refine' ⟨fun h ↦ ⟨h.indep, fun _ ↦ h.eq_of_subset_indep ⟩, fun h ↦ _⟩
  

Proof state:
α : Type u_1
M : Matroid α
B : Set α
h : M.Indep B ∧ ∀ (I : Set α), M.Indep I → B ⊆ I → B = I
⊢ M.Base B

Next tactic:
obtain ⟨⟨B', hB', hBB'⟩, h⟩ := h
theorem base_iff_maximal_indep : M.Base B ↔ M.Indep B ∧ ∀ I, M.Indep I → B ⊆ I → B = I := by
  refine' ⟨fun h ↦ ⟨h.indep, fun _ ↦ h.eq_of_subset_indep ⟩, fun h ↦ _⟩
  obtain ⟨⟨B', hB', hBB'⟩, h⟩ := h
  

Proof state:
case intro.intro.intro
α : Type u_1
M : Matroid α
B : Set α
h : ∀ (I : Set α), M.Indep I → B ⊆ I → B = I
B' : Set α
hB' : M.Base B'
hBB' : B ⊆ B'
⊢ M.Base B

Next tactic:
rwa [h _ hB'.indep hBB']
theorem setOf_base_eq_maximals_setOf_indep : {B | M.Base B} = maximals (· ⊆ ·) {I | M.Indep I} := by
  

Proof state:
α : Type u_1
M : Matroid α
⊢ {B | M.Base B} = maximals (fun x x_1 => x ⊆ x_1) {I | M.Indep I}

Next tactic:
ext B
theorem setOf_base_eq_maximals_setOf_indep : {B | M.Base B} = maximals (· ⊆ ·) {I | M.Indep I} := by
  ext B; 

Proof state:
case h
α : Type u_1
M : Matroid α
B : Set α
⊢ B ∈ {B | M.Base B} ↔ B ∈ maximals (fun x x_1 => x ⊆ x_1) {I | M.Indep I}

Next tactic:
rw [mem_maximals_setOf_iff, mem_setOf, base_iff_maximal_indep]
/-- If the difference of two Bases is a singleton, then they differ by an insertion/removal -/
theorem Base.eq_exchange_of_diff_eq_singleton (hB : M.Base B) (hB' : M.Base B') (h : B \ B' = {e}) :
    ∃ f ∈ B' \ B, B' = (insert f B) \ {e} := by
  

Proof state:
α : Type u_1
M : Matroid α
B B' : Set α
e : α
hB : M.Base B
hB' : M.Base B'
h : B \ B' = {e}
⊢ ∃ f ∈ B' \ B, B' = insert f B \ {e}

Next tactic:
obtain ⟨f, hf, hb⟩ := hB.exchange hB' (h.symm.subset (mem_singleton e))
/-- If the difference of two Bases is a singleton, then they differ by an insertion/removal -/
theorem Base.eq_exchange_of_diff_eq_singleton (hB : M.Base B) (hB' : M.Base B') (h : B \ B' = {e}) :
    ∃ f ∈ B' \ B, B' = (insert f B) \ {e} := by
  obtain ⟨f, hf, hb⟩ := hB.exchange hB' (h.symm.subset (mem_singleton e))
  

Proof state:
case intro.intro
α : Type u_1
M : Matroid α
B B' : Set α
e : α
hB : M.Base B
hB' : M.Base B'
h : B \ B' = {e}
f : α
hf : f ∈ B' \ B
hb : M.Base (insert f (B \ {e}))
⊢ ∃ f ∈ B' \ B, B' = insert f B \ {e}

Next tactic:
have hne : f ≠ e := by rintro rfl; exact hf.2 (h.symm.subset (mem_singleton f)).1
/-- If the difference of two Bases is a singleton, then they differ by an insertion/removal -/
theorem Base.eq_exchange_of_diff_eq_singleton (hB : M.Base B) (hB' : M.Base B') (h : B \ B' = {e}) :
    ∃ f ∈ B' \ B, B' = (insert f B) \ {e} := by
  obtain ⟨f, hf, hb⟩ := hB.exchange hB' (h.symm.subset (mem_singleton e))
  have hne : f ≠ e := by 

Proof state:
α : Type u_1
M : Matroid α
B B' : Set α
e : α
hB : M.Base B
hB' : M.Base B'
h : B \ B' = {e}
f : α
hf : f ∈ B' \ B
hb : M.Base (insert f (B \ {e}))
⊢ f ≠ e

Next tactic:
rintro rfl
/-- If the difference of two Bases is a singleton, then they differ by an insertion/removal -/
theorem Base.eq_exchange_of_diff_eq_singleton (hB : M.Base B) (hB' : M.Base B') (h : B \ B' = {e}) :
    ∃ f ∈ B' \ B, B' = (insert f B) \ {e} := by
  obtain ⟨f, hf, hb⟩ := hB.exchange hB' (h.symm.subset (mem_singleton e))
  have hne : f ≠ e := by rintro rfl; 

Proof state:
α : Type u_1
M : Matroid α
B B' : Set α
hB : M.Base B
hB' : M.Base B'
f : α
hf : f ∈ B' \ B
h : B \ B' = {f}
hb : M.Base (insert f (B \ {f}))
⊢ False

Next tactic:
exact hf.2 (h.symm.subset (mem_singleton f)).1
/-- If the difference of two Bases is a singleton, then they differ by an insertion/removal -/
theorem Base.eq_exchange_of_diff_eq_singleton (hB : M.Base B) (hB' : M.Base B') (h : B \ B' = {e}) :
    ∃ f ∈ B' \ B, B' = (insert f B) \ {e} := by
  obtain ⟨f, hf, hb⟩ := hB.exchange hB' (h.symm.subset (mem_singleton e))
  have hne : f ≠ e := by rintro rfl; exact hf.2 (h.symm.subset (mem_singleton f)).1
  

Proof state:
case intro.intro
α : Type u_1
M : Matroid α
B B' : Set α
e : α
hB : M.Base B
hB' : M.Base B'
h : B \ B' = {e}
f : α
hf : f ∈ B' \ B
hb : M.Base (insert f (B \ {e}))
hne : f ≠ e
⊢ ∃ f ∈ B' \ B, B' = insert f B \ {e}

Next tactic:
rw [insert_diff_singleton_comm hne] at hb
/-- If the difference of two Bases is a singleton, then they differ by an insertion/removal -/
theorem Base.eq_exchange_of_diff_eq_singleton (hB : M.Base B) (hB' : M.Base B') (h : B \ B' = {e}) :
    ∃ f ∈ B' \ B, B' = (insert f B) \ {e} := by
  obtain ⟨f, hf, hb⟩ := hB.exchange hB' (h.symm.subset (mem_singleton e))
  have hne : f ≠ e := by rintro rfl; exact hf.2 (h.symm.subset (mem_singleton f)).1
  rw [insert_diff_singleton_comm hne] at hb
  

Proof state:
case intro.intro
α : Type u_1
M : Matroid α
B B' : Set α
e : α
hB : M.Base B
hB' : M.Base B'
h : B \ B' = {e}
f : α
hf : f ∈ B' \ B
hb : M.Base (insert f B \ {e})
hne : f ≠ e
⊢ ∃ f ∈ B' \ B, B' = insert f B \ {e}

Next tactic:
refine ⟨f, hf, (hb.eq_of_subset_base hB' ?_).symm⟩
/-- If the difference of two Bases is a singleton, then they differ by an insertion/removal -/
theorem Base.eq_exchange_of_diff_eq_singleton (hB : M.Base B) (hB' : M.Base B') (h : B \ B' = {e}) :
    ∃ f ∈ B' \ B, B' = (insert f B) \ {e} := by
  obtain ⟨f, hf, hb⟩ := hB.exchange hB' (h.symm.subset (mem_singleton e))
  have hne : f ≠ e := by rintro rfl; exact hf.2 (h.symm.subset (mem_singleton f)).1
  rw [insert_diff_singleton_comm hne] at hb
  refine ⟨f, hf, (hb.eq_of_subset_base hB' ?_).symm⟩
  

Proof state:
case intro.intro
α : Type u_1
M : Matroid α
B B' : Set α
e : α
hB : M.Base B
hB' : M.Base B'
h : B \ B' = {e}
f : α
hf : f ∈ B' \ B
hb : M.Base (insert f B \ {e})
hne : f ≠ e
⊢ insert f B \ {e} ⊆ B'

Next tactic:
rw [diff_subset_iff, insert_subset_iff, union_comm, ← diff_subset_iff, h, and_iff_left rfl.subset]
/-- If the difference of two Bases is a singleton, then they differ by an insertion/removal -/
theorem Base.eq_exchange_of_diff_eq_singleton (hB : M.Base B) (hB' : M.Base B') (h : B \ B' = {e}) :
    ∃ f ∈ B' \ B, B' = (insert f B) \ {e} := by
  obtain ⟨f, hf, hb⟩ := hB.exchange hB' (h.symm.subset (mem_singleton e))
  have hne : f ≠ e := by rintro rfl; exact hf.2 (h.symm.subset (mem_singleton f)).1
  rw [insert_diff_singleton_comm hne] at hb
  refine ⟨f, hf, (hb.eq_of_subset_base hB' ?_).symm⟩
  rw [diff_subset_iff, insert_subset_iff, union_comm, ← diff_subset_iff, h, and_iff_left rfl.subset]
  

Proof state:
case intro.intro
α : Type u_1
M : Matroid α
B B' : Set α
e : α
hB : M.Base B
hB' : M.Base B'
h : B \ B' = {e}
f : α
hf : f ∈ B' \ B
hb : M.Base (insert f B \ {e})
hne : f ≠ e
⊢ f ∈ B' ∪ {e}

Next tactic:
exact Or.inl hf.1
theorem Base.exchange_base_of_indep (hB : M.Base B) (hf : f ∉ B)
    (hI : M.Indep (insert f (B \ {e}))) : M.Base (insert f (B \ {e})) := by
  

Proof state:
α : Type u_1
M : Matroid α
B : Set α
f e : α
hB : M.Base B
hf : f ∉ B
hI : M.Indep (insert f (B \ {e}))
⊢ M.Base (insert f (B \ {e}))

Next tactic:
obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset
theorem Base.exchange_base_of_indep (hB : M.Base B) (hf : f ∉ B)
    (hI : M.Indep (insert f (B \ {e}))) : M.Base (insert f (B \ {e})) := by
  obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset
  

Proof state:
case intro.intro
α : Type u_1
M : Matroid α
B : Set α
f e : α
hB : M.Base B
hf : f ∉ B
hI : M.Indep (insert f (B \ {e}))
B' : Set α
hB' : M.Base B'
hIB' : insert f (B \ {e}) ⊆ B'
⊢ M.Base (insert f (B \ {e}))

Next tactic:
have hcard := hB'.encard_diff_comm hB
theorem Base.exchange_base_of_indep (hB : M.Base B) (hf : f ∉ B)
    (hI : M.Indep (insert f (B \ {e}))) : M.Base (insert f (B \ {e})) := by
  obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset
  have hcard := hB'.encard_diff_comm hB
  

Proof state:
case intro.intro
α : Type u_1
M : Matroid α
B : Set α
f e : α
hB : M.Base B
hf : f ∉ B
hI : M.Indep (insert f (B \ {e}))
B' : Set α
hB' : M.Base B'
hIB' : insert f (B \ {e}) ⊆ B'
hcard : encard (B' \ B) = encard (B \ B')
⊢ M.Base (insert f (B \ {e}))

Next tactic:
rw [insert_subset_iff, ← diff_eq_empty, diff_diff_comm, diff_eq_empty, subset_singleton_iff_eq]
    at hIB'
theorem Base.exchange_base_of_indep (hB : M.Base B) (hf : f ∉ B)
    (hI : M.Indep (insert f (B \ {e}))) : M.Base (insert f (B \ {e})) := by
  obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset
  have hcard := hB'.encard_diff_comm hB
  rw [insert_subset_iff, ← diff_eq_empty, diff_diff_comm, diff_eq_empty, subset_singleton_iff_eq]
    at hIB'
  

Proof state:
case intro.intro
α : Type u_1
M : Matroid α
B : Set α
f e : α
hB : M.Base B
hf : f ∉ B
hI : M.Indep (insert f (B \ {e}))
B' : Set α
hB' : M.Base B'
hIB' : f ∈ B' ∧ (B \ B' = ∅ ∨ B \ B' = {e})
hcard : encard (B' \ B) = encard (B \ B')
⊢ M.Base (insert f (B \ {e}))

Next tactic:
obtain ⟨hfB, (h | h)⟩ := hIB'
theorem Base.exchange_base_of_indep (hB : M.Base B) (hf : f ∉ B)
    (hI : M.Indep (insert f (B \ {e}))) : M.Base (insert f (B \ {e})) := by
  obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset
  have hcard := hB'.encard_diff_comm hB
  rw [insert_subset_iff, ← diff_eq_empty, diff_diff_comm, diff_eq_empty, subset_singleton_iff_eq]
    at hIB'
  obtain ⟨hfB, (h | h)⟩ := hIB'
  · 

Proof state:
case intro.intro.intro.inl
α : Type u_1
M : Matroid α
B : Set α
f e : α
hB : M.Base B
hf : f ∉ B
hI : M.Indep (insert f (B \ {e}))
B' : Set α
hB' : M.Base B'
hcard : encard (B' \ B) = encard (B \ B')
hfB : f ∈ B'
h : B \ B' = ∅
⊢ M.Base (insert f (B \ {e}))

Next tactic:
rw [h, encard_empty, encard_eq_zero, eq_empty_iff_forall_not_mem] at hcard
theorem Base.exchange_base_of_indep (hB : M.Base B) (hf : f ∉ B)
    (hI : M.Indep (insert f (B \ {e}))) : M.Base (insert f (B \ {e})) := by
  obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset
  have hcard := hB'.encard_diff_comm hB
  rw [insert_subset_iff, ← diff_eq_empty, diff_diff_comm, diff_eq_empty, subset_singleton_iff_eq]
    at hIB'
  obtain ⟨hfB, (h | h)⟩ := hIB'
  · rw [h, encard_empty, encard_eq_zero, eq_empty_iff_forall_not_mem] at hcard
    

Proof state:
case intro.intro.intro.inl
α : Type u_1
M : Matroid α
B : Set α
f e : α
hB : M.Base B
hf : f ∉ B
hI : M.Indep (insert f (B \ {e}))
B' : Set α
hB' : M.Base B'
hcard : ∀ (x : α), x ∉ B' \ B
hfB : f ∈ B'
h : B \ B' = ∅
⊢ M.Base (insert f (B \ {e}))

Next tactic:
exact (hcard f ⟨hfB, hf⟩).elim
theorem Base.exchange_base_of_indep (hB : M.Base B) (hf : f ∉ B)
    (hI : M.Indep (insert f (B \ {e}))) : M.Base (insert f (B \ {e})) := by
  obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset
  have hcard := hB'.encard_diff_comm hB
  rw [insert_subset_iff, ← diff_eq_empty, diff_diff_comm, diff_eq_empty, subset_singleton_iff_eq]
    at hIB'
  obtain ⟨hfB, (h | h)⟩ := hIB'
  · rw [h, encard_empty, encard_eq_zero, eq_empty_iff_forall_not_mem] at hcard
    exact (hcard f ⟨hfB, hf⟩).elim
  

Proof state:
case intro.intro.intro.inr
α : Type u_1
M : Matroid α
B : Set α
f e : α
hB : M.Base B
hf : f ∉ B
hI : M.Indep (insert f (B \ {e}))
B' : Set α
hB' : M.Base B'
hcard : encard (B' \ B) = encard (B \ B')
hfB : f ∈ B'
h : B \ B' = {e}
⊢ M.Base (insert f (B \ {e}))

Next tactic:
rw [h, encard_singleton, encard_eq_one] at hcard
theorem Base.exchange_base_of_indep (hB : M.Base B) (hf : f ∉ B)
    (hI : M.Indep (insert f (B \ {e}))) : M.Base (insert f (B \ {e})) := by
  obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset
  have hcard := hB'.encard_diff_comm hB
  rw [insert_subset_iff, ← diff_eq_empty, diff_diff_comm, diff_eq_empty, subset_singleton_iff_eq]
    at hIB'
  obtain ⟨hfB, (h | h)⟩ := hIB'
  · rw [h, encard_empty, encard_eq_zero, eq_empty_iff_forall_not_mem] at hcard
    exact (hcard f ⟨hfB, hf⟩).elim
  rw [h, encard_singleton, encard_eq_one] at hcard
  

Proof state:
case intro.intro.intro.inr
α : Type u_1
M : Matroid α
B : Set α
f e : α
hB : M.Base B
hf : f ∉ B
hI : M.Indep (insert f (B \ {e}))
B' : Set α
hB' : M.Base B'
hcard : ∃ x, B' \ B = {x}
hfB : f ∈ B'
h : B \ B' = {e}
⊢ M.Base (insert f (B \ {e}))

Next tactic:
obtain ⟨x, hx⟩ := hcard
theorem Base.exchange_base_of_indep (hB : M.Base B) (hf : f ∉ B)
    (hI : M.Indep (insert f (B \ {e}))) : M.Base (insert f (B \ {e})) := by
  obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset
  have hcard := hB'.encard_diff_comm hB
  rw [insert_subset_iff, ← diff_eq_empty, diff_diff_comm, diff_eq_empty, subset_singleton_iff_eq]
    at hIB'
  obtain ⟨hfB, (h | h)⟩ := hIB'
  · rw [h, encard_empty, encard_eq_zero, eq_empty_iff_forall_not_mem] at hcard
    exact (hcard f ⟨hfB, hf⟩).elim
  rw [h, encard_singleton, encard_eq_one] at hcard
  obtain ⟨x, hx⟩ := hcard
  

Proof state:
case intro.intro.intro.inr.intro
α : Type u_1
M : Matroid α
B : Set α
f e : α
hB : M.Base B
hf : f ∉ B
hI : M.Indep (insert f (B \ {e}))
B' : Set α
hB' : M.Base B'
hfB : f ∈ B'
h : B \ B' = {e}
x : α
hx : B' \ B = {x}
⊢ M.Base (insert f (B \ {e}))

Next tactic:
obtain (rfl : f = x) := hx.subset ⟨hfB, hf⟩
theorem Base.exchange_base_of_indep (hB : M.Base B) (hf : f ∉ B)
    (hI : M.Indep (insert f (B \ {e}))) : M.Base (insert f (B \ {e})) := by
  obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset
  have hcard := hB'.encard_diff_comm hB
  rw [insert_subset_iff, ← diff_eq_empty, diff_diff_comm, diff_eq_empty, subset_singleton_iff_eq]
    at hIB'
  obtain ⟨hfB, (h | h)⟩ := hIB'
  · rw [h, encard_empty, encard_eq_zero, eq_empty_iff_forall_not_mem] at hcard
    exact (hcard f ⟨hfB, hf⟩).elim
  rw [h, encard_singleton, encard_eq_one] at hcard
  obtain ⟨x, hx⟩ := hcard
  obtain (rfl : f = x) := hx.subset ⟨hfB, hf⟩
  

Proof state:
case intro.intro.intro.inr.intro
α : Type u_1
M : Matroid α
B : Set α
f e : α
hB : M.Base B
hf : f ∉ B
hI : M.Indep (insert f (B \ {e}))
B' : Set α
hB' : M.Base B'
hfB : f ∈ B'
h : B \ B' = {e}
hx : B' \ B = {f}
⊢ M.Base (insert f (B \ {e}))

Next tactic:
simp_rw [← h, ← singleton_union, ← hx, sdiff_sdiff_right_self, inf_eq_inter, inter_comm B,
    diff_union_inter]
theorem Base.exchange_base_of_indep (hB : M.Base B) (hf : f ∉ B)
    (hI : M.Indep (insert f (B \ {e}))) : M.Base (insert f (B \ {e})) := by
  obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset
  have hcard := hB'.encard_diff_comm hB
  rw [insert_subset_iff, ← diff_eq_empty, diff_diff_comm, diff_eq_empty, subset_singleton_iff_eq]
    at hIB'
  obtain ⟨hfB, (h | h)⟩ := hIB'
  · rw [h, encard_empty, encard_eq_zero, eq_empty_iff_forall_not_mem] at hcard
    exact (hcard f ⟨hfB, hf⟩).elim
  rw [h, encard_singleton, encard_eq_one] at hcard
  obtain ⟨x, hx⟩ := hcard
  obtain (rfl : f = x) := hx.subset ⟨hfB, hf⟩
  simp_rw [← h, ← singleton_union, ← hx, sdiff_sdiff_right_self, inf_eq_inter, inter_comm B,
    diff_union_inter]
  

Proof state:
case intro.intro.intro.inr.intro
α : Type u_1
M : Matroid α
B : Set α
f e : α
hB : M.Base B
hf : f ∉ B
hI : M.Indep (insert f (B \ {e}))
B' : Set α
hB' : M.Base B'
hfB : f ∈ B'
h : B \ B' = {e}
hx : B' \ B = {f}
⊢ M.Base B'

Next tactic:
exact hB'
theorem Base.exchange_base_of_indep' (hB : M.Base B) (he : e ∈ B) (hf : f ∉ B)
    (hI : M.Indep (insert f B \ {e})) : M.Base (insert f B \ {e}) := by
  

Proof state:
α : Type u_1
M : Matroid α
B : Set α
e f : α
hB : M.Base B
he : e ∈ B
hf : f ∉ B
hI : M.Indep (insert f B \ {e})
⊢ M.Base (insert f B \ {e})

Next tactic:
have hfe : f ≠ e := by rintro rfl; exact hf he
theorem Base.exchange_base_of_indep' (hB : M.Base B) (he : e ∈ B) (hf : f ∉ B)
    (hI : M.Indep (insert f B \ {e})) : M.Base (insert f B \ {e}) := by
  have hfe : f ≠ e := by 

Proof state:
α : Type u_1
M : Matroid α
B : Set α
e f : α
hB : M.Base B
he : e ∈ B
hf : f ∉ B
hI : M.Indep (insert f B \ {e})
⊢ f ≠ e

Next tactic:
rintro rfl
theorem Base.exchange_base_of_indep' (hB : M.Base B) (he : e ∈ B) (hf : f ∉ B)
    (hI : M.Indep (insert f B \ {e})) : M.Base (insert f B \ {e}) := by
  have hfe : f ≠ e := by rintro rfl; 

Proof state:
α : Type u_1
M : Matroid α
B : Set α
f : α
hB : M.Base B
hf : f ∉ B
he : f ∈ B
hI : M.Indep (insert f B \ {f})
⊢ False

Next tactic:
exact hf he
theorem Base.exchange_base_of_indep' (hB : M.Base B) (he : e ∈ B) (hf : f ∉ B)
    (hI : M.Indep (insert f B \ {e})) : M.Base (insert f B \ {e}) := by
  have hfe : f ≠ e := by rintro rfl; exact hf he
  

Proof state:
α : Type u_1
M : Matroid α
B : Set α
e f : α
hB : M.Base B
he : e ∈ B
hf : f ∉ B
hI : M.Indep (insert f B \ {e})
hfe : f ≠ e
⊢ M.Base (insert f B \ {e})

Next tactic:
rw [← insert_diff_singleton_comm hfe] at *
theorem Base.exchange_base_of_indep' (hB : M.Base B) (he : e ∈ B) (hf : f ∉ B)
    (hI : M.Indep (insert f B \ {e})) : M.Base (insert f B \ {e}) := by
  have hfe : f ≠ e := by rintro rfl; exact hf he
  rw [← insert_diff_singleton_comm hfe] at *
  

Proof state:
α : Type u_1
M : Matroid α
B : Set α
e f : α
hB : M.Base B
he : e ∈ B
hf : f ∉ B
hI : M.Indep (insert f (B \ {e}))
hfe : f ≠ e
⊢ M.Base (insert f (B \ {e}))

Next tactic:
exact hB.exchange_base_of_indep hf hI
theorem Base.insert_dep (hB : M.Base B) (h : e ∈ M.E \ B) : M.Dep (insert e B) := by
  

Proof state:
α : Type u_1
M : Matroid α
B : Set α
e : α
hB : M.Base B
h : e ∈ M.E \ B
⊢ M.Dep (insert e B)

Next tactic:
rw [← not_indep_iff (insert_subset h.1 hB.subset_ground)]
theorem Base.insert_dep (hB : M.Base B) (h : e ∈ M.E \ B) : M.Dep (insert e B) := by
  rw [← not_indep_iff (insert_subset h.1 hB.subset_ground)]
  

Proof state:
α : Type u_1
M : Matroid α
B : Set α
e : α
hB : M.Base B
h : e ∈ M.E \ B
⊢ ¬M.Indep (insert e B)

Next tactic:
exact h.2 ∘ (fun hi ↦ insert_eq_self.mp (hB.eq_of_subset_indep hi (subset_insert e B)).symm)
theorem Indep.exists_insert_of_not_base (hI : M.Indep I) (hI' : ¬M.Base I) (hB : M.Base B) :
    ∃ e ∈ B \ I, M.Indep (insert e I) := by
  

Proof state:
α : Type u_1
M : Matroid α
I B : Set α
hI : M.Indep I
hI' : ¬M.Base I
hB : M.Base B
⊢ ∃ e ∈ B \ I, M.Indep (insert e I)

Next tactic:
obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset
theorem Indep.exists_insert_of_not_base (hI : M.Indep I) (hI' : ¬M.Base I) (hB : M.Base B) :
    ∃ e ∈ B \ I, M.Indep (insert e I) := by
  obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset
  

Proof state:
case intro.intro
α : Type u_1
M : Matroid α
I B : Set α
hI : M.Indep I
hI' : ¬M.Base I
hB : M.Base B
B' : Set α
hB' : M.Base B'
hIB' : I ⊆ B'
⊢ ∃ e ∈ B \ I, M.Indep (insert e I)

Next tactic:
obtain ⟨x, hxB', hx⟩ := exists_of_ssubset (hIB'.ssubset_of_ne (by (rintro rfl; exact hI' hB')))
theorem Indep.exists_insert_of_not_base (hI : M.Indep I) (hI' : ¬M.Base I) (hB : M.Base B) :
    ∃ e ∈ B \ I, M.Indep (insert e I) := by
  obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset
  obtain ⟨x, hxB', hx⟩ := exists_of_ssubset (hIB'.ssubset_of_ne (by (

Proof state:
α : Type u_1
M : Matroid α
I B : Set α
hI : M.Indep I
hI' : ¬M.Base I
hB : M.Base B
B' : Set α
hB' : M.Base B'
hIB' : I ⊆ B'
⊢ I ≠ B'

Next tactic:
rintro rfl
theorem Indep.exists_insert_of_not_base (hI : M.Indep I) (hI' : ¬M.Base I) (hB : M.Base B) :
    ∃ e ∈ B \ I, M.Indep (insert e I) := by
  obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset
  obtain ⟨x, hxB', hx⟩ := exists_of_ssubset (hIB'.ssubset_of_ne (by (rintro rfl; 

Proof state:
α : Type u_1
M : Matroid α
I B : Set α
hI : M.Indep I
hI' : ¬M.Base I
hB : M.Base B
hB' : M.Base I
hIB' : I ⊆ I
⊢ False

Next tactic:
exact hI' hB'
theorem Indep.exists_insert_of_not_base (hI : M.Indep I) (hI' : ¬M.Base I) (hB : M.Base B) :
    ∃ e ∈ B \ I, M.Indep (insert e I) := by
  obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset
  obtain ⟨x, hxB', hx⟩ := exists_of_ssubset (hIB'.ssubset_of_ne (by (rintro rfl; exact hI' hB')))
  

Proof state:
case intro.intro.intro.intro
α : Type u_1
M : Matroid α
I B : Set α
hI : M.Indep I
hI' : ¬M.Base I
hB : M.Base B
B' : Set α
hB' : M.Base B'
hIB' : I ⊆ B'
x : α
hxB' : x ∈ B'
hx : x ∉ I
⊢ ∃ e ∈ B \ I, M.Indep (insert e I)

Next tactic:
obtain (hxB | hxB) := em (x ∈ B)
theorem Indep.exists_insert_of_not_base (hI : M.Indep I) (hI' : ¬M.Base I) (hB : M.Base B) :
    ∃ e ∈ B \ I, M.Indep (insert e I) := by
  obtain ⟨B', hB', hIB'⟩ := hI.exists_base_superset
  obtain ⟨x, hxB', hx⟩ := exists_of_ssubset (hIB'.ssubset_of_ne (by (rintro rfl; exact hI' hB')))
  obtain (hxB | hxB) := em (x ∈ B)
  · 

Proof state:
case intro.intro.intro.intro.inl
α : Type u_1
M : Matroid α
I B : Set α
hI : M.Indep I
hI' : ¬M.Base I
hB : M.Base B
B' : Set α
hB' : M.Base B'
hIB' : I ⊆ B'
x : α
hxB' : x ∈ B'
hx : x ∉ I
hxB : x ∈ B
⊢ ∃ e ∈ B \ I, M.Indep (insert e I)

Next tactic:
exact ⟨x, ⟨hxB, hx⟩ , ⟨B', hB', insert_subset hxB' hIB'⟩⟩