l3lab/ntp-mathlib huggingface dataset:
/-- An `M : IndepMatroid α` gives a `Matroid α` whose bases are the maximal `M`-independent sets. -/
@[simps] protected def matroid (M : IndepMatroid α) : Matroid α where
  E := M.E
  Base := (· ∈ maximals (· ⊆ ·) {I | M.Indep I})
  exists_base := by
    obtain ⟨B, ⟨hB,-,-⟩, hB₁⟩ :=
      M.indep_maximal M.E rfl.subset ∅ M.indep_empty (empty_subset _)
    exact ⟨B, ⟨hB, fun B' hB' h' ↦ hB₁ ⟨hB', empty_subset _,M.subset_ground B' hB'⟩ h'⟩⟩
  base_exchange := by
    rintro B B' ⟨hB, hBmax⟩ ⟨hB',hB'max⟩ e he
    have hnotmax : B \ {e} ∉ maximals (· ⊆ ·) {I | M.Indep I}
    { simp only [mem_maximals_setOf_iff, diff_singleton_subset_iff, not_and, not_forall,
        exists_prop, exists_and_left]
      exact fun _ ↦ ⟨B, hB, subset_insert _ _, by simpa using he.1⟩ }

    obtain ⟨f,hf,hfB⟩ := M.indep_aug (M.indep_subset hB (diff_subset B {e})) hnotmax ⟨hB',hB'max⟩
    simp only [mem_diff, mem_singleton_iff, not_and, not_not] at hf

    have hfB' : f ∉ B := by (intro hfB; obtain rfl := hf.2 hfB; exact he.2 hf.1)

    refine' ⟨f, ⟨hf.1, hfB'⟩, by_contra (fun hnot ↦ _)⟩
    obtain ⟨x,hxB, hind⟩ :=  M.indep_aug hfB hnot ⟨hB, hBmax⟩
    simp only [mem_diff, mem_insert_iff, mem_singleton_iff, not_or, not_and, not_not] at hxB
    obtain rfl := hxB.2.2 hxB.1
    rw [insert_comm, insert_diff_singleton, insert_eq_of_mem he.1] at hind
    exact not_mem_subset (hBmax hind (subset_insert _ _)) hfB' (mem_insert _ _)
  maximality := by
    rintro X hXE I ⟨hB, hB, hIB⟩ hIX
    obtain ⟨J, ⟨hJ, hIJ, hJX⟩, hJmax⟩ := M.indep_maximal X hXE I (M.indep_subset hB.1 hIB) hIX
    obtain ⟨BJ, hBJ⟩ := M.indep_maximal M.E rfl.subset J hJ (M.subset_ground J hJ)
    refine' ⟨J, ⟨⟨BJ,_, hBJ.1.2.1⟩ ,hIJ,hJX⟩, _⟩
    · exact ⟨hBJ.1.1, fun B' hB' hBJB' ↦ hBJ.2 ⟨hB',hBJ.1.2.1.trans hBJB',
        M.subset_ground _ hB'⟩ hBJB'⟩
    simp only [maximals, mem_setOf_eq, and_imp, forall_exists_index]
    

