l3lab/ntp-mathlib huggingface dataset:
/-- The functions satisfying a local predicate satisfy the sheaf condition.
-/
theorem isSheaf (P : LocalPredicate T) : (subpresheafToTypes P.toPrelocalPredicate).IsSheaf :=
  Presheaf.isSheaf_of_isSheafUniqueGluing_types.{v} _ fun ι U sf sf_comp => by
    -- We show the sheaf condition in terms of unique gluing.
    -- First we obtain a family of sections for the underlying sheaf of functions,
    -- by forgetting that the predicate holds
    let sf' : ∀ i : ι, (presheafToTypes X T).obj (op (U i)) := fun i => (sf i).val
    -- Since our original family is compatible, this one is as well
    have sf'_comp : (presheafToTypes X T).IsCompatible U sf' := fun i j =>
      congr_arg Subtype.val (sf_comp i j)
    -- So, we can obtain a unique gluing
    obtain ⟨gl, gl_spec, gl_uniq⟩ := (sheafToTypes X T).existsUnique_gluing U sf' sf'_comp
    refine' ⟨⟨gl, _⟩, _, _⟩
    · -- Our first goal is to show that this chosen gluing satisfies the
      -- predicate. Of course, we use locality of the predicate.
      apply P.locality
      rintro ⟨x, mem⟩
      -- Once we're at a particular point `x`, we can select some open set `x ∈ U i`.
      choose i hi using Opens.mem_iSup.mp mem
      -- We claim that the predicate holds in `U i`
      use U i, hi, Opens.leSupr U i
      -- This follows, since our original family `sf` satisfies the predicate
      convert (sf i).property using 1
      exact gl_spec i

    -- It remains to show that the chosen lift is really a gluing for the subsheaf and
    -- that it is unique. Both of which follow immediately from the corresponding facts
    -- in the sheaf of functions without the local predicate.
    · exact fun i => Subtype.ext (gl_spec i)
    · intro gl' hgl'
      refine Subtype.ext ?_
      

Proof state:
case intro.intro.refine'_3
X : TopCat
T : ↑X → Type v
P✝ : PrelocalPredicate T
P : LocalPredicate T
ι : Type v
U : ι → Opens ↑X
sf : (i : ι) → (forget (Type v)).obj ((subpresheafToTypes P.toPrelocalPredicate).obj (op (U i)))
sf_comp : IsCompatible (subpresheafToTypes P.toPrelocalPredicate) U sf
sf' : (i : ι) → (presheafToTypes X T).obj (op (U i)) := fun i => ↑(sf i)
sf'_comp : IsCompatible (presheafToTypes X T) U sf'
gl : (forget (Type v)).obj ((sheafToTypes X T).val.obj (op (iSup U)))
gl_spec : IsGluing (sheafToTypes X T).val U sf' gl
gl_uniq :
  ∀ (y : (forget (Type v)).obj ((sheafToTypes X T).val.obj (op (iSup U)))),
    (fun s => IsGluing (sheafToTypes X T).val U sf' s) y → y = gl
gl' : (forget (Type v)).obj ((subpresheafToTypes P.toPrelocalPredicate).obj (op (iSup U)))
hgl' : IsGluing (subpresheafToTypes P.toPrelocalPredicate) U sf gl'
⊢ ↑gl' = ↑{ val := gl, property := (_ : PrelocalPredicate.pred P.toPrelocalPredicate gl) }

Next tactic:
exact gl_uniq gl'.1 fun i => congr_arg Subtype.val (hgl' i)
/-- There is a canonical map from the stalk to the original fiber, given by evaluating sections.
-/
def stalkToFiber (P : LocalPredicate T) (x : X) : (subsheafToTypes P).presheaf.stalk x ⟶ T x := by
  

Proof state:
X : TopCat
T : ↑X → Type v
P : LocalPredicate T
x : ↑X
⊢ Presheaf.stalk (Sheaf.presheaf (subsheafToTypes P)) x ⟶ T x

Next tactic:
refine'
    colimit.desc _
      { pt := T x
        ι :=
          { app := fun U f => _
            naturality := _ } }
/-- There is a canonical map from the stalk to the original fiber, given by evaluating sections.
-/
def stalkToFiber (P : LocalPredicate T) (x : X) : (subsheafToTypes P).presheaf.stalk x ⟶ T x := by
  refine'
    colimit.desc _
      { pt := T x
        ι :=
          { app := fun U f => _
            naturality := _ } }
  · 

