l3lab/ntp-mathlib huggingface dataset:
instance to_basicOpen_epi (r : R) : Epi (toOpen R (PrimeSpectrum.basicOpen r)) :=
  ⟨fun {S} f g h => by
    refine' IsLocalization.ringHom_ext (R := R)
      (S := (structureSheaf R).val.obj (op <| PrimeSpectrum.basicOpen r)) _ _
    

Proof state:
R : Type u
inst✝ : CommRing R
r : R
S : CommRingCat
f g : (structureSheaf R).val.obj (op (PrimeSpectrum.basicOpen r)) ⟶ S
h : toOpen R (PrimeSpectrum.basicOpen r) ≫ f = toOpen R (PrimeSpectrum.basicOpen r) ≫ g
⊢ RingHom.comp f (algebraMap R ↑((structureSheaf R).val.obj (op (PrimeSpectrum.basicOpen r)))) =
    RingHom.comp g (algebraMap R ↑((structureSheaf R).val.obj (op (PrimeSpectrum.basicOpen r))))

Next tactic:
exact h
@[elementwise]
theorem to_global_factors :
    toOpen R ⊤ =
      CommRingCat.ofHom (algebraMap R (Localization.Away (1 : R))) ≫
        toBasicOpen R (1 : R) ≫
        (structureSheaf R).1.map (eqToHom PrimeSpectrum.basicOpen_one.symm).op := by
  

Proof state:
R : Type u
inst✝ : CommRing R
⊢ toOpen R ⊤ =
    CommRingCat.ofHom (algebraMap R (Localization.Away 1)) ≫
      toBasicOpen R 1 ≫ (structureSheaf R).val.map (eqToHom (_ : ⊤ = PrimeSpectrum.basicOpen 1)).op

Next tactic:
rw [← Category.assoc]
@[elementwise]
theorem to_global_factors :
    toOpen R ⊤ =
      CommRingCat.ofHom (algebraMap R (Localization.Away (1 : R))) ≫
        toBasicOpen R (1 : R) ≫
        (structureSheaf R).1.map (eqToHom PrimeSpectrum.basicOpen_one.symm).op := by
  rw [← Category.assoc]
  

Proof state:
R : Type u
inst✝ : CommRing R
⊢ toOpen R ⊤ =
    (CommRingCat.ofHom (algebraMap R (Localization.Away 1)) ≫ toBasicOpen R 1) ≫
      (structureSheaf R).val.map (eqToHom (_ : ⊤ = PrimeSpectrum.basicOpen 1)).op

Next tactic:
change toOpen R ⊤ =
    (CommRingCat.ofHom <| (toBasicOpen R 1).comp (algebraMap R (Localization.Away 1))) ≫
    (structureSheaf R).1.map (eqToHom _).op
@[elementwise]
theorem to_global_factors :
    toOpen R ⊤ =
      CommRingCat.ofHom (algebraMap R (Localization.Away (1 : R))) ≫
        toBasicOpen R (1 : R) ≫
        (structureSheaf R).1.map (eqToHom PrimeSpectrum.basicOpen_one.symm).op := by
  rw [← Category.assoc]
  change toOpen R ⊤ =
    (CommRingCat.ofHom <| (toBasicOpen R 1).comp (algebraMap R (Localization.Away 1))) ≫
    (structureSheaf R).1.map (eqToHom _).op
  

Proof state:
R : Type u
inst✝ : CommRing R
⊢ toOpen R ⊤ =
    CommRingCat.ofHom (RingHom.comp (toBasicOpen R 1) (algebraMap R (Localization.Away 1))) ≫
      (structureSheaf R).val.map (eqToHom (_ : ⊤ = PrimeSpectrum.basicOpen 1)).op

Next tactic:
unfold CommRingCat.ofHom
@[elementwise]
theorem to_global_factors :
    toOpen R ⊤ =
      CommRingCat.ofHom (algebraMap R (Localization.Away (1 : R))) ≫
        toBasicOpen R (1 : R) ≫
        (structureSheaf R).1.map (eqToHom PrimeSpectrum.basicOpen_one.symm).op := by
  rw [← Category.assoc]
  change toOpen R ⊤ =
    (CommRingCat.ofHom <| (toBasicOpen R 1).comp (algebraMap R (Localization.Away 1))) ≫
    (structureSheaf R).1.map (eqToHom _).op
  unfold CommRingCat.ofHom
  

