l3lab/ntp-mathlib huggingface dataset:
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)
  · exact ⟨x, ⟨hxB, hx⟩ , ⟨B', hB', insert_subset hxB' hIB'⟩⟩
  

Proof state:
case intro.intro.intro.intro.inr
α : 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:
obtain ⟨e,he, hBase⟩ := hB'.exchange hB ⟨hxB',hxB⟩
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)
  · exact ⟨x, ⟨hxB, hx⟩ , ⟨B', hB', insert_subset hxB' hIB'⟩⟩
  obtain ⟨e,he, hBase⟩ := hB'.exchange hB ⟨hxB',hxB⟩
  

Proof state:
case intro.intro.intro.intro.inr.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
hxB : x ∉ B
e : α
he : e ∈ B \ B'
hBase : M.Base (insert e (B' \ {x}))
⊢ ∃ e ∈ B \ I, M.Indep (insert e I)

Next tactic:
exact ⟨e, ⟨he.1, not_mem_subset hIB' he.2⟩,
    ⟨_, hBase, insert_subset_insert (subset_diff_singleton hIB' hx)⟩⟩
/-- This is the same as `Indep.exists_insert_of_not_base`, but phrased so that
  it is defeq to the augmentation axiom for independent sets. -/
theorem Indep.exists_insert_of_not_mem_maximals (M : Matroid α) ⦃I B : Set α⦄ (hI : M.Indep I)
    (hInotmax : I ∉ maximals (· ⊆ ·) {I | M.Indep I}) (hB : B ∈ maximals (· ⊆ ·) {I | M.Indep I}) :
    ∃ x ∈ B \ I, M.Indep (insert x I) := by
  

Proof state:
α : Type u_1
M✝ M : Matroid α
I B : Set α
hI : M.Indep I
hInotmax : I ∉ maximals (fun x x_1 => x ⊆ x_1) {I | M.Indep I}
hB : B ∈ maximals (fun x x_1 => x ⊆ x_1) {I | M.Indep I}
⊢ ∃ x ∈ B \ I, M.Indep (insert x I)

Next tactic:
simp only [mem_maximals_iff, mem_setOf_eq, not_and, not_forall, exists_prop,
    exists_and_left, iff_true_intro hI, true_imp_iff] at hB hInotmax
/-- This is the same as `Indep.exists_insert_of_not_base`, but phrased so that
  it is defeq to the augmentation axiom for independent sets. -/
theorem Indep.exists_insert_of_not_mem_maximals (M : Matroid α) ⦃I B : Set α⦄ (hI : M.Indep I)
    (hInotmax : I ∉ maximals (· ⊆ ·) {I | M.Indep I}) (hB : B ∈ maximals (· ⊆ ·) {I | M.Indep I}) :
    ∃ x ∈ B \ I, M.Indep (insert x I) := by
  simp only [mem_maximals_iff, mem_setOf_eq, not_and, not_forall, exists_prop,
    exists_and_left, iff_true_intro hI, true_imp_iff] at hB hInotmax
  

Proof state:
α : Type u_1
M✝ M : Matroid α
I B : Set α
hI : M.Indep I
hB : M.Indep B ∧ ∀ ⦃y : Set α⦄, M.Indep y → B ⊆ y → B = y
hInotmax : ∃ x, M.Indep x ∧ I ⊆ x ∧ ¬I = x
⊢ ∃ x ∈ B \ I, M.Indep (insert x I)

Next tactic:
refine hI.exists_insert_of_not_base (fun hIb ↦ ?_) ?_
/-- This is the same as `Indep.exists_insert_of_not_base`, but phrased so that
  it is defeq to the augmentation axiom for independent sets. -/
theorem Indep.exists_insert_of_not_mem_maximals (M : Matroid α) ⦃I B : Set α⦄ (hI : M.Indep I)
    (hInotmax : I ∉ maximals (· ⊆ ·) {I | M.Indep I}) (hB : B ∈ maximals (· ⊆ ·) {I | M.Indep I}) :
    ∃ x ∈ B \ I, M.Indep (insert x I) := by
  simp only [mem_maximals_iff, mem_setOf_eq, not_and, not_forall, exists_prop,
    exists_and_left, iff_true_intro hI, true_imp_iff] at hB hInotmax
  refine hI.exists_insert_of_not_base (fun hIb ↦ ?_) ?_
  · 

Proof state:
case refine_1
α : Type u_1
M✝ M : Matroid α
I B : Set α
hI : M.Indep I
hB : M.Indep B ∧ ∀ ⦃y : Set α⦄, M.Indep y → B ⊆ y → B = y
hInotmax : ∃ x, M.Indep x ∧ I ⊆ x ∧ ¬I = x
hIb : M.Base I
⊢ False

Next tactic:
obtain ⟨I', hII', hI', hne⟩ := hInotmax
/-- This is the same as `Indep.exists_insert_of_not_base`, but phrased so that
  it is defeq to the augmentation axiom for independent sets. -/
theorem Indep.exists_insert_of_not_mem_maximals (M : Matroid α) ⦃I B : Set α⦄ (hI : M.Indep I)
    (hInotmax : I ∉ maximals (· ⊆ ·) {I | M.Indep I}) (hB : B ∈ maximals (· ⊆ ·) {I | M.Indep I}) :
    ∃ x ∈ B \ I, M.Indep (insert x I) := by
  simp only [mem_maximals_iff, mem_setOf_eq, not_and, not_forall, exists_prop,
    exists_and_left, iff_true_intro hI, true_imp_iff] at hB hInotmax
  refine hI.exists_insert_of_not_base (fun hIb ↦ ?_) ?_
  · obtain ⟨I', hII', hI', hne⟩ := hInotmax
    

Proof state:
case refine_1.intro.intro.intro
α : Type u_1
M✝ M : Matroid α
I B : Set α
hI : M.Indep I
hB : M.Indep B ∧ ∀ ⦃y : Set α⦄, M.Indep y → B ⊆ y → B = y
hIb : M.Base I
I' : Set α
hII' : M.Indep I'
hI' : I ⊆ I'
hne : ¬I = I'
⊢ False

Next tactic:
exact hne <| hIb.eq_of_subset_indep hII' hI'
/-- This is the same as `Indep.exists_insert_of_not_base`, but phrased so that
  it is defeq to the augmentation axiom for independent sets. -/
theorem Indep.exists_insert_of_not_mem_maximals (M : Matroid α) ⦃I B : Set α⦄ (hI : M.Indep I)
    (hInotmax : I ∉ maximals (· ⊆ ·) {I | M.Indep I}) (hB : B ∈ maximals (· ⊆ ·) {I | M.Indep I}) :
    ∃ x ∈ B \ I, M.Indep (insert x I) := by
  simp only [mem_maximals_iff, mem_setOf_eq, not_and, not_forall, exists_prop,
    exists_and_left, iff_true_intro hI, true_imp_iff] at hB hInotmax
  refine hI.exists_insert_of_not_base (fun hIb ↦ ?_) ?_
  · obtain ⟨I', hII', hI', hne⟩ := hInotmax
    exact hne <| hIb.eq_of_subset_indep hII' hI'
  

Proof state:
case refine_2
α : Type u_1
M✝ M : Matroid α
I B : Set α
hI : M.Indep I
hB : M.Indep B ∧ ∀ ⦃y : Set α⦄, M.Indep y → B ⊆ y → B = y
hInotmax : ∃ x, M.Indep x ∧ I ⊆ x ∧ ¬I = x
⊢ M.Base B

Next tactic:
exact hB.1.base_of_maximal fun J hJ hBJ ↦ hB.2 hJ hBJ
theorem eq_of_indep_iff_indep_forall {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E)
    (h : ∀ I, I ⊆ M₁.E → (M₁.Indep I ↔ M₂.Indep I)) : M₁ = M₂ :=
  let h' : ∀ I, M₁.Indep I ↔ M₂.Indep I := fun I ↦
    (em (I ⊆ M₁.E)).elim (h I) (fun h' ↦ iff_of_false (fun hi ↦ h' (hi.subset_ground))
      (fun hi ↦ h' (hi.subset_ground.trans_eq hE.symm)))
  eq_of_base_iff_base_forall hE (fun B _ ↦ by 

Proof state:
α : Type u_1
M M₁ M₂ : Matroid α
hE : M₁.E = M₂.E
h : ∀ I ⊆ M₁.E, M₁.Indep I ↔ M₂.Indep I
h' : ∀ (I : Set α), M₁.Indep I ↔ M₂.Indep I :=
  fun I =>
    Or.elim (em (I ⊆ M₁.E)) (h I) fun h' =>
      iff_of_false (fun hi => h' (Indep.subset_ground hi)) fun hi =>
        h' (LE.le.trans_eq (Indep.subset_ground hi) hE.symm)
B : Set α
x✝ : B ⊆ M₁.E
⊢ M₁.Base B ↔ M₂.Base B

Next tactic:
simp_rw [base_iff_maximal_indep, h']
theorem eq_iff_indep_iff_indep_forall {M₁ M₂ : Matroid α} :
    M₁ = M₂ ↔ (M₁.E = M₂.E) ∧ ∀ I, I ⊆ M₁.E → (M₁.Indep I ↔ M₂.Indep I) :=
⟨fun h ↦ by (

Proof state:
α : Type u_1
M M₁ M₂ : Matroid α
h : M₁ = M₂
⊢ M₁.E = M₂.E ∧ ∀ I ⊆ M₁.E, M₁.Indep I ↔ M₂.Indep I

Next tactic:
subst h
theorem eq_iff_indep_iff_indep_forall {M₁ M₂ : Matroid α} :
    M₁ = M₂ ↔ (M₁.E = M₂.E) ∧ ∀ I, I ⊆ M₁.E → (M₁.Indep I ↔ M₂.Indep I) :=
⟨fun h ↦ by (subst h; 

Proof state:
α : Type u_1
M M₁ : Matroid α
⊢ M₁.E = M₁.E ∧ ∀ I ⊆ M₁.E, M₁.Indep I ↔ M₁.Indep I

Next tactic:
simp
instance finitary_of_finiteRk {M : Matroid α} [FiniteRk M] : Finitary M :=
⟨ by
  

Proof state:
α : Type ?u.39946
M✝ M : Matroid α
inst✝ : FiniteRk M
⊢ ∀ (I : Set α), (∀ J ⊆ I, Set.Finite J → M.Indep J) → M.Indep I

Next tactic:
refine fun I hI ↦ I.finite_or_infinite.elim (hI _ Subset.rfl) (fun h ↦ False.elim ?_)
instance finitary_of_finiteRk {M : Matroid α} [FiniteRk M] : Finitary M :=
⟨ by
  refine fun I hI ↦ I.finite_or_infinite.elim (hI _ Subset.rfl) (fun h ↦ False.elim ?_)
  

Proof state:
α : Type ?u.39946
M✝ M : Matroid α
inst✝ : FiniteRk M
I : Set α
hI : ∀ J ⊆ I, Set.Finite J → M.Indep J
h : Set.Infinite I
⊢ False

Next tactic:
obtain ⟨B, hB⟩ := M.exists_base
instance finitary_of_finiteRk {M : Matroid α} [FiniteRk M] : Finitary M :=
⟨ by
  refine fun I hI ↦ I.finite_or_infinite.elim (hI _ Subset.rfl) (fun h ↦ False.elim ?_)
  obtain ⟨B, hB⟩ := M.exists_base
  

Proof state:
case intro
α : Type ?u.39946
M✝ M : Matroid α
inst✝ : FiniteRk M
I : Set α
hI : ∀ J ⊆ I, Set.Finite J → M.Indep J
h : Set.Infinite I
B : Set α
hB : M.Base B
⊢ False

Next tactic:
obtain ⟨I₀, hI₀I, hI₀fin, hI₀card⟩ := h.exists_subset_ncard_eq (B.ncard + 1)
instance finitary_of_finiteRk {M : Matroid α} [FiniteRk M] : Finitary M :=
⟨ by
  refine fun I hI ↦ I.finite_or_infinite.elim (hI _ Subset.rfl) (fun h ↦ False.elim ?_)
  obtain ⟨B, hB⟩ := M.exists_base
  obtain ⟨I₀, hI₀I, hI₀fin, hI₀card⟩ := h.exists_subset_ncard_eq (B.ncard + 1)
  

Proof state:
case intro.intro.intro.intro
α : Type ?u.39946
M✝ M : Matroid α
inst✝ : FiniteRk M
I : Set α
hI : ∀ J ⊆ I, Set.Finite J → M.Indep J
h : Set.Infinite I
B : Set α
hB : M.Base B
I₀ : Set α
hI₀I : I₀ ⊆ I
hI₀fin : Set.Finite I₀
hI₀card : ncard I₀ = ncard B + 1
⊢ False

Next tactic:
obtain ⟨B', hB', hI₀B'⟩ := hI _ hI₀I hI₀fin
instance finitary_of_finiteRk {M : Matroid α} [FiniteRk M] : Finitary M :=
⟨ by
  refine fun I hI ↦ I.finite_or_infinite.elim (hI _ Subset.rfl) (fun h ↦ False.elim ?_)
  obtain ⟨B, hB⟩ := M.exists_base
  obtain ⟨I₀, hI₀I, hI₀fin, hI₀card⟩ := h.exists_subset_ncard_eq (B.ncard + 1)
  obtain ⟨B', hB', hI₀B'⟩ := hI _ hI₀I hI₀fin
  

Proof state:
case intro.intro.intro.intro.intro.intro
α : Type ?u.39946
M✝ M : Matroid α
inst✝ : FiniteRk M
I : Set α
hI : ∀ J ⊆ I, Set.Finite J → M.Indep J
h : Set.Infinite I
B : Set α
hB : M.Base B
I₀ : Set α
hI₀I : I₀ ⊆ I
hI₀fin : Set.Finite I₀
hI₀card : ncard I₀ = ncard B + 1
B' : Set α
hB' : M.Base B'
hI₀B' : I₀ ⊆ B'
⊢ False

Next tactic:
have hle := ncard_le_of_subset hI₀B' hB'.finite
instance finitary_of_finiteRk {M : Matroid α} [FiniteRk M] : Finitary M :=
⟨ by
  refine fun I hI ↦ I.finite_or_infinite.elim (hI _ Subset.rfl) (fun h ↦ False.elim ?_)
  obtain ⟨B, hB⟩ := M.exists_base
  obtain ⟨I₀, hI₀I, hI₀fin, hI₀card⟩ := h.exists_subset_ncard_eq (B.ncard + 1)
  obtain ⟨B', hB', hI₀B'⟩ := hI _ hI₀I hI₀fin
  have hle := ncard_le_of_subset hI₀B' hB'.finite
  

Proof state:
case intro.intro.intro.intro.intro.intro
α : Type ?u.39946
M✝ M : Matroid α
inst✝ : FiniteRk M
I : Set α
hI : ∀ J ⊆ I, Set.Finite J → M.Indep J
h : Set.Infinite I
B : Set α
hB : M.Base B
I₀ : Set α
hI₀I : I₀ ⊆ I
hI₀fin : Set.Finite I₀
hI₀card : ncard I₀ = ncard B + 1
B' : Set α
hB' : M.Base B'
hI₀B' : I₀ ⊆ B'
hle : ncard I₀ ≤ ncard B'
⊢ False

Next tactic:
rw [hI₀card, hB'.ncard_eq_ncard_of_base hB, Nat.add_one_le_iff] at hle
instance finitary_of_finiteRk {M : Matroid α} [FiniteRk M] : Finitary M :=
⟨ by
  refine fun I hI ↦ I.finite_or_infinite.elim (hI _ Subset.rfl) (fun h ↦ False.elim ?_)
  obtain ⟨B, hB⟩ := M.exists_base
  obtain ⟨I₀, hI₀I, hI₀fin, hI₀card⟩ := h.exists_subset_ncard_eq (B.ncard + 1)
  obtain ⟨B', hB', hI₀B'⟩ := hI _ hI₀I hI₀fin
  have hle := ncard_le_of_subset hI₀B' hB'.finite
  rw [hI₀card, hB'.ncard_eq_ncard_of_base hB, Nat.add_one_le_iff] at hle
  

Proof state:
case intro.intro.intro.intro.intro.intro
α : Type ?u.39946
M✝ M : Matroid α
inst✝ : FiniteRk M
I : Set α
hI : ∀ J ⊆ I, Set.Finite J → M.Indep J
h : Set.Infinite I
B : Set α
hB : M.Base B
I₀ : Set α
hI₀I : I₀ ⊆ I
hI₀fin : Set.Finite I₀
hI₀card : ncard I₀ = ncard B + 1
B' : Set α
hB' : M.Base B'
hI₀B' : I₀ ⊆ B'
hle : ncard B < ncard B
⊢ False

Next tactic:
exact hle.ne rfl
theorem setOf_basis_eq (M : Matroid α) (hX : X ⊆ M.E := by aesop_mat) :
    {I | M.Basis I X} = maximals (· ⊆ ·) ({I | M.Indep I} ∩ Iic X) := by
  

Proof state:
α : Type u_1
M✝ : Matroid α
X : Set α
M : Matroid α
hX : autoParam (X ⊆ M.E) _auto✝
⊢ {I | M.Basis I X} = maximals (fun x x_1 => x ⊆ x_1) ({I | M.Indep I} ∩ Iic X)

Next tactic:
ext I
theorem setOf_basis_eq (M : Matroid α) (hX : X ⊆ M.E := by aesop_mat) :
    {I | M.Basis I X} = maximals (· ⊆ ·) ({I | M.Indep I} ∩ Iic X) := by
  ext I; 

Proof state:
case h
α : Type u_1
M✝ : Matroid α
X : Set α
M : Matroid α
hX : autoParam (X ⊆ M.E) _auto✝
I : Set α
⊢ I ∈ {I | M.Basis I X} ↔ I ∈ maximals (fun x x_1 => x ⊆ x_1) ({I | M.Indep I} ∩ Iic X)

Next tactic:
simp [Matroid.Basis, maximals, iff_true_intro hX]
theorem Basis.basis_inter_ground (hI : M.Basis I X) : M.Basis I (X ∩ M.E) := by
  

Proof state:
α : Type u_1
M : Matroid α
I X : Set α
hI : M.Basis I X
⊢ M.Basis I (X ∩ M.E)

Next tactic:
convert hI
theorem Basis.basis_inter_ground (hI : M.Basis I X) : M.Basis I (X ∩ M.E) := by
  convert hI
  

Proof state:
case h.e'_4
α : Type u_1
M : Matroid α
I X : Set α
hI : M.Basis I X
⊢ X ∩ M.E = X

Next tactic:
rw [inter_eq_self_of_subset_left hI.subset_ground]
theorem basis_iff' :
    M.Basis I X ↔ (M.Indep I ∧ I ⊆ X ∧ ∀ J, M.Indep J → I ⊆ J → J ⊆ X → I = J) ∧ X ⊆ M.E := by
  

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

Next tactic:
simp [Basis, mem_maximals_setOf_iff, and_assoc, and_congr_left_iff, and_imp,
    and_congr_left_iff, and_congr_right_iff, @Imp.swap (_ ⊆ X)]
theorem basis_iff (hX : X ⊆ M.E := by aesop_mat) :
    M.Basis I X ↔ (M.Indep I ∧ I ⊆ X ∧ ∀ J, M.Indep J → I ⊆ J → J ⊆ X → I = J) :=
by 

Proof state:
α : Type u_1
M : Matroid α
X I : Set α
hX : autoParam (X ⊆ M.E) _auto✝
⊢ M.Basis I X ↔ M.Indep I ∧ I ⊆ X ∧ ∀ (J : Set α), M.Indep J → I ⊆ J → J ⊆ X → I = J

Next tactic:
rw [basis_iff', and_iff_left hX]
theorem basis'_iff_basis_inter_ground : M.Basis' I X ↔ M.Basis I (X ∩ M.E) := by
  

Proof state:
α : Type u_1
M : Matroid α
I X : Set α
⊢ M.Basis' I X ↔ M.Basis I (X ∩ M.E)

Next tactic:
rw [Basis', Basis, and_iff_left (inter_subset_right _ _)]
theorem basis'_iff_basis_inter_ground : M.Basis' I X ↔ M.Basis I (X ∩ M.E) := by
  rw [Basis', Basis, and_iff_left (inter_subset_right _ _)]
  

Proof state:
α : Type u_1
M : Matroid α
I X : Set α
⊢ I ∈ maximals (fun x x_1 => x ⊆ x_1) {A | M.Indep A ∧ A ⊆ X} ↔
    I ∈ maximals (fun x x_1 => x ⊆ x_1) {A | M.Indep A ∧ A ⊆ X ∩ M.E}

Next tactic:
convert Iff.rfl using 3
theorem basis'_iff_basis_inter_ground : M.Basis' I X ↔ M.Basis I (X ∩ M.E) := by
  rw [Basis', Basis, and_iff_left (inter_subset_right _ _)]
  convert Iff.rfl using 3
  

Proof state:
case h.e'_2.h.e'_5.h.e'_3
α : Type u_1
M : Matroid α
I X : Set α
⊢ {A | M.Indep A ∧ A ⊆ X ∩ M.E} = {A | M.Indep A ∧ A ⊆ X}

Next tactic:
ext I
theorem basis'_iff_basis_inter_ground : M.Basis' I X ↔ M.Basis I (X ∩ M.E) := by
  rw [Basis', Basis, and_iff_left (inter_subset_right _ _)]
  convert Iff.rfl using 3
  ext I
  

Proof state:
case h.e'_2.h.e'_5.h.e'_3.h
α : Type u_1
M : Matroid α
I✝ X I : Set α
⊢ I ∈ {A | M.Indep A ∧ A ⊆ X ∩ M.E} ↔ I ∈ {A | M.Indep A ∧ A ⊆ X}

Next tactic:
simp only [subset_inter_iff, mem_setOf_eq, and_congr_right_iff, and_iff_left_iff_imp]
theorem basis'_iff_basis_inter_ground : M.Basis' I X ↔ M.Basis I (X ∩ M.E) := by
  rw [Basis', Basis, and_iff_left (inter_subset_right _ _)]
  convert Iff.rfl using 3
  ext I
  simp only [subset_inter_iff, mem_setOf_eq, and_congr_right_iff, and_iff_left_iff_imp]
  

Proof state:
case h.e'_2.h.e'_5.h.e'_3.h
α : Type u_1
M : Matroid α
I✝ X I : Set α
⊢ M.Indep I → I ⊆ X → I ⊆ M.E

Next tactic:
exact fun h _ ↦ h.subset_ground
theorem basis'_iff_basis (hX : X ⊆ M.E := by aesop_mat) : M.Basis' I X ↔ M.Basis I X := by
  

Proof state:
α : Type u_1
M : Matroid α
X I : Set α
hX : autoParam (X ⊆ M.E) _auto✝
⊢ M.Basis' I X ↔ M.Basis I X

Next tactic:
rw [basis'_iff_basis_inter_ground, inter_eq_self_of_subset_left hX]
theorem basis_iff_mem_maximals (hX : X ⊆ M.E := by aesop_mat):
    M.Basis I X ↔ I ∈ maximals (· ⊆ ·) {I | M.Indep I ∧ I ⊆ X} := by
  

Proof state:
α : Type u_1
M : Matroid α
X I : Set α
hX : autoParam (X ⊆ M.E) _auto✝
⊢ M.Basis I X ↔ I ∈ maximals (fun x x_1 => x ⊆ x_1) {I | M.Indep I ∧ I ⊆ X}

Next tactic:
rw [Basis, and_iff_left hX]
theorem Indep.basis_of_maximal_subset (hI : M.Indep I) (hIX : I ⊆ X)
    (hmax : ∀ ⦃J⦄, M.Indep J → I ⊆ J → J ⊆ X → J ⊆ I) (hX : X ⊆ M.E := by aesop_mat) :
    M.Basis I X := by
  

Proof state:
α : Type u_1
M : Matroid α
I X : Set α
hI : M.Indep I
hIX : I ⊆ X
hmax : ∀ ⦃J : Set α⦄, M.Indep J → I ⊆ J → J ⊆ X → J ⊆ I
hX : autoParam (X ⊆ M.E) _auto✝
⊢ M.Basis I X

Next tactic:
rw [basis_iff (by aesop_mat : X ⊆ M.E), and_iff_right hI, and_iff_right hIX]
theorem Indep.basis_of_maximal_subset (hI : M.Indep I) (hIX : I ⊆ X)
    (hmax : ∀ ⦃J⦄, M.Indep J → I ⊆ J → J ⊆ X → J ⊆ I) (hX : X ⊆ M.E := by aesop_mat) :
    M.Basis I X := by
  rw [basis_iff (by 

Proof state:
α : Type u_1
M : Matroid α
I X : Set α
hI : M.Indep I
hIX : I ⊆ X
hmax : ∀ ⦃J : Set α⦄, M.Indep J → I ⊆ J → J ⊆ X → J ⊆ I
hX : autoParam (X ⊆ M.E) _auto✝
⊢ X ⊆ M.E

Next tactic:
aesop_mat
theorem Indep.basis_of_maximal_subset (hI : M.Indep I) (hIX : I ⊆ X)
    (hmax : ∀ ⦃J⦄, M.Indep J → I ⊆ J → J ⊆ X → J ⊆ I) (hX : X ⊆ M.E := by aesop_mat) :
    M.Basis I X := by
  rw [basis_iff (by aesop_mat : X ⊆ M.E), and_iff_right hI, and_iff_right hIX]
  

Proof state:
α : Type u_1
M : Matroid α
I X : Set α
hI : M.Indep I
hIX : I ⊆ X
hmax : ∀ ⦃J : Set α⦄, M.Indep J → I ⊆ J → J ⊆ X → J ⊆ I
hX : autoParam (X ⊆ M.E) _auto✝
⊢ ∀ (J : Set α), M.Indep J → I ⊆ J → J ⊆ X → I = J

Next tactic:
exact fun J hJ hIJ hJX ↦ hIJ.antisymm (hmax hJ hIJ hJX)
theorem Basis.basis_subset (hI : M.Basis I X) (hIY : I ⊆ Y) (hYX : Y ⊆ X) : M.Basis I Y := by
  

Proof state:
α : Type u_1
M : Matroid α
I X Y : Set α
hI : M.Basis I X
hIY : I ⊆ Y
hYX : Y ⊆ X
⊢ M.Basis I Y

Next tactic:
rw [basis_iff (hYX.trans hI.subset_ground), and_iff_right hI.indep, and_iff_right hIY]
theorem Basis.basis_subset (hI : M.Basis I X) (hIY : I ⊆ Y) (hYX : Y ⊆ X) : M.Basis I Y := by
  rw [basis_iff (hYX.trans hI.subset_ground), and_iff_right hI.indep, and_iff_right hIY]
  

Proof state:
α : Type u_1
M : Matroid α
I X Y : Set α
hI : M.Basis I X
hIY : I ⊆ Y
hYX : Y ⊆ X
⊢ ∀ (J : Set α), M.Indep J → I ⊆ J → J ⊆ Y → I = J

Next tactic:
exact fun J hJ hIJ hJY ↦ hI.eq_of_subset_indep hJ hIJ (hJY.trans hYX)
@[simp] theorem basis_self_iff_indep : M.Basis I I ↔ M.Indep I := by
  

Proof state:
α : Type u_1
M : Matroid α
I : Set α
⊢ M.Basis I I ↔ M.Indep I

Next tactic:
rw [basis_iff', and_iff_right rfl.subset, and_assoc, and_iff_left_iff_imp]
@[simp] theorem basis_self_iff_indep : M.Basis I I ↔ M.Indep I := by
  rw [basis_iff', and_iff_right rfl.subset, and_assoc, and_iff_left_iff_imp]
  

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

Next tactic:
exact fun hi ↦ ⟨fun _ _ ↦ subset_antisymm, hi.subset_ground⟩
@[simp] theorem basis_empty_iff (M : Matroid α) : M.Basis I ∅ ↔ I = ∅ :=
  ⟨fun h ↦ subset_empty_iff.mp h.subset, fun h ↦ by (

Proof state:
α : Type u_1
M✝ : Matroid α
I : Set α
M : Matroid α
h : I = ∅
⊢ M.Basis I ∅

Next tactic:
rw [h]
@[simp] theorem basis_empty_iff (M : Matroid α) : M.Basis I ∅ ↔ I = ∅ :=
  ⟨fun h ↦ subset_empty_iff.mp h.subset, fun h ↦ by (rw [h]; 

Proof state:
α : Type u_1
M✝ : Matroid α
I : Set α
M : Matroid α
h : I = ∅
⊢ M.Basis ∅ ∅

Next tactic:
exact M.empty_indep.basis_self
theorem Basis.dep_of_ssubset (hI : M.Basis I X) (hIY : I ⊂ Y) (hYX : Y ⊆ X) : M.Dep Y := by
  

Proof state:
α : Type u_1
M : Matroid α
I X Y : Set α
hI : M.Basis I X
hIY : I ⊂ Y
hYX : Y ⊆ X
⊢ M.Dep Y

Next tactic:
have : X ⊆ M.E := hI.subset_ground
theorem Basis.dep_of_ssubset (hI : M.Basis I X) (hIY : I ⊂ Y) (hYX : Y ⊆ X) : M.Dep Y := by
  have : X ⊆ M.E := hI.subset_ground
  

Proof state:
α : Type u_1
M : Matroid α
I X Y : Set α
hI : M.Basis I X
hIY : I ⊂ Y
hYX : Y ⊆ X
this : X ⊆ M.E
⊢ M.Dep Y

Next tactic:
rw [← not_indep_iff]
theorem Basis.dep_of_ssubset (hI : M.Basis I X) (hIY : I ⊂ Y) (hYX : Y ⊆ X) : M.Dep Y := by
  have : X ⊆ M.E := hI.subset_ground
  rw [← not_indep_iff]
  

Proof state:
α : Type u_1
M : Matroid α
I X Y : Set α
hI : M.Basis I X
hIY : I ⊂ Y
hYX : Y ⊆ X
this : X ⊆ M.E
⊢ ¬M.Indep Y

Next tactic:
exact fun hY ↦ hIY.ne (hI.eq_of_subset_indep hY hIY.subset hYX)
theorem Indep.subset_basis_of_subset (hI : M.Indep I) (hIX : I ⊆ X) (hX : X ⊆ M.E := by aesop_mat) :
    ∃ J, M.Basis J X ∧ I ⊆ J := by
  

Proof state:
α : Type u_1
M : Matroid α
I X : Set α
hI : M.Indep I
hIX : I ⊆ X
hX : autoParam (X ⊆ M.E) _auto✝
⊢ ∃ J, M.Basis J X ∧ I ⊆ J

Next tactic:
obtain ⟨J, ⟨(hJ : M.Indep J),hIJ,hJX⟩, hJmax⟩ := M.maximality X hX I hI hIX
theorem Indep.subset_basis_of_subset (hI : M.Indep I) (hIX : I ⊆ X) (hX : X ⊆ M.E := by aesop_mat) :
    ∃ J, M.Basis J X ∧ I ⊆ J := by
  obtain ⟨J, ⟨(hJ : M.Indep J),hIJ,hJX⟩, hJmax⟩ := M.maximality X hX I hI hIX
  

Proof state:
case intro.intro.intro.intro
α : Type u_1
M : Matroid α
I X : Set α
hI : M.Indep I
hIX : I ⊆ X
hX : autoParam (X ⊆ M.E) _auto✝
J : Set α
hJmax :
  ∀ ⦃b : Set α⦄,
    b ∈ {Y | (fun x => ∃ B, M.Base B ∧ x ⊆ B) Y ∧ I ⊆ Y ∧ Y ⊆ X} →
      (fun x x_1 => x ⊆ x_1) J b → (fun x x_1 => x ⊆ x_1) b J
hJ : M.Indep J
hIJ : I ⊆ J
hJX : J ⊆ X
⊢ ∃ J, M.Basis J X ∧ I ⊆ J

Next tactic:
use J
theorem Indep.subset_basis_of_subset (hI : M.Indep I) (hIX : I ⊆ X) (hX : X ⊆ M.E := by aesop_mat) :
    ∃ J, M.Basis J X ∧ I ⊆ J := by
  obtain ⟨J, ⟨(hJ : M.Indep J),hIJ,hJX⟩, hJmax⟩ := M.maximality X hX I hI hIX
  use J
  

Proof state:
case h
α : Type u_1
M : Matroid α
I X : Set α
hI : M.Indep I
hIX : I ⊆ X
hX : autoParam (X ⊆ M.E) _auto✝
J : Set α
hJmax :
  ∀ ⦃b : Set α⦄,
    b ∈ {Y | (fun x => ∃ B, M.Base B ∧ x ⊆ B) Y ∧ I ⊆ Y ∧ Y ⊆ X} →
      (fun x x_1 => x ⊆ x_1) J b → (fun x x_1 => x ⊆ x_1) b J
hJ : M.Indep J
hIJ : I ⊆ J
hJX : J ⊆ X
⊢ M.Basis J X ∧ I ⊆ J

Next tactic:
rw [and_iff_left hIJ, basis_iff, and_iff_right hJ, and_iff_right hJX]
theorem Indep.subset_basis_of_subset (hI : M.Indep I) (hIX : I ⊆ X) (hX : X ⊆ M.E := by aesop_mat) :
    ∃ J, M.Basis J X ∧ I ⊆ J := by
  obtain ⟨J, ⟨(hJ : M.Indep J),hIJ,hJX⟩, hJmax⟩ := M.maximality X hX I hI hIX
  use J
  rw [and_iff_left hIJ, basis_iff, and_iff_right hJ, and_iff_right hJX]
  

Proof state:
case h
α : Type u_1
M : Matroid α
I X : Set α
hI : M.Indep I
hIX : I ⊆ X
hX : autoParam (X ⊆ M.E) _auto✝
J : Set α
hJmax :
  ∀ ⦃b : Set α⦄,
    b ∈ {Y | (fun x => ∃ B, M.Base B ∧ x ⊆ B) Y ∧ I ⊆ Y ∧ Y ⊆ X} →
      (fun x x_1 => x ⊆ x_1) J b → (fun x x_1 => x ⊆ x_1) b J
hJ : M.Indep J
hIJ : I ⊆ J
hJX : J ⊆ X
⊢ ∀ (J_1 : Set α), M.Indep J_1 → J ⊆ J_1 → J_1 ⊆ X → J = J_1

Next tactic:
exact fun K hK hJK hKX ↦ hJK.antisymm (hJmax ⟨hK, hIJ.trans hJK, hKX⟩ hJK)
theorem Indep.subset_basis'_of_subset (hI : M.Indep I) (hIX : I ⊆ X) :
    ∃ J, M.Basis' J X ∧ I ⊆ J := by
  

Proof state:
α : Type u_1
M : Matroid α
I X : Set α
hI : M.Indep I
hIX : I ⊆ X
⊢ ∃ J, M.Basis' J X ∧ I ⊆ J

Next tactic:
simp_rw [basis'_iff_basis_inter_ground]
theorem Indep.subset_basis'_of_subset (hI : M.Indep I) (hIX : I ⊆ X) :
    ∃ J, M.Basis' J X ∧ I ⊆ J := by
  simp_rw [basis'_iff_basis_inter_ground]
  

Proof state:
α : Type u_1
M : Matroid α
I X : Set α
hI : M.Indep I
hIX : I ⊆ X
⊢ ∃ J, M.Basis J (X ∩ M.E) ∧ I ⊆ J

Next tactic:
exact hI.subset_basis_of_subset (subset_inter hIX hI.subset_ground)
theorem exists_basis_subset_basis (M : Matroid α) (hXY : X ⊆ Y) (hY : Y ⊆ M.E := by aesop_mat) :
    ∃ I J, M.Basis I X ∧ M.Basis J Y ∧ I ⊆ J := by
  

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

Next tactic:
obtain ⟨I, hI⟩ := M.exists_basis X (hXY.trans hY)
theorem exists_basis_subset_basis (M : Matroid α) (hXY : X ⊆ Y) (hY : Y ⊆ M.E := by aesop_mat) :
    ∃ I J, M.Basis I X ∧ M.Basis J Y ∧ I ⊆ J := by
  obtain ⟨I, hI⟩ := M.exists_basis X (hXY.trans hY)
  

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

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

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

Next tactic:
exact ⟨_, _, hI, hJ, hIJ⟩