Proof state:
case intro.intro.intro.intro.intro.intro.intro.refine'_2
α : Type u_1
I✝ B X✝ : Set α
M : IndepMatroid α
X : Set α
hXE : X ⊆ M.E
I hB✝ : Set α
hB : hB✝ ∈ maximals (fun x x_1 => x ⊆ x_1) {I | M.Indep I}
hIB : I ⊆ hB✝
hIX : I ⊆ X
J : Set α
hJmax : ∀ ⦃b : Set α⦄, b ∈ {Y | M.Indep 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
BJ : Set α
hBJ : BJ ∈ maximals (fun x x_1 => x ⊆ x_1) {Y | M.Indep Y ∧ J ⊆ Y ∧ Y ⊆ M.E}
⊢ ∀ ⦃b : Set α⦄ (x : Set α),
    M.Indep x → (∀ ⦃b : Set α⦄, M.Indep b → x ⊆ b → b ⊆ x) → b ⊆ x → I ⊆ b → b ⊆ X → J ⊆ b → b ⊆ J

Next tactic:
rintro A B' (hBi' : M.Indep _) - hB'' hIA hAX hJA
/-- An `M : IndepMatroid α` gives a `Matroid α` whose bases are the maximal `M`-independent sets. -/
@[simps] protected def matroid (M : IndepMatroid α) : Matroid α where
  E := M.E
  Base := (· ∈ maximals (· ⊆ ·) {I | M.Indep I})
  exists_base := by
    obtain ⟨B, ⟨hB,-,-⟩, hB₁⟩ :=
      M.indep_maximal M.E rfl.subset ∅ M.indep_empty (empty_subset _)
    exact ⟨B, ⟨hB, fun B' hB' h' ↦ hB₁ ⟨hB', empty_subset _,M.subset_ground B' hB'⟩ h'⟩⟩
  base_exchange := by
    rintro B B' ⟨hB, hBmax⟩ ⟨hB',hB'max⟩ e he
    have hnotmax : B \ {e} ∉ maximals (· ⊆ ·) {I | M.Indep I}
    { simp only [mem_maximals_setOf_iff, diff_singleton_subset_iff, not_and, not_forall,
        exists_prop, exists_and_left]
      exact fun _ ↦ ⟨B, hB, subset_insert _ _, by simpa using he.1⟩ }

    obtain ⟨f,hf,hfB⟩ := M.indep_aug (M.indep_subset hB (diff_subset B {e})) hnotmax ⟨hB',hB'max⟩
    simp only [mem_diff, mem_singleton_iff, not_and, not_not] at hf

    have hfB' : f ∉ B := by (intro hfB; obtain rfl := hf.2 hfB; exact he.2 hf.1)

    refine' ⟨f, ⟨hf.1, hfB'⟩, by_contra (fun hnot ↦ _)⟩
    obtain ⟨x,hxB, hind⟩ :=  M.indep_aug hfB hnot ⟨hB, hBmax⟩
    simp only [mem_diff, mem_insert_iff, mem_singleton_iff, not_or, not_and, not_not] at hxB
    obtain rfl := hxB.2.2 hxB.1
    rw [insert_comm, insert_diff_singleton, insert_eq_of_mem he.1] at hind
    exact not_mem_subset (hBmax hind (subset_insert _ _)) hfB' (mem_insert _ _)
  maximality := by
    rintro X hXE I ⟨hB, hB, hIB⟩ hIX
    obtain ⟨J, ⟨hJ, hIJ, hJX⟩, hJmax⟩ := M.indep_maximal X hXE I (M.indep_subset hB.1 hIB) hIX
    obtain ⟨BJ, hBJ⟩ := M.indep_maximal M.E rfl.subset J hJ (M.subset_ground J hJ)
    refine' ⟨J, ⟨⟨BJ,_, hBJ.1.2.1⟩ ,hIJ,hJX⟩, _⟩
    · exact ⟨hBJ.1.1, fun B' hB' hBJB' ↦ hBJ.2 ⟨hB',hBJ.1.2.1.trans hBJB',
        M.subset_ground _ hB'⟩ hBJB'⟩
    simp only [maximals, mem_setOf_eq, and_imp, forall_exists_index]
    rintro A B' (hBi' : M.Indep _) - hB'' hIA hAX hJA
    

