l3lab/ntp-mathlib huggingface dataset:
theorem affineLocally_iff_affineOpens_le (hP : RingHom.RespectsIso @P) {X Y : Scheme} (f : X ⟶ Y) :
    affineLocally (@P) f ↔
    ∀ (U : Y.affineOpens) (V : X.affineOpens) (e : V.1 ≤ (Opens.map f.1.base).obj U.1),
      P (Scheme.Hom.appLe f e) := by
  apply forall_congr'
  intro U
  delta sourceAffineLocally
  simp_rw [op_comp, Scheme.Γ.map_comp, Γ_map_morphismRestrict, Category.assoc, Scheme.Γ_map_op,
    hP.cancel_left_isIso]
  constructor
  · intro H V e
    let U' := (Opens.map f.val.base).obj U.1
    have e' : U'.openEmbedding.isOpenMap.functor.obj ((Opens.map U'.inclusion).obj V.1) = V.1 := by
      ext1; refine' Set.image_preimage_eq_inter_range.trans (Set.inter_eq_left.mpr _)
      erw [Subtype.range_val]
      convert e
    have := H ⟨(Opens.map (X.ofRestrict U'.openEmbedding).1.base).obj V.1, ?h'⟩
    erw [← X.presheaf.map_comp] at this
    rw [← hP.cancel_right_isIso _ (X.presheaf.map (eqToHom _)), Category.assoc,
      ← X.presheaf.map_comp]
    convert this using 1
    dsimp only [Functor.op, unop_op]
    rw [Opens.openEmbedding_obj_top]
    congr 1
    exact e'.symm
    case h' =>
      

Proof state:
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : RingHom.RespectsIso P
X Y : Scheme
f : X ⟶ Y
U : ↑(Scheme.affineOpens Y)
H :
  ∀ (U_1 : ↑(Scheme.affineOpens (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U)))))),
    P
      (f.val.c.app (op ↑U) ≫
        X.presheaf.map
            (eqToHom (_ : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion (f⁻¹ᵁ ↑U)))).obj ⊤ = f⁻¹ᵁ ↑U)).op ≫
          (Scheme.ofRestrict (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U))))
                    (_ : OpenEmbedding ⇑(Opens.inclusion ↑U_1))).val.c.app
            (op ⊤))
V : ↑(Scheme.affineOpens X)
e : ↑V ≤ f⁻¹ᵁ ↑U
U' : Opens ↑↑X.toPresheafedSpace := f⁻¹ᵁ ↑U
e' : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U'))).obj ((Opens.map (Opens.inclusion U')).obj ↑V) = ↑V
⊢ Scheme.ofRestrict X (_ : OpenEmbedding ⇑(Opens.inclusion U'))⁻¹ᵁ ↑V ∈
    Scheme.affineOpens (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U))))

Next tactic:
apply (X.ofRestrict U'.openEmbedding).isAffineOpen_iff_of_isOpenImmersion.mp
theorem affineLocally_iff_affineOpens_le (hP : RingHom.RespectsIso @P) {X Y : Scheme} (f : X ⟶ Y) :
    affineLocally (@P) f ↔
    ∀ (U : Y.affineOpens) (V : X.affineOpens) (e : V.1 ≤ (Opens.map f.1.base).obj U.1),
      P (Scheme.Hom.appLe f e) := by
  apply forall_congr'
  intro U
  delta sourceAffineLocally
  simp_rw [op_comp, Scheme.Γ.map_comp, Γ_map_morphismRestrict, Category.assoc, Scheme.Γ_map_op,
    hP.cancel_left_isIso]
  constructor
  · intro H V e
    let U' := (Opens.map f.val.base).obj U.1
    have e' : U'.openEmbedding.isOpenMap.functor.obj ((Opens.map U'.inclusion).obj V.1) = V.1 := by
      ext1; refine' Set.image_preimage_eq_inter_range.trans (Set.inter_eq_left.mpr _)
      erw [Subtype.range_val]
      convert e
    have := H ⟨(Opens.map (X.ofRestrict U'.openEmbedding).1.base).obj V.1, ?h'⟩
    erw [← X.presheaf.map_comp] at this
    rw [← hP.cancel_right_isIso _ (X.presheaf.map (eqToHom _)), Category.assoc,
      ← X.presheaf.map_comp]
    convert this using 1
    dsimp only [Functor.op, unop_op]
    rw [Opens.openEmbedding_obj_top]
    congr 1
    exact e'.symm
    case h' =>
      apply (X.ofRestrict U'.openEmbedding).isAffineOpen_iff_of_isOpenImmersion.mp
      -- Porting note: was convert V.2
      

Proof state:
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : RingHom.RespectsIso P
X Y : Scheme
f : X ⟶ Y
U : ↑(Scheme.affineOpens Y)
H :
  ∀ (U_1 : ↑(Scheme.affineOpens (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U)))))),
    P
      (f.val.c.app (op ↑U) ≫
        X.presheaf.map
            (eqToHom (_ : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion (f⁻¹ᵁ ↑U)))).obj ⊤ = f⁻¹ᵁ ↑U)).op ≫
          (Scheme.ofRestrict (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U))))
                    (_ : OpenEmbedding ⇑(Opens.inclusion ↑U_1))).val.c.app
            (op ⊤))
