l3lab/ntp-mathlib huggingface dataset:
theorem targetAffineLocallyOfOpenCover {P : AffineTargetMorphismProperty} (hP : P.IsLocal)
    {X Y : Scheme} (f : X ⟶ Y) (𝒰 : Y.OpenCover) [∀ i, IsAffine (𝒰.obj i)]
    (h𝒰 : ∀ i, P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i)) :
    targetAffineLocally P f := by
  classical
  let S i := (⟨⟨Set.range (𝒰.map i).1.base, (𝒰.IsOpen i).base_open.open_range⟩,
    rangeIsAffineOpenOfOpenImmersion (𝒰.map i)⟩ : Y.affineOpens)
  intro U
  apply of_affine_open_cover (P := _) U (Set.range S)
  · intro U r h
    haveI : IsAffine _ := U.2
    have := hP.2 (f ∣_ U.1)
    replace this := this (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op r) h
    -- Porting note : the following 2 instances was not necessary
    haveI i1 : IsAffine (Y.restrict (Scheme.affineBasicOpen Y r).1.openEmbedding) :=
      (Scheme.affineBasicOpen Y r).2
    haveI i2 : IsAffine
      ((Y.restrict U.1.openEmbedding).restrict
        ((Y.restrict U.1.openEmbedding).basicOpen <|
          (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op r)).openEmbedding) :=
      IsAffineOpen.basicOpenIsAffine (X := Y.restrict U.1.openEmbedding) (topIsAffineOpen _) _
    

Proof state:
case hP₁
P : AffineTargetMorphismProperty
hP : AffineTargetMorphismProperty.IsLocal P
X Y : Scheme
f : X ⟶ Y
𝒰 : Scheme.OpenCover Y
inst✝ : ∀ (i : 𝒰.J), IsAffine (Scheme.OpenCover.obj 𝒰 i)
h𝒰 : ∀ (i : (Scheme.OpenCover.pullbackCover 𝒰 f).J), P pullback.snd
S : 𝒰.J → { x // x ∈ Scheme.affineOpens Y } :=
  fun i =>
    {
      val :=
        { carrier := Set.range ⇑(Scheme.OpenCover.map 𝒰 i).val.base,
          is_open' := (_ : IsOpen (Set.range ⇑(Scheme.OpenCover.map 𝒰 i).val.base)) },
      property := (_ : IsAffineOpen (Scheme.Hom.opensRange (Scheme.OpenCover.map 𝒰 i))) }
U✝ U : ↑(Scheme.affineOpens Y)
r : ↑(Y.presheaf.obj (op ↑U))
h : P (f ∣_ ↑U)
this✝ : IsAffine (Scheme.restrict Y (_ : OpenEmbedding ⇑(Opens.inclusion ↑U)))
this :
  P
    (f ∣_ ↑U ∣_
      (Y ∣_ᵤ ↑U).basicOpen
        ((Y.presheaf.map (eqToHom (_ : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion ↑U))).obj ⊤ = ↑U)).op) r))
i1 : IsAffine (Y ∣_ᵤ ↑(Scheme.affineBasicOpen Y r))
i2 :
  IsAffine
    (Y ∣_ᵤ ↑U ∣_ᵤ
      (Y ∣_ᵤ ↑U).basicOpen
        ((Y.presheaf.map (eqToHom (_ : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion ↑U))).obj ⊤ = ↑U)).op) r))
⊢ P (f ∣_ ↑(Scheme.affineBasicOpen Y r))

