l3lab/ntp-mathlib huggingface dataset:
instance is_irreducible_of_isIntegral [IsIntegral X] : IrreducibleSpace X.carrier := by
  by_contra H
  replace H : ¬IsPreirreducible (⊤ : Set X.carrier) := fun h =>
    H { toPreirreducibleSpace := ⟨h⟩
        toNonempty := inferInstance }
  simp_rw [isPreirreducible_iff_closed_union_closed, not_forall, not_or] at H
  rcases H with ⟨S, T, hS, hT, h₁, h₂, h₃⟩
  erw [not_forall] at h₂ h₃
  simp_rw [not_forall] at h₂ h₃
  haveI : Nonempty (⟨Sᶜ, hS.1⟩ : Opens X.carrier) := ⟨⟨_, h₂.choose_spec.choose_spec⟩⟩
  haveI : Nonempty (⟨Tᶜ, hT.1⟩ : Opens X.carrier) := ⟨⟨_, h₃.choose_spec.choose_spec⟩⟩
  haveI : Nonempty (⟨Sᶜ, hS.1⟩ ⊔ ⟨Tᶜ, hT.1⟩ : Opens X.carrier) :=
    ⟨⟨_, Or.inl h₂.choose_spec.choose_spec⟩⟩
  let e : X.presheaf.obj _ ≅ CommRingCat.of _ :=
    (X.sheaf.isProductOfDisjoint ⟨_, hS.1⟩ ⟨_, hT.1⟩ ?_).conePointUniqueUpToIso
      (CommRingCat.prodFanIsLimit _ _)
  apply (config := { allowSynthFailures := true }) false_of_nontrivial_of_product_domain
  · exact e.symm.commRingCatIsoToRingEquiv.toMulEquiv.isDomain _
  · apply X.toLocallyRingedSpace.component_nontrivial
  · 

Proof state:
case inst
X : Scheme
inst✝ : IsIntegral X
S T : Set ↑↑X.toPresheafedSpace
hS : IsClosed S
hT : IsClosed T
h₁ : ⊤ ⊆ S ∪ T
h₂ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ S
h₃ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ T
this✝¹ : Nonempty ↥{ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) }
this✝ : Nonempty ↥{ carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) }
this : Nonempty ↥({ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) } ⊔ { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) })
e : X.presheaf.obj
    (op ({ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) } ⊔ { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) })) ≅
  CommRingCat.of
    ↑(CommRingCat.prodFan ((Scheme.sheaf X).val.obj (op { carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) }))
          ((Scheme.sheaf X).val.obj (op { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) }))).1 :=
  IsLimit.conePointUniqueUpToIso
    (Sheaf.isProductOfDisjoint (Scheme.sheaf X) { carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) }
      { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) } ?intro.intro.intro.intro.intro.intro.refine_1)
    (CommRingCat.prodFanIsLimit ((Scheme.sheaf X).val.obj (op { carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) }))
      ((Scheme.sheaf X).val.obj (op { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) })))
⊢ Nontrivial ↑((Scheme.sheaf X).val.obj (op { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) }))

Next tactic:
apply X.toLocallyRingedSpace.component_nontrivial
instance is_irreducible_of_isIntegral [IsIntegral X] : IrreducibleSpace X.carrier := by
  by_contra H
  replace H : ¬IsPreirreducible (⊤ : Set X.carrier) := fun h =>
    H { toPreirreducibleSpace := ⟨h⟩
        toNonempty := inferInstance }
  simp_rw [isPreirreducible_iff_closed_union_closed, not_forall, not_or] at H
  rcases H with ⟨S, T, hS, hT, h₁, h₂, h₃⟩
  erw [not_forall] at h₂ h₃
  simp_rw [not_forall] at h₂ h₃
  haveI : Nonempty (⟨Sᶜ, hS.1⟩ : Opens X.carrier) := ⟨⟨_, h₂.choose_spec.choose_spec⟩⟩
  haveI : Nonempty (⟨Tᶜ, hT.1⟩ : Opens X.carrier) := ⟨⟨_, h₃.choose_spec.choose_spec⟩⟩
  haveI : Nonempty (⟨Sᶜ, hS.1⟩ ⊔ ⟨Tᶜ, hT.1⟩ : Opens X.carrier) :=
    ⟨⟨_, Or.inl h₂.choose_spec.choose_spec⟩⟩
  let e : X.presheaf.obj _ ≅ CommRingCat.of _ :=
    (X.sheaf.isProductOfDisjoint ⟨_, hS.1⟩ ⟨_, hT.1⟩ ?_).conePointUniqueUpToIso
      (CommRingCat.prodFanIsLimit _ _)
  apply (config := { allowSynthFailures := true }) false_of_nontrivial_of_product_domain
  · exact e.symm.commRingCatIsoToRingEquiv.toMulEquiv.isDomain _
  · apply X.toLocallyRingedSpace.component_nontrivial
  · apply X.toLocallyRingedSpace.component_nontrivial
  · 

