l3lab/ntp-mathlib huggingface dataset:
/-- The map on stalks induced by the unit commutes with maps from `Γ(X)` to
    stalks (in `Spec Γ(X)` and in `X`). -/
theorem toStalk_stalkMap_toΓSpec (x : X) :
    toStalk _ _ ≫ PresheafedSpace.stalkMap X.toΓSpecSheafedSpace x = X.ΓToStalk x := by
  rw [PresheafedSpace.stalkMap]
  erw [← toOpen_germ _ (basicOpen (1 : Γ.obj (op X)))
      ⟨X.toΓSpecFun x, by rw [basicOpen_one]; trivial⟩]
  rw [← Category.assoc, Category.assoc (toOpen _ _)]
  erw [stalkFunctor_map_germ]
  -- Porting note : was `rw [← assoc, toΓSpecSheafedSpace_app_spec]`, but Lean did not like it.
  rw [toΓSpecSheafedSpace_app_spec_assoc]
  unfold ΓToStalk
  rw [← stalkPushforward_germ _ X.toΓSpecBase X.presheaf ⊤]
  

Proof state:
X : LocallyRingedSpace
r : ↑(Γ.obj (op X))
x : ↑(toTopCat X)
⊢ (toToΓSpecMapBasicOpen X 1 ≫
        germ ((toΓSpecSheafedSpace X).base _* X.presheaf)
          { val := toΓSpecFun X x, property := (_ : toΓSpecFun X x ∈ basicOpen 1) }) ≫
      stalkPushforward CommRingCat (toΓSpecSheafedSpace X).base X.presheaf x =
    germ (toΓSpecBase X _* X.presheaf)
        { val := (toΓSpecBase X) ↑{ val := x, property := trivial },
          property := (_ : ↑{ val := x, property := trivial } ∈ (Opens.map (toΓSpecBase X)).obj ⊤) } ≫
      stalkPushforward CommRingCat (toΓSpecBase X) X.presheaf ↑{ val := x, property := trivial }

Next tactic:
congr 1
/-- The map on stalks induced by the unit commutes with maps from `Γ(X)` to
    stalks (in `Spec Γ(X)` and in `X`). -/
theorem toStalk_stalkMap_toΓSpec (x : X) :
    toStalk _ _ ≫ PresheafedSpace.stalkMap X.toΓSpecSheafedSpace x = X.ΓToStalk x := by
  rw [PresheafedSpace.stalkMap]
  erw [← toOpen_germ _ (basicOpen (1 : Γ.obj (op X)))
      ⟨X.toΓSpecFun x, by rw [basicOpen_one]; trivial⟩]
  rw [← Category.assoc, Category.assoc (toOpen _ _)]
  erw [stalkFunctor_map_germ]
  -- Porting note : was `rw [← assoc, toΓSpecSheafedSpace_app_spec]`, but Lean did not like it.
  rw [toΓSpecSheafedSpace_app_spec_assoc]
  unfold ΓToStalk
  rw [← stalkPushforward_germ _ X.toΓSpecBase X.presheaf ⊤]
  congr 1
  

Proof state:
case e_a
X : LocallyRingedSpace
r : ↑(Γ.obj (op X))
x : ↑(toTopCat X)
⊢ toToΓSpecMapBasicOpen X 1 ≫
      germ ((toΓSpecSheafedSpace X).base _* X.presheaf)
        { val := toΓSpecFun X x, property := (_ : toΓSpecFun X x ∈ basicOpen 1) } =
    germ (toΓSpecBase X _* X.presheaf)
      { val := (toΓSpecBase X) ↑{ val := x, property := trivial },
        property := (_ : ↑{ val := x, property := trivial } ∈ (Opens.map (toΓSpecBase X)).obj ⊤) }

Next tactic:
change (X.toΓSpecBase _* X.presheaf).map le_top.hom.op ≫ _ = _
/-- The map on stalks induced by the unit commutes with maps from `Γ(X)` to
    stalks (in `Spec Γ(X)` and in `X`). -/