Proof state:
case refine'_1
X : TopCat
T : ↑X → Type v
P : LocalPredicate T
x : ↑X
U : (OpenNhds x)ᵒᵖ
f :
  (((whiskeringLeft (OpenNhds x)ᵒᵖ (Opens ↑X)ᵒᵖ (Type v)).obj (OpenNhds.inclusion x).op).obj
        (Sheaf.presheaf (subsheafToTypes P))).obj
    U
⊢ ((Functor.const (OpenNhds x)ᵒᵖ).obj (T x)).obj U

Next tactic:
exact f.1 ⟨x, (unop U).2⟩
/-- There is a canonical map from the stalk to the original fiber, given by evaluating sections.
-/
def stalkToFiber (P : LocalPredicate T) (x : X) : (subsheafToTypes P).presheaf.stalk x ⟶ T x := by
  refine'
    colimit.desc _
      { pt := T x
        ι :=
          { app := fun U f => _
            naturality := _ } }
  · exact f.1 ⟨x, (unop U).2⟩
  · 

Proof state:
case refine'_2
X : TopCat
T : ↑X → Type v
P : LocalPredicate T
x : ↑X
⊢ ∀ ⦃X_1 Y : (OpenNhds x)ᵒᵖ⦄ (f : X_1 ⟶ Y),
    (((whiskeringLeft (OpenNhds x)ᵒᵖ (Opens ↑X)ᵒᵖ (Type v)).obj (OpenNhds.inclusion x).op).obj
              (Sheaf.presheaf (subsheafToTypes P))).map
          f ≫
        (fun U f => ↑f { val := x, property := (_ : x ∈ U.unop.obj) }) Y =
      (fun U f => ↑f { val := x, property := (_ : x ∈ U.unop.obj) }) X_1 ≫
        ((Functor.const (OpenNhds x)ᵒᵖ).obj (T x)).map f

Next tactic:
aesop
theorem stalkToFiber_germ (P : LocalPredicate T) (U : Opens X) (x : U) (f) :
    stalkToFiber P x ((subsheafToTypes P).presheaf.germ x f) = f.1 x := by
  

Proof state:
X : TopCat
T : ↑X → Type v
P : LocalPredicate T
U : Opens ↑X
x : ↥U
f : (Sheaf.presheaf (subsheafToTypes P)).obj (op U)
⊢ stalkToFiber P (↑x) (Presheaf.germ (Sheaf.presheaf (subsheafToTypes P)) x f) = ↑f x

Next tactic:
dsimp [Presheaf.germ, stalkToFiber]
theorem stalkToFiber_germ (P : LocalPredicate T) (U : Opens X) (x : U) (f) :
    stalkToFiber P x ((subsheafToTypes P).presheaf.germ x f) = f.1 x := by
  dsimp [Presheaf.germ, stalkToFiber]
  

Proof state:
X : TopCat
T : ↑X → Type v
P : LocalPredicate T
U : Opens ↑X
x : ↥U
f : (Sheaf.presheaf (subsheafToTypes P)).obj (op U)
⊢ colimit.desc ((OpenNhds.inclusion ↑x).op ⋙ subpresheafToTypes P.toPrelocalPredicate)
      { pt := T ↑x, ι := NatTrans.mk fun U_1 f => ↑f { val := ↑x, property := (_ : ↑x ∈ U_1.unop.obj) } }
      (colimit.ι ((OpenNhds.inclusion ↑x).op ⋙ subpresheafToTypes P.toPrelocalPredicate)
        (op { obj := U, property := (_ : ↑x ∈ U) }) f) =
    ↑f x

Next tactic:
cases x
theorem stalkToFiber_germ (P : LocalPredicate T) (U : Opens X) (x : U) (f) :
    stalkToFiber P x ((subsheafToTypes P).presheaf.germ x f) = f.1 x := by
  dsimp [Presheaf.germ, stalkToFiber]
  cases x
  