Proof state:
case intro.intro.intro.intro.intro.intro.intro.refine'_2
α : Type u_1
I✝ B X✝ : Set α
M : IndepMatroid α
X : Set α
hXE : X ⊆ M.E
I hB✝ : Set α
hB : hB✝ ∈ maximals (fun x x_1 => x ⊆ x_1) {I | M.Indep I}
hIB : I ⊆ hB✝
hIX : I ⊆ X
J : Set α
hJmax : ∀ ⦃b : Set α⦄, b ∈ {Y | M.Indep 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
BJ : Set α
hBJ : BJ ∈ maximals (fun x x_1 => x ⊆ x_1) {Y | M.Indep Y ∧ J ⊆ Y ∧ Y ⊆ M.E}
A B' : Set α
hBi' : M.Indep B'
hB'' : A ⊆ B'
hIA : I ⊆ A
hAX : A ⊆ X
hJA : J ⊆ A
⊢ A ⊆ J

Next tactic:
simp only [mem_setOf_eq, and_imp] at hJmax
/-- An `M : IndepMatroid α` gives a `Matroid α` whose bases are the maximal `M`-independent sets. -/
@[simps] protected def matroid (M : IndepMatroid α) : Matroid α where
  E := M.E
  Base := (· ∈ maximals (· ⊆ ·) {I | M.Indep I})
  exists_base := by
    obtain ⟨B, ⟨hB,-,-⟩, hB₁⟩ :=
      M.indep_maximal M.E rfl.subset ∅ M.indep_empty (empty_subset _)
    exact ⟨B, ⟨hB, fun B' hB' h' ↦ hB₁ ⟨hB', empty_subset _,M.subset_ground B' hB'⟩ h'⟩⟩
  base_exchange := by
    rintro B B' ⟨hB, hBmax⟩ ⟨hB',hB'max⟩ e he
    have hnotmax : B \ {e} ∉ maximals (· ⊆ ·) {I | M.Indep I}
    { simp only [mem_maximals_setOf_iff, diff_singleton_subset_iff, not_and, not_forall,
        exists_prop, exists_and_left]
      exact fun _ ↦ ⟨B, hB, subset_insert _ _, by simpa using he.1⟩ }

    obtain ⟨f,hf,hfB⟩ := M.indep_aug (M.indep_subset hB (diff_subset B {e})) hnotmax ⟨hB',hB'max⟩
    simp only [mem_diff, mem_singleton_iff, not_and, not_not] at hf

    have hfB' : f ∉ B := by (intro hfB; obtain rfl := hf.2 hfB; exact he.2 hf.1)

    refine' ⟨f, ⟨hf.1, hfB'⟩, by_contra (fun hnot ↦ _)⟩
    obtain ⟨x,hxB, hind⟩ :=  M.indep_aug hfB hnot ⟨hB, hBmax⟩
    simp only [mem_diff, mem_insert_iff, mem_singleton_iff, not_or, not_and, not_not] at hxB
    obtain rfl := hxB.2.2 hxB.1
    rw [insert_comm, insert_diff_singleton, insert_eq_of_mem he.1] at hind
    exact not_mem_subset (hBmax hind (subset_insert _ _)) hfB' (mem_insert _ _)
  maximality := by
    rintro X hXE I ⟨hB, hB, hIB⟩ hIX
    obtain ⟨J, ⟨hJ, hIJ, hJX⟩, hJmax⟩ := M.indep_maximal X hXE I (M.indep_subset hB.1 hIB) hIX
    obtain ⟨BJ, hBJ⟩ := M.indep_maximal M.E rfl.subset J hJ (M.subset_ground J hJ)
    refine' ⟨J, ⟨⟨BJ,_, hBJ.1.2.1⟩ ,hIJ,hJX⟩, _⟩
    · exact ⟨hBJ.1.1, fun B' hB' hBJB' ↦ hBJ.2 ⟨hB',hBJ.1.2.1.trans hBJB',
        M.subset_ground _ hB'⟩ hBJB'⟩
    simp only [maximals, mem_setOf_eq, and_imp, forall_exists_index]
    rintro A B' (hBi' : M.Indep _) - hB'' hIA hAX hJA
    simp only [mem_setOf_eq, and_imp] at hJmax
    

Proof state:
case intro.intro.intro.intro.intro.intro.intro.refine'_2
α : Type u_1
I✝ B X✝ : Set α
M : IndepMatroid α
X : Set α
hXE : X ⊆ M.E
I hB✝ : Set α
hB : hB✝ ∈ maximals (fun x x_1 => x ⊆ x_1) {I | M.Indep I}
hIB : I ⊆ hB✝
hIX : I ⊆ X
J : Set α
hJ : M.Indep J
hIJ : I ⊆ J
hJX : J ⊆ X
BJ : Set α
hBJ : BJ ∈ maximals (fun x x_1 => x ⊆ x_1) {Y | M.Indep Y ∧ J ⊆ Y ∧ Y ⊆ M.E}
A B' : Set α
hBi' : M.Indep B'
hB'' : A ⊆ B'
hIA : I ⊆ A
hAX : A ⊆ X
hJA : J ⊆ A
hJmax : ∀ ⦃b : Set α⦄, M.Indep b → I ⊆ b → b ⊆ X → J ⊆ b → b ⊆ J
⊢ A ⊆ J

