l3lab/ntp-mathlib huggingface dataset:
theorem affineLocally_of_comp
    (H : ∀ {R S T : Type u} [CommRing R] [CommRing S] [CommRing T],
      ∀ (f : R →+* S) (g : S →+* T), P (g.comp f) → P g)
    {X Y Z : Scheme} {f : X ⟶ Y} {g : Y ⟶ Z} (h : affineLocally (@P) (f ≫ g)) :
    affineLocally (@P) f := by
  let 𝒰 : ∀ i, ((Z.affineCover.pullbackCover (f ≫ g)).obj i).OpenCover := by
    intro i
    refine' Scheme.OpenCover.bind _ fun i => Scheme.affineCover _
    apply Scheme.OpenCover.pushforwardIso _
      (pullbackRightPullbackFstIso g (Z.affineCover.map i) f).hom
    apply Scheme.Pullback.openCoverOfRight
    exact (pullback g (Z.affineCover.map i)).affineCover
  have h𝒰 : ∀ i j, IsAffine ((𝒰 i).obj j) := by dsimp; infer_instance
  let 𝒰' := (Z.affineCover.pullbackCover g).bind fun i => Scheme.affineCover _
  have h𝒰' : ∀ i, IsAffine (𝒰'.obj i) := by dsimp; infer_instance
  rw [hP.affine_openCover_iff f 𝒰' fun i => Scheme.affineCover _]
  rw [hP.affine_openCover_iff (f ≫ g) Z.affineCover 𝒰] at h
  

Proof state:
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : PropertyIsLocal P
H :
  ∀ {R S T : Type u} [inst : CommRing R] [inst_1 : CommRing S] [inst_2 : CommRing T] (f : R →+* S) (g : S →+* T),
    P (comp g f) → P g
X Y Z : Scheme
f : X ⟶ Y
g : Y ⟶ Z
𝒰 : (i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover Z) (f ≫ g)).J) →
  Scheme.OpenCover (Scheme.OpenCover.obj (Scheme.OpenCover.pullbackCover (Scheme.affineCover Z) (f ≫ g)) i) :=
  fun i =>
    Scheme.OpenCover.bind
      (Scheme.OpenCover.pushforwardIso
        (Scheme.Pullback.openCoverOfRight
          (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover Z) i))) f pullback.fst)
        (pullbackRightPullbackFstIso g (Scheme.OpenCover.map (Scheme.affineCover Z) i) f).hom)
      fun i_1 =>
      Scheme.affineCover
        (Scheme.OpenCover.obj
          (Scheme.OpenCover.pushforwardIso
            (Scheme.Pullback.openCoverOfRight
              (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover Z) i))) f pullback.fst)
            (pullbackRightPullbackFstIso g (Scheme.OpenCover.map (Scheme.affineCover Z) i) f).hom)
          i_1)
h :
  ∀ (i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover Z) (f ≫ g)).J) (j : (𝒰 i).J),
    P (Scheme.Γ.map (Scheme.OpenCover.map (𝒰 i) j ≫ pullback.snd).op)
h𝒰 :
  ∀ (i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover Z) (f ≫ g)).J) (j : (𝒰 i).J),
    IsAffine (Scheme.OpenCover.obj (𝒰 i) j)
𝒰' : Scheme.OpenCover Y :=
  Scheme.OpenCover.bind (Scheme.OpenCover.pullbackCover (Scheme.affineCover Z) g) fun i =>
    Scheme.affineCover (Scheme.OpenCover.obj (Scheme.OpenCover.pullbackCover (Scheme.affineCover Z) g) i)