V : ↑(Scheme.affineOpens X)
e : ↑V ≤ f⁻¹ᵁ ↑U
U' : Opens ↑↑X.toPresheafedSpace := f⁻¹ᵁ ↑U
e' : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U'))).obj ((Opens.map (Opens.inclusion U')).obj ↑V) = ↑V
⊢ IsAffineOpen
    ((Scheme.Hom.opensFunctor (Scheme.ofRestrict X (_ : OpenEmbedding ⇑(Opens.inclusion U')))).obj
      (Scheme.ofRestrict X (_ : OpenEmbedding ⇑(Opens.inclusion U'))⁻¹ᵁ ↑V))

Next tactic:
erw [e']
theorem affineLocally_iff_affineOpens_le (hP : RingHom.RespectsIso @P) {X Y : Scheme} (f : X ⟶ Y) :
    affineLocally (@P) f ↔
    ∀ (U : Y.affineOpens) (V : X.affineOpens) (e : V.1 ≤ (Opens.map f.1.base).obj U.1),
      P (Scheme.Hom.appLe f e) := by
  apply forall_congr'
  intro U
  delta sourceAffineLocally
  simp_rw [op_comp, Scheme.Γ.map_comp, Γ_map_morphismRestrict, Category.assoc, Scheme.Γ_map_op,
    hP.cancel_left_isIso]
  constructor
  · intro H V e
    let U' := (Opens.map f.val.base).obj U.1
    have e' : U'.openEmbedding.isOpenMap.functor.obj ((Opens.map U'.inclusion).obj V.1) = V.1 := by
      ext1; refine' Set.image_preimage_eq_inter_range.trans (Set.inter_eq_left.mpr _)
      erw [Subtype.range_val]
      convert e
    have := H ⟨(Opens.map (X.ofRestrict U'.openEmbedding).1.base).obj V.1, ?h'⟩
    erw [← X.presheaf.map_comp] at this
    rw [← hP.cancel_right_isIso _ (X.presheaf.map (eqToHom _)), Category.assoc,
      ← X.presheaf.map_comp]
    convert this using 1
    dsimp only [Functor.op, unop_op]
    rw [Opens.openEmbedding_obj_top]
    congr 1
    exact e'.symm
    case h' =>
      apply (X.ofRestrict U'.openEmbedding).isAffineOpen_iff_of_isOpenImmersion.mp
      -- Porting note: was convert V.2
      erw [e']
      

Proof state:
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : RingHom.RespectsIso P
X Y : Scheme
f : X ⟶ Y
U : ↑(Scheme.affineOpens Y)
H :
  ∀ (U_1 : ↑(Scheme.affineOpens (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U)))))),
    P
      (f.val.c.app (op ↑U) ≫
        X.presheaf.map
            (eqToHom (_ : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion (f⁻¹ᵁ ↑U)))).obj ⊤ = f⁻¹ᵁ ↑U)).op ≫
          (Scheme.ofRestrict (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U))))
                    (_ : OpenEmbedding ⇑(Opens.inclusion ↑U_1))).val.c.app
            (op ⊤))
V : ↑(Scheme.affineOpens X)
e : ↑V ≤ f⁻¹ᵁ ↑U
U' : Opens ↑↑X.toPresheafedSpace := f⁻¹ᵁ ↑U
e' : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U'))).obj ((Opens.map (Opens.inclusion U')).obj ↑V) = ↑V
⊢ IsAffineOpen ↑V

Next tactic:
apply V.2
theorem affineLocally_iff_affineOpens_le (hP : RingHom.RespectsIso @P) {X Y : Scheme} (f : X ⟶ Y) :
    affineLocally (@P) f ↔
    ∀ (U : Y.affineOpens) (V : X.affineOpens) (e : V.1 ≤ (Opens.map f.1.base).obj U.1),
      P (Scheme.Hom.appLe f e) := by
  apply forall_congr'
  intro U
  delta sourceAffineLocally
  simp_rw [op_comp, Scheme.Γ.map_comp, Γ_map_morphismRestrict, Category.assoc, Scheme.Γ_map_op,
    hP.cancel_left_isIso]
  constructor
  · intro H V e
    let U' := (Opens.map f.val.base).obj U.1
    have e' : U'.openEmbedding.isOpenMap.functor.obj ((Opens.map U'.inclusion).obj V.1) = V.1 := by
      ext1; refine' Set.image_preimage_eq_inter_range.trans (Set.inter_eq_left.mpr _)
      erw [Subtype.range_val]
      convert e
    have := H ⟨(Opens.map (X.ofRestrict U'.openEmbedding).1.base).obj V.1, ?h'⟩
    erw [← X.presheaf.map_comp] at this
    rw [← hP.cancel_right_isIso _ (X.presheaf.map (eqToHom _)), Category.assoc,
      ← X.presheaf.map_comp]
    convert this using 1
    dsimp only [Functor.op, unop_op]
    rw [Opens.openEmbedding_obj_top]
    congr 1
    exact e'.symm
    case h' =>
      apply (X.ofRestrict U'.openEmbedding).isAffineOpen_iff_of_isOpenImmersion.mp
      -- Porting note: was convert V.2
      erw [e']
      apply V.2
  · 

Proof state:
case h.mpr
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : RingHom.RespectsIso P
X Y : Scheme
f : X ⟶ Y
U : ↑(Scheme.affineOpens Y)
⊢ (∀ (V : ↑(Scheme.affineOpens X)) (e : ↑V ≤ f⁻¹ᵁ ↑U), P (Scheme.Hom.appLe f e)) →
    ∀ (U_1 : ↑(Scheme.affineOpens (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U)))))),
      P
        (f.val.c.app (op ↑U) ≫
          X.presheaf.map
              (eqToHom (_ : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion (f⁻¹ᵁ ↑U)))).obj ⊤ = f⁻¹ᵁ ↑U)).op ≫
            (Scheme.ofRestrict (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U))))
                      (_ : OpenEmbedding ⇑(Opens.inclusion ↑U_1))).val.c.app
              (op ⊤))

Next tactic:
intro H V
theorem affineLocally_iff_affineOpens_le (hP : RingHom.RespectsIso @P) {X Y : Scheme} (f : X ⟶ Y) :
    affineLocally (@P) f ↔
    ∀ (U : Y.affineOpens) (V : X.affineOpens) (e : V.1 ≤ (Opens.map f.1.base).obj U.1),
      P (Scheme.Hom.appLe f e) := by
  apply forall_congr'
  intro U
  delta sourceAffineLocally
  simp_rw [op_comp, Scheme.Γ.map_comp, Γ_map_morphismRestrict, Category.assoc, Scheme.Γ_map_op,
    hP.cancel_left_isIso]
  constructor
  · intro H V e
    let U' := (Opens.map f.val.base).obj U.1
    have e' : U'.openEmbedding.isOpenMap.functor.obj ((Opens.map U'.inclusion).obj V.1) = V.1 := by
      ext1; refine' Set.image_preimage_eq_inter_range.trans (Set.inter_eq_left.mpr _)
      erw [Subtype.range_val]
      convert e
    have := H ⟨(Opens.map (X.ofRestrict U'.openEmbedding).1.base).obj V.1, ?h'⟩
    erw [← X.presheaf.map_comp] at this
    rw [← hP.cancel_right_isIso _ (X.presheaf.map (eqToHom _)), Category.assoc,
      ← X.presheaf.map_comp]
    convert this using 1
    dsimp only [Functor.op, unop_op]
    rw [Opens.openEmbedding_obj_top]
    congr 1
    exact e'.symm
    case h' =>
      apply (X.ofRestrict U'.openEmbedding).isAffineOpen_iff_of_isOpenImmersion.mp
      -- Porting note: was convert V.2
      erw [e']
      apply V.2
  · intro H V
    

Proof state:
case h.mpr
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : RingHom.RespectsIso P
X Y : Scheme
f : X ⟶ Y
U : ↑(Scheme.affineOpens Y)
H : ∀ (V : ↑(Scheme.affineOpens X)) (e : ↑V ≤ f⁻¹ᵁ ↑U), P (Scheme.Hom.appLe f e)
V : ↑(Scheme.affineOpens (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U)))))
⊢ P
    (f.val.c.app (op ↑U) ≫
      X.presheaf.map
          (eqToHom (_ : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion (f⁻¹ᵁ ↑U)))).obj ⊤ = f⁻¹ᵁ ↑U)).op ≫
        (Scheme.ofRestrict (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U))))
                  (_ : OpenEmbedding ⇑(Opens.inclusion ↑V))).val.c.app
          (op ⊤))

Next tactic:
specialize H ⟨_, V.2.imageIsOpenImmersion (X.ofRestrict _)⟩ (Subtype.coe_image_subset _ _)
theorem affineLocally_iff_affineOpens_le (hP : RingHom.RespectsIso @P) {X Y : Scheme} (f : X ⟶ Y) :
    affineLocally (@P) f ↔
    ∀ (U : Y.affineOpens) (V : X.affineOpens) (e : V.1 ≤ (Opens.map f.1.base).obj U.1),
      P (Scheme.Hom.appLe f e) := by
  apply forall_congr'
  intro U
  delta sourceAffineLocally
  simp_rw [op_comp, Scheme.Γ.map_comp, Γ_map_morphismRestrict, Category.assoc, Scheme.Γ_map_op,
    hP.cancel_left_isIso]
  constructor
  · intro H V e
    let U' := (Opens.map f.val.base).obj U.1
    have e' : U'.openEmbedding.isOpenMap.functor.obj ((Opens.map U'.inclusion).obj V.1) = V.1 := by
      ext1; refine' Set.image_preimage_eq_inter_range.trans (Set.inter_eq_left.mpr _)
      erw [Subtype.range_val]
      convert e
    have := H ⟨(Opens.map (X.ofRestrict U'.openEmbedding).1.base).obj V.1, ?h'⟩
    erw [← X.presheaf.map_comp] at this
    rw [← hP.cancel_right_isIso _ (X.presheaf.map (eqToHom _)), Category.assoc,
      ← X.presheaf.map_comp]
    convert this using 1
    dsimp only [Functor.op, unop_op]
    rw [Opens.openEmbedding_obj_top]
    congr 1
    exact e'.symm
    case h' =>
      apply (X.ofRestrict U'.openEmbedding).isAffineOpen_iff_of_isOpenImmersion.mp
      -- Porting note: was convert V.2
      erw [e']
      apply V.2
  · intro H V
    specialize H ⟨_, V.2.imageIsOpenImmersion (X.ofRestrict _)⟩ (Subtype.coe_image_subset _ _)
    

Proof state:
case h.mpr
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : RingHom.RespectsIso P
X Y : Scheme
f : X ⟶ Y
U : ↑(Scheme.affineOpens Y)
V : ↑(Scheme.affineOpens (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U)))))
H : P (Scheme.Hom.appLe f (_ : Subtype.val '' ↑↑V ⊆ ↑(f⁻¹ᵁ ↑U)))
⊢ P
    (f.val.c.app (op ↑U) ≫
      X.presheaf.map
          (eqToHom (_ : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion (f⁻¹ᵁ ↑U)))).obj ⊤ = f⁻¹ᵁ ↑U)).op ≫
        (Scheme.ofRestrict (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U))))
                  (_ : OpenEmbedding ⇑(Opens.inclusion ↑V))).val.c.app
          (op ⊤))