Proof state:
case intro.intro.intro.intro.intro.intro.refine_1
X : Scheme
inst✝ : IsIntegral X
S T : Set ↑↑X.toPresheafedSpace
hS : IsClosed S
hT : IsClosed T
h₁ : ⊤ ⊆ S ∪ T
h₂ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ S
h₃ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ T
this✝¹ : Nonempty ↥{ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) }
this✝ : Nonempty ↥{ carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) }
this : Nonempty ↥({ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) } ⊔ { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) })
⊢ { carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) } ⊓ { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) } = ⊥

Next tactic:
ext x
instance is_irreducible_of_isIntegral [IsIntegral X] : IrreducibleSpace X.carrier := by
  by_contra H
  replace H : ¬IsPreirreducible (⊤ : Set X.carrier) := fun h =>
    H { toPreirreducibleSpace := ⟨h⟩
        toNonempty := inferInstance }
  simp_rw [isPreirreducible_iff_closed_union_closed, not_forall, not_or] at H
  rcases H with ⟨S, T, hS, hT, h₁, h₂, h₃⟩
  erw [not_forall] at h₂ h₃
  simp_rw [not_forall] at h₂ h₃
  haveI : Nonempty (⟨Sᶜ, hS.1⟩ : Opens X.carrier) := ⟨⟨_, h₂.choose_spec.choose_spec⟩⟩
  haveI : Nonempty (⟨Tᶜ, hT.1⟩ : Opens X.carrier) := ⟨⟨_, h₃.choose_spec.choose_spec⟩⟩
  haveI : Nonempty (⟨Sᶜ, hS.1⟩ ⊔ ⟨Tᶜ, hT.1⟩ : Opens X.carrier) :=
    ⟨⟨_, Or.inl h₂.choose_spec.choose_spec⟩⟩
  let e : X.presheaf.obj _ ≅ CommRingCat.of _ :=
    (X.sheaf.isProductOfDisjoint ⟨_, hS.1⟩ ⟨_, hT.1⟩ ?_).conePointUniqueUpToIso
      (CommRingCat.prodFanIsLimit _ _)
  apply (config := { allowSynthFailures := true }) false_of_nontrivial_of_product_domain
  · exact e.symm.commRingCatIsoToRingEquiv.toMulEquiv.isDomain _
  · apply X.toLocallyRingedSpace.component_nontrivial
  · apply X.toLocallyRingedSpace.component_nontrivial
  · ext x
    

Proof state:
case intro.intro.intro.intro.intro.intro.refine_1.h.h
X : Scheme
inst✝ : IsIntegral X
S T : Set ↑↑X.toPresheafedSpace
hS : IsClosed S
hT : IsClosed T
h₁ : ⊤ ⊆ S ∪ T
h₂ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ S
h₃ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ T
this✝¹ : Nonempty ↥{ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) }
this✝ : Nonempty ↥{ carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) }
this : Nonempty ↥({ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) } ⊔ { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) })
x : ↑↑X.toPresheafedSpace
⊢ x ∈ ↑({ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) } ⊓ { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) }) ↔ x ∈ ↑⊥