Proof state:
R : Type u
inst✝ : CommRing R
⊢ toOpen R ⊤ =
    RingHom.comp (toBasicOpen R 1) (algebraMap R (Localization.Away 1)) ≫
      (structureSheaf R).val.map (eqToHom (_ : ⊤ = PrimeSpectrum.basicOpen 1)).op

Next tactic:
rw [localization_toBasicOpen R, toOpen_res]
instance isIso_to_global : IsIso (toOpen R ⊤) := by
  

Proof state:
R : Type u
inst✝ : CommRing R
⊢ IsIso (toOpen R ⊤)

Next tactic:
let hom := CommRingCat.ofHom (algebraMap R (Localization.Away (1 : R)))
instance isIso_to_global : IsIso (toOpen R ⊤) := by
  let hom := CommRingCat.ofHom (algebraMap R (Localization.Away (1 : R)))
  

Proof state:
R : Type u
inst✝ : CommRing R
hom : CommRingCat.of R ⟶ CommRingCat.of (Localization.Away 1) := CommRingCat.ofHom (algebraMap R (Localization.Away 1))
⊢ IsIso (toOpen R ⊤)

Next tactic:
haveI : IsIso hom :=
    IsIso.of_iso (IsLocalization.atOne R (Localization.Away (1 : R))).toRingEquiv.toCommRingCatIso
instance isIso_to_global : IsIso (toOpen R ⊤) := by
  let hom := CommRingCat.ofHom (algebraMap R (Localization.Away (1 : R)))
  haveI : IsIso hom :=
    IsIso.of_iso (IsLocalization.atOne R (Localization.Away (1 : R))).toRingEquiv.toCommRingCatIso
  

Proof state:
R : Type u
inst✝ : CommRing R
hom : CommRingCat.of R ⟶ CommRingCat.of (Localization.Away 1) := CommRingCat.ofHom (algebraMap R (Localization.Away 1))
this : IsIso hom
⊢ IsIso (toOpen R ⊤)

Next tactic:
rw [to_global_factors R]
instance isIso_to_global : IsIso (toOpen R ⊤) := by
  let hom := CommRingCat.ofHom (algebraMap R (Localization.Away (1 : R)))
  haveI : IsIso hom :=
    IsIso.of_iso (IsLocalization.atOne R (Localization.Away (1 : R))).toRingEquiv.toCommRingCatIso
  rw [to_global_factors R]
  

Proof state:
R : Type u
inst✝ : CommRing R
hom : CommRingCat.of R ⟶ CommRingCat.of (Localization.Away 1) := CommRingCat.ofHom (algebraMap R (Localization.Away 1))
this : IsIso hom
⊢ IsIso
    (CommRingCat.ofHom (algebraMap R (Localization.Away 1)) ≫
      toBasicOpen R 1 ≫ (structureSheaf R).val.map (eqToHom (_ : ⊤ = PrimeSpectrum.basicOpen 1)).op)

Next tactic:
infer_instance
@[simp, reassoc, elementwise]
theorem toStalk_stalkSpecializes {R : Type*} [CommRing R] {x y : PrimeSpectrum R} (h : x ⤳ y) :
    toStalk R y ≫ (structureSheaf R).presheaf.stalkSpecializes h = toStalk R x := by
  

Proof state:
R✝ : Type u
inst✝¹ : CommRing R✝
R : Type u_1
inst✝ : CommRing R
x y : PrimeSpectrum R
h : x ⤳ y
⊢ toStalk R y ≫ stalkSpecializes (Sheaf.presheaf (structureSheaf R)) h = toStalk R x