Next tactic:
exact hJmax (M.indep_subset hBi' hB'') hIA hAX hJA
@[simp] theorem matroid_indep_iff {M : IndepMatroid α} {I : Set α} :
    M.matroid.Indep I ↔ M.Indep I := by
  

Proof state:
α : Type u_1
I✝ B X : Set α
M : IndepMatroid α
I : Set α
⊢ (IndepMatroid.matroid M).Indep I ↔ M.Indep I

Next tactic:
simp only [IndepMatroid.matroid, indep_iff_subset_base]
@[simp] theorem matroid_indep_iff {M : IndepMatroid α} {I : Set α} :
    M.matroid.Indep I ↔ M.Indep I := by
  simp only [IndepMatroid.matroid, indep_iff_subset_base]
  

Proof state:
α : Type u_1
I✝ B X : Set α
M : IndepMatroid α
I : Set α
⊢ (∃ B ∈ maximals (fun x x_1 => x ⊆ x_1) {I | M.Indep I}, I ⊆ B) ↔ M.Indep I

Next tactic:
refine ⟨fun ⟨_, ⟨hB,_⟩, hIB⟩ ↦ M.indep_subset hB hIB, fun h ↦ ?_⟩
@[simp] theorem matroid_indep_iff {M : IndepMatroid α} {I : Set α} :
    M.matroid.Indep I ↔ M.Indep I := by
  simp only [IndepMatroid.matroid, indep_iff_subset_base]
  refine ⟨fun ⟨_, ⟨hB,_⟩, hIB⟩ ↦ M.indep_subset hB hIB, fun h ↦ ?_⟩
  

Proof state:
α : Type u_1
I✝ B X : Set α
M : IndepMatroid α
I : Set α
h : M.Indep I
⊢ ∃ B ∈ maximals (fun x x_1 => x ⊆ x_1) {I | M.Indep I}, I ⊆ B

Next tactic:
obtain ⟨B, hB⟩ := M.indep_maximal _ rfl.subset I h (M.subset_ground _ h)
@[simp] theorem matroid_indep_iff {M : IndepMatroid α} {I : Set α} :
    M.matroid.Indep I ↔ M.Indep I := by
  simp only [IndepMatroid.matroid, indep_iff_subset_base]
  refine ⟨fun ⟨_, ⟨hB,_⟩, hIB⟩ ↦ M.indep_subset hB hIB, fun h ↦ ?_⟩
  obtain ⟨B, hB⟩ := M.indep_maximal _ rfl.subset I h (M.subset_ground _ h)
  

Proof state:
case intro
α : Type u_1
I✝ B✝ X : Set α
M : IndepMatroid α
I : Set α
h : M.Indep I
B : Set α
hB : B ∈ maximals (fun x x_1 => x ⊆ x_1) {Y | M.Indep Y ∧ I ⊆ Y ∧ Y ⊆ M.E}
⊢ ∃ B ∈ maximals (fun x x_1 => x ⊆ x_1) {I | M.Indep I}, I ⊆ B

Next tactic:
simp only [mem_maximals_setOf_iff, and_imp] at *
@[simp] theorem matroid_indep_iff {M : IndepMatroid α} {I : Set α} :
    M.matroid.Indep I ↔ M.Indep I := by
  simp only [IndepMatroid.matroid, indep_iff_subset_base]
  refine ⟨fun ⟨_, ⟨hB,_⟩, hIB⟩ ↦ M.indep_subset hB hIB, fun h ↦ ?_⟩
  obtain ⟨B, hB⟩ := M.indep_maximal _ rfl.subset I h (M.subset_ground _ h)
  simp only [mem_maximals_setOf_iff, and_imp] at *
  

Proof state:
case intro
α : Type u_1
I✝ B✝ X : Set α
M : IndepMatroid α
I : Set α
h : M.Indep I
B : Set α
hB : (M.Indep B ∧ I ⊆ B ∧ B ⊆ M.E) ∧ ∀ ⦃y : Set α⦄, M.Indep y → I ⊆ y → y ⊆ M.E → B ⊆ y → B = y
⊢ ∃ B, (M.Indep B ∧ ∀ ⦃y : Set α⦄, M.Indep y → B ⊆ y → B = y) ∧ I ⊆ B

Next tactic:
exact ⟨B, ⟨hB.1.1, fun J hJ hBJ ↦
    hB.2 hJ (hB.1.2.1.trans hBJ) (M.subset_ground _ hJ) hBJ⟩, hB.1.2.1⟩
/-- An independence predicate satisfying the finite matroid axioms determines a matroid,
  provided independence is determined by its behaviour on finite sets.
  This fundamentally needs choice, since it can be used to prove that every vector space
  has a basis. -/
@[simps E] protected def ofFinitary (E : Set α) (Indep : Set α → Prop)
    (indep_empty : Indep ∅)
    (indep_subset : ∀ ⦃I J⦄, Indep J → I ⊆ J → Indep I)
    (indep_aug : ∀ ⦃I J⦄, Indep I → I.Finite → Indep J → J.Finite → I.ncard < J.ncard →
      ∃ e ∈ J, e ∉ I ∧ Indep (insert e I))
    (indep_compact : ∀ I, (∀ J, J ⊆ I → J.Finite → Indep J) → Indep I)
    (subset_ground : ∀ I, Indep I → I ⊆ E) : IndepMatroid α :=
  have htofin : ∀ I e, Indep I → ¬ Indep (insert e I) →
    ∃ I₀, I₀ ⊆ I ∧ I₀.Finite ∧ ¬ Indep (insert e I₀) := by
      

Proof state:
α : Type u_1
I B X E : Set α
Indep : Set α → Prop
indep_empty : Indep ∅
indep_subset : ∀ ⦃I J : Set α⦄, Indep J → I ⊆ J → Indep I
indep_aug :
  ∀ ⦃I J : Set α⦄,
    Indep I → Set.Finite I → Indep J → Set.Finite J → ncard I < ncard J → ∃ e ∈ J, e ∉ I ∧ Indep (insert e I)
indep_compact : ∀ (I : Set α), (∀ J ⊆ I, Set.Finite J → Indep J) → Indep I
subset_ground : ∀ (I : Set α), Indep I → I ⊆ E
⊢ ∀ (I : Set α) (e : α), Indep I → ¬Indep (insert e I) → ∃ I₀ ⊆ I, Set.Finite I₀ ∧ ¬Indep (insert e I₀)

Next tactic:
by_contra h
/-- An independence predicate satisfying the finite matroid axioms determines a matroid,
  provided independence is determined by its behaviour on finite sets.
  This fundamentally needs choice, since it can be used to prove that every vector space
  has a basis. -/
@[simps E] protected def ofFinitary (E : Set α) (Indep : Set α → Prop)
    (indep_empty : Indep ∅)
    (indep_subset : ∀ ⦃I J⦄, Indep J → I ⊆ J → Indep I)
    (indep_aug : ∀ ⦃I J⦄, Indep I → I.Finite → Indep J → J.Finite → I.ncard < J.ncard →
      ∃ e ∈ J, e ∉ I ∧ Indep (insert e I))
    (indep_compact : ∀ I, (∀ J, J ⊆ I → J.Finite → Indep J) → Indep I)
    (subset_ground : ∀ I, Indep I → I ⊆ E) : IndepMatroid α :=
  have htofin : ∀ I e, Indep I → ¬ Indep (insert e I) →
    ∃ I₀, I₀ ⊆ I ∧ I₀.Finite ∧ ¬ Indep (insert e I₀) := by
      by_contra h; 

Proof state:
α : Type u_1
I B X E : Set α
Indep : Set α → Prop
indep_empty : Indep ∅
indep_subset : ∀ ⦃I J : Set α⦄, Indep J → I ⊆ J → Indep I
indep_aug :
  ∀ ⦃I J : Set α⦄,
    Indep I → Set.Finite I → Indep J → Set.Finite J → ncard I < ncard J → ∃ e ∈ J, e ∉ I ∧ Indep (insert e I)
indep_compact : ∀ (I : Set α), (∀ J ⊆ I, Set.Finite J → Indep J) → Indep I
subset_ground : ∀ (I : Set α), Indep I → I ⊆ E
h : ¬∀ (I : Set α) (e : α), Indep I → ¬Indep (insert e I) → ∃ I₀ ⊆ I, Set.Finite I₀ ∧ ¬Indep (insert e I₀)
⊢ False

Next tactic:
push_neg at h
/-- An independence predicate satisfying the finite matroid axioms determines a matroid,
  provided independence is determined by its behaviour on finite sets.
  This fundamentally needs choice, since it can be used to prove that every vector space
  has a basis. -/
@[simps E] protected def ofFinitary (E : Set α) (Indep : Set α → Prop)
    (indep_empty : Indep ∅)
    (indep_subset : ∀ ⦃I J⦄, Indep J → I ⊆ J → Indep I)
    (indep_aug : ∀ ⦃I J⦄, Indep I → I.Finite → Indep J → J.Finite → I.ncard < J.ncard →
      ∃ e ∈ J, e ∉ I ∧ Indep (insert e I))
    (indep_compact : ∀ I, (∀ J, J ⊆ I → J.Finite → Indep J) → Indep I)
    (subset_ground : ∀ I, Indep I → I ⊆ E) : IndepMatroid α :=
  have htofin : ∀ I e, Indep I → ¬ Indep (insert e I) →
    ∃ I₀, I₀ ⊆ I ∧ I₀.Finite ∧ ¬ Indep (insert e I₀) := by
      by_contra h; push_neg at h
      

Proof state:
α : Type u_1
I B X E : Set α
Indep : Set α → Prop
indep_empty : Indep ∅
indep_subset : ∀ ⦃I J : Set α⦄, Indep J → I ⊆ J → Indep I
indep_aug :
  ∀ ⦃I J : Set α⦄,
    Indep I → Set.Finite I → Indep J → Set.Finite J → ncard I < ncard J → ∃ e ∈ J, e ∉ I ∧ Indep (insert e I)
indep_compact : ∀ (I : Set α), (∀ J ⊆ I, Set.Finite J → Indep J) → Indep I
subset_ground : ∀ (I : Set α), Indep I → I ⊆ E
h : ∃ I e, Indep I ∧ ¬Indep (insert e I) ∧ ∀ I₀ ⊆ I, Set.Finite I₀ → Indep (insert e I₀)
⊢ False

Next tactic:
obtain ⟨I, e, -, hIe, h⟩ := h
/-- An independence predicate satisfying the finite matroid axioms determines a matroid,
  provided independence is determined by its behaviour on finite sets.
  This fundamentally needs choice, since it can be used to prove that every vector space
  has a basis. -/
@[simps E] protected def ofFinitary (E : Set α) (Indep : Set α → Prop)
    (indep_empty : Indep ∅)
    (indep_subset : ∀ ⦃I J⦄, Indep J → I ⊆ J → Indep I)
    (indep_aug : ∀ ⦃I J⦄, Indep I → I.Finite → Indep J → J.Finite → I.ncard < J.ncard →
      ∃ e ∈ J, e ∉ I ∧ Indep (insert e I))
    (indep_compact : ∀ I, (∀ J, J ⊆ I → J.Finite → Indep J) → Indep I)
    (subset_ground : ∀ I, Indep I → I ⊆ E) : IndepMatroid α :=
  have htofin : ∀ I e, Indep I → ¬ Indep (insert e I) →
    ∃ I₀, I₀ ⊆ I ∧ I₀.Finite ∧ ¬ Indep (insert e I₀) := by
      by_contra h; push_neg at h
      obtain ⟨I, e, -, hIe, h⟩ := h
      

Proof state:
case intro.intro.intro.intro
α : Type u_1
I✝ B X E : Set α
Indep : Set α → Prop
indep_empty : Indep ∅
indep_subset : ∀ ⦃I J : Set α⦄, Indep J → I ⊆ J → Indep I
indep_aug :
  ∀ ⦃I J : Set α⦄,
    Indep I → Set.Finite I → Indep J → Set.Finite J → ncard I < ncard J → ∃ e ∈ J, e ∉ I ∧ Indep (insert e I)
indep_compact : ∀ (I : Set α), (∀ J ⊆ I, Set.Finite J → Indep J) → Indep I
subset_ground : ∀ (I : Set α), Indep I → I ⊆ E
I : Set α
e : α
hIe : ¬Indep (insert e I)
h : ∀ I₀ ⊆ I, Set.Finite I₀ → Indep (insert e I₀)
⊢ False

Next tactic:
refine hIe <| indep_compact _ fun J hJss hJfin ↦ ?_
/-- An independence predicate satisfying the finite matroid axioms determines a matroid,
  provided independence is determined by its behaviour on finite sets.
  This fundamentally needs choice, since it can be used to prove that every vector space
  has a basis. -/
@[simps E] protected def ofFinitary (E : Set α) (Indep : Set α → Prop)
    (indep_empty : Indep ∅)
    (indep_subset : ∀ ⦃I J⦄, Indep J → I ⊆ J → Indep I)
    (indep_aug : ∀ ⦃I J⦄, Indep I → I.Finite → Indep J → J.Finite → I.ncard < J.ncard →
      ∃ e ∈ J, e ∉ I ∧ Indep (insert e I))
    (indep_compact : ∀ I, (∀ J, J ⊆ I → J.Finite → Indep J) → Indep I)
    (subset_ground : ∀ I, Indep I → I ⊆ E) : IndepMatroid α :=
  have htofin : ∀ I e, Indep I → ¬ Indep (insert e I) →
    ∃ I₀, I₀ ⊆ I ∧ I₀.Finite ∧ ¬ Indep (insert e I₀) := by
      by_contra h; push_neg at h
      obtain ⟨I, e, -, hIe, h⟩ := h
      refine hIe <| indep_compact _ fun J hJss hJfin ↦ ?_
      

Proof state:
case intro.intro.intro.intro
α : Type u_1
I✝ B X E : Set α
Indep : Set α → Prop
indep_empty : Indep ∅
indep_subset : ∀ ⦃I J : Set α⦄, Indep J → I ⊆ J → Indep I
indep_aug :
  ∀ ⦃I J : Set α⦄,
    Indep I → Set.Finite I → Indep J → Set.Finite J → ncard I < ncard J → ∃ e ∈ J, e ∉ I ∧ Indep (insert e I)
indep_compact : ∀ (I : Set α), (∀ J ⊆ I, Set.Finite J → Indep J) → Indep I
subset_ground : ∀ (I : Set α), Indep I → I ⊆ E
I : Set α
e : α
hIe : ¬Indep (insert e I)
h : ∀ I₀ ⊆ I, Set.Finite I₀ → Indep (insert e I₀)
J : Set α
hJss : J ⊆ insert e I
hJfin : Set.Finite J
⊢ Indep J

Next tactic:
exact indep_subset (h (J \ {e}) (by rwa [diff_subset_iff]) (hJfin.diff _)) (by simp)
/-- An independence predicate satisfying the finite matroid axioms determines a matroid,
  provided independence is determined by its behaviour on finite sets.
  This fundamentally needs choice, since it can be used to prove that every vector space
  has a basis. -/
@[simps E] protected def ofFinitary (E : Set α) (Indep : Set α → Prop)
    (indep_empty : Indep ∅)
    (indep_subset : ∀ ⦃I J⦄, Indep J → I ⊆ J → Indep I)
    (indep_aug : ∀ ⦃I J⦄, Indep I → I.Finite → Indep J → J.Finite → I.ncard < J.ncard →
      ∃ e ∈ J, e ∉ I ∧ Indep (insert e I))
    (indep_compact : ∀ I, (∀ J, J ⊆ I → J.Finite → Indep J) → Indep I)
    (subset_ground : ∀ I, Indep I → I ⊆ E) : IndepMatroid α :=
  have htofin : ∀ I e, Indep I → ¬ Indep (insert e I) →
    ∃ I₀, I₀ ⊆ I ∧ I₀.Finite ∧ ¬ Indep (insert e I₀) := by
      by_contra h; push_neg at h
      obtain ⟨I, e, -, hIe, h⟩ := h
      refine hIe <| indep_compact _ fun J hJss hJfin ↦ ?_
      exact indep_subset (h (J \ {e}) (by 

Proof state:
α : Type u_1
I✝ B X E : Set α
Indep : Set α → Prop
indep_empty : Indep ∅
indep_subset : ∀ ⦃I J : Set α⦄, Indep J → I ⊆ J → Indep I
indep_aug :
  ∀ ⦃I J : Set α⦄,
    Indep I → Set.Finite I → Indep J → Set.Finite J → ncard I < ncard J → ∃ e ∈ J, e ∉ I ∧ Indep (insert e I)
indep_compact : ∀ (I : Set α), (∀ J ⊆ I, Set.Finite J → Indep J) → Indep I
subset_ground : ∀ (I : Set α), Indep I → I ⊆ E
I : Set α
e : α
hIe : ¬Indep (insert e I)
h : ∀ I₀ ⊆ I, Set.Finite I₀ → Indep (insert e I₀)
J : Set α
hJss : J ⊆ insert e I
hJfin : Set.Finite J
⊢ J \ {e} ⊆ I

Next tactic:
rwa [diff_subset_iff]
/-- An independence predicate satisfying the finite matroid axioms determines a matroid,
  provided independence is determined by its behaviour on finite sets.
  This fundamentally needs choice, since it can be used to prove that every vector space
  has a basis. -/
@[simps E] protected def ofFinitary (E : Set α) (Indep : Set α → Prop)
    (indep_empty : Indep ∅)
    (indep_subset : ∀ ⦃I J⦄, Indep J → I ⊆ J → Indep I)
    (indep_aug : ∀ ⦃I J⦄, Indep I → I.Finite → Indep J → J.Finite → I.ncard < J.ncard →
      ∃ e ∈ J, e ∉ I ∧ Indep (insert e I))
    (indep_compact : ∀ I, (∀ J, J ⊆ I → J.Finite → Indep J) → Indep I)
    (subset_ground : ∀ I, Indep I → I ⊆ E) : IndepMatroid α :=
  have htofin : ∀ I e, Indep I → ¬ Indep (insert e I) →
    ∃ I₀, I₀ ⊆ I ∧ I₀.Finite ∧ ¬ Indep (insert e I₀) := by
      by_contra h; push_neg at h
      obtain ⟨I, e, -, hIe, h⟩ := h
      refine hIe <| indep_compact _ fun J hJss hJfin ↦ ?_
      exact indep_subset (h (J \ {e}) (by rwa [diff_subset_iff]) (hJfin.diff _)) (by 

Proof state:
α : Type u_1
I✝ B X E : Set α
Indep : Set α → Prop
indep_empty : Indep ∅
indep_subset : ∀ ⦃I J : Set α⦄, Indep J → I ⊆ J → Indep I
indep_aug :
  ∀ ⦃I J : Set α⦄,
    Indep I → Set.Finite I → Indep J → Set.Finite J → ncard I < ncard J → ∃ e ∈ J, e ∉ I ∧ Indep (insert e I)
indep_compact : ∀ (I : Set α), (∀ J ⊆ I, Set.Finite J → Indep J) → Indep I
subset_ground : ∀ (I : Set α), Indep I → I ⊆ E
I : Set α
e : α
hIe : ¬Indep (insert e I)
h : ∀ I₀ ⊆ I, Set.Finite I₀ → Indep (insert e I₀)
J : Set α
hJss : J ⊆ insert e I
hJfin : Set.Finite J
⊢ J ⊆ insert e (J \ {e})

Next tactic:
simp
/-- An independence predicate satisfying the finite matroid axioms determines a matroid,
  provided independence is determined by its behaviour on finite sets.
  This fundamentally needs choice, since it can be used to prove that every vector space
  has a basis. -/
@[simps E] protected def ofFinitary (E : Set α) (Indep : Set α → Prop)
    (indep_empty : Indep ∅)
    (indep_subset : ∀ ⦃I J⦄, Indep J → I ⊆ J → Indep I)
    (indep_aug : ∀ ⦃I J⦄, Indep I → I.Finite → Indep J → J.Finite → I.ncard < J.ncard →
      ∃ e ∈ J, e ∉ I ∧ Indep (insert e I))
    (indep_compact : ∀ I, (∀ J, J ⊆ I → J.Finite → Indep J) → Indep I)
    (subset_ground : ∀ I, Indep I → I ⊆ E) : IndepMatroid α :=
  have htofin : ∀ I e, Indep I → ¬ Indep (insert e I) →
    ∃ I₀, I₀ ⊆ I ∧ I₀.Finite ∧ ¬ Indep (insert e I₀) := by
      by_contra h; push_neg at h
      obtain ⟨I, e, -, hIe, h⟩ := h
      refine hIe <| indep_compact _ fun J hJss hJfin ↦ ?_
      exact indep_subset (h (J \ {e}) (by rwa [diff_subset_iff]) (hJfin.diff _)) (by simp)
  IndepMatroid.mk
  (E := E)
  (Indep := Indep)
  (indep_empty := indep_empty)
  (indep_subset := indep_subset)
  (indep_aug := by
    

Proof state:
α : Type u_1
I B X E : Set α
Indep : Set α → Prop
indep_empty : Indep ∅
indep_subset : ∀ ⦃I J : Set α⦄, Indep J → I ⊆ J → Indep I
indep_aug :
  ∀ ⦃I J : Set α⦄,
    Indep I → Set.Finite I → Indep J → Set.Finite J → ncard I < ncard J → ∃ e ∈ J, e ∉ I ∧ Indep (insert e I)
indep_compact : ∀ (I : Set α), (∀ J ⊆ I, Set.Finite J → Indep J) → Indep I
subset_ground : ∀ (I : Set α), Indep I → I ⊆ E
htofin : ∀ (I : Set α) (e : α), Indep I → ¬Indep (insert e I) → ∃ I₀ ⊆ I, Set.Finite I₀ ∧ ¬Indep (insert e I₀)
⊢ ∀ ⦃I B : Set α⦄,
    Indep I →
      I ∉ maximals (fun x x_1 => x ⊆ x_1) {I | Indep I} →
        B ∈ maximals (fun x x_1 => x ⊆ x_1) {I | Indep I} → ∃ x ∈ B \ I, Indep (insert x I)

Next tactic:
intro I B hI hImax hBmax