h𝒰' : ∀ (i : 𝒰'.J), IsAffine (Scheme.OpenCover.obj 𝒰' i)
⊢ ∀ (i : (Scheme.OpenCover.pullbackCover 𝒰' f).J)
    (j : (Scheme.affineCover (Scheme.OpenCover.obj (Scheme.OpenCover.pullbackCover 𝒰' f) i)).J),
    P
      (Scheme.Γ.map
        (Scheme.OpenCover.map (Scheme.affineCover (Scheme.OpenCover.obj (Scheme.OpenCover.pullbackCover 𝒰' f) i)) j ≫
            pullback.snd).op)

Next tactic:
rintro ⟨i, j⟩ k
theorem affineLocally_stableUnderComposition : (affineLocally @P).StableUnderComposition := by
  

Proof state:
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : PropertyIsLocal P
⊢ MorphismProperty.StableUnderComposition (affineLocally P)

Next tactic:
intro X Y S f g hf hg
theorem affineLocally_stableUnderComposition : (affineLocally @P).StableUnderComposition := by
  intro X Y S f g hf hg
  

Proof state:
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : PropertyIsLocal P
X Y S : Scheme
f : X ⟶ Y
g : Y ⟶ S
hf : affineLocally P f
hg : affineLocally P g
⊢ affineLocally P (f ≫ g)

Next tactic:
let 𝒰 : ∀ i, ((S.affineCover.pullbackCover (f ≫ g)).obj i).OpenCover := by
    intro i
    refine' Scheme.OpenCover.bind _ fun i => Scheme.affineCover _
    apply Scheme.OpenCover.pushforwardIso _
      (pullbackRightPullbackFstIso g (S.affineCover.map i) f).hom
    apply Scheme.Pullback.openCoverOfRight
    exact (pullback g (S.affineCover.map i)).affineCover
theorem affineLocally_stableUnderComposition : (affineLocally @P).StableUnderComposition := by
  intro X Y S f g hf hg
  let 𝒰 : ∀ i, ((S.affineCover.pullbackCover (f ≫ g)).obj i).OpenCover := by
    

Proof state:
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : PropertyIsLocal P
X Y S : Scheme
f : X ⟶ Y
g : Y ⟶ S
hf : affineLocally P f
hg : affineLocally P g
⊢ (i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)).J) →
    Scheme.OpenCover (Scheme.OpenCover.obj (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)) i)

Next tactic:
intro i
theorem affineLocally_stableUnderComposition : (affineLocally @P).StableUnderComposition := by
  intro X Y S f g hf hg
  let 𝒰 : ∀ i, ((S.affineCover.pullbackCover (f ≫ g)).obj i).OpenCover := by
    intro i
    

Proof state:
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : PropertyIsLocal P
X Y S : Scheme
f : X ⟶ Y
g : Y ⟶ S
hf : affineLocally P f
hg : affineLocally P g
i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)).J
⊢ Scheme.OpenCover (Scheme.OpenCover.obj (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)) i)

Next tactic:
refine' Scheme.OpenCover.bind _ fun i => Scheme.affineCover _
theorem affineLocally_stableUnderComposition : (affineLocally @P).StableUnderComposition := by
  intro X Y S f g hf hg
  let 𝒰 : ∀ i, ((S.affineCover.pullbackCover (f ≫ g)).obj i).OpenCover := by
    intro i
    refine' Scheme.OpenCover.bind _ fun i => Scheme.affineCover _
    

Proof state:
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : PropertyIsLocal P
X Y S : Scheme
f : X ⟶ Y
g : Y ⟶ S
hf : affineLocally P f
hg : affineLocally P g
i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)).J
⊢ Scheme.OpenCover (Scheme.OpenCover.obj (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)) i)

Next tactic:
apply Scheme.OpenCover.pushforwardIso _
      (pullbackRightPullbackFstIso g (S.affineCover.map i) f).hom
theorem affineLocally_stableUnderComposition : (affineLocally @P).StableUnderComposition := by
  intro X Y S f g hf hg
  let 𝒰 : ∀ i, ((S.affineCover.pullbackCover (f ≫ g)).obj i).OpenCover := by
    intro i
    refine' Scheme.OpenCover.bind _ fun i => Scheme.affineCover _
    apply Scheme.OpenCover.pushforwardIso _
      (pullbackRightPullbackFstIso g (S.affineCover.map i) f).hom
    

Proof state:
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : PropertyIsLocal P
X Y S : Scheme
f : X ⟶ Y
g : Y ⟶ S
hf : affineLocally P f
hg : affineLocally P g
i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)).J
⊢ Scheme.OpenCover (pullback f pullback.fst)