Proof state:
case mk
X : TopCat
T : ↑X → Type v
P : LocalPredicate T
U : Opens ↑X
f : (Sheaf.presheaf (subsheafToTypes P)).obj (op U)
val✝ : ↑X
property✝ : val✝ ∈ U
⊢ colimit.desc
      ((OpenNhds.inclusion ↑{ val := val✝, property := property✝ }).op ⋙ subpresheafToTypes P.toPrelocalPredicate)
      { pt := T ↑{ val := val✝, property := property✝ },
        ι :=
          NatTrans.mk fun U_1 f =>
            ↑f
              { val := ↑{ val := val✝, property := property✝ },
                property := (_ : ↑{ val := val✝, property := property✝ } ∈ U_1.unop.obj) } }
      (colimit.ι
        ((OpenNhds.inclusion ↑{ val := val✝, property := property✝ }).op ⋙ subpresheafToTypes P.toPrelocalPredicate)
        (op { obj := U, property := (_ : ↑{ val := val✝, property := property✝ } ∈ U) }) f) =
    ↑f { val := val✝, property := property✝ }

Next tactic:
simp
/-- The `stalkToFiber` map is surjective at `x` if
every point in the fiber `T x` has an allowed section passing through it.
-/
theorem stalkToFiber_surjective (P : LocalPredicate T) (x : X)
    (w : ∀ t : T x, ∃ (U : OpenNhds x) (f : ∀ y : U.1, T y) (_ : P.pred f), f ⟨x, U.2⟩ = t) :
    Function.Surjective (stalkToFiber P x) := fun t => by
  

Proof state:
X : TopCat
T : ↑X → Type v
P : LocalPredicate T
x : ↑X
w :
  ∀ (t : T x),
    ∃ U f, ∃ (_ : PrelocalPredicate.pred P.toPrelocalPredicate f), f { val := x, property := (_ : x ∈ U.obj) } = t
t : T x
⊢ ∃ a, stalkToFiber P x a = t

Next tactic:
rcases w t with ⟨U, f, h, rfl⟩
/-- The `stalkToFiber` map is surjective at `x` if
every point in the fiber `T x` has an allowed section passing through it.
-/
theorem stalkToFiber_surjective (P : LocalPredicate T) (x : X)
    (w : ∀ t : T x, ∃ (U : OpenNhds x) (f : ∀ y : U.1, T y) (_ : P.pred f), f ⟨x, U.2⟩ = t) :
    Function.Surjective (stalkToFiber P x) := fun t => by
  rcases w t with ⟨U, f, h, rfl⟩
  

Proof state:
case intro.intro.intro
X : TopCat
T : ↑X → Type v
P : LocalPredicate T
x : ↑X
w :
  ∀ (t : T x),
    ∃ U f, ∃ (_ : PrelocalPredicate.pred P.toPrelocalPredicate f), f { val := x, property := (_ : x ∈ U.obj) } = t
U : OpenNhds x
f : (y : ↥U.obj) → T ↑y
h : PrelocalPredicate.pred P.toPrelocalPredicate f
⊢ ∃ a, stalkToFiber P x a = f { val := x, property := (_ : x ∈ U.obj) }

Next tactic:
fconstructor
/-- The `stalkToFiber` map is surjective at `x` if
every point in the fiber `T x` has an allowed section passing through it.
-/
theorem stalkToFiber_surjective (P : LocalPredicate T) (x : X)
    (w : ∀ t : T x, ∃ (U : OpenNhds x) (f : ∀ y : U.1, T y) (_ : P.pred f), f ⟨x, U.2⟩ = t) :
    Function.Surjective (stalkToFiber P x) := fun t => by
  rcases w t with ⟨U, f, h, rfl⟩
  fconstructor
  · 

Proof state:
case intro.intro.intro.w
X : TopCat
T : ↑X → Type v
P : LocalPredicate T
x : ↑X
w :
  ∀ (t : T x),
    ∃ U f, ∃ (_ : PrelocalPredicate.pred P.toPrelocalPredicate f), f { val := x, property := (_ : x ∈ U.obj) } = t
U : OpenNhds x
f : (y : ↥U.obj) → T ↑y
h : PrelocalPredicate.pred P.toPrelocalPredicate f
⊢ Presheaf.stalk (Sheaf.presheaf (subsheafToTypes P)) x