Next tactic:
dsimp [toStalk]
@[simp, reassoc, elementwise]
theorem toStalk_stalkSpecializes {R : Type*} [CommRing R] {x y : PrimeSpectrum R} (h : x ⤳ y) :
    toStalk R y ≫ (structureSheaf R).presheaf.stalkSpecializes h = toStalk R x := by
  dsimp [toStalk]; 

Proof state:
R✝ : Type u
inst✝¹ : CommRing R✝
R : Type u_1
inst✝ : CommRing R
x y : PrimeSpectrum R
h : x ⤳ y
⊢ (toOpen R ⊤ ≫ germ (Sheaf.presheaf (structureSheaf R)) { val := y, property := True.intro }) ≫
      stalkSpecializes (Sheaf.presheaf (structureSheaf R)) h =
    toOpen R ⊤ ≫ germ (Sheaf.presheaf (structureSheaf R)) { val := x, property := True.intro }

Next tactic:
simp [-toOpen_germ]
@[simp, reassoc, elementwise]
theorem localizationToStalk_stalkSpecializes {R : Type*} [CommRing R] {x y : PrimeSpectrum R}
    (h : x ⤳ y) :
    StructureSheaf.localizationToStalk R y ≫ (structureSheaf R).presheaf.stalkSpecializes h =
      CommRingCat.ofHom (PrimeSpectrum.localizationMapOfSpecializes h) ≫
        StructureSheaf.localizationToStalk R x := by
  

Proof state:
R✝ : Type u
inst✝¹ : CommRing R✝
R : Type u_1
inst✝ : CommRing R
x y : PrimeSpectrum R
h : x ⤳ y
⊢ localizationToStalk R y ≫ stalkSpecializes (Sheaf.presheaf (structureSheaf R)) h =
    CommRingCat.ofHom (PrimeSpectrum.localizationMapOfSpecializes h) ≫ localizationToStalk R x

Next tactic:
apply IsLocalization.ringHom_ext (S := Localization.AtPrime y.asIdeal) y.asIdeal.primeCompl
@[simp, reassoc, elementwise]
theorem localizationToStalk_stalkSpecializes {R : Type*} [CommRing R] {x y : PrimeSpectrum R}
    (h : x ⤳ y) :
    StructureSheaf.localizationToStalk R y ≫ (structureSheaf R).presheaf.stalkSpecializes h =
      CommRingCat.ofHom (PrimeSpectrum.localizationMapOfSpecializes h) ≫
        StructureSheaf.localizationToStalk R x := by
  apply IsLocalization.ringHom_ext (S := Localization.AtPrime y.asIdeal) y.asIdeal.primeCompl
  

Proof state:
case h
R✝ : Type u
inst✝¹ : CommRing R✝
R : Type u_1
inst✝ : CommRing R
x y : PrimeSpectrum R
h : x ⤳ y
⊢ RingHom.comp (localizationToStalk R y ≫ stalkSpecializes (Sheaf.presheaf (structureSheaf R)) h)
      (algebraMap R (Localization.AtPrime y.asIdeal)) =
    RingHom.comp (CommRingCat.ofHom (PrimeSpectrum.localizationMapOfSpecializes h) ≫ localizationToStalk R x)
      (algebraMap R (Localization.AtPrime y.asIdeal))

Next tactic:
erw [RingHom.comp_assoc]
@[simp, reassoc, elementwise]
theorem localizationToStalk_stalkSpecializes {R : Type*} [CommRing R] {x y : PrimeSpectrum R}
    (h : x ⤳ y) :
    StructureSheaf.localizationToStalk R y ≫ (structureSheaf R).presheaf.stalkSpecializes h =
      CommRingCat.ofHom (PrimeSpectrum.localizationMapOfSpecializes h) ≫
        StructureSheaf.localizationToStalk R x := by
  apply IsLocalization.ringHom_ext (S := Localization.AtPrime y.asIdeal) y.asIdeal.primeCompl
  erw [RingHom.comp_assoc]
  