Next tactic:
erw [← X.presheaf.map_comp]
theorem affineLocally_iff_affineOpens_le (hP : RingHom.RespectsIso @P) {X Y : Scheme} (f : X ⟶ Y) :
    affineLocally (@P) f ↔
    ∀ (U : Y.affineOpens) (V : X.affineOpens) (e : V.1 ≤ (Opens.map f.1.base).obj U.1),
      P (Scheme.Hom.appLe f e) := by
  apply forall_congr'
  intro U
  delta sourceAffineLocally
  simp_rw [op_comp, Scheme.Γ.map_comp, Γ_map_morphismRestrict, Category.assoc, Scheme.Γ_map_op,
    hP.cancel_left_isIso]
  constructor
  · intro H V e
    let U' := (Opens.map f.val.base).obj U.1
    have e' : U'.openEmbedding.isOpenMap.functor.obj ((Opens.map U'.inclusion).obj V.1) = V.1 := by
      ext1; refine' Set.image_preimage_eq_inter_range.trans (Set.inter_eq_left.mpr _)
      erw [Subtype.range_val]
      convert e
    have := H ⟨(Opens.map (X.ofRestrict U'.openEmbedding).1.base).obj V.1, ?h'⟩
    erw [← X.presheaf.map_comp] at this
    rw [← hP.cancel_right_isIso _ (X.presheaf.map (eqToHom _)), Category.assoc,
      ← X.presheaf.map_comp]
    convert this using 1
    dsimp only [Functor.op, unop_op]
    rw [Opens.openEmbedding_obj_top]
    congr 1
    exact e'.symm
    case h' =>
      apply (X.ofRestrict U'.openEmbedding).isAffineOpen_iff_of_isOpenImmersion.mp
      -- Porting note: was convert V.2
      erw [e']
      apply V.2
  · intro H V
    specialize H ⟨_, V.2.imageIsOpenImmersion (X.ofRestrict _)⟩ (Subtype.coe_image_subset _ _)
    erw [← X.presheaf.map_comp]
    

Proof state:
case h.mpr
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : RingHom.RespectsIso P
X Y : Scheme
f : X ⟶ Y
U : ↑(Scheme.affineOpens Y)
V : ↑(Scheme.affineOpens (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U)))))
H : P (Scheme.Hom.appLe f (_ : Subtype.val '' ↑↑V ⊆ ↑(f⁻¹ᵁ ↑U)))
⊢ P
    (f.val.c.app (op ↑U) ≫
      X.presheaf.map
        ((eqToHom (_ : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion (f⁻¹ᵁ ↑U)))).obj ⊤ = f⁻¹ᵁ ↑U)).op ≫
          (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion (f⁻¹ᵁ ↑U)))).op.map
            ((IsOpenMap.adjunction (_ : IsOpenMap ⇑(Opens.inclusion ↑V))).counit.app (op ⊤).unop).op))