Next tactic:
exact (subsheafToTypes P).presheaf.germ ⟨x, U.2⟩ ⟨f, h⟩
/-- The `stalkToFiber` map is surjective at `x` if
every point in the fiber `T x` has an allowed section passing through it.
-/
theorem stalkToFiber_surjective (P : LocalPredicate T) (x : X)
    (w : ∀ t : T x, ∃ (U : OpenNhds x) (f : ∀ y : U.1, T y) (_ : P.pred f), f ⟨x, U.2⟩ = t) :
    Function.Surjective (stalkToFiber P x) := fun t => by
  rcases w t with ⟨U, f, h, rfl⟩
  fconstructor
  · exact (subsheafToTypes P).presheaf.germ ⟨x, U.2⟩ ⟨f, h⟩
  · 

Proof state:
case intro.intro.intro.h
X : TopCat
T : ↑X → Type v
P : LocalPredicate T
x : ↑X
w :
  ∀ (t : T x),
    ∃ U f, ∃ (_ : PrelocalPredicate.pred P.toPrelocalPredicate f), f { val := x, property := (_ : x ∈ U.obj) } = t
U : OpenNhds x
f : (y : ↥U.obj) → T ↑y
h : PrelocalPredicate.pred P.toPrelocalPredicate f
⊢ stalkToFiber P x
      (Presheaf.germ (Sheaf.presheaf (subsheafToTypes P)) { val := x, property := (_ : x ∈ U.obj) }
        { val := f, property := h }) =
    f { val := x, property := (_ : x ∈ U.obj) }

Next tactic:
exact stalkToFiber_germ _ U.1 ⟨x, U.2⟩ ⟨f, h⟩
/-- The `stalkToFiber` map is injective at `x` if any two allowed sections which agree at `x`
agree on some neighborhood of `x`.
-/
theorem stalkToFiber_injective (P : LocalPredicate T) (x : X)
    (w :
      ∀ (U V : OpenNhds x) (fU : ∀ y : U.1, T y) (_ : P.pred fU) (fV : ∀ y : V.1, T y)
        (_ : P.pred fV) (_ : fU ⟨x, U.2⟩ = fV ⟨x, V.2⟩),
        ∃ (W : OpenNhds x) (iU : W ⟶ U) (iV : W ⟶ V), ∀ w : W.1,
          fU (iU w : U.1) = fV (iV w : V.1)) :
    Function.Injective (stalkToFiber P x) := fun tU tV h => by
  -- We promise to provide all the ingredients of the proof later:
  

Proof state:
X : TopCat
T : ↑X → Type v
P : LocalPredicate T
x : ↑X
w :
  ∀ (U V : OpenNhds x) (fU : (y : ↥U.obj) → T ↑y),
    PrelocalPredicate.pred P.toPrelocalPredicate fU →
      ∀ (fV : (y : ↥V.obj) → T ↑y),
        PrelocalPredicate.pred P.toPrelocalPredicate fV →
          fU { val := x, property := (_ : x ∈ U.obj) } = fV { val := x, property := (_ : x ∈ V.obj) } →
            ∃ W iU iV,
              ∀ (w : ↥W.obj),
                fU ((fun x_4 => { val := ↑x_4, property := (_ : ↑x_4 ∈ ↑U.obj) }) w) =
                  fV ((fun x_4 => { val := ↑x_4, property := (_ : ↑x_4 ∈ ↑V.obj) }) w)
tU tV : Presheaf.stalk (Sheaf.presheaf (subsheafToTypes P)) x
h : stalkToFiber P x tU = stalkToFiber P x tV
⊢ tU = tV

Next tactic:
let Q :
    ∃ (W : (OpenNhds x)ᵒᵖ) (s : ∀ w : (unop W).1, T w) (hW : P.pred s),
      tU = (subsheafToTypes P).presheaf.germ ⟨x, (unop W).2⟩ ⟨s, hW⟩ ∧
        tV = (subsheafToTypes P).presheaf.germ ⟨x, (unop W).2⟩ ⟨s, hW⟩ :=
    ?_