Proof state:
case h
R✝ : Type u
inst✝¹ : CommRing R✝
R : Type u_1
inst✝ : CommRing R
x y : PrimeSpectrum R
h : x ⤳ y
⊢ RingHom.comp (stalkSpecializes (Sheaf.presheaf (structureSheaf R)) h)
      (RingHom.comp (localizationToStalk R y) (algebraMap R (Localization.AtPrime y.asIdeal))) =
    RingHom.comp (CommRingCat.ofHom (PrimeSpectrum.localizationMapOfSpecializes h) ≫ localizationToStalk R x)
      (algebraMap R (Localization.AtPrime y.asIdeal))

Next tactic:
conv_rhs => erw [RingHom.comp_assoc]
@[simp, reassoc, elementwise]
theorem localizationToStalk_stalkSpecializes {R : Type*} [CommRing R] {x y : PrimeSpectrum R}
    (h : x ⤳ y) :
    StructureSheaf.localizationToStalk R y ≫ (structureSheaf R).presheaf.stalkSpecializes h =
      CommRingCat.ofHom (PrimeSpectrum.localizationMapOfSpecializes h) ≫
        StructureSheaf.localizationToStalk R x := by
  apply IsLocalization.ringHom_ext (S := Localization.AtPrime y.asIdeal) y.asIdeal.primeCompl
  erw [RingHom.comp_assoc]
  conv_rhs => 

Proof state:
R✝ : Type u
inst✝¹ : CommRing R✝
R : Type u_1
inst✝ : CommRing R
x y : PrimeSpectrum R
h : x ⤳ y
| RingHom.comp (CommRingCat.ofHom (PrimeSpectrum.localizationMapOfSpecializes h) ≫ localizationToStalk R x)
    (algebraMap R (Localization.AtPrime y.asIdeal))

Next tactic:
erw [RingHom.comp_assoc]
@[simp, reassoc, elementwise]
theorem localizationToStalk_stalkSpecializes {R : Type*} [CommRing R] {x y : PrimeSpectrum R}
    (h : x ⤳ y) :
    StructureSheaf.localizationToStalk R y ≫ (structureSheaf R).presheaf.stalkSpecializes h =
      CommRingCat.ofHom (PrimeSpectrum.localizationMapOfSpecializes h) ≫
        StructureSheaf.localizationToStalk R x := by
  apply IsLocalization.ringHom_ext (S := Localization.AtPrime y.asIdeal) y.asIdeal.primeCompl
  erw [RingHom.comp_assoc]
  conv_rhs => erw [RingHom.comp_assoc]
  

Proof state:
case h
R✝ : Type u
inst✝¹ : CommRing R✝
R : Type u_1
inst✝ : CommRing R
x y : PrimeSpectrum R
h : x ⤳ y
⊢ RingHom.comp (stalkSpecializes (Sheaf.presheaf (structureSheaf R)) h)
      (RingHom.comp (localizationToStalk R y) (algebraMap R (Localization.AtPrime y.asIdeal))) =
    RingHom.comp (localizationToStalk R x)
      (RingHom.comp (CommRingCat.ofHom (PrimeSpectrum.localizationMapOfSpecializes h))
        (algebraMap R (Localization.AtPrime y.asIdeal)))

Next tactic:
dsimp [CommRingCat.ofHom, localizationToStalk, PrimeSpectrum.localizationMapOfSpecializes]
@[simp, reassoc, elementwise]
theorem localizationToStalk_stalkSpecializes {R : Type*} [CommRing R] {x y : PrimeSpectrum R}
    (h : x ⤳ y) :
    StructureSheaf.localizationToStalk R y ≫ (structureSheaf R).presheaf.stalkSpecializes h =
      CommRingCat.ofHom (PrimeSpectrum.localizationMapOfSpecializes h) ≫
        StructureSheaf.localizationToStalk R x := by
  apply IsLocalization.ringHom_ext (S := Localization.AtPrime y.asIdeal) y.asIdeal.primeCompl
  erw [RingHom.comp_assoc]
  conv_rhs => erw [RingHom.comp_assoc]
  dsimp [CommRingCat.ofHom, localizationToStalk, PrimeSpectrum.localizationMapOfSpecializes]
  