Next tactic:
rw [← hP.cancel_right_isIso _ (X.presheaf.map (eqToHom _)), Category.assoc, ←
      X.presheaf.map_comp]
theorem affineLocally_iff_affineOpens_le (hP : RingHom.RespectsIso @P) {X Y : Scheme} (f : X ⟶ Y) :
    affineLocally (@P) f ↔
    ∀ (U : Y.affineOpens) (V : X.affineOpens) (e : V.1 ≤ (Opens.map f.1.base).obj U.1),
      P (Scheme.Hom.appLe f e) := by
  apply forall_congr'
  intro U
  delta sourceAffineLocally
  simp_rw [op_comp, Scheme.Γ.map_comp, Γ_map_morphismRestrict, Category.assoc, Scheme.Γ_map_op,
    hP.cancel_left_isIso]
  constructor
  · intro H V e
    let U' := (Opens.map f.val.base).obj U.1
    have e' : U'.openEmbedding.isOpenMap.functor.obj ((Opens.map U'.inclusion).obj V.1) = V.1 := by
      ext1; refine' Set.image_preimage_eq_inter_range.trans (Set.inter_eq_left.mpr _)
      erw [Subtype.range_val]
      convert e
    have := H ⟨(Opens.map (X.ofRestrict U'.openEmbedding).1.base).obj V.1, ?h'⟩
    erw [← X.presheaf.map_comp] at this
    rw [← hP.cancel_right_isIso _ (X.presheaf.map (eqToHom _)), Category.assoc,
      ← X.presheaf.map_comp]
    convert this using 1
    dsimp only [Functor.op, unop_op]
    rw [Opens.openEmbedding_obj_top]
    congr 1
    exact e'.symm
    case h' =>
      apply (X.ofRestrict U'.openEmbedding).isAffineOpen_iff_of_isOpenImmersion.mp
      -- Porting note: was convert V.2
      erw [e']
      apply V.2
  · intro H V
    specialize H ⟨_, V.2.imageIsOpenImmersion (X.ofRestrict _)⟩ (Subtype.coe_image_subset _ _)
    erw [← X.presheaf.map_comp]
    rw [← hP.cancel_right_isIso _ (X.presheaf.map (eqToHom _)), Category.assoc, ←
      X.presheaf.map_comp]
    convert H
    · 

Proof state:
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : RingHom.RespectsIso P
X Y : Scheme
f : X ⟶ Y
U : ↑(Scheme.affineOpens Y)
V : ↑(Scheme.affineOpens (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U)))))
H : P (Scheme.Hom.appLe f (_ : Subtype.val '' ↑↑V ⊆ ↑(f⁻¹ᵁ ↑U)))
⊢ (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion (f⁻¹ᵁ ↑U)))).op.obj
      ((IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion ↑V))).op.obj (op ⊤)) =
    op
      ↑{ val := (Scheme.Hom.opensFunctor (Scheme.ofRestrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U))))).obj ↑V,
          property :=
            (_ :
              IsAffineOpen
                ((Scheme.Hom.opensFunctor (Scheme.ofRestrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U))))).obj
                  ↑V)) }