/-- The `stalkToFiber` map is injective at `x` if any two allowed sections which agree at `x`
agree on some neighborhood of `x`.
-/
theorem stalkToFiber_injective (P : LocalPredicate T) (x : X)
    (w :
      ∀ (U V : OpenNhds x) (fU : ∀ y : U.1, T y) (_ : P.pred fU) (fV : ∀ y : V.1, T y)
        (_ : P.pred fV) (_ : fU ⟨x, U.2⟩ = fV ⟨x, V.2⟩),
        ∃ (W : OpenNhds x) (iU : W ⟶ U) (iV : W ⟶ V), ∀ w : W.1,
          fU (iU w : U.1) = fV (iV w : V.1)) :
    Function.Injective (stalkToFiber P x) := fun tU tV h => by
  -- We promise to provide all the ingredients of the proof later:
  let Q :
    ∃ (W : (OpenNhds x)ᵒᵖ) (s : ∀ w : (unop W).1, T w) (hW : P.pred s),
      tU = (subsheafToTypes P).presheaf.germ ⟨x, (unop W).2⟩ ⟨s, hW⟩ ∧
        tV = (subsheafToTypes P).presheaf.germ ⟨x, (unop W).2⟩ ⟨s, hW⟩ :=
    ?_
  · 

Proof state:
case refine_2
X : TopCat
T : ↑X → Type v
P : LocalPredicate T
x : ↑X
w :
  ∀ (U V : OpenNhds x) (fU : (y : ↥U.obj) → T ↑y),
    PrelocalPredicate.pred P.toPrelocalPredicate fU →
      ∀ (fV : (y : ↥V.obj) → T ↑y),
        PrelocalPredicate.pred P.toPrelocalPredicate fV →
          fU { val := x, property := (_ : x ∈ U.obj) } = fV { val := x, property := (_ : x ∈ V.obj) } →
            ∃ W iU iV,
              ∀ (w : ↥W.obj),
                fU ((fun x_4 => { val := ↑x_4, property := (_ : ↑x_4 ∈ ↑U.obj) }) w) =
                  fV ((fun x_4 => { val := ↑x_4, property := (_ : ↑x_4 ∈ ↑V.obj) }) w)
tU tV : Presheaf.stalk (Sheaf.presheaf (subsheafToTypes P)) x
h : stalkToFiber P x tU = stalkToFiber P x tV
Q : ∃ W s,
  ∃ (hW : PrelocalPredicate.pred P.toPrelocalPredicate s),
    tU =
        Presheaf.germ (Sheaf.presheaf (subsheafToTypes P)) { val := x, property := (_ : x ∈ W.unop.obj) }
          { val := s, property := hW } ∧
      tV =
        Presheaf.germ (Sheaf.presheaf (subsheafToTypes P)) { val := x, property := (_ : x ∈ W.unop.obj) }
          { val := s, property := hW } :=
  ?refine_1
⊢ tU = tV

Next tactic:
choose W s hW e using Q
/-- The `stalkToFiber` map is injective at `x` if any two allowed sections which agree at `x`
agree on some neighborhood of `x`.
-/
theorem stalkToFiber_injective (P : LocalPredicate T) (x : X)
    (w :
      ∀ (U V : OpenNhds x) (fU : ∀ y : U.1, T y) (_ : P.pred fU) (fV : ∀ y : V.1, T y)
        (_ : P.pred fV) (_ : fU ⟨x, U.2⟩ = fV ⟨x, V.2⟩),
        ∃ (W : OpenNhds x) (iU : W ⟶ U) (iV : W ⟶ V), ∀ w : W.1,
          fU (iU w : U.1) = fV (iV w : V.1)) :
    Function.Injective (stalkToFiber P x) := fun tU tV h => by
  -- We promise to provide all the ingredients of the proof later:
  let Q :
    ∃ (W : (OpenNhds x)ᵒᵖ) (s : ∀ w : (unop W).1, T w) (hW : P.pred s),
      tU = (subsheafToTypes P).presheaf.germ ⟨x, (unop W).2⟩ ⟨s, hW⟩ ∧
        tV = (subsheafToTypes P).presheaf.germ ⟨x, (unop W).2⟩ ⟨s, hW⟩ :=
    ?_
  · choose W s hW e using Q
    

