l3lab/ntp-mathlib huggingface dataset:
/-- 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
    dsimp at this ⊢
    

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 ((toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s)
⊢ IsUnit
    ((PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t *
      (PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) ((toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s))

Next tactic:
refine ht.mul <| this.map _
theorem comp_ring_hom_ext {X : LocallyRingedSpace} {R : CommRingCat} {f : R ⟶ Γ.obj (op X)}
    {β : X ⟶ Spec.locallyRingedSpaceObj R}
    (w : X.toΓSpec.1.base ≫ (Spec.locallyRingedSpaceMap f).1.base = β.1.base)
    (h :
      ∀ r : R,
        f ≫ X.presheaf.map (homOfLE le_top : (Opens.map β.1.base).obj (basicOpen r) ⟶ _).op =
          toOpen R (basicOpen r) ≫ β.1.c.app (op (basicOpen r))) :
    X.toΓSpec ≫ Spec.locallyRingedSpaceMap f = β := by
  

Proof state:
X✝ : LocallyRingedSpace
r : ↑(Γ.obj (op X✝))
X : LocallyRingedSpace
R : CommRingCat
f : R ⟶ Γ.obj (op X)
β : X ⟶ Spec.locallyRingedSpaceObj R
w : (toΓSpec X).val.base ≫ (Spec.locallyRingedSpaceMap f).val.base = β.val.base
h :
  ∀ (r : ↑R),
    f ≫ X.presheaf.map (homOfLE (_ : β⁻¹ᵁ basicOpen r ≤ ⊤)).op =
      toOpen (↑R) (basicOpen r) ≫ β.val.c.app (op (basicOpen r))
⊢ toΓSpec X ≫ Spec.locallyRingedSpaceMap f = β

Next tactic:
ext1
theorem comp_ring_hom_ext {X : LocallyRingedSpace} {R : CommRingCat} {f : R ⟶ Γ.obj (op X)}
    {β : X ⟶ Spec.locallyRingedSpaceObj R}
    (w : X.toΓSpec.1.base ≫ (Spec.locallyRingedSpaceMap f).1.base = β.1.base)
    (h :
      ∀ r : R,
        f ≫ X.presheaf.map (homOfLE le_top : (Opens.map β.1.base).obj (basicOpen r) ⟶ _).op =
          toOpen R (basicOpen r) ≫ β.1.c.app (op (basicOpen r))) :
    X.toΓSpec ≫ Spec.locallyRingedSpaceMap f = β := by
  ext1
  -- Porting note : need more hand holding here
  

Proof state:
case h
X✝ : LocallyRingedSpace
r : ↑(Γ.obj (op X✝))
X : LocallyRingedSpace
R : CommRingCat
f : R ⟶ Γ.obj (op X)
β : X ⟶ Spec.locallyRingedSpaceObj R
w : (toΓSpec X).val.base ≫ (Spec.locallyRingedSpaceMap f).val.base = β.val.base
h :
  ∀ (r : ↑R),
    f ≫ X.presheaf.map (homOfLE (_ : β⁻¹ᵁ basicOpen r ≤ ⊤)).op =
      toOpen (↑R) (basicOpen r) ≫ β.val.c.app (op (basicOpen r))
⊢ (toΓSpec X ≫ Spec.locallyRingedSpaceMap f).val = β.val

Next tactic:
change (X.toΓSpec.1 ≫ _).base = _ at w
theorem comp_ring_hom_ext {X : LocallyRingedSpace} {R : CommRingCat} {f : R ⟶ Γ.obj (op X)}
    {β : X ⟶ Spec.locallyRingedSpaceObj R}
    (w : X.toΓSpec.1.base ≫ (Spec.locallyRingedSpaceMap f).1.base = β.1.base)
    (h :
      ∀ r : R,
        f ≫ X.presheaf.map (homOfLE le_top : (Opens.map β.1.base).obj (basicOpen r) ⟶ _).op =
          toOpen R (basicOpen r) ≫ β.1.c.app (op (basicOpen r))) :
    X.toΓSpec ≫ Spec.locallyRingedSpaceMap f = β := by
  ext1
  -- Porting note : need more hand holding here
  change (X.toΓSpec.1 ≫ _).base = _ at w
  

Proof state:
case h
X✝ : LocallyRingedSpace
r : ↑(Γ.obj (op X✝))
X : LocallyRingedSpace
R : CommRingCat
f : R ⟶ Γ.obj (op X)
β : X ⟶ Spec.locallyRingedSpaceObj R
h :
  ∀ (r : ↑R),
    f ≫ X.presheaf.map (homOfLE (_ : β⁻¹ᵁ basicOpen r ≤ ⊤)).op =
      toOpen (↑R) (basicOpen r) ≫ β.val.c.app (op (basicOpen r))
w : ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base = β.val.base
⊢ (toΓSpec X ≫ Spec.locallyRingedSpaceMap f).val = β.val

Next tactic:
apply Spec.basicOpen_hom_ext w
theorem comp_ring_hom_ext {X : LocallyRingedSpace} {R : CommRingCat} {f : R ⟶ Γ.obj (op X)}
    {β : X ⟶ Spec.locallyRingedSpaceObj R}
    (w : X.toΓSpec.1.base ≫ (Spec.locallyRingedSpaceMap f).1.base = β.1.base)
    (h :
      ∀ r : R,
        f ≫ X.presheaf.map (homOfLE le_top : (Opens.map β.1.base).obj (basicOpen r) ⟶ _).op =
          toOpen R (basicOpen r) ≫ β.1.c.app (op (basicOpen r))) :
    X.toΓSpec ≫ Spec.locallyRingedSpaceMap f = β := by
  ext1
  -- Porting note : need more hand holding here
  change (X.toΓSpec.1 ≫ _).base = _ at w
  apply Spec.basicOpen_hom_ext w
  

Proof state:
case h
X✝ : LocallyRingedSpace
r : ↑(Γ.obj (op X✝))
X : LocallyRingedSpace
R : CommRingCat
f : R ⟶ Γ.obj (op X)
β : X ⟶ Spec.locallyRingedSpaceObj R
h :
  ∀ (r : ↑R),
    f ≫ X.presheaf.map (homOfLE (_ : β⁻¹ᵁ basicOpen r ≤ ⊤)).op =
      toOpen (↑R) (basicOpen r) ≫ β.val.c.app (op (basicOpen r))
w : ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base = β.val.base
⊢ ∀ (r : ↑R),
    let U := basicOpen r;
    (toOpen (↑R) U ≫ ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).c.app (op U)) ≫
        X.presheaf.map
          (eqToHom
            (_ :
              (Opens.map ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base).op.obj (op U) =
                (Opens.map β.val.base).op.obj (op U))) =
      toOpen (↑R) U ≫ β.val.c.app (op U)

Next tactic:
intro r U
theorem comp_ring_hom_ext {X : LocallyRingedSpace} {R : CommRingCat} {f : R ⟶ Γ.obj (op X)}
    {β : X ⟶ Spec.locallyRingedSpaceObj R}
    (w : X.toΓSpec.1.base ≫ (Spec.locallyRingedSpaceMap f).1.base = β.1.base)
    (h :
      ∀ r : R,
        f ≫ X.presheaf.map (homOfLE le_top : (Opens.map β.1.base).obj (basicOpen r) ⟶ _).op =
          toOpen R (basicOpen r) ≫ β.1.c.app (op (basicOpen r))) :
    X.toΓSpec ≫ Spec.locallyRingedSpaceMap f = β := by
  ext1
  -- Porting note : need more hand holding here
  change (X.toΓSpec.1 ≫ _).base = _ at w
  apply Spec.basicOpen_hom_ext w
  intro r U
  -- Porting note : changed `rw` to `erw`
  

Proof state:
case h
X✝ : LocallyRingedSpace
r✝ : ↑(Γ.obj (op X✝))
X : LocallyRingedSpace
R : CommRingCat
f : R ⟶ Γ.obj (op X)
β : X ⟶ Spec.locallyRingedSpaceObj R
h :
  ∀ (r : ↑R),
    f ≫ X.presheaf.map (homOfLE (_ : β⁻¹ᵁ basicOpen r ≤ ⊤)).op =
      toOpen (↑R) (basicOpen r) ≫ β.val.c.app (op (basicOpen r))
w : ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base = β.val.base
r : ↑R
U : Opens (PrimeSpectrum ↑R) := basicOpen r
⊢ (toOpen (↑R) U ≫ ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).c.app (op U)) ≫
      X.presheaf.map
        (eqToHom
          (_ :
            (Opens.map ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base).op.obj (op U) =
              (Opens.map β.val.base).op.obj (op U))) =
    toOpen (↑R) U ≫ β.val.c.app (op U)

Next tactic:
erw [LocallyRingedSpace.comp_val_c_app]
theorem comp_ring_hom_ext {X : LocallyRingedSpace} {R : CommRingCat} {f : R ⟶ Γ.obj (op X)}
    {β : X ⟶ Spec.locallyRingedSpaceObj R}
    (w : X.toΓSpec.1.base ≫ (Spec.locallyRingedSpaceMap f).1.base = β.1.base)
    (h :
      ∀ r : R,
        f ≫ X.presheaf.map (homOfLE le_top : (Opens.map β.1.base).obj (basicOpen r) ⟶ _).op =
          toOpen R (basicOpen r) ≫ β.1.c.app (op (basicOpen r))) :
    X.toΓSpec ≫ Spec.locallyRingedSpaceMap f = β := by
  ext1
  -- Porting note : need more hand holding here
  change (X.toΓSpec.1 ≫ _).base = _ at w
  apply Spec.basicOpen_hom_ext w
  intro r U
  -- Porting note : changed `rw` to `erw`
  erw [LocallyRingedSpace.comp_val_c_app]
  

Proof state:
case h
X✝ : LocallyRingedSpace
r✝ : ↑(Γ.obj (op X✝))
X : LocallyRingedSpace
R : CommRingCat
f : R ⟶ Γ.obj (op X)
β : X ⟶ Spec.locallyRingedSpaceObj R
h :
  ∀ (r : ↑R),
    f ≫ X.presheaf.map (homOfLE (_ : β⁻¹ᵁ basicOpen r ≤ ⊤)).op =
      toOpen (↑R) (basicOpen r) ≫ β.val.c.app (op (basicOpen r))
w : ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base = β.val.base
r : ↑R
U : Opens (PrimeSpectrum ↑R) := basicOpen r
⊢ (toOpen (↑R) U ≫
        (Spec.locallyRingedSpaceMap f).val.c.app (op U) ≫
          (toΓSpec X).val.c.app (op (Spec.locallyRingedSpaceMap f⁻¹ᵁ (op U).unop))) ≫
      X.presheaf.map
        (eqToHom
          (_ :
            (Opens.map ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base).op.obj (op U) =
              (Opens.map β.val.base).op.obj (op U))) =
    toOpen (↑R) U ≫ β.val.c.app (op U)

Next tactic:
erw [toOpen_comp_comap_assoc]
theorem comp_ring_hom_ext {X : LocallyRingedSpace} {R : CommRingCat} {f : R ⟶ Γ.obj (op X)}
    {β : X ⟶ Spec.locallyRingedSpaceObj R}
    (w : X.toΓSpec.1.base ≫ (Spec.locallyRingedSpaceMap f).1.base = β.1.base)
    (h :
      ∀ r : R,
        f ≫ X.presheaf.map (homOfLE le_top : (Opens.map β.1.base).obj (basicOpen r) ⟶ _).op =
          toOpen R (basicOpen r) ≫ β.1.c.app (op (basicOpen r))) :
    X.toΓSpec ≫ Spec.locallyRingedSpaceMap f = β := by
  ext1
  -- Porting note : need more hand holding here
  change (X.toΓSpec.1 ≫ _).base = _ at w
  apply Spec.basicOpen_hom_ext w
  intro r U
  -- Porting note : changed `rw` to `erw`
  erw [LocallyRingedSpace.comp_val_c_app]
  erw [toOpen_comp_comap_assoc]
  

Proof state:
case h
X✝ : LocallyRingedSpace
r✝ : ↑(Γ.obj (op X✝))
X : LocallyRingedSpace
R : CommRingCat
f : R ⟶ Γ.obj (op X)
β : X ⟶ Spec.locallyRingedSpaceObj R
h :
  ∀ (r : ↑R),
    f ≫ X.presheaf.map (homOfLE (_ : β⁻¹ᵁ basicOpen r ≤ ⊤)).op =
      toOpen (↑R) (basicOpen r) ≫ β.val.c.app (op (basicOpen r))
w : ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base = β.val.base
r : ↑R
U : Opens (PrimeSpectrum ↑R) := basicOpen r
⊢ (CommRingCat.ofHom f ≫
        toOpen (↑(Γ.obj (op X))) ((Opens.comap (PrimeSpectrum.comap f)) U) ≫
          (toΓSpec X).val.c.app (op (Spec.locallyRingedSpaceMap f⁻¹ᵁ (op U).unop))) ≫
      X.presheaf.map
        (eqToHom
          (_ :
            (Opens.map ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base).op.obj (op U) =
              (Opens.map β.val.base).op.obj (op U))) =
    toOpen (↑R) U ≫ β.val.c.app (op U)

Next tactic:
rw [Category.assoc]
theorem comp_ring_hom_ext {X : LocallyRingedSpace} {R : CommRingCat} {f : R ⟶ Γ.obj (op X)}
    {β : X ⟶ Spec.locallyRingedSpaceObj R}
    (w : X.toΓSpec.1.base ≫ (Spec.locallyRingedSpaceMap f).1.base = β.1.base)
    (h :
      ∀ r : R,
        f ≫ X.presheaf.map (homOfLE le_top : (Opens.map β.1.base).obj (basicOpen r) ⟶ _).op =
          toOpen R (basicOpen r) ≫ β.1.c.app (op (basicOpen r))) :
    X.toΓSpec ≫ Spec.locallyRingedSpaceMap f = β := by
  ext1
  -- Porting note : need more hand holding here
  change (X.toΓSpec.1 ≫ _).base = _ at w
  apply Spec.basicOpen_hom_ext w
  intro r U
  -- Porting note : changed `rw` to `erw`
  erw [LocallyRingedSpace.comp_val_c_app]
  erw [toOpen_comp_comap_assoc]
  rw [Category.assoc]
  

Proof state:
case h
X✝ : LocallyRingedSpace
r✝ : ↑(Γ.obj (op X✝))
X : LocallyRingedSpace
R : CommRingCat
f : R ⟶ Γ.obj (op X)
β : X ⟶ Spec.locallyRingedSpaceObj R
h :
  ∀ (r : ↑R),
    f ≫ X.presheaf.map (homOfLE (_ : β⁻¹ᵁ basicOpen r ≤ ⊤)).op =
      toOpen (↑R) (basicOpen r) ≫ β.val.c.app (op (basicOpen r))
w : ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base = β.val.base
r : ↑R
U : Opens (PrimeSpectrum ↑R) := basicOpen r
⊢ CommRingCat.ofHom f ≫
      (toOpen (↑(Γ.obj (op X))) ((Opens.comap (PrimeSpectrum.comap f)) U) ≫
          (toΓSpec X).val.c.app (op (Spec.locallyRingedSpaceMap f⁻¹ᵁ (op U).unop))) ≫
        X.presheaf.map
          (eqToHom
            (_ :
              (Opens.map ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base).op.obj (op U) =
                (Opens.map β.val.base).op.obj (op U))) =
    toOpen (↑R) U ≫ β.val.c.app (op U)

Next tactic:
erw [toΓSpecSheafedSpace_app_spec, ← X.presheaf.map_comp]
theorem comp_ring_hom_ext {X : LocallyRingedSpace} {R : CommRingCat} {f : R ⟶ Γ.obj (op X)}
    {β : X ⟶ Spec.locallyRingedSpaceObj R}
    (w : X.toΓSpec.1.base ≫ (Spec.locallyRingedSpaceMap f).1.base = β.1.base)
    (h :
      ∀ r : R,
        f ≫ X.presheaf.map (homOfLE le_top : (Opens.map β.1.base).obj (basicOpen r) ⟶ _).op =
          toOpen R (basicOpen r) ≫ β.1.c.app (op (basicOpen r))) :
    X.toΓSpec ≫ Spec.locallyRingedSpaceMap f = β := by
  ext1
  -- Porting note : need more hand holding here
  change (X.toΓSpec.1 ≫ _).base = _ at w
  apply Spec.basicOpen_hom_ext w
  intro r U
  -- Porting note : changed `rw` to `erw`
  erw [LocallyRingedSpace.comp_val_c_app]
  erw [toOpen_comp_comap_assoc]
  rw [Category.assoc]
  erw [toΓSpecSheafedSpace_app_spec, ← X.presheaf.map_comp]
  

Proof state:
case h
X✝ : LocallyRingedSpace
r✝ : ↑(Γ.obj (op X✝))
X : LocallyRingedSpace
R : CommRingCat
f : R ⟶ Γ.obj (op X)
β : X ⟶ Spec.locallyRingedSpaceObj R
h :
  ∀ (r : ↑R),
    f ≫ X.presheaf.map (homOfLE (_ : β⁻¹ᵁ basicOpen r ≤ ⊤)).op =
      toOpen (↑R) (basicOpen r) ≫ β.val.c.app (op (basicOpen r))
w : ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base = β.val.base
r : ↑R
U : Opens (PrimeSpectrum ↑R) := basicOpen r
⊢ CommRingCat.ofHom f ≫
      X.presheaf.map
        ((Opens.leTop (toΓSpecMapBasicOpen X (f r))).op ≫
          eqToHom
            (_ :
              (Opens.map ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base).op.obj (op U) =
                (Opens.map β.val.base).op.obj (op U))) =
    toOpen (↑R) U ≫ β.val.c.app (op U)

Next tactic:
convert h r using 1
/-- `toSpecΓ _` is an isomorphism so these are mutually two-sided inverses. -/
theorem Γ_Spec_left_triangle : toSpecΓ (Γ.obj (op X)) ≫ X.toΓSpec.1.c.app (op ⊤) = 𝟙 _ := by
  

Proof state:
X : LocallyRingedSpace
r : ↑(Γ.obj (op X))
⊢ toSpecΓ (Γ.obj (op X)) ≫ (toΓSpec X).val.c.app (op ⊤) = 𝟙 (Γ.obj (op X))

Next tactic:
unfold toSpecΓ
/-- `toSpecΓ _` is an isomorphism so these are mutually two-sided inverses. -/
theorem Γ_Spec_left_triangle : toSpecΓ (Γ.obj (op X)) ≫ X.toΓSpec.1.c.app (op ⊤) = 𝟙 _ := by
  unfold toSpecΓ
  

Proof state:
X : LocallyRingedSpace
r : ↑(Γ.obj (op X))
⊢ toOpen ↑(Γ.obj (op X)) ⊤ ≫ (toΓSpec X).val.c.app (op ⊤) = 𝟙 (Γ.obj (op X))

Next tactic:
rw [← toOpen_res _ (basicOpen (1 : Γ.obj (op X))) ⊤ (eqToHom basicOpen_one.symm)]
/-- `toSpecΓ _` is an isomorphism so these are mutually two-sided inverses. -/
theorem Γ_Spec_left_triangle : toSpecΓ (Γ.obj (op X)) ≫ X.toΓSpec.1.c.app (op ⊤) = 𝟙 _ := by
  unfold toSpecΓ
  rw [← toOpen_res _ (basicOpen (1 : Γ.obj (op X))) ⊤ (eqToHom basicOpen_one.symm)]
  

Proof state:
X : LocallyRingedSpace
r : ↑(Γ.obj (op X))
⊢ (toOpen (↑(Γ.obj (op X))) (basicOpen 1) ≫
        (structureSheaf ↑(Γ.obj (op X))).val.map (eqToHom (_ : ⊤ = basicOpen 1)).op) ≫
      (toΓSpec X).val.c.app (op ⊤) =
    𝟙 (Γ.obj (op X))

Next tactic:
erw [Category.assoc]
/-- `toSpecΓ _` is an isomorphism so these are mutually two-sided inverses. -/
theorem Γ_Spec_left_triangle : toSpecΓ (Γ.obj (op X)) ≫ X.toΓSpec.1.c.app (op ⊤) = 𝟙 _ := by
  unfold toSpecΓ
  rw [← toOpen_res _ (basicOpen (1 : Γ.obj (op X))) ⊤ (eqToHom basicOpen_one.symm)]
  erw [Category.assoc]
  

Proof state:
X : LocallyRingedSpace
r : ↑(Γ.obj (op X))
⊢ toOpen (↑(Γ.obj (op X))) (basicOpen 1) ≫
      (structureSheaf ↑(Γ.obj (op X))).val.map (eqToHom (_ : ⊤ = basicOpen 1)).op ≫ (toΓSpec X).val.c.app (op ⊤) =
    𝟙 (Γ.obj (op X))

Next tactic:
rw [NatTrans.naturality, ← Category.assoc]
/-- `toSpecΓ _` is an isomorphism so these are mutually two-sided inverses. -/
theorem Γ_Spec_left_triangle : toSpecΓ (Γ.obj (op X)) ≫ X.toΓSpec.1.c.app (op ⊤) = 𝟙 _ := by
  unfold toSpecΓ
  rw [← toOpen_res _ (basicOpen (1 : Γ.obj (op X))) ⊤ (eqToHom basicOpen_one.symm)]
  erw [Category.assoc]
  rw [NatTrans.naturality, ← Category.assoc]
  

Proof state:
X : LocallyRingedSpace
r : ↑(Γ.obj (op X))
⊢ (toOpen (↑(Γ.obj (op X))) (basicOpen 1) ≫ (toΓSpec X).val.c.app (op (basicOpen 1))) ≫
      ((toΓSpec X).val.base _* X.presheaf).map (eqToHom (_ : ⊤ = basicOpen 1)).op =
    𝟙 (Γ.obj (op X))

Next tactic:
erw [X.toΓSpecSheafedSpace_app_spec 1, ← Functor.map_comp]
/-- `toSpecΓ _` is an isomorphism so these are mutually two-sided inverses. -/
theorem Γ_Spec_left_triangle : toSpecΓ (Γ.obj (op X)) ≫ X.toΓSpec.1.c.app (op ⊤) = 𝟙 _ := by
  unfold toSpecΓ
  rw [← toOpen_res _ (basicOpen (1 : Γ.obj (op X))) ⊤ (eqToHom basicOpen_one.symm)]
  erw [Category.assoc]
  rw [NatTrans.naturality, ← Category.assoc]
  erw [X.toΓSpecSheafedSpace_app_spec 1, ← Functor.map_comp]
  

Proof state:
X : LocallyRingedSpace
r : ↑(Γ.obj (op X))
⊢ X.presheaf.map
      ((Opens.leTop (toΓSpecMapBasicOpen X 1)).op ≫
        (Opens.map (toΓSpec X).val.base).op.map (eqToHom (_ : ⊤ = basicOpen 1)).op) =
    𝟙 (Γ.obj (op X))

Next tactic:
convert eqToHom_map X.presheaf _
/-- `toSpecΓ _` is an isomorphism so these are mutually two-sided inverses. -/
theorem Γ_Spec_left_triangle : toSpecΓ (Γ.obj (op X)) ≫ X.toΓSpec.1.c.app (op ⊤) = 𝟙 _ := by
  unfold toSpecΓ
  rw [← toOpen_res _ (basicOpen (1 : Γ.obj (op X))) ⊤ (eqToHom basicOpen_one.symm)]
  erw [Category.assoc]
  rw [NatTrans.naturality, ← Category.assoc]
  erw [X.toΓSpecSheafedSpace_app_spec 1, ← Functor.map_comp]
  convert eqToHom_map X.presheaf _; 

Proof state:
case convert_3
X : LocallyRingedSpace
r : ↑(Γ.obj (op X))
⊢ op ⊤ = (Opens.map (toΓSpec X).val.base).op.obj (op ⊤)

Next tactic:
rfl
/-- The unit as a natural transformation. -/
def identityToΓSpec : 𝟭 LocallyRingedSpace.{u} ⟶ Γ.rightOp ⋙ Spec.toLocallyRingedSpace where
  app := LocallyRingedSpace.toΓSpec
  naturality X Y f := by
    

Proof state:
X Y : LocallyRingedSpace
f : X ⟶ Y
⊢ (𝟭 LocallyRingedSpace).map f ≫ toΓSpec Y = toΓSpec X ≫ (Γ.rightOp ⋙ Spec.toLocallyRingedSpace).map f

Next tactic:
symm
/-- The unit as a natural transformation. -/
def identityToΓSpec : 𝟭 LocallyRingedSpace.{u} ⟶ Γ.rightOp ⋙ Spec.toLocallyRingedSpace where
  app := LocallyRingedSpace.toΓSpec
  naturality X Y f := by
    symm
    

Proof state:
X Y : LocallyRingedSpace
f : X ⟶ Y
⊢ toΓSpec X ≫ (Γ.rightOp ⋙ Spec.toLocallyRingedSpace).map f = (𝟭 LocallyRingedSpace).map f ≫ toΓSpec Y

Next tactic:
apply LocallyRingedSpace.comp_ring_hom_ext
/-- The unit as a natural transformation. -/
def identityToΓSpec : 𝟭 LocallyRingedSpace.{u} ⟶ Γ.rightOp ⋙ Spec.toLocallyRingedSpace where
  app := LocallyRingedSpace.toΓSpec
  naturality X Y f := by
    symm
    apply LocallyRingedSpace.comp_ring_hom_ext
    · 

Proof state:
case w
X Y : LocallyRingedSpace
f : X ⟶ Y
⊢ (toΓSpec ((𝟭 LocallyRingedSpace).obj X)).val.base ≫ (Spec.locallyRingedSpaceMap (Γ.rightOp.map f).unop).val.base =
    ((𝟭 LocallyRingedSpace).map f ≫ toΓSpec Y).val.base

Next tactic:
ext1 x
/-- The unit as a natural transformation. -/
def identityToΓSpec : 𝟭 LocallyRingedSpace.{u} ⟶ Γ.rightOp ⋙ Spec.toLocallyRingedSpace where
  app := LocallyRingedSpace.toΓSpec
  naturality X Y f := by
    symm
    apply LocallyRingedSpace.comp_ring_hom_ext
    · ext1 x
      

Proof state:
case w.w
X Y : LocallyRingedSpace
f : X ⟶ Y
x : (forget TopCat).obj ↑((𝟭 LocallyRingedSpace).obj X).toPresheafedSpace
⊢ ((toΓSpec ((𝟭 LocallyRingedSpace).obj X)).val.base ≫ (Spec.locallyRingedSpaceMap (Γ.rightOp.map f).unop).val.base) x =
    ((𝟭 LocallyRingedSpace).map f ≫ toΓSpec Y).val.base x

Next tactic:
dsimp [Spec.topMap, LocallyRingedSpace.toΓSpecFun]
/-- The unit as a natural transformation. -/
def identityToΓSpec : 𝟭 LocallyRingedSpace.{u} ⟶ Γ.rightOp ⋙ Spec.toLocallyRingedSpace where
  app := LocallyRingedSpace.toΓSpec
  naturality X Y f := by
    symm
    apply LocallyRingedSpace.comp_ring_hom_ext
    · ext1 x
      dsimp [Spec.topMap, LocallyRingedSpace.toΓSpecFun]
      --Porting Note: Had to add the next four lines
      

Proof state:
case w.w
X Y : LocallyRingedSpace
f : X ⟶ Y
x : (forget TopCat).obj ↑((𝟭 LocallyRingedSpace).obj X).toPresheafedSpace
⊢ (toΓSpecBase X ≫ PrimeSpectrum.comap (f.val.c.app (op ⊤))) x = (f.val.base ≫ toΓSpecBase Y) x

Next tactic:
rw [comp_apply, comp_apply]
/-- The unit as a natural transformation. -/
def identityToΓSpec : 𝟭 LocallyRingedSpace.{u} ⟶ Γ.rightOp ⋙ Spec.toLocallyRingedSpace where
  app := LocallyRingedSpace.toΓSpec
  naturality X Y f := by
    symm
    apply LocallyRingedSpace.comp_ring_hom_ext
    · ext1 x
      dsimp [Spec.topMap, LocallyRingedSpace.toΓSpecFun]
      --Porting Note: Had to add the next four lines
      rw [comp_apply, comp_apply]
      

Proof state:
case w.w
X Y : LocallyRingedSpace
f : X ⟶ Y
x : (forget TopCat).obj ↑((𝟭 LocallyRingedSpace).obj X).toPresheafedSpace
⊢ (PrimeSpectrum.comap (f.val.c.app (op ⊤))) ((toΓSpecBase X) x) = (toΓSpecBase Y) (f.val.base x)

Next tactic:
dsimp [toΓSpecBase]
/-- The unit as a natural transformation. -/
def identityToΓSpec : 𝟭 LocallyRingedSpace.{u} ⟶ Γ.rightOp ⋙ Spec.toLocallyRingedSpace where
  app := LocallyRingedSpace.toΓSpec
  naturality X Y f := by
    symm
    apply LocallyRingedSpace.comp_ring_hom_ext
    · ext1 x
      dsimp [Spec.topMap, LocallyRingedSpace.toΓSpecFun]
      --Porting Note: Had to add the next four lines
      rw [comp_apply, comp_apply]
      dsimp [toΓSpecBase]
      -- The next six lines were `rw [ContinuousMap.coe_mk, ContinuousMap.coe_mk]` before
      -- leanprover/lean4#2644
      

Proof state:
case w.w
X Y : LocallyRingedSpace
f : X ⟶ Y
x : (forget TopCat).obj ↑((𝟭 LocallyRingedSpace).obj X).toPresheafedSpace
⊢ (PrimeSpectrum.comap (f.val.c.app (op ⊤))) ((ContinuousMap.mk (toΓSpecFun X)) x) =
    (ContinuousMap.mk (toΓSpecFun Y)) (f.val.base x)

Next tactic:
have : (ContinuousMap.mk (toΓSpecFun Y) (toΓSpec_continuous _)) (f.val.base x)
        = toΓSpecFun Y (f.val.base x) := by rw [ContinuousMap.coe_mk]
/-- The unit as a natural transformation. -/
def identityToΓSpec : 𝟭 LocallyRingedSpace.{u} ⟶ Γ.rightOp ⋙ Spec.toLocallyRingedSpace where
  app := LocallyRingedSpace.toΓSpec
  naturality X Y f := by
    symm
    apply LocallyRingedSpace.comp_ring_hom_ext
    · ext1 x
      dsimp [Spec.topMap, LocallyRingedSpace.toΓSpecFun]
      --Porting Note: Had to add the next four lines
      rw [comp_apply, comp_apply]
      dsimp [toΓSpecBase]
      -- The next six lines were `rw [ContinuousMap.coe_mk, ContinuousMap.coe_mk]` before
      -- leanprover/lean4#2644
      have : (ContinuousMap.mk (toΓSpecFun Y) (toΓSpec_continuous _)) (f.val.base x)
        = toΓSpecFun Y (f.val.base x) := by 

Proof state:
X Y : LocallyRingedSpace
f : X ⟶ Y
x : (forget TopCat).obj ↑((𝟭 LocallyRingedSpace).obj X).toPresheafedSpace
⊢ (ContinuousMap.mk (toΓSpecFun Y)) (f.val.base x) = toΓSpecFun Y (f.val.base x)

Next tactic:
rw [ContinuousMap.coe_mk]
/-- The unit as a natural transformation. -/
def identityToΓSpec : 𝟭 LocallyRingedSpace.{u} ⟶ Γ.rightOp ⋙ Spec.toLocallyRingedSpace where
  app := LocallyRingedSpace.toΓSpec
  naturality X Y f := by
    symm
    apply LocallyRingedSpace.comp_ring_hom_ext
    · ext1 x
      dsimp [Spec.topMap, LocallyRingedSpace.toΓSpecFun]
      --Porting Note: Had to add the next four lines
      rw [comp_apply, comp_apply]
      dsimp [toΓSpecBase]
      -- The next six lines were `rw [ContinuousMap.coe_mk, ContinuousMap.coe_mk]` before
      -- leanprover/lean4#2644
      have : (ContinuousMap.mk (toΓSpecFun Y) (toΓSpec_continuous _)) (f.val.base x)
        = toΓSpecFun Y (f.val.base x) := by rw [ContinuousMap.coe_mk]
      

Proof state:
case w.w
X Y : LocallyRingedSpace
f : X ⟶ Y
x : (forget TopCat).obj ↑((𝟭 LocallyRingedSpace).obj X).toPresheafedSpace
this : (ContinuousMap.mk (toΓSpecFun Y)) (f.val.base x) = toΓSpecFun Y (f.val.base x)
⊢ (PrimeSpectrum.comap (f.val.c.app (op ⊤))) ((ContinuousMap.mk (toΓSpecFun X)) x) =
    (ContinuousMap.mk (toΓSpecFun Y)) (f.val.base x)

Next tactic:
erw [this]