l3lab/ntp-mathlib huggingface dataset:
protected theorem isCompact :
    IsCompact (U : Set X) := by
  convert @IsCompact.image _ _ _ _ Set.univ hU.fromSpec.1.base PrimeSpectrum.compactSpace.1
    ((fromSpec hU).val.base.2) -- Porting note : `continuity` can't do this
  convert hU.fromSpec_range.symm
  

Proof state:
case h.e'_3.h
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
e_1✝¹ : ↑↑X.toPresheafedSpace = (forget TopCat).obj ↑X.toPresheafedSpace
e_1✝ : Set ↑↑X.toPresheafedSpace = Set ((forget TopCat).obj ↑X.toPresheafedSpace)
⊢ ⇑(fromSpec hU).val.base '' Set.univ = Set.range ⇑(fromSpec hU).val.base

Next tactic:
exact Set.image_univ
theorem imageIsOpenImmersion (f : X ⟶ Y) [H : IsOpenImmersion f] :
    IsAffineOpen (f.opensFunctor.obj U) := by
  

Proof state:
X Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f✝ : ↑(X.presheaf.obj (op U))
f : X ⟶ Y
H : IsOpenImmersion f
⊢ IsAffineOpen ((Scheme.Hom.opensFunctor f).obj U)

Next tactic:
have : IsAffine _ := hU
theorem imageIsOpenImmersion (f : X ⟶ Y) [H : IsOpenImmersion f] :
    IsAffineOpen (f.opensFunctor.obj U) := by
  have : IsAffine _ := hU
  

Proof state:
X Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f✝ : ↑(X.presheaf.obj (op U))
f : X ⟶ Y
H : IsOpenImmersion f
this : IsAffine (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)))
⊢ IsAffineOpen ((Scheme.Hom.opensFunctor f).obj U)

Next tactic:
convert rangeIsAffineOpenOfOpenImmersion (X.ofRestrict U.openEmbedding ≫ f)
theorem imageIsOpenImmersion (f : X ⟶ Y) [H : IsOpenImmersion f] :
    IsAffineOpen (f.opensFunctor.obj U) := by
  have : IsAffine _ := hU
  convert rangeIsAffineOpenOfOpenImmersion (X.ofRestrict U.openEmbedding ≫ f)
  

Proof state:
case h.e'_2
X Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f✝ : ↑(X.presheaf.obj (op U))
f : X ⟶ Y
H : IsOpenImmersion f
this : IsAffine (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)))
⊢ (Scheme.Hom.opensFunctor f).obj U =
    Scheme.Hom.opensRange (Scheme.ofRestrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)) ≫ f)

Next tactic:
ext1
theorem imageIsOpenImmersion (f : X ⟶ Y) [H : IsOpenImmersion f] :
    IsAffineOpen (f.opensFunctor.obj U) := by
  have : IsAffine _ := hU
  convert rangeIsAffineOpenOfOpenImmersion (X.ofRestrict U.openEmbedding ≫ f)
  ext1
  

Proof state:
case h.e'_2.h
X Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f✝ : ↑(X.presheaf.obj (op U))
f : X ⟶ Y
H : IsOpenImmersion f
this : IsAffine (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)))
⊢ ↑((Scheme.Hom.opensFunctor f).obj U) =
    ↑(Scheme.Hom.opensRange (Scheme.ofRestrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)) ≫ f))

Next tactic:
exact Set.image_eq_range _ _
theorem _root_.AlgebraicGeometry.Scheme.Hom.isAffineOpen_iff_of_isOpenImmersion
    (f : AlgebraicGeometry.Scheme.Hom X Y) [H : IsOpenImmersion f] {U : Opens X} :
    IsAffineOpen (f.opensFunctor.obj U) ↔ IsAffineOpen U := by
  

Proof state:
X Y : Scheme
U✝ : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U✝
f✝ : ↑(X.presheaf.obj (op U✝))
f : Scheme.Hom X Y
H : IsOpenImmersion f
U : Opens ↑↑X.toPresheafedSpace
⊢ IsAffineOpen ((Scheme.Hom.opensFunctor f).obj U) ↔ IsAffineOpen U