Proof state:
case refine_2
X : TopCat
T : ↑X → Type v
P : LocalPredicate T
x : ↑X
w :
  ∀ (U V : OpenNhds x) (fU : (y : ↥U.obj) → T ↑y),
    PrelocalPredicate.pred P.toPrelocalPredicate fU →
      ∀ (fV : (y : ↥V.obj) → T ↑y),
        PrelocalPredicate.pred P.toPrelocalPredicate fV →
          fU { val := x, property := (_ : x ∈ U.obj) } = fV { val := x, property := (_ : x ∈ V.obj) } →
            ∃ W iU iV,
              ∀ (w : ↥W.obj),
                fU ((fun x_4 => { val := ↑x_4, property := (_ : ↑x_4 ∈ ↑U.obj) }) w) =
                  fV ((fun x_4 => { val := ↑x_4, property := (_ : ↑x_4 ∈ ↑V.obj) }) w)
tU tV : Presheaf.stalk (Sheaf.presheaf (subsheafToTypes P)) x
h : stalkToFiber P x tU = stalkToFiber P x tV
W : (OpenNhds x)ᵒᵖ
s : (w : ↥W.unop.obj) → T ↑w
hW : PrelocalPredicate.pred P.toPrelocalPredicate s
e :
  tU =
      Presheaf.germ (Sheaf.presheaf (subsheafToTypes P)) { val := x, property := (_ : x ∈ W.unop.obj) }
        { val := s, property := hW } ∧
    tV =
      Presheaf.germ (Sheaf.presheaf (subsheafToTypes P)) { val := x, property := (_ : x ∈ W.unop.obj) }
        { val := s, property := hW }
⊢ tU = tV

Next tactic:
exact e.1.trans e.2.symm
/-- The `stalkToFiber` map is injective at `x` if any two allowed sections which agree at `x`
agree on some neighborhood of `x`.
-/
theorem stalkToFiber_injective (P : LocalPredicate T) (x : X)
    (w :
      ∀ (U V : OpenNhds x) (fU : ∀ y : U.1, T y) (_ : P.pred fU) (fV : ∀ y : V.1, T y)
        (_ : P.pred fV) (_ : fU ⟨x, U.2⟩ = fV ⟨x, V.2⟩),
        ∃ (W : OpenNhds x) (iU : W ⟶ U) (iV : W ⟶ V), ∀ w : W.1,
          fU (iU w : U.1) = fV (iV w : V.1)) :
    Function.Injective (stalkToFiber P x) := fun tU tV h => by
  -- We promise to provide all the ingredients of the proof later:
  let Q :
    ∃ (W : (OpenNhds x)ᵒᵖ) (s : ∀ w : (unop W).1, T w) (hW : P.pred s),
      tU = (subsheafToTypes P).presheaf.germ ⟨x, (unop W).2⟩ ⟨s, hW⟩ ∧
        tV = (subsheafToTypes P).presheaf.germ ⟨x, (unop W).2⟩ ⟨s, hW⟩ :=
    ?_
  · choose W s hW e using Q
    exact e.1.trans e.2.symm
  -- Then use induction to pick particular representatives of `tU tV : stalk x`
  

Proof state:
case refine_1
X : TopCat
T : ↑X → Type v
P : LocalPredicate T
x : ↑X
w :
  ∀ (U V : OpenNhds x) (fU : (y : ↥U.obj) → T ↑y),
    PrelocalPredicate.pred P.toPrelocalPredicate fU →
      ∀ (fV : (y : ↥V.obj) → T ↑y),
        PrelocalPredicate.pred P.toPrelocalPredicate fV →
          fU { val := x, property := (_ : x ∈ U.obj) } = fV { val := x, property := (_ : x ∈ V.obj) } →
            ∃ W iU iV,
              ∀ (w : ↥W.obj),
                fU ((fun x_4 => { val := ↑x_4, property := (_ : ↑x_4 ∈ ↑U.obj) }) w) =
                  fV ((fun x_4 => { val := ↑x_4, property := (_ : ↑x_4 ∈ ↑V.obj) }) w)
tU tV : Presheaf.stalk (Sheaf.presheaf (subsheafToTypes P)) x
h : stalkToFiber P x tU = stalkToFiber P x tV
⊢ ∃ W s,
    ∃ (hW : PrelocalPredicate.pred P.toPrelocalPredicate s),
      tU =
          Presheaf.germ (Sheaf.presheaf (subsheafToTypes P)) { val := x, property := (_ : x ∈ W.unop.obj) }
            { val := s, property := hW } ∧
        tV =
          Presheaf.germ (Sheaf.presheaf (subsheafToTypes P)) { val := x, property := (_ : x ∈ W.unop.obj) }
            { val := s, property := hW }