Next tactic:
rw [← P.toProperty_apply] at this ⊢
theorem targetAffineLocallyOfOpenCover {P : AffineTargetMorphismProperty} (hP : P.IsLocal)
    {X Y : Scheme} (f : X ⟶ Y) (𝒰 : Y.OpenCover) [∀ i, IsAffine (𝒰.obj i)]
    (h𝒰 : ∀ i, P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i)) :
    targetAffineLocally P f := by
  classical
  let S i := (⟨⟨Set.range (𝒰.map i).1.base, (𝒰.IsOpen i).base_open.open_range⟩,
    rangeIsAffineOpenOfOpenImmersion (𝒰.map i)⟩ : Y.affineOpens)
  intro U
  apply of_affine_open_cover (P := _) U (Set.range S)
  · intro U r h
    haveI : IsAffine _ := U.2
    have := hP.2 (f ∣_ U.1)
    replace this := this (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op r) h
    -- Porting note : the following 2 instances was not necessary
    haveI i1 : IsAffine (Y.restrict (Scheme.affineBasicOpen Y r).1.openEmbedding) :=
      (Scheme.affineBasicOpen Y r).2
    haveI i2 : IsAffine
      ((Y.restrict U.1.openEmbedding).restrict
        ((Y.restrict U.1.openEmbedding).basicOpen <|
          (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op r)).openEmbedding) :=
      IsAffineOpen.basicOpenIsAffine (X := Y.restrict U.1.openEmbedding) (topIsAffineOpen _) _
    rw [← P.toProperty_apply] at this ⊢
    

Proof state:
case hP₁
P : AffineTargetMorphismProperty
hP : AffineTargetMorphismProperty.IsLocal P
X Y : Scheme
f : X ⟶ Y
𝒰 : Scheme.OpenCover Y
inst✝ : ∀ (i : 𝒰.J), IsAffine (Scheme.OpenCover.obj 𝒰 i)
h𝒰 : ∀ (i : (Scheme.OpenCover.pullbackCover 𝒰 f).J), P pullback.snd
S : 𝒰.J → { x // x ∈ Scheme.affineOpens Y } :=
  fun i =>
    {
      val :=
        { carrier := Set.range ⇑(Scheme.OpenCover.map 𝒰 i).val.base,
          is_open' := (_ : IsOpen (Set.range ⇑(Scheme.OpenCover.map 𝒰 i).val.base)) },
      property := (_ : IsAffineOpen (Scheme.Hom.opensRange (Scheme.OpenCover.map 𝒰 i))) }
U✝ U : ↑(Scheme.affineOpens Y)
r : ↑(Y.presheaf.obj (op ↑U))
h : P (f ∣_ ↑U)
this✝ : IsAffine (Scheme.restrict Y (_ : OpenEmbedding ⇑(Opens.inclusion ↑U)))
this :
  AffineTargetMorphismProperty.toProperty P
    (f ∣_ ↑U ∣_
      (Y ∣_ᵤ ↑U).basicOpen
        ((Y.presheaf.map (eqToHom (_ : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion ↑U))).obj ⊤ = ↑U)).op) r))
i1 : IsAffine (Y ∣_ᵤ ↑(Scheme.affineBasicOpen Y r))
i2 :
  IsAffine
    (Y ∣_ᵤ ↑U ∣_ᵤ
      (Y ∣_ᵤ ↑U).basicOpen
        ((Y.presheaf.map (eqToHom (_ : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion ↑U))).obj ⊤ = ↑U)).op) r))
⊢ AffineTargetMorphismProperty.toProperty P (f ∣_ ↑(Scheme.affineBasicOpen Y r))