Next tactic:
apply Scheme.Pullback.openCoverOfRight
theorem affineLocally_stableUnderComposition : (affineLocally @P).StableUnderComposition := by
  intro X Y S f g hf hg
  let 𝒰 : ∀ i, ((S.affineCover.pullbackCover (f ≫ g)).obj i).OpenCover := by
    intro i
    refine' Scheme.OpenCover.bind _ fun i => Scheme.affineCover _
    apply Scheme.OpenCover.pushforwardIso _
      (pullbackRightPullbackFstIso g (S.affineCover.map i) f).hom
    apply Scheme.Pullback.openCoverOfRight
    

Proof state:
case 𝒰
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : PropertyIsLocal P
X Y S : Scheme
f : X ⟶ Y
g : Y ⟶ S
hf : affineLocally P f
hg : affineLocally P g
i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)).J
⊢ Scheme.OpenCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover S) i))

Next tactic:
exact (pullback g (S.affineCover.map i)).affineCover
theorem affineLocally_stableUnderComposition : (affineLocally @P).StableUnderComposition := by
  intro X Y S f g hf hg
  let 𝒰 : ∀ i, ((S.affineCover.pullbackCover (f ≫ g)).obj i).OpenCover := by
    intro i
    refine' Scheme.OpenCover.bind _ fun i => Scheme.affineCover _
    apply Scheme.OpenCover.pushforwardIso _
      (pullbackRightPullbackFstIso g (S.affineCover.map i) f).hom
    apply Scheme.Pullback.openCoverOfRight
    exact (pullback g (S.affineCover.map i)).affineCover
  -- Porting note: used to be - rw [hP.affine_openCover_iff (f ≫ g) S.affineCover _] - but
  -- metavariables cause problems in the instance search
  

Proof state:
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : PropertyIsLocal P
X Y S : Scheme
f : X ⟶ Y
g : Y ⟶ S
hf : affineLocally P f
hg : affineLocally P g
𝒰 : (i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)).J) →
  Scheme.OpenCover (Scheme.OpenCover.obj (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)) i) :=
  fun i =>
    Scheme.OpenCover.bind
      (Scheme.OpenCover.pushforwardIso
        (Scheme.Pullback.openCoverOfRight
          (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover S) i))) f pullback.fst)
        (pullbackRightPullbackFstIso g (Scheme.OpenCover.map (Scheme.affineCover S) i) f).hom)
      fun i_1 =>
      Scheme.affineCover
        (Scheme.OpenCover.obj
          (Scheme.OpenCover.pushforwardIso
            (Scheme.Pullback.openCoverOfRight
              (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover S) i))) f pullback.fst)
            (pullbackRightPullbackFstIso g (Scheme.OpenCover.map (Scheme.affineCover S) i) f).hom)
          i_1)
⊢ affineLocally P (f ≫ g)

Next tactic:
apply (@affine_openCover_iff _ hP _ _ (f ≫ g) S.affineCover _ ?_ ?_).mpr
theorem affineLocally_stableUnderComposition : (affineLocally @P).StableUnderComposition := by
  intro X Y S f g hf hg
  let 𝒰 : ∀ i, ((S.affineCover.pullbackCover (f ≫ g)).obj i).OpenCover := by
    intro i
    refine' Scheme.OpenCover.bind _ fun i => Scheme.affineCover _
    apply Scheme.OpenCover.pushforwardIso _
      (pullbackRightPullbackFstIso g (S.affineCover.map i) f).hom
    apply Scheme.Pullback.openCoverOfRight
    exact (pullback g (S.affineCover.map i)).affineCover
  -- Porting note: used to be - rw [hP.affine_openCover_iff (f ≫ g) S.affineCover _] - but
  -- metavariables cause problems in the instance search
  apply (@affine_openCover_iff _ hP _ _ (f ≫ g) S.affineCover _ ?_ ?_).mpr
  rotate_left
  · 

Proof state:
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : PropertyIsLocal P
X Y S : Scheme
f : X ⟶ Y
g : Y ⟶ S
hf : affineLocally P f
hg : affineLocally P g
𝒰 : (i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)).J) →
  Scheme.OpenCover (Scheme.OpenCover.obj (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)) i) :=
  fun i =>
    Scheme.OpenCover.bind
      (Scheme.OpenCover.pushforwardIso
        (Scheme.Pullback.openCoverOfRight
          (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover S) i))) f pullback.fst)
        (pullbackRightPullbackFstIso g (Scheme.OpenCover.map (Scheme.affineCover S) i) f).hom)
      fun i_1 =>
      Scheme.affineCover
        (Scheme.OpenCover.obj
          (Scheme.OpenCover.pushforwardIso
            (Scheme.Pullback.openCoverOfRight
              (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover S) i))) f pullback.fst)
            (pullbackRightPullbackFstIso g (Scheme.OpenCover.map (Scheme.affineCover S) i) f).hom)
          i_1)