Next tactic:
obtain ⟨U, ⟨fU, hU⟩, rfl⟩ := jointly_surjective'.{v, v} tU
/-- The `stalkToFiber` map is injective at `x` if any two allowed sections which agree at `x`
agree on some neighborhood of `x`.
-/
theorem stalkToFiber_injective (P : LocalPredicate T) (x : X)
    (w :
      ∀ (U V : OpenNhds x) (fU : ∀ y : U.1, T y) (_ : P.pred fU) (fV : ∀ y : V.1, T y)
        (_ : P.pred fV) (_ : fU ⟨x, U.2⟩ = fV ⟨x, V.2⟩),
        ∃ (W : OpenNhds x) (iU : W ⟶ U) (iV : W ⟶ V), ∀ w : W.1,
          fU (iU w : U.1) = fV (iV w : V.1)) :
    Function.Injective (stalkToFiber P x) := fun tU tV h => by
  -- We promise to provide all the ingredients of the proof later:
  let Q :
    ∃ (W : (OpenNhds x)ᵒᵖ) (s : ∀ w : (unop W).1, T w) (hW : P.pred s),
      tU = (subsheafToTypes P).presheaf.germ ⟨x, (unop W).2⟩ ⟨s, hW⟩ ∧
        tV = (subsheafToTypes P).presheaf.germ ⟨x, (unop W).2⟩ ⟨s, hW⟩ :=
    ?_
  · choose W s hW e using Q
    exact e.1.trans e.2.symm
  -- Then use induction to pick particular representatives of `tU tV : stalk x`
  obtain ⟨U, ⟨fU, hU⟩, rfl⟩ := jointly_surjective'.{v, v} tU
  

Proof state:
case refine_1.intro.intro.mk
X : TopCat
T : ↑X → Type v
P : LocalPredicate T
x : ↑X
w :
  ∀ (U V : OpenNhds x) (fU : (y : ↥U.obj) → T ↑y),
    PrelocalPredicate.pred P.toPrelocalPredicate fU →
      ∀ (fV : (y : ↥V.obj) → T ↑y),
        PrelocalPredicate.pred P.toPrelocalPredicate fV →
          fU { val := x, property := (_ : x ∈ U.obj) } = fV { val := x, property := (_ : x ∈ V.obj) } →
            ∃ W iU iV,
              ∀ (w : ↥W.obj),
                fU ((fun x_4 => { val := ↑x_4, property := (_ : ↑x_4 ∈ ↑U.obj) }) w) =
                  fV ((fun x_4 => { val := ↑x_4, property := (_ : ↑x_4 ∈ ↑V.obj) }) w)
tV : Presheaf.stalk (Sheaf.presheaf (subsheafToTypes P)) x
U : (OpenNhds x)ᵒᵖ
fU : (x_1 : ↥((OpenNhds.inclusion x).op.obj U).unop) → T ↑x_1
hU : PrelocalPredicate.pred P.toPrelocalPredicate fU
h :
  stalkToFiber P x
      (colimit.ι
        (((whiskeringLeft (OpenNhds x)ᵒᵖ (Opens ↑X)ᵒᵖ (Type v)).obj (OpenNhds.inclusion x).op).obj
          (Sheaf.presheaf (subsheafToTypes P)))
        U { val := fU, property := hU }) =
    stalkToFiber P x tV
⊢ ∃ W s,
    ∃ (hW : PrelocalPredicate.pred P.toPrelocalPredicate s),
      colimit.ι
            (((whiskeringLeft (OpenNhds x)ᵒᵖ (Opens ↑X)ᵒᵖ (Type v)).obj (OpenNhds.inclusion x).op).obj
              (Sheaf.presheaf (subsheafToTypes P)))
            U { val := fU, property := hU } =
          Presheaf.germ (Sheaf.presheaf (subsheafToTypes P)) { val := x, property := (_ : x ∈ W.unop.obj) }
            { val := s, property := hW } ∧
        tV =
          Presheaf.germ (Sheaf.presheaf (subsheafToTypes P)) { val := x, property := (_ : x ∈ W.unop.obj) }
            { val := s, property := hW }

