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]
    

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) ≫
          eqToHom ?m.98057))
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)))
⊢ (Opens ↑↑X.toPresheafedSpace)ᵒᵖ
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 ⊤)) =
    ?m.98948
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 ⊤)) =
    ?m.98948
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 ⊤)) =
    ?m.98948

Next tactic:
convert H