-- Lean 4 proof step from Mathlib.AlgebraicGeometry.AffineTransitionLimit (goal)
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)
inst_3 : ∀ (i : I), CompactSpace.{u} ↥(D.obj i)
inst_4 : ∀ (i : I), QuasiSeparatedSpace.{u} ↥(D.obj i)
inst_5 : IsQuasiAffine.{u} c.pt
have :
  ∀ (x : ↥c.pt),
    ∃ (i : I) (f : (↑Γ(D.obj i, ⊤) : Type u)),
      IsAffineOpen ((D.obj i).basicOpen f) ∧
        Membership.mem (α := ↥(D.obj i)) ((D.obj i).basicOpen f) ((c.π.app i) x : ↥(D.obj i))
have₁ :
  ∀
    (this :
      ∀ (x : ↥c.pt),
        ∃ (i : I) (f : (↑Γ(D.obj i, ⊤) : Type u)),
          IsAffineOpen ((D.obj i).basicOpen f) ∧
            Membership.mem (α := ↥(D.obj i)) ((D.obj i).basicOpen f) ((c.π.app i) x : ↥(D.obj i))),
    ∃ (i : I), IsQuasiAffine.{u} (D.obj i)
have₂ :
  ∀ (x : ↥c.pt),
    ∃ (i : I) (f : (↑Γ(D.obj i, ⊤) : Type u)),
      IsAffineOpen ((D.obj i).basicOpen f) ∧
        Membership.mem (α := ↥(D.obj i)) ((D.obj i).basicOpen f) ((c.π.app i) x : ↥(D.obj i))
have₃ have₄ :
  ∀
    (this :
      ∀ (x : ↥c.pt),
        ∃ (i : I) (f : (↑Γ(D.obj i, ⊤) : Type u)),
          IsAffineOpen ((D.obj i).basicOpen f) ∧
            Membership.mem (α := ↥(D.obj i)) ((D.obj i).basicOpen f) ((c.π.app i) x : ↥(D.obj i))),
    ∃ (i : I), IsQuasiAffine.{u} (D.obj i)
have₅ :
  ∀ (i : (x : ↥c.pt) → I) (f : (x : ↥c.pt) → (↑Γ(D.obj (i x), ⊤) : Type u))
    (hf : ∀ (x : ↥c.pt), IsAffineOpen ((D.obj (i x)).basicOpen (f x)))
    (hi :
      ∀ (x : ↥c.pt),
        Membership.mem (α := ↥(D.obj (i x))) ((D.obj (i x)).basicOpen (f x)) ((c.π.app (i x)) x : ↥(D.obj (i x)))),
    ∃ (i : I), IsQuasiAffine.{u} (D.obj i)
have₆ :
  ∀ (i : (x : ↥c.pt) → I) (f : (x : ↥c.pt) → (↑Γ(D.obj (i x), ⊤) : Type u))
    (hf : ∀ (x : ↥c.pt), IsAffineOpen ((D.obj (i x)).basicOpen (f x)))
    (hi :
      ∀ (x : ↥c.pt),
        Membership.mem (α := ↥(D.obj (i x))) ((D.obj (i x)).basicOpen (f x)) ((c.π.app (i x)) x : ↥(D.obj (i x))))
    (σ : Finset ↥c.pt)
    (hσ : Eq.{u + 1} (α := Set ↥c.pt) (⋃ x ∈ σ, (c.π.app (i x) ⁻¹ᵁ (D.obj (i x)).basicOpen (f x)).carrier) ⊤),
    ∃ (i : I), IsQuasiAffine.{u} (D.obj i)
