l3lab/ntp-mathlib huggingface dataset:
theorem opensFunctor_map_basicOpen :
    hU.fromSpec.opensFunctor.obj (PrimeSpectrum.basicOpen f) = X.basicOpen f := by
  rw [← hU.fromSpec_map_basicOpen]
  ext1
  change hU.fromSpec.val.base '' (hU.fromSpec.val.base ⁻¹' (X.basicOpen f : Set X)) = _
  

Proof state:
case h
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
⊢ ⇑(fromSpec hU).val.base '' (⇑(fromSpec hU).val.base ⁻¹' ↑(X.basicOpen f)) = ↑(X.basicOpen f)

Next tactic:
rw [Set.image_preimage_eq_inter_range, Set.inter_eq_left, hU.fromSpec_range]
theorem opensFunctor_map_basicOpen :
    hU.fromSpec.opensFunctor.obj (PrimeSpectrum.basicOpen f) = X.basicOpen f := by
  rw [← hU.fromSpec_map_basicOpen]
  ext1
  change hU.fromSpec.val.base '' (hU.fromSpec.val.base ⁻¹' (X.basicOpen f : Set X)) = _
  rw [Set.image_preimage_eq_inter_range, Set.inter_eq_left, hU.fromSpec_range]
  

Proof state:
case h
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
⊢ ↑(X.basicOpen f) ⊆ ↑U

Next tactic:
exact Scheme.basicOpen_le _ _
@[simp, nolint simpNF]
theorem basicOpen_fromSpec_app :
    (𝖲𝗉𝖾𝖼 𝓞ₓ(U)).basicOpen (hU.fromSpec.1.c.app (op U) f) =
      PrimeSpectrum.basicOpen f := by
  

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
⊢ (Scheme.Spec.obj (op (X.presheaf.obj (op U)))).basicOpen (((fromSpec hU).val.c.app (op U)) f) =
    PrimeSpectrum.basicOpen f

Next tactic:
rw [← hU.fromSpec_map_basicOpen, Scheme.preimage_basicOpen]
theorem basicOpenIsAffine :
    IsAffineOpen (X.basicOpen f) := by
  

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
⊢ IsAffineOpen (X.basicOpen f)

Next tactic:
rw [← hU.opensFunctor_map_basicOpen, Scheme.Hom.isAffineOpen_iff_of_isOpenImmersion]
theorem basicOpenIsAffine :
    IsAffineOpen (X.basicOpen f) := by
  rw [← hU.opensFunctor_map_basicOpen, Scheme.Hom.isAffineOpen_iff_of_isOpenImmersion]
  

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
⊢ IsAffineOpen (PrimeSpectrum.basicOpen f)

Next tactic:
convert rangeIsAffineOpenOfOpenImmersion (Scheme.Spec.map
    (CommRingCat.ofHom <| algebraMap (X.presheaf.obj (op U)) (Localization.Away f)).op)
theorem basicOpenIsAffine :
    IsAffineOpen (X.basicOpen f) := by
  rw [← hU.opensFunctor_map_basicOpen, Scheme.Hom.isAffineOpen_iff_of_isOpenImmersion]
  convert rangeIsAffineOpenOfOpenImmersion (Scheme.Spec.map
    (CommRingCat.ofHom <| algebraMap (X.presheaf.obj (op U)) (Localization.Away f)).op)
  

Proof state:
case h.e'_2.h
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
e_1✝ : Scheme.Spec.obj (op (X.presheaf.obj (op U))) = Scheme.Spec.obj (op (CommRingCat.of ↑(X.presheaf.obj (op U))))
⊢ PrimeSpectrum.basicOpen f =
    Scheme.Hom.opensRange
      (Scheme.Spec.map (CommRingCat.ofHom (algebraMap (↑(X.presheaf.obj (op U))) (Localization.Away f))).op)

Next tactic:
exact Opens.ext (PrimeSpectrum.localization_away_comap_range (Localization.Away f) f).symm
theorem mapRestrictBasicOpen (r : X.presheaf.obj (op ⊤)) :
    IsAffineOpen (Scheme.ιOpens (X.basicOpen r) ⁻¹ᵁ U) := by
  

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
r : ↑(X.presheaf.obj (op ⊤))
⊢ IsAffineOpen (Scheme.ιOpens (X.basicOpen r)⁻¹ᵁ U)

Next tactic:
apply (Scheme.ιOpens (X.basicOpen r)).isAffineOpen_iff_of_isOpenImmersion.mp
theorem mapRestrictBasicOpen (r : X.presheaf.obj (op ⊤)) :
    IsAffineOpen (Scheme.ιOpens (X.basicOpen r) ⁻¹ᵁ U) := by
  apply (Scheme.ιOpens (X.basicOpen r)).isAffineOpen_iff_of_isOpenImmersion.mp
  

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
r : ↑(X.presheaf.obj (op ⊤))
⊢ IsAffineOpen ((Scheme.Hom.opensFunctor (Scheme.ιOpens (X.basicOpen r))).obj (Scheme.ιOpens (X.basicOpen r)⁻¹ᵁ U))

Next tactic:
dsimp [Scheme.Hom.opensFunctor, PresheafedSpace.IsOpenImmersion.openFunctor]
theorem mapRestrictBasicOpen (r : X.presheaf.obj (op ⊤)) :
    IsAffineOpen (Scheme.ιOpens (X.basicOpen r) ⁻¹ᵁ U) := by
  apply (Scheme.ιOpens (X.basicOpen r)).isAffineOpen_iff_of_isOpenImmersion.mp
  dsimp [Scheme.Hom.opensFunctor, PresheafedSpace.IsOpenImmersion.openFunctor]
  

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
r : ↑(X.presheaf.obj (op ⊤))
⊢ IsAffineOpen
    ((IsOpenMap.functor (_ : IsOpenMap ⇑(Scheme.ιOpens (X.basicOpen r)).val.base)).obj
      ((Opens.map (Opens.inclusion (X.basicOpen r))).obj U))

Next tactic:
rw [Opens.functor_obj_map_obj, Opens.openEmbedding_obj_top, inf_comm,
    ← Scheme.basicOpen_res _ _ (homOfLE le_top).op]
theorem mapRestrictBasicOpen (r : X.presheaf.obj (op ⊤)) :
    IsAffineOpen (Scheme.ιOpens (X.basicOpen r) ⁻¹ᵁ U) := by
  apply (Scheme.ιOpens (X.basicOpen r)).isAffineOpen_iff_of_isOpenImmersion.mp
  dsimp [Scheme.Hom.opensFunctor, PresheafedSpace.IsOpenImmersion.openFunctor]
  rw [Opens.functor_obj_map_obj, Opens.openEmbedding_obj_top, inf_comm,
    ← Scheme.basicOpen_res _ _ (homOfLE le_top).op]
  

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
r : ↑(X.presheaf.obj (op ⊤))
⊢ IsAffineOpen (X.basicOpen ((X.presheaf.map (homOfLE (_ : U ≤ ⊤)).op) r))

Next tactic:
exact hU.basicOpenIsAffine _
theorem exists_basicOpen_le {V : Opens X} (x : V) (h : ↑x ∈ U) :
    ∃ f : X.presheaf.obj (op U), X.basicOpen f ≤ V ∧ ↑x ∈ X.basicOpen f := by
  

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
V : Opens ↑↑X.toPresheafedSpace
x : ↥V
h : ↑x ∈ U
⊢ ∃ f, X.basicOpen f ≤ V ∧ ↑x ∈ X.basicOpen f

Next tactic:
have : IsAffine _ := hU
theorem exists_basicOpen_le {V : Opens X} (x : V) (h : ↑x ∈ U) :
    ∃ f : X.presheaf.obj (op U), X.basicOpen f ≤ V ∧ ↑x ∈ X.basicOpen f := by
  have : IsAffine _ := hU
  

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
V : Opens ↑↑X.toPresheafedSpace
x : ↥V
h : ↑x ∈ U
this : IsAffine (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)))
⊢ ∃ f, X.basicOpen f ≤ V ∧ ↑x ∈ X.basicOpen f

Next tactic:
obtain ⟨_, ⟨_, ⟨r, rfl⟩, rfl⟩, h₁, h₂⟩ :=
    (isBasis_basicOpen (X ∣_ᵤ U)).exists_subset_of_mem_open (x.2 : ⟨x, h⟩ ∈ _)
      ((Opens.map U.inclusion).obj V).isOpen
theorem exists_basicOpen_le {V : Opens X} (x : V) (h : ↑x ∈ U) :
    ∃ f : X.presheaf.obj (op U), X.basicOpen f ≤ V ∧ ↑x ∈ X.basicOpen f := by
  have : IsAffine _ := hU
  obtain ⟨_, ⟨_, ⟨r, rfl⟩, rfl⟩, h₁, h₂⟩ :=
    (isBasis_basicOpen (X ∣_ᵤ U)).exists_subset_of_mem_open (x.2 : ⟨x, h⟩ ∈ _)
      ((Opens.map U.inclusion).obj V).isOpen
  

Proof state:
case intro.intro.intro.intro.intro.intro
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
V : Opens ↑↑X.toPresheafedSpace
x : ↥V
h : ↑x ∈ U
this : IsAffine (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)))
r : ↑((X ∣_ᵤ U).toLocallyRingedSpace.toSheafedSpace.toPresheafedSpace.presheaf.obj (op ⊤))
h₁ : { val := ↑x, property := h } ∈ ↑((X ∣_ᵤ U).basicOpen r)
h₂ : ↑((X ∣_ᵤ U).basicOpen r) ⊆ ↑((Opens.map (Opens.inclusion U)).obj V)
⊢ ∃ f, X.basicOpen f ≤ V ∧ ↑x ∈ X.basicOpen f