Next tactic:
constructor
instance is_irreducible_of_isIntegral [IsIntegral X] : IrreducibleSpace X.carrier := by
  by_contra H
  replace H : ¬IsPreirreducible (⊤ : Set X.carrier) := fun h =>
    H { toPreirreducibleSpace := ⟨h⟩
        toNonempty := inferInstance }
  simp_rw [isPreirreducible_iff_closed_union_closed, not_forall, not_or] at H
  rcases H with ⟨S, T, hS, hT, h₁, h₂, h₃⟩
  erw [not_forall] at h₂ h₃
  simp_rw [not_forall] at h₂ h₃
  haveI : Nonempty (⟨Sᶜ, hS.1⟩ : Opens X.carrier) := ⟨⟨_, h₂.choose_spec.choose_spec⟩⟩
  haveI : Nonempty (⟨Tᶜ, hT.1⟩ : Opens X.carrier) := ⟨⟨_, h₃.choose_spec.choose_spec⟩⟩
  haveI : Nonempty (⟨Sᶜ, hS.1⟩ ⊔ ⟨Tᶜ, hT.1⟩ : Opens X.carrier) :=
    ⟨⟨_, Or.inl h₂.choose_spec.choose_spec⟩⟩
  let e : X.presheaf.obj _ ≅ CommRingCat.of _ :=
    (X.sheaf.isProductOfDisjoint ⟨_, hS.1⟩ ⟨_, hT.1⟩ ?_).conePointUniqueUpToIso
      (CommRingCat.prodFanIsLimit _ _)
  apply (config := { allowSynthFailures := true }) false_of_nontrivial_of_product_domain
  · exact e.symm.commRingCatIsoToRingEquiv.toMulEquiv.isDomain _
  · apply X.toLocallyRingedSpace.component_nontrivial
  · apply X.toLocallyRingedSpace.component_nontrivial
  · ext x
    constructor
    · 

Proof state:
case intro.intro.intro.intro.intro.intro.refine_1.h.h.mp
X : Scheme
inst✝ : IsIntegral X
S T : Set ↑↑X.toPresheafedSpace
hS : IsClosed S
hT : IsClosed T
h₁ : ⊤ ⊆ S ∪ T
h₂ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ S
h₃ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ T
this✝¹ : Nonempty ↥{ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) }
this✝ : Nonempty ↥{ carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) }
this : Nonempty ↥({ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) } ⊔ { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) })
x : ↑↑X.toPresheafedSpace
⊢ x ∈ ↑({ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) } ⊓ { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) }) → x ∈ ↑⊥

Next tactic:
rintro ⟨hS, hT⟩
instance is_irreducible_of_isIntegral [IsIntegral X] : IrreducibleSpace X.carrier := by
  by_contra H
  replace H : ¬IsPreirreducible (⊤ : Set X.carrier) := fun h =>
    H { toPreirreducibleSpace := ⟨h⟩
        toNonempty := inferInstance }
  simp_rw [isPreirreducible_iff_closed_union_closed, not_forall, not_or] at H
  rcases H with ⟨S, T, hS, hT, h₁, h₂, h₃⟩
  erw [not_forall] at h₂ h₃
  simp_rw [not_forall] at h₂ h₃
  haveI : Nonempty (⟨Sᶜ, hS.1⟩ : Opens X.carrier) := ⟨⟨_, h₂.choose_spec.choose_spec⟩⟩
  haveI : Nonempty (⟨Tᶜ, hT.1⟩ : Opens X.carrier) := ⟨⟨_, h₃.choose_spec.choose_spec⟩⟩
  haveI : Nonempty (⟨Sᶜ, hS.1⟩ ⊔ ⟨Tᶜ, hT.1⟩ : Opens X.carrier) :=
    ⟨⟨_, Or.inl h₂.choose_spec.choose_spec⟩⟩
  let e : X.presheaf.obj _ ≅ CommRingCat.of _ :=
    (X.sheaf.isProductOfDisjoint ⟨_, hS.1⟩ ⟨_, hT.1⟩ ?_).conePointUniqueUpToIso
      (CommRingCat.prodFanIsLimit _ _)
  apply (config := { allowSynthFailures := true }) false_of_nontrivial_of_product_domain
  · exact e.symm.commRingCatIsoToRingEquiv.toMulEquiv.isDomain _
  · apply X.toLocallyRingedSpace.component_nontrivial
  · apply X.toLocallyRingedSpace.component_nontrivial
  · ext x
    constructor
    · rintro ⟨hS, hT⟩
      

Proof state:
case intro.intro.intro.intro.intro.intro.refine_1.h.h.mp.intro
X : Scheme
inst✝ : IsIntegral X
S T : Set ↑↑X.toPresheafedSpace
hS✝ : IsClosed S
hT✝ : IsClosed T
h₁ : ⊤ ⊆ S ∪ T
h₂ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ S
h₃ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ T
this✝¹ : Nonempty ↥{ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) }
this✝ : Nonempty ↥{ carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) }
this : Nonempty ↥({ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) } ⊔ { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) })
x : ↑↑X.toPresheafedSpace
hS : x ∈ ↑{ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) }
hT : x ∈ ↑{ carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) }
⊢ x ∈ ↑⊥

