l3lab/ntp-mathlib huggingface dataset:
/-- The functions satisfying `isLocallyFraction` form a subring.
-/
def sectionsSubring (U : (Opens (PrimeSpectrum.Top R))ᵒᵖ) :
    Subring (∀ x : U.unop, Localizations R x) where
  carrier := { f | (isLocallyFraction R).pred f }
  zero_mem' := by
    refine' fun x => ⟨unop U, x.2, 𝟙 _, 0, 1, fun y => ⟨_, _⟩⟩
    · rw [← Ideal.ne_top_iff_one]; exact y.1.IsPrime.1
    · 

Proof state:
case refine'_2
R : Type u
inst✝ : CommRing R
U : (Opens ↑(PrimeSpectrum.Top R))ᵒᵖ
x y : ↥U.unop
⊢ (fun x => OfNat.ofNat 0 ((fun x => { val := ↑x, property := (_ : ↑x ∈ ↑U.unop) }) x)) y *
      (algebraMap R (Localizations R ↑y)) 1 =
    (algebraMap R (Localizations R ↑y)) 0

Next tactic:
simp
theorem const_zero (f : R) (U hu) : const R 0 f U hu = 0 :=
  Subtype.eq <| funext fun x => IsLocalization.mk'_eq_iff_eq_mul.2 <| by
    

Proof state:
R : Type u
inst✝ : CommRing R
f : R
U : Opens ↑(PrimeSpectrum.Top R)
hu : ∀ x ∈ U, f ∈ Ideal.primeCompl x.asIdeal
x : ↥(op U).unop
⊢ (algebraMap R (Localizations R ↑x)) 0 =
    ↑0 x * (algebraMap R (Localizations R ↑x)) ↑{ val := f, property := (_ : f ∈ Ideal.primeCompl (↑x).asIdeal) }

Next tactic:
erw [RingHom.map_zero, Subring.coe_zero, Pi.zero_apply, zero_mul]
theorem const_mul (f₁ f₂ g₁ g₂ : R) (U hu₁ hu₂) :
    const R f₁ g₁ U hu₁ * const R f₂ g₂ U hu₂ =
      const R (f₁ * f₂) (g₁ * g₂) U fun x hx => Submonoid.mul_mem _ (hu₁ x hx) (hu₂ x hx) :=
  Subtype.eq <|
    funext fun x =>
      Eq.symm <| by 

Proof state:
R : Type u
inst✝ : CommRing R
f₁ f₂ g₁ g₂ : R
U : Opens ↑(PrimeSpectrum.Top R)
hu₁ : ∀ x ∈ U, g₁ ∈ Ideal.primeCompl x.asIdeal
hu₂ : ∀ x ∈ U, g₂ ∈ Ideal.primeCompl x.asIdeal
x : ↥(op U).unop
⊢ ↑(const R (f₁ * f₂) (g₁ * g₂) U (_ : ∀ x ∈ U, g₁ * g₂ ∈ Ideal.primeCompl x.asIdeal)) x =
    ↑(const R f₁ g₁ U hu₁ * const R f₂ g₂ U hu₂) x

Next tactic:
convert IsLocalization.mk'_mul _ f₁ f₂ ⟨g₁, hu₁ x x.2⟩ ⟨g₂, hu₂ x x.2⟩
theorem const_ext {f₁ f₂ g₁ g₂ : R} {U hu₁ hu₂} (h : f₁ * g₂ = f₂ * g₁) :
    const R f₁ g₁ U hu₁ = const R f₂ g₂ U hu₂ :=
  Subtype.eq <|
    funext fun x =>
      IsLocalization.mk'_eq_of_eq (by 

Proof state:
R : Type u
inst✝ : CommRing R
f₁ f₂ g₁ g₂ : R
U : Opens ↑(PrimeSpectrum.Top R)
hu₁ : ∀ x ∈ U, g₁ ∈ Ideal.primeCompl x.asIdeal
hu₂ : ∀ x ∈ U, g₂ ∈ Ideal.primeCompl x.asIdeal
h : f₁ * g₂ = f₂ * g₁
x : ↥(op U).unop
⊢ ↑{ val := g₁, property := (_ : g₁ ∈ Ideal.primeCompl (↑x).asIdeal) } * f₂ =
    ↑{ val := g₂, property := (_ : g₂ ∈ Ideal.primeCompl (↑x).asIdeal) } * f₁

