l3lab/ntp-mathlib huggingface dataset:
theorem Basis.exists_basis_inter_eq_of_superset (hI : M.Basis I X) (hXY : X ⊆ Y)
    (hY : Y ⊆ M.E := by aesop_mat) : ∃ J, M.Basis J Y ∧ J ∩ X = I := by
  

Proof state:
α : Type u_1
M : Matroid α
I X Y : Set α
hI : M.Basis I X
hXY : X ⊆ Y
hY : autoParam (Y ⊆ M.E) _auto✝
⊢ ∃ J, M.Basis J Y ∧ J ∩ X = I

Next tactic:
obtain ⟨J, hJ, hIJ⟩ := hI.indep.subset_basis_of_subset (hI.subset.trans hXY)
theorem Basis.exists_basis_inter_eq_of_superset (hI : M.Basis I X) (hXY : X ⊆ Y)
    (hY : Y ⊆ M.E := by aesop_mat) : ∃ J, M.Basis J Y ∧ J ∩ X = I := by
  obtain ⟨J, hJ, hIJ⟩ := hI.indep.subset_basis_of_subset (hI.subset.trans hXY)
  

Proof state:
case intro.intro
α : Type u_1
M : Matroid α
I X Y : Set α
hI : M.Basis I X
hXY : X ⊆ Y
hY : autoParam (Y ⊆ M.E) _auto✝
J : Set α
hJ : M.Basis J Y
hIJ : I ⊆ J
⊢ ∃ J, M.Basis J Y ∧ J ∩ X = I

Next tactic:
refine ⟨J, hJ, subset_antisymm ?_ (subset_inter hIJ hI.subset)⟩
theorem Basis.exists_basis_inter_eq_of_superset (hI : M.Basis I X) (hXY : X ⊆ Y)
    (hY : Y ⊆ M.E := by aesop_mat) : ∃ J, M.Basis J Y ∧ J ∩ X = I := by
  obtain ⟨J, hJ, hIJ⟩ := hI.indep.subset_basis_of_subset (hI.subset.trans hXY)
  refine ⟨J, hJ, subset_antisymm ?_ (subset_inter hIJ hI.subset)⟩
  

Proof state:
case intro.intro
α : Type u_1
M : Matroid α
I X Y : Set α
hI : M.Basis I X
hXY : X ⊆ Y
hY : autoParam (Y ⊆ M.E) _auto✝
J : Set α
hJ : M.Basis J Y
hIJ : I ⊆ J
⊢ J ∩ X ⊆ I