Next tactic:
cases' h₁ (show x ∈ ⊤ by trivial) with h h
instance is_irreducible_of_isIntegral [IsIntegral X] : IrreducibleSpace X.carrier := by
  by_contra H
  replace H : ¬IsPreirreducible (⊤ : Set X.carrier) := fun h =>
    H { toPreirreducibleSpace := ⟨h⟩
        toNonempty := inferInstance }
  simp_rw [isPreirreducible_iff_closed_union_closed, not_forall, not_or] at H
  rcases H with ⟨S, T, hS, hT, h₁, h₂, h₃⟩
  erw [not_forall] at h₂ h₃
  simp_rw [not_forall] at h₂ h₃
  haveI : Nonempty (⟨Sᶜ, hS.1⟩ : Opens X.carrier) := ⟨⟨_, h₂.choose_spec.choose_spec⟩⟩
  haveI : Nonempty (⟨Tᶜ, hT.1⟩ : Opens X.carrier) := ⟨⟨_, h₃.choose_spec.choose_spec⟩⟩
  haveI : Nonempty (⟨Sᶜ, hS.1⟩ ⊔ ⟨Tᶜ, hT.1⟩ : Opens X.carrier) :=
    ⟨⟨_, Or.inl h₂.choose_spec.choose_spec⟩⟩
  let e : X.presheaf.obj _ ≅ CommRingCat.of _ :=
    (X.sheaf.isProductOfDisjoint ⟨_, hS.1⟩ ⟨_, hT.1⟩ ?_).conePointUniqueUpToIso
      (CommRingCat.prodFanIsLimit _ _)
  apply (config := { allowSynthFailures := true }) false_of_nontrivial_of_product_domain
  · exact e.symm.commRingCatIsoToRingEquiv.toMulEquiv.isDomain _
  · apply X.toLocallyRingedSpace.component_nontrivial
  · apply X.toLocallyRingedSpace.component_nontrivial
  · ext x
    constructor
    · rintro ⟨hS, hT⟩
      cases' h₁ (show x ∈ ⊤ by 

Proof state:
X : Scheme
inst✝ : IsIntegral X
S T : Set ↑↑X.toPresheafedSpace
hS✝ : IsClosed S
hT✝ : IsClosed T
h₁ : ⊤ ⊆ S ∪ T
h₂ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ S
h₃ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ T
this✝¹ : Nonempty ↥{ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) }
this✝ : Nonempty ↥{ carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) }
this : Nonempty ↥({ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) } ⊔ { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) })
x : ↑↑X.toPresheafedSpace
hS : x ∈ ↑{ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) }
hT : x ∈ ↑{ carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) }
⊢ x ∈ ⊤

Next tactic:
trivial
instance is_irreducible_of_isIntegral [IsIntegral X] : IrreducibleSpace X.carrier := by
  by_contra H
  replace H : ¬IsPreirreducible (⊤ : Set X.carrier) := fun h =>
    H { toPreirreducibleSpace := ⟨h⟩
        toNonempty := inferInstance }
  simp_rw [isPreirreducible_iff_closed_union_closed, not_forall, not_or] at H
  rcases H with ⟨S, T, hS, hT, h₁, h₂, h₃⟩
  erw [not_forall] at h₂ h₃
  simp_rw [not_forall] at h₂ h₃
  haveI : Nonempty (⟨Sᶜ, hS.1⟩ : Opens X.carrier) := ⟨⟨_, h₂.choose_spec.choose_spec⟩⟩
  haveI : Nonempty (⟨Tᶜ, hT.1⟩ : Opens X.carrier) := ⟨⟨_, h₃.choose_spec.choose_spec⟩⟩
  haveI : Nonempty (⟨Sᶜ, hS.1⟩ ⊔ ⟨Tᶜ, hT.1⟩ : Opens X.carrier) :=
    ⟨⟨_, Or.inl h₂.choose_spec.choose_spec⟩⟩
  let e : X.presheaf.obj _ ≅ CommRingCat.of _ :=
    (X.sheaf.isProductOfDisjoint ⟨_, hS.1⟩ ⟨_, hT.1⟩ ?_).conePointUniqueUpToIso
      (CommRingCat.prodFanIsLimit _ _)
  apply (config := { allowSynthFailures := true }) false_of_nontrivial_of_product_domain
  · exact e.symm.commRingCatIsoToRingEquiv.toMulEquiv.isDomain _
  · apply X.toLocallyRingedSpace.component_nontrivial
  · apply X.toLocallyRingedSpace.component_nontrivial
  · ext x
    constructor
    · rintro ⟨hS, hT⟩
      cases' h₁ (show x ∈ ⊤ by trivial) with h h
      

