l3lab/ntp-mathlib huggingface dataset:
theorem sourceAffineLocally_respectsIso (h₁ : RingHom.RespectsIso @P) :
    (sourceAffineLocally @P).toProperty.RespectsIso := by
  apply AffineTargetMorphismProperty.respectsIso_mk
  · introv H U
    rw [← h₁.cancel_right_isIso _ (Scheme.Γ.map (Scheme.restrictMapIso e.inv U.1).hom.op), ←
      Functor.map_comp, ← op_comp]
    convert H ⟨_, U.prop.map_isIso e.inv⟩ using 3
    -- Porting note : have to add this instance manually
    

Proof state:
case h.e'_5.h.e'_8.h.e'_5
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
h₁ : RingHom.RespectsIso P
X Y Z : Scheme
e : X ≅ Y
f : Y ⟶ Z
inst✝ : IsAffine Z
H : sourceAffineLocally P f
U : ↑(Scheme.affineOpens X)
⊢ (Scheme.restrictMapIso e.inv ↑U).hom ≫ Scheme.ofRestrict X (_ : OpenEmbedding ⇑(Opens.inclusion ↑U)) ≫ e.hom ≫ f =
    Scheme.ofRestrict Y
        (_ : OpenEmbedding ⇑(Opens.inclusion ↑{ val := e.inv⁻¹ᵁ ↑U, property := (_ : IsAffineOpen (e.inv⁻¹ᵁ ↑U)) })) ≫
      f

Next tactic:
haveI i1 : IsOpenImmersion
      (Scheme.ofRestrict Y ((Opens.map e.inv.val.base).obj U.1).openEmbedding ≫ e.inv) :=
      PresheafedSpace.IsOpenImmersion.comp _ _
theorem sourceAffineLocally_respectsIso (h₁ : RingHom.RespectsIso @P) :
    (sourceAffineLocally @P).toProperty.RespectsIso := by
  apply AffineTargetMorphismProperty.respectsIso_mk
  · introv H U
    rw [← h₁.cancel_right_isIso _ (Scheme.Γ.map (Scheme.restrictMapIso e.inv U.1).hom.op), ←
      Functor.map_comp, ← op_comp]
    convert H ⟨_, U.prop.map_isIso e.inv⟩ using 3
    -- Porting note : have to add this instance manually
    haveI i1 : IsOpenImmersion
      (Scheme.ofRestrict Y ((Opens.map e.inv.val.base).obj U.1).openEmbedding ≫ e.inv) :=
      PresheafedSpace.IsOpenImmersion.comp _ _
    

Proof state:
case h.e'_5.h.e'_8.h.e'_5
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
h₁ : RingHom.RespectsIso P
X Y Z : Scheme
e : X ≅ Y
f : Y ⟶ Z
inst✝ : IsAffine Z
H : sourceAffineLocally P f
U : ↑(Scheme.affineOpens X)
i1 : IsOpenImmersion (Scheme.ofRestrict Y (_ : OpenEmbedding ⇑(Opens.inclusion (e.inv⁻¹ᵁ ↑U))) ≫ e.inv)
⊢ (Scheme.restrictMapIso e.inv ↑U).hom ≫ Scheme.ofRestrict X (_ : OpenEmbedding ⇑(Opens.inclusion ↑U)) ≫ e.hom ≫ f =
    Scheme.ofRestrict Y
        (_ : OpenEmbedding ⇑(Opens.inclusion ↑{ val := e.inv⁻¹ᵁ ↑U, property := (_ : IsAffineOpen (e.inv⁻¹ᵁ ↑U)) })) ≫
      f

Next tactic:
rw [IsOpenImmersion.isoOfRangeEq_hom_fac_assoc, Category.assoc,
      e.inv_hom_id_assoc]