Next tactic:
refine' ⟨fun hU => @isAffineOfIso _ _
    (IsOpenImmersion.isoOfRangeEq (X.ofRestrict U.openEmbedding ≫ f) (Y.ofRestrict _) _).hom ?_ hU,
    fun hU => hU.imageIsOpenImmersion f⟩
theorem _root_.AlgebraicGeometry.Scheme.Hom.isAffineOpen_iff_of_isOpenImmersion
    (f : AlgebraicGeometry.Scheme.Hom X Y) [H : IsOpenImmersion f] {U : Opens X} :
    IsAffineOpen (f.opensFunctor.obj U) ↔ IsAffineOpen U := by
  refine' ⟨fun hU => @isAffineOfIso _ _
    (IsOpenImmersion.isoOfRangeEq (X.ofRestrict U.openEmbedding ≫ f) (Y.ofRestrict _) _).hom ?_ hU,
    fun hU => hU.imageIsOpenImmersion f⟩
  · 

Proof state:
case refine'_1
X Y : Scheme
U✝ : Opens ↑↑X.toPresheafedSpace
hU✝ : IsAffineOpen U✝
f✝ : ↑(X.presheaf.obj (op U✝))
f : Scheme.Hom X Y
H : IsOpenImmersion f
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen ((Scheme.Hom.opensFunctor f).obj U)
⊢ Set.range ⇑(Scheme.ofRestrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)) ≫ f).val.base =
    Set.range ⇑(Scheme.ofRestrict Y (_ : OpenEmbedding ⇑(Opens.inclusion ((Scheme.Hom.opensFunctor f).obj U)))).val.base

Next tactic:
rw [Scheme.comp_val_base, coe_comp, Set.range_comp]
theorem _root_.AlgebraicGeometry.Scheme.Hom.isAffineOpen_iff_of_isOpenImmersion
    (f : AlgebraicGeometry.Scheme.Hom X Y) [H : IsOpenImmersion f] {U : Opens X} :
    IsAffineOpen (f.opensFunctor.obj U) ↔ IsAffineOpen U := by
  refine' ⟨fun hU => @isAffineOfIso _ _
    (IsOpenImmersion.isoOfRangeEq (X.ofRestrict U.openEmbedding ≫ f) (Y.ofRestrict _) _).hom ?_ hU,
    fun hU => hU.imageIsOpenImmersion f⟩
  · rw [Scheme.comp_val_base, coe_comp, Set.range_comp]
    

Proof state:
case refine'_1
X Y : Scheme
U✝ : Opens ↑↑X.toPresheafedSpace
hU✝ : IsAffineOpen U✝
f✝ : ↑(X.presheaf.obj (op U✝))
f : Scheme.Hom X Y
H : IsOpenImmersion f
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen ((Scheme.Hom.opensFunctor f).obj U)
⊢ ⇑f.val.base '' Set.range ⇑(Scheme.ofRestrict X (_ : OpenEmbedding ⇑(Opens.inclusion U))).val.base =
    Set.range ⇑(Scheme.ofRestrict Y (_ : OpenEmbedding ⇑(Opens.inclusion ((Scheme.Hom.opensFunctor f).obj U)))).val.base

Next tactic:
dsimp [Opens.coe_inclusion, Scheme.restrict]
theorem _root_.AlgebraicGeometry.Scheme.Hom.isAffineOpen_iff_of_isOpenImmersion
    (f : AlgebraicGeometry.Scheme.Hom X Y) [H : IsOpenImmersion f] {U : Opens X} :
    IsAffineOpen (f.opensFunctor.obj U) ↔ IsAffineOpen U := by
  refine' ⟨fun hU => @isAffineOfIso _ _
    (IsOpenImmersion.isoOfRangeEq (X.ofRestrict U.openEmbedding ≫ f) (Y.ofRestrict _) _).hom ?_ hU,
    fun hU => hU.imageIsOpenImmersion f⟩
  · rw [Scheme.comp_val_base, coe_comp, Set.range_comp]
    dsimp [Opens.coe_inclusion, Scheme.restrict]
    