Next tactic:
exact (hP.1.arrow_mk_iso_iff (morphismRestrictRestrictBasicOpen f _ r)).mp this
theorem targetAffineLocallyOfOpenCover {P : AffineTargetMorphismProperty} (hP : P.IsLocal)
    {X Y : Scheme} (f : X ⟶ Y) (𝒰 : Y.OpenCover) [∀ i, IsAffine (𝒰.obj i)]
    (h𝒰 : ∀ i, P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i)) :
    targetAffineLocally P f := by
  classical
  let S i := (⟨⟨Set.range (𝒰.map i).1.base, (𝒰.IsOpen i).base_open.open_range⟩,
    rangeIsAffineOpenOfOpenImmersion (𝒰.map i)⟩ : Y.affineOpens)
  intro U
  apply of_affine_open_cover (P := _) U (Set.range S)
  · intro U r h
    haveI : IsAffine _ := U.2
    have := hP.2 (f ∣_ U.1)
    replace this := this (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op r) h
    -- Porting note : the following 2 instances was not necessary
    haveI i1 : IsAffine (Y.restrict (Scheme.affineBasicOpen Y r).1.openEmbedding) :=
      (Scheme.affineBasicOpen Y r).2
    haveI i2 : IsAffine
      ((Y.restrict U.1.openEmbedding).restrict
        ((Y.restrict U.1.openEmbedding).basicOpen <|
          (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op r)).openEmbedding) :=
      IsAffineOpen.basicOpenIsAffine (X := Y.restrict U.1.openEmbedding) (topIsAffineOpen _) _
    rw [← P.toProperty_apply] at this ⊢
    exact (hP.1.arrow_mk_iso_iff (morphismRestrictRestrictBasicOpen f _ r)).mp this
  · 