theorem sourceAffineLocally_respectsIso (h₁ : RingHom.RespectsIso @P) :
    (sourceAffineLocally @P).toProperty.RespectsIso := by
  apply AffineTargetMorphismProperty.respectsIso_mk
  · introv H U
    rw [← h₁.cancel_right_isIso _ (Scheme.Γ.map (Scheme.restrictMapIso e.inv U.1).hom.op), ←
      Functor.map_comp, ← op_comp]
    convert H ⟨_, U.prop.map_isIso e.inv⟩ using 3
    -- Porting note : have to add this instance manually
    haveI i1 : IsOpenImmersion
      (Scheme.ofRestrict Y ((Opens.map e.inv.val.base).obj U.1).openEmbedding ≫ e.inv) :=
      PresheafedSpace.IsOpenImmersion.comp _ _
    rw [IsOpenImmersion.isoOfRangeEq_hom_fac_assoc, Category.assoc,
      e.inv_hom_id_assoc]
  · 

Proof state:
case h₂
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
h₁ : RingHom.RespectsIso P
⊢ ∀ {X Y Z : Scheme} (e : Y ≅ Z) (f : X ⟶ Y) [h : IsAffine Y],
    sourceAffineLocally P f → sourceAffineLocally P (f ≫ e.hom)

Next tactic:
introv H U
theorem sourceAffineLocally_respectsIso (h₁ : RingHom.RespectsIso @P) :
    (sourceAffineLocally @P).toProperty.RespectsIso := by
  apply AffineTargetMorphismProperty.respectsIso_mk
  · introv H U
    rw [← h₁.cancel_right_isIso _ (Scheme.Γ.map (Scheme.restrictMapIso e.inv U.1).hom.op), ←
      Functor.map_comp, ← op_comp]
    convert H ⟨_, U.prop.map_isIso e.inv⟩ using 3
    -- Porting note : have to add this instance manually
    haveI i1 : IsOpenImmersion
      (Scheme.ofRestrict Y ((Opens.map e.inv.val.base).obj U.1).openEmbedding ≫ e.inv) :=
      PresheafedSpace.IsOpenImmersion.comp _ _
    rw [IsOpenImmersion.isoOfRangeEq_hom_fac_assoc, Category.assoc,
      e.inv_hom_id_assoc]
  · introv H U
    

Proof state:
case h₂
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
h₁ : RingHom.RespectsIso P
X Y Z : Scheme
e : Y ≅ Z
f : X ⟶ Y
h : IsAffine Y
H : sourceAffineLocally P f
U : ↑(Scheme.affineOpens X)
⊢ P (Scheme.Γ.map (Scheme.ofRestrict X (_ : OpenEmbedding ⇑(Opens.inclusion ↑U)) ≫ f ≫ e.hom).op)

Next tactic:
rw [← Category.assoc, op_comp, Functor.map_comp, h₁.cancel_left_isIso]
theorem sourceAffineLocally_respectsIso (h₁ : RingHom.RespectsIso @P) :
    (sourceAffineLocally @P).toProperty.RespectsIso := by
  apply AffineTargetMorphismProperty.respectsIso_mk
  · introv H U
    rw [← h₁.cancel_right_isIso _ (Scheme.Γ.map (Scheme.restrictMapIso e.inv U.1).hom.op), ←
      Functor.map_comp, ← op_comp]
    convert H ⟨_, U.prop.map_isIso e.inv⟩ using 3
    -- Porting note : have to add this instance manually
    haveI i1 : IsOpenImmersion
      (Scheme.ofRestrict Y ((Opens.map e.inv.val.base).obj U.1).openEmbedding ≫ e.inv) :=
      PresheafedSpace.IsOpenImmersion.comp _ _
    rw [IsOpenImmersion.isoOfRangeEq_hom_fac_assoc, Category.assoc,
      e.inv_hom_id_assoc]
  · introv H U
    rw [← Category.assoc, op_comp, Functor.map_comp, h₁.cancel_left_isIso]
    