Proof state:
case intro.intro.intro.intro.intro.intro.refine_1.h.h.mp.intro.inl
X : Scheme
inst✝ : IsIntegral X
S T : Set ↑↑X.toPresheafedSpace
hS✝ : IsClosed S
hT✝ : IsClosed T
h₁ : ⊤ ⊆ S ∪ T
h₂ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ S
h₃ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ T
this✝¹ : Nonempty ↥{ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) }
this✝ : Nonempty ↥{ carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) }
this : Nonempty ↥({ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) } ⊔ { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) })
x : ↑↑X.toPresheafedSpace
hS : x ∈ ↑{ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) }
hT : x ∈ ↑{ carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) }
h : x ∈ S
⊢ x ∈ ↑⊥
case intro.intro.intro.intro.intro.intro.refine_1.h.h.mp.intro.inr
X : Scheme
inst✝ : IsIntegral X
S T : Set ↑↑X.toPresheafedSpace
hS✝ : IsClosed S
hT✝ : IsClosed T
h₁ : ⊤ ⊆ S ∪ T
h₂ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ S
h₃ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ T
this✝¹ : Nonempty ↥{ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) }
this✝ : Nonempty ↥{ carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) }
this : Nonempty ↥({ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) } ⊔ { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) })
x : ↑↑X.toPresheafedSpace
hS : x ∈ ↑{ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) }
hT : x ∈ ↑{ carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) }
h : x ∈ T
⊢ x ∈ ↑⊥

Next tactic:
exacts [hS h, hT h]
instance is_irreducible_of_isIntegral [IsIntegral X] : IrreducibleSpace X.carrier := by
  by_contra H
  replace H : ¬IsPreirreducible (⊤ : Set X.carrier) := fun h =>
    H { toPreirreducibleSpace := ⟨h⟩
        toNonempty := inferInstance }
  simp_rw [isPreirreducible_iff_closed_union_closed, not_forall, not_or] at H
  rcases H with ⟨S, T, hS, hT, h₁, h₂, h₃⟩
  erw [not_forall] at h₂ h₃
  simp_rw [not_forall] at h₂ h₃
  haveI : Nonempty (⟨Sᶜ, hS.1⟩ : Opens X.carrier) := ⟨⟨_, h₂.choose_spec.choose_spec⟩⟩
  haveI : Nonempty (⟨Tᶜ, hT.1⟩ : Opens X.carrier) := ⟨⟨_, h₃.choose_spec.choose_spec⟩⟩
  haveI : Nonempty (⟨Sᶜ, hS.1⟩ ⊔ ⟨Tᶜ, hT.1⟩ : Opens X.carrier) :=
    ⟨⟨_, Or.inl h₂.choose_spec.choose_spec⟩⟩
  let e : X.presheaf.obj _ ≅ CommRingCat.of _ :=
    (X.sheaf.isProductOfDisjoint ⟨_, hS.1⟩ ⟨_, hT.1⟩ ?_).conePointUniqueUpToIso
      (CommRingCat.prodFanIsLimit _ _)
  apply (config := { allowSynthFailures := true }) false_of_nontrivial_of_product_domain
  · exact e.symm.commRingCatIsoToRingEquiv.toMulEquiv.isDomain _
  · apply X.toLocallyRingedSpace.component_nontrivial
  · apply X.toLocallyRingedSpace.component_nontrivial
  · ext x
    constructor
    · rintro ⟨hS, hT⟩
      cases' h₁ (show x ∈ ⊤ by trivial) with h h
      exacts [hS h, hT h]
    · 