Proof state:
case hP₂
P : AffineTargetMorphismProperty
hP : AffineTargetMorphismProperty.IsLocal P
X Y : Scheme
f : X ⟶ Y
𝒰 : Scheme.OpenCover Y
inst✝ : ∀ (i : 𝒰.J), IsAffine (Scheme.OpenCover.obj 𝒰 i)
h𝒰 : ∀ (i : (Scheme.OpenCover.pullbackCover 𝒰 f).J), P pullback.snd
S : 𝒰.J → { x // x ∈ Scheme.affineOpens Y } :=
  fun i =>
    {
      val :=
        { carrier := Set.range ⇑(Scheme.OpenCover.map 𝒰 i).val.base,
          is_open' := (_ : IsOpen (Set.range ⇑(Scheme.OpenCover.map 𝒰 i).val.base)) },
      property := (_ : IsAffineOpen (Scheme.Hom.opensRange (Scheme.OpenCover.map 𝒰 i))) }
U : ↑(Scheme.affineOpens Y)
⊢ ∀ (U : ↑(Scheme.affineOpens Y)) (s : Finset ↑(Y.presheaf.obj (op ↑U))),
    Ideal.span ↑s = ⊤ → (∀ (f_1 : { x // x ∈ s }), P (f ∣_ ↑(Scheme.affineBasicOpen Y ↑f_1))) → P (f ∣_ ↑U)

Next tactic:
intro U s hs H
theorem targetAffineLocallyOfOpenCover {P : AffineTargetMorphismProperty} (hP : P.IsLocal)
    {X Y : Scheme} (f : X ⟶ Y) (𝒰 : Y.OpenCover) [∀ i, IsAffine (𝒰.obj i)]
    (h𝒰 : ∀ i, P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i)) :
    targetAffineLocally P f := by
  classical
  let S i := (⟨⟨Set.range (𝒰.map i).1.base, (𝒰.IsOpen i).base_open.open_range⟩,
    rangeIsAffineOpenOfOpenImmersion (𝒰.map i)⟩ : Y.affineOpens)
  intro U
  apply of_affine_open_cover (P := _) U (Set.range S)
  · intro U r h
    haveI : IsAffine _ := U.2
    have := hP.2 (f ∣_ U.1)
    replace this := this (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op r) h
    -- Porting note : the following 2 instances was not necessary
    haveI i1 : IsAffine (Y.restrict (Scheme.affineBasicOpen Y r).1.openEmbedding) :=
      (Scheme.affineBasicOpen Y r).2
    haveI i2 : IsAffine
      ((Y.restrict U.1.openEmbedding).restrict
        ((Y.restrict U.1.openEmbedding).basicOpen <|
          (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op r)).openEmbedding) :=
      IsAffineOpen.basicOpenIsAffine (X := Y.restrict U.1.openEmbedding) (topIsAffineOpen _) _
    rw [← P.toProperty_apply] at this ⊢
    exact (hP.1.arrow_mk_iso_iff (morphismRestrictRestrictBasicOpen f _ r)).mp this
  · intro U s hs H
    

Proof state:
case hP₂
P : AffineTargetMorphismProperty
hP : AffineTargetMorphismProperty.IsLocal P
X Y : Scheme
f : X ⟶ Y
𝒰 : Scheme.OpenCover Y
inst✝ : ∀ (i : 𝒰.J), IsAffine (Scheme.OpenCover.obj 𝒰 i)
h𝒰 : ∀ (i : (Scheme.OpenCover.pullbackCover 𝒰 f).J), P pullback.snd
S : 𝒰.J → { x // x ∈ Scheme.affineOpens Y } :=
  fun i =>
    {
      val :=
        { carrier := Set.range ⇑(Scheme.OpenCover.map 𝒰 i).val.base,
          is_open' := (_ : IsOpen (Set.range ⇑(Scheme.OpenCover.map 𝒰 i).val.base)) },
      property := (_ : IsAffineOpen (Scheme.Hom.opensRange (Scheme.OpenCover.map 𝒰 i))) }
U✝ U : ↑(Scheme.affineOpens Y)
s : Finset ↑(Y.presheaf.obj (op ↑U))
hs : Ideal.span ↑s = ⊤
H : ∀ (f_1 : { x // x ∈ s }), P (f ∣_ ↑(Scheme.affineBasicOpen Y ↑f_1))
⊢ P (f ∣_ ↑U)

Next tactic:
haveI : IsAffine _ := U.2
theorem targetAffineLocallyOfOpenCover {P : AffineTargetMorphismProperty} (hP : P.IsLocal)
    {X Y : Scheme} (f : X ⟶ Y) (𝒰 : Y.OpenCover) [∀ i, IsAffine (𝒰.obj i)]
    (h𝒰 : ∀ i, P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i)) :
    targetAffineLocally P f := by
  classical
  let S i := (⟨⟨Set.range (𝒰.map i).1.base, (𝒰.IsOpen i).base_open.open_range⟩,
    rangeIsAffineOpenOfOpenImmersion (𝒰.map i)⟩ : Y.affineOpens)
  intro U
  apply of_affine_open_cover (P := _) U (Set.range S)
  · intro U r h
    haveI : IsAffine _ := U.2
    have := hP.2 (f ∣_ U.1)
    replace this := this (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op r) h
    -- Porting note : the following 2 instances was not necessary
    haveI i1 : IsAffine (Y.restrict (Scheme.affineBasicOpen Y r).1.openEmbedding) :=
      (Scheme.affineBasicOpen Y r).2
    haveI i2 : IsAffine
      ((Y.restrict U.1.openEmbedding).restrict
        ((Y.restrict U.1.openEmbedding).basicOpen <|
          (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op r)).openEmbedding) :=
      IsAffineOpen.basicOpenIsAffine (X := Y.restrict U.1.openEmbedding) (topIsAffineOpen _) _
    rw [← P.toProperty_apply] at this ⊢
    exact (hP.1.arrow_mk_iso_iff (morphismRestrictRestrictBasicOpen f _ r)).mp this
  · intro U s hs H
    haveI : IsAffine _ := U.2
    

Proof state:
case hP₂
P : AffineTargetMorphismProperty
hP : AffineTargetMorphismProperty.IsLocal P
X Y : Scheme
f : X ⟶ Y
𝒰 : Scheme.OpenCover Y
inst✝ : ∀ (i : 𝒰.J), IsAffine (Scheme.OpenCover.obj 𝒰 i)
h𝒰 : ∀ (i : (Scheme.OpenCover.pullbackCover 𝒰 f).J), P pullback.snd
S : 𝒰.J → { x // x ∈ Scheme.affineOpens Y } :=
  fun i =>
    {
      val :=
        { carrier := Set.range ⇑(Scheme.OpenCover.map 𝒰 i).val.base,
          is_open' := (_ : IsOpen (Set.range ⇑(Scheme.OpenCover.map 𝒰 i).val.base)) },
      property := (_ : IsAffineOpen (Scheme.Hom.opensRange (Scheme.OpenCover.map 𝒰 i))) }
U✝ U : ↑(Scheme.affineOpens Y)
s : Finset ↑(Y.presheaf.obj (op ↑U))
hs : Ideal.span ↑s = ⊤
H : ∀ (f_1 : { x // x ∈ s }), P (f ∣_ ↑(Scheme.affineBasicOpen Y ↑f_1))
this : IsAffine (Scheme.restrict Y (_ : OpenEmbedding ⇑(Opens.inclusion ↑U)))
⊢ P (f ∣_ ↑U)

Next tactic:
apply hP.3 (f ∣_ U.1) (s.image (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op))
theorem targetAffineLocallyOfOpenCover {P : AffineTargetMorphismProperty} (hP : P.IsLocal)
    {X Y : Scheme} (f : X ⟶ Y) (𝒰 : Y.OpenCover) [∀ i, IsAffine (𝒰.obj i)]
    (h𝒰 : ∀ i, P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i)) :
    targetAffineLocally P f := by
  classical
  let S i := (⟨⟨Set.range (𝒰.map i).1.base, (𝒰.IsOpen i).base_open.open_range⟩,
    rangeIsAffineOpenOfOpenImmersion (𝒰.map i)⟩ : Y.affineOpens)
  intro U
  apply of_affine_open_cover (P := _) U (Set.range S)
  · intro U r h
    haveI : IsAffine _ := U.2
    have := hP.2 (f ∣_ U.1)
    replace this := this (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op r) h
    -- Porting note : the following 2 instances was not necessary
    haveI i1 : IsAffine (Y.restrict (Scheme.affineBasicOpen Y r).1.openEmbedding) :=
      (Scheme.affineBasicOpen Y r).2
    haveI i2 : IsAffine
      ((Y.restrict U.1.openEmbedding).restrict
        ((Y.restrict U.1.openEmbedding).basicOpen <|
          (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op r)).openEmbedding) :=
      IsAffineOpen.basicOpenIsAffine (X := Y.restrict U.1.openEmbedding) (topIsAffineOpen _) _
    rw [← P.toProperty_apply] at this ⊢
    exact (hP.1.arrow_mk_iso_iff (morphismRestrictRestrictBasicOpen f _ r)).mp this
  · intro U s hs H
    haveI : IsAffine _ := U.2
    apply hP.3 (f ∣_ U.1) (s.image (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op))
    · 

Proof state:
case hP₂.x
P : AffineTargetMorphismProperty
hP : AffineTargetMorphismProperty.IsLocal P
X Y : Scheme
f : X ⟶ Y
𝒰 : Scheme.OpenCover Y
inst✝ : ∀ (i : 𝒰.J), IsAffine (Scheme.OpenCover.obj 𝒰 i)
h𝒰 : ∀ (i : (Scheme.OpenCover.pullbackCover 𝒰 f).J), P pullback.snd
S : 𝒰.J → { x // x ∈ Scheme.affineOpens Y } :=
  fun i =>
    {
      val :=
        { carrier := Set.range ⇑(Scheme.OpenCover.map 𝒰 i).val.base,
          is_open' := (_ : IsOpen (Set.range ⇑(Scheme.OpenCover.map 𝒰 i).val.base)) },
      property := (_ : IsAffineOpen (Scheme.Hom.opensRange (Scheme.OpenCover.map 𝒰 i))) }
U✝ U : ↑(Scheme.affineOpens Y)
s : Finset ↑(Y.presheaf.obj (op ↑U))
hs : Ideal.span ↑s = ⊤
H : ∀ (f_1 : { x // x ∈ s }), P (f ∣_ ↑(Scheme.affineBasicOpen Y ↑f_1))
this : IsAffine (Scheme.restrict Y (_ : OpenEmbedding ⇑(Opens.inclusion ↑U)))
⊢ Ideal.span
      ↑(Finset.image
          (⇑(Y.presheaf.map (eqToHom (_ : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion ↑U))).obj ⊤ = ↑U)).op))
          s) =
    ⊤

Next tactic:
apply_fun Ideal.comap (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top.symm).op) at hs
theorem targetAffineLocallyOfOpenCover {P : AffineTargetMorphismProperty} (hP : P.IsLocal)
    {X Y : Scheme} (f : X ⟶ Y) (𝒰 : Y.OpenCover) [∀ i, IsAffine (𝒰.obj i)]
    (h𝒰 : ∀ i, P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i)) :
    targetAffineLocally P f := by
  classical
  let S i := (⟨⟨Set.range (𝒰.map i).1.base, (𝒰.IsOpen i).base_open.open_range⟩,
    rangeIsAffineOpenOfOpenImmersion (𝒰.map i)⟩ : Y.affineOpens)
  intro U
  apply of_affine_open_cover (P := _) U (Set.range S)
  · intro U r h
    haveI : IsAffine _ := U.2
    have := hP.2 (f ∣_ U.1)
    replace this := this (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op r) h
    -- Porting note : the following 2 instances was not necessary
    haveI i1 : IsAffine (Y.restrict (Scheme.affineBasicOpen Y r).1.openEmbedding) :=
      (Scheme.affineBasicOpen Y r).2
    haveI i2 : IsAffine
      ((Y.restrict U.1.openEmbedding).restrict
        ((Y.restrict U.1.openEmbedding).basicOpen <|
          (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op r)).openEmbedding) :=
      IsAffineOpen.basicOpenIsAffine (X := Y.restrict U.1.openEmbedding) (topIsAffineOpen _) _
    rw [← P.toProperty_apply] at this ⊢
    exact (hP.1.arrow_mk_iso_iff (morphismRestrictRestrictBasicOpen f _ r)).mp this
  · intro U s hs H
    haveI : IsAffine _ := U.2
    apply hP.3 (f ∣_ U.1) (s.image (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op))
    · apply_fun Ideal.comap (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top.symm).op) at hs
      

Proof state:
case hP₂.x
P : AffineTargetMorphismProperty
hP : AffineTargetMorphismProperty.IsLocal P
X Y : Scheme
f : X ⟶ Y
𝒰 : Scheme.OpenCover Y
inst✝ : ∀ (i : 𝒰.J), IsAffine (Scheme.OpenCover.obj 𝒰 i)
h𝒰 : ∀ (i : (Scheme.OpenCover.pullbackCover 𝒰 f).J), P pullback.snd
S : 𝒰.J → { x // x ∈ Scheme.affineOpens Y } :=
  fun i =>
    {
      val :=
        { carrier := Set.range ⇑(Scheme.OpenCover.map 𝒰 i).val.base,
          is_open' := (_ : IsOpen (Set.range ⇑(Scheme.OpenCover.map 𝒰 i).val.base)) },
      property := (_ : IsAffineOpen (Scheme.Hom.opensRange (Scheme.OpenCover.map 𝒰 i))) }
U✝ U : ↑(Scheme.affineOpens Y)
s : Finset ↑(Y.presheaf.obj (op ↑U))
H : ∀ (f_1 : { x // x ∈ s }), P (f ∣_ ↑(Scheme.affineBasicOpen Y ↑f_1))
this : IsAffine (Scheme.restrict Y (_ : OpenEmbedding ⇑(Opens.inclusion ↑U)))
hs :
  Ideal.comap (Y.presheaf.map (eqToHom (_ : ↑U = (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion ↑U))).obj ⊤)).op)
      (Ideal.span ↑s) =
    Ideal.comap (Y.presheaf.map (eqToHom (_ : ↑U = (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion ↑U))).obj ⊤)).op)
      ⊤
⊢ Ideal.span
      ↑(Finset.image
          (⇑(Y.presheaf.map (eqToHom (_ : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion ↑U))).obj ⊤ = ↑U)).op))
          s) =
    ⊤

Next tactic:
rw [Ideal.comap_top] at hs
theorem targetAffineLocallyOfOpenCover {P : AffineTargetMorphismProperty} (hP : P.IsLocal)
    {X Y : Scheme} (f : X ⟶ Y) (𝒰 : Y.OpenCover) [∀ i, IsAffine (𝒰.obj i)]
    (h𝒰 : ∀ i, P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i)) :
    targetAffineLocally P f := by
  classical
  let S i := (⟨⟨Set.range (𝒰.map i).1.base, (𝒰.IsOpen i).base_open.open_range⟩,
    rangeIsAffineOpenOfOpenImmersion (𝒰.map i)⟩ : Y.affineOpens)
  intro U
  apply of_affine_open_cover (P := _) U (Set.range S)
  · intro U r h
    haveI : IsAffine _ := U.2
    have := hP.2 (f ∣_ U.1)
    replace this := this (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op r) h
    -- Porting note : the following 2 instances was not necessary
    haveI i1 : IsAffine (Y.restrict (Scheme.affineBasicOpen Y r).1.openEmbedding) :=
      (Scheme.affineBasicOpen Y r).2
    haveI i2 : IsAffine
      ((Y.restrict U.1.openEmbedding).restrict
        ((Y.restrict U.1.openEmbedding).basicOpen <|
          (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op r)).openEmbedding) :=
      IsAffineOpen.basicOpenIsAffine (X := Y.restrict U.1.openEmbedding) (topIsAffineOpen _) _
    rw [← P.toProperty_apply] at this ⊢
    exact (hP.1.arrow_mk_iso_iff (morphismRestrictRestrictBasicOpen f _ r)).mp this
  · intro U s hs H
    haveI : IsAffine _ := U.2
    apply hP.3 (f ∣_ U.1) (s.image (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op))
    · apply_fun Ideal.comap (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top.symm).op) at hs
      rw [Ideal.comap_top] at hs
      

Proof state:
case hP₂.x
P : AffineTargetMorphismProperty
hP : AffineTargetMorphismProperty.IsLocal P
X Y : Scheme
f : X ⟶ Y
𝒰 : Scheme.OpenCover Y
inst✝ : ∀ (i : 𝒰.J), IsAffine (Scheme.OpenCover.obj 𝒰 i)
h𝒰 : ∀ (i : (Scheme.OpenCover.pullbackCover 𝒰 f).J), P pullback.snd
S : 𝒰.J → { x // x ∈ Scheme.affineOpens Y } :=
  fun i =>
    {
      val :=
        { carrier := Set.range ⇑(Scheme.OpenCover.map 𝒰 i).val.base,
          is_open' := (_ : IsOpen (Set.range ⇑(Scheme.OpenCover.map 𝒰 i).val.base)) },
      property := (_ : IsAffineOpen (Scheme.Hom.opensRange (Scheme.OpenCover.map 𝒰 i))) }
U✝ U : ↑(Scheme.affineOpens Y)
s : Finset ↑(Y.presheaf.obj (op ↑U))
H : ∀ (f_1 : { x // x ∈ s }), P (f ∣_ ↑(Scheme.affineBasicOpen Y ↑f_1))
this : IsAffine (Scheme.restrict Y (_ : OpenEmbedding ⇑(Opens.inclusion ↑U)))
hs :
  Ideal.comap (Y.presheaf.map (eqToHom (_ : ↑U = (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion ↑U))).obj ⊤)).op)
      (Ideal.span ↑s) =
    ⊤
⊢ Ideal.span
      ↑(Finset.image
          (⇑(Y.presheaf.map (eqToHom (_ : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion ↑U))).obj ⊤ = ↑U)).op))
          s) =
    ⊤

Next tactic:
rw [← hs]
theorem targetAffineLocallyOfOpenCover {P : AffineTargetMorphismProperty} (hP : P.IsLocal)
    {X Y : Scheme} (f : X ⟶ Y) (𝒰 : Y.OpenCover) [∀ i, IsAffine (𝒰.obj i)]
    (h𝒰 : ∀ i, P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i)) :
    targetAffineLocally P f := by
  classical
  let S i := (⟨⟨Set.range (𝒰.map i).1.base, (𝒰.IsOpen i).base_open.open_range⟩,
    rangeIsAffineOpenOfOpenImmersion (𝒰.map i)⟩ : Y.affineOpens)
  intro U
  apply of_affine_open_cover (P := _) U (Set.range S)
  · intro U r h
    haveI : IsAffine _ := U.2
    have := hP.2 (f ∣_ U.1)
    replace this := this (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op r) h
    -- Porting note : the following 2 instances was not necessary
    haveI i1 : IsAffine (Y.restrict (Scheme.affineBasicOpen Y r).1.openEmbedding) :=
      (Scheme.affineBasicOpen Y r).2
    haveI i2 : IsAffine
      ((Y.restrict U.1.openEmbedding).restrict
        ((Y.restrict U.1.openEmbedding).basicOpen <|
          (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op r)).openEmbedding) :=
      IsAffineOpen.basicOpenIsAffine (X := Y.restrict U.1.openEmbedding) (topIsAffineOpen _) _
    rw [← P.toProperty_apply] at this ⊢
    exact (hP.1.arrow_mk_iso_iff (morphismRestrictRestrictBasicOpen f _ r)).mp this
  · intro U s hs H
    haveI : IsAffine _ := U.2
    apply hP.3 (f ∣_ U.1) (s.image (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op))
    · apply_fun Ideal.comap (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top.symm).op) at hs
      rw [Ideal.comap_top] at hs
      rw [← hs]
      