Proof state:
case h
R✝ : Type u
inst✝¹ : CommRing R✝
R : Type u_1
inst✝ : CommRing R
x y : PrimeSpectrum R
h : x ⤳ y
⊢ RingHom.comp (stalkSpecializes (Sheaf.presheaf (structureSheaf R)) h)
      (RingHom.comp (IsLocalization.lift (_ : ∀ (f : ↥(Ideal.primeCompl y.asIdeal)), IsUnit ((toStalk R y) ↑f)))
        (algebraMap R (Localization.AtPrime y.asIdeal))) =
    RingHom.comp (IsLocalization.lift (_ : ∀ (f : ↥(Ideal.primeCompl x.asIdeal)), IsUnit ((toStalk R x) ↑f)))
      (RingHom.comp
        (IsLocalization.lift
          (_ : ∀ (y_1 : ↥(Ideal.primeCompl y.asIdeal)), IsUnit ((algebraMap R (Localization.AtPrime x.asIdeal)) ↑y_1)))
        (algebraMap R (Localization.AtPrime y.asIdeal)))

Next tactic:
rw [IsLocalization.lift_comp, IsLocalization.lift_comp, IsLocalization.lift_comp]
@[simp, reassoc, elementwise]
theorem localizationToStalk_stalkSpecializes {R : Type*} [CommRing R] {x y : PrimeSpectrum R}
    (h : x ⤳ y) :
    StructureSheaf.localizationToStalk R y ≫ (structureSheaf R).presheaf.stalkSpecializes h =
      CommRingCat.ofHom (PrimeSpectrum.localizationMapOfSpecializes h) ≫
        StructureSheaf.localizationToStalk R x := by
  apply IsLocalization.ringHom_ext (S := Localization.AtPrime y.asIdeal) y.asIdeal.primeCompl
  erw [RingHom.comp_assoc]
  conv_rhs => erw [RingHom.comp_assoc]
  dsimp [CommRingCat.ofHom, localizationToStalk, PrimeSpectrum.localizationMapOfSpecializes]
  rw [IsLocalization.lift_comp, IsLocalization.lift_comp, IsLocalization.lift_comp]
  

Proof state:
case h
R✝ : Type u
inst✝¹ : CommRing R✝
R : Type u_1
inst✝ : CommRing R
x y : PrimeSpectrum R
h : x ⤳ y
⊢ RingHom.comp (stalkSpecializes (Sheaf.presheaf (structureSheaf R)) h) (toStalk R y) = toStalk R x

Next tactic:
exact toStalk_stalkSpecializes h
@[simp, reassoc, elementwise]
theorem stalkSpecializes_stalk_to_fiber {R : Type*} [CommRing R] {x y : PrimeSpectrum R}
    (h : x ⤳ y) :
    (structureSheaf R).presheaf.stalkSpecializes h ≫ StructureSheaf.stalkToFiberRingHom R x =
      StructureSheaf.stalkToFiberRingHom R y ≫
      -- Porting note : `PrimeSpectrum.localizationMapOfSpecializes h` by itself is interpreted as a
      -- ring homomorphism, so it is changed in a way to force it being interpreted as categorical
      -- arrow.
      (show CommRingCat.of (Localization.AtPrime y.asIdeal) ⟶
        CommRingCat.of (Localization.AtPrime x.asIdeal)
        from PrimeSpectrum.localizationMapOfSpecializes h) := by
  

Proof state:
R✝ : Type u
inst✝¹ : CommRing R✝
R : Type u_1
inst✝ : CommRing R
x y : PrimeSpectrum R
h : x ⤳ y
⊢ stalkSpecializes (Sheaf.presheaf (structureSheaf R)) h ≫ stalkToFiberRingHom R x =
    stalkToFiberRingHom R y ≫
      let_fun this := PrimeSpectrum.localizationMapOfSpecializes h;
      this