Next tactic:
obtain ⟨V, ⟨fV, hV⟩, rfl⟩ := jointly_surjective'.{v, v} tV
/-- The `stalkToFiber` map is injective at `x` if any two allowed sections which agree at `x`
agree on some neighborhood of `x`.
-/
theorem stalkToFiber_injective (P : LocalPredicate T) (x : X)
    (w :
      ∀ (U V : OpenNhds x) (fU : ∀ y : U.1, T y) (_ : P.pred fU) (fV : ∀ y : V.1, T y)
        (_ : P.pred fV) (_ : fU ⟨x, U.2⟩ = fV ⟨x, V.2⟩),
        ∃ (W : OpenNhds x) (iU : W ⟶ U) (iV : W ⟶ V), ∀ w : W.1,
          fU (iU w : U.1) = fV (iV w : V.1)) :
    Function.Injective (stalkToFiber P x) := fun tU tV h => by
  -- We promise to provide all the ingredients of the proof later:
  let Q :
    ∃ (W : (OpenNhds x)ᵒᵖ) (s : ∀ w : (unop W).1, T w) (hW : P.pred s),
      tU = (subsheafToTypes P).presheaf.germ ⟨x, (unop W).2⟩ ⟨s, hW⟩ ∧
        tV = (subsheafToTypes P).presheaf.germ ⟨x, (unop W).2⟩ ⟨s, hW⟩ :=
    ?_
  · choose W s hW e using Q
    exact e.1.trans e.2.symm
  -- Then use induction to pick particular representatives of `tU tV : stalk x`
  obtain ⟨U, ⟨fU, hU⟩, rfl⟩ := jointly_surjective'.{v, v} tU
  obtain ⟨V, ⟨fV, hV⟩, rfl⟩ := jointly_surjective'.{v, v} tV
  · -- Decompose everything into its constituent parts:
    dsimp
    simp only [stalkToFiber, Types.Colimit.ι_desc_apply'] at h
    

Proof state:
case refine_1.intro.intro.mk.intro.intro.mk
X : TopCat
T : ↑X → Type v
P : LocalPredicate T
x : ↑X
w :
  ∀ (U V : OpenNhds x) (fU : (y : ↥U.obj) → T ↑y),
    PrelocalPredicate.pred P.toPrelocalPredicate fU →
      ∀ (fV : (y : ↥V.obj) → T ↑y),
        PrelocalPredicate.pred P.toPrelocalPredicate fV →
          fU { val := x, property := (_ : x ∈ U.obj) } = fV { val := x, property := (_ : x ∈ V.obj) } →
            ∃ W iU iV,
              ∀ (w : ↥W.obj),
                fU ((fun x_4 => { val := ↑x_4, property := (_ : ↑x_4 ∈ ↑U.obj) }) w) =
                  fV ((fun x_4 => { val := ↑x_4, property := (_ : ↑x_4 ∈ ↑V.obj) }) w)
U : (OpenNhds x)ᵒᵖ
fU : (x_1 : ↥((OpenNhds.inclusion x).op.obj U).unop) → T ↑x_1
hU : PrelocalPredicate.pred P.toPrelocalPredicate fU
V : (OpenNhds x)ᵒᵖ
fV : (x_1 : ↥((OpenNhds.inclusion x).op.obj V).unop) → T ↑x_1
hV : PrelocalPredicate.pred P.toPrelocalPredicate fV
h : fU { val := x, property := (_ : x ∈ U.unop.obj) } = fV { val := x, property := (_ : x ∈ V.unop.obj) }
⊢ ∃ W s,
    ∃ (hW : PrelocalPredicate.pred P.toPrelocalPredicate s),
      colimit.ι ((OpenNhds.inclusion x).op ⋙ subpresheafToTypes P.toPrelocalPredicate) U { val := fU, property := hU } =
          Presheaf.germ (subpresheafToTypes P.toPrelocalPredicate) { val := x, property := (_ : x ∈ W.unop.obj) }
            { val := s, property := hW } ∧
        colimit.ι ((OpenNhds.inclusion x).op ⋙ subpresheafToTypes P.toPrelocalPredicate) V
            { val := fV, property := hV } =
          Presheaf.germ (subpresheafToTypes P.toPrelocalPredicate) { val := x, property := (_ : x ∈ W.unop.obj) }
            { val := s, property := hW }

Next tactic:
specialize w (unop U) (unop V) fU hU fV hV h