Proof state:
case intro.intro.intro.intro.intro.intro.refine_1.h.h.mpr
X : Scheme
inst✝ : IsIntegral X
S T : Set ↑↑X.toPresheafedSpace
hS : IsClosed S
hT : IsClosed T
h₁ : ⊤ ⊆ S ∪ T
h₂ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ S
h₃ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ T
this✝¹ : Nonempty ↥{ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) }
this✝ : Nonempty ↥{ carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) }
this : Nonempty ↥({ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) } ⊔ { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) })
x : ↑↑X.toPresheafedSpace
⊢ x ∈ ↑⊥ → x ∈ ↑({ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) } ⊓ { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) })

Next tactic:
intro x
instance is_irreducible_of_isIntegral [IsIntegral X] : IrreducibleSpace X.carrier := by
  by_contra H
  replace H : ¬IsPreirreducible (⊤ : Set X.carrier) := fun h =>
    H { toPreirreducibleSpace := ⟨h⟩
        toNonempty := inferInstance }
  simp_rw [isPreirreducible_iff_closed_union_closed, not_forall, not_or] at H
  rcases H with ⟨S, T, hS, hT, h₁, h₂, h₃⟩
  erw [not_forall] at h₂ h₃
  simp_rw [not_forall] at h₂ h₃
  haveI : Nonempty (⟨Sᶜ, hS.1⟩ : Opens X.carrier) := ⟨⟨_, h₂.choose_spec.choose_spec⟩⟩
  haveI : Nonempty (⟨Tᶜ, hT.1⟩ : Opens X.carrier) := ⟨⟨_, h₃.choose_spec.choose_spec⟩⟩
  haveI : Nonempty (⟨Sᶜ, hS.1⟩ ⊔ ⟨Tᶜ, hT.1⟩ : Opens X.carrier) :=
    ⟨⟨_, Or.inl h₂.choose_spec.choose_spec⟩⟩
  let e : X.presheaf.obj _ ≅ CommRingCat.of _ :=
    (X.sheaf.isProductOfDisjoint ⟨_, hS.1⟩ ⟨_, hT.1⟩ ?_).conePointUniqueUpToIso
      (CommRingCat.prodFanIsLimit _ _)
  apply (config := { allowSynthFailures := true }) false_of_nontrivial_of_product_domain
  · exact e.symm.commRingCatIsoToRingEquiv.toMulEquiv.isDomain _
  · apply X.toLocallyRingedSpace.component_nontrivial
  · apply X.toLocallyRingedSpace.component_nontrivial
  · ext x
    constructor
    · rintro ⟨hS, hT⟩
      cases' h₁ (show x ∈ ⊤ by trivial) with h h
      exacts [hS h, hT h]
    · intro x
      

Proof state:
case intro.intro.intro.intro.intro.intro.refine_1.h.h.mpr
X : Scheme
inst✝ : IsIntegral X
S T : Set ↑↑X.toPresheafedSpace
hS : IsClosed S
hT : IsClosed T
h₁ : ⊤ ⊆ S ∪ T
h₂ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ S
h₃ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ T
this✝¹ : Nonempty ↥{ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) }
this✝ : Nonempty ↥{ carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) }
this : Nonempty ↥({ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) } ⊔ { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) })
x✝ : ↑↑X.toPresheafedSpace
x : x✝ ∈ ↑⊥
⊢ x✝ ∈ ↑({ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) } ⊓ { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) })