have₇ :
  ∀ (i : (x : ↥c.pt) → I) (f : (x : ↥c.pt) → (↑Γ(D.obj (i x), ⊤) : Type u))
    (hf : ∀ (x : ↥c.pt), IsAffineOpen ((D.obj (i x)).basicOpen (f x)))
    (hi :
      ∀ (x : ↥c.pt),
        Membership.mem (α := ↥(D.obj (i x))) ((D.obj (i x)).basicOpen (f x)) ((c.π.app (i x)) x : ↥(D.obj (i x))))
    (σ : Finset ↥c.pt)
    (hσ : Eq.{u + 1} (α := Set ↥c.pt) (⋃ x ∈ σ, (c.π.app (i x) ⁻¹ᵁ (D.obj (i x)).basicOpen (f 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)) ⁻¹ᵁ (D.obj (i (σi x))).basicOpen (f (σi x))) :
            Set ↥(Functor.obj (Functor.obj (Functor.const I) c.pt) (i (σi x))))
          x),
    ∃ (i : I), IsQuasiAffine.{u} (D.obj i)
have₈ :
  ∀ (i : (x : ↥c.pt) → I) (f : (x : ↥c.pt) → (↑Γ(D.obj (i x), ⊤) : Type u))
    (hf : ∀ (x : ↥c.pt), IsAffineOpen ((D.obj (i x)).basicOpen (f x)))
    (hi :
      ∀ (x : ↥c.pt),
        Membership.mem (α := ↥(D.obj (i x))) ((D.obj (i x)).basicOpen (f x)) ((c.π.app (i x)) x : ↥(D.obj (i x))))
    (σ : Finset ↥c.pt)
    (hσ : Eq.{u + 1} (α := Set ↥c.pt) (⋃ x ∈ σ, (c.π.app (i x) ⁻¹ᵁ (D.obj (i x)).basicOpen (f 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)) ⁻¹ᵁ (D.obj (i (σi x))).basicOpen (f (σi x))) :
            Set ↥(Functor.obj (Functor.obj (Functor.const I) c.pt) (i (σi x))))
          x)
    (j : I) (fj : ∀ {X : I}, X ∈ Finset.image i σ → Nonempty.{u + 1} (j ⟶ X)), ∃ (i : I), IsQuasiAffine.{u} (D.obj i)
have₉ :
  ∀ (i : (x : ↥c.pt) → I) (f : (x : ↥c.pt) → (↑Γ(D.obj (i x), ⊤) : Type u))
    (hf : ∀ (x : ↥c.pt), IsAffineOpen ((D.obj (i x)).basicOpen (f x)))
    (hi :
      ∀ (x : ↥c.pt),
        Membership.mem (α := ↥(D.obj (i x))) ((D.obj (i x)).basicOpen (f x)) ((c.π.app (i x)) x : ↥(D.obj (i x))))
    (σ : Finset ↥c.pt)
    (hσ : Eq.{u + 1} (α := Set ↥c.pt) (⋃ x ∈ σ, (c.π.app (i x) ⁻¹ᵁ (D.obj (i x)).basicOpen (f 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)) ⁻¹ᵁ (D.obj (i (σi x))).basicOpen (f (σi x))) :
            Set ↥(Functor.obj (Functor.obj (Functor.const I) c.pt) (i (σi x))))
          x)
    (j : I) (fj : (i_1 : I) → (h : i_1 ∈ Finset.image i σ) → j ⟶ i_1), ∃ (i : I), IsQuasiAffine.{u} (D.obj i)
have₁₀ :
  ∀ (i : (x : ↥c.pt) → I) (f : (x : ↥c.pt) → (↑Γ(D.obj (i x), ⊤) : Type u))
    (hf : ∀ (x : ↥c.pt), IsAffineOpen ((D.obj (i x)).basicOpen (f x)))
    (hi :
      ∀ (x : ↥c.pt),
        Membership.mem (α := ↥(D.obj (i x))) ((D.obj (i x)).basicOpen (f x)) ((c.π.app (i x)) x : ↥(D.obj (i x))))
    (σ : Finset ↥c.pt)
    (hσ : Eq.{u + 1} (α := Set ↥c.pt) (⋃ x ∈ σ, (c.π.app (i x) ⁻¹ᵁ (D.obj (i x)).basicOpen (f 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)) ⁻¹ᵁ (D.obj (i (σi x))).basicOpen (f (σi x))) :
            Set ↥(Functor.obj (Functor.obj (Functor.const I) c.pt) (i (σi x))))
          x)
    (j : I) (fj : (i_1 : I) → (h : i_1 ∈ Finset.image i σ) → j ⟶ i_1) (k : I) (fkj : k ⟶ j)
    (hk : D.map fkj ⁻¹ᵁ ⨆ (k : ↥c.pt), D.map (fj (i (σi k)) ⋯) ⁻¹ᵁ (D.obj (i (σi k))).basicOpen (f (σi k)) = ⊤),
    ∃ (i : I), IsQuasiAffine.{u} (D.obj i)