Next tactic:
change _ ≫ (StructureSheaf.stalkIso R x).hom = (StructureSheaf.stalkIso R y).hom ≫ _
@[simp, reassoc, elementwise]
theorem stalkSpecializes_stalk_to_fiber {R : Type*} [CommRing R] {x y : PrimeSpectrum R}
    (h : x ⤳ y) :
    (structureSheaf R).presheaf.stalkSpecializes h ≫ StructureSheaf.stalkToFiberRingHom R x =
      StructureSheaf.stalkToFiberRingHom R y ≫
      -- Porting note : `PrimeSpectrum.localizationMapOfSpecializes h` by itself is interpreted as a
      -- ring homomorphism, so it is changed in a way to force it being interpreted as categorical
      -- arrow.
      (show CommRingCat.of (Localization.AtPrime y.asIdeal) ⟶
        CommRingCat.of (Localization.AtPrime x.asIdeal)
        from PrimeSpectrum.localizationMapOfSpecializes h) := by
  change _ ≫ (StructureSheaf.stalkIso R x).hom = (StructureSheaf.stalkIso R y).hom ≫ _
  

Proof state:
R✝ : Type u
inst✝¹ : CommRing R✝
R : Type u_1
inst✝ : CommRing R
x y : PrimeSpectrum R
h : x ⤳ y
⊢ stalkSpecializes (Sheaf.presheaf (structureSheaf R)) h ≫ (stalkIso R x).hom =
    (stalkIso R y).hom ≫
      let_fun this := PrimeSpectrum.localizationMapOfSpecializes h;
      this

Next tactic:
rw [← Iso.eq_comp_inv, Category.assoc, ← Iso.inv_comp_eq]
@[simp, reassoc, elementwise]
theorem stalkSpecializes_stalk_to_fiber {R : Type*} [CommRing R] {x y : PrimeSpectrum R}
    (h : x ⤳ y) :
    (structureSheaf R).presheaf.stalkSpecializes h ≫ StructureSheaf.stalkToFiberRingHom R x =
      StructureSheaf.stalkToFiberRingHom R y ≫
      -- Porting note : `PrimeSpectrum.localizationMapOfSpecializes h` by itself is interpreted as a
      -- ring homomorphism, so it is changed in a way to force it being interpreted as categorical
      -- arrow.
      (show CommRingCat.of (Localization.AtPrime y.asIdeal) ⟶
        CommRingCat.of (Localization.AtPrime x.asIdeal)
        from PrimeSpectrum.localizationMapOfSpecializes h) := by
  change _ ≫ (StructureSheaf.stalkIso R x).hom = (StructureSheaf.stalkIso R y).hom ≫ _
  rw [← Iso.eq_comp_inv, Category.assoc, ← Iso.inv_comp_eq]
  

Proof state:
R✝ : Type u
inst✝¹ : CommRing R✝
R : Type u_1
inst✝ : CommRing R
x y : PrimeSpectrum R
h : x ⤳ y
⊢ (stalkIso R y).inv ≫ stalkSpecializes (Sheaf.presheaf (structureSheaf R)) h =
    (let_fun this := PrimeSpectrum.localizationMapOfSpecializes h;
      this) ≫
      (stalkIso R x).inv