⊢ (i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)).J) →
    Scheme.OpenCover (Scheme.OpenCover.obj (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)) i)

Next tactic:
exact 𝒰
theorem affineLocally_stableUnderComposition : (affineLocally @P).StableUnderComposition := by
  intro X Y S f g hf hg
  let 𝒰 : ∀ i, ((S.affineCover.pullbackCover (f ≫ g)).obj i).OpenCover := by
    intro i
    refine' Scheme.OpenCover.bind _ fun i => Scheme.affineCover _
    apply Scheme.OpenCover.pushforwardIso _
      (pullbackRightPullbackFstIso g (S.affineCover.map i) f).hom
    apply Scheme.Pullback.openCoverOfRight
    exact (pullback g (S.affineCover.map i)).affineCover
  -- Porting note: used to be - rw [hP.affine_openCover_iff (f ≫ g) S.affineCover _] - but
  -- metavariables cause problems in the instance search
  apply (@affine_openCover_iff _ hP _ _ (f ≫ g) S.affineCover _ ?_ ?_).mpr
  rotate_left
  · exact 𝒰
  · 

Proof state:
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : PropertyIsLocal P
X Y S : Scheme
f : X ⟶ Y
g : Y ⟶ S
hf : affineLocally P f
hg : affineLocally P g
𝒰 : (i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)).J) →
  Scheme.OpenCover (Scheme.OpenCover.obj (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)) i) :=
  fun i =>
    Scheme.OpenCover.bind
      (Scheme.OpenCover.pushforwardIso
        (Scheme.Pullback.openCoverOfRight
          (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover S) i))) f pullback.fst)
        (pullbackRightPullbackFstIso g (Scheme.OpenCover.map (Scheme.affineCover S) i) f).hom)
      fun i_1 =>
      Scheme.affineCover
        (Scheme.OpenCover.obj
          (Scheme.OpenCover.pushforwardIso
            (Scheme.Pullback.openCoverOfRight
              (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover S) i))) f pullback.fst)
            (pullbackRightPullbackFstIso g (Scheme.OpenCover.map (Scheme.affineCover S) i) f).hom)
          i_1)
⊢ ∀ (i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)).J) (j : (𝒰 i).J),
    IsAffine (Scheme.OpenCover.obj (𝒰 i) j)

Next tactic:
intro i j
theorem affineLocally_stableUnderComposition : (affineLocally @P).StableUnderComposition := by
  intro X Y S f g hf hg
  let 𝒰 : ∀ i, ((S.affineCover.pullbackCover (f ≫ g)).obj i).OpenCover := by
    intro i
    refine' Scheme.OpenCover.bind _ fun i => Scheme.affineCover _
    apply Scheme.OpenCover.pushforwardIso _
      (pullbackRightPullbackFstIso g (S.affineCover.map i) f).hom
    apply Scheme.Pullback.openCoverOfRight
    exact (pullback g (S.affineCover.map i)).affineCover
  -- Porting note: used to be - rw [hP.affine_openCover_iff (f ≫ g) S.affineCover _] - but
  -- metavariables cause problems in the instance search
  apply (@affine_openCover_iff _ hP _ _ (f ≫ g) S.affineCover _ ?_ ?_).mpr
  rotate_left
  · exact 𝒰
  · intro i j; 

Proof state:
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : PropertyIsLocal P
X Y S : Scheme
f : X ⟶ Y
g : Y ⟶ S
hf : affineLocally P f
hg : affineLocally P g
𝒰 : (i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)).J) →
  Scheme.OpenCover (Scheme.OpenCover.obj (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)) i) :=
  fun i =>
    Scheme.OpenCover.bind
      (Scheme.OpenCover.pushforwardIso
        (Scheme.Pullback.openCoverOfRight
          (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover S) i))) f pullback.fst)
        (pullbackRightPullbackFstIso g (Scheme.OpenCover.map (Scheme.affineCover S) i) f).hom)
      fun i_1 =>
      Scheme.affineCover
        (Scheme.OpenCover.obj
          (Scheme.OpenCover.pushforwardIso
            (Scheme.Pullback.openCoverOfRight
              (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover S) i))) f pullback.fst)
            (pullbackRightPullbackFstIso g (Scheme.OpenCover.map (Scheme.affineCover S) i) f).hom)
          i_1)