Next tactic:
dsimp only [Functor.op, unop_op]
theorem affineLocally_iff_affineOpens_le (hP : RingHom.RespectsIso @P) {X Y : Scheme} (f : X ⟶ Y) :
    affineLocally (@P) f ↔
    ∀ (U : Y.affineOpens) (V : X.affineOpens) (e : V.1 ≤ (Opens.map f.1.base).obj U.1),
      P (Scheme.Hom.appLe f e) := by
  apply forall_congr'
  intro U
  delta sourceAffineLocally
  simp_rw [op_comp, Scheme.Γ.map_comp, Γ_map_morphismRestrict, Category.assoc, Scheme.Γ_map_op,
    hP.cancel_left_isIso]
  constructor
  · intro H V e
    let U' := (Opens.map f.val.base).obj U.1
    have e' : U'.openEmbedding.isOpenMap.functor.obj ((Opens.map U'.inclusion).obj V.1) = V.1 := by
      ext1; refine' Set.image_preimage_eq_inter_range.trans (Set.inter_eq_left.mpr _)
      erw [Subtype.range_val]
      convert e
    have := H ⟨(Opens.map (X.ofRestrict U'.openEmbedding).1.base).obj V.1, ?h'⟩
    erw [← X.presheaf.map_comp] at this
    rw [← hP.cancel_right_isIso _ (X.presheaf.map (eqToHom _)), Category.assoc,
      ← X.presheaf.map_comp]
    convert this using 1
    dsimp only [Functor.op, unop_op]
    rw [Opens.openEmbedding_obj_top]
    congr 1
    exact e'.symm
    case h' =>
      apply (X.ofRestrict U'.openEmbedding).isAffineOpen_iff_of_isOpenImmersion.mp
      -- Porting note: was convert V.2
      erw [e']
      apply V.2
  · intro H V
    specialize H ⟨_, V.2.imageIsOpenImmersion (X.ofRestrict _)⟩ (Subtype.coe_image_subset _ _)
    erw [← X.presheaf.map_comp]
    rw [← hP.cancel_right_isIso _ (X.presheaf.map (eqToHom _)), Category.assoc, ←
      X.presheaf.map_comp]
    convert H
    · dsimp only [Functor.op, unop_op]; 

Proof state:
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : RingHom.RespectsIso P
X Y : Scheme
f : X ⟶ Y
U : ↑(Scheme.affineOpens Y)
V : ↑(Scheme.affineOpens (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U)))))
H : P (Scheme.Hom.appLe f (_ : Subtype.val '' ↑↑V ⊆ ↑(f⁻¹ᵁ ↑U)))
⊢ op
      ((IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion (f⁻¹ᵁ ↑U)))).obj
        ((IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion ↑V))).obj ⊤)) =
    op ((Scheme.Hom.opensFunctor (Scheme.ofRestrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U))))).obj ↑V)