Next tactic:
exact localizationToStalk_stalkSpecializes h
theorem comapFunIsLocallyFraction (f : R →+* S) (U : Opens (PrimeSpectrum.Top R))
    (V : Opens (PrimeSpectrum.Top S)) (hUV : V.1 ⊆ PrimeSpectrum.comap f ⁻¹' U.1)
    (s : ∀ x : U, Localizations R x) (hs : (isLocallyFraction R).toPrelocalPredicate.pred s) :
    (isLocallyFraction S).toPrelocalPredicate.pred (comapFun f U V hUV s) := by
  

Proof state:
R : Type u
inst✝² : CommRing R
S : Type u
inst✝¹ : CommRing S
P : Type u
inst✝ : CommRing P
f : R →+* S
U : Opens ↑(PrimeSpectrum.Top R)
V : Opens ↑(PrimeSpectrum.Top S)
hUV : V.carrier ⊆ ⇑(PrimeSpectrum.comap f) ⁻¹' U.carrier
s : (x : ↥U) → Localizations R ↑x
hs : PrelocalPredicate.pred (isLocallyFraction R).toPrelocalPredicate s
⊢ PrelocalPredicate.pred (isLocallyFraction S).toPrelocalPredicate (comapFun f U V hUV s)

Next tactic:
rintro ⟨p, hpV⟩
theorem comapFunIsLocallyFraction (f : R →+* S) (U : Opens (PrimeSpectrum.Top R))
    (V : Opens (PrimeSpectrum.Top S)) (hUV : V.1 ⊆ PrimeSpectrum.comap f ⁻¹' U.1)
    (s : ∀ x : U, Localizations R x) (hs : (isLocallyFraction R).toPrelocalPredicate.pred s) :
    (isLocallyFraction S).toPrelocalPredicate.pred (comapFun f U V hUV s) := by
  rintro ⟨p, hpV⟩
  -- Since `s` is locally fraction, we can find a neighborhood `W` of `PrimeSpectrum.comap f p`
  -- in `U`, such that `s = a / b` on `W`, for some ring elements `a, b : R`.
  

Proof state:
case mk
R : Type u
inst✝² : CommRing R
S : Type u
inst✝¹ : CommRing S
P : Type u
inst✝ : CommRing P
f : R →+* S
U : Opens ↑(PrimeSpectrum.Top R)
V : Opens ↑(PrimeSpectrum.Top S)
hUV : V.carrier ⊆ ⇑(PrimeSpectrum.comap f) ⁻¹' U.carrier
s : (x : ↥U) → Localizations R ↑x
hs : PrelocalPredicate.pred (isLocallyFraction R).toPrelocalPredicate s
p : ↑(PrimeSpectrum.Top S)
hpV : p ∈ V
⊢ ∃ V_1,
    ∃ (_ : ↑{ val := p, property := hpV } ∈ V_1),
      ∃ i,
        PrelocalPredicate.pred (isFractionPrelocal S) fun x =>
          comapFun f U V hUV s ((fun x => { val := ↑x, property := (_ : ↑x ∈ ↑V) }) x)

Next tactic:
rcases hs ⟨PrimeSpectrum.comap f p, hUV hpV⟩ with ⟨W, m, iWU, a, b, h_frac⟩
theorem comapFunIsLocallyFraction (f : R →+* S) (U : Opens (PrimeSpectrum.Top R))
    (V : Opens (PrimeSpectrum.Top S)) (hUV : V.1 ⊆ PrimeSpectrum.comap f ⁻¹' U.1)
    (s : ∀ x : U, Localizations R x) (hs : (isLocallyFraction R).toPrelocalPredicate.pred s) :
    (isLocallyFraction S).toPrelocalPredicate.pred (comapFun f U V hUV s) := by
  rintro ⟨p, hpV⟩
  -- Since `s` is locally fraction, we can find a neighborhood `W` of `PrimeSpectrum.comap f p`
  -- in `U`, such that `s = a / b` on `W`, for some ring elements `a, b : R`.
  rcases hs ⟨PrimeSpectrum.comap f p, hUV hpV⟩ with ⟨W, m, iWU, a, b, h_frac⟩
  -- We claim that we can write our new section as the fraction `f a / f b` on the neighborhood
  -- `(comap f) ⁻¹ W ⊓ V` of `p`.
  

Proof state:
case mk.intro.intro.intro.intro.intro
R : Type u
inst✝² : CommRing R
S : Type u
inst✝¹ : CommRing S
P : Type u
inst✝ : CommRing P
f : R →+* S
U : Opens ↑(PrimeSpectrum.Top R)
V : Opens ↑(PrimeSpectrum.Top S)
hUV : V.carrier ⊆ ⇑(PrimeSpectrum.comap f) ⁻¹' U.carrier
s : (x : ↥U) → Localizations R ↑x
hs : PrelocalPredicate.pred (isLocallyFraction R).toPrelocalPredicate s
p : ↑(PrimeSpectrum.Top S)
hpV : p ∈ V
W : Opens ↑(PrimeSpectrum.Top R)
m : ↑{ val := (PrimeSpectrum.comap f) p, property := (_ : p ∈ ⇑(PrimeSpectrum.comap f) ⁻¹' U.carrier) } ∈ W
iWU : W ⟶ U
a b : R
h_frac :
  ∀ (x : ↥W),
    b ∉ (↑x).asIdeal ∧
      (fun x => s ((fun x => { val := ↑x, property := (_ : ↑x ∈ ↑U) }) x)) x * (algebraMap R (Localizations R ↑x)) b =
        (algebraMap R (Localizations R ↑x)) a
⊢ ∃ V_1,
    ∃ (_ : ↑{ val := p, property := hpV } ∈ V_1),
      ∃ i,
        PrelocalPredicate.pred (isFractionPrelocal S) fun x =>
          comapFun f U V hUV s ((fun x => { val := ↑x, property := (_ : ↑x ∈ ↑V) }) x)

Next tactic:
refine' ⟨Opens.comap (PrimeSpectrum.comap f) W ⊓ V, ⟨m, hpV⟩, Opens.infLERight _ _, f a, f b, _⟩
theorem comapFunIsLocallyFraction (f : R →+* S) (U : Opens (PrimeSpectrum.Top R))
    (V : Opens (PrimeSpectrum.Top S)) (hUV : V.1 ⊆ PrimeSpectrum.comap f ⁻¹' U.1)
    (s : ∀ x : U, Localizations R x) (hs : (isLocallyFraction R).toPrelocalPredicate.pred s) :
    (isLocallyFraction S).toPrelocalPredicate.pred (comapFun f U V hUV s) := by
  rintro ⟨p, hpV⟩
  -- Since `s` is locally fraction, we can find a neighborhood `W` of `PrimeSpectrum.comap f p`
  -- in `U`, such that `s = a / b` on `W`, for some ring elements `a, b : R`.
  rcases hs ⟨PrimeSpectrum.comap f p, hUV hpV⟩ with ⟨W, m, iWU, a, b, h_frac⟩
  -- We claim that we can write our new section as the fraction `f a / f b` on the neighborhood
  -- `(comap f) ⁻¹ W ⊓ V` of `p`.
  refine' ⟨Opens.comap (PrimeSpectrum.comap f) W ⊓ V, ⟨m, hpV⟩, Opens.infLERight _ _, f a, f b, _⟩
  

Proof state:
case mk.intro.intro.intro.intro.intro
R : Type u
inst✝² : CommRing R
S : Type u
inst✝¹ : CommRing S
P : Type u
inst✝ : CommRing P
f : R →+* S
U : Opens ↑(PrimeSpectrum.Top R)
V : Opens ↑(PrimeSpectrum.Top S)
hUV : V.carrier ⊆ ⇑(PrimeSpectrum.comap f) ⁻¹' U.carrier
s : (x : ↥U) → Localizations R ↑x
hs : PrelocalPredicate.pred (isLocallyFraction R).toPrelocalPredicate s
p : ↑(PrimeSpectrum.Top S)
hpV : p ∈ V
W : Opens ↑(PrimeSpectrum.Top R)
m : ↑{ val := (PrimeSpectrum.comap f) p, property := (_ : p ∈ ⇑(PrimeSpectrum.comap f) ⁻¹' U.carrier) } ∈ W
iWU : W ⟶ U
a b : R
h_frac :
  ∀ (x : ↥W),
    b ∉ (↑x).asIdeal ∧
      (fun x => s ((fun x => { val := ↑x, property := (_ : ↑x ∈ ↑U) }) x)) x * (algebraMap R (Localizations R ↑x)) b =
        (algebraMap R (Localizations R ↑x)) a
⊢ ∀ (x : ↥((Opens.comap (PrimeSpectrum.comap f)) W ⊓ V)),
    f b ∉ (↑x).asIdeal ∧
      (fun x => comapFun f U V hUV s ((fun x => { val := ↑x, property := (_ : ↑x ∈ ↑V) }) x)) x *
          (algebraMap S (Localizations S ↑x)) (f b) =
        (algebraMap S (Localizations S ↑x)) (f a)

Next tactic:
rintro ⟨q, ⟨hqW, hqV⟩⟩