i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)).J
j : (𝒰 i).J
⊢ IsAffine (Scheme.OpenCover.obj (𝒰 i) j)

Next tactic:
dsimp at *
theorem affineLocally_stableUnderComposition : (affineLocally @P).StableUnderComposition := by
  intro X Y S f g hf hg
  let 𝒰 : ∀ i, ((S.affineCover.pullbackCover (f ≫ g)).obj i).OpenCover := by
    intro i
    refine' Scheme.OpenCover.bind _ fun i => Scheme.affineCover _
    apply Scheme.OpenCover.pushforwardIso _
      (pullbackRightPullbackFstIso g (S.affineCover.map i) f).hom
    apply Scheme.Pullback.openCoverOfRight
    exact (pullback g (S.affineCover.map i)).affineCover
  -- Porting note: used to be - rw [hP.affine_openCover_iff (f ≫ g) S.affineCover _] - but
  -- metavariables cause problems in the instance search
  apply (@affine_openCover_iff _ hP _ _ (f ≫ g) S.affineCover _ ?_ ?_).mpr
  rotate_left
  · exact 𝒰
  · intro i j; dsimp at *; 

Proof state:
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : PropertyIsLocal P
X Y S : Scheme
f : X ⟶ Y
g : Y ⟶ S
hf : affineLocally P f
hg : affineLocally P g
𝒰 : (i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)).J) →
  Scheme.OpenCover (Scheme.OpenCover.obj (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)) i) :=
  fun i =>
    Scheme.OpenCover.bind
      (Scheme.OpenCover.pushforwardIso
        (Scheme.Pullback.openCoverOfRight
          (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover S) i))) f pullback.fst)
        (pullbackRightPullbackFstIso g (Scheme.OpenCover.map (Scheme.affineCover S) i) f).hom)
      fun i_1 =>
      Scheme.affineCover
        (Scheme.OpenCover.obj
          (Scheme.OpenCover.pushforwardIso
            (Scheme.Pullback.openCoverOfRight
              (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover S) i))) f pullback.fst)
            (pullbackRightPullbackFstIso g (Scheme.OpenCover.map (Scheme.affineCover S) i) f).hom)
          i_1)
i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)).J
j : (𝒰 i).J
⊢ IsAffine
    (Scheme.OpenCover.obj
      (Scheme.affineCover
        (pullback f
          (Scheme.OpenCover.map (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover S) i)))
              j.fst ≫
            pullback.fst)))
      j.snd)

Next tactic:
infer_instance
theorem affineLocally_stableUnderComposition : (affineLocally @P).StableUnderComposition := by
  intro X Y S f g hf hg
  let 𝒰 : ∀ i, ((S.affineCover.pullbackCover (f ≫ g)).obj i).OpenCover := by
    intro i
    refine' Scheme.OpenCover.bind _ fun i => Scheme.affineCover _
    apply Scheme.OpenCover.pushforwardIso _
      (pullbackRightPullbackFstIso g (S.affineCover.map i) f).hom
    apply Scheme.Pullback.openCoverOfRight
    exact (pullback g (S.affineCover.map i)).affineCover
  -- Porting note: used to be - rw [hP.affine_openCover_iff (f ≫ g) S.affineCover _] - but
  -- metavariables cause problems in the instance search
  apply (@affine_openCover_iff _ hP _ _ (f ≫ g) S.affineCover _ ?_ ?_).mpr
  rotate_left
  · exact 𝒰
  · intro i j; dsimp at *; infer_instance
  · 