Next tactic:
rw [Opens.openEmbedding_obj_top]
theorem scheme_restrict_basicOpen_of_localizationPreserves (h₁ : RingHom.RespectsIso @P)
    (h₂ : RingHom.LocalizationPreserves @P) {X Y : Scheme} [IsAffine Y] (f : X ⟶ Y)
    (r : Y.presheaf.obj (op ⊤)) (H : sourceAffineLocally (@P) f)
    (U : (X.restrict ((Opens.map f.1.base).obj <| Y.basicOpen r).openEmbedding).affineOpens) :
    P (Scheme.Γ.map ((X.restrict ((Opens.map f.1.base).obj <|
      Y.basicOpen r).openEmbedding).ofRestrict U.1.openEmbedding ≫ f ∣_ Y.basicOpen r).op) := by
  

Proof state:
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
h₁ : RingHom.RespectsIso P
h₂ : RingHom.LocalizationPreserves P
X Y : Scheme
inst✝ : IsAffine Y
f : X ⟶ Y
r : ↑(Y.presheaf.obj (op ⊤))
H : sourceAffineLocally P f
U : ↑(Scheme.affineOpens (X ∣_ᵤ f⁻¹ᵁ Y.basicOpen r))
⊢ P
    (Scheme.Γ.map
      (Scheme.ofRestrict (X ∣_ᵤ f⁻¹ᵁ Y.basicOpen r) (_ : OpenEmbedding ⇑(Opens.inclusion ↑U)) ≫ f ∣_ Y.basicOpen r).op)