Next tactic:
refine' x.rec (by contradiction)
instance is_irreducible_of_isIntegral [IsIntegral X] : IrreducibleSpace X.carrier := by
  by_contra H
  replace H : ¬IsPreirreducible (⊤ : Set X.carrier) := fun h =>
    H { toPreirreducibleSpace := ⟨h⟩
        toNonempty := inferInstance }
  simp_rw [isPreirreducible_iff_closed_union_closed, not_forall, not_or] at H
  rcases H with ⟨S, T, hS, hT, h₁, h₂, h₃⟩
  erw [not_forall] at h₂ h₃
  simp_rw [not_forall] at h₂ h₃
  haveI : Nonempty (⟨Sᶜ, hS.1⟩ : Opens X.carrier) := ⟨⟨_, h₂.choose_spec.choose_spec⟩⟩
  haveI : Nonempty (⟨Tᶜ, hT.1⟩ : Opens X.carrier) := ⟨⟨_, h₃.choose_spec.choose_spec⟩⟩
  haveI : Nonempty (⟨Sᶜ, hS.1⟩ ⊔ ⟨Tᶜ, hT.1⟩ : Opens X.carrier) :=
    ⟨⟨_, Or.inl h₂.choose_spec.choose_spec⟩⟩
  let e : X.presheaf.obj _ ≅ CommRingCat.of _ :=
    (X.sheaf.isProductOfDisjoint ⟨_, hS.1⟩ ⟨_, hT.1⟩ ?_).conePointUniqueUpToIso
      (CommRingCat.prodFanIsLimit _ _)
  apply (config := { allowSynthFailures := true }) false_of_nontrivial_of_product_domain
  · exact e.symm.commRingCatIsoToRingEquiv.toMulEquiv.isDomain _
  · apply X.toLocallyRingedSpace.component_nontrivial
  · apply X.toLocallyRingedSpace.component_nontrivial
  · ext x
    constructor
    · rintro ⟨hS, hT⟩
      cases' h₁ (show x ∈ ⊤ by trivial) with h h
      exacts [hS h, hT h]
    · intro x
      refine' x.rec (by 

Proof state:
X : Scheme
inst✝ : IsIntegral X
S T : Set ↑↑X.toPresheafedSpace
hS : IsClosed S
hT : IsClosed T
h₁ : ⊤ ⊆ S ∪ T
h₂ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ S
h₃ : ∃ x, ∃ (_ : x ∈ ⊤), x ∉ T
this✝¹ : Nonempty ↥{ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) }
this✝ : Nonempty ↥{ carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) }
this : Nonempty ↥({ carrier := Sᶜ, is_open' := (_ : IsOpen Sᶜ) } ⊔ { carrier := Tᶜ, is_open' := (_ : IsOpen Tᶜ) })
x✝ : ↑↑X.toPresheafedSpace
x : x✝ ∈ ↑⊥
⊢ False

Next tactic:
contradiction
theorem isIntegralOfIsIrreducibleIsReduced [IsReduced X] [H : IrreducibleSpace X.carrier] :
    IsIntegral X := by
  

Proof state:
X : Scheme
inst✝ : IsReduced X
H : IrreducibleSpace ↑↑X.toPresheafedSpace
⊢ IsIntegral X

Next tactic:
constructor
theorem isIntegralOfIsIrreducibleIsReduced [IsReduced X] [H : IrreducibleSpace X.carrier] :
    IsIntegral X := by
  constructor; · 

Proof state:
case nonempty
X : Scheme
inst✝ : IsReduced X
H : IrreducibleSpace ↑↑X.toPresheafedSpace
⊢ autoParam (Nonempty ↑↑X.toPresheafedSpace) _auto✝

Next tactic:
infer_instance
theorem isIntegralOfIsIrreducibleIsReduced [IsReduced X] [H : IrreducibleSpace X.carrier] :
    IsIntegral X := by
  constructor; · infer_instance
  

Proof state:
case component_integral
X : Scheme
inst✝ : IsReduced X
H : IrreducibleSpace ↑↑X.toPresheafedSpace
⊢ autoParam (∀ (U : Opens ↑↑X.toPresheafedSpace) [inst : Nonempty ↥U], IsDomain ↑(X.presheaf.obj (op U))) _auto✝

Next tactic:
intro U hU
theorem isIntegralOfIsIrreducibleIsReduced [IsReduced X] [H : IrreducibleSpace X.carrier] :
    IsIntegral X := by
  constructor; · infer_instance
  intro U hU
  

Proof state:
case component_integral
X : Scheme
inst✝ : IsReduced X
H : IrreducibleSpace ↑↑X.toPresheafedSpace
U : Opens ↑↑X.toPresheafedSpace
hU : Nonempty ↥U
⊢ IsDomain ↑(X.presheaf.obj (op U))

Next tactic:
haveI := (@LocallyRingedSpace.component_nontrivial X.toLocallyRingedSpace U hU).1
theorem isIntegralOfIsIrreducibleIsReduced [IsReduced X] [H : IrreducibleSpace X.carrier] :
    IsIntegral X := by
  constructor; · infer_instance
  intro U hU
  haveI := (@LocallyRingedSpace.component_nontrivial X.toLocallyRingedSpace U hU).1
  

