l3lab/ntp-mathlib huggingface dataset:
/-- Given `M : Matroid α`, the `IndepMatroid α` whose independent sets are
  the subsets of `M.E` that are disjoint from some base of `M` -/
@[simps] def dualIndepMatroid (M : Matroid α) : IndepMatroid α where
  E := M.E
  Indep I := I ⊆ M.E ∧ ∃ B, M.Base B ∧ Disjoint I B
  indep_empty := ⟨empty_subset M.E, M.exists_base.imp (fun B hB ↦ ⟨hB, empty_disjoint _⟩)⟩
  indep_subset := by
    rintro I J ⟨hJE, B, hB, hJB⟩ hIJ
    exact ⟨hIJ.trans hJE, ⟨B, hB, disjoint_of_subset_left hIJ hJB⟩⟩
  indep_aug := by
    rintro I X ⟨hIE, B, hB, hIB⟩ hI_not_max hX_max
    have hXE := hX_max.1.1
    have hB' := (base_compl_iff_mem_maximals_disjoint_base hXE).mpr hX_max

    set B' := M.E \ X with hX
    have hI := (not_iff_not.mpr (base_compl_iff_mem_maximals_disjoint_base)).mpr hI_not_max
    obtain ⟨B'', hB'', hB''₁, hB''₂⟩ := (hB'.indep.diff I).exists_base_subset_union_base hB
    rw [← compl_subset_compl, ← hIB.sdiff_eq_right, ← union_diff_distrib, diff_eq, compl_inter,
      compl_compl, union_subset_iff, compl_subset_compl] at hB''₂

    have hssu := (subset_inter (hB''₂.2) hIE).ssubset_of_ne
      (by { rintro rfl; apply hI; convert hB''; simp [hB''.subset_ground] })

    obtain ⟨e, ⟨(heB'' : e ∉ _), heE⟩, heI⟩ := exists_of_ssubset hssu
    use e
    simp_rw [mem_diff, insert_subset_iff, and_iff_left heI, and_iff_right heE, and_iff_right hIE]
    refine' ⟨by_contra (fun heX ↦ heB'' (hB''₁ ⟨_, heI⟩)), ⟨B'', hB'', _⟩⟩
    · rw [hX]; exact ⟨heE, heX⟩
    rw [← union_singleton, disjoint_union_left, disjoint_singleton_left, and_iff_left heB'']
    exact disjoint_of_subset_left hB''₂.2 disjoint_compl_left
  indep_maximal := by
    rintro X - I'⟨hI'E, B, hB, hI'B⟩ hI'X
    obtain ⟨I, hI⟩ :=  M.exists_basis (M.E \ X)
    obtain ⟨B', hB', hIB', hB'IB⟩ := hI.indep.exists_base_subset_union_base hB
    refine' ⟨(X \ B') ∩ M.E,
      ⟨_,subset_inter (subset_diff.mpr _) hI'E, (inter_subset_left _ _).trans (diff_subset _ _)⟩, _⟩
    · simp only [inter_subset_right, true_and]
      exact ⟨B', hB', disjoint_of_subset_left (inter_subset_left _ _) disjoint_sdiff_left⟩
    · rw [and_iff_right hI'X]
      refine' disjoint_of_subset_right hB'IB _
      rw [disjoint_union_right, and_iff_left hI'B]
      exact disjoint_of_subset hI'X hI.subset disjoint_sdiff_right
    simp only [mem_setOf_eq, subset_inter_iff, and_imp, forall_exists_index]
    intros J hJE B'' hB'' hdj _ hJX hssJ
    rw [and_iff_left hJE]
    rw [diff_eq, inter_right_comm, ← diff_eq, diff_subset_iff] at hssJ

    have hI' : (B'' ∩ X) ∪ (B' \ X) ⊆ B'
    · 

Proof state:
case hI'
α : Type u_1
M✝ : Matroid α
I✝ B✝ X✝ : Set α
M : Matroid α
X I' : Set α
hI'E : I' ⊆ M.E
B : Set α
hB : M.Base B
hI'B : Disjoint I' B
hI'X : I' ⊆ X
I : Set α
hI : M.Basis I (M.E \ X)
B' : Set α
hB' : M.Base B'
hIB' : I ⊆ B'
hB'IB : B' ⊆ I ∪ B
J : Set α
hJE : J ⊆ M.E
B'' : Set α
hB'' : M.Base B''
hdj : Disjoint J B''
a✝ : I' ⊆ J
hJX : J ⊆ X
hssJ : X ∩ M.E ⊆ B' ∪ J
⊢ B'' ∩ X ∪ B' \ X ⊆ B'

Next tactic:
rw [union_subset_iff, and_iff_left (diff_subset _ _),
        ← inter_eq_self_of_subset_left hB''.subset_ground, inter_right_comm, inter_assoc]
theorem dual_indep_iff_exists' : (M﹡.Indep I) ↔ I ⊆ M.E ∧ (∃ B, M.Base B ∧ Disjoint I B) := by
  

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
⊢ M﹡.Indep I ↔ I ⊆ M.E ∧ ∃ B, M.Base B ∧ Disjoint I B

Next tactic:
simp [dual]
@[simp] theorem dual_indep_iff_exists (hI : I ⊆ M.E := by aesop_mat) :
    M﹡.Indep I ↔ (∃ B, M.Base B ∧ Disjoint I B) := by
  

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
hI : autoParam (I ⊆ M.E) _auto✝
⊢ M﹡.Indep I ↔ ∃ B, M.Base B ∧ Disjoint I B

Next tactic:
rw [dual_indep_iff_exists', and_iff_right hI]
theorem dual_dep_iff_forall : (M﹡.Dep I) ↔ (∀ B, M.Base B → (I ∩ B).Nonempty) ∧ I ⊆ M.E := by
  

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
⊢ M﹡.Dep I ↔ (∀ (B : Set α), M.Base B → Set.Nonempty (I ∩ B)) ∧ I ⊆ M.E

Next tactic:
simp_rw [dep_iff, dual_indep_iff_exists', dual_ground, and_congr_left_iff, not_and,
    not_exists, not_and, not_disjoint_iff_nonempty_inter, imp_iff_right_iff, iff_true_intro Or.inl]
@[simp] theorem dual_base_iff (hB : B ⊆ M.E := by aesop_mat) : M﹡.Base B ↔ M.Base (M.E \ B) := by
  

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
hB : autoParam (B ⊆ M.E) _auto✝
⊢ M﹡.Base B ↔ M.Base (M.E \ B)

Next tactic:
rw [base_compl_iff_mem_maximals_disjoint_base, base_iff_maximal_indep, dual_indep_iff_exists',
    mem_maximals_setOf_iff]
@[simp] theorem dual_base_iff (hB : B ⊆ M.E := by aesop_mat) : M﹡.Base B ↔ M.Base (M.E \ B) := by
  rw [base_compl_iff_mem_maximals_disjoint_base, base_iff_maximal_indep, dual_indep_iff_exists',
    mem_maximals_setOf_iff]
  

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
hB : autoParam (B ⊆ M.E) _auto✝
⊢ ((B ⊆ M.E ∧ ∃ B_1, M.Base B_1 ∧ Disjoint B B_1) ∧ ∀ (I : Set α), M﹡.Indep I → B ⊆ I → B = I) ↔
    (B ⊆ M.E ∧ ∃ B_1, M.Base B_1 ∧ Disjoint B B_1) ∧
      ∀ ⦃y : Set α⦄, (y ⊆ M.E ∧ ∃ B, M.Base B ∧ Disjoint y B) → B ⊆ y → B = y

Next tactic:
simp [dual_indep_iff_exists']
theorem dual_base_iff' : M﹡.Base B ↔ M.Base (M.E \ B) ∧ B ⊆ M.E :=
  (em (B ⊆ M.E)).elim (fun h ↦ by 

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
h : B ⊆ M.E
⊢ M﹡.Base B ↔ M.Base (M.E \ B) ∧ B ⊆ M.E

Next tactic:
rw [dual_base_iff, and_iff_left h]
theorem setOf_dual_base_eq : {B | M﹡.Base B} = (fun X ↦ M.E \ X) '' {B | M.Base B} := by
  

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
⊢ {B | M﹡.Base B} = (fun X => M.E \ X) '' {B | M.Base B}

Next tactic:
ext B
theorem setOf_dual_base_eq : {B | M﹡.Base B} = (fun X ↦ M.E \ X) '' {B | M.Base B} := by
  ext B
  

Proof state:
case h
α : Type u_1
M : Matroid α
I B✝ X B : Set α
⊢ B ∈ {B | M﹡.Base B} ↔ B ∈ (fun X => M.E \ X) '' {B | M.Base B}

Next tactic:
simp only [mem_setOf_eq, mem_image, dual_base_iff']
theorem setOf_dual_base_eq : {B | M﹡.Base B} = (fun X ↦ M.E \ X) '' {B | M.Base B} := by
  ext B
  simp only [mem_setOf_eq, mem_image, dual_base_iff']
  

Proof state:
case h
α : Type u_1
M : Matroid α
I B✝ X B : Set α
⊢ M.Base (M.E \ B) ∧ B ⊆ M.E ↔ ∃ x, M.Base x ∧ M.E \ x = B

Next tactic:
refine' ⟨fun h ↦ ⟨_, h.1, diff_diff_cancel_left h.2⟩,
    fun ⟨B', hB', h⟩ ↦ ⟨_,h.symm.trans_subset (diff_subset _ _)⟩⟩
theorem setOf_dual_base_eq : {B | M﹡.Base B} = (fun X ↦ M.E \ X) '' {B | M.Base B} := by
  ext B
  simp only [mem_setOf_eq, mem_image, dual_base_iff']
  refine' ⟨fun h ↦ ⟨_, h.1, diff_diff_cancel_left h.2⟩,
    fun ⟨B', hB', h⟩ ↦ ⟨_,h.symm.trans_subset (diff_subset _ _)⟩⟩
  

Proof state:
case h
α : Type u_1
M : Matroid α
I B✝ X B : Set α
x✝ : ∃ x, M.Base x ∧ M.E \ x = B
B' : Set α
hB' : M.Base B'
h : M.E \ B' = B
⊢ M.Base (M.E \ B)

Next tactic:
rwa [← h, diff_diff_cancel_left hB'.subset_ground]
@[simp] theorem dual_dual (M : Matroid α) : M﹡﹡ = M :=
  eq_of_base_iff_base_forall rfl (fun B (h : B ⊆ M.E) ↦
    by 

Proof state:
α : Type u_1
M✝ : Matroid α
I B✝ X : Set α
M : Matroid α
B : Set α
h : B ⊆ M.E
⊢ M﹡﹡.Base B ↔ M.Base B

Next tactic:
rw [dual_base_iff, dual_base_iff, dual_ground, diff_diff_cancel_left h]
theorem eq_dual_comm {M₁ M₂ : Matroid α} : M₁ = M₂﹡ ↔ M₂ = M₁﹡ := by
  

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
M₁ M₂ : Matroid α
⊢ M₁ = M₂﹡ ↔ M₂ = M₁﹡

Next tactic:
rw [← dual_inj, dual_dual, eq_comm]
theorem Base.compl_base_dual (h : M.Base B) : M﹡.Base (M.E \ B) := by
  

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
h : M.Base B
⊢ M﹡.Base (M.E \ B)

Next tactic:
rwa [dual_base_iff, diff_diff_cancel_left h.subset_ground]
theorem Base.compl_inter_basis_of_inter_basis (hB : M.Base B) (hBX : M.Basis (B ∩ X) X) :
    M﹡.Basis ((M.E \ B) ∩ (M.E \ X)) (M.E \ X) := by
  

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
hB : M.Base B
hBX : M.Basis (B ∩ X) X
⊢ M﹡.Basis (M.E \ B ∩ (M.E \ X)) (M.E \ X)

Next tactic:
refine' Indep.basis_of_forall_insert _ (inter_subset_right _ _) (fun e he ↦ _)
theorem Base.compl_inter_basis_of_inter_basis (hB : M.Base B) (hBX : M.Basis (B ∩ X) X) :
    M﹡.Basis ((M.E \ B) ∩ (M.E \ X)) (M.E \ X) := by
  refine' Indep.basis_of_forall_insert _ (inter_subset_right _ _) (fun e he ↦ _)
  · 

Proof state:
case refine'_1
α : Type u_1
M : Matroid α
I B X : Set α
hB : M.Base B
hBX : M.Basis (B ∩ X) X
⊢ M﹡.Indep (M.E \ B ∩ (M.E \ X))

Next tactic:
rw [dual_indep_iff_exists]
theorem Base.compl_inter_basis_of_inter_basis (hB : M.Base B) (hBX : M.Basis (B ∩ X) X) :
    M﹡.Basis ((M.E \ B) ∩ (M.E \ X)) (M.E \ X) := by
  refine' Indep.basis_of_forall_insert _ (inter_subset_right _ _) (fun e he ↦ _)
  · rw [dual_indep_iff_exists]
    

Proof state:
case refine'_1
α : Type u_1
M : Matroid α
I B X : Set α
hB : M.Base B
hBX : M.Basis (B ∩ X) X
⊢ ∃ B_1, M.Base B_1 ∧ Disjoint (M.E \ B ∩ (M.E \ X)) B_1

Next tactic:
exact ⟨B, hB, disjoint_of_subset_left (inter_subset_left _ _) disjoint_sdiff_left⟩
theorem Base.compl_inter_basis_of_inter_basis (hB : M.Base B) (hBX : M.Basis (B ∩ X) X) :
    M﹡.Basis ((M.E \ B) ∩ (M.E \ X)) (M.E \ X) := by
  refine' Indep.basis_of_forall_insert _ (inter_subset_right _ _) (fun e he ↦ _)
  · rw [dual_indep_iff_exists]
    exact ⟨B, hB, disjoint_of_subset_left (inter_subset_left _ _) disjoint_sdiff_left⟩
  

Proof state:
case refine'_2
α : Type u_1
M : Matroid α
I B X : Set α
hB : M.Base B
hBX : M.Basis (B ∩ X) X
e : α
he : e ∈ (M.E \ X) \ (M.E \ B ∩ (M.E \ X))
⊢ M﹡.Dep (insert e (M.E \ B ∩ (M.E \ X)))

Next tactic:
simp only [diff_inter_self_eq_diff, mem_diff, not_and, not_not, imp_iff_right he.1.1] at he
theorem Base.compl_inter_basis_of_inter_basis (hB : M.Base B) (hBX : M.Basis (B ∩ X) X) :
    M﹡.Basis ((M.E \ B) ∩ (M.E \ X)) (M.E \ X) := by
  refine' Indep.basis_of_forall_insert _ (inter_subset_right _ _) (fun e he ↦ _)
  · rw [dual_indep_iff_exists]
    exact ⟨B, hB, disjoint_of_subset_left (inter_subset_left _ _) disjoint_sdiff_left⟩
  simp only [diff_inter_self_eq_diff, mem_diff, not_and, not_not, imp_iff_right he.1.1] at he
  

Proof state:
case refine'_2
α : Type u_1
M : Matroid α
I B X : Set α
hB : M.Base B
hBX : M.Basis (B ∩ X) X
e : α
he : (e ∈ M.E ∧ e ∉ X) ∧ e ∈ B
⊢ M﹡.Dep (insert e (M.E \ B ∩ (M.E \ X)))

Next tactic:
simp_rw [dual_dep_iff_forall, insert_subset_iff, and_iff_right he.1.1,
    and_iff_left ((inter_subset_left _ _).trans (diff_subset _ _))]
theorem Base.compl_inter_basis_of_inter_basis (hB : M.Base B) (hBX : M.Basis (B ∩ X) X) :
    M﹡.Basis ((M.E \ B) ∩ (M.E \ X)) (M.E \ X) := by
  refine' Indep.basis_of_forall_insert _ (inter_subset_right _ _) (fun e he ↦ _)
  · rw [dual_indep_iff_exists]
    exact ⟨B, hB, disjoint_of_subset_left (inter_subset_left _ _) disjoint_sdiff_left⟩
  simp only [diff_inter_self_eq_diff, mem_diff, not_and, not_not, imp_iff_right he.1.1] at he
  simp_rw [dual_dep_iff_forall, insert_subset_iff, and_iff_right he.1.1,
    and_iff_left ((inter_subset_left _ _).trans (diff_subset _ _))]
  

Proof state:
case refine'_2
α : Type u_1
M : Matroid α
I B X : Set α
hB : M.Base B
hBX : M.Basis (B ∩ X) X
e : α
he : (e ∈ M.E ∧ e ∉ X) ∧ e ∈ B
⊢ ∀ (B_1 : Set α), M.Base B_1 → Set.Nonempty (insert e (M.E \ B ∩ (M.E \ X)) ∩ B_1)

Next tactic:
refine' fun B' hB' ↦ by_contra (fun hem ↦ _)
theorem Base.compl_inter_basis_of_inter_basis (hB : M.Base B) (hBX : M.Basis (B ∩ X) X) :
    M﹡.Basis ((M.E \ B) ∩ (M.E \ X)) (M.E \ X) := by
  refine' Indep.basis_of_forall_insert _ (inter_subset_right _ _) (fun e he ↦ _)
  · rw [dual_indep_iff_exists]
    exact ⟨B, hB, disjoint_of_subset_left (inter_subset_left _ _) disjoint_sdiff_left⟩
  simp only [diff_inter_self_eq_diff, mem_diff, not_and, not_not, imp_iff_right he.1.1] at he
  simp_rw [dual_dep_iff_forall, insert_subset_iff, and_iff_right he.1.1,
    and_iff_left ((inter_subset_left _ _).trans (diff_subset _ _))]
  refine' fun B' hB' ↦ by_contra (fun hem ↦ _)
  

Proof state:
case refine'_2
α : Type u_1
M : Matroid α
I B X : Set α
hB : M.Base B
hBX : M.Basis (B ∩ X) X
e : α
he : (e ∈ M.E ∧ e ∉ X) ∧ e ∈ B
B' : Set α
hB' : M.Base B'
hem : ¬Set.Nonempty (insert e (M.E \ B ∩ (M.E \ X)) ∩ B')
⊢ False

Next tactic:
rw [nonempty_iff_ne_empty, not_ne_iff, ← union_singleton, diff_inter_diff,
   inter_distrib_right, union_empty_iff, singleton_inter_eq_empty, diff_eq,
   inter_right_comm, inter_eq_self_of_subset_right hB'.subset_ground, ← diff_eq,
   diff_eq_empty] at hem
theorem Base.compl_inter_basis_of_inter_basis (hB : M.Base B) (hBX : M.Basis (B ∩ X) X) :
    M﹡.Basis ((M.E \ B) ∩ (M.E \ X)) (M.E \ X) := by
  refine' Indep.basis_of_forall_insert _ (inter_subset_right _ _) (fun e he ↦ _)
  · rw [dual_indep_iff_exists]
    exact ⟨B, hB, disjoint_of_subset_left (inter_subset_left _ _) disjoint_sdiff_left⟩
  simp only [diff_inter_self_eq_diff, mem_diff, not_and, not_not, imp_iff_right he.1.1] at he
  simp_rw [dual_dep_iff_forall, insert_subset_iff, and_iff_right he.1.1,
    and_iff_left ((inter_subset_left _ _).trans (diff_subset _ _))]
  refine' fun B' hB' ↦ by_contra (fun hem ↦ _)
  rw [nonempty_iff_ne_empty, not_ne_iff, ← union_singleton, diff_inter_diff,
   inter_distrib_right, union_empty_iff, singleton_inter_eq_empty, diff_eq,
   inter_right_comm, inter_eq_self_of_subset_right hB'.subset_ground, ← diff_eq,
   diff_eq_empty] at hem
  

Proof state:
case refine'_2
α : Type u_1
M : Matroid α
I B X : Set α
hB : M.Base B
hBX : M.Basis (B ∩ X) X
e : α
he : (e ∈ M.E ∧ e ∉ X) ∧ e ∈ B
B' : Set α
hB' : M.Base B'
hem : B' ⊆ B ∪ X ∧ e ∉ B'
⊢ False

Next tactic:
obtain ⟨f, hfb, hBf⟩ := hB.exchange hB' ⟨he.2, hem.2⟩
theorem Base.compl_inter_basis_of_inter_basis (hB : M.Base B) (hBX : M.Basis (B ∩ X) X) :
    M﹡.Basis ((M.E \ B) ∩ (M.E \ X)) (M.E \ X) := by
  refine' Indep.basis_of_forall_insert _ (inter_subset_right _ _) (fun e he ↦ _)
  · rw [dual_indep_iff_exists]
    exact ⟨B, hB, disjoint_of_subset_left (inter_subset_left _ _) disjoint_sdiff_left⟩
  simp only [diff_inter_self_eq_diff, mem_diff, not_and, not_not, imp_iff_right he.1.1] at he
  simp_rw [dual_dep_iff_forall, insert_subset_iff, and_iff_right he.1.1,
    and_iff_left ((inter_subset_left _ _).trans (diff_subset _ _))]
  refine' fun B' hB' ↦ by_contra (fun hem ↦ _)
  rw [nonempty_iff_ne_empty, not_ne_iff, ← union_singleton, diff_inter_diff,
   inter_distrib_right, union_empty_iff, singleton_inter_eq_empty, diff_eq,
   inter_right_comm, inter_eq_self_of_subset_right hB'.subset_ground, ← diff_eq,
   diff_eq_empty] at hem
  obtain ⟨f, hfb, hBf⟩ := hB.exchange hB' ⟨he.2, hem.2⟩

  

Proof state:
case refine'_2.intro.intro
α : Type u_1
M : Matroid α
I B X : Set α
hB : M.Base B
hBX : M.Basis (B ∩ X) X
e : α
he : (e ∈ M.E ∧ e ∉ X) ∧ e ∈ B
B' : Set α
hB' : M.Base B'
hem : B' ⊆ B ∪ X ∧ e ∉ B'
f : α
hfb : f ∈ B' \ B
hBf : M.Base (insert f (B \ {e}))
⊢ False

Next tactic:
have hi : M.Indep (insert f (B ∩ X))
theorem Base.compl_inter_basis_of_inter_basis (hB : M.Base B) (hBX : M.Basis (B ∩ X) X) :
    M﹡.Basis ((M.E \ B) ∩ (M.E \ X)) (M.E \ X) := by
  refine' Indep.basis_of_forall_insert _ (inter_subset_right _ _) (fun e he ↦ _)
  · rw [dual_indep_iff_exists]
    exact ⟨B, hB, disjoint_of_subset_left (inter_subset_left _ _) disjoint_sdiff_left⟩
  simp only [diff_inter_self_eq_diff, mem_diff, not_and, not_not, imp_iff_right he.1.1] at he
  simp_rw [dual_dep_iff_forall, insert_subset_iff, and_iff_right he.1.1,
    and_iff_left ((inter_subset_left _ _).trans (diff_subset _ _))]
  refine' fun B' hB' ↦ by_contra (fun hem ↦ _)
  rw [nonempty_iff_ne_empty, not_ne_iff, ← union_singleton, diff_inter_diff,
   inter_distrib_right, union_empty_iff, singleton_inter_eq_empty, diff_eq,
   inter_right_comm, inter_eq_self_of_subset_right hB'.subset_ground, ← diff_eq,
   diff_eq_empty] at hem
  obtain ⟨f, hfb, hBf⟩ := hB.exchange hB' ⟨he.2, hem.2⟩

  have hi : M.Indep (insert f (B ∩ X))
  · 

Proof state:
case hi
α : Type u_1
M : Matroid α
I B X : Set α
hB : M.Base B
hBX : M.Basis (B ∩ X) X
e : α
he : (e ∈ M.E ∧ e ∉ X) ∧ e ∈ B
B' : Set α
hB' : M.Base B'
hem : B' ⊆ B ∪ X ∧ e ∉ B'
f : α
hfb : f ∈ B' \ B
hBf : M.Base (insert f (B \ {e}))
⊢ M.Indep (insert f (B ∩ X))

Next tactic:
refine' hBf.indep.subset (insert_subset_insert _)
theorem Base.compl_inter_basis_of_inter_basis (hB : M.Base B) (hBX : M.Basis (B ∩ X) X) :
    M﹡.Basis ((M.E \ B) ∩ (M.E \ X)) (M.E \ X) := by
  refine' Indep.basis_of_forall_insert _ (inter_subset_right _ _) (fun e he ↦ _)
  · rw [dual_indep_iff_exists]
    exact ⟨B, hB, disjoint_of_subset_left (inter_subset_left _ _) disjoint_sdiff_left⟩
  simp only [diff_inter_self_eq_diff, mem_diff, not_and, not_not, imp_iff_right he.1.1] at he
  simp_rw [dual_dep_iff_forall, insert_subset_iff, and_iff_right he.1.1,
    and_iff_left ((inter_subset_left _ _).trans (diff_subset _ _))]
  refine' fun B' hB' ↦ by_contra (fun hem ↦ _)
  rw [nonempty_iff_ne_empty, not_ne_iff, ← union_singleton, diff_inter_diff,
   inter_distrib_right, union_empty_iff, singleton_inter_eq_empty, diff_eq,
   inter_right_comm, inter_eq_self_of_subset_right hB'.subset_ground, ← diff_eq,
   diff_eq_empty] at hem
  obtain ⟨f, hfb, hBf⟩ := hB.exchange hB' ⟨he.2, hem.2⟩

  have hi : M.Indep (insert f (B ∩ X))
  · refine' hBf.indep.subset (insert_subset_insert _)
    

Proof state:
case hi
α : Type u_1
M : Matroid α
I B X : Set α
hB : M.Base B
hBX : M.Basis (B ∩ X) X
e : α
he : (e ∈ M.E ∧ e ∉ X) ∧ e ∈ B
B' : Set α
hB' : M.Base B'
hem : B' ⊆ B ∪ X ∧ e ∉ B'
f : α
hfb : f ∈ B' \ B
hBf : M.Base (insert f (B \ {e}))
⊢ B ∩ X ⊆ B \ {e}

Next tactic:
simp_rw [subset_diff, and_iff_right (inter_subset_left _ _), disjoint_singleton_right,
      mem_inter_iff, iff_false_intro he.1.2, and_false, not_false_iff]
theorem Base.compl_inter_basis_of_inter_basis (hB : M.Base B) (hBX : M.Basis (B ∩ X) X) :
    M﹡.Basis ((M.E \ B) ∩ (M.E \ X)) (M.E \ X) := by
  refine' Indep.basis_of_forall_insert _ (inter_subset_right _ _) (fun e he ↦ _)
  · rw [dual_indep_iff_exists]
    exact ⟨B, hB, disjoint_of_subset_left (inter_subset_left _ _) disjoint_sdiff_left⟩
  simp only [diff_inter_self_eq_diff, mem_diff, not_and, not_not, imp_iff_right he.1.1] at he
  simp_rw [dual_dep_iff_forall, insert_subset_iff, and_iff_right he.1.1,
    and_iff_left ((inter_subset_left _ _).trans (diff_subset _ _))]
  refine' fun B' hB' ↦ by_contra (fun hem ↦ _)
  rw [nonempty_iff_ne_empty, not_ne_iff, ← union_singleton, diff_inter_diff,
   inter_distrib_right, union_empty_iff, singleton_inter_eq_empty, diff_eq,
   inter_right_comm, inter_eq_self_of_subset_right hB'.subset_ground, ← diff_eq,
   diff_eq_empty] at hem
  obtain ⟨f, hfb, hBf⟩ := hB.exchange hB' ⟨he.2, hem.2⟩

  have hi : M.Indep (insert f (B ∩ X))
  · refine' hBf.indep.subset (insert_subset_insert _)
    simp_rw [subset_diff, and_iff_right (inter_subset_left _ _), disjoint_singleton_right,
      mem_inter_iff, iff_false_intro he.1.2, and_false, not_false_iff]
  

Proof state:
case refine'_2.intro.intro
α : Type u_1
M : Matroid α
I B X : Set α
hB : M.Base B
hBX : M.Basis (B ∩ X) X
e : α
he : (e ∈ M.E ∧ e ∉ X) ∧ e ∈ B
B' : Set α
hB' : M.Base B'
hem : B' ⊆ B ∪ X ∧ e ∉ B'
f : α
hfb : f ∈ B' \ B
hBf : M.Base (insert f (B \ {e}))
hi : M.Indep (insert f (B ∩ X))
⊢ False

Next tactic:
exact hfb.2 (hBX.mem_of_insert_indep (Or.elim (hem.1 hfb.1) (False.elim ∘ hfb.2) id) hi).1
theorem Base.inter_basis_iff_compl_inter_basis_dual (hB : M.Base B) (hX : X ⊆ M.E := by aesop_mat):
    M.Basis (B ∩ X) X ↔ M﹡.Basis ((M.E \ B) ∩ (M.E \ X)) (M.E \ X) := by
  

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
hB : M.Base B
hX : autoParam (X ⊆ M.E) _auto✝
⊢ M.Basis (B ∩ X) X ↔ M﹡.Basis (M.E \ B ∩ (M.E \ X)) (M.E \ X)

Next tactic:
refine' ⟨hB.compl_inter_basis_of_inter_basis, fun h ↦ _⟩
theorem Base.inter_basis_iff_compl_inter_basis_dual (hB : M.Base B) (hX : X ⊆ M.E := by aesop_mat):
    M.Basis (B ∩ X) X ↔ M﹡.Basis ((M.E \ B) ∩ (M.E \ X)) (M.E \ X) := by
  refine' ⟨hB.compl_inter_basis_of_inter_basis, fun h ↦ _⟩
  

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
hB : M.Base B
hX : autoParam (X ⊆ M.E) _auto✝
h : M﹡.Basis (M.E \ B ∩ (M.E \ X)) (M.E \ X)
⊢ M.Basis (B ∩ X) X

Next tactic:
simpa [inter_eq_self_of_subset_right hX, inter_eq_self_of_subset_right hB.subset_ground] using
    hB.compl_base_dual.compl_inter_basis_of_inter_basis h
theorem base_iff_dual_base_compl (hB : B ⊆ M.E := by aesop_mat) :
    M.Base B ↔ M﹡.Base (M.E \ B) := by
  

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
hB : autoParam (B ⊆ M.E) _auto✝
⊢ M.Base B ↔ M﹡.Base (M.E \ B)

Next tactic:
rw [dual_base_iff, diff_diff_cancel_left hB]
theorem ground_not_base (M : Matroid α) [h : RkPos M﹡] : ¬M.Base M.E := by
  

Proof state:
α : Type u_1
M✝ : Matroid α
I B X : Set α
M : Matroid α
h : RkPos M﹡
⊢ ¬M.Base M.E

Next tactic:
rwa [rkPos_iff_empty_not_base, dual_base_iff, diff_empty] at h
theorem Base.ssubset_ground [h : RkPos M﹡] (hB : M.Base B) : B ⊂ M.E :=
  hB.subset_ground.ssubset_of_ne (by 

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
h : RkPos M﹡
hB : M.Base B
⊢ B ≠ M.E

Next tactic:
rintro rfl
theorem Base.ssubset_ground [h : RkPos M﹡] (hB : M.Base B) : B ⊂ M.E :=
  hB.subset_ground.ssubset_of_ne (by rintro rfl; 

Proof state:
α : Type u_1
M : Matroid α
I X : Set α
h : RkPos M﹡
hB : M.Base M.E
⊢ False

Next tactic:
exact M.ground_not_base hB
theorem Indep.ssubset_ground [h : RkPos M﹡] (hI : M.Indep I) : I ⊂ M.E := by
  

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
h : RkPos M﹡
hI : M.Indep I
⊢ I ⊂ M.E

Next tactic:
obtain ⟨B, hB⟩ := hI.exists_base_superset
theorem Indep.ssubset_ground [h : RkPos M﹡] (hI : M.Indep I) : I ⊂ M.E := by
  obtain ⟨B, hB⟩ := hI.exists_base_superset; 

Proof state:
case intro
α : Type u_1
M : Matroid α
I B✝ X : Set α
h : RkPos M﹡
hI : M.Indep I
B : Set α
hB : M.Base B ∧ I ⊆ B
⊢ I ⊂ M.E

Next tactic:
exact hB.2.trans_ssubset hB.1.ssubset_ground
@[simp] theorem dual_coindep_iff : M﹡.Coindep X ↔ M.Indep X := by
  

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
⊢ Coindep M﹡ X ↔ M.Indep X

Next tactic:
rw [Coindep, dual_dual]
theorem coindep_iff_exists' : M.Coindep X ↔ (∃ B, M.Base B ∧ B ⊆ M.E \ X) ∧ X ⊆ M.E := by
  

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
⊢ Coindep M X ↔ (∃ B, M.Base B ∧ B ⊆ M.E \ X) ∧ X ⊆ M.E

Next tactic:
simp_rw [Coindep, dual_indep_iff_exists', and_comm (a := _ ⊆ _), and_congr_left_iff, subset_diff]
theorem coindep_iff_exists' : M.Coindep X ↔ (∃ B, M.Base B ∧ B ⊆ M.E \ X) ∧ X ⊆ M.E := by
  simp_rw [Coindep, dual_indep_iff_exists', and_comm (a := _ ⊆ _), and_congr_left_iff, subset_diff]
  

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
⊢ X ⊆ M.E → ((∃ B, M.Base B ∧ Disjoint X B) ↔ ∃ B, M.Base B ∧ B ⊆ M.E ∧ Disjoint B X)

Next tactic:
exact fun _ ↦ ⟨fun ⟨B, hB, hXB⟩ ↦ ⟨B, hB, hB.subset_ground, hXB.symm⟩,
    fun ⟨B, hB, _, hBX⟩ ↦ ⟨B, hB, hBX.symm⟩⟩
theorem coindep_iff_exists (hX : X ⊆ M.E := by aesop_mat) :
    M.Coindep X ↔ ∃ B, M.Base B ∧ B ⊆ M.E \ X := by
  

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
hX : autoParam (X ⊆ M.E) _auto✝
⊢ Coindep M X ↔ ∃ B, M.Base B ∧ B ⊆ M.E \ X

Next tactic:
rw [coindep_iff_exists', and_iff_left hX]
theorem coindep_iff_subset_compl_base : M.Coindep X ↔ ∃ B, M.Base B ∧ X ⊆ M.E \ B := by
  

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
⊢ Coindep M X ↔ ∃ B, M.Base B ∧ X ⊆ M.E \ B

Next tactic:
simp_rw [coindep_iff_exists', subset_diff]
theorem coindep_iff_subset_compl_base : M.Coindep X ↔ ∃ B, M.Base B ∧ X ⊆ M.E \ B := by
  simp_rw [coindep_iff_exists', subset_diff]
  

Proof state:
α : Type u_1
M : Matroid α
I B X : Set α
⊢ (∃ B, M.Base B ∧ B ⊆ M.E ∧ Disjoint B X) ∧ X ⊆ M.E ↔ ∃ B, M.Base B ∧ X ⊆ M.E ∧ Disjoint X B

Next tactic:
exact ⟨fun ⟨⟨B, hB, _, hBX⟩, hX⟩ ↦ ⟨B, hB, hX, hBX.symm⟩,
    fun ⟨B, hB, hXE, hXB⟩ ↦ ⟨⟨B, hB, hB.subset_ground,  hXB.symm⟩, hXE⟩⟩
instance {X Y : Action V G} : Zero (X ⟶ Y) := ⟨0, by 

Proof state:
V : Type (u + 1)
inst✝¹ : LargeCategory V
G : MonCat
inst✝ : HasZeroMorphisms V
X Y : Action V G
⊢ ∀ (g : ↑G), X.ρ g ≫ 0 = 0 ≫ Y.ρ g

Next tactic:
aesop_cat
instance : Preadditive (Action V G) where
  homGroup X Y :=
    { add := fun f g => ⟨f.hom + g.hom, by 

Proof state:
V : Type (u + 1)
inst✝¹ : LargeCategory V
G : MonCat
inst✝ : Preadditive V
X Y : Action V G
f g : X ⟶ Y
⊢ ∀ (g_1 : ↑G), X.ρ g_1 ≫ (f.hom + g.hom) = (f.hom + g.hom) ≫ Y.ρ g_1

Next tactic:
simp [f.comm, g.comm]