Proof state:
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : PropertyIsLocal P
X Y S : Scheme
f : X ⟶ Y
g : Y ⟶ S
hf : affineLocally P f
hg : affineLocally P g
𝒰 : (i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)).J) →
  Scheme.OpenCover (Scheme.OpenCover.obj (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)) i) :=
  fun i =>
    Scheme.OpenCover.bind
      (Scheme.OpenCover.pushforwardIso
        (Scheme.Pullback.openCoverOfRight
          (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover S) i))) f pullback.fst)
        (pullbackRightPullbackFstIso g (Scheme.OpenCover.map (Scheme.affineCover S) i) f).hom)
      fun i_1 =>
      Scheme.affineCover
        (Scheme.OpenCover.obj
          (Scheme.OpenCover.pushforwardIso
            (Scheme.Pullback.openCoverOfRight
              (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover S) i))) f pullback.fst)
            (pullbackRightPullbackFstIso g (Scheme.OpenCover.map (Scheme.affineCover S) i) f).hom)
          i_1)
⊢ ∀ (i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)).J) (j : (𝒰 i).J),
    P (Scheme.Γ.map (Scheme.OpenCover.map (𝒰 i) j ≫ pullback.snd).op)

Next tactic:
rintro i ⟨j, k⟩
theorem affineLocally_stableUnderComposition : (affineLocally @P).StableUnderComposition := by
  intro X Y S f g hf hg
  let 𝒰 : ∀ i, ((S.affineCover.pullbackCover (f ≫ g)).obj i).OpenCover := by
    intro i
    refine' Scheme.OpenCover.bind _ fun i => Scheme.affineCover _
    apply Scheme.OpenCover.pushforwardIso _
      (pullbackRightPullbackFstIso g (S.affineCover.map i) f).hom
    apply Scheme.Pullback.openCoverOfRight
    exact (pullback g (S.affineCover.map i)).affineCover
  -- Porting note: used to be - rw [hP.affine_openCover_iff (f ≫ g) S.affineCover _] - but
  -- metavariables cause problems in the instance search
  apply (@affine_openCover_iff _ hP _ _ (f ≫ g) S.affineCover _ ?_ ?_).mpr
  rotate_left
  · exact 𝒰
  · intro i j; dsimp at *; infer_instance
  · rintro i ⟨j, k⟩
    

Proof state:
case mk
P : {R S : Type u} → [inst : CommRing R] → [inst_1 : CommRing S] → (R →+* S) → Prop
hP : PropertyIsLocal P
X Y S : Scheme
f : X ⟶ Y
g : Y ⟶ S
hf : affineLocally P f
hg : affineLocally P g
𝒰 : (i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)).J) →
  Scheme.OpenCover (Scheme.OpenCover.obj (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)) i) :=
  fun i =>
    Scheme.OpenCover.bind
      (Scheme.OpenCover.pushforwardIso
        (Scheme.Pullback.openCoverOfRight
          (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover S) i))) f pullback.fst)
        (pullbackRightPullbackFstIso g (Scheme.OpenCover.map (Scheme.affineCover S) i) f).hom)
      fun i_1 =>
      Scheme.affineCover
        (Scheme.OpenCover.obj
          (Scheme.OpenCover.pushforwardIso
            (Scheme.Pullback.openCoverOfRight
              (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover S) i))) f pullback.fst)
            (pullbackRightPullbackFstIso g (Scheme.OpenCover.map (Scheme.affineCover S) i) f).hom)
          i_1)
i : (Scheme.OpenCover.pullbackCover (Scheme.affineCover S) (f ≫ g)).J
j :
  (Scheme.OpenCover.pushforwardIso
      (Scheme.Pullback.openCoverOfRight
        (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover S) i))) f pullback.fst)
      (pullbackRightPullbackFstIso g (Scheme.OpenCover.map (Scheme.affineCover S) i) f).hom).J
k :
  ((fun i_1 =>
        Scheme.affineCover
          (Scheme.OpenCover.obj
            (Scheme.OpenCover.pushforwardIso
              (Scheme.Pullback.openCoverOfRight
                (Scheme.affineCover (pullback g (Scheme.OpenCover.map (Scheme.affineCover S) i))) f pullback.fst)
              (pullbackRightPullbackFstIso g (Scheme.OpenCover.map (Scheme.affineCover S) i) f).hom)
            i_1))
      j).J
⊢ P (Scheme.Γ.map (Scheme.OpenCover.map (𝒰 i) { fst := j, snd := k } ≫ pullback.snd).op)

Next tactic:
dsimp at i j k