Proof state:
case hP₂.x
P : AffineTargetMorphismProperty
hP : AffineTargetMorphismProperty.IsLocal P
X Y : Scheme
f : X ⟶ Y
𝒰 : Scheme.OpenCover Y
inst✝ : ∀ (i : 𝒰.J), IsAffine (Scheme.OpenCover.obj 𝒰 i)
h𝒰 : ∀ (i : (Scheme.OpenCover.pullbackCover 𝒰 f).J), P pullback.snd
S : 𝒰.J → { x // x ∈ Scheme.affineOpens Y } :=
  fun i =>
    {
      val :=
        { carrier := Set.range ⇑(Scheme.OpenCover.map 𝒰 i).val.base,
          is_open' := (_ : IsOpen (Set.range ⇑(Scheme.OpenCover.map 𝒰 i).val.base)) },
      property := (_ : IsAffineOpen (Scheme.Hom.opensRange (Scheme.OpenCover.map 𝒰 i))) }
U✝ U : ↑(Scheme.affineOpens Y)
s : Finset ↑(Y.presheaf.obj (op ↑U))
H : ∀ (f_1 : { x // x ∈ s }), P (f ∣_ ↑(Scheme.affineBasicOpen Y ↑f_1))
this : IsAffine (Scheme.restrict Y (_ : OpenEmbedding ⇑(Opens.inclusion ↑U)))
hs :
  Ideal.comap (Y.presheaf.map (eqToHom (_ : ↑U = (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion ↑U))).obj ⊤)).op)
      (Ideal.span ↑s) =
    ⊤
⊢ Ideal.span
      ↑(Finset.image
          (⇑(Y.presheaf.map (eqToHom (_ : (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion ↑U))).obj ⊤ = ↑U)).op))
          s) =
    Ideal.comap (Y.presheaf.map (eqToHom (_ : ↑U = (IsOpenMap.functor (_ : IsOpenMap ⇑(Opens.inclusion ↑U))).obj ⊤)).op)
      (Ideal.span ↑s)

Next tactic:
simp only [eqToHom_op, eqToHom_map, Finset.coe_image]