have₁₁ :
  ∀ (i : (x : ↥c.pt) → I) (f : (x : ↥c.pt) → (↑Γ(D.obj (i x), ⊤) : Type u))
    (hf : ∀ (x : ↥c.pt), IsAffineOpen ((D.obj (i x)).basicOpen (f x)))
    (hi :
      ∀ (x : ↥c.pt),
        Membership.mem (α := ↥(D.obj (i x))) ((D.obj (i x)).basicOpen (f x)) ((c.π.app (i x)) x : ↥(D.obj (i x))))
    (σ : Finset ↥c.pt)
    (hσ : Eq.{u + 1} (α := Set ↥c.pt) (⋃ x ∈ σ, (c.π.app (i x) ⁻¹ᵁ (D.obj (i x)).basicOpen (f 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)) ⁻¹ᵁ (D.obj (i (σi x))).basicOpen (f (σi x))) :
            Set ↥(Functor.obj (Functor.obj (Functor.const I) c.pt) (i (σi x))))
          x)
    (j : I) (fj : (i_1 : I) → (h : i_1 ∈ Finset.image i σ) → j ⟶ i_1) (k : I) (fkj : k ⟶ j)
    (hk : D.map fkj ⁻¹ᵁ ⨆ (k : ↥c.pt), D.map (fj (i (σi k)) ⋯) ⁻¹ᵁ (D.obj (i (σi k))).basicOpen (f (σi k)) = ⊤)
    (x : ↥(D.obj k)),
    ∃ (r : (↑Γ(D.obj k, ⊤) : Type u)), IsAffineOpen ((D.obj k).basicOpen r) ∧ x ∈ (D.obj k).basicOpen r
have₁₂ :
  ∀ (i : (x : ↥c.pt) → I) (f : (x : ↥c.pt) → (↑Γ(D.obj (i x), ⊤) : Type u))
    (hf : ∀ (x : ↥c.pt), IsAffineOpen ((D.obj (i x)).basicOpen (f x)))
    (hi :
      ∀ (x : ↥c.pt),
        Membership.mem (α := ↥(D.obj (i x))) ((D.obj (i x)).basicOpen (f x)) ((c.π.app (i x)) x : ↥(D.obj (i x))))
    (σ : Finset ↥c.pt)
    (hσ : Eq.{u + 1} (α := Set ↥c.pt) (⋃ x ∈ σ, (c.π.app (i x) ⁻¹ᵁ (D.obj (i x)).basicOpen (f 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)) ⁻¹ᵁ (D.obj (i (σi x))).basicOpen (f (σi x))) :
            Set ↥(Functor.obj (Functor.obj (Functor.const I) c.pt) (i (σi x))))
          x)
    (j : I) (fj : (i_1 : I) → (h : i_1 ∈ Finset.image i σ) → j ⟶ i_1) (k : I) (fkj : k ⟶ j)
    (hk : D.map fkj ⁻¹ᵁ ⨆ (k : ↥c.pt), D.map (fj (i (σi k)) ⋯) ⁻¹ᵁ (D.obj (i (σi k))).basicOpen (f (σi k)) = ⊤)
    (x : ↥(D.obj k)) (y : ↥c.pt)
    (hy :
      Membership.mem (α := ↥(D.obj j)) (D.map (fj (i (σi y)) ⋯) ⁻¹ᵁ (D.obj (i (σi y))).basicOpen (f (σi y)))
        ((D.map fkj) x : ↥(D.obj j))),
    ∃ (r : (↑Γ(D.obj k, ⊤) : Type u)), IsAffineOpen ((D.obj k).basicOpen r) ∧ x ∈ (D.obj k).basicOpen r
