-- Mathlib/AlgebraicGeometry/Morphisms/SurjectiveOnStalks.lean
/-- If `Y ⟶ S` is surjective on stalks, then for every `X ⟶ S`, `X ×ₛ Y` is a subset of
`X × Y` (cartesian product as topological spaces) with the induced topology. -/
lemma isEmbedding_pullback {X Y S : Scheme.{u}} (f : X ⟶ S) (g : Y ⟶ S) [SurjectiveOnStalks g] :
    IsEmbedding (fun x ↦ ((pullback.fst f g).base x, (pullback.snd f g).base x))

Proof state:
case refine_2.intro.intro.intro.intro.intro.intro.refine_3.e_a.e_a.e_self.e_self.e_self
X Y S : Scheme
f : X ⟶ S
g : Y ⟶ S
inst✝ : SurjectiveOnStalks g
L : ↑↑(pullback f g).toPresheafedSpace → ↑↑X.toPresheafedSpace × ↑↑Y.toPresheafedSpace :=
  fun x => ((ConcreteCategory.hom (pullback.fst f g).base) x, (ConcreteCategory.hom (pullback.snd f g).base) x)
H :
  ∀ (R A B : CommRingCat) (f' : Spec A ⟶ Spec R) (g' : Spec B ⟶ Spec R) (iX : Spec A ⟶ X) (iY : Spec B ⟶ Y)
    (iS : Spec R ⟶ S) (e₁ : f' ≫ iS = iX ≫ f) (e₂ : g' ≫ iS = iY ≫ g),
    IsOpenImmersion iX →
      IsOpenImmersion iY →
        IsOpenImmersion iS → IsEmbedding (L ∘ ⇑(ConcreteCategory.hom (pullback.map f' g' f g iX iY iS e₁ e₂).base))
𝒰 : S.OpenCover := S.affineOpenCover.openCover
𝒱 : (i : (Scheme.Cover.pullbackCover 𝒰 f).J) → ((Scheme.Cover.pullbackCover 𝒰 f).obj i).OpenCover :=
  fun i => ((Scheme.Cover.pullbackCover 𝒰 f).obj i).affineOpenCover.openCover
𝒲 : (i : (Scheme.Cover.pullbackCover 𝒰 g).J) → ((Scheme.Cover.pullbackCover 𝒰 g).obj i).OpenCover :=
  fun i => ((Scheme.Cover.pullbackCover 𝒰 g).obj i).affineOpenCover.openCover