Next tactic:
specialize H ⟨_, U.2.imageIsOpenImmersion (X.ofRestrict _)⟩
theorem scheme_restrict_basicOpen_of_localizationPreserves (h₁ : RingHom.RespectsIso @P)
    (h₂ : RingHom.LocalizationPreserves @P) {X Y : Scheme} [IsAffine Y] (f : X ⟶ Y)
    (r : Y.presheaf.obj (op ⊤)) (H : sourceAffineLocally (@P) f)
    (U : (X.restrict ((Opens.map f.1.base).obj <| Y.basicOpen r).openEmbedding).affineOpens) :
    P (Scheme.Γ.map ((X.restrict ((Opens.map f.1.base).obj <|
      Y.basicOpen r).openEmbedding).ofRestrict U.1.openEmbedding ≫ f ∣_ Y.basicOpen r).op) := by
  specialize H ⟨_, U.2.imageIsOpenImmersion (X.ofRestrict _)⟩
  

Proof state:
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
h₁ : RingHom.RespectsIso P
h₂ : RingHom.LocalizationPreserves P
X Y : Scheme
inst✝ : IsAffine Y
f : X ⟶ Y
r : ↑(Y.presheaf.obj (op ⊤))
U : ↑(Scheme.affineOpens (X ∣_ᵤ f⁻¹ᵁ Y.basicOpen r))
H :
  P
    (Scheme.Γ.map
      (Scheme.ofRestrict X
            (_ :
              OpenEmbedding
                ⇑(Opens.inclusion
                    ↑{
                        val :=
                          (Scheme.Hom.opensFunctor
                                (Scheme.ofRestrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ Y.basicOpen r))))).obj
                            ↑U,
                        property :=
                          (_ :
                            IsAffineOpen
                              ((Scheme.Hom.opensFunctor
                                    (Scheme.ofRestrict X
                                      (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ Y.basicOpen r))))).obj
                                ↑U)) })) ≫
          f).op)
⊢ P
    (Scheme.Γ.map
      (Scheme.ofRestrict (X ∣_ᵤ f⁻¹ᵁ Y.basicOpen r) (_ : OpenEmbedding ⇑(Opens.inclusion ↑U)) ≫ f ∣_ Y.basicOpen r).op)

Next tactic:
letI i1 : Algebra (Y.presheaf.obj <| Opposite.op ⊤) (Localization.Away r) := Localization.algebra