Proof state:
case refine'_1
X Y : Scheme
U✝ : Opens ↑↑X.toPresheafedSpace
hU✝ : IsAffineOpen U✝
f✝ : ↑(X.presheaf.obj (op U✝))
f : Scheme.Hom X Y
H : IsOpenImmersion f
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen ((Scheme.Hom.opensFunctor f).obj U)
⊢ ⇑f.val.base '' Set.range Subtype.val = Set.range Subtype.val

Next tactic:
rw [Subtype.range_coe, Subtype.range_coe]
theorem _root_.AlgebraicGeometry.Scheme.Hom.isAffineOpen_iff_of_isOpenImmersion
    (f : AlgebraicGeometry.Scheme.Hom X Y) [H : IsOpenImmersion f] {U : Opens X} :
    IsAffineOpen (f.opensFunctor.obj U) ↔ IsAffineOpen U := by
  refine' ⟨fun hU => @isAffineOfIso _ _
    (IsOpenImmersion.isoOfRangeEq (X.ofRestrict U.openEmbedding ≫ f) (Y.ofRestrict _) _).hom ?_ hU,
    fun hU => hU.imageIsOpenImmersion f⟩
  · rw [Scheme.comp_val_base, coe_comp, Set.range_comp]
    dsimp [Opens.coe_inclusion, Scheme.restrict]
    rw [Subtype.range_coe, Subtype.range_coe]
    

Proof state:
case refine'_1
X Y : Scheme
U✝ : Opens ↑↑X.toPresheafedSpace
hU✝ : IsAffineOpen U✝
f✝ : ↑(X.presheaf.obj (op U✝))
f : Scheme.Hom X Y
H : IsOpenImmersion f
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen ((Scheme.Hom.opensFunctor f).obj U)
⊢ ⇑f.val.base '' ↑U = ↑((Scheme.Hom.opensFunctor f).obj U)

Next tactic:
rfl
theorem _root_.AlgebraicGeometry.Scheme.Hom.isAffineOpen_iff_of_isOpenImmersion
    (f : AlgebraicGeometry.Scheme.Hom X Y) [H : IsOpenImmersion f] {U : Opens X} :
    IsAffineOpen (f.opensFunctor.obj U) ↔ IsAffineOpen U := by
  refine' ⟨fun hU => @isAffineOfIso _ _
    (IsOpenImmersion.isoOfRangeEq (X.ofRestrict U.openEmbedding ≫ f) (Y.ofRestrict _) _).hom ?_ hU,
    fun hU => hU.imageIsOpenImmersion f⟩
  · rw [Scheme.comp_val_base, coe_comp, Set.range_comp]
    dsimp [Opens.coe_inclusion, Scheme.restrict]
    rw [Subtype.range_coe, Subtype.range_coe]
    rfl
  · 

Proof state:
case refine'_2
X Y : Scheme
U✝ : Opens ↑↑X.toPresheafedSpace
hU✝ : IsAffineOpen U✝
f✝ : ↑(X.presheaf.obj (op U✝))
f : Scheme.Hom X Y
H : IsOpenImmersion f
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen ((Scheme.Hom.opensFunctor f).obj U)
⊢ IsIso
    (IsOpenImmersion.isoOfRangeEq (Scheme.ofRestrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)) ≫ f)
        (Scheme.ofRestrict Y (_ : OpenEmbedding ⇑(Opens.inclusion ((Scheme.Hom.opensFunctor f).obj U))))
        (_ :
          Set.range ⇑(Scheme.ofRestrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)) ≫ f).val.base =
            Set.range
              ⇑(Scheme.ofRestrict Y
                      (_ : OpenEmbedding ⇑(Opens.inclusion ((Scheme.Hom.opensFunctor f).obj U)))).val.base)).hom