⊢ ∃ (i : I), IsQuasiAffine.{u} (D.obj i)
have h : ∀ (i : (x : ↥c.pt) → I) (f : (x : ↥c.pt) → (↑Γ(D.obj (i x), ⊤) : Type u))
  (hf : ∀ (x : ↥c.pt), IsAffineOpen ((D.obj (i x)).basicOpen (f x)))
  (hi :
    ∀ (x : ↥c.pt),
      Membership.mem (α := ↥(D.obj (i x))) ((D.obj (i x)).basicOpen (f x)) ((c.π.app (i x)) x : ↥(D.obj (i x))))
  (σ : Finset ↥c.pt)
  (hσ : Eq.{u + 1} (α := Set ↥c.pt) (⋃ x ∈ σ, (c.π.app (i x) ⁻¹ᵁ (D.obj (i x)).basicOpen (f 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)) ⁻¹ᵁ (D.obj (i (σi x))).basicOpen (f (σi x))) :
          Set ↥(Functor.obj (Functor.obj (Functor.const I) c.pt) (i (σi x))))
        x)
  (j : I) (fj : (i_1 : I) → (h : i_1 ∈ Finset.image i σ) → j ⟶ i_1) (k : I) (fkj : k ⟶ j)
  (hk : D.map fkj ⁻¹ᵁ ⨆ (k : ↥c.pt), D.map (fj (i (σi k)) sorry) ⁻¹ᵁ (D.obj (i (σi k))).basicOpen (f (σi k)) = ⊤)
  (x : ↥(D.obj k)) (y : ↥c.pt)
  (hy :
    Membership.mem (α := ↥(D.obj j)) (D.map (fj (i (σi y)) sorry) ⁻¹ᵁ (D.obj (i (σi y))).basicOpen (f (σi y)))
      ((D.map fkj) x : ↥(D.obj j))),
  IsAffineOpen.{u} (X := D.obj k)
      ((D.obj k).basicOpen (U := ⊤)
        ((ConcreteCategory.hom (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
              CommRingCat.carrier) (Hom.appTop (D.map fkj)) :
            (a : (↑Γ(D.obj j, ⊤) : Type u)) → (↑Γ(D.obj k, ⊤) : Type u))
          ((ConcreteCategory.hom (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
                  CommRingCat.carrier) (Hom.appTop (D.map (fj (i (σi y)) sorry))) :
                (a : (↑Γ(D.obj (i (σi y)), ⊤) : Type u)) → (↑Γ(D.obj j, ⊤) : Type u))
              (f (σi y)) :
            (↑Γ(D.obj j, ⊤) : Type u)))) ∧
    Membership.mem (γ := (D.obj k).Opens)
      ((D.obj k).basicOpen (U := ⊤)
        ((ConcreteCategory.hom (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
              CommRingCat.carrier) (Hom.appTop (D.map fkj)) :
            (a : (↑Γ(D.obj j, ⊤) : Type u)) → (↑Γ(D.obj k, ⊤) : Type u))
          ((ConcreteCategory.hom (FC := fun (R S : CommRingCat.{u}) ↦ (↑R : Type u) →+* (↑S : Type u)) (CC :=
                  CommRingCat.carrier) (Hom.appTop (D.map (fj (i (σi y)) sorry))) :
                (a : (↑Γ(D.obj (i (σi y)), ⊤) : Type u)) → (↑Γ(D.obj j, ⊤) : Type u))
              (f (σi y)) :
            (↑Γ(D.obj j, ⊤) : Type u))))
      x