Proof state:
case h₂
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
h₁ : RingHom.RespectsIso P
X Y Z : Scheme
e : Y ≅ Z
f : X ⟶ Y
h : IsAffine Y
H : sourceAffineLocally P f
U : ↑(Scheme.affineOpens X)
⊢ P (Scheme.Γ.map (Scheme.ofRestrict X (_ : OpenEmbedding ⇑(Opens.inclusion ↑U)) ≫ f).op)

Next tactic:
exact H U
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
  

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
⊢ affineLocally P f ↔
    ∀ (U : ↑(Scheme.affineOpens Y)) (V : ↑(Scheme.affineOpens X)) (e : ↑V ≤ f⁻¹ᵁ ↑U), P (Scheme.Hom.appLe f e)

Next tactic:
apply forall_congr'
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'
  

Proof state:
case h
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
⊢ ∀ (a : ↑(Scheme.affineOpens Y)),
    sourceAffineLocally P (f ∣_ ↑a) ↔ ∀ (V : ↑(Scheme.affineOpens X)) (e : ↑V ≤ f⁻¹ᵁ ↑a), P (Scheme.Hom.appLe f e)

Next tactic:
intro U
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
  

Proof state:
case h
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)
⊢ sourceAffineLocally P (f ∣_ ↑U) ↔ ∀ (V : ↑(Scheme.affineOpens X)) (e : ↑V ≤ f⁻¹ᵁ ↑U), P (Scheme.Hom.appLe f e)

Next tactic:
delta sourceAffineLocally
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
  

Proof state:
case h
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)
⊢ (∀ (U_1 : ↑(Scheme.affineOpens (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U)))))),
      P
        (Scheme.Γ.map
          (Scheme.ofRestrict (Scheme.restrict X (_ : OpenEmbedding ⇑(Opens.inclusion (f⁻¹ᵁ ↑U))))
                (_ : OpenEmbedding ⇑(Opens.inclusion ↑U_1)) ≫
              f ∣_ ↑U).op)) ↔
    ∀ (V : ↑(Scheme.affineOpens X)) (e : ↑V ≤ f⁻¹ᵁ ↑U), P (Scheme.Hom.appLe f e)

Next tactic:
simp_rw [op_comp, Scheme.Γ.map_comp, Γ_map_morphismRestrict, Category.assoc, Scheme.Γ_map_op,
    hP.cancel_left_isIso]
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]
  

Proof state:
case h
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)
⊢ (∀ (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), P (Scheme.Hom.appLe f e)

Next tactic:
constructor
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
  · 

Proof state:
case h.mp
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)
⊢ (∀ (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), P (Scheme.Hom.appLe f e)

Next tactic:
intro H V 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
    

Proof state:
case h.mp
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
⊢ P (Scheme.Hom.appLe f e)

Next tactic:
let U' := (Opens.map f.val.base).obj U.1
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
    

Proof state:
case h.mp
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
⊢ P (Scheme.Hom.appLe f e)

Next tactic:
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
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
      

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
⊢ (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U'))).obj ((Opens.map (Opens.inclusion U')).obj ↑V) = ↑V

Next tactic:
ext1
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; 

Proof state:
case h
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
⊢ ↑((IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion U'))).obj ((Opens.map (Opens.inclusion U')).obj ↑V)) = ↑↑V

Next tactic:
refine' Set.image_preimage_eq_inter_range.trans (Set.inter_eq_left.mpr _)
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 _)
      

Proof state:
case h
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
⊢ (↑V).1 ⊆ Set.range fun x => (Opens.inclusion U') x

Next tactic:
erw [Subtype.range_val]
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]
      

Proof state:
case h
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
⊢ (↑V).1 ⊆ ↑U'

Next tactic:
convert 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
    

Proof state:
case h.mp
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
⊢ P (Scheme.Hom.appLe f e)

Next tactic:
have := H ⟨(Opens.map (X.ofRestrict U'.openEmbedding).1.base).obj V.1, ?h'⟩
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
    

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:
case h' =>
      apply (X.ofRestrict U'.openEmbedding).isAffineOpen_iff_of_isOpenImmersion.mp
      -- Porting note: was convert V.2
      erw [e']
      apply V.2