Next tactic:
infer_instance
theorem fromSpec_base_preimage :
    hU.fromSpec ⁻¹ᵁ U = ⊤ := by
  

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

Next tactic:
ext1
theorem fromSpec_base_preimage :
    hU.fromSpec ⁻¹ᵁ U = ⊤ := by
  ext1
  

Proof state:
case h
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
⊢ ↑(fromSpec hU⁻¹ᵁ U) = ↑⊤

Next tactic:
rw [Opens.map_coe, Opens.coe_top, ← hU.fromSpec_range, ← Set.image_univ]
theorem fromSpec_base_preimage :
    hU.fromSpec ⁻¹ᵁ U = ⊤ := by
  ext1
  rw [Opens.map_coe, Opens.coe_top, ← hU.fromSpec_range, ← Set.image_univ]
  

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

Next tactic:
exact Set.preimage_image_eq _ PresheafedSpace.IsOpenImmersion.base_open.inj
@[nolint unusedHavesSuffices]
theorem SpecΓIdentity_hom_app_fromSpec :
    SpecΓIdentity.hom.app (X.presheaf.obj <| op U) ≫ hU.fromSpec.1.c.app (op U) =
      (𝖲𝗉𝖾𝖼 𝓞ₓ(U)).presheaf.map (eqToHom hU.fromSpec_base_preimage).op := by
  

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

Next tactic:
have : IsAffine _ := hU
@[nolint unusedHavesSuffices]
theorem SpecΓIdentity_hom_app_fromSpec :
    SpecΓIdentity.hom.app (X.presheaf.obj <| op U) ≫ hU.fromSpec.1.c.app (op U) =
      (𝖲𝗉𝖾𝖼 𝓞ₓ(U)).presheaf.map (eqToHom hU.fromSpec_base_preimage).op := by
  have : IsAffine _ := hU
  

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
this : IsAffine (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)))
⊢ SpecΓIdentity.hom.app (X.presheaf.obj (op U)) ≫ (fromSpec hU).val.c.app (op U) =
    (Scheme.Spec.obj (op (X.presheaf.obj (op U)))).presheaf.map (eqToHom (_ : fromSpec hU⁻¹ᵁ U = ⊤)).op

Next tactic:
delta IsAffineOpen.fromSpec Scheme.isoSpec
@[nolint unusedHavesSuffices]
theorem SpecΓIdentity_hom_app_fromSpec :
    SpecΓIdentity.hom.app (X.presheaf.obj <| op U) ≫ hU.fromSpec.1.c.app (op U) =
      (𝖲𝗉𝖾𝖼 𝓞ₓ(U)).presheaf.map (eqToHom hU.fromSpec_base_preimage).op := by
  have : IsAffine _ := hU
  delta IsAffineOpen.fromSpec Scheme.isoSpec
  

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
this : IsAffine (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)))
⊢ SpecΓIdentity.hom.app (X.presheaf.obj (op U)) ≫
      (Scheme.Spec.map
                  (X.presheaf.map
                      (eqToHom (_ : U = (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤)).op).op ≫
                (asIso (ΓSpec.adjunction.unit.app (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U))))).inv ≫
                  Scheme.ιOpens U).val.c.app
        (op U) =
    (Scheme.Spec.obj (op (X.presheaf.obj (op U)))).presheaf.map (eqToHom (_ : fromSpec hU⁻¹ᵁ U = ⊤)).op

Next tactic:
rw [Scheme.comp_val_c_app, Scheme.comp_val_c_app, SpecΓIdentity_hom_app_presheaf_obj,
    Scheme.ofRestrict_val_c_app_self]