Proof state:
case component_integral
X : Scheme
inst✝ : IsReduced X
H : IrreducibleSpace ↑↑X.toPresheafedSpace
U : Opens ↑↑X.toPresheafedSpace
hU : Nonempty ↥U
this : ∃ x y, x ≠ y
⊢ IsDomain ↑(X.presheaf.obj (op U))

Next tactic:
have : NoZeroDivisors
      (X.toLocallyRingedSpace.toSheafedSpace.toPresheafedSpace.presheaf.obj (op U)) := by
    refine' ⟨fun {a b} e => _⟩
    simp_rw [← basicOpen_eq_bot_iff, ← Opens.not_nonempty_iff_eq_bot]
    by_contra! h
    obtain ⟨_, ⟨x, hx₁, rfl⟩, ⟨x, hx₂, e'⟩⟩ :=
      nonempty_preirreducible_inter (X.basicOpen a).2 (X.basicOpen b).2 h.1 h.2
    replace e' := Subtype.eq e'
    subst e'
    replace e := congr_arg (X.presheaf.germ x) e
    rw [RingHom.map_mul, RingHom.map_zero] at e
    refine' zero_ne_one' (X.presheaf.stalk x.1) (isUnit_zero_iff.1 _)
    convert hx₁.mul hx₂
    exact e.symm
theorem isIntegralOfIsIrreducibleIsReduced [IsReduced X] [H : IrreducibleSpace X.carrier] :
    IsIntegral X := by
  constructor; · infer_instance
  intro U hU
  haveI := (@LocallyRingedSpace.component_nontrivial X.toLocallyRingedSpace U hU).1
  have : NoZeroDivisors
      (X.toLocallyRingedSpace.toSheafedSpace.toPresheafedSpace.presheaf.obj (op U)) := by
    

Proof state:
X : Scheme
inst✝ : IsReduced X
H : IrreducibleSpace ↑↑X.toPresheafedSpace
U : Opens ↑↑X.toPresheafedSpace
hU : Nonempty ↥U
this : ∃ x y, x ≠ y
⊢ NoZeroDivisors ↑(X.presheaf.obj (op U))

Next tactic:
refine' ⟨fun {a b} e => _⟩
theorem isIntegralOfIsIrreducibleIsReduced [IsReduced X] [H : IrreducibleSpace X.carrier] :
    IsIntegral X := by
  constructor; · infer_instance
  intro U hU
  haveI := (@LocallyRingedSpace.component_nontrivial X.toLocallyRingedSpace U hU).1
  have : NoZeroDivisors
      (X.toLocallyRingedSpace.toSheafedSpace.toPresheafedSpace.presheaf.obj (op U)) := by
    refine' ⟨fun {a b} e => _⟩
    

Proof state:
X : Scheme
inst✝ : IsReduced X
H : IrreducibleSpace ↑↑X.toPresheafedSpace
U : Opens ↑↑X.toPresheafedSpace
hU : Nonempty ↥U
this : ∃ x y, x ≠ y
a b : ↑(X.presheaf.obj (op U))
e : a * b = 0
⊢ a = 0 ∨ b = 0

Next tactic:
simp_rw [← basicOpen_eq_bot_iff, ← Opens.not_nonempty_iff_eq_bot]
theorem isIntegralOfIsIrreducibleIsReduced [IsReduced X] [H : IrreducibleSpace X.carrier] :
    IsIntegral X := by
  constructor; · infer_instance
  intro U hU
  haveI := (@LocallyRingedSpace.component_nontrivial X.toLocallyRingedSpace U hU).1
  have : NoZeroDivisors
      (X.toLocallyRingedSpace.toSheafedSpace.toPresheafedSpace.presheaf.obj (op U)) := by
    refine' ⟨fun {a b} e => _⟩
    simp_rw [← basicOpen_eq_bot_iff, ← Opens.not_nonempty_iff_eq_bot]
    

Proof state:
X : Scheme
inst✝ : IsReduced X
H : IrreducibleSpace ↑↑X.toPresheafedSpace
U : Opens ↑↑X.toPresheafedSpace
hU : Nonempty ↥U
this : ∃ x y, x ≠ y
a b : ↑(X.presheaf.obj (op U))
e : a * b = 0
⊢ ¬Set.Nonempty ↑(X.basicOpen a) ∨ ¬Set.Nonempty ↑(X.basicOpen b)

Next tactic:
by_contra! h