Next tactic:
exact fun e he ↦ hI.mem_of_insert_indep he.2 (hJ.indep.subset (insert_subset he.1 hIJ))
theorem exists_basis_union_inter_basis (M : Matroid α) (X Y : Set α) (hX : X ⊆ M.E := by aesop_mat)
    (hY : Y ⊆ M.E := by aesop_mat) : ∃ I, M.Basis I (X ∪ Y) ∧ M.Basis (I ∩ Y) Y :=
  let ⟨J, hJ⟩ := M.exists_basis Y
  (hJ.exists_basis_inter_eq_of_superset (subset_union_right X Y)).imp
  (fun I hI ↦ ⟨hI.1, by 

Proof state:
α : Type u_1
M✝ M : Matroid α
X Y : Set α
hX : autoParam (X ⊆ M.E) _auto✝
hY : autoParam (Y ⊆ M.E) _auto✝
J : Set α
hJ : M.Basis J Y
I : Set α
hI : M.Basis I (X ∪ Y) ∧ I ∩ Y = J
⊢ M.Basis (I ∩ Y) Y

Next tactic:
rwa [hI.2]
theorem Basis.exists_base (hI : M.Basis I X) : ∃ B, M.Base B ∧ I = B ∩ X :=
  let ⟨B,hB, hIB⟩ := hI.indep
  ⟨B, hB, subset_antisymm (subset_inter hIB hI.subset)
    (by 

Proof state:
α : Type u_1
M : Matroid α
I X : Set α
hI : M.Basis I X
B : Set α
hB : M.Base B
hIB : I ⊆ B
⊢ B ∩ X ⊆ I

Next tactic:
rw [hI.eq_of_subset_indep (hB.indep.inter_right X) (subset_inter hIB hI.subset)
    (inter_subset_right _ _)]
@[simp] theorem basis_ground_iff : M.Basis B M.E ↔ M.Base B := by
  

Proof state:
α : Type u_1
M : Matroid α
B : Set α
⊢ M.Basis B M.E ↔ M.Base B

Next tactic:
rw [base_iff_maximal_indep, basis_iff', and_assoc, and_congr_right]
@[simp] theorem basis_ground_iff : M.Basis B M.E ↔ M.Base B := by
  rw [base_iff_maximal_indep, basis_iff', and_assoc, and_congr_right]
  

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

Next tactic:
rw [and_iff_left (rfl.subset : M.E ⊆ M.E)]
@[simp] theorem basis_ground_iff : M.Basis B M.E ↔ M.Base B := by
  rw [base_iff_maximal_indep, basis_iff', and_assoc, and_congr_right]
  rw [and_iff_left (rfl.subset : M.E ⊆ M.E)]
  

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

Next tactic:
exact fun h ↦ ⟨fun h' I hI hBI ↦ h'.2 _ hI hBI hI.subset_ground,
    fun h' ↦ ⟨h.subset_ground,fun J hJ hBJ _ ↦ h' J hJ hBJ⟩⟩
theorem Indep.basis_iff_forall_insert_dep (hI : M.Indep I) (hIX : I ⊆ X) :
    M.Basis I X ↔ ∀ e ∈ X \ I, M.Dep (insert e I) := by
  

Proof state:
α : Type u_1
M : Matroid α
I X : Set α
hI : M.Indep I
hIX : I ⊆ X
⊢ M.Basis I X ↔ ∀ e ∈ X \ I, M.Dep (insert e I)

Next tactic:
rw [basis_iff', and_iff_right hIX, and_iff_right hI]
theorem Indep.basis_iff_forall_insert_dep (hI : M.Indep I) (hIX : I ⊆ X) :
    M.Basis I X ↔ ∀ e ∈ X \ I, M.Dep (insert e I) := by
  rw [basis_iff', and_iff_right hIX, and_iff_right hI]
  

Proof state:
α : Type u_1
M : Matroid α
I X : Set α
hI : M.Indep I
hIX : I ⊆ X
⊢ (∀ (J : Set α), M.Indep J → I ⊆ J → J ⊆ X → I = J) ∧ X ⊆ M.E ↔ ∀ e ∈ X \ I, M.Dep (insert e I)

Next tactic:
refine' ⟨fun h e he ↦ ⟨fun hi ↦ he.2 _, insert_subset (h.2 he.1) hI.subset_ground⟩,
    fun h ↦ ⟨fun J hJ hIJ hJX ↦ hIJ.antisymm (fun e heJ ↦ by_contra (fun heI ↦ _)),_⟩⟩
theorem Indep.basis_iff_forall_insert_dep (hI : M.Indep I) (hIX : I ⊆ X) :
    M.Basis I X ↔ ∀ e ∈ X \ I, M.Dep (insert e I) := by
  rw [basis_iff', and_iff_right hIX, and_iff_right hI]
  refine' ⟨fun h e he ↦ ⟨fun hi ↦ he.2 _, insert_subset (h.2 he.1) hI.subset_ground⟩,
    fun h ↦ ⟨fun J hJ hIJ hJX ↦ hIJ.antisymm (fun e heJ ↦ by_contra (fun heI ↦ _)),_⟩⟩
  · 

Proof state:
case refine'_1
α : Type u_1
M : Matroid α
I X : Set α
hI : M.Indep I
hIX : I ⊆ X
h : (∀ (J : Set α), M.Indep J → I ⊆ J → J ⊆ X → I = J) ∧ X ⊆ M.E
e : α
he : e ∈ X \ I
hi : M.Indep (insert e I)
⊢ e ∈ I

Next tactic:
exact (h.1 _ hi (subset_insert _ _) (insert_subset he.1 hIX)).symm.subset (mem_insert e I)
theorem Indep.basis_iff_forall_insert_dep (hI : M.Indep I) (hIX : I ⊆ X) :
    M.Basis I X ↔ ∀ e ∈ X \ I, M.Dep (insert e I) := by
  rw [basis_iff', and_iff_right hIX, and_iff_right hI]
  refine' ⟨fun h e he ↦ ⟨fun hi ↦ he.2 _, insert_subset (h.2 he.1) hI.subset_ground⟩,
    fun h ↦ ⟨fun J hJ hIJ hJX ↦ hIJ.antisymm (fun e heJ ↦ by_contra (fun heI ↦ _)),_⟩⟩
  · exact (h.1 _ hi (subset_insert _ _) (insert_subset he.1 hIX)).symm.subset (mem_insert e I)
  · 

Proof state:
case refine'_2
α : Type u_1
M : Matroid α
I X : Set α
hI : M.Indep I
hIX : I ⊆ X
h : ∀ e ∈ X \ I, M.Dep (insert e I)
J : Set α
hJ : M.Indep J
hIJ : I ⊆ J
hJX : J ⊆ X
e : α
heJ : e ∈ J
heI : e ∉ I
⊢ False

Next tactic:
exact (h e ⟨hJX heJ, heI⟩).not_indep (hJ.subset (insert_subset heJ hIJ))
theorem Indep.basis_iff_forall_insert_dep (hI : M.Indep I) (hIX : I ⊆ X) :
    M.Basis I X ↔ ∀ e ∈ X \ I, M.Dep (insert e I) := by
  rw [basis_iff', and_iff_right hIX, and_iff_right hI]
  refine' ⟨fun h e he ↦ ⟨fun hi ↦ he.2 _, insert_subset (h.2 he.1) hI.subset_ground⟩,
    fun h ↦ ⟨fun J hJ hIJ hJX ↦ hIJ.antisymm (fun e heJ ↦ by_contra (fun heI ↦ _)),_⟩⟩
  · exact (h.1 _ hi (subset_insert _ _) (insert_subset he.1 hIX)).symm.subset (mem_insert e I)
  · exact (h e ⟨hJX heJ, heI⟩).not_indep (hJ.subset (insert_subset heJ hIJ))
  

Proof state:
case refine'_3
α : Type u_1
M : Matroid α
I X : Set α
hI : M.Indep I
hIX : I ⊆ X
h : ∀ e ∈ X \ I, M.Dep (insert e I)
⊢ X ⊆ M.E

Next tactic:
rw [← diff_union_of_subset hIX, union_subset_iff, and_iff_left hI.subset_ground]
theorem Indep.basis_iff_forall_insert_dep (hI : M.Indep I) (hIX : I ⊆ X) :
    M.Basis I X ↔ ∀ e ∈ X \ I, M.Dep (insert e I) := by
  rw [basis_iff', and_iff_right hIX, and_iff_right hI]
  refine' ⟨fun h e he ↦ ⟨fun hi ↦ he.2 _, insert_subset (h.2 he.1) hI.subset_ground⟩,
    fun h ↦ ⟨fun J hJ hIJ hJX ↦ hIJ.antisymm (fun e heJ ↦ by_contra (fun heI ↦ _)),_⟩⟩
  · exact (h.1 _ hi (subset_insert _ _) (insert_subset he.1 hIX)).symm.subset (mem_insert e I)
  · exact (h e ⟨hJX heJ, heI⟩).not_indep (hJ.subset (insert_subset heJ hIJ))
  rw [← diff_union_of_subset hIX, union_subset_iff, and_iff_left hI.subset_ground]
  

Proof state:
case refine'_3
α : Type u_1
M : Matroid α
I X : Set α
hI : M.Indep I
hIX : I ⊆ X
h : ∀ e ∈ X \ I, M.Dep (insert e I)
⊢ X \ I ⊆ M.E

Next tactic:
exact fun e he ↦ (h e he).subset_ground (mem_insert _ _)
theorem Indep.basis_insert_iff (hI : M.Indep I) :
    M.Basis I (insert e I) ↔ M.Dep (insert e I) ∨ e ∈ I := by
  

Proof state:
α : Type u_1
M : Matroid α
I : Set α
e : α
hI : M.Indep I
⊢ M.Basis I (insert e I) ↔ M.Dep (insert e I) ∨ e ∈ I

Next tactic:
simp_rw [hI.basis_iff_forall_insert_dep (subset_insert _ _), dep_iff, insert_subset_iff,
    and_iff_left hI.subset_ground, mem_diff, mem_insert_iff, or_and_right, and_not_self,
    or_false, and_imp, forall_eq]
theorem Indep.basis_insert_iff (hI : M.Indep I) :
    M.Basis I (insert e I) ↔ M.Dep (insert e I) ∨ e ∈ I := by
  simp_rw [hI.basis_iff_forall_insert_dep (subset_insert _ _), dep_iff, insert_subset_iff,
    and_iff_left hI.subset_ground, mem_diff, mem_insert_iff, or_and_right, and_not_self,
    or_false, and_imp, forall_eq]
  

Proof state:
α : Type u_1
M : Matroid α
I : Set α
e : α
hI : M.Indep I
⊢ e ∉ I → ¬M.Indep (insert e I) ∧ e ∈ M.E ↔ ¬M.Indep (insert e I) ∧ e ∈ M.E ∨ e ∈ I

Next tactic:
tauto
theorem Basis.iUnion_basis_iUnion {ι : Type _} (X I : ι → Set α) (hI : ∀ i, M.Basis (I i) (X i))
    (h_ind : M.Indep (⋃ i, I i)) : M.Basis (⋃ i, I i) (⋃ i, X i) := by
  

Proof state:
α : Type u_2
M : Matroid α
ι : Type u_1
X I : ι → Set α
hI : ∀ (i : ι), M.Basis (I i) (X i)
h_ind : M.Indep (⋃ i, I i)
⊢ M.Basis (⋃ i, I i) (⋃ i, X i)

Next tactic:
refine' h_ind.basis_of_forall_insert
    (iUnion_subset (fun i ↦ (hI i).subset.trans (subset_iUnion _ _))) _
theorem Basis.iUnion_basis_iUnion {ι : Type _} (X I : ι → Set α) (hI : ∀ i, M.Basis (I i) (X i))
    (h_ind : M.Indep (⋃ i, I i)) : M.Basis (⋃ i, I i) (⋃ i, X i) := by
  refine' h_ind.basis_of_forall_insert
    (iUnion_subset (fun i ↦ (hI i).subset.trans (subset_iUnion _ _))) _
  

Proof state:
α : Type u_2
M : Matroid α
ι : Type u_1
X I : ι → Set α
hI : ∀ (i : ι), M.Basis (I i) (X i)
h_ind : M.Indep (⋃ i, I i)
⊢ ∀ e ∈ (⋃ i, X i) \ ⋃ i, I i, M.Dep (insert e (⋃ i, I i))

Next tactic:
rintro e ⟨⟨_, ⟨⟨i, hi, rfl⟩, (hes : e ∈ X i)⟩⟩, he'⟩
theorem Basis.iUnion_basis_iUnion {ι : Type _} (X I : ι → Set α) (hI : ∀ i, M.Basis (I i) (X i))
    (h_ind : M.Indep (⋃ i, I i)) : M.Basis (⋃ i, I i) (⋃ i, X i) := by
  refine' h_ind.basis_of_forall_insert
    (iUnion_subset (fun i ↦ (hI i).subset.trans (subset_iUnion _ _))) _
  rintro e ⟨⟨_, ⟨⟨i, hi, rfl⟩, (hes : e ∈ X i)⟩⟩, he'⟩
  

Proof state:
case intro.intro.intro.intro.refl
α : Type u_2
M : Matroid α
ι : Type u_1
X I : ι → Set α
hI : ∀ (i : ι), M.Basis (I i) (X i)
h_ind : M.Indep (⋃ i, I i)
e : α
he' : e ∉ ⋃ i, I i
i : ι
hes : e ∈ X i
⊢ M.Dep (insert e (⋃ i, I i))

Next tactic:
rw [mem_iUnion, not_exists] at he'
theorem Basis.iUnion_basis_iUnion {ι : Type _} (X I : ι → Set α) (hI : ∀ i, M.Basis (I i) (X i))
    (h_ind : M.Indep (⋃ i, I i)) : M.Basis (⋃ i, I i) (⋃ i, X i) := by
  refine' h_ind.basis_of_forall_insert
    (iUnion_subset (fun i ↦ (hI i).subset.trans (subset_iUnion _ _))) _
  rintro e ⟨⟨_, ⟨⟨i, hi, rfl⟩, (hes : e ∈ X i)⟩⟩, he'⟩
  rw [mem_iUnion, not_exists] at he'
  

Proof state:
case intro.intro.intro.intro.refl
α : Type u_2
M : Matroid α
ι : Type u_1
X I : ι → Set α
hI : ∀ (i : ι), M.Basis (I i) (X i)
h_ind : M.Indep (⋃ i, I i)
e : α
he' : ∀ (x : ι), e ∉ I x
i : ι
hes : e ∈ X i
⊢ M.Dep (insert e (⋃ i, I i))

Next tactic:
refine' ((hI i).insert_dep ⟨hes, he' _⟩).superset (insert_subset_insert (subset_iUnion _ _)) _
theorem Basis.iUnion_basis_iUnion {ι : Type _} (X I : ι → Set α) (hI : ∀ i, M.Basis (I i) (X i))
    (h_ind : M.Indep (⋃ i, I i)) : M.Basis (⋃ i, I i) (⋃ i, X i) := by
  refine' h_ind.basis_of_forall_insert
    (iUnion_subset (fun i ↦ (hI i).subset.trans (subset_iUnion _ _))) _
  rintro e ⟨⟨_, ⟨⟨i, hi, rfl⟩, (hes : e ∈ X i)⟩⟩, he'⟩
  rw [mem_iUnion, not_exists] at he'
  refine' ((hI i).insert_dep ⟨hes, he' _⟩).superset (insert_subset_insert (subset_iUnion _ _)) _
  

Proof state:
case intro.intro.intro.intro.refl
α : Type u_2
M : Matroid α
ι : Type u_1
X I : ι → Set α
hI : ∀ (i : ι), M.Basis (I i) (X i)
h_ind : M.Indep (⋃ i, I i)
e : α
he' : ∀ (x : ι), e ∉ I x
i : ι
hes : e ∈ X i
⊢ insert e (⋃ i, I i) ⊆ M.E

Next tactic:
rw [insert_subset_iff, iUnion_subset_iff, and_iff_left (fun i ↦ (hI i).indep.subset_ground)]
theorem Basis.iUnion_basis_iUnion {ι : Type _} (X I : ι → Set α) (hI : ∀ i, M.Basis (I i) (X i))
    (h_ind : M.Indep (⋃ i, I i)) : M.Basis (⋃ i, I i) (⋃ i, X i) := by
  refine' h_ind.basis_of_forall_insert
    (iUnion_subset (fun i ↦ (hI i).subset.trans (subset_iUnion _ _))) _
  rintro e ⟨⟨_, ⟨⟨i, hi, rfl⟩, (hes : e ∈ X i)⟩⟩, he'⟩
  rw [mem_iUnion, not_exists] at he'
  refine' ((hI i).insert_dep ⟨hes, he' _⟩).superset (insert_subset_insert (subset_iUnion _ _)) _
  rw [insert_subset_iff, iUnion_subset_iff, and_iff_left (fun i ↦ (hI i).indep.subset_ground)]
  

Proof state:
case intro.intro.intro.intro.refl
α : Type u_2
M : Matroid α
ι : Type u_1
X I : ι → Set α
hI : ∀ (i : ι), M.Basis (I i) (X i)
h_ind : M.Indep (⋃ i, I i)
e : α
he' : ∀ (x : ι), e ∉ I x
i : ι
hes : e ∈ X i
⊢ e ∈ M.E

Next tactic:
exact (hI i).subset_ground hes
theorem Basis.basis_iUnion {ι : Type _} [Nonempty ι] (X : ι → Set α)
    (hI : ∀ i, M.Basis I (X i)) : M.Basis I (⋃ i, X i) := by
  

Proof state:
α : Type u_1
M : Matroid α
I : Set α
ι : Type u_2
inst✝ : Nonempty ι
X : ι → Set α
hI : ∀ (i : ι), M.Basis I (X i)
⊢ M.Basis I (⋃ i, X i)

Next tactic:
convert Basis.iUnion_basis_iUnion X (fun _ ↦ I) (fun i ↦ hI i) _
theorem Basis.basis_iUnion {ι : Type _} [Nonempty ι] (X : ι → Set α)
    (hI : ∀ i, M.Basis I (X i)) : M.Basis I (⋃ i, X i) := by
  convert Basis.iUnion_basis_iUnion X (fun _ ↦ I) (fun i ↦ hI i) _ <;> 

Proof state:
case h.e'_3
α : Type u_1
M : Matroid α
I : Set α
ι : Type u_2
inst✝ : Nonempty ι
X : ι → Set α
hI : ∀ (i : ι), M.Basis I (X i)
⊢ I = ⋃ i, I

Next tactic:
rw [iUnion_const]
theorem Basis.basis_iUnion {ι : Type _} [Nonempty ι] (X : ι → Set α)
    (hI : ∀ i, M.Basis I (X i)) : M.Basis I (⋃ i, X i) := by
  convert Basis.iUnion_basis_iUnion X (fun _ ↦ I) (fun i ↦ hI i) _ <;> 

Proof state:
α : Type u_1
M : Matroid α
I : Set α
ι : Type u_2
inst✝ : Nonempty ι
X : ι → Set α
hI : ∀ (i : ι), M.Basis I (X i)
⊢ M.Indep (⋃ i, (fun x => I) i)

Next tactic:
rw [iUnion_const]
theorem Basis.basis_iUnion {ι : Type _} [Nonempty ι] (X : ι → Set α)
    (hI : ∀ i, M.Basis I (X i)) : M.Basis I (⋃ i, X i) := by
  convert Basis.iUnion_basis_iUnion X (fun _ ↦ I) (fun i ↦ hI i) _ <;> rw [iUnion_const]
  

Proof state:
α : Type u_1
M : Matroid α
I : Set α
ι : Type u_2
inst✝ : Nonempty ι
X : ι → Set α
hI : ∀ (i : ι), M.Basis I (X i)
⊢ M.Indep I

Next tactic:
exact (hI (Classical.arbitrary ι)).indep
theorem Basis.basis_sUnion {Xs : Set (Set α)} (hne : Xs.Nonempty) (h : ∀ X ∈ Xs, M.Basis I X) :
    M.Basis I (⋃₀ Xs) := by
  

Proof state:
α : Type u_1
M : Matroid α
I : Set α
Xs : Set (Set α)
hne : Set.Nonempty Xs
h : ∀ X ∈ Xs, M.Basis I X
⊢ M.Basis I (⋃₀ Xs)

Next tactic:
rw [sUnion_eq_iUnion]
theorem Basis.basis_sUnion {Xs : Set (Set α)} (hne : Xs.Nonempty) (h : ∀ X ∈ Xs, M.Basis I X) :
    M.Basis I (⋃₀ Xs) := by
  rw [sUnion_eq_iUnion]
  

Proof state:
α : Type u_1
M : Matroid α
I : Set α
Xs : Set (Set α)
hne : Set.Nonempty Xs
h : ∀ X ∈ Xs, M.Basis I X
⊢ M.Basis I (⋃ i, ↑i)

Next tactic:
have := Iff.mpr nonempty_coe_sort hne
theorem Basis.basis_sUnion {Xs : Set (Set α)} (hne : Xs.Nonempty) (h : ∀ X ∈ Xs, M.Basis I X) :
    M.Basis I (⋃₀ Xs) := by
  rw [sUnion_eq_iUnion]
  have := Iff.mpr nonempty_coe_sort hne
  

Proof state:
α : Type u_1
M : Matroid α
I : Set α
Xs : Set (Set α)
hne : Set.Nonempty Xs
h : ∀ X ∈ Xs, M.Basis I X
this : Nonempty ↑Xs
⊢ M.Basis I (⋃ i, ↑i)

Next tactic:
exact Basis.basis_iUnion _ fun X ↦ (h X X.prop)
theorem Indep.basis_setOf_insert_basis (hI : M.Indep I) :
    M.Basis I {x | M.Basis I (insert x I)} := by
  

Proof state:
α : Type u_1
M : Matroid α
I : Set α
hI : M.Indep I
⊢ M.Basis I {x | M.Basis I (insert x I)}

Next tactic:
refine' hI.basis_of_forall_insert (fun e he ↦ (_ : M.Basis _ _))
    (fun e he ↦ ⟨fun hu ↦ he.2 _, he.1.subset_ground⟩)
theorem Indep.basis_setOf_insert_basis (hI : M.Indep I) :
    M.Basis I {x | M.Basis I (insert x I)} := by
  refine' hI.basis_of_forall_insert (fun e he ↦ (_ : M.Basis _ _))
    (fun e he ↦ ⟨fun hu ↦ he.2 _, he.1.subset_ground⟩)
  · 

Proof state:
case refine'_1
α : Type u_1
M : Matroid α
I : Set α
hI : M.Indep I
e : α
he : e ∈ I
⊢ M.Basis I (insert e I)

Next tactic:
rw [insert_eq_of_mem he]
theorem Indep.basis_setOf_insert_basis (hI : M.Indep I) :
    M.Basis I {x | M.Basis I (insert x I)} := by
  refine' hI.basis_of_forall_insert (fun e he ↦ (_ : M.Basis _ _))
    (fun e he ↦ ⟨fun hu ↦ he.2 _, he.1.subset_ground⟩)
  · rw [insert_eq_of_mem he]; 

Proof state:
case refine'_1
α : Type u_1
M : Matroid α
I : Set α
hI : M.Indep I
e : α
he : e ∈ I
⊢ M.Basis I I

Next tactic:
exact hI.basis_self
theorem Indep.basis_setOf_insert_basis (hI : M.Indep I) :
    M.Basis I {x | M.Basis I (insert x I)} := by
  refine' hI.basis_of_forall_insert (fun e he ↦ (_ : M.Basis _ _))
    (fun e he ↦ ⟨fun hu ↦ he.2 _, he.1.subset_ground⟩)
  · rw [insert_eq_of_mem he]; exact hI.basis_self
  

Proof state:
case refine'_2
α : Type u_1
M : Matroid α
I : Set α
hI : M.Indep I
e : α
he : e ∈ {x | M.Basis I (insert x I)} \ I
hu : M.Indep (insert e I)
⊢ e ∈ I

Next tactic:
simpa using (hu.eq_of_basis he.1).symm
theorem Basis.union_basis_union (hIX : M.Basis I X) (hJY : M.Basis J Y) (h : M.Indep (I ∪ J)) :
    M.Basis (I ∪ J) (X ∪ Y) := by
  

Proof state:
α : Type u_1
M : Matroid α
I X J Y : Set α
hIX : M.Basis I X
hJY : M.Basis J Y
h : M.Indep (I ∪ J)
⊢ M.Basis (I ∪ J) (X ∪ Y)

Next tactic:
rw [union_eq_iUnion, union_eq_iUnion]
theorem Basis.union_basis_union (hIX : M.Basis I X) (hJY : M.Basis J Y) (h : M.Indep (I ∪ J)) :
    M.Basis (I ∪ J) (X ∪ Y) := by
  rw [union_eq_iUnion, union_eq_iUnion]
  

Proof state:
α : Type u_1
M : Matroid α
I X J Y : Set α
hIX : M.Basis I X
hJY : M.Basis J Y
h : M.Indep (I ∪ J)
⊢ M.Basis (⋃ b, bif b then I else J) (⋃ b, bif b then X else Y)

Next tactic:
refine' Basis.iUnion_basis_iUnion _ _ _ _
theorem Basis.union_basis_union (hIX : M.Basis I X) (hJY : M.Basis J Y) (h : M.Indep (I ∪ J)) :
    M.Basis (I ∪ J) (X ∪ Y) := by
  rw [union_eq_iUnion, union_eq_iUnion]
  refine' Basis.iUnion_basis_iUnion _ _ _ _
  · 

Proof state:
case refine'_1
α : Type u_1
M : Matroid α
I X J Y : Set α
hIX : M.Basis I X
hJY : M.Basis J Y
h : M.Indep (I ∪ J)
⊢ ∀ (i : Bool), M.Basis (bif i then I else J) (bif i then X else Y)

Next tactic:
simp only [Bool.forall_bool, cond_false, cond_true]
theorem Basis.union_basis_union (hIX : M.Basis I X) (hJY : M.Basis J Y) (h : M.Indep (I ∪ J)) :
    M.Basis (I ∪ J) (X ∪ Y) := by
  rw [union_eq_iUnion, union_eq_iUnion]
  refine' Basis.iUnion_basis_iUnion _ _ _ _
  · simp only [Bool.forall_bool, cond_false, cond_true]; 

Proof state:
case refine'_1
α : Type u_1
M : Matroid α
I X J Y : Set α
hIX : M.Basis I X
hJY : M.Basis J Y
h : M.Indep (I ∪ J)
⊢ M.Basis J Y ∧ M.Basis I X

Next tactic:
exact ⟨hJY, hIX⟩
theorem Basis.union_basis_union (hIX : M.Basis I X) (hJY : M.Basis J Y) (h : M.Indep (I ∪ J)) :
    M.Basis (I ∪ J) (X ∪ Y) := by
  rw [union_eq_iUnion, union_eq_iUnion]
  refine' Basis.iUnion_basis_iUnion _ _ _ _
  · simp only [Bool.forall_bool, cond_false, cond_true]; exact ⟨hJY, hIX⟩
  

Proof state:
case refine'_2
α : Type u_1
M : Matroid α
I X J Y : Set α
hIX : M.Basis I X
hJY : M.Basis J Y
h : M.Indep (I ∪ J)
⊢ M.Indep (⋃ i, bif i then I else J)

Next tactic:
rwa [← union_eq_iUnion]
theorem Basis.basis_union (hIX : M.Basis I X) (hIY : M.Basis I Y) : M.Basis I (X ∪ Y) := by
    

Proof state:
α : Type u_1
M : Matroid α
I X Y : Set α
hIX : M.Basis I X
hIY : M.Basis I Y
⊢ M.Basis I (X ∪ Y)

Next tactic:
convert hIX.union_basis_union hIY _
theorem Basis.basis_union (hIX : M.Basis I X) (hIY : M.Basis I Y) : M.Basis I (X ∪ Y) := by
    convert hIX.union_basis_union hIY _ <;> 

Proof state:
case h.e'_3
α : Type u_1
M : Matroid α
I X Y : Set α
hIX : M.Basis I X
hIY : M.Basis I Y
⊢ I = I ∪ I

Next tactic:
rw [union_self]
theorem Basis.basis_union (hIX : M.Basis I X) (hIY : M.Basis I Y) : M.Basis I (X ∪ Y) := by
    convert hIX.union_basis_union hIY _ <;> 

Proof state:
α : Type u_1
M : Matroid α
I X Y : Set α
hIX : M.Basis I X
hIY : M.Basis I Y
⊢ M.Indep (I ∪ I)

Next tactic:
rw [union_self]
theorem Basis.basis_union (hIX : M.Basis I X) (hIY : M.Basis I Y) : M.Basis I (X ∪ Y) := by
    convert hIX.union_basis_union hIY _ <;> rw [union_self]; 

Proof state:
α : Type u_1
M : Matroid α
I X Y : Set α
hIX : M.Basis I X
hIY : M.Basis I Y
⊢ M.Indep I

Next tactic:
exact hIX.indep
theorem Basis.basis_union_of_subset (hI : M.Basis I X) (hJ : M.Indep J) (hIJ : I ⊆ J) :
    M.Basis J (J ∪ X) := by
  

Proof state:
α : Type u_1
M : Matroid α
I X J : Set α
hI : M.Basis I X
hJ : M.Indep J
hIJ : I ⊆ J
⊢ M.Basis J (J ∪ X)

Next tactic:
convert hJ.basis_self.union_basis_union hI _
theorem Basis.basis_union_of_subset (hI : M.Basis I X) (hJ : M.Indep J) (hIJ : I ⊆ J) :
    M.Basis J (J ∪ X) := by
  convert hJ.basis_self.union_basis_union hI _ <;>
  

Proof state:
case h.e'_3
α : Type u_1
M : Matroid α
I X J : Set α
hI : M.Basis I X
hJ : M.Indep J
hIJ : I ⊆ J
⊢ J = J ∪ I

Next tactic:
rw [union_eq_self_of_subset_right hIJ]
theorem Basis.basis_union_of_subset (hI : M.Basis I X) (hJ : M.Indep J) (hIJ : I ⊆ J) :
    M.Basis J (J ∪ X) := by
  convert hJ.basis_self.union_basis_union hI _ <;>
  

Proof state:
α : Type u_1
M : Matroid α
I X J : Set α
hI : M.Basis I X
hJ : M.Indep J
hIJ : I ⊆ J
⊢ M.Indep (J ∪ I)

Next tactic:
rw [union_eq_self_of_subset_right hIJ]
theorem Basis.basis_union_of_subset (hI : M.Basis I X) (hJ : M.Indep J) (hIJ : I ⊆ J) :
    M.Basis J (J ∪ X) := by
  convert hJ.basis_self.union_basis_union hI _ <;>
  rw [union_eq_self_of_subset_right hIJ]
  

Proof state:
α : Type u_1
M : Matroid α
I X J : Set α
hI : M.Basis I X
hJ : M.Indep J
hIJ : I ⊆ J
⊢ M.Indep J

Next tactic:
assumption
theorem Basis.insert_basis_insert (hI : M.Basis I X) (h : M.Indep (insert e I)) :
    M.Basis (insert e I) (insert e X) := by
  

Proof state:
α : Type u_1
M : Matroid α
I X : Set α
e : α
hI : M.Basis I X
h : M.Indep (insert e I)
⊢ M.Basis (insert e I) (insert e X)

Next tactic:
simp_rw [← union_singleton] at *
theorem Basis.insert_basis_insert (hI : M.Basis I X) (h : M.Indep (insert e I)) :
    M.Basis (insert e I) (insert e X) := by
  simp_rw [← union_singleton] at *
  

Proof state:
α : Type u_1
M : Matroid α
I X : Set α
e : α
hI : M.Basis I X
h : M.Indep (I ∪ {e})
⊢ M.Basis (I ∪ {e}) (X ∪ {e})

Next tactic:
exact hI.union_basis_union (h.subset (subset_union_right _ _)).basis_self h
theorem Base.base_of_basis_superset (hB : M.Base B) (hBX : B ⊆ X) (hIX : M.Basis I X) :
    M.Base I := by
  

Proof state:
α : Type u_1
M : Matroid α
B X I : Set α
hB : M.Base B
hBX : B ⊆ X
hIX : M.Basis I X
⊢ M.Base I

Next tactic:
by_contra h
theorem Base.base_of_basis_superset (hB : M.Base B) (hBX : B ⊆ X) (hIX : M.Basis I X) :
    M.Base I := by
  by_contra h
  

Proof state:
α : Type u_1
M : Matroid α
B X I : Set α
hB : M.Base B
hBX : B ⊆ X
hIX : M.Basis I X
h : ¬M.Base I
⊢ False

Next tactic:
obtain ⟨e,heBI,he⟩ := hIX.indep.exists_insert_of_not_base h hB
theorem Base.base_of_basis_superset (hB : M.Base B) (hBX : B ⊆ X) (hIX : M.Basis I X) :
    M.Base I := by
  by_contra h
  obtain ⟨e,heBI,he⟩ := hIX.indep.exists_insert_of_not_base h hB
  

Proof state:
case intro.intro
α : Type u_1
M : Matroid α
B X I : Set α
hB : M.Base B
hBX : B ⊆ X
hIX : M.Basis I X
h : ¬M.Base I
e : α
heBI : e ∈ B \ I
he : M.Indep (insert e I)
⊢ False

Next tactic:
exact heBI.2 (hIX.mem_of_insert_indep (hBX heBI.1) he)
theorem Indep.exists_base_subset_union_base (hI : M.Indep I) (hB : M.Base B) :
    ∃ B', M.Base B' ∧ I ⊆ B' ∧ B' ⊆ I ∪ B := by
  

Proof state:
α : Type u_1
M : Matroid α
I B : Set α
hI : M.Indep I
hB : M.Base B
⊢ ∃ B', M.Base B' ∧ I ⊆ B' ∧ B' ⊆ I ∪ B

Next tactic:
obtain ⟨B', hB', hIB'⟩ := hI.subset_basis_of_subset (subset_union_left I B)
theorem Indep.exists_base_subset_union_base (hI : M.Indep I) (hB : M.Base B) :
    ∃ B', M.Base B' ∧ I ⊆ B' ∧ B' ⊆ I ∪ B := by
  obtain ⟨B', hB', hIB'⟩ := hI.subset_basis_of_subset (subset_union_left I B)
  

Proof state:
case intro.intro
α : Type u_1
M : Matroid α
I B : Set α
hI : M.Indep I
hB : M.Base B
B' : Set α
hB' : M.Basis B' (I ∪ B)
hIB' : I ⊆ B'
⊢ ∃ B', M.Base B' ∧ I ⊆ B' ∧ B' ⊆ I ∪ B

Next tactic:
exact ⟨B', hB.base_of_basis_superset (subset_union_right _ _) hB', hIB', hB'.subset⟩
theorem Base.basis_of_subset (hX : X ⊆ M.E := by aesop_mat) (hB : M.Base B) (hBX : B ⊆ X) :
    M.Basis B X := by
  

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

Next tactic:
rw [basis_iff, and_iff_right hB.indep, and_iff_right hBX]