-- 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_2
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₁'
⊢ ((𝒲 i.fst).map i.snd.2 ≫ pullback.snd g (𝒰.map i.fst)) ≫ 𝒰.map i.fst =
    ((𝒲 i.fst).map i.snd.2 ≫ (Scheme.Cover.pullbackCover 𝒰 g).map i.fst) ≫ g

Tactic:
simp [pullback.condition]

Result:
no goals

Proof state:
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
⊢ IsEmbedding fun x =>
    ((ConcreteCategory.hom (pullback.fst f g).base) x, (ConcreteCategory.hom (pullback.snd f g).base) x)

Tactic:
let 𝒱 (i) := ((𝒰.pullbackCover f).obj i).affineOpenCover.openCover

Result:
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
⊢ IsEmbedding fun x =>
    ((ConcreteCategory.hom (pullback.fst f g).base) x, (ConcreteCategory.hom (pullback.snd f g).base) x)