Next tactic:
have :
    U.openEmbedding.isOpenMap.functor.obj ((X ∣_ᵤ U).basicOpen r) =
      X.basicOpen (X.presheaf.map (eqToHom U.openEmbedding_obj_top.symm).op r) := by
    refine' (Scheme.image_basicOpen (X.ofRestrict U.openEmbedding) r).trans _
    rw [← Scheme.basicOpen_res_eq _ _ (eqToHom U.openEmbedding_obj_top).op,
      ← comp_apply, ← CategoryTheory.Functor.map_comp, ← op_comp, eqToHom_trans, eqToHom_refl,
      op_id, CategoryTheory.Functor.map_id, Scheme.Hom.invApp,
      PresheafedSpace.IsOpenImmersion.ofRestrict_invApp]
    congr
theorem exists_basicOpen_le {V : Opens X} (x : V) (h : ↑x ∈ U) :
    ∃ f : X.presheaf.obj (op U), X.basicOpen f ≤ V ∧ ↑x ∈ X.basicOpen f := by
  have : IsAffine _ := hU
  obtain ⟨_, ⟨_, ⟨r, rfl⟩, rfl⟩, h₁, h₂⟩ :=
    (isBasis_basicOpen (X ∣_ᵤ U)).exists_subset_of_mem_open (x.2 : ⟨x, h⟩ ∈ _)
      ((Opens.map U.inclusion).obj V).isOpen
  have :
    U.openEmbedding.isOpenMap.functor.obj ((X ∣_ᵤ U).basicOpen r) =
      X.basicOpen (X.presheaf.map (eqToHom U.openEmbedding_obj_top.symm).op r) := by
    

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
V : Opens ↑↑X.toPresheafedSpace
x : ↥V
h : ↑x ∈ U
this : IsAffine (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)))
r : ↑((X ∣_ᵤ U).toLocallyRingedSpace.toSheafedSpace.toPresheafedSpace.presheaf.obj (op ⊤))
h₁ : { val := ↑x, property := h } ∈ ↑((X ∣_ᵤ U).basicOpen r)
h₂ : ↑((X ∣_ᵤ U).basicOpen r) ⊆ ↑((Opens.map (Opens.inclusion U)).obj V)
⊢ (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ((X ∣_ᵤ U).basicOpen r) =
    X.basicOpen
      ((X.presheaf.map (eqToHom (_ : U = (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤)).op) r)

Next tactic:
refine' (Scheme.image_basicOpen (X.ofRestrict U.openEmbedding) r).trans _
theorem exists_basicOpen_le {V : Opens X} (x : V) (h : ↑x ∈ U) :
    ∃ f : X.presheaf.obj (op U), X.basicOpen f ≤ V ∧ ↑x ∈ X.basicOpen f := by
  have : IsAffine _ := hU
  obtain ⟨_, ⟨_, ⟨r, rfl⟩, rfl⟩, h₁, h₂⟩ :=
    (isBasis_basicOpen (X ∣_ᵤ U)).exists_subset_of_mem_open (x.2 : ⟨x, h⟩ ∈ _)
      ((Opens.map U.inclusion).obj V).isOpen
  have :
    U.openEmbedding.isOpenMap.functor.obj ((X ∣_ᵤ U).basicOpen r) =
      X.basicOpen (X.presheaf.map (eqToHom U.openEmbedding_obj_top.symm).op r) := by
    refine' (Scheme.image_basicOpen (X.ofRestrict U.openEmbedding) r).trans _
    

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
V : Opens ↑↑X.toPresheafedSpace
x : ↥V
h : ↑x ∈ U
this : IsAffine (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)))
r : ↑((X ∣_ᵤ U).toLocallyRingedSpace.toSheafedSpace.toPresheafedSpace.presheaf.obj (op ⊤))
h₁ : { val := ↑x, property := h } ∈ ↑((X ∣_ᵤ U).basicOpen r)
h₂ : ↑((X ∣_ᵤ U).basicOpen r) ⊆ ↑((Opens.map (Opens.inclusion U)).obj V)
⊢ X.basicOpen ((Scheme.Hom.invApp (Scheme.ofRestrict X (_ : OpenEmbedding ⇑(Opens.inclusion U))) ⊤) r) =
    X.basicOpen
      ((X.presheaf.map (eqToHom (_ : U = (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤)).op) r)

Next tactic:
rw [← Scheme.basicOpen_res_eq _ _ (eqToHom U.openEmbedding_obj_top).op,
      ← comp_apply, ← CategoryTheory.Functor.map_comp, ← op_comp, eqToHom_trans, eqToHom_refl,
      op_id, CategoryTheory.Functor.map_id, Scheme.Hom.invApp,
      PresheafedSpace.IsOpenImmersion.ofRestrict_invApp]
theorem exists_basicOpen_le {V : Opens X} (x : V) (h : ↑x ∈ U) :
    ∃ f : X.presheaf.obj (op U), X.basicOpen f ≤ V ∧ ↑x ∈ X.basicOpen f := by
  have : IsAffine _ := hU
  obtain ⟨_, ⟨_, ⟨r, rfl⟩, rfl⟩, h₁, h₂⟩ :=
    (isBasis_basicOpen (X ∣_ᵤ U)).exists_subset_of_mem_open (x.2 : ⟨x, h⟩ ∈ _)
      ((Opens.map U.inclusion).obj V).isOpen
  have :
    U.openEmbedding.isOpenMap.functor.obj ((X ∣_ᵤ U).basicOpen r) =
      X.basicOpen (X.presheaf.map (eqToHom U.openEmbedding_obj_top.symm).op r) := by
    refine' (Scheme.image_basicOpen (X.ofRestrict U.openEmbedding) r).trans _
    rw [← Scheme.basicOpen_res_eq _ _ (eqToHom U.openEmbedding_obj_top).op,
      ← comp_apply, ← CategoryTheory.Functor.map_comp, ← op_comp, eqToHom_trans, eqToHom_refl,
      op_id, CategoryTheory.Functor.map_id, Scheme.Hom.invApp,
      PresheafedSpace.IsOpenImmersion.ofRestrict_invApp]
    

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
V : Opens ↑↑X.toPresheafedSpace
x : ↥V
h : ↑x ∈ U
this : IsAffine (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)))
r : ↑((X ∣_ᵤ U).toLocallyRingedSpace.toSheafedSpace.toPresheafedSpace.presheaf.obj (op ⊤))
h₁ : { val := ↑x, property := h } ∈ ↑((X ∣_ᵤ U).basicOpen r)
h₂ : ↑((X ∣_ᵤ U).basicOpen r) ⊆ ↑((Opens.map (Opens.inclusion U)).obj V)
⊢ X.basicOpen
      ((𝟙 ((PresheafedSpace.restrict X.toPresheafedSpace (_ : OpenEmbedding ⇑(Opens.inclusion U))).presheaf.obj (op ⊤)))
        r) =
    X.basicOpen ((𝟙 (X.presheaf.obj (op ((IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤)))) r)

Next tactic:
congr
theorem exists_basicOpen_le {V : Opens X} (x : V) (h : ↑x ∈ U) :
    ∃ f : X.presheaf.obj (op U), X.basicOpen f ≤ V ∧ ↑x ∈ X.basicOpen f := by
  have : IsAffine _ := hU
  obtain ⟨_, ⟨_, ⟨r, rfl⟩, rfl⟩, h₁, h₂⟩ :=
    (isBasis_basicOpen (X ∣_ᵤ U)).exists_subset_of_mem_open (x.2 : ⟨x, h⟩ ∈ _)
      ((Opens.map U.inclusion).obj V).isOpen
  have :
    U.openEmbedding.isOpenMap.functor.obj ((X ∣_ᵤ U).basicOpen r) =
      X.basicOpen (X.presheaf.map (eqToHom U.openEmbedding_obj_top.symm).op r) := by
    refine' (Scheme.image_basicOpen (X.ofRestrict U.openEmbedding) r).trans _
    rw [← Scheme.basicOpen_res_eq _ _ (eqToHom U.openEmbedding_obj_top).op,
      ← comp_apply, ← CategoryTheory.Functor.map_comp, ← op_comp, eqToHom_trans, eqToHom_refl,
      op_id, CategoryTheory.Functor.map_id, Scheme.Hom.invApp,
      PresheafedSpace.IsOpenImmersion.ofRestrict_invApp]
    congr
  

Proof state:
case intro.intro.intro.intro.intro.intro
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
V : Opens ↑↑X.toPresheafedSpace
x : ↥V
h : ↑x ∈ U
this✝ : IsAffine (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)))
r : ↑((X ∣_ᵤ U).toLocallyRingedSpace.toSheafedSpace.toPresheafedSpace.presheaf.obj (op ⊤))
h₁ : { val := ↑x, property := h } ∈ ↑((X ∣_ᵤ U).basicOpen r)
h₂ : ↑((X ∣_ᵤ U).basicOpen r) ⊆ ↑((Opens.map (Opens.inclusion U)).obj V)
this :
  (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ((X ∣_ᵤ U).basicOpen r) =
    X.basicOpen
      ((X.presheaf.map (eqToHom (_ : U = (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤)).op) r)
⊢ ∃ f, X.basicOpen f ≤ V ∧ ↑x ∈ X.basicOpen f

Next tactic:
use X.presheaf.map (eqToHom U.openEmbedding_obj_top.symm).op r
theorem exists_basicOpen_le {V : Opens X} (x : V) (h : ↑x ∈ U) :
    ∃ f : X.presheaf.obj (op U), X.basicOpen f ≤ V ∧ ↑x ∈ X.basicOpen f := by
  have : IsAffine _ := hU
  obtain ⟨_, ⟨_, ⟨r, rfl⟩, rfl⟩, h₁, h₂⟩ :=
    (isBasis_basicOpen (X ∣_ᵤ U)).exists_subset_of_mem_open (x.2 : ⟨x, h⟩ ∈ _)
      ((Opens.map U.inclusion).obj V).isOpen
  have :
    U.openEmbedding.isOpenMap.functor.obj ((X ∣_ᵤ U).basicOpen r) =
      X.basicOpen (X.presheaf.map (eqToHom U.openEmbedding_obj_top.symm).op r) := by
    refine' (Scheme.image_basicOpen (X.ofRestrict U.openEmbedding) r).trans _
    rw [← Scheme.basicOpen_res_eq _ _ (eqToHom U.openEmbedding_obj_top).op,
      ← comp_apply, ← CategoryTheory.Functor.map_comp, ← op_comp, eqToHom_trans, eqToHom_refl,
      op_id, CategoryTheory.Functor.map_id, Scheme.Hom.invApp,
      PresheafedSpace.IsOpenImmersion.ofRestrict_invApp]
    congr
  use X.presheaf.map (eqToHom U.openEmbedding_obj_top.symm).op r
  

Proof state:
case h
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
V : Opens ↑↑X.toPresheafedSpace
x : ↥V
h : ↑x ∈ U
this✝ : IsAffine (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)))
r : ↑((X ∣_ᵤ U).toLocallyRingedSpace.toSheafedSpace.toPresheafedSpace.presheaf.obj (op ⊤))
h₁ : { val := ↑x, property := h } ∈ ↑((X ∣_ᵤ U).basicOpen r)
h₂ : ↑((X ∣_ᵤ U).basicOpen r) ⊆ ↑((Opens.map (Opens.inclusion U)).obj V)
this :
  (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ((X ∣_ᵤ U).basicOpen r) =
    X.basicOpen
      ((X.presheaf.map (eqToHom (_ : U = (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤)).op) r)
⊢ X.basicOpen
        ((X.presheaf.map (eqToHom (_ : U = (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤)).op) r) ≤
      V ∧
    ↑x ∈
      X.basicOpen
        ((X.presheaf.map (eqToHom (_ : U = (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤)).op) r)

Next tactic:
rw [← this]
theorem exists_basicOpen_le {V : Opens X} (x : V) (h : ↑x ∈ U) :
    ∃ f : X.presheaf.obj (op U), X.basicOpen f ≤ V ∧ ↑x ∈ X.basicOpen f := by
  have : IsAffine _ := hU
  obtain ⟨_, ⟨_, ⟨r, rfl⟩, rfl⟩, h₁, h₂⟩ :=
    (isBasis_basicOpen (X ∣_ᵤ U)).exists_subset_of_mem_open (x.2 : ⟨x, h⟩ ∈ _)
      ((Opens.map U.inclusion).obj V).isOpen
  have :
    U.openEmbedding.isOpenMap.functor.obj ((X ∣_ᵤ U).basicOpen r) =
      X.basicOpen (X.presheaf.map (eqToHom U.openEmbedding_obj_top.symm).op r) := by
    refine' (Scheme.image_basicOpen (X.ofRestrict U.openEmbedding) r).trans _
    rw [← Scheme.basicOpen_res_eq _ _ (eqToHom U.openEmbedding_obj_top).op,
      ← comp_apply, ← CategoryTheory.Functor.map_comp, ← op_comp, eqToHom_trans, eqToHom_refl,
      op_id, CategoryTheory.Functor.map_id, Scheme.Hom.invApp,
      PresheafedSpace.IsOpenImmersion.ofRestrict_invApp]
    congr
  use X.presheaf.map (eqToHom U.openEmbedding_obj_top.symm).op r
  rw [← this]
  

Proof state:
case h
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
V : Opens ↑↑X.toPresheafedSpace
x : ↥V
h : ↑x ∈ U
this✝ : IsAffine (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)))
r : ↑((X ∣_ᵤ U).toLocallyRingedSpace.toSheafedSpace.toPresheafedSpace.presheaf.obj (op ⊤))
h₁ : { val := ↑x, property := h } ∈ ↑((X ∣_ᵤ U).basicOpen r)
h₂ : ↑((X ∣_ᵤ U).basicOpen r) ⊆ ↑((Opens.map (Opens.inclusion U)).obj V)
this :
  (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ((X ∣_ᵤ U).basicOpen r) =
    X.basicOpen
      ((X.presheaf.map (eqToHom (_ : U = (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤)).op) r)
⊢ (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ((X ∣_ᵤ U).basicOpen r) ≤ V ∧
    ↑x ∈ (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ((X ∣_ᵤ U).basicOpen r)

Next tactic:
exact ⟨Set.image_subset_iff.mpr h₂, ⟨_, h⟩, h₁, rfl⟩
instance basicOpenSectionsToAffine_isIso :
    IsIso (basicOpenSectionsToAffine hU f) := by
  

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
⊢ IsIso (basicOpenSectionsToAffine hU f)

Next tactic:
delta basicOpenSectionsToAffine
instance basicOpenSectionsToAffine_isIso :
    IsIso (basicOpenSectionsToAffine hU f) := by
  delta basicOpenSectionsToAffine
  

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
⊢ IsIso
    ((fromSpec hU).val.c.app (op (X.basicOpen f)) ≫
      (Scheme.Spec.obj (op (X.presheaf.obj (op U)))).presheaf.map
        (eqToHom (_ : PrimeSpectrum.basicOpen f = fromSpec hU⁻¹ᵁ X.basicOpen f)).op)

Next tactic:
apply (config := { allowSynthFailures := true }) IsIso.comp_isIso
instance basicOpenSectionsToAffine_isIso :
    IsIso (basicOpenSectionsToAffine hU f) := by
  delta basicOpenSectionsToAffine
  apply (config := { allowSynthFailures := true }) IsIso.comp_isIso
  

Proof state:
case inst
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
⊢ IsIso ((fromSpec hU).val.c.app (op (X.basicOpen f)))

Next tactic:
apply PresheafedSpace.IsOpenImmersion.isIso_of_subset
instance basicOpenSectionsToAffine_isIso :
    IsIso (basicOpenSectionsToAffine hU f) := by
  delta basicOpenSectionsToAffine
  apply (config := { allowSynthFailures := true }) IsIso.comp_isIso
  apply PresheafedSpace.IsOpenImmersion.isIso_of_subset
  

Proof state:
case inst.hU
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
⊢ ↑(X.basicOpen f) ⊆ Set.range ⇑(fromSpec hU).val.base

Next tactic:
rw [hU.fromSpec_range]
instance basicOpenSectionsToAffine_isIso :
    IsIso (basicOpenSectionsToAffine hU f) := by
  delta basicOpenSectionsToAffine
  apply (config := { allowSynthFailures := true }) IsIso.comp_isIso
  apply PresheafedSpace.IsOpenImmersion.isIso_of_subset
  rw [hU.fromSpec_range]
  

Proof state:
case inst.hU
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
⊢ ↑(X.basicOpen f) ⊆ ↑U

Next tactic:
exact RingedSpace.basicOpen_le _ _
theorem isLocalization_basicOpen :
    IsLocalization.Away f (X.presheaf.obj (op <| X.basicOpen f)) := by
  

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
⊢ IsLocalization.Away f ↑(X.presheaf.obj (op (X.basicOpen f)))

Next tactic:
apply
    (IsLocalization.isLocalization_iff_of_ringEquiv (Submonoid.powers f)
      (asIso <| basicOpenSectionsToAffine hU f).commRingCatIsoToRingEquiv).mpr
theorem isLocalization_basicOpen :
    IsLocalization.Away f (X.presheaf.obj (op <| X.basicOpen f)) := by
  apply
    (IsLocalization.isLocalization_iff_of_ringEquiv (Submonoid.powers f)
      (asIso <| basicOpenSectionsToAffine hU f).commRingCatIsoToRingEquiv).mpr
  

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
⊢ IsLocalization (Submonoid.powers f)
    ↑((Scheme.Spec.obj (op (X.presheaf.obj (op U)))).presheaf.obj (op (PrimeSpectrum.basicOpen f)))

Next tactic:
convert StructureSheaf.IsLocalization.to_basicOpen _ f using 1
theorem isLocalization_basicOpen :
    IsLocalization.Away f (X.presheaf.obj (op <| X.basicOpen f)) := by
  apply
    (IsLocalization.isLocalization_iff_of_ringEquiv (Submonoid.powers f)
      (asIso <| basicOpenSectionsToAffine hU f).commRingCatIsoToRingEquiv).mpr
  convert StructureSheaf.IsLocalization.to_basicOpen _ f using 1
  -- Porting note : more hand holding is required here, the next 4 lines were not necessary
  

Proof state:
case h.e'_3.h.h
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
e_1✝ :
  ↑((Scheme.Spec.obj (op (X.presheaf.obj (op U)))).presheaf.obj (op (PrimeSpectrum.basicOpen f))) =
    ↑((structureSheaf ↑(X.presheaf.obj (op U))).val.obj (op (PrimeSpectrum.basicOpen f)))
he✝ : CommRing.toCommSemiring = CommRing.toCommSemiring
⊢ RingHom.toAlgebra
      (RingHom.comp (RingEquiv.toRingHom (Iso.commRingCatIsoToRingEquiv (asIso (basicOpenSectionsToAffine hU f))))
        (algebraMap ↑(X.presheaf.obj (op U)) ↑(X.presheaf.obj (op (X.basicOpen f))))) =
    StructureSheaf.openAlgebra (↑(X.presheaf.obj (op U))) (op (PrimeSpectrum.basicOpen f))

Next tactic:
delta StructureSheaf.openAlgebra
theorem isLocalization_basicOpen :
    IsLocalization.Away f (X.presheaf.obj (op <| X.basicOpen f)) := by
  apply
    (IsLocalization.isLocalization_iff_of_ringEquiv (Submonoid.powers f)
      (asIso <| basicOpenSectionsToAffine hU f).commRingCatIsoToRingEquiv).mpr
  convert StructureSheaf.IsLocalization.to_basicOpen _ f using 1
  -- Porting note : more hand holding is required here, the next 4 lines were not necessary
  delta StructureSheaf.openAlgebra
  

Proof state:
case h.e'_3.h.h
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
e_1✝ :
  ↑((Scheme.Spec.obj (op (X.presheaf.obj (op U)))).presheaf.obj (op (PrimeSpectrum.basicOpen f))) =
    ↑((structureSheaf ↑(X.presheaf.obj (op U))).val.obj (op (PrimeSpectrum.basicOpen f)))
he✝ : CommRing.toCommSemiring = CommRing.toCommSemiring
⊢ RingHom.toAlgebra
      (RingHom.comp (RingEquiv.toRingHom (Iso.commRingCatIsoToRingEquiv (asIso (basicOpenSectionsToAffine hU f))))
        (algebraMap ↑(X.presheaf.obj (op U)) ↑(X.presheaf.obj (op (X.basicOpen f))))) =
    RingHom.toAlgebra (StructureSheaf.toOpen (↑(X.presheaf.obj (op U))) (op (PrimeSpectrum.basicOpen f)).unop)

Next tactic:
congr 1