U : (i : (Scheme.Cover.pullbackCover 𝒰 f).J) × (𝒱 i).J × (𝒲 i).J →
  TopologicalSpace.Opens (↑↑X.toPresheafedSpace × ↑↑Y.toPresheafedSpace) :=
  fun ijk =>
    {
      carrier :=
        {P |
          P.1 ∈ Scheme.Hom.opensRange ((𝒱 ijk.fst).map ijk.snd.1 ≫ (Scheme.Cover.pullbackCover 𝒰 f).map ijk.fst) ∧
            P.2 ∈ Scheme.Hom.opensRange ((𝒲 ijk.fst).map ijk.snd.2 ≫ (Scheme.Cover.pullbackCover 𝒰 g).map ijk.fst)},
      is_open' := ⋯ }
this : Set.range L ⊆ ↑(iSup U)
𝓤 : Scheme.Cover (@IsOpenImmersion) (pullback f g) :=
  Scheme.Cover.bind (Scheme.Pullback.openCoverOfBase 𝒰 f g) fun i =>
    Scheme.Pullback.openCoverOfLeftRight (𝒱 i) (𝒲 i) (pullback.snd f (𝒰.map i)) (pullback.snd g (𝒰.map i))
i : (i : (Scheme.Cover.pullbackCover 𝒰 f).J) × (𝒱 i).J × (𝒲 i).J
x : ↑↑(pullback f g).toPresheafedSpace
x₁ : ↑↑((𝒱 i.fst).obj i.snd.1).toPresheafedSpace
hx₁ :
  (ConcreteCategory.hom ((𝒱 i.fst).map i.snd.1 ≫ (Scheme.Cover.pullbackCover 𝒰 f).map i.fst).base) x₁ =
    ((fun x => ((ConcreteCategory.hom (pullback.fst f g).base) x, (ConcreteCategory.hom (pullback.snd f g).base) x))
        x).1
x₂ : ↑↑((𝒲 i.fst).obj i.snd.2).toPresheafedSpace
hx₂ :
  (ConcreteCategory.hom ((𝒲 i.fst).map i.snd.2 ≫ (Scheme.Cover.pullbackCover 𝒰 g).map i.fst).base) x₂ =
    ((fun x => ((ConcreteCategory.hom (pullback.fst f g).base) x, (ConcreteCategory.hom (pullback.snd f g).base) x))
        x).2
x₁' :
  ↑↑(pullback (pullback.fst f g) ((𝒱 i.fst).map i.snd.1 ≫ (Scheme.Cover.pullbackCover 𝒰 f).map i.fst)).toPresheafedSpace
hx₁' :
  (ConcreteCategory.hom
        (pullback.fst (pullback.fst f g) ((𝒱 i.fst).map i.snd.1 ≫ (Scheme.Cover.pullbackCover 𝒰 f).map i.fst)).base)
      x₁' =
    x
x₂' :
  ↑↑(pullback (pullback.snd f g) ((𝒲 i.fst).map i.snd.2 ≫ (Scheme.Cover.pullbackCover 𝒰 g).map i.fst)).toPresheafedSpace
hx₂' :
  (ConcreteCategory.hom
        (pullback.fst (pullback.snd f g) ((𝒲 i.fst).map i.snd.2 ≫ (Scheme.Cover.pullbackCover 𝒰 g).map i.fst)).base)
      x₂' =
    x
z :
  ↑↑(pullback (pullback.fst (pullback.fst f g) ((𝒱 i.fst).map i.snd.1 ≫ (Scheme.Cover.pullbackCover 𝒰 f).map i.fst))
          (pullback.fst (pullback.snd f g)
            ((𝒲 i.fst).map i.snd.2 ≫ (Scheme.Cover.pullbackCover 𝒰 g).map i.fst))).toPresheafedSpace
hz :
  (ConcreteCategory.hom
        (pullback.fst
            (pullback.fst (pullback.fst f g) ((𝒱 i.fst).map i.snd.1 ≫ (Scheme.Cover.pullbackCover 𝒰 f).map i.fst))
            (pullback.fst (pullback.snd f g)
              ((𝒲 i.fst).map i.snd.2 ≫ (Scheme.Cover.pullbackCover 𝒰 g).map i.fst))).base)
      z =
    x₁'
⊢ (pullbackFstFstIso ((𝒱 i.fst).map i.snd.1 ≫ pullback.snd f (𝒰.map i.fst))
          ((𝒲 i.fst).map i.snd.2 ≫ pullback.snd g (𝒰.map i.fst)) f g
          ((𝒱 i.fst).map i.snd.1 ≫ (Scheme.Cover.pullbackCover 𝒰 f).map i.fst)
          ((𝒲 i.fst).map i.snd.2 ≫ (Scheme.Cover.pullbackCover 𝒰 g).map i.fst) (𝒰.map i.fst) ⋯ ⋯).hom ≫
      𝓤.map i =
    pullback.fst (pullback.fst (pullback.fst f g) ((𝒱 i.fst).map i.snd.1 ≫ (Scheme.Cover.pullbackCover 𝒰 f).map i.fst))
        (pullback.fst (pullback.snd f g) ((𝒲 i.fst).map i.snd.2 ≫ (Scheme.Cover.pullbackCover 𝒰 g).map i.fst)) ≫
      pullback.fst (pullback.fst f g) ((𝒱 i.fst).map i.snd.1 ≫ (Scheme.Cover.pullbackCover 𝒰 f).map i.fst)

Tactic:
apply pullback.hom_ext <;> simp [𝓤, ← pullback.condition, ← pullback.condition_assoc]

Result:
no goals

Proof state:
case h.e'_5.h.h
X Y S : Scheme
f : X ⟶ S
g : Y ⟶ S
inst✝ : SurjectiveOnStalks g
L : ↑↑(pullback f g).toPresheafedSpace → ↑↑X.toPresheafedSpace × ↑↑Y.toPresheafedSpace :=
  fun x => ((ConcreteCategory.hom (pullback.fst f g).base) x, (ConcreteCategory.hom (pullback.snd f g).base) x)
R A B : CommRingCat
iX : Spec A ⟶ X
iY : Spec B ⟶ Y
iS : Spec R ⟶ S
a✝² : IsOpenImmersion iX
a✝¹ : IsOpenImmersion iY
a✝ : IsOpenImmersion iS
φ : R ⟶ A
e₁ : Spec.map φ ≫ iS = iX ≫ f
ψ : R ⟶ B
e₂ : Spec.map ψ ≫ iS = iY ≫ g
H : (CommRingCat.Hom.hom ψ).SurjectiveOnStalks
algInst✝¹ : Algebra ↑R ↑A := (CommRingCat.Hom.hom φ).toAlgebra
algInst✝ : Algebra ↑R ↑B := (CommRingCat.Hom.hom ψ).toAlgebra
e_1✝ :
  ↑↑(pullback (Spec.map φ) (Spec.map ψ)).toPresheafedSpace =
    ↑↑(pullback (Spec.map (CommRingCat.ofHom (algebraMap ↑R ↑A)))
            (Spec.map (CommRingCat.ofHom (algebraMap ↑R ↑B)))).toPresheafedSpace
x : ↑↑(pullback (Spec.map φ) (Spec.map ψ)).toPresheafedSpace
⊢ (L ∘ ⇑(ConcreteCategory.hom (pullback.map (Spec.map φ) (Spec.map ψ) f g iX iY iS e₁ e₂).base)) x =
    ((Prod.map ⇑(ConcreteCategory.hom iX.base) ⇑(ConcreteCategory.hom iY.base) ∘
          PrimeSpectrum.tensorProductTo ↑R ↑A ↑B) ∘
        ⇑(Scheme.homeoOfIso (pullbackSpecIso ↑R ↑A ↑B)))
      x

Tactic:
obtain ⟨x, rfl⟩ := (Scheme.homeoOfIso (pullbackSpecIso R A B).symm).surjective x

Result:
case h.e'_5.h.h.intro
X Y S : Scheme
f : X ⟶ S
g : Y ⟶ S
inst✝ : SurjectiveOnStalks g
L : ↑↑(pullback f g).toPresheafedSpace → ↑↑X.toPresheafedSpace × ↑↑Y.toPresheafedSpace :=
  fun x => ((ConcreteCategory.hom (pullback.fst f g).base) x, (ConcreteCategory.hom (pullback.snd f g).base) x)
R A B : CommRingCat
iX : Spec A ⟶ X
iY : Spec B ⟶ Y
iS : Spec R ⟶ S
a✝² : IsOpenImmersion iX
a✝¹ : IsOpenImmersion iY
a✝ : IsOpenImmersion iS
φ : R ⟶ A
e₁ : Spec.map φ ≫ iS = iX ≫ f
ψ : R ⟶ B
e₂ : Spec.map ψ ≫ iS = iY ≫ g
H : (CommRingCat.Hom.hom ψ).SurjectiveOnStalks
algInst✝¹ : Algebra ↑R ↑A := (CommRingCat.Hom.hom φ).toAlgebra
algInst✝ : Algebra ↑R ↑B := (CommRingCat.Hom.hom ψ).toAlgebra
e_1✝ :
  ↑↑(pullback (Spec.map φ) (Spec.map ψ)).toPresheafedSpace =
    ↑↑(pullback (Spec.map (CommRingCat.ofHom (algebraMap ↑R ↑A)))
            (Spec.map (CommRingCat.ofHom (algebraMap ↑R ↑B)))).toPresheafedSpace
x : ↑↑(Spec (CommRingCat.of (TensorProduct ↑R ↑A ↑B))).toPresheafedSpace
⊢ (L ∘ ⇑(ConcreteCategory.hom (pullback.map (Spec.map φ) (Spec.map ψ) f g iX iY iS e₁ e₂).base))
      ((Scheme.homeoOfIso (pullbackSpecIso ↑R ↑A ↑B).symm) x) =
    ((Prod.map ⇑(ConcreteCategory.hom iX.base) ⇑(ConcreteCategory.hom iY.base) ∘
          PrimeSpectrum.tensorProductTo ↑R ↑A ↑B) ∘
        ⇑(Scheme.homeoOfIso (pullbackSpecIso ↑R ↑A ↑B)))
      ((Scheme.homeoOfIso (pullbackSpecIso ↑R ↑A ↑B).symm) x)