@[nolint unusedHavesSuffices]
theorem SpecΓIdentity_hom_app_fromSpec :
    SpecΓIdentity.hom.app (X.presheaf.obj <| op U) ≫ hU.fromSpec.1.c.app (op U) =
      (𝖲𝗉𝖾𝖼 𝓞ₓ(U)).presheaf.map (eqToHom hU.fromSpec_base_preimage).op := by
  have : IsAffine _ := hU
  delta IsAffineOpen.fromSpec Scheme.isoSpec
  rw [Scheme.comp_val_c_app, Scheme.comp_val_c_app, SpecΓIdentity_hom_app_presheaf_obj,
    Scheme.ofRestrict_val_c_app_self]
  

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
this : IsAffine (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)))
⊢ (Scheme.Γ.map
          (Scheme.Spec.map
              (X.presheaf.map
                  (eqToHom (_ : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤ = U)).op).op).op ≫
        (ΓSpec.adjunction.unit.app (X ∣_ᵤ U)).val.c.app (op ⊤) ≫
          X.presheaf.map (eqToHom (_ : U = (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤)).op) ≫
      (X.presheaf.map
            (eqToHom
                (_ :
                  (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj
                      (op ((Opens.map (Opens.inclusion U)).obj U)).unop =
                    U)).op ≫
          (asIso (ΓSpec.adjunction.unit.app (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U))))).inv.val.c.app
            ((Opens.map (Scheme.ιOpens U).val.base).op.obj (op U))) ≫
        (Scheme.Spec.map
                  (X.presheaf.map
                      (eqToHom
                          (_ : U = (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤)).op).op).val.c.app
          ((Opens.map
                  ((asIso
                            (ΓSpec.adjunction.unit.app
                              (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U))))).inv ≫
                        Scheme.ιOpens U).val.base).op.obj
            (op U)) =
    (Scheme.Spec.obj (op (X.presheaf.obj (op U)))).presheaf.map (eqToHom (_ : fromSpec hU⁻¹ᵁ U = ⊤)).op

Next tactic:
simp only [Category.assoc]
@[nolint unusedHavesSuffices]
theorem SpecΓIdentity_hom_app_fromSpec :
    SpecΓIdentity.hom.app (X.presheaf.obj <| op U) ≫ hU.fromSpec.1.c.app (op U) =
      (𝖲𝗉𝖾𝖼 𝓞ₓ(U)).presheaf.map (eqToHom hU.fromSpec_base_preimage).op := by
  have : IsAffine _ := hU
  delta IsAffineOpen.fromSpec Scheme.isoSpec
  rw [Scheme.comp_val_c_app, Scheme.comp_val_c_app, SpecΓIdentity_hom_app_presheaf_obj,
    Scheme.ofRestrict_val_c_app_self]
  simp only [Category.assoc]
  

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
this : IsAffine (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)))
⊢ Scheme.Γ.map
        (Scheme.Spec.map
            (X.presheaf.map
                (eqToHom (_ : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤ = U)).op).op).op ≫
      (ΓSpec.adjunction.unit.app (X ∣_ᵤ U)).val.c.app (op ⊤) ≫
        X.presheaf.map (eqToHom (_ : U = (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤)).op ≫
          X.presheaf.map
              (eqToHom
                  (_ :
                    (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj
                        (op ((Opens.map (Opens.inclusion U)).obj U)).unop =
                      U)).op ≫
            (asIso
                          (ΓSpec.adjunction.unit.app
                            (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U))))).inv.val.c.app
                ((Opens.map (Scheme.ιOpens U).val.base).op.obj (op U)) ≫
              (Scheme.Spec.map
                        (X.presheaf.map
                            (eqToHom
                                (_ :
                                  U = (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤)).op).op).val.c.app
                ((Opens.map
                        ((asIso
                                  (ΓSpec.adjunction.unit.app
                                    (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U))))).inv ≫
                              Scheme.ιOpens U).val.base).op.obj
                  (op U)) =
    (Scheme.Spec.obj (op (X.presheaf.obj (op U)))).presheaf.map (eqToHom (_ : fromSpec hU⁻¹ᵁ U = ⊤)).op