Next tactic:
rw [mul_comm, Subtype.coe_mk, ← h, mul_comm, Subtype.coe_mk]
theorem const_congr {f₁ f₂ g₁ g₂ : R} {U hu} (hf : f₁ = f₂) (hg : g₁ = g₂) :
    const R f₁ g₁ U hu = const R f₂ g₂ U (hg ▸ hu) := by 

Proof state:
R : Type u
inst✝ : CommRing R
f₁ f₂ g₁ g₂ : R
U : Opens ↑(PrimeSpectrum.Top R)
hu : ∀ x ∈ U, g₁ ∈ Ideal.primeCompl x.asIdeal
hf : f₁ = f₂
hg : g₁ = g₂
⊢ const R f₁ g₁ U hu = const R f₂ g₂ U (_ : ∀ x ∈ U, g₂ ∈ Ideal.primeCompl x.asIdeal)

Next tactic:
substs hf hg
theorem const_congr {f₁ f₂ g₁ g₂ : R} {U hu} (hf : f₁ = f₂) (hg : g₁ = g₂) :
    const R f₁ g₁ U hu = const R f₂ g₂ U (hg ▸ hu) := by substs hf hg; 

Proof state:
R : Type u
inst✝ : CommRing R
f₁ g₁ : R
U : Opens ↑(PrimeSpectrum.Top R)
hu : ∀ x ∈ U, g₁ ∈ Ideal.primeCompl x.asIdeal
⊢ const R f₁ g₁ U hu = const R f₁ g₁ U (_ : ∀ x ∈ U, g₁ ∈ Ideal.primeCompl x.asIdeal)

Next tactic:
rfl
theorem const_mul_rev (f g : R) (U hu₁ hu₂) : const R f g U hu₁ * const R g f U hu₂ = 1 := by
  

Proof state:
R : Type u
inst✝ : CommRing R
f g : R
U : Opens ↑(PrimeSpectrum.Top R)
hu₁ : ∀ x ∈ U, g ∈ Ideal.primeCompl x.asIdeal
hu₂ : ∀ x ∈ U, f ∈ Ideal.primeCompl x.asIdeal
⊢ const R f g U hu₁ * const R g f U hu₂ = 1

Next tactic:
rw [const_mul, const_congr R rfl (mul_comm g f), const_self]
theorem const_mul_cancel (f g₁ g₂ : R) (U hu₁ hu₂) :
    const R f g₁ U hu₁ * const R g₁ g₂ U hu₂ = const R f g₂ U hu₂ := by
  

Proof state:
R : Type u
inst✝ : CommRing R
f g₁ g₂ : R
U : Opens ↑(PrimeSpectrum.Top R)
hu₁ : ∀ x ∈ U, g₁ ∈ Ideal.primeCompl x.asIdeal
hu₂ : ∀ x ∈ U, g₂ ∈ Ideal.primeCompl x.asIdeal
⊢ const R f g₁ U hu₁ * const R g₁ g₂ U hu₂ = const R f g₂ U hu₂

Next tactic:
rw [const_mul, const_ext]
theorem const_mul_cancel (f g₁ g₂ : R) (U hu₁ hu₂) :
    const R f g₁ U hu₁ * const R g₁ g₂ U hu₂ = const R f g₂ U hu₂ := by
  rw [const_mul, const_ext]; 

Proof state:
case h
R : Type u
inst✝ : CommRing R
f g₁ g₂ : R
U : Opens ↑(PrimeSpectrum.Top R)
hu₁ : ∀ x ∈ U, g₁ ∈ Ideal.primeCompl x.asIdeal
hu₂ : ∀ x ∈ U, g₂ ∈ Ideal.primeCompl x.asIdeal
⊢ f * g₁ * g₂ = f * (g₁ * g₂)

Next tactic:
rw [mul_assoc]
theorem const_mul_cancel' (f g₁ g₂ : R) (U hu₁ hu₂) :
    const R g₁ g₂ U hu₂ * const R f g₁ U hu₁ = const R f g₂ U hu₂ := by
  

Proof state:
R : Type u
inst✝ : CommRing R
f g₁ g₂ : R
U : Opens ↑(PrimeSpectrum.Top R)
hu₁ : ∀ x ∈ U, g₁ ∈ Ideal.primeCompl x.asIdeal
hu₂ : ∀ x ∈ U, g₂ ∈ Ideal.primeCompl x.asIdeal
⊢ const R g₁ g₂ U hu₂ * const R f g₁ U hu₁ = const R f g₂ U hu₂

