-- Module: Mathlib.AlgebraicGeometry.AffineTransitionLimit
Goal:
I : Type u
inst : Category.{u, u} I
D : I ⥤ Scheme
c : Cone D
hc : IsLimit c
inst_1 : IsCofiltered I
inst_2 : ∀ {i j : I} (f : i ⟶ j), IsAffineHom (D.map f)
s : (↑Γ(c.pt, ⊤) : Type u)
inst_3 : ∀ (i : I), CompactSpace.{u} ↥(D.obj i)
inst_4 : ∀ (i : I), QuasiSeparatedSpace.{u} ↥(D.obj i)
this_1 : CompactSpace.{u} ↥c.pt
i : (x : ↥c.pt) → I
U : (x : ↥c.pt) → (D.obj (i x)).Opens
hU : ∀ (x : ↥c.pt), IsAffineOpen (U x)
hxU : ∀ (x : ↥c.pt), Membership.mem (α := ↥(D.obj (i x))) (U x) ((c.π.app (i x)) x : ↥(D.obj (i x)))
t : (x : ↥c.pt) → (↑Γ(D.obj (i x), U x) : Type u)
ht :
  ∀ (x : ↥c.pt),
    Eq (α := (↑Γ(c.pt, c.π.app (i x) ⁻¹ᵁ U x) : Type u))
      ((ConcreteCategory.hom (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
              CommRingCat.carrier) (Y := Γ(c.pt, c.π.app (i x) ⁻¹ᵁ U x)) (Scheme.Hom.app (c.π.app (i x)) (U x)) :
            (a : (↑Γ(D.obj (i x), U x) : Type u)) → (↑Γ(c.pt, c.π.app (i x) ⁻¹ᵁ U x) : Type u))
          (t x) :
        (↑Γ(c.pt, c.π.app (i x) ⁻¹ᵁ U x) : Type u))
      (TopCat.Presheaf.restrictOpen (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
          CommRingCat.carrier) s (c.π.app (i x) ⁻¹ᵁ U x) ⋯ :
        ToType (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC := CommRingCat.carrier)
          (c.pt.presheaf.obj (Opposite.op (c.π.app (i x) ⁻¹ᵁ U x))))
j : (x y : ↥c.pt) → I
fjx : (x y : ↥c.pt) → j x y ⟶ i x
fjy : (x y : ↥c.pt) → j x y ⟶ i y
hj :
  ∀ (x y : ↥c.pt),
    Eq (α :=
      ToType (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC := CommRingCat.carrier)
        ((D.obj (j x y)).presheaf.obj (Opposite.op (D.map (fjx x y) ⁻¹ᵁ U x ⊓ D.map (fjy x y) ⁻¹ᵁ U y))))
      (TopCat.Presheaf.restrictOpen (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
        CommRingCat.carrier)
        ((ConcreteCategory.hom (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
              CommRingCat.carrier) (X := Γ(D.obj (i x), U x)) (Scheme.Hom.app (D.map (fjx x y)) (U x)) :
            (a : (↑Γ(D.obj (i x), U x) : Type u)) → (↑Γ(D.obj (j x y), D.map (fjx x y) ⁻¹ᵁ U x) : Type u))
          (t x))
        (D.map (fjx x y) ⁻¹ᵁ U x ⊓ D.map (fjy x y) ⁻¹ᵁ U y) ⋯)
      (TopCat.Presheaf.restrictOpen (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
        CommRingCat.carrier)
        ((ConcreteCategory.hom (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
              CommRingCat.carrier) (X := Γ(D.obj (i y), U y)) (Scheme.Hom.app (D.map (fjy x y)) (U y)) :
            (a : (↑Γ(D.obj (i y), U y) : Type u)) → (↑Γ(D.obj (j x y), D.map (fjy x y) ⁻¹ᵁ U y) : Type u))
          (t y))
        (D.map (fjx x y) ⁻¹ᵁ U x ⊓ D.map (fjy x y) ⁻¹ᵁ U y) ⋯)