theorem toStalk_stalkMap_toΓSpec (x : X) :
    toStalk _ _ ≫ PresheafedSpace.stalkMap X.toΓSpecSheafedSpace x = X.ΓToStalk x := by
  rw [PresheafedSpace.stalkMap]
  erw [← toOpen_germ _ (basicOpen (1 : Γ.obj (op X)))
      ⟨X.toΓSpecFun x, by rw [basicOpen_one]; trivial⟩]
  rw [← Category.assoc, Category.assoc (toOpen _ _)]
  erw [stalkFunctor_map_germ]
  -- Porting note : was `rw [← assoc, toΓSpecSheafedSpace_app_spec]`, but Lean did not like it.
  rw [toΓSpecSheafedSpace_app_spec_assoc]
  unfold ΓToStalk
  rw [← stalkPushforward_germ _ X.toΓSpecBase X.presheaf ⊤]
  congr 1
  change (X.toΓSpecBase _* X.presheaf).map le_top.hom.op ≫ _ = _
  

Proof state:
case e_a
X : LocallyRingedSpace
r : ↑(Γ.obj (op X))
x : ↑(toTopCat X)
⊢ (toΓSpecBase X _* X.presheaf).map
        (LE.le.hom
            (_ :
              { carrier := {x | 1 ∉ x.asIdeal}, is_open' := (_ : ∃ y, zeroLocus y = {x | 1 ∉ x.asIdeal}ᶜ) } ≤ ⊤)).op ≫
      germ ((toΓSpecSheafedSpace X).base _* X.presheaf)
        { val := toΓSpecFun X x, property := (_ : toΓSpecFun X x ∈ basicOpen 1) } =
    germ (toΓSpecBase X _* X.presheaf)
      { val := (toΓSpecBase X) ↑{ val := x, property := trivial },
        property := (_ : ↑{ val := x, property := trivial } ∈ (Opens.map (toΓSpecBase X)).obj ⊤) }

Next tactic:
apply germ_res
/-- The canonical morphism from `X` to the spectrum of its global sections. -/
@[simps! val_base]
def toΓSpec : X ⟶ Spec.locallyRingedSpaceObj (Γ.obj (op X)) where
  val := X.toΓSpecSheafedSpace
  prop := by
    

Proof state:
X : LocallyRingedSpace
r : ↑(Γ.obj (op X))
⊢ ∀ (x : ↑↑X.toPresheafedSpace), IsLocalRingHom (PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x)

Next tactic:
intro x
/-- The canonical morphism from `X` to the spectrum of its global sections. -/
@[simps! val_base]
def toΓSpec : X ⟶ Spec.locallyRingedSpaceObj (Γ.obj (op X)) where
  val := X.toΓSpecSheafedSpace
  prop := by
    intro x
    

Proof state:
X : LocallyRingedSpace
r : ↑(Γ.obj (op X))
x : ↑↑X.toPresheafedSpace
⊢ IsLocalRingHom (PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x)

Next tactic:
let p : PrimeSpectrum (Γ.obj (op X)) := X.toΓSpecFun x
/-- The canonical morphism from `X` to the spectrum of its global sections. -/
@[simps! val_base]
def toΓSpec : X ⟶ Spec.locallyRingedSpaceObj (Γ.obj (op X)) where
  val := X.toΓSpecSheafedSpace
  prop := by
    intro x
    let p : PrimeSpectrum (Γ.obj (op X)) := X.toΓSpecFun x
    

Proof state:
X : LocallyRingedSpace
r : ↑(Γ.obj (op X))
x : ↑↑X.toPresheafedSpace
p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x
⊢ IsLocalRingHom (PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x)

Next tactic:
constructor
/-- The canonical morphism from `X` to the spectrum of its global sections. -/
@[simps! val_base]
def toΓSpec : X ⟶ Spec.locallyRingedSpaceObj (Γ.obj (op X)) where
  val := X.toΓSpecSheafedSpace
  prop := by
    intro x
    let p : PrimeSpectrum (Γ.obj (op X)) := X.toΓSpecFun x
    constructor
    -- show stalk map is local hom ↓
    

Proof state:
case map_nonunit
X : LocallyRingedSpace
r : ↑(Γ.obj (op X))
x : ↑↑X.toPresheafedSpace
p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x
⊢ ∀
    (a :
      ↑(PresheafedSpace.stalk (Spec.locallyRingedSpaceObj (Γ.obj (op X))).toSheafedSpace.toPresheafedSpace
          ((toΓSpecSheafedSpace X).base x))),
    IsUnit ((PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) a) → IsUnit a

Next tactic:
let S := (structureSheaf _).presheaf.stalk p
/-- The canonical morphism from `X` to the spectrum of its global sections. -/
@[simps! val_base]
def toΓSpec : X ⟶ Spec.locallyRingedSpaceObj (Γ.obj (op X)) where
  val := X.toΓSpecSheafedSpace
  prop := by
    intro x
    let p : PrimeSpectrum (Γ.obj (op X)) := X.toΓSpecFun x
    constructor
    -- show stalk map is local hom ↓
    let S := (structureSheaf _).presheaf.stalk p
    

Proof state:
case map_nonunit
X : LocallyRingedSpace
r : ↑(Γ.obj (op X))
x : ↑↑X.toPresheafedSpace
p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x
S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p
⊢ ∀
    (a :
      ↑(PresheafedSpace.stalk (Spec.locallyRingedSpaceObj (Γ.obj (op X))).toSheafedSpace.toPresheafedSpace
          ((toΓSpecSheafedSpace X).base x))),
    IsUnit ((PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) a) → IsUnit a

Next tactic:
rintro (t : S) ht
/-- The canonical morphism from `X` to the spectrum of its global sections. -/
@[simps! val_base]
def toΓSpec : X ⟶ Spec.locallyRingedSpaceObj (Γ.obj (op X)) where
  val := X.toΓSpecSheafedSpace
  prop := by
    intro x
    let p : PrimeSpectrum (Γ.obj (op X)) := X.toΓSpecFun x
    constructor
    -- show stalk map is local hom ↓
    let S := (structureSheaf _).presheaf.stalk p
    rintro (t : S) ht
    

Proof state:
case map_nonunit
X : LocallyRingedSpace
r : ↑(Γ.obj (op X))
x : ↑↑X.toPresheafedSpace
p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x
S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p
t : ↑S
ht : IsUnit ((PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t)
⊢ IsUnit t

Next tactic:
obtain ⟨⟨r, s⟩, he⟩ := IsLocalization.surj p.asIdeal.primeCompl t
/-- The canonical morphism from `X` to the spectrum of its global sections. -/
@[simps! val_base]
def toΓSpec : X ⟶ Spec.locallyRingedSpaceObj (Γ.obj (op X)) where
  val := X.toΓSpecSheafedSpace
  prop := by
    intro x
    let p : PrimeSpectrum (Γ.obj (op X)) := X.toΓSpecFun x
    constructor
    -- show stalk map is local hom ↓
    let S := (structureSheaf _).presheaf.stalk p
    rintro (t : S) ht
    obtain ⟨⟨r, s⟩, he⟩ := IsLocalization.surj p.asIdeal.primeCompl t
    

Proof state:
case map_nonunit.intro.mk
X : LocallyRingedSpace
r✝ : ↑(Γ.obj (op X))
x : ↑↑X.toPresheafedSpace
p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x
S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p
t : ↑S
ht : IsUnit ((PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t)
r : ↑(Γ.obj (op X))
s : ↥(Ideal.primeCompl p.asIdeal)
he : t * (algebraMap ↑(Γ.obj (op X)) ↑S) ↑(r, s).2 = (algebraMap ↑(Γ.obj (op X)) ↑S) (r, s).1
⊢ IsUnit t

Next tactic:
dsimp at he
/-- The canonical morphism from `X` to the spectrum of its global sections. -/
@[simps! val_base]
def toΓSpec : X ⟶ Spec.locallyRingedSpaceObj (Γ.obj (op X)) where
  val := X.toΓSpecSheafedSpace
  prop := by
    intro x
    let p : PrimeSpectrum (Γ.obj (op X)) := X.toΓSpecFun x
    constructor
    -- show stalk map is local hom ↓
    let S := (structureSheaf _).presheaf.stalk p
    rintro (t : S) ht
    obtain ⟨⟨r, s⟩, he⟩ := IsLocalization.surj p.asIdeal.primeCompl t
    dsimp at he
    

Proof state:
case map_nonunit.intro.mk
X : LocallyRingedSpace
r✝ : ↑(Γ.obj (op X))
x : ↑↑X.toPresheafedSpace
p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x
S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p
t : ↑S
ht : IsUnit ((PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t)
r : ↑(Γ.obj (op X))
s : ↥(Ideal.primeCompl p.asIdeal)
he :
  t * (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s = (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r
⊢ IsUnit t

Next tactic:
set t' := _
/-- The canonical morphism from `X` to the spectrum of its global sections. -/
@[simps! val_base]
def toΓSpec : X ⟶ Spec.locallyRingedSpaceObj (Γ.obj (op X)) where
  val := X.toΓSpecSheafedSpace
  prop := by
    intro x
    let p : PrimeSpectrum (Γ.obj (op X)) := X.toΓSpecFun x
    constructor
    -- show stalk map is local hom ↓
    let S := (structureSheaf _).presheaf.stalk p
    rintro (t : S) ht
    obtain ⟨⟨r, s⟩, he⟩ := IsLocalization.surj p.asIdeal.primeCompl t
    dsimp at he
    set t' := _
    

Proof state:
case map_nonunit.intro.mk
X : LocallyRingedSpace
r✝ : ↑(Γ.obj (op X))
x : ↑↑X.toPresheafedSpace
p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x
S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p
t : ↑S
ht : IsUnit ((PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t)
r : ↑(Γ.obj (op X))
s : ↥(Ideal.primeCompl p.asIdeal)
he :
  t * (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s = (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r
t' : ?m.141977 := ?m.141978
⊢ IsUnit t

Next tactic:
change t * t' = _ at he
/-- The canonical morphism from `X` to the spectrum of its global sections. -/
@[simps! val_base]
def toΓSpec : X ⟶ Spec.locallyRingedSpaceObj (Γ.obj (op X)) where
  val := X.toΓSpecSheafedSpace
  prop := by
    intro x
    let p : PrimeSpectrum (Γ.obj (op X)) := X.toΓSpecFun x
    constructor
    -- show stalk map is local hom ↓
    let S := (structureSheaf _).presheaf.stalk p
    rintro (t : S) ht
    obtain ⟨⟨r, s⟩, he⟩ := IsLocalization.surj p.asIdeal.primeCompl t
    dsimp at he
    set t' := _
    change t * t' = _ at he
    

Proof state:
case map_nonunit.intro.mk
X : LocallyRingedSpace
r✝ : ↑(Γ.obj (op X))
x : ↑↑X.toPresheafedSpace
p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x
S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p
t : ↑S
ht : IsUnit ((PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t)
r : ↑(Γ.obj (op X))
s : ↥(Ideal.primeCompl p.asIdeal)
t' : ↑S := (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s
he : t * t' = (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r
⊢ IsUnit t

Next tactic:
apply isUnit_of_mul_isUnit_left (y := t')
/-- The canonical morphism from `X` to the spectrum of its global sections. -/
@[simps! val_base]
def toΓSpec : X ⟶ Spec.locallyRingedSpaceObj (Γ.obj (op X)) where
  val := X.toΓSpecSheafedSpace
  prop := by
    intro x
    let p : PrimeSpectrum (Γ.obj (op X)) := X.toΓSpecFun x
    constructor
    -- show stalk map is local hom ↓
    let S := (structureSheaf _).presheaf.stalk p
    rintro (t : S) ht
    obtain ⟨⟨r, s⟩, he⟩ := IsLocalization.surj p.asIdeal.primeCompl t
    dsimp at he
    set t' := _
    change t * t' = _ at he
    apply isUnit_of_mul_isUnit_left (y := t')
    

Proof state:
case map_nonunit.intro.mk
X : LocallyRingedSpace
r✝ : ↑(Γ.obj (op X))
x : ↑↑X.toPresheafedSpace
p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x
S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p
t : ↑S
ht : IsUnit ((PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t)
r : ↑(Γ.obj (op X))
s : ↥(Ideal.primeCompl p.asIdeal)
t' : ↑S := (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s
he : t * t' = (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r
⊢ IsUnit (t * t')

Next tactic:
rw [he]
/-- The canonical morphism from `X` to the spectrum of its global sections. -/
@[simps! val_base]
def toΓSpec : X ⟶ Spec.locallyRingedSpaceObj (Γ.obj (op X)) where
  val := X.toΓSpecSheafedSpace
  prop := by
    intro x
    let p : PrimeSpectrum (Γ.obj (op X)) := X.toΓSpecFun x
    constructor
    -- show stalk map is local hom ↓
    let S := (structureSheaf _).presheaf.stalk p
    rintro (t : S) ht
    obtain ⟨⟨r, s⟩, he⟩ := IsLocalization.surj p.asIdeal.primeCompl t
    dsimp at he
    set t' := _
    change t * t' = _ at he
    apply isUnit_of_mul_isUnit_left (y := t')
    rw [he]
    

Proof state:
case map_nonunit.intro.mk
X : LocallyRingedSpace
r✝ : ↑(Γ.obj (op X))
x : ↑↑X.toPresheafedSpace
p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x
S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p
t : ↑S
ht : IsUnit ((PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t)
r : ↑(Γ.obj (op X))
s : ↥(Ideal.primeCompl p.asIdeal)
t' : ↑S := (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s
he : t * t' = (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r
⊢ IsUnit ((toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r)

Next tactic:
refine' IsLocalization.map_units S (⟨r, _⟩ : p.asIdeal.primeCompl)
/-- The canonical morphism from `X` to the spectrum of its global sections. -/
@[simps! val_base]
def toΓSpec : X ⟶ Spec.locallyRingedSpaceObj (Γ.obj (op X)) where
  val := X.toΓSpecSheafedSpace
  prop := by
    intro x
    let p : PrimeSpectrum (Γ.obj (op X)) := X.toΓSpecFun x
    constructor
    -- show stalk map is local hom ↓
    let S := (structureSheaf _).presheaf.stalk p
    rintro (t : S) ht
    obtain ⟨⟨r, s⟩, he⟩ := IsLocalization.surj p.asIdeal.primeCompl t
    dsimp at he
    set t' := _
    change t * t' = _ at he
    apply isUnit_of_mul_isUnit_left (y := t')
    rw [he]
    refine' IsLocalization.map_units S (⟨r, _⟩ : p.asIdeal.primeCompl)
    

Proof state:
case map_nonunit.intro.mk
X : LocallyRingedSpace
r✝ : ↑(Γ.obj (op X))
x : ↑↑X.toPresheafedSpace
p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x
S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p
t : ↑S
ht : IsUnit ((PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t)
r : ↑(Γ.obj (op X))
s : ↥(Ideal.primeCompl p.asIdeal)
t' : ↑S := (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s
he : t * t' = (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r
⊢ r ∈ Ideal.primeCompl p.asIdeal

Next tactic:
apply (not_mem_prime_iff_unit_in_stalk _ _ _).mpr
/-- The canonical morphism from `X` to the spectrum of its global sections. -/
@[simps! val_base]
def toΓSpec : X ⟶ Spec.locallyRingedSpaceObj (Γ.obj (op X)) where
  val := X.toΓSpecSheafedSpace
  prop := by
    intro x
    let p : PrimeSpectrum (Γ.obj (op X)) := X.toΓSpecFun x
    constructor
    -- show stalk map is local hom ↓
    let S := (structureSheaf _).presheaf.stalk p
    rintro (t : S) ht
    obtain ⟨⟨r, s⟩, he⟩ := IsLocalization.surj p.asIdeal.primeCompl t
    dsimp at he
    set t' := _
    change t * t' = _ at he
    apply isUnit_of_mul_isUnit_left (y := t')
    rw [he]
    refine' IsLocalization.map_units S (⟨r, _⟩ : p.asIdeal.primeCompl)
    apply (not_mem_prime_iff_unit_in_stalk _ _ _).mpr
    

Proof state:
case map_nonunit.intro.mk
X : LocallyRingedSpace
r✝ : ↑(Γ.obj (op X))
x : ↑↑X.toPresheafedSpace
p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x
S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p
t : ↑S
ht : IsUnit ((PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t)
r : ↑(Γ.obj (op X))
s : ↥(Ideal.primeCompl p.asIdeal)
t' : ↑S := (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s
he : t * t' = (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r
⊢ IsUnit ((ΓToStalk X x) r)

Next tactic:
rw [← toStalk_stalkMap_toΓSpec]
/-- The canonical morphism from `X` to the spectrum of its global sections. -/
@[simps! val_base]
def toΓSpec : X ⟶ Spec.locallyRingedSpaceObj (Γ.obj (op X)) where
  val := X.toΓSpecSheafedSpace
  prop := by
    intro x
    let p : PrimeSpectrum (Γ.obj (op X)) := X.toΓSpecFun x
    constructor
    -- show stalk map is local hom ↓
    let S := (structureSheaf _).presheaf.stalk p
    rintro (t : S) ht
    obtain ⟨⟨r, s⟩, he⟩ := IsLocalization.surj p.asIdeal.primeCompl t
    dsimp at he
    set t' := _
    change t * t' = _ at he
    apply isUnit_of_mul_isUnit_left (y := t')
    rw [he]
    refine' IsLocalization.map_units S (⟨r, _⟩ : p.asIdeal.primeCompl)
    apply (not_mem_prime_iff_unit_in_stalk _ _ _).mpr
    rw [← toStalk_stalkMap_toΓSpec]
    

Proof state:
case map_nonunit.intro.mk
X : LocallyRingedSpace
r✝ : ↑(Γ.obj (op X))
x : ↑↑X.toPresheafedSpace
p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x
S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p
t : ↑S
ht : IsUnit ((PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t)
r : ↑(Γ.obj (op X))
s : ↥(Ideal.primeCompl p.asIdeal)
t' : ↑S := (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s
he : t * t' = (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r
⊢ IsUnit
    ((toStalk (↑(op (Γ.obj (op X))).unop) ((toΓSpecSheafedSpace X).base x) ≫
        PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x)
      r)

Next tactic:
erw [comp_apply, ← he]
/-- The canonical morphism from `X` to the spectrum of its global sections. -/
@[simps! val_base]
def toΓSpec : X ⟶ Spec.locallyRingedSpaceObj (Γ.obj (op X)) where
  val := X.toΓSpecSheafedSpace
  prop := by
    intro x
    let p : PrimeSpectrum (Γ.obj (op X)) := X.toΓSpecFun x
    constructor
    -- show stalk map is local hom ↓
    let S := (structureSheaf _).presheaf.stalk p
    rintro (t : S) ht
    obtain ⟨⟨r, s⟩, he⟩ := IsLocalization.surj p.asIdeal.primeCompl t
    dsimp at he
    set t' := _
    change t * t' = _ at he
    apply isUnit_of_mul_isUnit_left (y := t')
    rw [he]
    refine' IsLocalization.map_units S (⟨r, _⟩ : p.asIdeal.primeCompl)
    apply (not_mem_prime_iff_unit_in_stalk _ _ _).mpr
    rw [← toStalk_stalkMap_toΓSpec]
    erw [comp_apply, ← he]
    

Proof state:
case map_nonunit.intro.mk
X : LocallyRingedSpace
r✝ : ↑(Γ.obj (op X))
x : ↑↑X.toPresheafedSpace
p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x
S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p
t : ↑S
ht : IsUnit ((PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t)
r : ↑(Γ.obj (op X))
s : ↥(Ideal.primeCompl p.asIdeal)
t' : ↑S := (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s
he : t * t' = (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r
⊢ IsUnit ((PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) (t * t'))

Next tactic:
rw [RingHom.map_mul]
/-- The canonical morphism from `X` to the spectrum of its global sections. -/
@[simps! val_base]
def toΓSpec : X ⟶ Spec.locallyRingedSpaceObj (Γ.obj (op X)) where
  val := X.toΓSpecSheafedSpace
  prop := by
    intro x
    let p : PrimeSpectrum (Γ.obj (op X)) := X.toΓSpecFun x
    constructor
    -- show stalk map is local hom ↓
    let S := (structureSheaf _).presheaf.stalk p
    rintro (t : S) ht
    obtain ⟨⟨r, s⟩, he⟩ := IsLocalization.surj p.asIdeal.primeCompl t
    dsimp at he
    set t' := _
    change t * t' = _ at he
    apply isUnit_of_mul_isUnit_left (y := t')
    rw [he]
    refine' IsLocalization.map_units S (⟨r, _⟩ : p.asIdeal.primeCompl)
    apply (not_mem_prime_iff_unit_in_stalk _ _ _).mpr
    rw [← toStalk_stalkMap_toΓSpec]
    erw [comp_apply, ← he]
    rw [RingHom.map_mul]
    -- Porting note : `IsLocalization.map_units` and the goal needs to be simplified before Lean
    -- realize it is useful
    

Proof state:
case map_nonunit.intro.mk
X : LocallyRingedSpace
r✝ : ↑(Γ.obj (op X))
x : ↑↑X.toPresheafedSpace
p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x
S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p
t : ↑S
ht : IsUnit ((PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t)
r : ↑(Γ.obj (op X))
s : ↥(Ideal.primeCompl p.asIdeal)
t' : ↑S := (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s
he : t * t' = (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r
⊢ IsUnit
    ((PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t * (PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t')

Next tactic:
have := IsLocalization.map_units (R := Γ.obj (op X)) S s
/-- The canonical morphism from `X` to the spectrum of its global sections. -/
@[simps! val_base]
def toΓSpec : X ⟶ Spec.locallyRingedSpaceObj (Γ.obj (op X)) where
  val := X.toΓSpecSheafedSpace
  prop := by
    intro x
    let p : PrimeSpectrum (Γ.obj (op X)) := X.toΓSpecFun x
    constructor
    -- show stalk map is local hom ↓
    let S := (structureSheaf _).presheaf.stalk p
    rintro (t : S) ht
    obtain ⟨⟨r, s⟩, he⟩ := IsLocalization.surj p.asIdeal.primeCompl t
    dsimp at he
    set t' := _
    change t * t' = _ at he
    apply isUnit_of_mul_isUnit_left (y := t')
    rw [he]
    refine' IsLocalization.map_units S (⟨r, _⟩ : p.asIdeal.primeCompl)
    apply (not_mem_prime_iff_unit_in_stalk _ _ _).mpr
    rw [← toStalk_stalkMap_toΓSpec]
    erw [comp_apply, ← he]
    rw [RingHom.map_mul]
    -- Porting note : `IsLocalization.map_units` and the goal needs to be simplified before Lean
    -- realize it is useful
    have := IsLocalization.map_units (R := Γ.obj (op X)) S s
    

Proof state:
case map_nonunit.intro.mk
X : LocallyRingedSpace
r✝ : ↑(Γ.obj (op X))
x : ↑↑X.toPresheafedSpace
p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x
S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p
t : ↑S
ht : IsUnit ((PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t)
r : ↑(Γ.obj (op X))
s : ↥(Ideal.primeCompl p.asIdeal)
t' : ↑S := (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s
he : t * t' = (toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r
this : IsUnit ((algebraMap ↑(Γ.obj (op X)) ↑S) ↑s)
⊢ IsUnit
    ((PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t * (PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t')

Next tactic:
dsimp at this ⊢