Next tactic:
rw [mul_comm, const_mul_cancel]
/-- The canonical ring homomorphism interpreting an element of `R` as
a section of the structure sheaf. -/
def toOpen (U : Opens (PrimeSpectrum.Top R)) : CommRingCat.of R ⟶ (structureSheaf R).1.obj (op U)
    where
  toFun f :=
    ⟨fun x => algebraMap R _ f, fun x =>
      ⟨U, x.2, 𝟙 _, f, 1, fun y =>
        ⟨(Ideal.ne_top_iff_one _).1 y.1.2.1, by 

Proof state:
R : Type u
inst✝ : CommRing R
U : Opens ↑(PrimeSpectrum.Top R)
f : ↑(CommRingCat.of R)
x : ↥(op U).unop
y : ↥U
⊢ (fun x =>
          (fun x => (algebraMap R (Localizations R ↑x)) f)
            ((fun x => { val := ↑x, property := (_ : ↑x ∈ ↑(op U).unop) }) x))
        y *
      (algebraMap R (Localizations R ↑y)) 1 =
    (algebraMap R (Localizations R ↑y)) f

Next tactic:
rw [RingHom.map_one, mul_one]
/-- The canonical ring homomorphism interpreting an element of `R` as an element of
the stalk of `structureSheaf R` at `x`. -/
def toStalk (x : PrimeSpectrum.Top R) : CommRingCat.of R ⟶ (structureSheaf R).presheaf.stalk x :=
  (toOpen R ⊤ ≫ (structureSheaf R).presheaf.germ ⟨x, by 

Proof state:
R : Type u
inst✝ : CommRing R
x : ↑(PrimeSpectrum.Top R)
⊢ x ∈ ⊤

Next tactic:
trivial
@[simp]
theorem toOpen_germ (U : Opens (PrimeSpectrum.Top R)) (x : U) :
    toOpen R U ≫ (structureSheaf R).presheaf.germ x = toStalk R x := by
  

Proof state:
R : Type u
inst✝ : CommRing R
U : Opens ↑(PrimeSpectrum.Top R)
x : ↥U
⊢ toOpen R U ≫ germ (Sheaf.presheaf (structureSheaf R)) x = toStalk R ↑x

Next tactic:
rw [← toOpen_res R ⊤ U (homOfLE le_top : U ⟶ ⊤), Category.assoc, Presheaf.germ_res]
@[simp]
theorem toOpen_germ (U : Opens (PrimeSpectrum.Top R)) (x : U) :
    toOpen R U ≫ (structureSheaf R).presheaf.germ x = toStalk R x := by
  rw [← toOpen_res R ⊤ U (homOfLE le_top : U ⟶ ⊤), Category.assoc, Presheaf.germ_res]; 

Proof state:
R : Type u
inst✝ : CommRing R
U : Opens ↑(PrimeSpectrum.Top R)
x : ↥U
⊢ toOpen R ⊤ ≫ germ (structureSheaf R).val ((fun x => { val := ↑x, property := (_ : ↑x ∈ ↑⊤) }) x) = toStalk R ↑x

Next tactic:
rfl
@[simp]
theorem germ_toOpen (U : Opens (PrimeSpectrum.Top R)) (x : U) (f : R) :
    (structureSheaf R).presheaf.germ x (toOpen R U f) = toStalk R x f := by 

Proof state:
R : Type u
inst✝ : CommRing R
U : Opens ↑(PrimeSpectrum.Top R)
x : ↥U
f : R
⊢ (germ (Sheaf.presheaf (structureSheaf R)) x) ((toOpen R U) f) = (toStalk R ↑x) f

Next tactic:
rw [← toOpen_germ]
@[simp]
theorem germ_toOpen (U : Opens (PrimeSpectrum.Top R)) (x : U) (f : R) :
    (structureSheaf R).presheaf.germ x (toOpen R U f) = toStalk R x f := by rw [← toOpen_germ]; 

Proof state:
R : Type u
inst✝ : CommRing R
U : Opens ↑(PrimeSpectrum.Top R)
x : ↥U
f : R
⊢ (germ (Sheaf.presheaf (structureSheaf R)) x) ((toOpen R U) f) =
    (toOpen R U ≫ germ (Sheaf.presheaf (structureSheaf R)) x) f

Next tactic:
rfl
theorem isUnit_to_basicOpen_self (f : R) : IsUnit (toOpen R (PrimeSpectrum.basicOpen f) f) :=
  isUnit_of_mul_eq_one _ (const R 1 f (PrimeSpectrum.basicOpen f) fun _ => id) <| by
    

Proof state:
R : Type u
inst✝ : CommRing R
f : R
⊢ (toOpen R (PrimeSpectrum.basicOpen f)) f *
      const R 1 f (PrimeSpectrum.basicOpen f) (_ : ∀ x ∈ PrimeSpectrum.basicOpen f, x ∈ PrimeSpectrum.basicOpen f) =
    1

Next tactic:
rw [toOpen_eq_const, const_mul_rev]
theorem isUnit_toStalk (x : PrimeSpectrum.Top R) (f : x.asIdeal.primeCompl) :
    IsUnit (toStalk R x (f : R)) := by
  

Proof state:
R : Type u
inst✝ : CommRing R
x : ↑(PrimeSpectrum.Top R)
f : ↥(Ideal.primeCompl x.asIdeal)
⊢ IsUnit ((toStalk R x) ↑f)

Next tactic:
erw [← germ_toOpen R (PrimeSpectrum.basicOpen (f : R)) ⟨x, f.2⟩ (f : R)]
theorem isUnit_toStalk (x : PrimeSpectrum.Top R) (f : x.asIdeal.primeCompl) :
    IsUnit (toStalk R x (f : R)) := by
  erw [← germ_toOpen R (PrimeSpectrum.basicOpen (f : R)) ⟨x, f.2⟩ (f : R)]
  

Proof state:
R : Type u
inst✝ : CommRing R
x : ↑(PrimeSpectrum.Top R)
f : ↥(Ideal.primeCompl x.asIdeal)
⊢ IsUnit
    ((germ (Sheaf.presheaf (structureSheaf R)) { val := x, property := (_ : ↑f ∈ Ideal.primeCompl x.asIdeal) })
      ((toOpen R (PrimeSpectrum.basicOpen ↑f)) ↑f))

Next tactic:
exact RingHom.isUnit_map _ (isUnit_to_basicOpen_self R f)
@[simp]
theorem localizationToStalk_mk' (x : PrimeSpectrum.Top R) (f : R) (s : x.asIdeal.primeCompl) :
    localizationToStalk R x (IsLocalization.mk' (Localization.AtPrime x.asIdeal) f s) =
      (structureSheaf R).presheaf.germ (⟨x, s.2⟩ : PrimeSpectrum.basicOpen (s : R))
        (const R f s (PrimeSpectrum.basicOpen s) fun _ => id) :=
  (IsLocalization.lift_mk'_spec (S := Localization.AtPrime x.asIdeal) _ _ _ _).2 <| by
    

Proof state:
R : Type u
inst✝ : CommRing R
x : ↑(PrimeSpectrum.Top R)
f : R
s : ↥(Ideal.primeCompl x.asIdeal)
⊢ (toStalk R x) f =
    (toStalk R x) ↑s *
      (germ (Sheaf.presheaf (structureSheaf R)) { val := x, property := (_ : ↑s ∈ Ideal.primeCompl x.asIdeal) })
        (const R f (↑s) (PrimeSpectrum.basicOpen ↑s)
          (_ : ∀ x_1 ∈ PrimeSpectrum.basicOpen ↑s, x_1 ∈ PrimeSpectrum.basicOpen ↑s))

Next tactic:
erw [← germ_toOpen R (PrimeSpectrum.basicOpen s) ⟨x, s.2⟩,
      ← germ_toOpen R (PrimeSpectrum.basicOpen s) ⟨x, s.2⟩, ← RingHom.map_mul, toOpen_eq_const,
      toOpen_eq_const, const_mul_cancel']
@[simp]
theorem stalkToFiberRingHom_germ (U : Opens (PrimeSpectrum.Top R)) (x : U)
    (s : (structureSheaf R).1.obj (op U)) :
    stalkToFiberRingHom R x ((structureSheaf R).presheaf.germ x s) = s.1 x := by
  

Proof state:
R : Type u
inst✝ : CommRing R
U : Opens ↑(PrimeSpectrum.Top R)
x : ↥U
s : ↑((structureSheaf R).val.obj (op U))
⊢ (stalkToFiberRingHom R ↑x) ((germ (Sheaf.presheaf (structureSheaf R)) x) s) = ↑s x

Next tactic:
cases x
@[simp]
theorem stalkToFiberRingHom_germ (U : Opens (PrimeSpectrum.Top R)) (x : U)
    (s : (structureSheaf R).1.obj (op U)) :
    stalkToFiberRingHom R x ((structureSheaf R).presheaf.germ x s) = s.1 x := by
  cases x; 

Proof state:
case mk
R : Type u
inst✝ : CommRing R
U : Opens ↑(PrimeSpectrum.Top R)
s : ↑((structureSheaf R).val.obj (op U))
val✝ : ↑(PrimeSpectrum.Top R)
property✝ : val✝ ∈ U
⊢ (stalkToFiberRingHom R ↑{ val := val✝, property := property✝ })
      ((germ (Sheaf.presheaf (structureSheaf R)) { val := val✝, property := property✝ }) s) =
    ↑s { val := val✝, property := property✝ }

Next tactic:
exact stalkToFiberRingHom_germ' R U _ _ _
@[simp]
theorem toStalk_comp_stalkToFiberRingHom (x : PrimeSpectrum.Top R) :
    -- Porting note : now `algebraMap _ _` needs to be explicitly typed
    toStalk R x ≫ stalkToFiberRingHom R x = algebraMap R (Localization.AtPrime x.asIdeal) := by
  

Proof state:
R : Type u
inst✝ : CommRing R
x : ↑(PrimeSpectrum.Top R)
⊢ toStalk R x ≫ stalkToFiberRingHom R x = algebraMap R (Localization.AtPrime x.asIdeal)

Next tactic:
erw [toStalk, Category.assoc, germ_comp_stalkToFiberRingHom]
@[simp]
theorem toStalk_comp_stalkToFiberRingHom (x : PrimeSpectrum.Top R) :
    -- Porting note : now `algebraMap _ _` needs to be explicitly typed
    toStalk R x ≫ stalkToFiberRingHom R x = algebraMap R (Localization.AtPrime x.asIdeal) := by
  erw [toStalk, Category.assoc, germ_comp_stalkToFiberRingHom]; 

Proof state:
R : Type u
inst✝ : CommRing R
x : ↑(PrimeSpectrum.Top R)
⊢ toOpen R ⊤ ≫
      openToLocalization R ⊤ ↑{ val := x, property := True.intro } (_ : ↑{ val := x, property := True.intro } ∈ ⊤) =
    algebraMap R (Localization.AtPrime x.asIdeal)

Next tactic:
rfl
/-- The ring isomorphism between the stalk of the structure sheaf of `R` at a point `p`
corresponding to a prime ideal in `R` and the localization of `R` at `p`. -/
@[simps]
def stalkIso (x : PrimeSpectrum.Top R) :
    (structureSheaf R).presheaf.stalk x ≅ CommRingCat.of (Localization.AtPrime x.asIdeal) where
  hom := stalkToFiberRingHom R x
  inv := localizationToStalk R x
  hom_inv_id := by
    

Proof state:
R : Type u
inst✝ : CommRing R
x : ↑(PrimeSpectrum.Top R)
⊢ stalkToFiberRingHom R x ≫ localizationToStalk R x = 𝟙 (stalk (Sheaf.presheaf (structureSheaf R)) x)

Next tactic:
ext U hxU s
/-- The ring isomorphism between the stalk of the structure sheaf of `R` at a point `p`
corresponding to a prime ideal in `R` and the localization of `R` at `p`. -/
@[simps]
def stalkIso (x : PrimeSpectrum.Top R) :
    (structureSheaf R).presheaf.stalk x ≅ CommRingCat.of (Localization.AtPrime x.asIdeal) where
  hom := stalkToFiberRingHom R x
  inv := localizationToStalk R x
  hom_inv_id := by
    ext U hxU s
    

Proof state:
case ih.w
R : Type u
inst✝ : CommRing R
x : ↑(PrimeSpectrum.Top R)
U : Opens ↑(PrimeSpectrum.Top R)
hxU : x ∈ U
s : (forget CommRingCat).obj ((Sheaf.presheaf (structureSheaf R)).obj (op U))
⊢ (germ (Sheaf.presheaf (structureSheaf R)) { val := x, property := hxU } ≫
        stalkToFiberRingHom R x ≫ localizationToStalk R x)
      s =
    (germ (Sheaf.presheaf (structureSheaf R)) { val := x, property := hxU } ≫
        𝟙 (stalk (Sheaf.presheaf (structureSheaf R)) x))
      s

Next tactic:
simp only [FunctorToTypes.map_comp_apply, CommRingCat.forget_map,
      CommRingCat.coe_of, Category.comp_id]
/-- The ring isomorphism between the stalk of the structure sheaf of `R` at a point `p`
corresponding to a prime ideal in `R` and the localization of `R` at `p`. -/
@[simps]
def stalkIso (x : PrimeSpectrum.Top R) :
    (structureSheaf R).presheaf.stalk x ≅ CommRingCat.of (Localization.AtPrime x.asIdeal) where
  hom := stalkToFiberRingHom R x
  inv := localizationToStalk R x
  hom_inv_id := by
    ext U hxU s
    simp only [FunctorToTypes.map_comp_apply, CommRingCat.forget_map,
      CommRingCat.coe_of, Category.comp_id]
    

Proof state:
case ih.w
R : Type u
inst✝ : CommRing R
x : ↑(PrimeSpectrum.Top R)
U : Opens ↑(PrimeSpectrum.Top R)
hxU : x ∈ U
s : (forget CommRingCat).obj ((Sheaf.presheaf (structureSheaf R)).obj (op U))
⊢ (germ (Sheaf.presheaf (structureSheaf R)) { val := x, property := hxU } ≫
        stalkToFiberRingHom R x ≫ localizationToStalk R x)
      s =
    (germ (Sheaf.presheaf (structureSheaf R)) { val := x, property := hxU }) s

Next tactic:
rw [comp_apply, comp_apply, stalkToFiberRingHom_germ']
/-- The ring isomorphism between the stalk of the structure sheaf of `R` at a point `p`
corresponding to a prime ideal in `R` and the localization of `R` at `p`. -/
@[simps]
def stalkIso (x : PrimeSpectrum.Top R) :
    (structureSheaf R).presheaf.stalk x ≅ CommRingCat.of (Localization.AtPrime x.asIdeal) where
  hom := stalkToFiberRingHom R x
  inv := localizationToStalk R x
  hom_inv_id := by
    ext U hxU s
    simp only [FunctorToTypes.map_comp_apply, CommRingCat.forget_map,
      CommRingCat.coe_of, Category.comp_id]
    rw [comp_apply, comp_apply, stalkToFiberRingHom_germ']
    

Proof state:
case ih.w
R : Type u
inst✝ : CommRing R
x : ↑(PrimeSpectrum.Top R)
U : Opens ↑(PrimeSpectrum.Top R)
hxU : x ∈ U
s : (forget CommRingCat).obj ((Sheaf.presheaf (structureSheaf R)).obj (op U))
⊢ (localizationToStalk R x) (↑s { val := x, property := hxU }) =
    (germ (Sheaf.presheaf (structureSheaf R)) { val := x, property := hxU }) s

Next tactic:
obtain ⟨V, hxV, iVU, f, g, (hg : V ≤ PrimeSpectrum.basicOpen _), hs⟩ :=
      exists_const _ _ s x hxU
/-- The ring isomorphism between the stalk of the structure sheaf of `R` at a point `p`
corresponding to a prime ideal in `R` and the localization of `R` at `p`. -/
@[simps]
def stalkIso (x : PrimeSpectrum.Top R) :
    (structureSheaf R).presheaf.stalk x ≅ CommRingCat.of (Localization.AtPrime x.asIdeal) where
  hom := stalkToFiberRingHom R x
  inv := localizationToStalk R x
  hom_inv_id := by
    ext U hxU s
    simp only [FunctorToTypes.map_comp_apply, CommRingCat.forget_map,
      CommRingCat.coe_of, Category.comp_id]
    rw [comp_apply, comp_apply, stalkToFiberRingHom_germ']
    obtain ⟨V, hxV, iVU, f, g, (hg : V ≤ PrimeSpectrum.basicOpen _), hs⟩ :=
      exists_const _ _ s x hxU
    

Proof state:
case ih.w.intro.intro.intro.intro.intro.intro
R : Type u
inst✝ : CommRing R
x : ↑(PrimeSpectrum.Top R)
U : Opens ↑(PrimeSpectrum.Top R)
hxU : x ∈ U
s : (forget CommRingCat).obj ((Sheaf.presheaf (structureSheaf R)).obj (op U))
V : Opens ↑(PrimeSpectrum.Top R)
hxV : x ∈ V
iVU : V ⟶ U
f g : R
hg : V ≤ PrimeSpectrum.basicOpen g
hs : const R f g V hg = ((structureSheaf R).val.map iVU.op) s
⊢ (localizationToStalk R x) (↑s { val := x, property := hxU }) =
    (germ (Sheaf.presheaf (structureSheaf R)) { val := x, property := hxU }) s

Next tactic:
erw [← res_apply R U V iVU s ⟨x, hxV⟩, ← hs, const_apply, localizationToStalk_mk']
/-- The ring isomorphism between the stalk of the structure sheaf of `R` at a point `p`
corresponding to a prime ideal in `R` and the localization of `R` at `p`. -/
@[simps]
def stalkIso (x : PrimeSpectrum.Top R) :
    (structureSheaf R).presheaf.stalk x ≅ CommRingCat.of (Localization.AtPrime x.asIdeal) where
  hom := stalkToFiberRingHom R x
  inv := localizationToStalk R x
  hom_inv_id := by
    ext U hxU s
    simp only [FunctorToTypes.map_comp_apply, CommRingCat.forget_map,
      CommRingCat.coe_of, Category.comp_id]
    rw [comp_apply, comp_apply, stalkToFiberRingHom_germ']
    obtain ⟨V, hxV, iVU, f, g, (hg : V ≤ PrimeSpectrum.basicOpen _), hs⟩ :=
      exists_const _ _ s x hxU
    erw [← res_apply R U V iVU s ⟨x, hxV⟩, ← hs, const_apply, localizationToStalk_mk']
    

Proof state:
case ih.w.intro.intro.intro.intro.intro.intro
R : Type u
inst✝ : CommRing R
x : ↑(PrimeSpectrum.Top R)
U : Opens ↑(PrimeSpectrum.Top R)
hxU : x ∈ U
s : (forget CommRingCat).obj ((Sheaf.presheaf (structureSheaf R)).obj (op U))
V : Opens ↑(PrimeSpectrum.Top R)
hxV : x ∈ V
iVU : V ⟶ U
f g : R
hg : V ≤ PrimeSpectrum.basicOpen g
hs : const R f g V hg = ((structureSheaf R).val.map iVU.op) s
⊢ (germ (Sheaf.presheaf (structureSheaf R))
        { val := x,
          property :=
            (_ :
              ↑{ val := g, property := (_ : ↑{ val := x, property := hxV } ∈ ↑(PrimeSpectrum.basicOpen ?m.727557)) } ∈
                Ideal.primeCompl x.asIdeal) })
      (const R f
        (↑{ val := g, property := (_ : ↑{ val := x, property := hxV } ∈ ↑(PrimeSpectrum.basicOpen ?m.727557)) })
        (PrimeSpectrum.basicOpen
          ↑{ val := g, property := (_ : ↑{ val := x, property := hxV } ∈ ↑(PrimeSpectrum.basicOpen ?m.727557)) })
        (_ :
          ∀
            x_1 ∈
              PrimeSpectrum.basicOpen
                ↑{ val := g, property := (_ : ↑{ val := x, property := hxV } ∈ ↑(PrimeSpectrum.basicOpen ?m.727557)) },
            x_1 ∈
              PrimeSpectrum.basicOpen
                ↑{ val := g,
                    property := (_ : ↑{ val := x, property := hxV } ∈ ↑(PrimeSpectrum.basicOpen ?m.727557)) })) =
    (germ (Sheaf.presheaf (structureSheaf R)) { val := x, property := hxU }) s

Next tactic:
refine' (structureSheaf R).presheaf.germ_ext V hxV (homOfLE hg) iVU _
/-- The ring isomorphism between the stalk of the structure sheaf of `R` at a point `p`
corresponding to a prime ideal in `R` and the localization of `R` at `p`. -/
@[simps]
def stalkIso (x : PrimeSpectrum.Top R) :
    (structureSheaf R).presheaf.stalk x ≅ CommRingCat.of (Localization.AtPrime x.asIdeal) where
  hom := stalkToFiberRingHom R x
  inv := localizationToStalk R x
  hom_inv_id := by
    ext U hxU s
    simp only [FunctorToTypes.map_comp_apply, CommRingCat.forget_map,
      CommRingCat.coe_of, Category.comp_id]
    rw [comp_apply, comp_apply, stalkToFiberRingHom_germ']
    obtain ⟨V, hxV, iVU, f, g, (hg : V ≤ PrimeSpectrum.basicOpen _), hs⟩ :=
      exists_const _ _ s x hxU
    erw [← res_apply R U V iVU s ⟨x, hxV⟩, ← hs, const_apply, localizationToStalk_mk']
    refine' (structureSheaf R).presheaf.germ_ext V hxV (homOfLE hg) iVU _
    

Proof state:
case ih.w.intro.intro.intro.intro.intro.intro
R : Type u
inst✝ : CommRing R
x : ↑(PrimeSpectrum.Top R)
U : Opens ↑(PrimeSpectrum.Top R)
hxU : x ∈ U
s : (forget CommRingCat).obj ((Sheaf.presheaf (structureSheaf R)).obj (op U))
V : Opens ↑(PrimeSpectrum.Top R)
hxV : x ∈ V
iVU : V ⟶ U
f g : R
hg : V ≤ PrimeSpectrum.basicOpen g
hs : const R f g V hg = ((structureSheaf R).val.map iVU.op) s
⊢ ((Sheaf.presheaf (structureSheaf R)).map (homOfLE hg).op)
      (const R f
        (↑{ val := g, property := (_ : ↑{ val := x, property := hxV } ∈ ↑(PrimeSpectrum.basicOpen ?m.727557)) })
        (PrimeSpectrum.basicOpen
          ↑{ val := g, property := (_ : ↑{ val := x, property := hxV } ∈ ↑(PrimeSpectrum.basicOpen ?m.727557)) })
        (_ :
          ∀
            x_1 ∈
              PrimeSpectrum.basicOpen
                ↑{ val := g, property := (_ : ↑{ val := x, property := hxV } ∈ ↑(PrimeSpectrum.basicOpen ?m.727557)) },
            x_1 ∈
              PrimeSpectrum.basicOpen
                ↑{ val := g,
                    property := (_ : ↑{ val := x, property := hxV } ∈ ↑(PrimeSpectrum.basicOpen ?m.727557)) })) =
    ((Sheaf.presheaf (structureSheaf R)).map iVU.op) s

Next tactic:
dsimp
/-- The ring isomorphism between the stalk of the structure sheaf of `R` at a point `p`
corresponding to a prime ideal in `R` and the localization of `R` at `p`. -/
@[simps]
def stalkIso (x : PrimeSpectrum.Top R) :
    (structureSheaf R).presheaf.stalk x ≅ CommRingCat.of (Localization.AtPrime x.asIdeal) where
  hom := stalkToFiberRingHom R x
  inv := localizationToStalk R x
  hom_inv_id := by
    ext U hxU s
    simp only [FunctorToTypes.map_comp_apply, CommRingCat.forget_map,
      CommRingCat.coe_of, Category.comp_id]
    rw [comp_apply, comp_apply, stalkToFiberRingHom_germ']
    obtain ⟨V, hxV, iVU, f, g, (hg : V ≤ PrimeSpectrum.basicOpen _), hs⟩ :=
      exists_const _ _ s x hxU
    erw [← res_apply R U V iVU s ⟨x, hxV⟩, ← hs, const_apply, localizationToStalk_mk']
    refine' (structureSheaf R).presheaf.germ_ext V hxV (homOfLE hg) iVU _
    dsimp
    

Proof state:
case ih.w.intro.intro.intro.intro.intro.intro
R : Type u
inst✝ : CommRing R
x : ↑(PrimeSpectrum.Top R)
U : Opens ↑(PrimeSpectrum.Top R)
hxU : x ∈ U
s : (forget CommRingCat).obj ((Sheaf.presheaf (structureSheaf R)).obj (op U))
V : Opens ↑(PrimeSpectrum.Top R)
hxV : x ∈ V
iVU : V ⟶ U
f g : R
hg : V ≤ PrimeSpectrum.basicOpen g
hs : const R f g V hg = ((structureSheaf R).val.map iVU.op) s
⊢ ((Sheaf.presheaf (structureSheaf R)).map (homOfLE hg).op)
      (const R f g (PrimeSpectrum.basicOpen g) (_ : ∀ x ∈ PrimeSpectrum.basicOpen g, x ∈ PrimeSpectrum.basicOpen g)) =
    ((Sheaf.presheaf (structureSheaf R)).map iVU.op) s

Next tactic:
erw [← hs, res_const']