σ : Finset ↥c.pt
hσ : Eq.{u + 1} (α := Set ↥c.pt) (⋃ x ∈ σ, (c.π.app (i x) ⁻¹ᵁ U x).carrier) ⊤
σi : (x : ↥c.pt) → ↥c.pt
hσiσ : ∀ (x : ↥c.pt), σi x ∈ σ
hσi :
  ∀ (x : ↥c.pt),
    Membership.mem (γ := Set ↥c.pt)
      (TopologicalSpace.Opens.carrier (c.π.app (i (σi x)) ⁻¹ᵁ U (σi x)) :
        Set ↥(Functor.obj (Functor.obj (Functor.const I) c.pt) (i (σi x))))
      x
S : Finset I := Finset.image i σ ∪ Finset.image₂ j σ σ
hiS : ∀ {x : ↥c.pt} (hx : x ∈ σ), i x ∈ S
hjS : ∀ {x y : ↥c.pt} (hx : x ∈ σ) (hy : y ∈ σ), j x y ∈ S
k : I
fk : {X : I} → X ∈ S → (k ⟶ X)
hk :
  ∀ {X Y : I} (mX : X ∈ S) (mY : Y ∈ S) {f : X ⟶ Y},
    Membership.mem (γ := Finset ((X : I) ×' (Y : I) ×' (_ : X ∈ S) ×' (_ : Y ∈ S) ×' (X ⟶ Y)))
        (Finset.image₂
            (fun (x y : ↥σ) ↦
              PSigma.mk (β := fun (X : I) ↦ (Y : I) ×' (_ : X ∈ S) ×' (_ : Y ∈ S) ×' (X ⟶ Y))
                (j (↑x : ↥c.pt) (↑y : ↥c.pt))
                (PSigma.mk (β := fun (Y : I) ↦
                  (_ : j (↑x : ↥c.pt) (↑y : ↥c.pt) ∈ S) ×' (_ : Y ∈ S) ×' (j (↑x : ↥c.pt) (↑y : ↥c.pt) ⟶ Y))
                  (i (↑x : ↥c.pt))
                  (PSigma.mk (β := fun (x_1 : j (↑x : ↥c.pt) (↑y : ↥c.pt) ∈ S) ↦
                    (_ : i (↑x : ↥c.pt) ∈ S) ×' (j (↑x : ↥c.pt) (↑y : ↥c.pt) ⟶ i (↑x : ↥c.pt))) ⋯
                    (PSigma.mk (β := fun (x_1 : i (↑x : ↥c.pt) ∈ S) ↦ j (↑x : ↥c.pt) (↑y : ↥c.pt) ⟶ i (↑x : ↥c.pt)) ⋯
                      (fjx (↑x : ↥c.pt) (↑y : ↥c.pt))))))
            σ.attach σ.attach ∪
          Finset.image₂
            (fun (x y : ↥σ) ↦
              PSigma.mk (β := fun (X : I) ↦ (Y : I) ×' (_ : X ∈ S) ×' (_ : Y ∈ S) ×' (X ⟶ Y))
                (j (↑x : ↥c.pt) (↑y : ↥c.pt))
                (PSigma.mk (β := fun (Y : I) ↦
                  (_ : j (↑x : ↥c.pt) (↑y : ↥c.pt) ∈ S) ×' (_ : Y ∈ S) ×' (j (↑x : ↥c.pt) (↑y : ↥c.pt) ⟶ Y))
                  (i (↑y : ↥c.pt))
                  (PSigma.mk (β := fun (x_1 : j (↑x : ↥c.pt) (↑y : ↥c.pt) ∈ S) ↦
                    (_ : i (↑y : ↥c.pt) ∈ S) ×' (j (↑x : ↥c.pt) (↑y : ↥c.pt) ⟶ i (↑y : ↥c.pt))) ⋯
                    (PSigma.mk (β := fun (x_1 : i (↑y : ↥c.pt) ∈ S) ↦ j (↑x : ↥c.pt) (↑y : ↥c.pt) ⟶ i (↑y : ↥c.pt)) ⋯
                      (fjy (↑x : ↥c.pt) (↑y : ↥c.pt))))))
            σ.attach σ.attach)
        (PSigma.mk (β := fun (X : I) ↦ (Y : I) ×' (_ : X ∈ S) ×' (_ : Y ∈ S) ×' (X ⟶ Y)) X
          (PSigma.mk (β := fun (Y : I) ↦ (_ : X ∈ S) ×' (_ : Y ∈ S) ×' (X ⟶ Y)) Y
            (PSigma.mk (β := fun (x : X ∈ S) ↦ (_ : Y ∈ S) ×' (X ⟶ Y)) mX
              (PSigma.mk (β := fun (x : Y ∈ S) ↦ X ⟶ Y) mY f)))) →
      fk mX ≫ f = fk mY
hk₁ : ∀ {x y : ↥c.pt} (hx : x ∈ σ) (hy : y ∈ σ), fk ⋯ ≫ fjx x y = fk ⋯
hk₂ : ∀ {x y : ↥c.pt} (hx : x ∈ σ) (hy : y ∈ σ), fk ⋯ ≫ fjy x y = fk ⋯
k' : I
fk'k : k' ⟶ k
hk' : D.map fk'k ⁻¹ᵁ ⨆ (x : ↥c.pt), ⨆ (hx : x ∈ σ), D.map (fk ⋯) ⁻¹ᵁ U x = ⊤
this :
  ∀
    (x :
      (i_1 : ↥σ) →
        ((D.obj k').presheaf ⋙
              forget CommRingCat (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
                CommRingCat.carrier)).obj
          (Opposite.op (D.map (fk'k ≫ fk ⋯) ⁻¹ᵁ U (↑i_1 : ↥c.pt)))),
    Presieve.Arrows.Compatible
        ((D.obj k').presheaf ⋙
          forget CommRingCat (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
            CommRingCat.carrier))
        (B := ⊤) (fun (x : ↥σ) ↦ homOfLE ⋯) x →
      ∃! t :
        (fun (X : Type u) ↦ X)
          (((D.obj k').presheaf ⋙
                forget CommRingCat (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
                  CommRingCat.carrier)).obj
            (Opposite.op ⊤)),
        ∀ (i_1 : ↥σ),
          (ConcreteCategory.hom (FC := TypeCat.Fun)
                  (((D.obj k').presheaf ⋙
                        forget CommRingCat (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
                          CommRingCat.carrier)).map
                    (Quiver.Hom.op (homOfLE ⋯))) :
                (a : (fun (X : Type u) ↦ X) (((D.obj k').presheaf ⋙ forget CommRingCat).obj (Opposite.op ⊤))) →
                  (fun (X : Type u) ↦ X)
                    (((D.obj k').presheaf ⋙ forget CommRingCat).obj
                      (Opposite.op (D.map (fk'k ≫ fk ⋯) ⁻¹ᵁ U (↑i_1 : ↥c.pt)))))
              t =
            x i_1
obtain :
  ∀
    (t₀ :
      ((D.obj k').presheaf ⋙
            forget CommRingCat (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
              CommRingCat.carrier)).obj
        (Opposite.op ⊤))
    (ht₀ :
      ∀ (i_1 : ↥σ),
        Eq (α :=
          (fun (X : Type u) ↦ X)
            (((D.obj k').presheaf ⋙
                  forget CommRingCat (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
                    CommRingCat.carrier)).obj
              (Opposite.op (D.map (fk'k ≫ fk ⋯) ⁻¹ᵁ U (↑i_1 : ↥c.pt)))))
          ((ConcreteCategory.hom (FC := TypeCat.Fun)
                  (((D.obj k').presheaf ⋙
                        forget CommRingCat (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
                          CommRingCat.carrier)).map
                    (Quiver.Hom.op (homOfLE ⋯))) :
                (a : (fun (X : Type u) ↦ X) (((D.obj k').presheaf ⋙ forget CommRingCat).obj (Opposite.op ⊤))) →
                  (fun (X : Type u) ↦ X)
                    (((D.obj k').presheaf ⋙ forget CommRingCat).obj
                      (Opposite.op (D.map (fk'k ≫ fk ⋯) ⁻¹ᵁ U (↑i_1 : ↥c.pt)))))
              t₀ :
            (fun (X : Type u) ↦ X)
              (((D.obj k').presheaf ⋙
                    forget CommRingCat (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
                      CommRingCat.carrier)).obj
                (Opposite.op (D.map (fk'k ≫ fk ⋯) ⁻¹ᵁ U (↑i_1 : ↥c.pt)))))
          ((ConcreteCategory.hom (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
                  CommRingCat.carrier) (X := Γ(D.obj (i (↑i_1 : ↥c.pt)), U (↑i_1 : ↥c.pt)))
                  (Scheme.Hom.app (D.map (fk'k ≫ fk ⋯)) (U (↑i_1 : ↥c.pt))) :
                (a : (↑Γ(D.obj (i (↑i_1 : ↥c.pt)), U (↑i_1 : ↥c.pt)) : Type u)) →
                  (↑Γ(D.obj k', D.map (fk'k ≫ fk ⋯) ⁻¹ᵁ U (↑i_1 : ↥c.pt)) : Type u))
              (t (↑i_1 : ↥c.pt)) :
            (↑Γ(D.obj k', D.map (fk'k ≫ fk ⋯) ⁻¹ᵁ U (↑i_1 : ↥c.pt)) : Type u))),
    ∃ (i : I) (t : (↑Γ(D.obj i, ⊤) : Type u)),
      s =
        (ConcreteCategory.hom (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
              CommRingCat.carrier) (Scheme.Hom.appTop (c.π.app i)) :
            (a : (↑Γ(D.obj i, ⊤) : Type u)) → (↑Γ(((Functor.const I).obj c.pt).obj i, ⊤) : Type u))
          t
⊢ ∃ (i : I) (t : (↑Γ(D.obj i, ⊤) : Type u)),
    s =
      (ConcreteCategory.hom (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
            CommRingCat.carrier) (Scheme.Hom.appTop (c.π.app i)) :
          (a : (↑Γ(D.obj i, ⊤) : Type u)) → (↑Γ(((Functor.const I).obj c.pt).obj i, ⊤) : Type u))
        t

Tactic:
obtain ⟨t₀, ht₀, -⟩ := this (fun x ↦ (D.map _).app _ (t x)) fun x y V fVx fVy _ ↦ by
    have H : V ≤ D.map (fk'k ≫ fk (hjS x.2 y.2)) ⁻¹ᵁ
        (D.map (fjx ↑x ↑y) ⁻¹ᵁ U ↑x ⊓ D.map (fjy ↑x ↑y) ⁻¹ᵁ U ↑y) := by
      change V ≤ (D.map (fk'k ≫ fk (hjS x.2 y.2)) ≫ D.map (fjx ↑x ↑y)) ⁻¹ᵁ U x ⊓
        (D.map (fk'k ≫ fk (hjS x.2 y.2)) ≫ D.map (fjy x y)) ⁻¹ᵁ U y
      rw [← Functor.map_comp, ← Functor.map_comp, Category.assoc, Category.assoc,
        hk₁ x.2 y.2, hk₂ x.2 y.2, le_inf_iff]
      exact ⟨fVx.le, fVy.le⟩
    convert!
      congr(((D.map (fk'k ≫ fk (hjS x.2 y.2))).app _ ≫ (D.obj k').presheaf.map (homOfLE H).op)
        $(hj x y)) using 1
    · dsimp [TopCat.Presheaf.restrictOpen, TopCat.Presheaf.restrict]
      simp only [← ConcreteCategory.comp_apply]
      congr 2
      simp [Scheme.Hom.app_eq_appLE, Scheme.Hom.appLE_comp_appLE,
        -Scheme.Hom.comp_appLE, ← Functor.map_comp, hk₁]
    · dsimp [TopCat.Presheaf.restrictOpen, TopCat.Presheaf.restrict]
      simp only [← ConcreteCategory.comp_apply]
      congr 2
      simp [Scheme.Hom.app_eq_appLE, Scheme.Hom.appLE_comp_appLE,
        -Scheme.Hom.comp_appLE, ← Functor.map_comp, hk₂]

Premises used: CategoryTheory.ConcreteCategory.hom, CategoryTheory.Functor.map, AlgebraicGeometry.Scheme.Hom.app, CategoryTheory.CategoryStruct.comp, Subtype.val, DFunLike.coe, Subtype.property