-- Module: Mathlib.AlgebraicGeometry.AffineTransitionLimit
Goal:
I : Type u
inst : Category.{u, u} I
S X : Scheme
D : I ⥤ Scheme
t : D ⟶ Functor.obj (Functor.const I) S
f : X ⟶ S
c : Cone D
hc : IsLimit c
inst_1 : IsCofiltered I
inst_2 : LocallyOfFinitePresentation f
inst_3 : ∀ {i j : I} (f : i ⟶ j), IsAffineHom (D.map f)
inst_4 : ∀ (i : I), CompactSpace.{u} ↥(D.obj i)
inst_5 : ∀ (i : I), QuasiSeparatedSpace.{u} ↥(D.obj i)
a : c.pt ⟶ X
ha : c.π ≫ t = CategoryTheory.Functor.map (Functor.const I) (a ≫ f)
𝒰 :
  IsOpenCover (X := ↥c.pt)
    fun
      (V :
        { x :
          TopologicalSpace.Opens ↥c.pt ×
            { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
              x.1 ∈ X.affineOpens ∧
                x.1 ≤
                  (Opens.comap (TopCat.Hom.hom f.base) : (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                    (↑x.2 : TopologicalSpace.Opens ↥S) } //
          Membership.mem (γ := Set (TopologicalSpace.Opens ↥c.pt)) c.pt.affineOpens x.1 ∧
            x.1 ≤
              (Opens.comap (TopCat.Hom.hom a.base) : (a : TopologicalSpace.Opens ↥X) → TopologicalSpace.Opens ↥c.pt)
                (↑x.2 : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u)).1 }) ↦
    (↑V :
        TopologicalSpace.Opens ↥c.pt ×
          { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
            x.1 ∈ X.affineOpens ∧
              x.1 ≤
                (Opens.comap (TopCat.Hom.hom f.base) : (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                  (↑x.2 : TopologicalSpace.Opens ↥S) }).1
i : I
s :
  Finset
    { x :
      TopologicalSpace.Opens ↥c.pt ×
        { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
          x.1 ∈ X.affineOpens ∧
            x.1 ≤
              (Opens.comap (TopCat.Hom.hom f.base) : (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                (↑x.2 : TopologicalSpace.Opens ↥S) } //
      Membership.mem (γ := Set (TopologicalSpace.Opens ↥c.pt)) c.pt.affineOpens x.1 ∧
        x.1 ≤
          (Opens.comap (TopCat.Hom.hom a.base) : (a : TopologicalSpace.Opens ↥X) → TopologicalSpace.Opens ↥c.pt)
            (↑x.2 : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u)).1 }
𝒱 : ↥s → (D.obj i).Opens
h𝒱 : IsOpenCover 𝒱
h𝒱𝒰 :
  ∀ (j : ↥s),
    IsAffineOpen (𝒱 j) ∧
      (↑(↑j :
                { x :
                  TopologicalSpace.Opens ↥c.pt ×
                    { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
                      x.1 ∈ X.affineOpens ∧
                        x.1 ≤
                          (Opens.comap (TopCat.Hom.hom f.base) :
                              (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                            (↑x.2 : TopologicalSpace.Opens ↥S) } //
                  x.1 ∈ c.pt.affineOpens ∧
                    x.1 ≤
                      (Opens.comap (TopCat.Hom.hom a.base) :
                          (a : TopologicalSpace.Opens ↥X) → TopologicalSpace.Opens ↥c.pt)
                        (↑x.2 : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u)).1 }) :
            TopologicalSpace.Opens ↥c.pt ×
              { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
                x.1 ∈ X.affineOpens ∧
                  x.1 ≤
                    (Opens.comap (TopCat.Hom.hom f.base) : (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                      (↑x.2 : TopologicalSpace.Opens ↥S) }).1 =
        c.π.app i ⁻¹ᵁ 𝒱 j
i' : I
fi'i : i' ⟶ i
hi' :
  ∀ (j : ↥s),
    D.map fi'i ⁻¹ᵁ 𝒱 j ≤
      t.app i' ⁻¹ᵁ
        (↑(↑(↑(↑j :
                          { x :
                            TopologicalSpace.Opens ↥c.pt ×
                              { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
                                x.1 ∈ X.affineOpens ∧
                                  x.1 ≤
                                    (Opens.comap (TopCat.Hom.hom f.base) :
                                        (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                                      (↑x.2 : TopologicalSpace.Opens ↥S) } //
                            x.1 ∈ c.pt.affineOpens ∧
                              x.1 ≤
                                (Opens.comap (TopCat.Hom.hom a.base) :
                                    (a : TopologicalSpace.Opens ↥X) → TopologicalSpace.Opens ↥c.pt)
                                  (↑x.2 : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u)).1 }) :
                      TopologicalSpace.Opens ↥c.pt ×
                        { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
                          x.1 ∈ X.affineOpens ∧
                            x.1 ≤
                              (Opens.comap (TopCat.Hom.hom f.base) :
                                  (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                                (↑x.2 : TopologicalSpace.Opens ↥S) }).2 :
                TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u)).2 :
          TopologicalSpace.Opens ↥S)
𝒱' : ↥s → (D.obj i').Opens := fun (x : ↥s) ↦ D.map fi'i ⁻¹ᵁ 𝒱 x
h𝒱'𝒰 :
  ∀ (j : ↥s),
    c.π.app i' ⁻¹ᵁ 𝒱' j =
      (↑(↑j :
              { x :
                TopologicalSpace.Opens ↥c.pt ×
                  { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
                    x.1 ∈ X.affineOpens ∧
                      x.1 ≤
                        (Opens.comap (TopCat.Hom.hom f.base) :
                            (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                          (↑x.2 : TopologicalSpace.Opens ↥S) } //
                x.1 ∈ c.pt.affineOpens ∧
                  x.1 ≤
                    (Opens.comap (TopCat.Hom.hom a.base) :
                        (a : TopologicalSpace.Opens ↥X) → TopologicalSpace.Opens ↥c.pt)
                      (↑x.2 : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u)).1 }) :
          TopologicalSpace.Opens ↥c.pt ×
            { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
              x.1 ∈ X.affineOpens ∧
                x.1 ≤
                  (Opens.comap (TopCat.Hom.hom f.base) : (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                    (↑x.2 : TopologicalSpace.Opens ↥S) }).1
h : ∀ (j : ↥s) (k : Over i'), IsAffine.{u} ((opensDiagram D i' (𝒱' j)).obj k)
t𝒱 : (j : ↥s) →
  opensDiagram D i' (𝒱' j) ⟶
    Functor.obj (Functor.const (Over i'))
      (↑(↑(↑(↑(↑j :
                            { x :
                              TopologicalSpace.Opens ↥c.pt ×
                                { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
                                  x.1 ∈ X.affineOpens ∧
                                    x.1 ≤
                                      (Opens.comap (TopCat.Hom.hom f.base) :
                                          (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                                        (↑x.2 : TopologicalSpace.Opens ↥S) } //
                              x.1 ∈ c.pt.affineOpens ∧
                                x.1 ≤
                                  (Opens.comap (TopCat.Hom.hom a.base) :
                                      (a : TopologicalSpace.Opens ↥X) → TopologicalSpace.Opens ↥c.pt)
                                    (↑x.2 : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u)).1 }) :
                        TopologicalSpace.Opens ↥c.pt ×
                          { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
                            x.1 ∈ X.affineOpens ∧
                              x.1 ≤
                                (Opens.comap (TopCat.Hom.hom f.base) :
                                    (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                                  (↑x.2 : TopologicalSpace.Opens ↥S) }).2 :
                  TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u)).2 :
            TopologicalSpace.Opens ↥S) :
        Scheme) :=
  fun (j : ↥s) ↦
    {
      app := fun (k : Over i') ↦
        Hom.resLE (t.app k.left)
          (↑(↑(↑(↑j :
                            { x :
                              TopologicalSpace.Opens ↥c.pt ×
                                { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
                                  x.1 ∈ X.affineOpens ∧
                                    x.1 ≤
                                      (Opens.comap (TopCat.Hom.hom f.base) :
                                          (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                                        (↑x.2 : TopologicalSpace.Opens ↥S) } //
                              x.1 ∈ c.pt.affineOpens ∧
                                x.1 ≤
                                  (Opens.comap (TopCat.Hom.hom a.base) :
                                      (a : TopologicalSpace.Opens ↥X) → TopologicalSpace.Opens ↥c.pt)
                                    (↑x.2 : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u)).1 }) :
                        TopologicalSpace.Opens ↥c.pt ×
                          { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
                            x.1 ∈ X.affineOpens ∧
                              x.1 ≤
                                (Opens.comap (TopCat.Hom.hom f.base) :
                                    (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                                  (↑x.2 : TopologicalSpace.Opens ↥S) }).2 :
                  TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u)).2 :
            TopologicalSpace.Opens ↥S)
          (D.map k.hom ⁻¹ᵁ 𝒱' j) ⋯,
      naturality := ⋯ }
this :
  ∀ (j : ↥s),
    IsAffine.{u}
      (↑(↑(↑(↑j :
                        { x :
                          TopologicalSpace.Opens ↥c.pt ×
                            { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
                              x.1 ∈ X.affineOpens ∧
                                x.1 ≤
                                  (Opens.comap (TopCat.Hom.hom f.base) :
                                      (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                                    (↑x.2 : TopologicalSpace.Opens ↥S) } //
                          x.1 ∈ c.pt.affineOpens ∧
                            x.1 ≤
                              (Opens.comap (TopCat.Hom.hom a.base) :
                                  (a : TopologicalSpace.Opens ↥X) → TopologicalSpace.Opens ↥c.pt)
                                (↑x.2 : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u)).1 }) :
                    TopologicalSpace.Opens ↥c.pt ×
                      { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
                        x.1 ∈ X.affineOpens ∧
                          x.1 ≤
                            (Opens.comap (TopCat.Hom.hom f.base) :
                                (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                              (↑x.2 : TopologicalSpace.Opens ↥S) }).2 :
              TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u)).1 :
        Scheme)
choose :
  ∀ (k : (j : ↥s) → Over i')
    (ak :
      (j : ↥s) →
        (opensDiagram D i' (𝒱' j)).obj (k j) ⟶
          (↑(↑(↑(↑j :
                            { x :
                              TopologicalSpace.Opens ↥c.pt ×
                                { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
                                  x.1 ∈ X.affineOpens ∧
                                    x.1 ≤
                                      (Opens.comap (TopCat.Hom.hom f.base) :
                                          (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                                        (↑x.2 : TopologicalSpace.Opens ↥S) } //
                              x.1 ∈ c.pt.affineOpens ∧
                                x.1 ≤
                                  (Opens.comap (TopCat.Hom.hom a.base) :
                                      (a : TopologicalSpace.Opens ↥X) → TopologicalSpace.Opens ↥c.pt)
                                    (↑x.2 : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u)).1 }) :
                        TopologicalSpace.Opens ↥c.pt ×
                          { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
                            x.1 ∈ X.affineOpens ∧
                              x.1 ≤
                                (Opens.comap (TopCat.Hom.hom f.base) :
                                    (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                                  (↑x.2 : TopologicalSpace.Opens ↥S) }).2 :
                  TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u)).1 :
            Scheme))
    (hk :
      ∀ (j : ↥s),
        NatTrans.app (Cone.π (opensCone D c i' (𝒱' j))) (k j) ≫ ak j =
          Hom.resLE a
            (↑(↑(↑j :
                          { x :
                            TopologicalSpace.Opens ↥c.pt ×
                              { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
                                x.1 ∈ X.affineOpens ∧
                                  x.1 ≤
                                    (Opens.comap (TopCat.Hom.hom f.base) :
                                        (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                                      (↑x.2 : TopologicalSpace.Opens ↥S) } //
                            x.1 ∈ c.pt.affineOpens ∧
                              x.1 ≤
                                (Opens.comap (TopCat.Hom.hom a.base) :
                                    (a : TopologicalSpace.Opens ↥X) → TopologicalSpace.Opens ↥c.pt)
                                  (↑x.2 : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u)).1 }) :
                      TopologicalSpace.Opens ↥c.pt ×
                        { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
                          x.1 ∈ X.affineOpens ∧
                            x.1 ≤
                              (Opens.comap (TopCat.Hom.hom f.base) :
                                  (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                                (↑x.2 : TopologicalSpace.Opens ↥S) }).2 :
                TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u)).1
            (c.π.app i' ⁻¹ᵁ 𝒱' j) ⋯)
    (hk' :
      ∀ (j : ↥s),
        ak j ≫
            Hom.resLE f
              (↑(↑(↑(↑j :
                                { x :
                                  TopologicalSpace.Opens ↥c.pt ×
                                    { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
                                      x.1 ∈ X.affineOpens ∧
                                        x.1 ≤
                                          (Opens.comap (TopCat.Hom.hom f.base) :
                                              (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                                            (↑x.2 : TopologicalSpace.Opens ↥S) } //
                                  x.1 ∈ c.pt.affineOpens ∧
                                    x.1 ≤
                                      (Opens.comap (TopCat.Hom.hom a.base) :
                                          (a : TopologicalSpace.Opens ↥X) → TopologicalSpace.Opens ↥c.pt)
                                        (↑x.2 : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u)).1 }) :
                            TopologicalSpace.Opens ↥c.pt ×
                              { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
                                x.1 ∈ X.affineOpens ∧
                                  x.1 ≤
                                    (Opens.comap (TopCat.Hom.hom f.base) :
                                        (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                                      (↑x.2 : TopologicalSpace.Opens ↥S) }).2 :
                      TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u)).2 :
                TopologicalSpace.Opens ↥S)
              (↑(↑(↑j :
                            { x :
                              TopologicalSpace.Opens ↥c.pt ×
                                { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
                                  x.1 ∈ X.affineOpens ∧
                                    x.1 ≤
                                      (Opens.comap (TopCat.Hom.hom f.base) :
                                          (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                                        (↑x.2 : TopologicalSpace.Opens ↥S) } //
                              x.1 ∈ c.pt.affineOpens ∧
                                x.1 ≤
                                  (Opens.comap (TopCat.Hom.hom a.base) :
                                      (a : TopologicalSpace.Opens ↥X) → TopologicalSpace.Opens ↥c.pt)
                                    (↑x.2 : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u)).1 }) :
                        TopologicalSpace.Opens ↥c.pt ×
                          { x : TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u) //
                            x.1 ∈ X.affineOpens ∧
                              x.1 ≤
                                (Opens.comap (TopCat.Hom.hom f.base) :
                                    (a : TopologicalSpace.Opens ↥S) → TopologicalSpace.Opens ↥X)
                                  (↑x.2 : TopologicalSpace.Opens ↥S) }).2 :
                  TopologicalSpace.Opens ↥X × (↑S.affineOpens : Type u)).1
              ⋯ =
          (t𝒱 j).app (k j)),
    ∃ (k : I) (fk : k ⟶ i),
      ∀ (j : ↥s),
        ∃ (ak : (↑(D.map fk ⁻¹ᵁ 𝒱 j) : Scheme) ⟶ X),
          ak ≫ f = (D.map fk ⁻¹ᵁ 𝒱 j).ι ≫ t.app k ∧
            c.π.app k ∣_ D.map fk ⁻¹ᵁ 𝒱 j ≫ ak = (c.π.app k ⁻¹ᵁ D.map fk ⁻¹ᵁ 𝒱 j).ι ≫ a
⊢ ∃ (k : I) (fk : k ⟶ i),
    ∀ (j : ↥s),
      ∃ (ak : (↑(D.map fk ⁻¹ᵁ 𝒱 j) : Scheme) ⟶ X),
        ak ≫ f = (D.map fk ⁻¹ᵁ 𝒱 j).ι ≫ t.app k ∧
          c.π.app k ∣_ D.map fk ⁻¹ᵁ 𝒱 j ≫ ak = (c.π.app k ⁻¹ᵁ D.map fk ⁻¹ᵁ 𝒱 j).ι ≫ a

Tactic:
choose k ak hk hk' using fun j ↦ exists_π_app_comp_eq_of_locallyOfFinitePresentation_of_isAffine
      _ (t𝒱 j) (f.resLE _ _ j.1.1.2.prop.2) _ (isLimitOpensCone D c hc i' (𝒱' j))
      (a.resLE _ _ ((h𝒱'𝒰 _).trans_le j.1.prop.2)) (by
      ext k
      simp [t𝒱, Hom.resLE_comp_resLE, show c.π.app k.left ≫ t.app k.left = a ≫ f from
        congr(($ha).app k.left)])

Premises used: CategoryTheory.Limits.Cone.π, _private.0.AlgebraicGeometry.Scheme.exists_π_app_comp_eq_of_locallyOfFinitePresentation_of_isAffine, AlgebraicGeometry.isLimitOpensCone, Eq.trans_le, AlgebraicGeometry.LocallyRingedSpace.Hom.toHom, AlgebraicGeometry.Scheme.Hom.toLRSHom', Prod.fst, AlgebraicGeometry.opensDiagram, And.right, Subtype.prop, AlgebraicGeometry.PresheafedSpace.Hom.base, TopologicalSpace.Opens.map, AlgebraicGeometry.opensCone, Subtype.val, Prod.snd, CategoryTheory.Functor.obj, CategoryTheory.NatTrans.app, AlgebraicGeometry.Scheme.Hom.resLE