Next tactic:
dsimp only [asIso_inv, Functor.op_obj, unop_op]
@[nolint unusedHavesSuffices]
theorem SpecΓIdentity_hom_app_fromSpec :
    SpecΓIdentity.hom.app (X.presheaf.obj <| op U) ≫ hU.fromSpec.1.c.app (op U) =
      (𝖲𝗉𝖾𝖼 𝓞ₓ(U)).presheaf.map (eqToHom hU.fromSpec_base_preimage).op := by
  have : IsAffine _ := hU
  delta IsAffineOpen.fromSpec Scheme.isoSpec
  rw [Scheme.comp_val_c_app, Scheme.comp_val_c_app, SpecΓIdentity_hom_app_presheaf_obj,
    Scheme.ofRestrict_val_c_app_self]
  simp only [Category.assoc]
  dsimp only [asIso_inv, Functor.op_obj, unop_op]
  

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
this : IsAffine (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)))
⊢ Scheme.Γ.map
        (Scheme.Spec.map
            (X.presheaf.map
                (eqToHom (_ : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤ = U)).op).op).op ≫
      (ΓSpec.adjunction.unit.app (X ∣_ᵤ U)).val.c.app (op ⊤) ≫
        X.presheaf.map (eqToHom (_ : U = (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤)).op ≫
          X.presheaf.map
              (eqToHom
                  (_ :
                    (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj
                        ((Opens.map (Opens.inclusion U)).obj U) =
                      U)).op ≫
            (inv (ΓSpec.adjunction.unit.app (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U))))).val.c.app
                (op (Scheme.ιOpens U⁻¹ᵁ U)) ≫
              (Scheme.Spec.map
                        (X.presheaf.map
                            (eqToHom
                                (_ :
                                  U = (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤)).op).op).val.c.app
                (op
                  ((inv (ΓSpec.adjunction.unit.app (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)))) ≫
                      Scheme.ιOpens U)⁻¹ᵁ
                    U)) =
    (Scheme.Spec.obj (op (X.presheaf.obj (op U)))).presheaf.map (eqToHom (_ : fromSpec hU⁻¹ᵁ U = ⊤)).op

Next tactic:
rw [← Functor.map_comp_assoc, ← op_comp, eqToHom_trans, Scheme.eq_restrict_presheaf_map_eqToHom,
    NatTrans.naturality_assoc, Scheme.inv_val_c_app_top, IsIso.hom_inv_id_assoc]
@[nolint unusedHavesSuffices]
theorem SpecΓIdentity_hom_app_fromSpec :
    SpecΓIdentity.hom.app (X.presheaf.obj <| op U) ≫ hU.fromSpec.1.c.app (op U) =
      (𝖲𝗉𝖾𝖼 𝓞ₓ(U)).presheaf.map (eqToHom hU.fromSpec_base_preimage).op := by
  have : IsAffine _ := hU
  delta IsAffineOpen.fromSpec Scheme.isoSpec
  rw [Scheme.comp_val_c_app, Scheme.comp_val_c_app, SpecΓIdentity_hom_app_presheaf_obj,
    Scheme.ofRestrict_val_c_app_self]
  simp only [Category.assoc]
  dsimp only [asIso_inv, Functor.op_obj, unop_op]
  rw [← Functor.map_comp_assoc, ← op_comp, eqToHom_trans, Scheme.eq_restrict_presheaf_map_eqToHom,
    NatTrans.naturality_assoc, Scheme.inv_val_c_app_top, IsIso.hom_inv_id_assoc]
  

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
this : IsAffine (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)))
⊢ Scheme.Γ.map
        (Scheme.Spec.map
            (X.presheaf.map
                (eqToHom (_ : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤ = U)).op).op).op ≫
      ((inv (ΓSpec.adjunction.unit.app (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U))))).val.base _*
              (Scheme.Spec.obj
                  (op
                    (X.presheaf.obj
                      (op ((IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤))))).presheaf).map
          (eqToHom (_ : Scheme.ofRestrict X (_ : OpenEmbedding ⇑(Opens.inclusion U))⁻¹ᵁ U = ⊤)).op ≫
        (Scheme.Spec.map
                  (X.presheaf.map
                      (eqToHom
                          (_ : U = (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U))).obj ⊤)).op).op).val.c.app
          (op
            ((inv (ΓSpec.adjunction.unit.app (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion U)))) ≫
                Scheme.ιOpens U)⁻¹ᵁ
              U)) =
    (Scheme.Spec.obj (op (X.presheaf.obj (op U)))).presheaf.map (eqToHom (_ : fromSpec hU⁻¹ᵁ U = ⊤)).op