Tactic: classical
  have (x : c.pt) : ∃ (i : I) (f : Γ(D.obj i, ⊤)),
      IsAffineOpen (Scheme.basicOpen _ f) ∧ c.π.app i x ∈ (Scheme.basicOpen _ f) := by
    obtain ⟨i⟩ := IsCofiltered.nonempty (C := I)
    obtain ⟨_, ⟨U, hU, rfl⟩, hxU, -⟩ := (D.obj i).isBasis_affineOpens.exists_subset_of_mem_open
      (Set.mem_univ (c.π.app i x)) isOpen_univ
    obtain ⟨_, ⟨_, ⟨r, hr, rfl⟩, rfl⟩, hxr, hrU⟩ :=
      (IsQuasiAffine.isBasis_basicOpen c.pt).exists_subset_of_mem_open hxU (c.π.app i ⁻¹ᵁ U).isOpen
    obtain ⟨j, r, rfl⟩ := exists_appTop_π_eq_of_isLimit D c hc r
    obtain ⟨k, fki, fkj, -⟩ := IsCofilteredOrEmpty.cone_objs i j
    obtain ⟨l, flk, hl⟩ := exists_map_preimage_le_map_preimage D c hc (isCompact_basicOpen _
      isCompact_univ ((D.map fkj).appTop r)) (V := D.map fki ⁻¹ᵁ U) (by
        rwa [← preimage_basicOpen_top, ← Hom.comp_preimage, ← Hom.comp_preimage,
          c.w, c.w, preimage_basicOpen_top])
    refine ⟨l, (D.map (flk ≫ fkj)).appTop r, ?_, ?_⟩
    · convert!
      (hU.preimage (D.map (flk ≫ fki))).basicOpen
        ((D.obj _).presheaf.map (homOfLE le_top).op ((D.map (flk ≫ fkj)).appTop r)) using 1
      rwa [Scheme.basicOpen_res, eq_comm, inf_eq_right, Functor.map_comp,
        elementwise_of% Scheme.Hom.comp_appTop, ← Scheme.preimage_basicOpen_top, Functor.map_comp,
        Scheme.Hom.comp_preimage]
    · change x ∈ c.π.app l ⁻¹ᵁ (D.obj l).basicOpen _
      rwa [Scheme.preimage_basicOpen_top, ← elementwise_of% Scheme.Hom.comp_appTop, Cone.w]
  choose i f hf hi using this
  obtain ⟨σ, hσ⟩ := CompactSpace.elim_nhds_subcover
    (fun x ↦ (((c.π.app (i x)) ⁻¹ᵁ (D.obj (i x)).basicOpen (f x)).1))
    (fun x ↦ ((c.π.app (i x)) ⁻¹ᵁ (D.obj (i x)).basicOpen (f x)).2.mem_nhds (by exact hi x))
  choose σi hσiσ hσi using fun x ↦ Set.mem_iUnion₂.mp (hσ.ge (Set.mem_univ x))
  obtain ⟨j, fj⟩ := IsCofiltered.inf_objs_exists (σ.image i)
  replace fj := fun i h ↦ (@fj i h).some
  obtain ⟨k, fkj, hk⟩ := exists_map_eq_top D c hc
    (⨆ k, D.map (fj _ (Finset.mem_image_of_mem i (hσiσ k))) ⁻¹ᵁ (D.obj (i _)).basicOpen (f _)) (by
      refine top_le_iff.mp fun x _ ↦ TopologicalSpace.Opens.mem_iSup.mpr ⟨x, ?_⟩
      change (c.π.app j ≫ D.map _).base x ∈ (D.obj (i (σi x))).basicOpen (f (σi x))
      rw [Cone.w]
      exact hσi _)
  refine ⟨k, .of_forall_exists_mem_basicOpen _ fun x ↦ ?_⟩
  obtain ⟨y, hy⟩ := TopologicalSpace.Opens.mem_iSup.mp (hk.ge (Set.mem_univ x))
  use (D.map fkj).appTop ((D.map (fj _ (Finset.mem_image_of_mem i (hσiσ y)))).appTop (f _))
  rw [← Scheme.preimage_basicOpen_top, ← Scheme.preimage_basicOpen_top]
  exact ⟨((hf _).preimage _).preimage _, hy⟩