Next tactic:
simp only [eqToHom_map, eqToHom_op, Scheme.Spec_map_presheaf_map_eqToHom, eqToHom_trans]
@[elementwise]
theorem fromSpec_app_self :
    hU.fromSpec.1.c.app (op U) = SpecΓIdentity.inv.app (X.presheaf.obj <| op U) ≫
    (𝖲𝗉𝖾𝖼 𝓞ₓ(U)).presheaf.map (eqToHom hU.fromSpec_base_preimage).op := by
  

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

Next tactic:
rw [← hU.SpecΓIdentity_hom_app_fromSpec, ← NatTrans.comp_app_assoc, Iso.inv_hom_id,
    NatTrans.id_app, Category.id_comp]
theorem fromSpec_map_basicOpen' :
    hU.fromSpec ⁻¹ᵁ X.basicOpen f =
      (𝖲𝗉𝖾𝖼 𝓞ₓ(U)).basicOpen (SpecΓIdentity.inv.app (X.presheaf.obj (op U)) f) := by
  

Proof state:
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
⊢ fromSpec hU⁻¹ᵁ X.basicOpen f =
    (Scheme.Spec.obj (op (X.presheaf.obj (op U)))).basicOpen ((SpecΓIdentity.inv.app (X.presheaf.obj (op U))) f)

Next tactic:
rw [Scheme.preimage_basicOpen, hU.fromSpec_app_self]
theorem fromSpec_map_basicOpen' :
    hU.fromSpec ⁻¹ᵁ X.basicOpen f =
      (𝖲𝗉𝖾𝖼 𝓞ₓ(U)).basicOpen (SpecΓIdentity.inv.app (X.presheaf.obj (op U)) f) := by
  rw [Scheme.preimage_basicOpen, hU.fromSpec_app_self]
  

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

Next tactic:
exact Scheme.basicOpen_res_eq _ _ (eqToHom hU.fromSpec_base_preimage).op
theorem fromSpec_map_basicOpen :
    hU.fromSpec ⁻¹ᵁ X.basicOpen f = PrimeSpectrum.basicOpen f := by
  

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

Next tactic:
rw [fromSpec_map_basicOpen', ← basicOpen_eq_of_affine, NatIso.app_inv]
theorem opensFunctor_map_basicOpen :
    hU.fromSpec.opensFunctor.obj (PrimeSpectrum.basicOpen f) = X.basicOpen f := by
  

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

Next tactic:
rw [← hU.fromSpec_map_basicOpen]
theorem opensFunctor_map_basicOpen :
    hU.fromSpec.opensFunctor.obj (PrimeSpectrum.basicOpen f) = X.basicOpen f := by
  rw [← hU.fromSpec_map_basicOpen]
  

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

Next tactic:
ext1
theorem opensFunctor_map_basicOpen :
    hU.fromSpec.opensFunctor.obj (PrimeSpectrum.basicOpen f) = X.basicOpen f := by
  rw [← hU.fromSpec_map_basicOpen]
  ext1
  

Proof state:
case h
X : Scheme
Y : Scheme
U : Opens ↑↑X.toPresheafedSpace
hU : IsAffineOpen U
f : ↑(X.presheaf.obj (op U))
⊢ ↑((Scheme.Hom.opensFunctor (fromSpec hU)).obj (fromSpec hU⁻¹ᵁ X.basicOpen f)) = ↑(X.basicOpen f)

Next tactic:
change hU.fromSpec.val.base '' (hU.fromSpec.val.base ⁻¹' (X.basicOpen f : Set X)) = _